Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2009-09-25 18:00:55 +0000
committerAndrew Niefer2009-09-25 18:00:55 +0000
commit3b06e26406802f2a81ba8fca800c022317de30b0 (patch)
treeb894234d7a50818c9d344521448fd156deff1baa /bundles/org.eclipse.equinox.p2.jarprocessor
parent72c0b6eb9350a622a6d2dcb860328de3d1275eab (diff)
downloadrt.equinox.p2-3b06e26406802f2a81ba8fca800c022317de30b0.tar.gz
rt.equinox.p2-3b06e26406802f2a81ba8fca800c022317de30b0.tar.xz
rt.equinox.p2-3b06e26406802f2a81ba8fca800c022317de30b0.zip
bug 206971 - use jobs to limit number of threads created
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.jarprocessor')
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF5
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/CommandStep.java28
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/StreamProcessor.java36
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/StreamProcessorJob.java36
4 files changed, 77 insertions, 28 deletions
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF
index 86bd99a00..f912e2ad8 100644
--- a/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF
@@ -4,10 +4,13 @@ Bundle-SymbolicName: org.eclipse.equinox.p2.jarprocessor;singleton:=true
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
-Bundle-Version: 1.0.100.qualifier
+Bundle-Version: 1.0.200.qualifier
Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
J2SE-1.4
+Main-Class: org.eclipse.equinox.internal.p2.jarprocessor.Main
Export-Package: org.eclipse.equinox.internal.p2.jarprocessor;x-friends:="org.eclipse.equinox.p2.artifact.repository,org.eclipse.pde.build",
org.eclipse.equinox.internal.p2.jarprocessor.unsigner;x-internal:=true,
org.eclipse.equinox.internal.p2.jarprocessor.verifier;x-internal:=true,
org.eclipse.internal.provisional.equinox.p2.jarprocessor;x-friends:="org.eclipse.equinox.p2.artifact.optimizers,org.eclipse.equinox.p2.artifact.repository,org.eclipse.pde.build"
+Import-Package: org.eclipse.core.runtime;version="3.4.0";resolution:=optional,
+ org.eclipse.core.runtime.jobs;resolution:=optional
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/CommandStep.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/CommandStep.java
index f5652aee1..dde666095 100644
--- a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/CommandStep.java
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/CommandStep.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * 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
@@ -15,16 +15,12 @@ import java.util.List;
import java.util.Properties;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.IProcessStep;
-/**
- * @author aniefer@ca.ibm.com
- *
- */
public abstract class CommandStep implements IProcessStep {
protected String command = null;
protected String extension = null;
- private Properties options = 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;
@@ -35,18 +31,16 @@ public abstract class CommandStep implements IProcessStep {
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 errorStreamProcessor = new StreamProcessor(proc.getErrorStream(), StreamProcessor.STDERR, verbose);
- StreamProcessor outputStreamProcessor = new StreamProcessor(proc.getInputStream(), StreamProcessor.STDOUT, verbose);
- errorStreamProcessor.start();
- outputStreamProcessor.start();
+ StreamProcessor.start(proc.getErrorStream(), StreamProcessor.STDERR, verbose);
+ StreamProcessor.start(proc.getInputStream(), StreamProcessor.STDOUT, verbose);
} catch (Exception e) {
- if(verbose) {
+ if (verbose) {
System.out.println("Error executing command " + Utils.concat(cmd)); //$NON-NLS-1$
e.printStackTrace();
}
@@ -56,18 +50,18 @@ public abstract class CommandStep implements IProcessStep {
int result = proc.waitFor();
return result;
} catch (InterruptedException e) {
- if(verbose)
+ if (verbose)
e.printStackTrace();
}
return -1;
}
-
+
public Properties getOptions() {
- if(options == null)
+ if (options == null)
options = new Properties();
return options;
}
-
+
public void adjustInf(File input, Properties inf, List containers) {
//nothing
}
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/StreamProcessor.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/StreamProcessor.java
index cdab81291..a32f3d854 100644
--- a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/StreamProcessor.java
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/StreamProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 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
@@ -12,21 +12,37 @@ package org.eclipse.equinox.internal.p2.jarprocessor;
import java.io.*;
-public class StreamProcessor extends Thread {
+public class StreamProcessor {
+ private static final String JOBS = "org.eclipse.core.runtime.jobs.Job"; //$NON-NLS-1$
+ public static final String STREAM_PROCESSOR = "Stream Processor"; //$NON-NLS-1$
public static final String STDERR = "STDERR"; //$NON-NLS-1$
public static final String STDOUT = "STDOUT"; //$NON-NLS-1$
- private InputStream inputStream;
- private String name;
- private boolean verbose;
+ static private boolean haveJobs = false;
- public StreamProcessor(InputStream is, String name, boolean verbose) {
- this.inputStream = is;
- this.name = name;
- this.verbose = verbose;
+ static {
+ try {
+ haveJobs = (Class.forName(JOBS) != null);
+ } catch (ClassNotFoundException e) {
+ //no jobs
+ }
+ }
+
+ static public void start(final InputStream is, final String name, final boolean verbose) {
+ if (haveJobs) {
+ StreamProcessorJob job = new StreamProcessorJob(is, name, verbose);
+ job.schedule();
+ } else {
+ Thread job = new Thread(STREAM_PROCESSOR) {
+ public void run() {
+ StreamProcessor.run(is, name, verbose);
+ }
+ };
+ job.start();
+ }
}
- public void run() {
+ static public void run(InputStream inputStream, String name, boolean verbose) {
try {
InputStreamReader isr = new InputStreamReader(inputStream);
BufferedReader br = new BufferedReader(isr);
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/StreamProcessorJob.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/StreamProcessorJob.java
new file mode 100644
index 000000000..db404fec4
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/StreamProcessorJob.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 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.InputStream;
+import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.jobs.Job;
+
+public class StreamProcessorJob extends Job {
+ private InputStream inputStream = null;
+ private String name = null;
+ private boolean verbose = false;
+
+ public StreamProcessorJob(InputStream stream, String name, boolean verbose) {
+ super(StreamProcessor.STREAM_PROCESSOR + " : " + name); //$NON-NLS-1$
+ setPriority(Job.SHORT);
+ setSystem(true);
+ this.inputStream = stream;
+ this.name = name;
+ this.verbose = verbose;
+ }
+
+ protected IStatus run(IProgressMonitor monitor) {
+ StreamProcessor.run(inputStream, name, verbose);
+ inputStream = null;
+ return Status.OK_STATUS;
+ }
+}

Back to the top