Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.ui.externaltools/Program Tools Support')
-rw-r--r--org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/BackgroundResourceRefresher.java87
-rw-r--r--org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.java4
-rw-r--r--org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.properties4
-rw-r--r--org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramLaunchDelegate.java246
4 files changed, 2 insertions, 339 deletions
diff --git a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/BackgroundResourceRefresher.java b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/BackgroundResourceRefresher.java
deleted file mode 100644
index 2d7ab0a78..000000000
--- a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/BackgroundResourceRefresher.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.ui.externaltools.internal.program.launchConfigurations;
-
-
-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.Job;
-import org.eclipse.debug.core.DebugEvent;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.IDebugEventSetListener;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.debug.ui.RefreshTab;
-import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
-
-/**
- * Refreshes resources as specified by a launch configuration, when
- * an associated process terminates.
- */
-public class BackgroundResourceRefresher implements IDebugEventSetListener {
-
- private ILaunchConfiguration fConfiguration;
- private IProcess fProcess;
-
- public BackgroundResourceRefresher(ILaunchConfiguration configuration, IProcess process) {
- fConfiguration = configuration;
- fProcess = process;
- }
-
- /**
- * If the process has already terminated, resource refreshing is done
- * immediately in the current thread. Otherwise, refreshing is done when the
- * process terminates.
- */
- public void startBackgroundRefresh() {
- synchronized (fProcess) {
- if (fProcess.isTerminated()) {
- refresh();
- } else {
- DebugPlugin.getDefault().addDebugEventListener(this);
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
- */
- public void handleDebugEvents(DebugEvent[] events) {
- for (int i = 0; i < events.length; i++) {
- DebugEvent event = events[i];
- if (event.getSource() == fProcess && event.getKind() == DebugEvent.TERMINATE) {
- DebugPlugin.getDefault().removeDebugEventListener(this);
- refresh();
- break;
- }
- }
- }
-
- /**
- * Submits a job to do the refresh
- */
- protected void refresh() {
- Job job= new Job(ExternalToolsProgramMessages.BackgroundResourceRefresher_0) {
- public IStatus run(IProgressMonitor monitor) {
- try {
- RefreshTab.refreshResources(fConfiguration, monitor);
- } catch (CoreException e) {
- ExternalToolsPlugin.getDefault().log(e);
- return e.getStatus();
- }
- return Status.OK_STATUS;
- }
- };
- job.schedule();
- }
-}
diff --git a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.java b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.java
index 7e817f8dd..82687b476 100644
--- a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.java
+++ b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2000, 2009 IBM Corporation 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 http://www.eclipse.org/legal/epl-v10.html
@@ -18,8 +18,6 @@ public class ExternalToolsProgramMessages extends NLS {
public static String ProgramLaunchDelegate_Workbench_Closing_1;
public static String ProgramLaunchDelegate_The_workbench_is_exiting;
- public static String ProgramLaunchDelegate_3;
- public static String ProgramLaunchDelegate_4;
public static String ProgramMainTab_Select;
diff --git a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.properties b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.properties
index 059a02635..5687b92fc 100644
--- a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.properties
+++ b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2005 IBM Corporation and others.
+# Copyright (c) 2000, 2009 IBM Corporation 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
@@ -13,7 +13,5 @@ BackgroundResourceRefresher_0=Refreshing resources...
ProgramLaunchDelegate_Workbench_Closing_1=Workbench Closing
ProgramLaunchDelegate_The_workbench_is_exiting=The workbench is exiting and a program launched from an external tool appears to still be running. These programs will be terminated when the workbench exits. It is recommended that you exit any external programs launched from the workbench before you proceed.\n\nClick OK to continue exiting the workbench.
-ProgramLaunchDelegate_3=Running {0}...
-ProgramLaunchDelegate_4=An IProcess could not be created for the launch
ProgramMainTab_Select=&Select a program:
diff --git a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramLaunchDelegate.java b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramLaunchDelegate.java
deleted file mode 100644
index bed630430..000000000
--- a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramLaunchDelegate.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Keith Seitz (keiths@redhat.com) - environment variables contribution (Bug 27243)
- * dakshinamurthy.karra@gmail.com - bug 165371
- *******************************************************************************/
-package org.eclipse.ui.externaltools.internal.program.launchConfigurations;
-
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.resources.IProject;
-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.Status;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
-import org.eclipse.debug.ui.CommonTab;
-import org.eclipse.debug.ui.RefreshTab;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.ui.IWindowListener;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsBuildTab;
-import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
-import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
-
-/**
- * Launch delegate for a program.
- */
-public class ProgramLaunchDelegate extends LaunchConfigurationDelegate {
-
- private static IWindowListener fWindowListener;
-
- /**
- * A window listener that warns the user about any running programs when
- * the workbench closes. Programs are killed when the VM exits.
- */
- private class ProgramLaunchWindowListener implements IWindowListener {
- public void windowActivated(IWorkbenchWindow window) {
- }
- public void windowDeactivated(IWorkbenchWindow window) {
- }
- public void windowClosed(IWorkbenchWindow window) {
- IWorkbenchWindow windows[]= PlatformUI.getWorkbench().getWorkbenchWindows();
- if (windows.length > 1) {
- // There are more windows still open.
- return;
- }
- ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
- ILaunchConfigurationType programType= manager.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE);
- if (programType == null) {
- return;
- }
- ILaunch launches[]= manager.getLaunches();
- ILaunchConfigurationType configType;
- ILaunchConfiguration config;
- for (int i = 0; i < launches.length; i++) {
- try {
- config= launches[i].getLaunchConfiguration();
- if (config == null) {
- continue;
- }
- configType= config.getType();
- } catch (CoreException e) {
- continue;
- }
- if (configType.equals(programType)) {
- if (!launches[i].isTerminated()) {
- MessageDialog.openWarning(window.getShell(), ExternalToolsProgramMessages.ProgramLaunchDelegate_Workbench_Closing_1, ExternalToolsProgramMessages.ProgramLaunchDelegate_The_workbench_is_exiting);
- break;
- }
- }
- }
- }
- public void windowOpened(IWorkbenchWindow window) {
- }
- }
-
- /**
- * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
- */
- public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
-
- if (monitor.isCanceled()) {
- return;
- }
-
- // resolve location
- IPath location = ExternalToolsUtil.getLocation(configuration);
-
- if (monitor.isCanceled()) {
- return;
- }
-
- // resolve working directory
- IPath workingDirectory = ExternalToolsUtil.getWorkingDirectory(configuration);
-
- if (monitor.isCanceled()) {
- return;
- }
-
- // resolve arguments
- String[] arguments = ExternalToolsUtil.getArguments(configuration);
-
- if (monitor.isCanceled()) {
- return;
- }
-
- int cmdLineLength = 1;
- if (arguments != null) {
- cmdLineLength += arguments.length;
- }
- String[] cmdLine = new String[cmdLineLength];
- cmdLine[0] = location.toOSString();
- if (arguments != null) {
- System.arraycopy(arguments, 0, cmdLine, 1, arguments.length);
- }
-
- File workingDir = null;
- if (workingDirectory != null) {
- workingDir = workingDirectory.toFile();
- }
-
- if (monitor.isCanceled()) {
- return;
- }
-
- String[] envp = DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration);
-
- if (monitor.isCanceled()) {
- return;
- }
-
- if (fWindowListener == null) {
- fWindowListener= new ProgramLaunchWindowListener();
- PlatformUI.getWorkbench().addWindowListener(fWindowListener);
- }
- Process p = DebugPlugin.exec(cmdLine, workingDir, envp);
- IProcess process = null;
-
- // add process type to process attributes
- Map processAttributes = new HashMap();
- String programName = location.lastSegment();
- String extension = location.getFileExtension();
- if (extension != null) {
- programName = programName.substring(0, programName.length() - (extension.length() + 1));
- }
- programName = programName.toLowerCase();
- processAttributes.put(IProcess.ATTR_PROCESS_TYPE, programName);
-
- if (p != null) {
- monitor.beginTask(NLS.bind(ExternalToolsProgramMessages.ProgramLaunchDelegate_3, new String[] {configuration.getName()}), IProgressMonitor.UNKNOWN);
- process = DebugPlugin.newProcess(launch, p, location.toOSString(), processAttributes);
- }
- if (p == null || process == null) {
- if (p != null)
- p.destroy();
- throw new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, IExternalToolConstants.ERR_INTERNAL_ERROR, ExternalToolsProgramMessages.ProgramLaunchDelegate_4, null));
- }
- process.setAttribute(IProcess.ATTR_CMDLINE, generateCommandLine(cmdLine));
-
- if (CommonTab.isLaunchInBackground(configuration)) {
- // refresh resources after process finishes
- if (RefreshTab.getRefreshScope(configuration) != null) {
- BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(configuration, process);
- refresher.startBackgroundRefresh();
- }
- } else {
- // wait for process to exit
- while (!process.isTerminated()) {
- try {
- if (monitor.isCanceled()) {
- process.terminate();
- break;
- }
- Thread.sleep(50);
- } catch (InterruptedException e) {
- }
- }
-
- // refresh resources
- RefreshTab.refreshResources(configuration, monitor);
- }
- }
-
- private String generateCommandLine(String[] commandLine) {
- if (commandLine.length < 1)
- return ""; //$NON-NLS-1$
- StringBuffer buf= new StringBuffer();
- for (int i= 0; i < commandLine.length; i++) {
- buf.append(' ');
- char[] characters= commandLine[i].toCharArray();
- StringBuffer command= new StringBuffer();
- boolean containsSpace= false;
- for (int j = 0; j < characters.length; j++) {
- char character= characters[j];
- if (character == '\"') {
- command.append('\\');
- } else if (character == ' ') {
- containsSpace = true;
- }
- command.append(character);
- }
- if (containsSpace) {
- buf.append('\"');
- buf.append(command);
- buf.append('\"');
- } else {
- buf.append(command);
- }
- }
- return buf.toString();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBuildOrder(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
- */
- protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
- IProject[] projects = ExternalToolsBuildTab.getBuildProjects(configuration, null);
- if (projects == null) {
- return null ;
- }
- boolean isRef = ExternalToolsBuildTab.isIncludeReferencedProjects(configuration, null);
- if (isRef) {
- return computeReferencedBuildOrder(projects);
- }
- return computeBuildOrder(projects);
- }
-}

Back to the top