diff options
author | Mykola Nikishov | 2018-06-26 09:24:37 +0000 |
---|---|---|
committer | Mykola Nikishov | 2018-12-20 19:12:48 +0000 |
commit | b8b794603e2cc67f4b2d7e5c392b6f1f8b534d86 (patch) | |
tree | efee6c0e7134cd3d9e80ee46e6a0202f9f556921 | |
parent | 27630805f3b5764e05f4101744f94caff0947099 (diff) | |
download | rt.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>
10 files changed, 155 insertions, 16 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF index 02340afdf..4306c1213 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.p2.artifact.repository;singleton:=true -Bundle-Version: 1.2.200.qualifier +Bundle-Version: 1.3.0.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.artifact.repository.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/pom.xml b/bundles/org.eclipse.equinox.p2.artifact.repository/pom.xml index 0aac67153..f38947c34 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/pom.xml +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/pom.xml @@ -9,6 +9,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.p2.artifact.repository</artifactId> - <version>1.2.200-SNAPSHOT</version> + <version>1.3.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> 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 7eb071752..c088e95ed 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 @@ -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,6 +11,7 @@ * Contributors: * compeople AG (Stefan Liebig) - initial API and implementation * IBM Corporation - ongoing development +* Mykola Nikishov - continuing development *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.processors.pack200; @@ -47,7 +48,7 @@ public class Pack200ProcessorStep extends AbstractBufferingStep { @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 +104,9 @@ public class Pack200ProcessorStep extends AbstractBufferingStep { 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 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; } diff --git a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF index c24b00f55..761be42ef 100644 --- a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.p2.tests;singleton:=true -Bundle-Version: 1.7.400.qualifier +Bundle-Version: 1.7.500.qualifier Bundle-ClassPath: . Bundle-Activator: org.eclipse.equinox.p2.tests.TestActivator Bundle-Vendor: %providerName @@ -53,7 +53,8 @@ Require-Bundle: org.eclipse.equinox.frameworkadmin, org.eclipse.equinox.p2.transport.ecf;bundle-version="1.0.0", org.eclipse.equinox.p2.publisher.eclipse;bundle-version="1.0.0", org.eclipse.equinox.p2.operations;bundle-version="2.1.0", - org.eclipse.equinox.p2.ui.sdk.scheduler + org.eclipse.equinox.p2.ui.sdk.scheduler, + org.eclipse.equinox.p2.artifact.repository;bundle-version="[1.3.0,2.0.0)" Eclipse-RegisterBuddy: org.eclipse.equinox.p2.artifact.repository Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Eclipse-BundleShape: dir diff --git a/bundles/org.eclipse.equinox.p2.tests/plugin.xml b/bundles/org.eclipse.equinox.p2.tests/plugin.xml index 70f56fb29..841b529ea 100644 --- a/bundles/org.eclipse.equinox.p2.tests/plugin.xml +++ b/bundles/org.eclipse.equinox.p2.tests/plugin.xml @@ -37,6 +37,18 @@ id="org.eclipse.equinox.p2.processing.Multiplier"> <step class="org.eclipse.equinox.p2.tests.artifact.repository.processing.Multiplier"/> </extension> + <extension + point="org.eclipse.equinox.p2.artifact.repository.processingSteps" + id="org.eclipse.equinox.p2.processing.AlwaysDisabled"> + <step class="org.eclipse.equinox.p2.tests.artifact.repository.processing.AlwaysDisabled"/> + </extension> + <extension + point="org.eclipse.equinox.p2.artifact.repository.processingSteps" + id="org.eclipse.equinox.p2.processing.MultipleSteps"> + <step class="org.eclipse.equinox.p2.tests.artifact.repository.processing.Adder"/> + <step class="org.eclipse.equinox.p2.tests.artifact.repository.processing.ByteShifter"/> + <step class="org.eclipse.equinox.p2.tests.artifact.repository.processing.Multiplier"/> + </extension> <extension point="org.eclipse.equinox.p2.engine.actions"> <action diff --git a/bundles/org.eclipse.equinox.p2.tests/pom.xml b/bundles/org.eclipse.equinox.p2.tests/pom.xml index 5c8d6bb61..f29c44ced 100644 --- a/bundles/org.eclipse.equinox.p2.tests/pom.xml +++ b/bundles/org.eclipse.equinox.p2.tests/pom.xml @@ -16,7 +16,7 @@ <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.p2.tests</artifactId> - <version>1.7.400-SNAPSHOT</version> + <version>1.7.500-SNAPSHOT</version> <packaging>eclipse-test-plugin</packaging> <properties> diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/AlwaysDisabled.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/AlwaysDisabled.java new file mode 100644 index 000000000..6835e99de --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/AlwaysDisabled.java @@ -0,0 +1,28 @@ +/******************************************************************************* +* Copyright (c) 2018 Mykola Nikishov. +* +* This program and the accompanying materials +* are made available under the terms of the Eclipse Public License 2.0 +* which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-2.0/ +* +* SPDX-License-Identifier: EPL-2.0 +* +* Contributors: +* Mykola Nikishov - initial API and implementation +*******************************************************************************/ +package org.eclipse.equinox.p2.tests.artifact.repository.processing; + +import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep; + +public class AlwaysDisabled extends ProcessingStep { + + public AlwaysDisabled() { + // needed + } + + @Override + public boolean isEnabled() { + return false; + } +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java index 04216eb73..c8df6b48d 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.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,6 +11,7 @@ * Contributors: * compeople AG (Stefan Liebig) - initial API and implementation * IBM - continuing development +* Mykola Nikishov - continuing development *******************************************************************************/ package org.eclipse.equinox.p2.tests.artifact.repository.processing; @@ -27,9 +28,11 @@ import org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5Verifier; import org.eclipse.equinox.internal.p2.artifact.processors.pack200.Pack200ProcessorStep; import org.eclipse.equinox.internal.p2.core.helpers.FileUtils; import org.eclipse.equinox.internal.p2.jarprocessor.PackStep; +import org.eclipse.equinox.internal.p2.metadata.ArtifactKey; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepHandler; import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; import org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor; import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; import org.eclipse.equinox.p2.tests.TestActivator; @@ -41,6 +44,45 @@ public class ProcessingStepHandlerTest extends AbstractProvisioningTest { ProcessingStepHandler handler = new ProcessingStepHandler(); IProgressMonitor monitor = new NullProgressMonitor(); + public void testCanProcess_Ok() { + ArtifactDescriptor descriptor = new ArtifactDescriptor(ArtifactKey.parse("classifier,id,1.0.0")); + descriptor.setProcessingSteps(new ProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true)}); + + assertTrue(ProcessingStepHandler.canProcess(descriptor)); + } + + public void testCanProcess_FailNoSuchStep() { + String noSuchStepId = "org.eclipse.equinox.p2.processing.test.Dummy"; + ArtifactDescriptor descriptor = new ArtifactDescriptor(ArtifactKey.parse("classifier,id,1.0.0")); + descriptor.setProcessingSteps(new ProcessingStepDescriptor[] {new ProcessingStepDescriptor(noSuchStepId, null, true), new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.ByteShifter", "1", true)}); + + assertFalse(ProcessingStepHandler.canProcess(descriptor)); + } + + public void testCanProcess_FailAlwaysDisabled() { + ArtifactDescriptor descriptor = new ArtifactDescriptor(ArtifactKey.parse("classifier,id,1.0.0")); + String processorId = "org.eclipse.equinox.p2.processing.AlwaysDisabled"; + descriptor.setProcessingSteps(new ProcessingStepDescriptor[] {new ProcessingStepDescriptor(processorId, null, true), new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.ByteShifter", "1", true)}); + + assertFalse(ProcessingStepHandler.canProcess(descriptor)); + } + + public void testCanProcess_OkOptionalAlwaysDisabled() { + ArtifactDescriptor descriptor = new ArtifactDescriptor(ArtifactKey.parse("classifier,id,1.0.0")); + String processorId = "org.eclipse.equinox.p2.processing.AlwaysDisabled"; + descriptor.setProcessingSteps(new ProcessingStepDescriptor[] {new ProcessingStepDescriptor(processorId, null, false), new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.ByteShifter", "1", true)}); + + assertTrue("Not enabled optional step should not block processing", ProcessingStepHandler.canProcess(descriptor)); + } + + public void testCanProcess_FailMultipleSteps() { + ArtifactDescriptor descriptor = new ArtifactDescriptor(ArtifactKey.parse("classifier,id,1.0.0")); + String processorId = "org.eclipse.equinox.p2.processing.MultipleSteps"; + descriptor.setProcessingSteps(new ProcessingStepDescriptor[] {new ProcessingStepDescriptor(processorId, null, true), new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.ByteShifter", "1", true)}); + + assertFalse(String.format("Multiple step attributes in %s are not supported", processorId), ProcessingStepHandler.canProcess(descriptor)); + } + public void testExecuteNoPSs() throws IOException { IProcessingStepDescriptor[] descriptors = new IProcessingStepDescriptor[0]; OutputStream result = new ByteArrayOutputStream(10); |