1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 10:15:39 +02:00

[autotools] Prevent MalformedURLException when setting remote working

directory.

Change-Id: Ib8a6a7d4df09a1f73a533db0a3821fcdb8cecdcb
Signed-off-by: Greg Watson <g.watson@computer.org>
Reviewed-on: https://git.eclipse.org/r/26428
Tested-by: Hudson CI
Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
Tested-by: Jeff Johnston <jjohnstn@redhat.com>
This commit is contained in:
Greg Watson 2014-05-13 17:56:51 +01:00 committed by Jeff Johnston
parent 5806deb5b8
commit 009a3a7d5f
2 changed files with 80 additions and 41 deletions

View file

@ -84,6 +84,7 @@ import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteResource;
import org.eclipse.remote.core.IRemoteServices;
import org.eclipse.remote.core.RemoteServices;
import org.eclipse.remote.core.exception.RemoteConnectionException;
@SuppressWarnings("deprecation")
@ -220,12 +221,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
newFile.setDerived(true);
}
// if successful, refresh any remote projects to notify them of the new file
IRemoteResource remRes =
(IRemoteResource)getProject().getAdapter(IRemoteResource.class);
if (remRes != null) {
remRes.refresh(new NullProgressMonitor());
}
refresh();
} catch (CoreException e) {
// If the file already existed locally, just refresh to get contents
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
@ -253,17 +249,20 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
rc = f.mkdirs();
if (rc) {
// if successful, refresh any remote projects to notify them of the new directory
IRemoteResource remRes =
(IRemoteResource)project.getAdapter(IRemoteResource.class);
if (remRes != null) {
remRes.refresh(new NullProgressMonitor());
}
refresh();
}
}
return rc;
}
private void refresh() throws CoreException{
IRemoteResource remRes =
(IRemoteResource)getProject().getAdapter(IRemoteResource.class);
if (remRes != null) {
remRes.refresh(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
}
}
/*
* (non-Javadoc)
@ -537,6 +536,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
errMsg, console, autogenEnvs, consoleStart);
consoleStart = false;
if (rc != IStatus.ERROR) {
refresh();
configStatus = configfile.toFile();
// Check for config.status. If it is created, then
// autogen.sh ran configure and we should not run it
@ -556,6 +556,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
AutotoolsPlugin.getFormattedString("MakeGenerator.autoreconf", new String[]{buildDir}), //$NON-NLS-1$
errMsg, console, null, consoleStart);
consoleStart = false;
refresh();
}
// Check if configure generated and if yes, run it.
if (rc != IStatus.ERROR && configurePath.toFile().exists()) {
@ -611,6 +612,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
consoleStart = false;
// Check if configure generated and if yes, run it.
if (rc != IStatus.ERROR) {
refresh();
if (configurePath.toFile().exists()) {
rc = runScript(configurePath,
buildLocation,
@ -926,7 +928,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
launcher.showCommand(true);
Process proc = launcher.execute(commandPath, configTargets, env,
runPath, new NullProgressMonitor());
runPath, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
int exitValue = 0;
if (proc != null) {
try {
@ -1036,15 +1038,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
private IPath getRemotePath(IPath path) {
IRemoteResource remRes = (IRemoteResource) getProject().getAdapter(IRemoteResource.class);
if (remRes != null) {
IPath relativePath = path.makeRelativeTo(getProject().getLocation());
try {
IPath remotePath =
new Path(remRes.getActiveLocationURI().toURL().getPath()).append(relativePath);
return remotePath;
} catch (MalformedURLException e) {
// fall-through to default action
}
return RemoteCommandLauncher.makeRemote(path, remRes);
}
return path;
}
@ -1075,7 +1069,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
new String[] { "-c", "echo $OSTYPE" }, //$NON-NLS-1$ //$NON-NLS-2$
env,
new Path("."), //$NON-NLS-1$
new NullProgressMonitor());
new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
if (launcher.waitAndRead(out, out) == ICommandLauncher.OK)
winOSType = out.toString().trim();
} catch (CoreException e) {
@ -1096,7 +1090,16 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
IRemoteConnection conn =
remServices.getConnectionManager().getConnection(uri);
if (conn != null) {
return conn.getProperty(IRemoteConnection.OS_NAME_PROPERTY);
if (!conn.isOpen()) {
try {
conn.open(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
if (conn.isOpen()) {
return conn.getProperty(IRemoteConnection.OS_NAME_PROPERTY);
}
} catch (RemoteConnectionException e) {
// Ignore and return platform OS
}
}
}
}
}
@ -1282,7 +1285,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
launcher.showCommand(true);
// Run the shell script via shell command.
Process proc = launcher.execute(new Path(SHELL_COMMAND), configTargets, env,
runPath, new NullProgressMonitor());
runPath, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
int exitValue = 0;
if (proc != null) {

View file

@ -35,6 +35,47 @@ import org.eclipse.remote.core.RemoteProcessAdapter;
import org.eclipse.remote.core.RemoteServices;
public class RemoteCommandLauncher implements ICommandLauncher {
/**
* Convert a local (workspace) path into the remote equivalent. If the local path is not
* absolute, then do nothing.
*
* e.g. Suppose the local path is /u/local_user/workspace/local_project/subdir1/subdir2
* Suppose the remote project location is /home/remote_user/remote_project
* Then the resulting path will be /home/remote_user/remote_project/subdir1/subdir2
*
* @param localPath absolute local path in the workspace
* @param remote remote project
* @return remote path that is the equivalent of the local path
*/
public static String makeRemote(String local, IRemoteResource remote) {
return makeRemote(new Path(local), remote).toString();
}
/**
* Convert a local (workspace) path into the remote equivalent. If the local path is not
* absolute, then do nothing.
*
* e.g. Suppose the local path is /u/local_user/workspace/local_project/subdir1/subdir2
* Suppose the remote project location is /home/remote_user/remote_project
* Then the resulting path will be /home/remote_user/remote_project/subdir1/subdir2
*
* @param localPath absolute local path in the workspace
* @param remote remote project
* @return remote path that is the equivalent of the local path
*/
public static IPath makeRemote(IPath localPath, IRemoteResource remote) {
if (!localPath.isAbsolute()) {
return localPath;
}
IPath relativePath = localPath.makeRelativeTo(remote.getResource().getLocation());
IPath remotePath = new Path(remote.getActiveLocationURI().getPath());
if (!relativePath.isEmpty()) {
remotePath = remotePath.append(relativePath);
}
return remotePath;
}
private final ICommandLauncher fLocalLauncher = new CommandLauncher();
private boolean fShowCommand;
private String[] fCommandArgs;
@ -50,18 +91,20 @@ public class RemoteCommandLauncher implements ICommandLauncher {
/**
* Constructs a command array that will be passed to the process
*/
private String[] constructCommandArray(String command, String[] commandArgs) {
private String[] constructCommandArray(String command, String[] commandArgs, IRemoteResource remote) {
String[] args = new String[1 + commandArgs.length];
args[0] = command;
System.arraycopy(commandArgs, 0, args, 1, commandArgs.length);
args[0] = makeRemote(command, remote);
for (int i = 0; i < commandArgs.length; i++) {
args[i + 1] = makeRemote(commandArgs[i], remote);
}
return args;
}
@Override
public Process execute(IPath commandPath, String[] args, String[] env, IPath workingDirectory, IProgressMonitor monitor)
throws CoreException {
if (fLocalLauncher.getProject() != null) {
IRemoteResource remRes = (IRemoteResource) fLocalLauncher.getProject().getAdapter(IRemoteResource.class);
if (getProject() != null) {
IRemoteResource remRes = (IRemoteResource) getProject().getAdapter(IRemoteResource.class);
if (remRes != null) {
URI uri = remRes.getActiveLocationURI();
IRemoteServices remServices = RemoteServices.getRemoteServices(uri);
@ -69,19 +112,12 @@ public class RemoteCommandLauncher implements ICommandLauncher {
fConnection = remServices.getConnectionManager().getConnection(uri);
if (fConnection != null) {
parseEnvironment(env);
fCommandArgs = constructCommandArray(commandPath.toOSString(), args);
fCommandArgs = constructCommandArray(commandPath.toString(), args, remRes);
IRemoteProcessBuilder processBuilder = fConnection.getProcessBuilder(fCommandArgs);
if (workingDirectory != null) {
IPath relativePath = workingDirectory.makeRelativeTo(getProject().getLocation());
try {
IPath remoteWorkingPath =
new Path(remRes.getActiveLocationURI().toURL().getPath()).append(relativePath);
IFileStore wd = fConnection.getFileManager().getResource(remoteWorkingPath.toString());
processBuilder.directory(wd);
} catch (MalformedURLException e) {
fLocalLauncher.setErrorMessage(e.getMessage());
return null;
}
String remoteWorkingPath = makeRemote(workingDirectory.toString(), remRes);
IFileStore wd = fConnection.getFileManager().getResource(remoteWorkingPath);
processBuilder.directory(wd);
}
Map<String, String> processEnv = processBuilder.environment();
for (String key : fEnvironment.stringPropertyNames()) {