Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4b34f5522ddc168ed15e34e24d54f18528881409 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.eclipse.ui.externaltools.internal.core;

/**********************************************************************
Copyright (c) 2002 IBM Corp. and others.
All rights reserved.   This program and the accompanying materials
are made available under the terms of the Common Public License v0.5
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/cpl-v05.html
 
Contributors:
**********************************************************************/
import org.apache.tools.ant.BuildListener;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

/**
 * Responsible for executing the external tool. Clients
 * must provide a public no-argument constructor
 */
public abstract class ExternalToolsRunner {

	/**
	 * Creates an empty external tool runner
	 */
	public ExternalToolsRunner() {
		super();
	}

	/**
	 * Execute the external tool within the given context. Subclasses
	 * are responsible for showing the execution log if
	 * specified in the context.
	 */
	public abstract void execute(IProgressMonitor monitor, IRunnerContext scriptContext) throws CoreException;
	
	/**
	 * Handles exceptions that may occur while running.
	 */
	protected final void handleException(Exception e) throws CoreException {
		String msg = e.getMessage();
		if (msg == null)
			msg = ToolMessages.getString("ExternalToolsRunner.internalErrorMessage"); //$NON-NLS-1$;
		throw new CoreException(new Status(IStatus.ERROR, ExternalToolsPlugin.PLUGIN_ID, 0, msg, e));
	}

	/**
	 * Starts the monitor to show progress while running.
	 */
	protected final void startMonitor(IProgressMonitor monitor, IRunnerContext scriptContext, int workAmount) {
		String label = ToolMessages.format("ExternalToolsRunner.runningScriptLabel", new Object[] {scriptContext.getName()}); //$NON-NLS-1$;
		monitor.beginTask(label, workAmount);
	}
}

Back to the top