[RFC] Bug 536282 - Check whether processing step is available

Change-Id: I6a625d3fe89ca63a4b176f4fef18f07f9ba4d103
Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep.java
index 7eb0717..3a1c0d6 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep.java
@@ -47,7 +47,7 @@
 	@Override
 	public void initialize(IProvisioningAgent agent, IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
 		super.initialize(agent, descriptor, context);
-		if (!UnpackStep.canUnpack()) {
+		if (!isEnabled()) {
 			IStatus status = null;
 			if (detailedResult) {
 				status = new Status(IStatus.ERROR, Activator.ID, MirrorRequest.ARTIFACT_PROCESSING_ERROR, "Unpack facility not configured.", null); //$NON-NLS-1$
@@ -103,4 +103,9 @@
 		new JarProcessorExecutor().runJarProcessor(options);
 		return new File(getWorkDir(), incoming.getName().substring(0, incoming.getName().length() - PACKED_SUFFIX.length()));
 	}
+
+	@Override
+	public boolean isEnabled() {
+		return UnpackStep.canUnpack();
+	}
 }
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java
index 734a548..22e407b 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java
@@ -133,4 +133,8 @@
 	public IStatus getStatus(boolean deep) {
 		return ProcessingStepHandler.getStatus(this, deep);
 	}
+
+	public boolean isEnabled() {
+		return true;
+	}
 }
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java
index 25a099e..cee0631 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java
@@ -48,9 +48,19 @@
 		if (point == null)
 			return false;
 		IProcessingStepDescriptor[] steps = descriptor.getProcessingSteps();
-		for (int i = 0; i < steps.length; i++) {
-			if (point.getExtension(steps[i].getProcessorId()) == null)
+		for (IProcessingStepDescriptor stepDescriptor : steps) {
+			String processorId = stepDescriptor.getProcessorId();
+			IExtension extension = point.getExtension(processorId);
+			if (extension == null)
 				return false;
+
+			IConfigurationElement[] config = extension.getConfigurationElements();
+			try {
+				Object object = config[0].createExecutableExtension("class"); //$NON-NLS-1$
+				return ((ProcessingStep) object).isEnabled();
+			} catch (CoreException e) {
+				// noop
+			}
 		}
 		return true;
 	}