Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed absolute path calculation for workspace resources #148

Merged
merged 1 commit into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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