Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMykola Nikishov2018-11-14 06:57:43 -0500
committerMykola Nikishov2019-01-13 22:12:07 -0500
commitd37052d1aef964673ecebeab8ed2a6fe6c4e85f7 (patch)
treec8d33d7f4a07b05f6f3a5e1207637b9a2bea7747
parent273c0702dae302ab3a650ae9e31b65e422ab4177 (diff)
downloadrt.equinox.p2-d37052d1aef964673ecebeab8ed2a6fe6c4e85f7.tar.gz
rt.equinox.p2-d37052d1aef964673ecebeab8ed2a6fe6c4e85f7.tar.xz
rt.equinox.p2-d37052d1aef964673ecebeab8ed2a6fe6c4e85f7.zip
Bug 543024 - Initialize ChecksumVerifier as ProcessingStep
According to ProcessingStep's javadoc, a processing step should be created in two steps: ProcessingStep step = new ProcessingStep(...); step.initialize(agent, processingStepDescriptor, artifactDescriptor) Only after initialization, the step is ready for linking with other steps or output streams. Let ChecksumVerifier follow this pattern. Change-Id: Ic4ff2aacb137b6bef8e616624b3d9797381f07fe Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumUtilities.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumVerifier.java31
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumVerifierTest.java9
3 files changed, 28 insertions, 16 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumUtilities.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumUtilities.java
index 317778e28..1fdf96364 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumUtilities.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumUtilities.java
@@ -25,6 +25,7 @@ import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumHelper;
import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumProducer;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
+import org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor;
import org.eclipse.osgi.util.NLS;
public class ChecksumUtilities {
@@ -56,7 +57,8 @@ public class ChecksumUtilities {
String checksumId = checksumVerifierConfiguration.getAttribute("id"); //$NON-NLS-1$
if (checksumEntry.getKey().equals(checksumId)) {
String checksumAlgorithm = checksumVerifierConfiguration.getAttribute("algorithm"); //$NON-NLS-1$
- ChecksumVerifier checksumVerifier = new ChecksumVerifier(checksumAlgorithm, checksumId, checksumEntry.getValue());
+ ChecksumVerifier checksumVerifier = new ChecksumVerifier(checksumAlgorithm, checksumId);
+ checksumVerifier.initialize(null, new ProcessingStepDescriptor(null, checksumEntry.getValue(), true), descriptor);
if (checksumVerifier.getStatus().isOK())
steps.add(checksumVerifier);
else
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumVerifier.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumVerifier.java
index 3335fdb48..d0fcb1c06 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumVerifier.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumVerifier.java
@@ -13,9 +13,10 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.processors.checksum;
+import static java.util.Optional.ofNullable;
+
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.util.Optional;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
@@ -29,20 +30,25 @@ import org.eclipse.osgi.util.NLS;
final public class ChecksumVerifier extends MessageDigestProcessingStep {
private String expectedChecksum;
- private String algorithmName;
- private String algorithmId;
+ final private String algorithmName;
+ final private String algorithmId;
// public to access from tests
- public ChecksumVerifier(String digestAlgorithm, String algorithmId, String expectedChecksum) {
+ public ChecksumVerifier(String digestAlgorithm, String algorithmId) {
this.algorithmName = digestAlgorithm;
this.algorithmId = algorithmId;
- this.expectedChecksum = expectedChecksum;
basicInitialize(null);
}
@Override
public final void initialize(IProvisioningAgent agent, IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
super.initialize(agent, descriptor, context);
+
+ basicInitialize(descriptor);
+ if (!getStatus().isOK()) {
+ return;
+ }
+
String data = descriptor.getData();
if (IArtifactDescriptor.DOWNLOAD_CHECKSUM.concat(".").concat(algorithmId).equals(data)) //$NON-NLS-1$
expectedChecksum = ChecksumHelper.getChecksums(context, IArtifactDescriptor.DOWNLOAD_CHECKSUM).get(algorithmId);
@@ -51,20 +57,27 @@ final public class ChecksumVerifier extends MessageDigestProcessingStep {
else
expectedChecksum = data;
- basicInitialize(descriptor);
+ if (ofNullable(expectedChecksum).orElse("").isEmpty()) { //$NON-NLS-1$
+ int code = buildErrorCode(descriptor);
+ setStatus(new Status(code, Activator.ID, NLS.bind(Messages.Error_invalid_checksum, algorithmName, expectedChecksum)));
+ }
+
}
private void basicInitialize(IProcessingStepDescriptor descriptor) {
- int code = (descriptor == null) ? IStatus.ERROR : descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
- if (Optional.ofNullable(expectedChecksum).orElse("").isEmpty()) //$NON-NLS-1$
- setStatus(new Status(code, Activator.ID, NLS.bind(Messages.Error_invalid_checksum, algorithmName, expectedChecksum)));
try {
messageDigest = MessageDigest.getInstance(algorithmName);
+ setStatus(Status.OK_STATUS);
} catch (NoSuchAlgorithmException e) {
+ int code = buildErrorCode(descriptor);
setStatus(new Status(code, Activator.ID, NLS.bind(Messages.Error_checksum_unavailable, algorithmName), e));
}
}
+ private int buildErrorCode(IProcessingStepDescriptor descriptor) {
+ return (descriptor == null) ? IStatus.ERROR : descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
+ }
+
@Override
final protected void onClose(String digestString) {
// if the hashes don't line up set the status to error.
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumVerifierTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumVerifierTest.java
index d7c9f5aba..3c7fe791b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumVerifierTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumVerifierTest.java
@@ -54,10 +54,9 @@ public class ChecksumVerifierTest {
public void testInitialize() throws IOException, IllegalArgumentException, SecurityException {
IProcessingStepDescriptor processingStepDescriptor = createMock(IProcessingStepDescriptor.class);
expect(processingStepDescriptor.getData()).andReturn(checksum);
- expect(processingStepDescriptor.isRequired()).andReturn(true);
replay(processingStepDescriptor);
- ChecksumVerifier verifier = new ChecksumVerifier(digestAlgorithm, algorithmId, checksum);
+ ChecksumVerifier verifier = new ChecksumVerifier(digestAlgorithm, algorithmId);
verifier.initialize(null, processingStepDescriptor, null);
@@ -71,7 +70,6 @@ public class ChecksumVerifierTest {
public void testInitialize_DownloadChecksum() throws IOException, IllegalArgumentException, SecurityException {
IProcessingStepDescriptor processingStepDescriptor = createMock(IProcessingStepDescriptor.class);
expect(processingStepDescriptor.getData()).andReturn(downloadProperty);
- expect(processingStepDescriptor.isRequired()).andReturn(true);
IArtifactDescriptor artifactDescriptor = createMock(IArtifactDescriptor.class);
replay(processingStepDescriptor);
expect(artifactDescriptor.getProperty(eq(downloadProperty))).andReturn(checksum);
@@ -81,7 +79,7 @@ public class ChecksumVerifierTest {
expect(artifactDescriptor.getProperties()).andReturn(properties);
replay(artifactDescriptor);
- ChecksumVerifier verifier = new ChecksumVerifier(digestAlgorithm, algorithmId, checksum);
+ ChecksumVerifier verifier = new ChecksumVerifier(digestAlgorithm, algorithmId);
verifier.initialize(null, processingStepDescriptor, artifactDescriptor);
@@ -95,7 +93,6 @@ public class ChecksumVerifierTest {
public void testInitialize_ArtifactChecksum() throws IOException, IllegalArgumentException, SecurityException {
IProcessingStepDescriptor processingStepDescriptor = createMock(IProcessingStepDescriptor.class);
expect(processingStepDescriptor.getData()).andReturn(artifactProperty);
- expect(processingStepDescriptor.isRequired()).andReturn(true);
IArtifactDescriptor artifactDescriptor = createMock(IArtifactDescriptor.class);
replay(processingStepDescriptor);
expect(artifactDescriptor.getProperty(eq(artifactProperty))).andReturn(checksum);
@@ -105,7 +102,7 @@ public class ChecksumVerifierTest {
expect(artifactDescriptor.getProperty(not(eq(artifactProperty)))).andReturn(null).times(1, 2);
replay(artifactDescriptor);
- ChecksumVerifier verifier = new ChecksumVerifier(digestAlgorithm, algorithmId, checksum);
+ ChecksumVerifier verifier = new ChecksumVerifier(digestAlgorithm, algorithmId);
verifier.initialize(null, processingStepDescriptor, artifactDescriptor);

Back to the top