Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java')
-rw-r--r--build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java138
1 files changed, 120 insertions, 18 deletions
diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java
index 2d3c4106517..fca9628a345 100644
--- a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java
+++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java
@@ -18,6 +18,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
@@ -30,9 +31,9 @@ import java.util.regex.Pattern;
import org.eclipse.cdt.autotools.core.AutotoolsPlugin;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.core.ConsoleOutputStream;
import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICommandLauncher;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
@@ -58,6 +59,7 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
import org.eclipse.cdt.newmake.core.IMakeCommonBuildInfo;
+import org.eclipse.cdt.remote.core.RemoteCommandLauncher;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IContainer;
@@ -78,6 +80,10 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.core.IRemoteResource;
+import org.eclipse.remote.core.IRemoteServices;
+import org.eclipse.remote.core.RemoteServices;
@SuppressWarnings("deprecation")
@@ -162,6 +168,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
CUIPlugin.getDefault().getPreferenceStore().getString("dummy");
}
+ @Override
public IProject getProject() {
return project;
}
@@ -211,6 +218,12 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
if (!newFile.isDerived()) {
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());
+ }
} catch (CoreException e) {
// If the file already existed locally, just refresh to get contents
@@ -235,8 +248,18 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
if (dirName.length() == 0 || dirName.equals("."))
path = project.getLocation().append(dirName);
File f = path.toFile();
- if (!f.exists())
+ if (!f.exists()) {
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());
+ }
+
+ }
+ }
return rc;
}
@@ -876,7 +899,8 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
consoleOutStream.flush();
// Get a launcher for the config command
- CommandLauncher launcher = new CommandLauncher();
+ RemoteCommandLauncher launcher = new RemoteCommandLauncher();
+ launcher.setProject(project);
// Set the environment
IEnvironmentVariable variables[] =
CCorePlugin.getDefault().getBuildEnvironmentManager().getVariables(cdesc, true);
@@ -887,7 +911,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
envList.add(variables[i].getName()
+ "=" + variables[i].getValue()); //$NON-NLS-1$
}
- env = (String[]) envList.toArray(new String[envList.size()]);
+ env = envList.toArray(new String[envList.size()]);
}
// Hook up an error parser manager
@@ -902,6 +926,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
launcher.showCommand(true);
Process proc = launcher.execute(commandPath, configTargets, env,
runPath, new NullProgressMonitor());
+ int exitValue = 0;
if (proc != null) {
try {
// Close the input of the process since we will never write to
@@ -911,10 +936,26 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
}
if (launcher.waitAndRead(stdout, stderr, new SubProgressMonitor(
- monitor, IProgressMonitor.UNKNOWN)) != CommandLauncher.OK) {
+ monitor, IProgressMonitor.UNKNOWN)) != ICommandLauncher.OK) {
errMsg = launcher.getErrorMessage();
}
+ // There can be a problem looking at the process exit value,
+ // so prevent an exception from occurring.
+ if (errMsg == null || errMsg.length() == 0) {
+ try {
+ exitValue = proc.exitValue();
+ } catch (IllegalThreadStateException e) {
+ try {
+ proc.waitFor();
+ } catch (InterruptedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ exitValue = proc.exitValue();
+ }
+ }
+
// Force a resync of the projects without allowing the user to
// cancel.
// This is probably unkind, but short of this there is no way to
@@ -943,7 +984,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
buf.append("(").append(errMsg).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
rc = IStatus.ERROR;
- } else if (proc.exitValue() >= 1 || proc.exitValue() < 0) {
+ } else if (exitValue >= 1 || exitValue < 0) {
// We have an invalid return code from configuration.
String[] errArg = new String[2];
errArg[0] = Integer.toString(proc.exitValue());
@@ -990,11 +1031,29 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
return rc;
}
+ // Method to translate paths to various commands to their remote counter-parts
+ 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 path;
+ }
+
// Method to get the Win OS Type to distinguish between Cygwin and MingW
private String getWinOSType() {
if (winOSType.equals("")) {
try {
- CommandLauncher launcher = new CommandLauncher();
+ RemoteCommandLauncher launcher = new RemoteCommandLauncher();
+ launcher.setProject(getProject());
ByteArrayOutputStream out = new ByteArrayOutputStream();
// Fix Bug 423192 - use environment variables when checking the Win OS Type using
// a shell command as the path to sh may be specified there
@@ -1007,7 +1066,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
envList.add(variables[i].getName()
+ "=" + variables[i].getValue()); //$NON-NLS-1$
}
- env = (String[]) envList.toArray(new String[envList.size()]);
+ env = envList.toArray(new String[envList.size()]);
}
launcher.execute(
@@ -1016,7 +1075,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
env,
new Path("."), //$NON-NLS-1$
new NullProgressMonitor());
- if (launcher.waitAndRead(out, out) == CommandLauncher.OK)
+ if (launcher.waitAndRead(out, out) == ICommandLauncher.OK)
winOSType = out.toString().trim();
} catch (CoreException e) {
// do nothing
@@ -1025,12 +1084,30 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
return winOSType;
}
+ // Get OS name either remotely or locally, depending on the project
+ private String getOSName() {
+ IRemoteResource remRes =
+ (IRemoteResource)getProject().getAdapter(IRemoteResource.class);
+ if (remRes != null) {
+ URI uri = remRes.getActiveLocationURI();
+ IRemoteServices remServices = RemoteServices.getRemoteServices(uri);
+ if (remServices != null) {
+ IRemoteConnection conn =
+ remServices.getConnectionManager().getConnection(uri);
+ if (conn != null) {
+ return conn.getProperty(IRemoteConnection.OS_NAME_PROPERTY);
+ }
+ }
+ }
+ return Platform.getOS();
+ }
+
// Get the path string. We add a Win check to handle MingW.
// For MingW, we would rather represent C:\a\b as /C/a/b which
// doesn't cause Makefile to choke. For Cygwin we use /cygdrive/C/a/b
private String getPathString(IPath path) {
String s = path.toString();
- if (Platform.getOS().equals(Platform.OS_WIN32)) {
+ if (getOSName().equals(Platform.OS_WIN32)) {
if (getWinOSType().equals("cygwin")) {
s = s.replaceAll("^([A-Z])(:)", "/cygdrive/$1");
} else {
@@ -1048,7 +1125,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
return s;
}
- // Run an autotools script (e.g. configure, autogen.sh, config.status).
+ // Run an autotools script (e.g. configure, autogen.sh, config.status).
private int runScript(IPath commandPath, IPath runPath, String[] args,
String jobDescription, String errMsg, IConsole console,
ArrayList<String> additionalEnvs,
@@ -1060,6 +1137,10 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
removeAllMarkers(project);
+ // Convert the command path if we have an absolute path and we are executing this remotely
+ if (commandPath.isAbsolute())
+ commandPath = getRemotePath(commandPath);
+
// We want to run the script via the shell command. So, we add the command
// script as the first argument and expect "sh" to be on the runtime path.
// Any other arguments are placed after the script name.
@@ -1073,8 +1154,9 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
configTargets[0] = getPathString(commandPath);
// Fix for bug #343879
- if (Platform.getOS().equals(Platform.OS_WIN32)
- || Platform.getOS().equals(Platform.OS_MACOSX))
+ String osName = getOSName();
+ if (osName.equals(Platform.OS_WIN32)
+ || osName.equals(Platform.OS_MACOSX))
removePWD = true;
// Fix for bug #343731 and bug #371277
@@ -1155,7 +1237,8 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
consoleOutStream.flush();
// Get a launcher for the config command
- CommandLauncher launcher = new CommandLauncher();
+ RemoteCommandLauncher launcher = new RemoteCommandLauncher();
+ launcher.setProject(project);
// Set the environment
IEnvironmentVariable variables[] =
CCorePlugin.getDefault().getBuildEnvironmentManager().getVariables(cdesc, true);
@@ -1183,7 +1266,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
}
if (additionalEnvs != null)
envList.addAll(additionalEnvs); // add any additional environment variables specified ahead of script
- env = (String[]) envList.toArray(new String[envList.size()]);
+ env = envList.toArray(new String[envList.size()]);
}
// Hook up an error parser manager
@@ -1199,6 +1282,8 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
// Run the shell script via shell command.
Process proc = launcher.execute(new Path(SHELL_COMMAND), configTargets, env,
runPath, new NullProgressMonitor());
+
+ int exitValue = 0;
if (proc != null) {
try {
// Close the input of the process since we will never write to
@@ -1208,9 +1293,25 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
}
if (launcher.waitAndRead(stdout, stderr, new SubProgressMonitor(
- monitor, IProgressMonitor.UNKNOWN)) != CommandLauncher.OK) {
+ monitor, IProgressMonitor.UNKNOWN)) != ICommandLauncher.OK) {
errMsg = launcher.getErrorMessage();
}
+
+ // There can be a problem looking at the process exit value,
+ // so prevent an exception from occurring.
+ if (errMsg == null || errMsg.length() == 0) {
+ try {
+ exitValue = proc.exitValue();
+ } catch (IllegalThreadStateException e) {
+ try {
+ proc.waitFor();
+ } catch (InterruptedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ exitValue = proc.exitValue();
+ }
+ }
// Force a resync of the projects without allowing the user to
// cancel.
@@ -1240,7 +1341,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
buf.append("(").append(errMsg).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
rc = IStatus.ERROR;
- } else if (proc.exitValue() >= 1 || proc.exitValue() < 0) {
+ } else if (exitValue >= 1 || exitValue < 0) {
// We have an invalid return code from configuration.
String[] errArg = new String[2];
errArg[0] = Integer.toString(proc.exitValue());
@@ -1342,6 +1443,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
}
protected static class MakeTargetComparator implements Comparator<Object> {
+ @Override
public int compare(Object a, Object b) {
IMakeTarget make1 = (IMakeTarget)a;
IMakeTarget make2 = (IMakeTarget)b;
@@ -1505,6 +1607,6 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
aList.add(str);
}
}
- return (String[])aList.toArray(new String[aList.size()]);
+ return aList.toArray(new String[aList.size()]);
}
} \ No newline at end of file

Back to the top