Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d03a9f7953ef4a11bdd01ee87873a89fb73d3c97 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*******************************************************************************
 * Copyright (c) 2006, 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
 *
 * Contributors:
 *     IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.jarprocessor;

import java.io.File;
import java.util.List;
import java.util.Properties;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.IProcessStep;

public abstract class CommandStep implements IProcessStep {
	protected String command = null;
	protected String extension = null;
	private Properties options = null;
	protected boolean verbose = false;

	public CommandStep(Properties options, String command, String extension, boolean verbose) {
		this.command = command;
		this.extension = extension;
		this.options = options;
		this.verbose = verbose;
	}

	protected static int execute(String[] cmd) {
		return execute(cmd, false);
	}

	protected static int execute(String[] cmd, boolean verbose) {
		Runtime runtime = Runtime.getRuntime();
		Process proc = null;
		try {
			proc = runtime.exec(cmd);
			StreamProcessor.start(proc.getErrorStream(), StreamProcessor.STDERR, verbose);
			StreamProcessor.start(proc.getInputStream(), StreamProcessor.STDOUT, verbose);
		} catch (Exception e) {
			if (verbose) {
				System.out.println("Error executing command " + Utils.concat(cmd)); //$NON-NLS-1$
				e.printStackTrace();
			}
			return -1;
		}
		try {
			int result = proc.waitFor();
			return result;
		} catch (InterruptedException e) {
			if (verbose)
				e.printStackTrace();
		}
		return -1;
	}

	public Properties getOptions() {
		if (options == null)
			options = new Properties();
		return options;
	}

	public boolean adjustInf(File input, Properties inf, List containers) {
		//do nothing by default
		return false;
	}
}

Back to the top