### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.runtime.emf.core Index: src/org/eclipse/gmf/runtime/emf/core/internal/resources/PathmapManager.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.core/src/org/eclipse/gmf/runtime/emf/core/internal/resources/PathmapManager.java,v retrieving revision 1.8 diff -u -r1.8 PathmapManager.java --- src/org/eclipse/gmf/runtime/emf/core/internal/resources/PathmapManager.java 3 Oct 2006 15:05:22 -0000 1.8 +++ src/org/eclipse/gmf/runtime/emf/core/internal/resources/PathmapManager.java 18 Feb 2008 16:04:22 -0000 @@ -54,6 +54,7 @@ import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants; import org.eclipse.gmf.runtime.emf.core.resources.GMFResource; import org.eclipse.gmf.runtime.emf.core.resources.IPathmapManager; +import org.eclipse.gmf.runtime.emf.core.resources.IPathmapManager2; import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil; import org.osgi.framework.Bundle; import org.osgi.service.prefs.BackingStoreException; @@ -63,7 +64,7 @@ * * @author rafikj */ -public class PathmapManager extends AdapterImpl implements IPathmapManager { +public class PathmapManager extends AdapterImpl implements IPathmapManager, IPathmapManager2 { // path maps can be defined using an extension point: Pathmaps // or by referencing an eclipse path variable // or by adding a pathmap manually @@ -83,6 +84,7 @@ // The path map as defined by the extensions and the referenced path variables and the manually // added pathmaps. private static final Map PATH_MAP = Collections.synchronizedMap(configure()); + private static final Set FILE_VARIABLES = Collections.synchronizedSet(new HashSet()); private static final Map instances = Collections.synchronizedMap(new WeakHashMap()); @@ -318,6 +320,14 @@ * @param val the path map variable value (must be an encoded URI) */ public static void setPathVariable(String var, String val) { + internalSetPathVariable(var, val); + + for (Iterator i = allInstances().iterator(); i.hasNext();) { + ((PathmapManager) i.next()).resyncEntries(true); + } + } + + private static void internalSetPathVariable(String var, String val) { // We must try to determine if this pathmap resides in the workspace as some container // so that we store into the pathmap a substitution that is a platform:/resource // type of substitution. This is required because otherwise, pathmap URIs normalize @@ -337,7 +347,51 @@ } PATH_MAP.put(var, val); - + } + + /** + * Set the value of a pathmap variable to point to a specific file (not a folder) + * + * @param var the path map variable name + * @param val the path map variable value (must be an encoded URI pointing to a file, not a folder) + */ + public static void setFilePathVariable(String var, String val) { + FILE_VARIABLES.add(var); + internalSetPathVariable(var, val); + for (Iterator i = allInstances().iterator(); i.hasNext();) { + ((PathmapManager) i.next()).resyncEntries(true); + } + } + + /** + * Sets the value of a map of pathmap variables to point to specific files (not folders) + * + * @param settings A map of new variables(Strings) to their values(Strings). + */ + public static void setFilePathVariables(Map settings) { + FILE_VARIABLES.addAll(settings.keySet()); + + for (Iterator i = settings.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry)i.next(); + internalSetPathVariable((String)entry.getKey(), (String)entry.getValue()); + } + + for (Iterator i = allInstances().iterator(); i.hasNext();) { + ((PathmapManager) i.next()).resyncEntries(true); + } + } + + /** + * Sets the value of a map of pathmap variables to point specific folders (not files) + * + * @param settings A map of new variables(Strings) to their values(Strings). + */ + public static void setPathVariables(Map settings) { + for (Iterator i = settings.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry)i.next(); + internalSetPathVariable((String)entry.getKey(), (String)entry.getValue()); + } + for (Iterator i = allInstances().iterator(); i.hasNext();) { ((PathmapManager) i.next()).resyncEntries(true); } @@ -349,6 +403,30 @@ return Status.OK_STATUS; // TODO: report accurate status } + public IStatus addFilePathVariable(String name, String value) { + setFilePathVariable(name, value); + + return Status.OK_STATUS; // TODO: report accurate status + } + + public IStatus addFilePathVariables(Map settings) { + setFilePathVariables(settings); + + return Status.OK_STATUS; // TODO: report accurate status + } + + public IStatus addFolderPathVariable(String name, String value) { + setPathVariable(name, value); + + return Status.OK_STATUS; + } + + public IStatus addFolderPathVariables(Map settings) { + setPathVariables(settings); + + return Status.OK_STATUS; + } + /** * Remove a pathmap variable. */ @@ -637,7 +715,8 @@ uri.append(val); - if (val.charAt(len - 1) != EMFCoreConstants.PATH_SEPARATOR) + // TODO + if (!FILE_VARIABLES.contains(var) && val.charAt(len - 1) != EMFCoreConstants.PATH_SEPARATOR) uri.append(EMFCoreConstants.PATH_SEPARATOR); URI valURI = URI.createURI(uri.toString()); @@ -728,7 +807,8 @@ uri.append(EMFCoreConstants.PATH_SEPARATOR); uri.append(var); - if (var.charAt(len - 1) != EMFCoreConstants.PATH_SEPARATOR) + //TODO + if (!FILE_VARIABLES.contains(var) && var.charAt(len - 1) != EMFCoreConstants.PATH_SEPARATOR) uri.append(EMFCoreConstants.PATH_SEPARATOR); return URI.createURI(uri.toString()); Index: src/org/eclipse/gmf/runtime/emf/core/resources/IPathmapManager2.java =================================================================== RCS file: src/org/eclipse/gmf/runtime/emf/core/resources/IPathmapManager2.java diff -N src/org/eclipse/gmf/runtime/emf/core/resources/IPathmapManager2.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/runtime/emf/core/resources/IPathmapManager2.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,53 @@ +package org.eclipse.gmf.runtime.emf.core.resources; + +import java.util.Map; + +import org.eclipse.core.runtime.IStatus; + +public interface IPathmapManager2 extends IPathmapManager { + /** + * Adds a map of file path variables (not folders). + * + * @param settings A map from variables(String) to values(String). + * + * @return a status indicating success (OK) or failure (ERROR) to set the + * path variable. In case of error, the status message provides a + * user-friendly explanation of the reason + */ + public IStatus addFilePathVariables(Map settings); + + /** + * Sets the value of a path variable to a file (not a folder). + * + * @param name the path variable name + * @param value the path variable value pointing to a specific file (not a folder) + * + * @return a status indicating success (OK) or failure (ERROR) to set the + * path variable. In case of error, the status message provides a + * user-friendly explanation of the reason + */ + public IStatus addFilePathVariable(String name, String value); + + /** + * Adds a map of folder path variables (not files). + * + * @param settings A map from variables(String) to values(String). + * + * @return a status indicating success (OK) or failure (ERROR) to set the + * path variable. In case of error, the status message provides a + * user-friendly explanation of the reason + */ + public IStatus addFolderPathVariables(Map settings); + + /** + * Sets the value of a path variable to a folder (not a file). + * + * @param name the path variable name + * @param value the path variable value pointing to a specific folder (not a file) + * + * @return a status indicating success (OK) or failure (ERROR) to set the + * path variable. In case of error, the status message provides a + * user-friendly explanation of the reason + */ + public IStatus addFolderPathVariable(String name, String value); +}