mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
autotools: Start using Job.create.
Making use of lambdas for the sake of showing new APIs and having better code. Change-Id: If03cde0b2ae58d965387b0b224bc5129af78dacc Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
This commit is contained in:
parent
4b43360130
commit
0a65f2925b
3 changed files with 142 additions and 159 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2015 Wind River Systems, Inc. and others.
|
* Copyright (c) 2008, 2016 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -40,8 +40,6 @@ import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.IStatus;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
@ -125,13 +123,10 @@ class ResourceLookupTree implements IResourceChangeListener, IResourceDeltaVisit
|
||||||
public ResourceLookupTree() {
|
public ResourceLookupTree() {
|
||||||
fRootNode= new Node(null, CharArrayUtils.EMPTY, false, false) {};
|
fRootNode= new Node(null, CharArrayUtils.EMPTY, false, false) {};
|
||||||
fFileExtensions= new HashMap<>();
|
fFileExtensions= new HashMap<>();
|
||||||
fUnrefJob= new Job("Timer") { //$NON-NLS-1$
|
fUnrefJob = Job.create("Timer", monitor -> {
|
||||||
@Override
|
unrefNodeMap();
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
return Status.OK_STATUS;
|
||||||
unrefNodeMap();
|
});
|
||||||
return Status.OK_STATUS;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fUnrefJob.setSystem(true);
|
fUnrefJob.setSystem(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,6 @@ import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.IStatus;
|
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
@ -266,138 +264,134 @@ public abstract class AbstractAutotoolsHandler extends AbstractHandler {
|
||||||
// workspace root rule.
|
// workspace root rule.
|
||||||
final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
|
final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
|
||||||
|
|
||||||
Job backgroundJob = new Job(actionName) {
|
Job backgroundJob = Job.create(actionName, monitor -> {
|
||||||
@Override
|
try {
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> {
|
||||||
try {
|
try {
|
||||||
ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> {
|
String errMsg = null;
|
||||||
try {
|
IProject project = getSelectedContainer().getProject();
|
||||||
String errMsg = null;
|
// Get a build console for the project
|
||||||
IProject project = getSelectedContainer().getProject();
|
IConsole console = CCorePlugin.getDefault()
|
||||||
// Get a build console for the project
|
.getConsole("org.eclipse.cdt.autotools.ui.autotoolsConsole"); //$NON-NLS-1$
|
||||||
IConsole console = CCorePlugin.getDefault()
|
console.start(project);
|
||||||
.getConsole("org.eclipse.cdt.autotools.ui.autotoolsConsole"); //$NON-NLS-1$
|
CUIPlugin.getDefault().startGlobalConsole();
|
||||||
console.start(project);
|
ConsoleOutputStream consoleOutStream = console.getOutputStream();
|
||||||
CUIPlugin.getDefault().startGlobalConsole();
|
// FIXME: we want to remove need for
|
||||||
ConsoleOutputStream consoleOutStream = console.getOutputStream();
|
// ManagedBuilderManager, but how do we
|
||||||
// FIXME: we want to remove need for
|
// get environment variables.
|
||||||
// ManagedBuilderManager, but how do we
|
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
|
||||||
// get environment variables.
|
IConfiguration cfg = info.getDefaultConfiguration();
|
||||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
|
|
||||||
IConfiguration cfg = info.getDefaultConfiguration();
|
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
String[] consoleHeader = new String[3];
|
String[] consoleHeader = new String[3];
|
||||||
|
|
||||||
consoleHeader[0] = actionName;
|
consoleHeader[0] = actionName;
|
||||||
consoleHeader[1] = cfg.getName();
|
consoleHeader[1] = cfg.getName();
|
||||||
consoleHeader[2] = project.getName();
|
consoleHeader[2] = project.getName();
|
||||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
String invokeMsg = InvokeMessages.getFormattedString("InvokeAction.console.message", //$NON-NLS-1$
|
String invokeMsg = InvokeMessages.getFormattedString("InvokeAction.console.message", //$NON-NLS-1$
|
||||||
new String[] { actionName, execDir.toString() }); //$NON-NLS-1$
|
new String[] { actionName, execDir.toString() }); // $NON-NLS-1$
|
||||||
buf.append(invokeMsg);
|
buf.append(invokeMsg);
|
||||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
consoleOutStream.write(buf.toString().getBytes());
|
consoleOutStream.write(buf.toString().getBytes());
|
||||||
consoleOutStream.flush();
|
consoleOutStream.flush();
|
||||||
|
|
||||||
ArrayList<String> additionalEnvs = new ArrayList<>();
|
ArrayList<String> additionalEnvs = new ArrayList<>();
|
||||||
String strippedCommand = AutotoolsNewMakeGenerator.stripEnvVars(command, additionalEnvs);
|
String strippedCommand = AutotoolsNewMakeGenerator.stripEnvVars(command, additionalEnvs);
|
||||||
// Get a launcher for the config command
|
// Get a launcher for the config command
|
||||||
RemoteCommandLauncher launcher = new RemoteCommandLauncher();
|
RemoteCommandLauncher launcher = new RemoteCommandLauncher();
|
||||||
launcher.setProject(project);
|
launcher.setProject(project);
|
||||||
// Set the environment
|
// Set the environment
|
||||||
IEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider()
|
IEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider()
|
||||||
.getVariables(cfg, true);
|
.getVariables(cfg, true);
|
||||||
String[] env = null;
|
String[] env = null;
|
||||||
ArrayList<String> envList = new ArrayList<>();
|
ArrayList<String> envList = new ArrayList<>();
|
||||||
if (variables != null) {
|
if (variables != null) {
|
||||||
for (int i = 0; i < variables.length; i++) {
|
for (int i = 0; i < variables.length; i++) {
|
||||||
envList.add(variables[i].getName() + "=" + variables[i].getValue()); //$NON-NLS-1$
|
envList.add(variables[i].getName() + "=" + variables[i].getValue()); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
if (additionalEnvs.size() > 0)
|
if (additionalEnvs.size() > 0)
|
||||||
envList.addAll(additionalEnvs); // add any
|
envList.addAll(additionalEnvs); // add any
|
||||||
// additional
|
// additional
|
||||||
// environment
|
// environment
|
||||||
// variables
|
// variables
|
||||||
// specified
|
// specified
|
||||||
// ahead of
|
// ahead of
|
||||||
// script
|
// script
|
||||||
env = envList.toArray(new String[envList.size()]);
|
env = envList.toArray(new String[envList.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] newArgumentList;
|
||||||
|
|
||||||
|
// Fix for bug #343905 and bug #371277
|
||||||
|
// For Windows and Mac, we cannot run a script
|
||||||
|
// directly (in this case,
|
||||||
|
// autotools are scripts). We need to run "sh -c
|
||||||
|
// command args where command
|
||||||
|
// plus args is represented in a single string. The
|
||||||
|
// same applies for
|
||||||
|
// some Linux shells such as dash. Using sh -c will
|
||||||
|
// work on all Linux
|
||||||
|
// POSIX-compliant shells.
|
||||||
|
StringBuilder command1 = new StringBuilder(strippedCommand);
|
||||||
|
for (String arg : argumentList) {
|
||||||
|
command1.append(' ').append(arg);
|
||||||
|
}
|
||||||
|
newArgumentList = new String[] { "-c", command1.toString() };
|
||||||
|
|
||||||
|
OutputStream stdout = consoleOutStream;
|
||||||
|
OutputStream stderr = consoleOutStream;
|
||||||
|
|
||||||
|
launcher.showCommand(true);
|
||||||
|
// Run the shell script via shell command.
|
||||||
|
Process proc = launcher.execute(new Path(SHELL_COMMAND), newArgumentList, env, execDir,
|
||||||
|
new NullProgressMonitor());
|
||||||
|
if (proc != null) {
|
||||||
|
try {
|
||||||
|
// Close the input of the process since we
|
||||||
|
// will never write to
|
||||||
|
// it
|
||||||
|
proc.getOutputStream().close();
|
||||||
|
} catch (IOException e1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] newArgumentList;
|
if (launcher.waitAndRead(stdout, stderr,
|
||||||
|
SubMonitor.convert(monitor1)) != ICommandLauncher.OK) {
|
||||||
// Fix for bug #343905 and bug #371277
|
|
||||||
// For Windows and Mac, we cannot run a script
|
|
||||||
// directly (in this case,
|
|
||||||
// autotools are scripts). We need to run "sh -c
|
|
||||||
// command args where command
|
|
||||||
// plus args is represented in a single string. The
|
|
||||||
// same applies for
|
|
||||||
// some Linux shells such as dash. Using sh -c will
|
|
||||||
// work on all Linux
|
|
||||||
// POSIX-compliant shells.
|
|
||||||
StringBuilder command1 = new StringBuilder(strippedCommand);
|
|
||||||
for (String arg : argumentList) {
|
|
||||||
command1.append(' ').append(arg);
|
|
||||||
}
|
|
||||||
newArgumentList = new String[] { "-c", command1.toString() };
|
|
||||||
|
|
||||||
OutputStream stdout = consoleOutStream;
|
|
||||||
OutputStream stderr = consoleOutStream;
|
|
||||||
|
|
||||||
launcher.showCommand(true);
|
|
||||||
// Run the shell script via shell command.
|
|
||||||
Process proc = launcher.execute(new Path(SHELL_COMMAND), newArgumentList, env, execDir,
|
|
||||||
new NullProgressMonitor());
|
|
||||||
if (proc != null) {
|
|
||||||
try {
|
|
||||||
// Close the input of the process since we
|
|
||||||
// will never write to
|
|
||||||
// it
|
|
||||||
proc.getOutputStream().close();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (launcher.waitAndRead(stdout, stderr,
|
|
||||||
SubMonitor.convert(monitor1)) != ICommandLauncher.OK) {
|
|
||||||
errMsg = launcher.getErrorMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
|
||||||
// ensure
|
|
||||||
// the UI is up-to-date with the build results
|
|
||||||
// monitor.subTask(ManagedMakeMessages
|
|
||||||
// .getResourceString(REFRESH));
|
|
||||||
monitor1.subTask(AutotoolsUIPlugin.getResourceString("MakeGenerator.refresh")); //$NON-NLS-1$
|
|
||||||
try {
|
|
||||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
|
||||||
} catch (CoreException e2) {
|
|
||||||
monitor1.subTask(
|
|
||||||
AutotoolsUIPlugin.getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
errMsg = launcher.getErrorMessage();
|
errMsg = launcher.getErrorMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errMsg != null)
|
// Force a resync of the projects without
|
||||||
AutotoolsUIPlugin.logErrorMessage(errMsg);
|
// allowing the user to
|
||||||
|
// cancel.
|
||||||
} catch (IOException e3) {
|
// This is probably unkind, but short of this
|
||||||
AutotoolsUIPlugin.log(e3);
|
// there is no way to
|
||||||
|
// ensure
|
||||||
|
// the UI is up-to-date with the build results
|
||||||
|
// monitor.subTask(ManagedMakeMessages
|
||||||
|
// .getResourceString(REFRESH));
|
||||||
|
monitor1.subTask(AutotoolsUIPlugin.getResourceString("MakeGenerator.refresh")); //$NON-NLS-1$
|
||||||
|
try {
|
||||||
|
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||||
|
} catch (CoreException e2) {
|
||||||
|
monitor1.subTask(AutotoolsUIPlugin.getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errMsg = launcher.getErrorMessage();
|
||||||
}
|
}
|
||||||
}, rule, IWorkspace.AVOID_UPDATE, monitor);
|
|
||||||
} catch (CoreException e) {
|
if (errMsg != null)
|
||||||
return e.getStatus();
|
AutotoolsUIPlugin.logErrorMessage(errMsg);
|
||||||
}
|
|
||||||
return Status.OK_STATUS;
|
} catch (IOException e3) {
|
||||||
|
AutotoolsUIPlugin.log(e3);
|
||||||
|
}
|
||||||
|
}, rule, IWorkspace.AVOID_UPDATE, monitor);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
return e.getStatus();
|
||||||
}
|
}
|
||||||
};
|
return Status.OK_STATUS;
|
||||||
|
});
|
||||||
|
|
||||||
backgroundJob.setRule(rule);
|
backgroundJob.setRule(rule);
|
||||||
backgroundJob.schedule();
|
backgroundJob.schedule();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2009, 2015 Red Hat Inc..
|
* Copyright (c) 2009, 2016 Red Hat Inc..
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -21,8 +21,6 @@ import org.eclipse.core.resources.IWorkspace;
|
||||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.IStatus;
|
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
|
@ -51,29 +49,25 @@ public class ReconfigureHandler extends AbstractAutotoolsHandler {
|
||||||
// workspace root rule.
|
// workspace root rule.
|
||||||
final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
|
final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
|
||||||
|
|
||||||
Job backgroundJob = new Job("Reconfigure Action") { //$NON-NLS-1$
|
Job backgroundJob = Job.create("Reconfigure Action", monitor -> {
|
||||||
@Override
|
try {
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> {
|
||||||
try {
|
IProject project = getSelectedContainer().getProject();
|
||||||
ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> {
|
AutotoolsNewMakeGenerator m = new AutotoolsNewMakeGenerator();
|
||||||
IProject project = getSelectedContainer().getProject();
|
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
|
||||||
AutotoolsNewMakeGenerator m = new AutotoolsNewMakeGenerator();
|
CUIPlugin.getDefault().startGlobalConsole();
|
||||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
|
m.initialize(project, info, monitor1);
|
||||||
CUIPlugin.getDefault().startGlobalConsole();
|
try {
|
||||||
m.initialize(project, info, monitor1);
|
m.reconfigure();
|
||||||
try {
|
} catch (CoreException e) {
|
||||||
m.reconfigure();
|
// do nothing for now
|
||||||
} catch (CoreException e) {
|
}
|
||||||
// do nothing for now
|
}, rule, IWorkspace.AVOID_UPDATE, monitor);
|
||||||
}
|
} catch (CoreException e) {
|
||||||
}, rule, IWorkspace.AVOID_UPDATE, monitor);
|
return e.getStatus();
|
||||||
} catch (CoreException e) {
|
|
||||||
return e.getStatus();
|
|
||||||
}
|
|
||||||
IStatus returnStatus = Status.OK_STATUS;
|
|
||||||
return returnStatus;
|
|
||||||
}
|
}
|
||||||
};
|
return Status.OK_STATUS;
|
||||||
|
});
|
||||||
|
|
||||||
backgroundJob.setRule(rule);
|
backgroundJob.setRule(rule);
|
||||||
backgroundJob.schedule();
|
backgroundJob.schedule();
|
||||||
|
|
Loading…
Add table
Reference in a new issue