Skip to content

Commit

Permalink
Fixed absolute path calculation for workspace resources
Browse files Browse the repository at this point in the history
* Previously it was assumed that projects are physically stored below
  the workspace directory. When projects are located e.g. in a git
  repository and imported into the workspace this assumption does not
  hold. This was fixed with a proper lookup.

* Changed API of the convertToAbsolutePath method to take a string
  instead of a file, since all callers had to create a file from a
  string anyway.

Signed-off-by: Max Bureck <[email protected]>
  • Loading branch information
Boereck committed Oct 15, 2018
1 parent dc9a46a commit 38a8259
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IPr
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
String workingDirectoryString = RustLaunchDelegateTools.performVariableSubstitution(
configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, "").trim()); //$NON-NLS-1$
File workingDirectory = RustLaunchDelegateTools.convertToAbsolutePath(new File(workingDirectoryString));
File workingDirectory = RustLaunchDelegateTools.convertToAbsolutePath(workingDirectoryString);
if (workingDirectoryString.isEmpty() || !workingDirectory.exists() || !workingDirectory.isDirectory()) {
workingDirectory = project.getLocation().toFile();
}
Expand Down Expand Up @@ -150,13 +150,13 @@ public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
String workingDirectoryString = RustLaunchDelegateTools.performVariableSubstitution(
configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, "").trim()); //$NON-NLS-1$
File workingDirectory = RustLaunchDelegateTools.convertToAbsolutePath(new File(workingDirectoryString));
File workingDirectory = RustLaunchDelegateTools.convertToAbsolutePath(workingDirectoryString);
if (workingDirectoryString.isEmpty() || !workingDirectory.exists() || !workingDirectory.isDirectory()) {
workingDirectory = project.getLocation().toFile();
}
String executableString = RustLaunchDelegateTools.performVariableSubstitution(
configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "").trim()); //$NON-NLS-1$
File executable = RustLaunchDelegateTools.convertToAbsolutePath(new File(executableString));
File executable = RustLaunchDelegateTools.convertToAbsolutePath(executableString);

ILaunchConfigurationWorkingCopy wc = configuration.copy(configuration.getName() + "[Variables Parsed]") //$NON-NLS-1$
.getWorkingCopy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,19 @@ public static IResource resourceFromEditor(IEditorPart editor) {
return input.getAdapter(IResource.class);
}

public static File convertToAbsolutePath(File file) {
/**
* Converts the given relative path to a workspace resource and converts it to a
* {@code File} with the absolute path on the file system.
*
* @param path to a workspace resource
* @return File object of the given {@code path}, with an absolute path on the
* file system
*/
public static File convertToAbsolutePath(String path) {
final File file = new File(path);
if (file.isAbsolute())
return file;
return ResourcesPlugin.getWorkspace().getRoot().getLocation().append(file.getPath()).toFile();
return ResourcesPlugin.getWorkspace().getRoot().findMember(file.getPath()).getRawLocation().toFile();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
String arguments = configuration.getAttribute(RustLaunchDelegateTools.ARGUMENTS_ATTRIBUTE, "").trim(); //$NON-NLS-1$
String workingDirectoryString = RustLaunchDelegateTools.performVariableSubstitution(
configuration.getAttribute(RustLaunchDelegateTools.WORKING_DIRECTORY_ATTRIBUTE, "").trim()); //$NON-NLS-1$
File workingDirectory = RustLaunchDelegateTools.convertToAbsolutePath(new File(workingDirectoryString));
File workingDirectory = RustLaunchDelegateTools.convertToAbsolutePath(workingDirectoryString);
if (workingDirectoryString.isEmpty() || !workingDirectory.exists() || !workingDirectory.isDirectory()) {
workingDirectory = project.getLocation().toFile();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
String arguments = configuration.getAttribute(RustLaunchDelegateTools.ARGUMENTS_ATTRIBUTE, "").trim(); //$NON-NLS-1$
String workingDirectoryString = RustLaunchDelegateTools.performVariableSubstitution(
configuration.getAttribute(RustLaunchDelegateTools.WORKING_DIRECTORY_ATTRIBUTE, "").trim()); //$NON-NLS-1$
File workingDirectory = RustLaunchDelegateTools.convertToAbsolutePath(new File(workingDirectoryString));
File workingDirectory = RustLaunchDelegateTools.convertToAbsolutePath(workingDirectoryString);
if (workingDirectoryString.isEmpty() || !workingDirectory.exists() || !workingDirectory.isDirectory()) {
workingDirectory = null;
}
Expand Down

0 comments on commit 38a8259

Please sign in to comment.