Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Arthorne2008-02-10 17:46:21 -0500
committerJohn Arthorne2008-02-10 17:46:21 -0500
commitfa3dae8f4fb19d14dd04f4e00669a215cc6a13c8 (patch)
treecbc0dd1a91f0f6079e9b8397e6e169c79490e40e /bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing
parente615dae2244101e844d0851f3d9c8c754ffaffe0 (diff)
downloadrt.equinox.p2-fa3dae8f4fb19d14dd04f4e00669a215cc6a13c8.tar.gz
rt.equinox.p2-fa3dae8f4fb19d14dd04f4e00669a215cc6a13c8.tar.xz
rt.equinox.p2-fa3dae8f4fb19d14dd04f4e00669a215cc6a13c8.zip
Bug 218451 [prov] Rename API packages to provisional API
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.java128
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepDescriptor.java86
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java106
3 files changed, 320 insertions, 0 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
new file mode 100644
index 000000000..a9634f845
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+* Copyright (c) 2007 compeople AG 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:
+* compeople AG (Stefan Liebig) - initial API and implementation
+* IBM Corporation - continuing development
+*******************************************************************************/
+package org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IStateful;
+
+/**
+ * ProcessingSteps process the data written to them and pass the resultant data on
+ * to a configured destination stream. Steps may monitor (e.g., count) the data, compute information
+ * about the data (e.g., checksum or hash) or transform the data (e.g., unpack200).
+ */
+public abstract class ProcessingStep extends OutputStream implements IStateful {
+ //TODO It's generally not good to expose fields as API. It raises difficulties about
+ //when the subclass should be writing the fields, when the fields will have
+ //meaningful values, etc. It's generally better to pass values as parameters
+ //in a hook method rather than letting the subclass access this state directly.
+ protected OutputStream destination;
+ protected IProgressMonitor monitor;
+ protected IStatus status = Status.OK_STATUS;
+
+ protected ProcessingStep() {
+ super();
+ }
+
+ /**
+ * Initialize this processing step according to the information in the given
+ * descriptor and context. After initialization, this step is ready for linking
+ * with other steps or output streams
+ * @param descriptor description of the step
+ * @param context the context in which the step is being used
+ */
+ public void initialize(ProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
+ }
+
+ /**
+ * Link this step with the given output stream and configure the step to use the given
+ * progress monitor. After linking the step is ready to have data written to it.
+ * @param destination the stream into which to write the processed data
+ * @param monitor the progress monitor to use for reporting activity
+ */
+ public void link(OutputStream destination, IProgressMonitor monitor) {
+ this.destination = destination;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Process the given byte and pass the result on to the configured destination stream
+ * @param b the byte being written
+ */
+ public void write(int b) throws IOException {
+ }
+
+ /**
+ * Flush any unwritten data from this stream.
+ */
+ public void flush() throws IOException {
+ super.flush();
+ if (destination != null)
+ destination.flush();
+ }
+
+ /**
+ * Close this stream and, if the configured destination is a ProcessingStep,
+ * close it as well. Typically a chain of steps terminates in a conventional
+ * output stream. Implementors of this method should ensure they set the
+ * status of the step.
+ */
+ public void close() throws IOException {
+ super.close();
+ if (destination instanceof ProcessingStep)
+ destination.close();
+ monitor = null;
+ }
+
+ public IStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(IStatus status) {
+ this.status = status;
+ }
+
+ /**
+ * Return the status of this step. The status will be <code>null</code> if the
+ * step has not yet executed. If the step has executed the returned status
+ * indicates the success or failure of the step.
+ * @param deep whether or not to aggregate the status of any linked steps
+ * @return the requested status
+ */
+ public IStatus getStatus(boolean deep) {
+ if (!deep)
+ return getStatus();
+ ArrayList list = new ArrayList();
+ int severity = collectStatus(list);
+ if (severity == IStatus.OK)
+ return Status.OK_STATUS;
+ IStatus[] result = (IStatus[]) list.toArray(new IStatus[list.size()]);
+ return new MultiStatus(Activator.ID, severity, result, "Result of processing steps", null);
+ }
+
+ private int collectStatus(ArrayList list) {
+ list.add(getStatus());
+ if (!(destination instanceof ProcessingStep))
+ return getStatus().getSeverity();
+ int result = ((ProcessingStep) destination).collectStatus(list);
+ // TODO greater than test here is a little brittle but it is very unlikely that we will add
+ // a new status severity.
+ if (getStatus().getSeverity() > result)
+ return getStatus().getSeverity();
+ return result;
+
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepDescriptor.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepDescriptor.java
new file mode 100644
index 000000000..4320fb00b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepDescriptor.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+* Copyright (c) 2007 compeople AG 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:
+* compeople AG (Stefan Liebig) - initial API and implementation
+*******************************************************************************/
+package org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing;
+
+/**
+ * The description of a processor step.
+ */
+public class ProcessingStepDescriptor {
+
+ private final String processorId; //the operation to be applied (e.g: unpack, md5, signature verification, etc.)
+ private final String data; //data requested for the processing (eg. expected checksum)
+ private final boolean required; //whether the step is optional or not
+
+ /**
+ * Create a processing step description.
+ *
+ * @param processorId
+ * @param data
+ * @param required
+ */
+ public ProcessingStepDescriptor(String processorId, String data, boolean required) {
+ super();
+ this.processorId = processorId;
+ this.data = data;
+ this.required = required;
+ }
+
+ public String getProcessorId() {
+ return processorId;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((data == null) ? 0 : data.hashCode());
+ result = prime * result + ((processorId == null) ? 0 : processorId.hashCode());
+ result = prime * result + (required ? 1231 : 1237);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof ProcessingStepDescriptor))
+ return false;
+ final ProcessingStepDescriptor other = (ProcessingStepDescriptor) obj;
+ if (data == null) {
+ if (other.data != null)
+ return false;
+ } else if (!data.equals(other.data))
+ return false;
+ if (processorId == null) {
+ if (other.processorId != null)
+ return false;
+ } else if (!processorId.equals(other.processorId))
+ return false;
+ if (required != other.required)
+ return false;
+ 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
new file mode 100644
index 000000000..bdf0a41ff
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+* Copyright (c) 2007, 2008 compeople AG 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:
+* compeople AG (Stefan Liebig) - initial API and implementation
+* IBM - continuing development
+*******************************************************************************/
+package org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing;
+
+import java.io.OutputStream;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
+
+/**
+ * Creates processing step instances from extensions and executes them.
+ */
+public class ProcessingStepHandler {
+
+ private static final String PROCESSING_STEPS_EXTENSION_ID = "org.eclipse.equinox.p2.artifact.repository.processingSteps"; //$NON-NLS-1$
+
+ public static IStatus checkStatus(OutputStream output) {
+ if (!(output instanceof ProcessingStep))
+ return Status.OK_STATUS;
+ return ((ProcessingStep) output).getStatus(true);
+ }
+
+ /**
+ * Check to see that we have processors for all the steps in the given descriptor
+ * @param descriptor the descriptor to check
+ * @return whether or not processors for all the descriptor's steps are installed
+ */
+ public static boolean canProcess(IArtifactDescriptor descriptor) {
+ IExtensionRegistry registry = RegistryFactory.getRegistry();
+ IExtensionPoint point = registry.getExtensionPoint(PROCESSING_STEPS_EXTENSION_ID);
+ if (point == null)
+ return false;
+ ProcessingStepDescriptor[] steps = descriptor.getProcessingSteps();
+ for (int i = 0; i < steps.length; i++) {
+ if (point.getExtension(steps[i].getProcessorId()) == null)
+ return false;
+ }
+ return true;
+ }
+
+ public ProcessingStep[] create(ProcessingStepDescriptor[] descriptors, IArtifactDescriptor context) {
+ ProcessingStep[] result = new ProcessingStep[descriptors.length];
+ for (int i = 0; i < descriptors.length; i++)
+ result[i] = create(descriptors[i], context);
+ return result;
+ }
+
+ public ProcessingStep create(ProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
+ IExtensionRegistry registry = RegistryFactory.getRegistry();
+ IExtension extension = registry.getExtension(PROCESSING_STEPS_EXTENSION_ID, descriptor.getProcessorId());
+ Exception error;
+ if (extension != null) {
+ IConfigurationElement[] config = extension.getConfigurationElements();
+ try {
+ Object object = config[0].createExecutableExtension("class"); //$NON-NLS-1$
+ ProcessingStep step = (ProcessingStep) object;
+ step.initialize(descriptor, context);
+ return step;
+ } catch (Exception e) {
+ error = e;
+ }
+ } else
+ error = new ProcessingStepHandlerException("Could not get extension " + PROCESSING_STEPS_EXTENSION_ID + " for desriptor id " + descriptor.getProcessorId());
+
+ int severity = descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
+ ProcessingStep result = new EmptyProcessingStep();
+ result.setStatus(new Status(severity, Activator.ID, "Could not instantiate step:" + descriptor.getProcessorId(), error));
+ return result;
+ }
+
+ public OutputStream createAndLink(ProcessingStepDescriptor[] descriptors, IArtifactDescriptor context, OutputStream output, IProgressMonitor monitor) {
+ if (descriptors == null)
+ return output;
+ ProcessingStep[] steps = create(descriptors, context);
+ return link(steps, output, monitor);
+ }
+
+ public OutputStream link(ProcessingStep[] steps, OutputStream output, IProgressMonitor monitor) {
+ OutputStream previous = output;
+ for (int i = steps.length - 1; i >= 0; i--) {
+ ProcessingStep step = steps[i];
+ step.link(previous, monitor);
+ previous = step;
+ }
+ return previous;
+ }
+
+ protected static final class EmptyProcessingStep extends ProcessingStep {
+ // Just to hold the status
+ }
+
+ protected static final class ProcessingStepHandlerException extends Exception {
+ public ProcessingStepHandlerException(String message) {
+ super(message);
+ }
+ }
+}

Back to the top