Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2016-06-17 08:33:54 +0000
committerAlexander Kurtakov2016-06-17 08:33:54 +0000
commit0a65f2925bad38a1ec376ce04c87695cf7ea7043 (patch)
treed4c46b2796b394c299d1d7807edf81bac92a36c1
parent4b43360130b0573a083124883555d09a483e5921 (diff)
downloadorg.eclipse.cdt-0a65f2925bad38a1ec376ce04c87695cf7ea7043.tar.gz
org.eclipse.cdt-0a65f2925bad38a1ec376ce04c87695cf7ea7043.tar.xz
org.eclipse.cdt-0a65f2925bad38a1ec376ce04c87695cf7ea7043.zip
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>
-rw-r--r--build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/ResourceLookupTree.java15
-rw-r--r--build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java246
-rw-r--r--build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureHandler.java44
3 files changed, 144 insertions, 161 deletions
diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/ResourceLookupTree.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/ResourceLookupTree.java
index c1c12e9e558..a7b55cdeecf 100644
--- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/ResourceLookupTree.java
+++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/ResourceLookupTree.java
@@ -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
* are made available under the terms of the Eclipse Public License v1.0
* 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.runtime.CoreException;
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.Platform;
import org.eclipse.core.runtime.Status;
@@ -125,13 +123,10 @@ class ResourceLookupTree implements IResourceChangeListener, IResourceDeltaVisit
public ResourceLookupTree() {
fRootNode= new Node(null, CharArrayUtils.EMPTY, false, false) {};
fFileExtensions= new HashMap<>();
- fUnrefJob= new Job("Timer") { //$NON-NLS-1$
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- unrefNodeMap();
- return Status.OK_STATUS;
- }
- };
+ fUnrefJob = Job.create("Timer", monitor -> {
+ unrefNodeMap();
+ return Status.OK_STATUS;
+ });
fUnrefJob.setSystem(true);
}
diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java
index 0dc8e0ce748..56908da270b 100644
--- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java
+++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java
@@ -42,8 +42,6 @@ import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
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.Path;
import org.eclipse.core.runtime.Status;
@@ -266,138 +264,134 @@ public abstract class AbstractAutotoolsHandler extends AbstractHandler {
// workspace root rule.
final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
- Job backgroundJob = new Job(actionName) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> {
- try {
- String errMsg = null;
- IProject project = getSelectedContainer().getProject();
- // Get a build console for the project
- IConsole console = CCorePlugin.getDefault()
- .getConsole("org.eclipse.cdt.autotools.ui.autotoolsConsole"); //$NON-NLS-1$
- console.start(project);
- CUIPlugin.getDefault().startGlobalConsole();
- ConsoleOutputStream consoleOutStream = console.getOutputStream();
- // FIXME: we want to remove need for
- // ManagedBuilderManager, but how do we
- // get environment variables.
- IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
- IConfiguration cfg = info.getDefaultConfiguration();
-
- StringBuilder buf = new StringBuilder();
- String[] consoleHeader = new String[3];
-
- consoleHeader[0] = actionName;
- consoleHeader[1] = cfg.getName();
- consoleHeader[2] = project.getName();
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
- String invokeMsg = InvokeMessages.getFormattedString("InvokeAction.console.message", //$NON-NLS-1$
- new String[] { actionName, execDir.toString() }); //$NON-NLS-1$
- 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$
- consoleOutStream.write(buf.toString().getBytes());
- consoleOutStream.flush();
-
- ArrayList<String> additionalEnvs = new ArrayList<>();
- String strippedCommand = AutotoolsNewMakeGenerator.stripEnvVars(command, additionalEnvs);
- // Get a launcher for the config command
- RemoteCommandLauncher launcher = new RemoteCommandLauncher();
- launcher.setProject(project);
- // Set the environment
- IEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider()
- .getVariables(cfg, true);
- String[] env = null;
- ArrayList<String> envList = new ArrayList<>();
- if (variables != null) {
- for (int i = 0; i < variables.length; i++) {
- envList.add(variables[i].getName() + "=" + variables[i].getValue()); //$NON-NLS-1$
- }
- if (additionalEnvs.size() > 0)
- envList.addAll(additionalEnvs); // add any
- // additional
- // environment
- // variables
- // specified
- // ahead of
- // script
- env = envList.toArray(new String[envList.size()]);
+ Job backgroundJob = Job.create(actionName, monitor -> {
+ try {
+ ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> {
+ try {
+ String errMsg = null;
+ IProject project = getSelectedContainer().getProject();
+ // Get a build console for the project
+ IConsole console = CCorePlugin.getDefault()
+ .getConsole("org.eclipse.cdt.autotools.ui.autotoolsConsole"); //$NON-NLS-1$
+ console.start(project);
+ CUIPlugin.getDefault().startGlobalConsole();
+ ConsoleOutputStream consoleOutStream = console.getOutputStream();
+ // FIXME: we want to remove need for
+ // ManagedBuilderManager, but how do we
+ // get environment variables.
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
+ IConfiguration cfg = info.getDefaultConfiguration();
+
+ StringBuilder buf = new StringBuilder();
+ String[] consoleHeader = new String[3];
+
+ consoleHeader[0] = actionName;
+ consoleHeader[1] = cfg.getName();
+ consoleHeader[2] = project.getName();
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
+ String invokeMsg = InvokeMessages.getFormattedString("InvokeAction.console.message", //$NON-NLS-1$
+ new String[] { actionName, execDir.toString() }); // $NON-NLS-1$
+ 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$
+ consoleOutStream.write(buf.toString().getBytes());
+ consoleOutStream.flush();
+
+ ArrayList<String> additionalEnvs = new ArrayList<>();
+ String strippedCommand = AutotoolsNewMakeGenerator.stripEnvVars(command, additionalEnvs);
+ // Get a launcher for the config command
+ RemoteCommandLauncher launcher = new RemoteCommandLauncher();
+ launcher.setProject(project);
+ // Set the environment
+ IEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider()
+ .getVariables(cfg, true);
+ String[] env = null;
+ ArrayList<String> envList = new ArrayList<>();
+ if (variables != null) {
+ for (int i = 0; i < variables.length; i++) {
+ envList.add(variables[i].getName() + "=" + variables[i].getValue()); //$NON-NLS-1$
}
+ if (additionalEnvs.size() > 0)
+ envList.addAll(additionalEnvs); // add any
+ // additional
+ // environment
+ // variables
+ // specified
+ // ahead of
+ // script
+ 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);
+ 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) {
}
- 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 {
+
+ if (launcher.waitAndRead(stdout, stderr,
+ SubMonitor.convert(monitor1)) != ICommandLauncher.OK) {
errMsg = launcher.getErrorMessage();
}
- if (errMsg != null)
- AutotoolsUIPlugin.logErrorMessage(errMsg);
-
- } catch (IOException e3) {
- AutotoolsUIPlugin.log(e3);
+ // 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();
}
- }, rule, IWorkspace.AVOID_UPDATE, monitor);
- } catch (CoreException e) {
- return e.getStatus();
- }
- return Status.OK_STATUS;
+
+ if (errMsg != null)
+ AutotoolsUIPlugin.logErrorMessage(errMsg);
+
+ } 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.schedule();
diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureHandler.java
index 503aea7d40e..8dde50db5a1 100644
--- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureHandler.java
+++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureHandler.java
@@ -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
* are made available under the terms of the Eclipse Public License v1.0
* 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.ResourcesPlugin;
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.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
@@ -51,29 +49,25 @@ public class ReconfigureHandler extends AbstractAutotoolsHandler {
// workspace root rule.
final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
- Job backgroundJob = new Job("Reconfigure Action") { //$NON-NLS-1$
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> {
- IProject project = getSelectedContainer().getProject();
- AutotoolsNewMakeGenerator m = new AutotoolsNewMakeGenerator();
- IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
- CUIPlugin.getDefault().startGlobalConsole();
- m.initialize(project, info, monitor1);
- try {
- m.reconfigure();
- } catch (CoreException e) {
- // do nothing for now
- }
- }, rule, IWorkspace.AVOID_UPDATE, monitor);
- } catch (CoreException e) {
- return e.getStatus();
- }
- IStatus returnStatus = Status.OK_STATUS;
- return returnStatus;
+ Job backgroundJob = Job.create("Reconfigure Action", monitor -> {
+ try {
+ ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> {
+ IProject project = getSelectedContainer().getProject();
+ AutotoolsNewMakeGenerator m = new AutotoolsNewMakeGenerator();
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
+ CUIPlugin.getDefault().startGlobalConsole();
+ m.initialize(project, info, monitor1);
+ try {
+ m.reconfigure();
+ } catch (CoreException e) {
+ // do nothing for now
+ }
+ }, rule, IWorkspace.AVOID_UPDATE, monitor);
+ } catch (CoreException e) {
+ return e.getStatus();
}
- };
+ return Status.OK_STATUS;
+ });
backgroundJob.setRule(rule);
backgroundJob.schedule();

Back to the top