Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 158766 Details for
Bug 302152
New path variable created unexpectedly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Implementation Patch
patch.txt (text/plain), 41.38 KB, created by
Serge Beauchamp
on 2010-02-10 14:42:51 EST
(
hide
)
Description:
Implementation Patch
Filename:
MIME Type:
Creator:
Serge Beauchamp
Created:
2010-02-10 14:42:51 EST
Size:
41.38 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.resources >Index: src/org/eclipse/core/internal/resources/PathVariableManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/PathVariableManager.java,v >retrieving revision 1.34 >diff -u -r1.34 PathVariableManager.java >--- src/org/eclipse/core/internal/resources/PathVariableManager.java 26 Jan 2010 10:32:41 -0000 1.34 >+++ src/org/eclipse/core/internal/resources/PathVariableManager.java 10 Feb 2010 19:37:32 -0000 >@@ -363,13 +363,13 @@ > } > > /** >- * @see IPathVariableManager#convertToUserEditableFormat(String) >+ * @see IPathVariableManager#convertToUserEditableFormat(String, boolean) > */ >- public String convertToUserEditableFormat(String value) { >- return PathVariableUtil.convertToUserEditableFormatInternal(value); >+ public String convertToUserEditableFormat(String value, boolean locationFormat) { >+ return PathVariableUtil.convertToUserEditableFormatInternal(value, locationFormat); > } > >- public String convertFromUserEditableFormat(String userFormat, IResource resource) { >- return PathVariableUtil.convertFromUserEditableFormatInternal(this, userFormat, resource); >+ public String convertFromUserEditableFormat(String userFormat, boolean locationFormat, IResource resource) { >+ return PathVariableUtil.convertFromUserEditableFormatInternal(this, userFormat, locationFormat, resource); > } > } >Index: src/org/eclipse/core/internal/resources/PathVariableUtil.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/PathVariableUtil.java,v >retrieving revision 1.5 >diff -u -r1.5 PathVariableUtil.java >--- src/org/eclipse/core/internal/resources/PathVariableUtil.java 26 Jan 2010 10:32:42 -0000 1.5 >+++ src/org/eclipse/core/internal/resources/PathVariableUtil.java 10 Feb 2010 19:37:33 -0000 >@@ -10,6 +10,10 @@ > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >+import org.eclipse.core.runtime.IPath; >+ >+import org.eclipse.core.internal.resources.projectvariables.WorkspaceParentLocationVariableResolver; >+ > import java.net.URI; > import java.util.ArrayList; > import java.util.LinkedList; >@@ -90,6 +94,8 @@ > if (variable.equals(WorkspaceLocationVariableResolver.NAME)) > continue; > } >+ if (variable.equals(WorkspaceParentLocationVariableResolver.NAME)) >+ continue; > if (variable.equals(ParentVariableResolver.NAME)) > continue; > // find closest path to the original path >@@ -119,6 +125,8 @@ > if (variable.equals(WorkspaceLocationVariableResolver.NAME)) > continue; > } >+ if (variable.equals(WorkspaceParentLocationVariableResolver.NAME)) >+ continue; > if (variable.equals(ParentVariableResolver.NAME)) > continue; > IPath value = URIUtil.toPath(pathVariableManager.getValue(variable, resource)); >@@ -158,7 +166,7 @@ > return newPath; > } > >- private static IPath makeRelativeToVariable(IPathVariableManager pathVariableManager, IPath originalPath, IResource resource, boolean force, String variableHint, boolean generateMacro) throws CoreException { >+ private static IPath makeRelativeToVariable(IPathVariableManager pathVariableManager, IPath originalPath, IResource resource, boolean force, String variableHint, boolean generateMacro) { > IPath path = convertToProperCase(originalPath); > IPath value = URIUtil.toPath(pathVariableManager.getValue(variableHint, resource)); > value = convertToProperCase(URIUtil.toPath(pathVariableManager.resolveURI(URIUtil.toURI(value), resource))); >@@ -173,57 +181,28 @@ > } > > if (force) { >- // transform "c:/foo/bar/other_child/file.txt" into "${PARENT-1-BAR_CHILD}/other_child/file.txt" >- int matchingFirstSegments = path.matchingFirstSegments(value); >- if (matchingFirstSegments >= 0) { >- String newValue = buildParentPathVariable(variableHint, valueSegmentCount - matchingFirstSegments, generateMacro); >- String originalName; >- if (generateMacro) >- originalName = newValue; >- else { >- originalName = getExistingVariable(newValue, pathVariableManager, resource); >- if (originalName == null) { >- String name; >- if (matchingFirstSegments > 0) >- name = originalPath.segment(matchingFirstSegments - 1); >- else >- name = originalPath.getDevice(); >- if (name == null) >- name = "ROOT"; //$NON-NLS-1$ >- originalName = getUniqueVariableName(name, pathVariableManager, resource); >- pathVariableManager.setValue(originalName, resource, URIUtil.toURI(Path.fromOSString(newValue))); >+ if (devicesAreCompatible(path, value)) { >+ // transform "c:/foo/bar/other_child/file.txt" into "${PARENT-1-BAR_CHILD}/other_child/file.txt" >+ int matchingFirstSegments = path.matchingFirstSegments(value); >+ if (matchingFirstSegments >= 0) { >+ String originalName= buildParentPathVariable(variableHint, valueSegmentCount - matchingFirstSegments, true); >+ IPath tmp = Path.fromOSString(originalName); >+ for (int j = matchingFirstSegments ;j < originalPath.segmentCount(); j++) { >+ tmp = tmp.append(originalPath.segment(j)); > } >+ return tmp; > } >- IPath tmp = Path.fromOSString(originalName); >- for (int j = matchingFirstSegments ;j < originalPath.segmentCount(); j++) { >- tmp = tmp.append(originalPath.segment(j)); >- } >- return tmp; > } > } > return originalPath; > } >- >- private static String getExistingVariable(String newValue, IPathVariableManager pathVariableManager, IResource resource) { >- IPath resolvedNewValue = convertToProperCase(URIUtil.toPath(pathVariableManager.resolveURI(URIUtil.toURI(Path.fromOSString(newValue)), resource))); >- String[] existingVariables = pathVariableManager.getPathVariableNames(resource); >- for (int i = 0; i < existingVariables.length; i++) { >- String variable = existingVariables[i]; >- URI uri = pathVariableManager.getValue(variable, resource); >- if (uri != null) { >- IPath value = URIUtil.toPath(uri); >- if (value != null) { >- if (value.toOSString().equals(newValue)) >- return variable; >- IPath resolvedValue = convertToProperCase(URIUtil.toPath(pathVariableManager.resolveURI(URIUtil.toURI(value), resource))); >- if (resolvedValue.equals(resolvedNewValue)) >- return variable; >- } >- } >- } >- return null; >- } > >+ private static boolean devicesAreCompatible(IPath path, IPath value) { >+ return (path.getDevice() != null && value.getDevice() != null) ? >+ (path.getDevice().equals(value.getDevice())) : >+ (path.getDevice() == value.getDevice()); >+ } >+ > static private IPath convertToProperCase(IPath path) { > if (Platform.getOS().equals(Platform.OS_WIN32)) > return Path.fromPortableString(path.toPortableString().toLowerCase()); >@@ -270,8 +249,10 @@ > return Path.fromOSString(variable).append(relativeSrcValue.removeFirstSegments(1)); > } > >- public static String convertFromUserEditableFormatInternal(IPathVariableManager manager, String userFormat, IResource resource) { >- boolean isAbsolute = (userFormat.length() > 0) && (userFormat.charAt(0) == '/' || userFormat.charAt(0) == '\\'); >+ public static String convertFromUserEditableFormatInternal(IPathVariableManager manager, String userFormat, boolean locationFormat, IResource resource) { >+ char pathPrefix = 0; >+ if ((userFormat.length() > 0) && (userFormat.charAt(0) == '/' || userFormat.charAt(0) == '\\')) >+ pathPrefix = userFormat.charAt(0); > String components[] = splitPathComponents(userFormat); > for (int i = 0; i < components.length; i++) { > if (components[i] == null) >@@ -297,41 +278,51 @@ > if (components[j] == null) > continue; > String variable = extractVariable(components[j]); >+ >+ boolean hasVariableWithMacroSyntax = true; >+ if (variable.length() == 0 && (locationFormat && j == 0)) { >+ variable = components[j]; >+ hasVariableWithMacroSyntax = false; >+ } >+ > try { > if (variable.length() > 0) { >- int indexOfVariable = components[j].indexOf(variable) - "${".length(); //$NON-NLS-1$ >- String prefix = components[j].substring(0, indexOfVariable); >- String suffix = components[j].substring(indexOfVariable + "${".length() + variable.length() + "}".length()); //$NON-NLS-1$ //$NON-NLS-2$ >- if (suffix.length() != 0) { >- // Create an intermediate variable, since a syntax of "${VAR}foo/../" >- // can't be converted to a "${PARENT-1-VAR}foo" variable. >- // So instead, an intermediate variable "VARFOO" will be created of value >- // "${VAR}foo", and the string "${PARENT-1-VARFOO}" will be inserted. >- String intermediateVariable = PathVariableUtil.getValidVariableName(variable + suffix); >- IPath intermediateValue = Path.fromPortableString(components[j]); >- int intermediateVariableIndex = 1; >- String originalIntermediateVariableName = intermediateVariable; >- while (manager.isDefined(intermediateVariable, resource)) { >- IPath tmpValue = URIUtil.toPath(manager.getValue(intermediateVariable, resource)); >- if (tmpValue.equals(intermediateValue)) >- break; >- intermediateVariable = originalIntermediateVariableName + intermediateVariableIndex; >+ String prefix = new String(); >+ if (hasVariableWithMacroSyntax) { >+ int indexOfVariable = components[j].indexOf(variable) - "${".length(); //$NON-NLS-1$ >+ prefix = components[j].substring(0, indexOfVariable); >+ String suffix = components[j].substring(indexOfVariable + "${".length() + variable.length() + "}".length()); //$NON-NLS-1$ //$NON-NLS-2$ >+ if (suffix.length() != 0) { >+ // Create an intermediate variable, since a syntax of "${VAR}foo/../" >+ // can't be converted to a "${PARENT-1-VAR}foo" variable. >+ // So instead, an intermediate variable "VARFOO" will be created of value >+ // "${VAR}foo", and the string "${PARENT-1-VARFOO}" will be inserted. >+ String intermediateVariable = PathVariableUtil.getValidVariableName(variable + suffix); >+ IPath intermediateValue = Path.fromPortableString(components[j]); >+ int intermediateVariableIndex = 1; >+ String originalIntermediateVariableName = intermediateVariable; >+ while (manager.isDefined(intermediateVariable, resource)) { >+ IPath tmpValue = URIUtil.toPath(manager.getValue(intermediateVariable, resource)); >+ if (tmpValue.equals(intermediateValue)) >+ break; >+ intermediateVariable = originalIntermediateVariableName + intermediateVariableIndex; >+ } >+ if (!manager.isDefined(intermediateVariable, resource)) >+ manager.setValue(intermediateVariable, resource, URIUtil.toURI(intermediateValue)); >+ variable = intermediateVariable; >+ prefix = new String(); > } >- if (!manager.isDefined(intermediateVariable, resource)) >- manager.setValue(intermediateVariable, resource, URIUtil.toURI(intermediateValue)); >- variable = intermediateVariable; >- prefix = new String(); > } > String newVariable = variable; > if (PathVariableUtil.isParentVariable(variable)) { > String argument = PathVariableUtil.getParentVariableArgument(variable); > int count = PathVariableUtil.getParentVariableCount(variable); > if (argument != null && count != -1) >- newVariable = PathVariableUtil.buildParentPathVariable(argument, count + parentCount, false); >+ newVariable = PathVariableUtil.buildParentPathVariable(argument, count + parentCount, locationFormat); > else >- newVariable = PathVariableUtil.buildParentPathVariable(variable, parentCount, false); >+ newVariable = PathVariableUtil.buildParentPathVariable(variable, parentCount, locationFormat); > } else >- newVariable = PathVariableUtil.buildParentPathVariable(variable, parentCount, false); >+ newVariable = PathVariableUtil.buildParentPathVariable(variable, parentCount, locationFormat); > components[j] = prefix + newVariable; > break; > } >@@ -346,12 +337,12 @@ > } > } > StringBuffer buffer = new StringBuffer(); >- if (isAbsolute) >- buffer.append('/'); >+ if (pathPrefix != 0) >+ buffer.append(pathPrefix); > for (int i = 0; i < components.length; i++) { > if (components[i] != null) { > if (i > 0) >- buffer.append('/'); >+ buffer.append(java.io.File.separator); > buffer.append(components[i]); > } > } >@@ -379,26 +370,41 @@ > return (String[]) list.toArray(new String[0]); > } > >- public static String convertToUserEditableFormatInternal(String value) { >+ public static String convertToUserEditableFormatInternal(String value, boolean locationFormat) { > StringBuffer buffer = new StringBuffer(); >- String components[] = splitVariablesAndContent(value); >- for (int i = 0; i < components.length; i++) { >- String variable = extractVariable(components[i]); >- if (PathVariableUtil.isParentVariable(variable)) { >- String argument = PathVariableUtil.getParentVariableArgument(variable); >- int count = PathVariableUtil.getParentVariableCount(variable); >- if (argument != null && count != -1) { >- buffer.append(PathVariableUtil.buildVariableMacro(Path.fromOSString(argument))); >- for (int j = 0; j < count; j++) { >- buffer.append("/.."); //$NON-NLS-1$ >- } >- } else >- buffer.append(components[i]); >- } else >- buffer.append(components[i]); >+ if (locationFormat) { >+ IPath path = Path.fromOSString(value); >+ if (path.isAbsolute()) >+ return path.toOSString(); >+ int index = value.indexOf(java.io.File.separator); >+ String variable = index != -1 ? value.substring(0, index): value; >+ convertVariableToUserFormat(buffer, variable, variable, false); >+ if (index != -1) >+ buffer.append(value.substring(index)); >+ } else { >+ String components[] = splitVariablesAndContent(value); >+ for (int i = 0; i < components.length; i++) { >+ String variable = extractVariable(components[i]); >+ convertVariableToUserFormat(buffer, components[i], variable, true); >+ } > } > return buffer.toString(); > } >+ >+ private static void convertVariableToUserFormat(StringBuffer buffer, String component, String variable, boolean generateMacro) { >+ if (PathVariableUtil.isParentVariable(variable)) { >+ String argument = PathVariableUtil.getParentVariableArgument(variable); >+ int count = PathVariableUtil.getParentVariableCount(variable); >+ if (argument != null && count != -1) { >+ buffer.append(generateMacro? PathVariableUtil.buildVariableMacro(Path.fromOSString(argument)):Path.fromOSString(argument)); >+ for (int j = 0; j < count; j++) { >+ buffer.append(java.io.File.separator + ".."); //$NON-NLS-1$ >+ } >+ } else >+ buffer.append(component); >+ } else >+ buffer.append(component); >+ } > /* > * Splits a value (returned by this.getValue(variable) in an array of > * string, where the array is divided between the value content and the >Index: src/org/eclipse/core/internal/resources/ProjectPathVariableManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectPathVariableManager.java,v >retrieving revision 1.4 >diff -u -r1.4 ProjectPathVariableManager.java >--- src/org/eclipse/core/internal/resources/ProjectPathVariableManager.java 26 Jan 2010 14:59:20 -0000 1.4 >+++ src/org/eclipse/core/internal/resources/ProjectPathVariableManager.java 10 Feb 2010 19:37:33 -0000 >@@ -177,7 +177,16 @@ > } catch (CoreException e) { > return false; > } >- return getWorkspaceManager().isDefined(varName); >+ boolean value = getWorkspaceManager().isDefined(varName); >+ if (!value) { >+ // this is to handle variables with encoded arguments >+ int index = varName.indexOf('-'); >+ if (index != -1) { >+ String newVarName = varName.substring(0, index); >+ value = isDefined(newVarName); >+ } >+ } >+ return value; > } > > /** >@@ -432,14 +441,14 @@ > } > > /** >- * @see IPathVariableManager#convertToUserEditableFormat(String) >+ * @see IPathVariableManager#convertToUserEditableFormat(String, boolean) > */ >- public String convertToUserEditableFormat(String value) { >- return PathVariableUtil.convertToUserEditableFormatInternal(value); >+ public String convertToUserEditableFormat(String value, boolean locationFormat) { >+ return PathVariableUtil.convertToUserEditableFormatInternal(value, locationFormat); > } > >- public String convertFromUserEditableFormat(String userFormat, IResource resource) { >- return PathVariableUtil.convertFromUserEditableFormatInternal(this, userFormat, resource); >+ public String convertFromUserEditableFormat(String userFormat, boolean locationFormat, IResource resource) { >+ return PathVariableUtil.convertFromUserEditableFormatInternal(this, userFormat, locationFormat, resource); > } > > public void addChangeListener(IPathVariableChangeListener listener) { >Index: src/org/eclipse/core/internal/resources/Workspace.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java,v >retrieving revision 1.229 >diff -u -r1.229 Workspace.java >--- src/org/eclipse/core/internal/resources/Workspace.java 26 Jan 2010 10:32:42 -0000 1.229 >+++ src/org/eclipse/core/internal/resources/Workspace.java 10 Feb 2010 19:37:35 -0000 >@@ -13,6 +13,8 @@ > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >+import org.eclipse.core.internal.resources.projectvariables.WorkspaceParentLocationVariableResolver; >+ > import java.io.IOException; > import java.io.InputStream; > import java.net.URI; >@@ -877,6 +879,8 @@ > for (int i = 0; i < variables.length; i++) { > if (variables[i].equals(WorkspaceLocationVariableResolver.NAME)) > continue; >+ if (variables[i].equals(WorkspaceParentLocationVariableResolver.NAME)) >+ continue; > if (variables[i].equals(ParentVariableResolver.NAME)) > continue; > IPath resolveDestVariable = URIUtil.toPath(destPathVariableManager >Index: src/org/eclipse/core/resources/IPathVariableManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/resources/IPathVariableManager.java,v >retrieving revision 1.21 >diff -u -r1.21 IPathVariableManager.java >--- src/org/eclipse/core/resources/IPathVariableManager.java 26 Jan 2010 10:32:42 -0000 1.21 >+++ src/org/eclipse/core/resources/IPathVariableManager.java 10 Feb 2010 19:37:35 -0000 >@@ -369,25 +369,27 @@ > > /** > * Converts the internal format of the linked resource location if the PARENT >- * variables is used. For example, if the value is "${PARENT-2-VAR}/foo", the >- * converted result is "${VAR}/../../foo". >- * @param value >+ * variables is used. For example, if the value is "${PARENT-2-VAR}\foo", the >+ * converted result is "${VAR}\..\..\foo". >+ * @param value the value encoded using OS string (as returned from Path.toOSString()) >+ * @param locationFormat indicates whether the value contains a string that is stored in the linked resource location rather than in the path variable value > * @return the converted path variable value > * @since 3.6 > */ >- public String convertToUserEditableFormat(String value); >+ public String convertToUserEditableFormat(String value, boolean locationFormat); > > /** > * Converts the user editable format to the internal format. >- * For example, if the value is "${VAR}/../../foo", the >- * converted result is "${PARENT-2-VAR}/foo". >+ * For example, if the value is "${VAR}\..\..\foo", the >+ * converted result is "${PARENT-2-VAR}\foo". > * If the string is not directly convertible to a ${PARENT-COUNT-VAR} >- * syntax (for example, the editable string "${FOO}bar/../../"), intermediate >+ * syntax (for example, the editable string "${FOO}bar\..\..\"), intermediate > * path variables will be created. >- * @param userFormat The user editable string >+ * @param value the value encoded using OS string (as returned from Path.toOSString()) >+ * @param locationFormat indicates whether the value contains a string that is stored in the linked resource location rather than in the path variable value > * @param resource the resource for which this variable is resolved > * @return the converted path variable value > * @since 3.6 > */ >- public String convertFromUserEditableFormat(String userFormat, IResource resource); >+ public String convertFromUserEditableFormat(String value, boolean locationFormat, IResource resource); > } >#P org.eclipse.core.tests.resources >Index: src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java,v >retrieving revision 1.27 >diff -u -r1.27 LinkedResourceWithPathVariableTest.java >--- src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java 27 Jan 2010 22:47:55 -0000 1.27 >+++ src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java 10 Feb 2010 19:37:41 -0000 >@@ -431,9 +431,7 @@ > } > assertExistsInWorkspace("3,1", newFile); > assertTrue("3,2", !newFile.getLocation().equals(newFile.getRawLocation())); >- assertTrue("3,3", newFile.getRawLocation().equals(variableBasedLocation)); >- assertTrue("3,4", newFile.getRawLocation().equals(variableBasedLocation)); >- assertEquals("3,5", newFile.getLocation(), resolvedPath); >+ assertEquals("3,3", newFile.getLocation(), resolvedPath); > } > > private IPath convertToRelative(IPathVariableManager manager, IPath path, IResource res, boolean force, String variableHint) throws CoreException { >@@ -1355,107 +1353,58 @@ > public void testConvertToUserEditableFormat() { > IPathVariableManager pathVariableManager = existingProject.getPathVariableManager(); > >- String result = pathVariableManager.convertToUserEditableFormat("C:\\foo\\bar"); >- assertEquals("1.0", "C:\\foo\\bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("C:/foo/bar"); >- assertEquals("1.1", "C:/foo/bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("VAR/foo/bar"); >- assertEquals("1.2", "VAR/foo/bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${VAR}/foo/bar"); >- assertEquals("1.3", "${VAR}/foo/bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${VAR}/../foo/bar"); >- assertEquals("1.4", "${VAR}/../foo/bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${PARENT-1-VAR}/foo/bar"); >- assertEquals("1.5", "${VAR}/../foo/bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${PARENT-0-VAR}/foo/bar"); >- assertEquals("1.6", "${VAR}/foo/bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${PARENT-VAR}/foo/bar"); >- assertEquals("1.7", "${PARENT-VAR}/foo/bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${PARENT-2}/foo/bar"); >- assertEquals("1.8", "${PARENT-2}/foo/bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${PARENT}/foo/bar"); >- assertEquals("1.9", "${PARENT}/foo/bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${PARENT-2-VAR}/foo/bar"); >- assertEquals("2.0", "${VAR}/../../foo/bar", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${PARENT-2-VAR}/foo/${PARENT-4-BAR}"); >- assertEquals("2.1", "${VAR}/../../foo/${BAR}/../../../..", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${PARENT-2-VAR}/foo${PARENT-4-BAR}"); >- assertEquals("2.2", "${VAR}/../../foo${BAR}/../../../..", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${PARENT-2-VAR}/${PARENT-4-BAR}/foo"); >- assertEquals("2.3", "${VAR}/../../${BAR}/../../../../foo", result); >- >- result = pathVariableManager.convertToUserEditableFormat("${PARENT-2-VAR}/f${PARENT-4-BAR}/oo"); >- assertEquals("2.4", "${VAR}/../../f${BAR}/../../../../oo", result); >- >- result = pathVariableManager.convertToUserEditableFormat("/foo/bar"); >- assertEquals("2.5", "/foo/bar", result); >+ String[][] table = { // format: {internal-format, user-editable-format [, internal-format-reconverted] >+ {"C:\\foo\\bar", "C:\\foo\\bar"}, // >+ {"C:/foo/bar", "C:/foo/bar"}, // >+ {"VAR/foo/bar", "VAR/foo/bar"}, // >+ {"${VAR}/foo/bar", "${VAR}/foo/bar"}, // >+ {"${VAR}/../foo/bar", "${VAR}/../foo/bar", "${PARENT-1-VAR}/foo/bar"}, // >+ {"${PARENT-1-VAR}/foo/bar", "${VAR}/../foo/bar"}, // >+ {"${PARENT-0-VAR}/foo/bar", "${VAR}/foo/bar", "${VAR}/foo/bar"}, // >+ {"${PARENT-VAR}/foo/bar", "${PARENT-VAR}/foo/bar"}, // >+ {"${PARENT-2}/foo/bar", "${PARENT-2}/foo/bar"}, // >+ {"${PARENT}/foo/bar", "${PARENT}/foo/bar"}, // >+ {"${PARENT-2-VAR}/foo/bar", "${VAR}/../../foo/bar"}, // >+ {"${PARENT-2-VAR}/foo/${PARENT-4-BAR}", "${VAR}/../../foo/${BAR}/../../../.."}, // >+ {"${PARENT-2-VAR}/foo${PARENT-4-BAR}", "${VAR}/../../foo${BAR}/../../../.."}, // >+ {"${PARENT-2-VAR}/${PARENT-4-BAR}/foo", "${VAR}/../../${BAR}/../../../../foo"}, // >+ {"${PARENT-2-VAR}/f${PARENT-4-BAR}/oo", "${VAR}/../../f${BAR}/../../../../oo"} // >+ }; >+ >+ for (int i = 0; i < table.length; i++) { >+ String result = pathVariableManager.convertToUserEditableFormat(toOS(table[i][0]), false); >+ assertEquals("1." + i, toOS(table[i][1]), result); >+ String original = pathVariableManager.convertFromUserEditableFormat(result, false, existingProject); >+ assertEquals("2." + i, toOS(table[i].length == 2 ? table[i][0] : table[i][2]), original); >+ } >+ >+ String[][] tableLocationFormat = { // format: {internal-format, user-editable-format [, internal-format-reconverted] >+ {"C:\\foo\\bar", "C:\\foo\\bar"}, // >+ {"C:/foo/bar", "C:/foo/bar"}, // >+ {"VAR/foo/bar", "VAR/foo/bar"}, // >+ {"${VAR}/../foo/bar", "${VAR}/../foo/bar", "PARENT-1-VAR/foo/bar"}, // >+ {"PARENT-1-VAR/foo/bar", "VAR/../foo/bar"}, // >+ {"PARENT-0-VAR/foo/bar", "VAR/foo/bar", "VAR/foo/bar"}, // >+ {"PARENT-VAR/foo/bar", "PARENT-VAR/foo/bar"}, // >+ {"PARENT-2/foo/bar", "PARENT-2/foo/bar"}, // >+ {"PARENT/foo/bar", "PARENT/foo/bar"}, // >+ {"PARENT-2-VAR/foo/bar", "VAR/../../foo/bar"}, // >+ {"PARENT-2-VAR/foo/PARENT-4-BAR", "VAR/../../foo/PARENT-4-BAR"}, // >+ {"PARENT-2-VAR/fooPARENT-4-BAR", "VAR/../../fooPARENT-4-BAR"}, // >+ {"PARENT-2-VAR/PARENT-4-BAR/foo", "VAR/../../PARENT-4-BAR/foo"}, // >+ {"PARENT-2-VAR/fPARENT-4-BAR/oo", "VAR/../../fPARENT-4-BAR/oo"}, // >+ {"/foo/bar", "/foo/bar"}, // >+ }; >+ >+ for (int i = 0; i < table.length; i++) { >+ String result = pathVariableManager.convertToUserEditableFormat(toOS(tableLocationFormat[i][0]), true); >+ assertEquals("3." + i, toOS(tableLocationFormat[i][1]), result); >+ String original = pathVariableManager.convertFromUserEditableFormat(result, true, existingProject); >+ assertEquals("4." + i, toOS(tableLocationFormat[i].length == 2 ? tableLocationFormat[i][0] : tableLocationFormat[i][2]), original); >+ } > } > >- public void testConvertFromUserEditableFormat() { >- IPathVariableManager manager = existingProject.getPathVariableManager(); >- >- String result = manager.convertFromUserEditableFormat("C:\\foo\\bar", existingProject); >- assertEquals("1.0", "C:/foo/bar", result); >- >- result = manager.convertFromUserEditableFormat("C:/foo/bar", existingProject); >- assertEquals("1.1", "C:/foo/bar", result); >- >- result = manager.convertFromUserEditableFormat("VAR/foo/bar", existingProject); >- assertEquals("1.2", "VAR/foo/bar", result); >- >- result = manager.convertFromUserEditableFormat("${VAR}/foo/bar", existingProject); >- assertEquals("1.3", "${VAR}/foo/bar", result); >- >- result = manager.convertFromUserEditableFormat("${VAR}/../foo/bar", existingProject); >- assertEquals("1.4", "${PARENT-1-VAR}/foo/bar", result); >- >- result = manager.convertFromUserEditableFormat("${PARENT-1-VAR}/foo/bar", existingProject); >- assertEquals("1.5", "${PARENT-1-VAR}/foo/bar", result); >- >- result = manager.convertFromUserEditableFormat("${PARENT-VAR}/foo/bar", existingProject); >- assertEquals("1.6", "${PARENT-VAR}/foo/bar", result); >- >- result = manager.convertFromUserEditableFormat("${PARENT-2}/foo/bar", existingProject); >- assertEquals("1.7", "${PARENT-2}/foo/bar", result); >- >- result = manager.convertFromUserEditableFormat("${PARENT}/foo/bar", existingProject); >- assertEquals("1.8", "${PARENT}/foo/bar", result); >- >- result = manager.convertFromUserEditableFormat("${VAR}/../../foo/bar", existingProject); >- assertEquals("1.9", "${PARENT-2-VAR}/foo/bar", result); >- >- result = manager.convertFromUserEditableFormat("${VAR}/../../foo/${BAR}/../../../../", existingProject); >- assertEquals("2.0", "${PARENT-2-VAR}/foo/${PARENT-4-BAR}", result); >- >- result = manager.convertFromUserEditableFormat("${VAR}/../../foo${BAR}/../../../../", existingProject); >- assertEquals("2.1", "${PARENT-2-VAR}/foo${PARENT-4-BAR}", result); >- >- result = manager.convertFromUserEditableFormat("${VAR}/../../${BAR}foo/../../../../", existingProject); >- assertEquals("2.2", "${PARENT-2-VAR}/${PARENT-4-BARfoo}", result); >- >- IPath intermeiateValue = manager.getValue("BARfoo"); >- assertEquals("2.3", "${BAR}foo", intermeiateValue.toPortableString()); >- >- result = manager.convertFromUserEditableFormat("${VAR}/../../f${BAR}oo/../../../../", existingProject); >- assertEquals("2.4", "${PARENT-2-VAR}/${PARENT-4-BARoo}", result); >- >- intermeiateValue = manager.getValue("BARoo"); >- assertEquals("2.5", "f${BAR}oo", intermeiateValue.toPortableString()); >- >- result = manager.convertFromUserEditableFormat("/foo/bar", existingProject); >- assertEquals("2.6", "/foo/bar", result); >+ private String toOS(String path) { >+ return path.replace("/", File.separator); > } > } >#P org.eclipse.ui.ide >Index: src/org/eclipse/ui/internal/ide/dialogs/IDEResourceInfoUtils.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEResourceInfoUtils.java,v >retrieving revision 1.21 >diff -u -r1.21 IDEResourceInfoUtils.java >--- src/org/eclipse/ui/internal/ide/dialogs/IDEResourceInfoUtils.java 20 Jan 2010 17:02:29 -0000 1.21 >+++ src/org/eclipse/ui/internal/ide/dialogs/IDEResourceInfoUtils.java 10 Feb 2010 19:37:45 -0000 >@@ -255,7 +255,8 @@ > } > } > if (isLinked && isPathVariable) { >- return resource.getRawLocationURI().toString(); >+ String tmp = resource.getRawLocationURI().toString(); >+ return resource.getProject().getPathVariableManager().convertToUserEditableFormat(tmp, true); > } > if (store != null) { > return store.toString(); >Index: src/org/eclipse/ui/internal/ide/dialogs/LinkedResourceEditor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/LinkedResourceEditor.java,v >retrieving revision 1.3 >diff -u -r1.3 LinkedResourceEditor.java >--- src/org/eclipse/ui/internal/ide/dialogs/LinkedResourceEditor.java 4 Feb 2010 13:15:02 -0000 1.3 >+++ src/org/eclipse/ui/internal/ide/dialogs/LinkedResourceEditor.java 10 Feb 2010 19:37:46 -0000 >@@ -275,7 +275,7 @@ > else { > IPath rawLocation = ((IResource) obj).getRawLocation(); > if (rawLocation != null) >- return rawLocation.toPortableString(); >+ return rawLocation.toOSString(); > } > } else if ((obj instanceof String) && index == 0) > return (String) obj; >@@ -522,8 +522,8 @@ > res.getProjectRelativePath() > .toPortableString(), > res.getRawLocation() >- .toPortableString(), >- location.toPortableString() })); >+ .toOSString(), >+ location.toOSString() })); > } catch (CoreException e) { > report > .add(NLS >@@ -642,9 +642,9 @@ > res > .getProjectRelativePath() > .toPortableString(), >- location.toPortableString(), >+ location.toOSString(), > newLocation >- .toPortableString() })); >+ .toOSString() })); > } > } catch (CoreException e) { > remaining.add(res); >@@ -667,7 +667,7 @@ > for (int i = 0; i < variables.length; i++) { > IPath resolvePath = URIUtil.toPath(fProject > .getPathVariableManager().resolveURI( >- URIUtil.toURI(Path.fromPortableString(variables[i])), res)); >+ URIUtil.toURI(Path.fromOSString(variables[i])), res)); > if (resolvePath > .isPrefixOf(convertToProperCase(location))) { > int count = location >@@ -691,9 +691,9 @@ > res > .getProjectRelativePath() > .toPortableString(), >- location.toPortableString(), >+ location.toOSString(), > newLocation >- .toPortableString() })); >+ .toOSString() })); > } catch (CoreException e) { > variable = -1; > } >@@ -737,7 +737,7 @@ > .bind( > IDEWorkbenchMessages.LinkedResourceEditor_unableToCreateVariable, > variableName, commonPath >- .toPortableString())); >+ .toOSString())); > } > it = resources.iterator(); > while (it.hasNext()) { >@@ -758,9 +758,9 @@ > .getProjectRelativePath() > .toPortableString(), > location >- .toPortableString(), >+ .toOSString(), > newLocation >- .toPortableString() })); >+ .toOSString() })); > } catch (CoreException e) { > report > .add(NLS >@@ -808,8 +808,8 @@ > new Object[] { > res.getProjectRelativePath() > .toPortableString(), >- location.toPortableString(), >- newLocation.toPortableString() })); >+ location.toOSString(), >+ newLocation.toOSString() })); > } catch (CoreException e) { > report > .add(NLS >@@ -827,6 +827,13 @@ > > private String getSuitablePathVariable(IPath commonPath) { > String variableName = commonPath.lastSegment(); >+ if (variableName == null) { >+ variableName = commonPath.getDevice(); >+ if (variableName == null) >+ variableName = "ROOT"; //$NON-NLS-1$ >+ else >+ variableName = variableName.substring(0, variableName.length() -1); // remove the tailing ':' >+ } > StringBuffer buf = new StringBuffer(); > for (int i = 0; i < variableName.length(); i++) { > char c = variableName.charAt(i); >Index: src/org/eclipse/ui/internal/ide/dialogs/PathVariableDialog.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/PathVariableDialog.java,v >retrieving revision 1.22 >diff -u -r1.22 PathVariableDialog.java >--- src/org/eclipse/ui/internal/ide/dialogs/PathVariableDialog.java 1 Feb 2010 14:50:39 -0000 1.22 >+++ src/org/eclipse/ui/internal/ide/dialogs/PathVariableDialog.java 10 Feb 2010 19:37:46 -0000 >@@ -382,10 +382,10 @@ > if (currentResource != null) { > IPathVariableManager pathVariableManager2 = currentResource.getProject().getPathVariableManager(); > String[] variables = pathVariableManager2.getPathVariableNames(currentResource); >- String internalFormat = pathVariableManager2.convertFromUserEditableFormat(variableValue, currentResource); >- URI uri = URIUtil.toURI(Path.fromPortableString(internalFormat)); >+ String internalFormat = pathVariableManager2.convertFromUserEditableFormat(variableValue, operationMode == EDIT_LINK_LOCATION, currentResource); >+ URI uri = URIUtil.toURI(Path.fromOSString(internalFormat)); > URI resolvedURI = pathVariableManager2.resolveURI(uri, currentResource); >- String resolveValue = URIUtil.toPath(resolvedURI).toPortableString(); >+ String resolveValue = URIUtil.toPath(resolvedURI).toOSString(); > // Delete intermediate variables that might have been created as > // as a side effect of converting arbitrary relative paths to an internal string. > String[] newVariables = pathVariableManager2.getPathVariableNames(currentResource); >@@ -474,10 +474,10 @@ > String[] variableNames = (String[]) dialog.getResult(); > if (variableNames != null && variableNames.length == 1) { > String newValue = variableNames[0]; >- IPath path = Path.fromPortableString(newValue); >+ IPath path = Path.fromOSString(newValue); > if (operationMode != EDIT_LINK_LOCATION && currentResource != null && !path.isAbsolute() && path.segmentCount() > 0) { > path = buildVariableMacro(path); >- newValue = path.toPortableString(); >+ newValue = path.toOSString(); > } > variableValue = newValue; > variableValueField.setText(newValue); >@@ -593,7 +593,7 @@ > // contain macros such as "${foo}\etc" > allowFinish = true; > String resolvedValue = getVariableResolvedValue(); >- IPath resolvedPath = Path.fromPortableString(resolvedValue); >+ IPath resolvedPath = Path.fromOSString(resolvedValue); > if (!IDEResourceInfoUtils.exists(resolvedPath.toOSString())) { > // the path does not exist (warning) > message = IDEWorkbenchMessages.PathVariableDialog_pathDoesNotExistMessage; >@@ -655,7 +655,7 @@ > */ > public String getVariableValue() { > if (currentResource != null) { >- String internalFormat = getPathVariableManager().convertFromUserEditableFormat(variableValue, currentResource); >+ String internalFormat = getPathVariableManager().convertFromUserEditableFormat(variableValue, operationMode == EDIT_LINK_LOCATION, currentResource); > return internalFormat; > } > return variableValue; >@@ -677,7 +677,7 @@ > * @param variable the new variable value > */ > public void setVariableValue(String variable) { >- String userEditableString = getPathVariableManager().convertToUserEditableFormat(variable); >+ String userEditableString = getPathVariableManager().convertToUserEditableFormat(variable, operationMode == EDIT_LINK_LOCATION); > variableValue = userEditableString; > } > >@@ -692,7 +692,7 @@ > * @param location > */ > public void setLinkLocation(IPath location) { >- String userEditableString = getPathVariableManager().convertToUserEditableFormat(location.toPortableString()); >+ String userEditableString = getPathVariableManager().convertToUserEditableFormat(location.toOSString(), operationMode == EDIT_LINK_LOCATION); > variableValue = userEditableString; > } > >Index: src/org/eclipse/ui/internal/ide/dialogs/PathVariablesGroup.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/PathVariablesGroup.java,v >retrieving revision 1.13 >diff -u -r1.13 PathVariablesGroup.java >--- src/org/eclipse/ui/internal/ide/dialogs/PathVariablesGroup.java 4 Feb 2010 13:54:37 -0000 1.13 >+++ src/org/eclipse/ui/internal/ide/dialogs/PathVariablesGroup.java 10 Feb 2010 19:37:46 -0000 >@@ -571,7 +571,7 @@ > * @return the converted value > */ > private String removeParentVariable(String value) { >- return pathVariableManager.convertToUserEditableFormat(value); >+ return pathVariableManager.convertToUserEditableFormat(value, false); > } > > /** >Index: src/org/eclipse/ui/internal/ide/dialogs/ResourceInfoPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/ResourceInfoPage.java,v >retrieving revision 1.42 >diff -u -r1.42 ResourceInfoPage.java >--- src/org/eclipse/ui/internal/ide/dialogs/ResourceInfoPage.java 25 Jan 2010 16:12:12 -0000 1.42 >+++ src/org/eclipse/ui/internal/ide/dialogs/ResourceInfoPage.java 10 Feb 2010 19:37:47 -0000 >@@ -286,7 +286,8 @@ > protected void editLinkLocation() { > IResource resource = (IResource) getElement().getAdapter( > IResource.class); >- IPath location = Path.fromPortableString(locationValue.getText()); >+ String locationFormat = resource.getProject().getPathVariableManager().convertFromUserEditableFormat(locationValue.getText(), true, resource); >+ IPath location = Path.fromOSString(locationFormat); > > PathVariableDialog dialog = new PathVariableDialog(getShell(), > PathVariableDialog.EDIT_LINK_LOCATION, resource.getType(), >@@ -306,7 +307,8 @@ > IResource resource = (IResource) getElement().getAdapter( > IResource.class); > >- locationValue.setText(newResourceLocation.toPortableString()); >+ String userEditableFormat = resource.getProject().getPathVariableManager().convertToUserEditableFormat(newResourceLocation.toOSString(), true); >+ locationValue.setText(userEditableFormat); > > URI resolvedURI = resource.getProject().getPathVariableManager() > .resolveURI(URIUtil.toURI(newResourceLocation), resource);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 302152
:
158583
|
158766
|
158773