mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 18:25:40 +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:
parent
5806deb5b8
commit
009a3a7d5f
2 changed files with 80 additions and 41 deletions
|
@ -84,6 +84,7 @@ import org.eclipse.remote.core.IRemoteConnection;
|
||||||
import org.eclipse.remote.core.IRemoteResource;
|
import org.eclipse.remote.core.IRemoteResource;
|
||||||
import org.eclipse.remote.core.IRemoteServices;
|
import org.eclipse.remote.core.IRemoteServices;
|
||||||
import org.eclipse.remote.core.RemoteServices;
|
import org.eclipse.remote.core.RemoteServices;
|
||||||
|
import org.eclipse.remote.core.exception.RemoteConnectionException;
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@ -220,12 +221,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
|
||||||
newFile.setDerived(true);
|
newFile.setDerived(true);
|
||||||
}
|
}
|
||||||
// if successful, refresh any remote projects to notify them of the new file
|
// if successful, refresh any remote projects to notify them of the new file
|
||||||
IRemoteResource remRes =
|
refresh();
|
||||||
(IRemoteResource)getProject().getAdapter(IRemoteResource.class);
|
|
||||||
if (remRes != null) {
|
|
||||||
remRes.refresh(new NullProgressMonitor());
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
// If the file already existed locally, just refresh to get contents
|
// If the file already existed locally, just refresh to get contents
|
||||||
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
|
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
|
||||||
|
@ -253,18 +249,21 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
|
||||||
rc = f.mkdirs();
|
rc = f.mkdirs();
|
||||||
if (rc) {
|
if (rc) {
|
||||||
// if successful, refresh any remote projects to notify them of the new directory
|
// if successful, refresh any remote projects to notify them of the new directory
|
||||||
IRemoteResource remRes =
|
refresh();
|
||||||
(IRemoteResource)project.getAdapter(IRemoteResource.class);
|
|
||||||
if (remRes != null) {
|
|
||||||
remRes.refresh(new NullProgressMonitor());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
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)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
@ -537,6 +536,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
|
||||||
errMsg, console, autogenEnvs, consoleStart);
|
errMsg, console, autogenEnvs, consoleStart);
|
||||||
consoleStart = false;
|
consoleStart = false;
|
||||||
if (rc != IStatus.ERROR) {
|
if (rc != IStatus.ERROR) {
|
||||||
|
refresh();
|
||||||
configStatus = configfile.toFile();
|
configStatus = configfile.toFile();
|
||||||
// Check for config.status. If it is created, then
|
// Check for config.status. If it is created, then
|
||||||
// autogen.sh ran configure and we should not run it
|
// 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$
|
AutotoolsPlugin.getFormattedString("MakeGenerator.autoreconf", new String[]{buildDir}), //$NON-NLS-1$
|
||||||
errMsg, console, null, consoleStart);
|
errMsg, console, null, consoleStart);
|
||||||
consoleStart = false;
|
consoleStart = false;
|
||||||
|
refresh();
|
||||||
}
|
}
|
||||||
// Check if configure generated and if yes, run it.
|
// Check if configure generated and if yes, run it.
|
||||||
if (rc != IStatus.ERROR && configurePath.toFile().exists()) {
|
if (rc != IStatus.ERROR && configurePath.toFile().exists()) {
|
||||||
|
@ -611,6 +612,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
|
||||||
consoleStart = false;
|
consoleStart = false;
|
||||||
// Check if configure generated and if yes, run it.
|
// Check if configure generated and if yes, run it.
|
||||||
if (rc != IStatus.ERROR) {
|
if (rc != IStatus.ERROR) {
|
||||||
|
refresh();
|
||||||
if (configurePath.toFile().exists()) {
|
if (configurePath.toFile().exists()) {
|
||||||
rc = runScript(configurePath,
|
rc = runScript(configurePath,
|
||||||
buildLocation,
|
buildLocation,
|
||||||
|
@ -926,7 +928,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
|
||||||
|
|
||||||
launcher.showCommand(true);
|
launcher.showCommand(true);
|
||||||
Process proc = launcher.execute(commandPath, configTargets, env,
|
Process proc = launcher.execute(commandPath, configTargets, env,
|
||||||
runPath, new NullProgressMonitor());
|
runPath, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
|
||||||
int exitValue = 0;
|
int exitValue = 0;
|
||||||
if (proc != null) {
|
if (proc != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -1036,15 +1038,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
|
||||||
private IPath getRemotePath(IPath path) {
|
private IPath getRemotePath(IPath path) {
|
||||||
IRemoteResource remRes = (IRemoteResource) getProject().getAdapter(IRemoteResource.class);
|
IRemoteResource remRes = (IRemoteResource) getProject().getAdapter(IRemoteResource.class);
|
||||||
if (remRes != null) {
|
if (remRes != null) {
|
||||||
IPath relativePath = path.makeRelativeTo(getProject().getLocation());
|
return RemoteCommandLauncher.makeRemote(path, remRes);
|
||||||
try {
|
|
||||||
IPath remotePath =
|
|
||||||
new Path(remRes.getActiveLocationURI().toURL().getPath()).append(relativePath);
|
|
||||||
return remotePath;
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
// fall-through to default action
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
@ -1075,7 +1069,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
|
||||||
new String[] { "-c", "echo $OSTYPE" }, //$NON-NLS-1$ //$NON-NLS-2$
|
new String[] { "-c", "echo $OSTYPE" }, //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
env,
|
env,
|
||||||
new Path("."), //$NON-NLS-1$
|
new Path("."), //$NON-NLS-1$
|
||||||
new NullProgressMonitor());
|
new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
|
||||||
if (launcher.waitAndRead(out, out) == ICommandLauncher.OK)
|
if (launcher.waitAndRead(out, out) == ICommandLauncher.OK)
|
||||||
winOSType = out.toString().trim();
|
winOSType = out.toString().trim();
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
@ -1096,7 +1090,16 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
|
||||||
IRemoteConnection conn =
|
IRemoteConnection conn =
|
||||||
remServices.getConnectionManager().getConnection(uri);
|
remServices.getConnectionManager().getConnection(uri);
|
||||||
if (conn != null) {
|
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);
|
launcher.showCommand(true);
|
||||||
// Run the shell script via shell command.
|
// Run the shell script via shell command.
|
||||||
Process proc = launcher.execute(new Path(SHELL_COMMAND), configTargets, env,
|
Process proc = launcher.execute(new Path(SHELL_COMMAND), configTargets, env,
|
||||||
runPath, new NullProgressMonitor());
|
runPath, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
|
||||||
|
|
||||||
int exitValue = 0;
|
int exitValue = 0;
|
||||||
if (proc != null) {
|
if (proc != null) {
|
||||||
|
|
|
@ -35,6 +35,47 @@ import org.eclipse.remote.core.RemoteProcessAdapter;
|
||||||
import org.eclipse.remote.core.RemoteServices;
|
import org.eclipse.remote.core.RemoteServices;
|
||||||
|
|
||||||
public class RemoteCommandLauncher implements ICommandLauncher {
|
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 final ICommandLauncher fLocalLauncher = new CommandLauncher();
|
||||||
private boolean fShowCommand;
|
private boolean fShowCommand;
|
||||||
private String[] fCommandArgs;
|
private String[] fCommandArgs;
|
||||||
|
@ -50,18 +91,20 @@ public class RemoteCommandLauncher implements ICommandLauncher {
|
||||||
/**
|
/**
|
||||||
* Constructs a command array that will be passed to the process
|
* 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];
|
String[] args = new String[1 + commandArgs.length];
|
||||||
args[0] = command;
|
args[0] = makeRemote(command, remote);
|
||||||
System.arraycopy(commandArgs, 0, args, 1, commandArgs.length);
|
for (int i = 0; i < commandArgs.length; i++) {
|
||||||
|
args[i + 1] = makeRemote(commandArgs[i], remote);
|
||||||
|
}
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Process execute(IPath commandPath, String[] args, String[] env, IPath workingDirectory, IProgressMonitor monitor)
|
public Process execute(IPath commandPath, String[] args, String[] env, IPath workingDirectory, IProgressMonitor monitor)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
if (fLocalLauncher.getProject() != null) {
|
if (getProject() != null) {
|
||||||
IRemoteResource remRes = (IRemoteResource) fLocalLauncher.getProject().getAdapter(IRemoteResource.class);
|
IRemoteResource remRes = (IRemoteResource) getProject().getAdapter(IRemoteResource.class);
|
||||||
if (remRes != null) {
|
if (remRes != null) {
|
||||||
URI uri = remRes.getActiveLocationURI();
|
URI uri = remRes.getActiveLocationURI();
|
||||||
IRemoteServices remServices = RemoteServices.getRemoteServices(uri);
|
IRemoteServices remServices = RemoteServices.getRemoteServices(uri);
|
||||||
|
@ -69,19 +112,12 @@ public class RemoteCommandLauncher implements ICommandLauncher {
|
||||||
fConnection = remServices.getConnectionManager().getConnection(uri);
|
fConnection = remServices.getConnectionManager().getConnection(uri);
|
||||||
if (fConnection != null) {
|
if (fConnection != null) {
|
||||||
parseEnvironment(env);
|
parseEnvironment(env);
|
||||||
fCommandArgs = constructCommandArray(commandPath.toOSString(), args);
|
fCommandArgs = constructCommandArray(commandPath.toString(), args, remRes);
|
||||||
IRemoteProcessBuilder processBuilder = fConnection.getProcessBuilder(fCommandArgs);
|
IRemoteProcessBuilder processBuilder = fConnection.getProcessBuilder(fCommandArgs);
|
||||||
if (workingDirectory != null) {
|
if (workingDirectory != null) {
|
||||||
IPath relativePath = workingDirectory.makeRelativeTo(getProject().getLocation());
|
String remoteWorkingPath = makeRemote(workingDirectory.toString(), remRes);
|
||||||
try {
|
IFileStore wd = fConnection.getFileManager().getResource(remoteWorkingPath);
|
||||||
IPath remoteWorkingPath =
|
processBuilder.directory(wd);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Map<String, String> processEnv = processBuilder.environment();
|
Map<String, String> processEnv = processBuilder.environment();
|
||||||
for (String key : fEnvironment.stringPropertyNames()) {
|
for (String key : fEnvironment.stringPropertyNames()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue