Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMykola Nikishov2018-06-26 05:24:37 -0400
committerMykola Nikishov2018-12-20 14:12:48 -0500
commitb8b794603e2cc67f4b2d7e5c392b6f1f8b534d86 (patch)
treeefee6c0e7134cd3d9e80ee46e6a0202f9f556921 /bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing
parent27630805f3b5764e05f4101744f94caff0947099 (diff)
downloadrt.equinox.p2-b8b794603e2cc67f4b2d7e5c392b6f1f8b534d86.tar.gz
rt.equinox.p2-b8b794603e2cc67f4b2d7e5c392b6f1f8b534d86.tar.xz
rt.equinox.p2-b8b794603e2cc67f4b2d7e5c392b6f1f8b534d86.zip
Bug 536282 - Check whether processing step is availableI20181220-1800
Extend ProcessingStep with isEnabled() method that checks if step's dependencies are available. ProcessingStepHandler's canProcess will ensure that all required processing steps are enabled and skip this check for optional processing steps. MirrorRequest's perform(IArtifactRepository, IProgressMonitor) method will skip optimized artifact if it can't be processed and chose canonical one. Pack200ProcessorStep's isEnabled() checks if 'unpack200' CLI utility is available by calling UnpackStep's canUnpack(). Change-Id: I048db3b833f6e0881cca06ad48be37ad6d17a0c9 Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing')
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java13
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java53
2 files changed, 58 insertions, 8 deletions
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 734a5482a..b32c1cfee 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
@@ -11,6 +11,7 @@
* Contributors:
* compeople AG (Stefan Liebig) - initial API and implementation
* IBM Corporation - continuing development
+* Mykola Nikishov - continuing development
*******************************************************************************/
package org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing;
@@ -133,4 +134,16 @@ public abstract class ProcessingStep extends OutputStream implements IStateful {
public IStatus getStatus(boolean deep) {
return ProcessingStepHandler.getStatus(this, deep);
}
+
+ /**
+ * If step has dependencies that may come and go during application's
+ * lifetime (i.e., user may uninstall CLI utility that step depended on),
+ * this method checks if such dependencies are available.
+ *
+ * @return if step's dependencies are satisfied
+ * @since 1.3
+ */
+ 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 25a099eb6..adc2fc484 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
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2007, 2017 compeople AG and others.
+* Copyright (c) 2007, 2018 compeople AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -11,14 +11,21 @@
* Contributors:
* compeople AG (Stefan Liebig) - initial API and implementation
* IBM - continuing development
+* Mykola Nikishov - continuing development
*******************************************************************************/
package org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing;
+import static java.util.Arrays.stream;
+import static java.util.Optional.ofNullable;
+import static java.util.stream.Collectors.toList;
+
import java.io.OutputStream;
import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository.ArtifactOutputStream;
+import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.provisional.p2.repository.IStateful;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
@@ -38,19 +45,49 @@ public class ProcessingStepHandler {
}
/**
- * Check to see that we have processors for all the steps in the given descriptor
+ * Check to see that we have processors for all required steps in the given descriptor
* @param descriptor the descriptor to check
* @return whether or not processors for all the descriptor's steps are installed
+ * @see IProcessingStepDescriptor#isRequired()
*/
public static boolean canProcess(IArtifactDescriptor descriptor) {
- IExtensionRegistry registry = RegistryFactory.getRegistry();
- IExtensionPoint point = registry.getExtensionPoint(PROCESSING_STEPS_EXTENSION_ID);
+ IExtensionPoint point = ofNullable(RegistryFactory.getRegistry())
+ .map(r -> r.getExtensionPoint(PROCESSING_STEPS_EXTENSION_ID))
+ .orElse(null);
if (point == null)
return false;
- IProcessingStepDescriptor[] steps = descriptor.getProcessingSteps();
- for (int i = 0; i < steps.length; i++) {
- if (point.getExtension(steps[i].getProcessorId()) == null)
- return false;
+
+ List<String> processorIds = stream(descriptor.getProcessingSteps())
+ // ignore steps that are not required
+ .filter(IProcessingStepDescriptor::isRequired)
+ .map(IProcessingStepDescriptor::getProcessorId)
+ .collect(toList());
+ try {
+ for (String processorId : processorIds) {
+ IExtension requiredExtension = point.getExtension(processorId);
+ if (requiredExtension == null)
+ return false;
+
+ List<IConfigurationElement> stepConfigs = stream(requiredExtension.getConfigurationElements())
+ // skip anything but step elements
+ .filter(config -> "step".equals(config.getName())) //$NON-NLS-1$
+ .collect(toList());
+ if (stepConfigs.size() != 1)
+ // do not tolerate no or multiple step elements
+ return false;
+
+ IConfigurationElement stepConfig = stepConfigs.get(0);
+ ProcessingStep stepToCheck = (ProcessingStep) stepConfig.createExecutableExtension("class"); //$NON-NLS-1$
+ if (!stepToCheck.isEnabled())
+ return false;
+ }
+ } catch (InvalidRegistryObjectException e) {
+ // extension is no longer valid, log and ignore
+ LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "", e)); //$NON-NLS-1$
+ return false;
+ } catch (CoreException e) {
+ // unable to instantiate an extension, already logged, ignore
+ return false;
}
return true;
}

Back to the top