diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository/src/org')
41 files changed, 649 insertions, 2211 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/FileMirrorLog.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/FileMirrorLog.java deleted file mode 100644 index a0602b4d2..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/FileMirrorLog.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.p2.artifact.mirror; - -import java.io.*; -import java.util.Date; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.p2.artifact.repository.Messages; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor; - -public class FileMirrorLog implements IArtifactMirrorLog { - - private static final String INDENT = "\t"; //$NON-NLS-1$ - private static final String SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$ - private BufferedWriter out; - private boolean consoleMessage = false; - private int minSeverity = IStatus.OK; - private boolean hasRoot = false; - - public FileMirrorLog(String location, int minSeverity, String root) { - this.minSeverity = minSeverity; - try { - File log = new File(location); - if (log.getParentFile().exists() || log.getParentFile().mkdirs()) { - out = new BufferedWriter(new FileWriter(log, true)); - if (root != null) { - log(root + " - " + new Date()); //$NON-NLS-1$ - hasRoot = true; - } - } else - throw new IOException(Messages.exception_unableToCreateParentDir); - } catch (IOException e) { - exceptionOccurred(null, e); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#log(org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor, org.eclipse.core.runtime.IStatus) - */ - public void log(IArtifactDescriptor descriptor, IStatus status) { - if (status.getSeverity() >= minSeverity) { - log(descriptor.toString()); - log(status, INDENT); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#log(org.eclipse.core.runtime.IStatus) - */ - public void log(IStatus status) { - log(status, ""); //$NON-NLS-1$ - } - - /* - * Write a status to the log, indenting it based on status depth. - * @param status the status to log - * @param depth the depth of the status - */ - private void log(IStatus status, String prefix) { - if (status.getSeverity() >= minSeverity) { - // Write status to log - log(prefix + status.getMessage()); - - // Write exception to log if applicable - String exceptionMessage = status.getException() != null ? status.getException().getMessage() : null; - if (exceptionMessage != null) - log(prefix + exceptionMessage); - - // Write the children of the status to the log - IStatus[] nestedStatus = status.getChildren(); - if (nestedStatus != null) - for (int i = 0; i < nestedStatus.length; i++) - log(nestedStatus[i], prefix + INDENT); - } - } - - /* - * Write a message to the log - * @param message the message to write - */ - private void log(String message) { - try { - out.write((hasRoot ? INDENT : "") + message + SEPARATOR); //$NON-NLS-1$ - } catch (IOException e) { - exceptionOccurred((hasRoot ? INDENT : "") + message, e); //$NON-NLS-1$ - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#close() - */ - public void close() { - try { - if (out != null) - out.close(); - } catch (IOException e) { - exceptionOccurred(null, e); - } - } - - /* - * Show an error message if this the first time, and print status messages. - */ - private void exceptionOccurred(String message, Exception e) { - if (!consoleMessage) { - System.err.println(Messages.MirrorLog_Exception_Occurred); - e.printStackTrace(System.err); - System.err.println(Messages.MirrorLog_Console_Log); - consoleMessage = true; - } - if (message != null) - System.out.println(message); - } -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/IArtifactMirrorLog.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/IArtifactMirrorLog.java deleted file mode 100644 index 959a7a35d..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/IArtifactMirrorLog.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.p2.artifact.mirror; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor; - -public interface IArtifactMirrorLog { - - // Log a status associated with a descriptor - public void log(IArtifactDescriptor descriptor, IStatus status); - - // Log a status - public void log(IStatus status); - - // Notify that logging is completed & cleanup resources - public void close(); -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java deleted file mode 100644 index 83983b520..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java +++ /dev/null @@ -1,263 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.p2.artifact.mirror; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Map; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.URIUtil; -import org.eclipse.equinox.app.IApplication; -import org.eclipse.equinox.app.IApplicationContext; -import org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5ArtifactComparator; -import org.eclipse.equinox.internal.p2.artifact.repository.*; -import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; -import org.eclipse.osgi.framework.log.FrameworkLog; -import org.eclipse.osgi.util.NLS; - -/** - * An application that performs mirroring of artifacts between repositories. - */ -public class MirrorApplication implements IApplication { - - private URI sourceLocation; - private URI destinationLocation; - private URI baselineLocation; - private IArtifactRepository source; - private IArtifactRepository destination; - private IArtifactRepository baseline; - private boolean append = true; - private boolean raw = false; - private boolean failOnError = true; - private boolean validate = false; - private boolean verbose = false; - private IArtifactRepositoryManager cachedManager; - private boolean sourceLoaded = false; - private boolean destinationLoaded = false; - private boolean baselineLoaded = false; - private boolean compare = false; - private String comparatorID = MD5ArtifactComparator.MD5_COMPARATOR_ID; //use MD5 as default - private String destinationName; - private IArtifactMirrorLog mirrorLog; - private IArtifactMirrorLog comparatorLog; - - /* (non-Javadoc) - * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext) - */ - public Object start(IApplicationContext context) throws Exception { - try { - Map args = context.getArguments(); - initializeFromArguments((String[]) args.get(IApplicationContext.APPLICATION_ARGS)); - setupRepositories(); - - Mirroring mirroring = new Mirroring(source, destination, raw); - mirroring.setCompare(compare); - mirroring.setComparatorId(comparatorID); - mirroring.setBaseline(baseline); - mirroring.setValidate(validate); - if (comparatorLog != null) - mirroring.setComparatorLog(comparatorLog); - - IStatus result = mirroring.run(failOnError, verbose); - if (!result.isOK()) { - //only noteworthy statuses should be resulted from mirroring.run - if (result.matches(IStatus.INFO)) - System.err.println("Mirroring completed. Please check log file for more information."); //$NON-NLS-1$ - else - System.err.println("Mirroring completed with warnings and/or errors. Please check log file for more information."); //$NON-NLS-1$ - log(result); - } - return IApplication.EXIT_OK; - } catch (Exception e) { - System.err.println(e.getMessage()); - throw e; - } finally { - cleanup(); - } - } - - /* - * Return the artifact repository manager. We need to check the service here - * as well as creating one manually in case we are running a stand-alone application - * in which no one has registered a manager yet. - */ - private IArtifactRepositoryManager getManager() { - if (cachedManager != null) - return cachedManager; - IArtifactRepositoryManager result = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); - // service not available... create one and hang onto it - if (result == null) { - cachedManager = new ArtifactRepositoryManager(); - result = cachedManager; - } - return result; - } - - private void setupRepositories() throws ProvisionException { - if (destinationLocation == null || sourceLocation == null) - throw new IllegalStateException(Messages.exception_needSourceDestination); - - //Check if repositories are already loaded - sourceLoaded = getManager().contains(sourceLocation); - destinationLoaded = getManager().contains(destinationLocation); - - //must execute before initializeDestination is called - source = getManager().loadRepository(sourceLocation, 0, null); - destination = initializeDestination(); - - if (baselineLocation != null) { - baselineLoaded = getManager().contains(baselineLocation); - try { - baseline = getManager().loadRepository(baselineLocation, 0, null); - } catch (ProvisionException e) { - // catch the exception and log it. we will continue without doing a baseline comparison - System.err.println("Error occurred while trying to load baseline repository."); - e.printStackTrace(); - } - } - } - - private IArtifactRepository initializeDestination() throws ProvisionException { - try { - IArtifactRepository repository = getManager().loadRepository(destinationLocation, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); - if (repository != null && repository.isModifiable()) { - if (destinationName != null) - repository.setName(destinationName); - if (!append) - repository.removeAll(); - return repository; - } - } catch (ProvisionException e) { - //fall through and create a new repository below - } - //This code assumes source has been successfully loaded before this point - //No existing repository; create a new repository at destinationLocation but with source's attributes. - // TODO for now create a Simple repo by default. - return (IArtifactRepository) RepositoryHelper.validDestinationRepository(getManager().createRepository(destinationLocation, destinationName == null ? source.getName() : destinationName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, source.getProperties())); - } - - /* (non-Javadoc) - * @see org.eclipse.equinox.app.IApplication#stop() - */ - public void stop() { - // nothing to do - } - - public void initializeFromArguments(String[] args) throws Exception { - if (args == null) - return; - - String comparatorLogLocation = null; - String mirrorLogLocation = null; - - for (int i = 0; i < args.length; i++) { - // check for args without parameters (i.e., a flag arg) - if (args[i].equalsIgnoreCase("-raw")) //$NON-NLS-1$ - raw = true; - if (args[i].equalsIgnoreCase("-ignoreErrors")) //$NON-NLS-1$ - failOnError = false; - if (args[i].equalsIgnoreCase("-verbose")) //$NON-NLS-1$ - verbose = true; - if (args[i].equalsIgnoreCase("-compare")) //$NON-NLS-1$ - compare = true; - if (args[i].equalsIgnoreCase("-validate")) //$NON-NLS-1$ - validate = true; - - // check for args with parameters. If we are at the last argument or - // if the next one has a '-' as the first character, then we can't have - // an arg with a param so continue. - if (i == args.length - 1 || args[i + 1].startsWith("-")) //$NON-NLS-1$ - continue; - String arg = args[++i]; - - if (args[i - 1].equalsIgnoreCase("-comparator")) //$NON-NLS-1$ - comparatorID = arg; - if (args[i - 1].equalsIgnoreCase("-comparatorLog")) //$NON-NLS-1$ - comparatorLogLocation = arg; - if (args[i - 1].equalsIgnoreCase("-destinationName")) //$NON-NLS-1$ - destinationName = arg; - if (args[i - 1].equalsIgnoreCase("-writeMode")) //$NON-NLS-1$ - if (args[i].equalsIgnoreCase("clean")) //$NON-NLS-1$ - append = false; - if (args[i - 1].equalsIgnoreCase("-log")) //$NON-NLS-1$ - mirrorLogLocation = arg; - - try { - if (args[i - 1].equalsIgnoreCase("-source")) //$NON-NLS-1$ - sourceLocation = RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg)); - if (args[i - 1].equalsIgnoreCase("-destination")) //$NON-NLS-1$ - destinationLocation = RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg)); - if (args[i - 1].equalsIgnoreCase("-compareAgainst")) { //$NON-NLS-1$ - baselineLocation = RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg)); - compare = true; - } - } catch (URISyntaxException e) { - throw new IllegalArgumentException(NLS.bind(Messages.exception_malformedRepoURI, arg)); - } - } - // Create logs - if (mirrorLogLocation != null) - mirrorLog = getLog(mirrorLogLocation, "p2.artifact.mirror"); //$NON-NLS-1$ - if (comparatorLogLocation != null && comparatorID != null) - comparatorLog = getLog(comparatorLogLocation, comparatorID); - } - - public void setLog(IArtifactMirrorLog log) { - mirrorLog = log; - } - - /* - * Create a MirrorLog based on a filename - */ - private IArtifactMirrorLog getLog(String location, String root) { - if (location.toLowerCase().endsWith(".xml")) //$NON-NLS-1$ - return new XMLMirrorLog(location, verbose ? IStatus.INFO : IStatus.ERROR, root); - return new FileMirrorLog(location, verbose ? IStatus.INFO : IStatus.ERROR, root); - } - - /* - * Log the result of mirroring - */ - private void log(IStatus status) { - if (mirrorLog == null) { - FrameworkLog log = (FrameworkLog) ServiceHelper.getService(Activator.getContext(), FrameworkLog.class.getName()); - if (log != null) - System.err.println("Log file location: " + log.getFile()); //$NON-NLS-1$ - LogHelper.log(status); - } else - mirrorLog.log(status); - } - - /* - * Cleanup - */ - private void cleanup() { - //if the repository was not already loaded before the mirror application started, close it. - if (!sourceLoaded && sourceLocation != null) - getManager().removeRepository(sourceLocation); - if (!destinationLoaded && destinationLocation != null) - getManager().removeRepository(destinationLocation); - if (baselineLocation != null && !baselineLoaded) - getManager().removeRepository(baselineLocation); - - // Close logs - if (mirrorLog != null) - mirrorLog.close(); - if (comparatorLog != null) - comparatorLog.close(); - } -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/Mirroring.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/Mirroring.java deleted file mode 100644 index 45573693b..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/Mirroring.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - * Compeople AG (Stefan Liebig) - various ongoing maintenance - *******************************************************************************/ -package org.eclipse.equinox.internal.p2.artifact.mirror; - -import java.util.*; -import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.osgi.util.NLS; - -/** - * A utility class that performs mirroring of artifacts between repositories. - */ -public class Mirroring { - private IArtifactRepository source; - private IArtifactRepository destination; - private IArtifactRepository baseline; - private boolean raw; - private boolean compare = false; - private boolean validate = false; - private IArtifactComparator comparator; - private String comparatorID; - private IArtifactKey[] keysToMirror; - private IArtifactMirrorLog comparatorLog; - - private IArtifactComparator getComparator() { - if (comparator == null) - comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID); - return comparator; - } - - public Mirroring(IArtifactRepository source, IArtifactRepository destination, boolean raw) { - this.source = source; - this.destination = destination; - this.raw = raw; - } - - public void setCompare(boolean compare) { - this.compare = compare; - } - - public void setComparatorId(String id) { - this.comparatorID = id; - } - - public void setComparatorLog(IArtifactMirrorLog comparatorLog) { - this.comparatorLog = comparatorLog; - } - - public void setBaseline(IArtifactRepository baseline) { - this.baseline = baseline; - } - - public void setValidate(boolean validate) { - this.validate = validate; - } - - public MultiStatus run(boolean failOnError, boolean verbose) { - if (!destination.isModifiable()) - throw new IllegalStateException(NLS.bind(Messages.exception_destinationNotModifiable, destination.getLocation())); - if (compare) - getComparator(); //initialize the comparator. Only needed if we're comparing. Used to force error if comparatorID is invalid. - IArtifactKey[] keys = keysToMirror == null ? source.getArtifactKeys() : keysToMirror; - MultiStatus multiStatus = new MultiStatus(Activator.ID, IStatus.OK, Messages.message_mirroringStatus, null); - for (int i = 0; i < keys.length; i++) { - IArtifactKey key = keys[i]; - IArtifactDescriptor[] descriptors = source.getArtifactDescriptors(key); - for (int j = 0; j < descriptors.length; j++) { - IStatus result = mirror(descriptors[j], verbose); - //Only log INFO and WARNING if we want verbose logging. Always log ERRORs - if (!result.isOK() && (verbose || result.getSeverity() == IStatus.ERROR)) - multiStatus.add(result); - //stop mirroring as soon as we have an error - if (failOnError && multiStatus.getSeverity() == IStatus.ERROR) - return multiStatus; - } - } - if (validate) { - // Simple validation of the mirror - IStatus validation = validateMirror(verbose); - if (!validation.isOK() && (verbose || validation.getSeverity() == IStatus.ERROR)) - multiStatus.add(validation); - } - return multiStatus; - } - - private IStatus mirror(IArtifactDescriptor descriptor, boolean verbose) { - IArtifactDescriptor newDescriptor = raw ? descriptor : new ArtifactDescriptor(descriptor); - - if (verbose) - System.out.println("Mirroring: " + descriptor.getArtifactKey() + " (Descriptor: " + descriptor + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - if (compare && baseline != null) - if (baseline.contains(descriptor)) { - // we have to create an output stream based on the descriptor found in the baseline otherwise all - // the properties will be copied over from the wrong descriptor and our repository will be inconsistent. - IArtifactDescriptor baselineDescriptor = getBaselineDescriptor(descriptor); - - // if we found a descriptor in the baseline then we'll use it to copy the artifact - if (baselineDescriptor != null) { - MultiStatus status = new MultiStatus(Activator.ID, IStatus.OK, NLS.bind(Messages.Mirroring_compareAndDownload, descriptor), null); - //Compare source against baseline - IStatus comparison = getComparator().compare(baseline, baselineDescriptor, source, descriptor); - if (comparatorLog != null) - comparatorLog.log(baselineDescriptor, comparison); - status.add(comparison); - if (destination.contains(baselineDescriptor)) - return compareToDestination(baselineDescriptor); - - //download artifact from baseline - status.add(downloadArtifact(baseline, baselineDescriptor, baselineDescriptor)); - return status; - } - } - - // Check if the destination already contains the file. - if (destination.contains(newDescriptor)) { - if (compare) - return compareToDestination(descriptor); - String message = NLS.bind(Messages.mirror_alreadyExists, descriptor, destination); - return new Status(IStatus.INFO, Activator.ID, ProvisionException.ARTIFACT_EXISTS, message, null); - } - - return downloadArtifact(source, newDescriptor, descriptor); - } - - /** - * Takes an IArtifactDescriptor descriptor and the ProvisionException that was thrown when destination.getOutputStream(descriptor) - * and compares descriptor to the duplicate descriptor in the destination. - * - * Callers should verify the ProvisionException was thrown due to the artifact existing in the destination before invoking this method. - * @param descriptor - * @return the status of the compare - */ - private IStatus compareToDestination(IArtifactDescriptor descriptor) { - IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(descriptor.getArtifactKey()); - IArtifactDescriptor destDescriptor = null; - for (int i = 0; destDescriptor == null && i < destDescriptors.length; i++) { - if (destDescriptors[i].equals(descriptor)) - destDescriptor = destDescriptors[i]; - } - if (destDescriptor == null) - return new Status(IStatus.INFO, Activator.ID, ProvisionException.ARTIFACT_EXISTS, Messages.Mirroring_NO_MATCHING_DESCRIPTOR, null); - return compare(source, descriptor, destination, destDescriptor); - } - - private IStatus compare(IArtifactRepository sourceRepository, IArtifactDescriptor sourceDescriptor, IArtifactRepository destRepository, IArtifactDescriptor destDescriptor) { - IStatus comparison = getComparator().compare(sourceRepository, sourceDescriptor, destRepository, destDescriptor); - if (comparatorLog != null) - comparatorLog.log(sourceDescriptor, comparison); - return comparison; - } - - /* - * Create, and execute a MirrorRequest for a given descriptor. - */ - private IStatus downloadArtifact(IArtifactRepository sourceRepo, IArtifactDescriptor destDescriptor, IArtifactDescriptor srcDescriptor) { - RawMirrorRequest request = new RawMirrorRequest(srcDescriptor, destDescriptor, destination); - request.setSourceRepository(sourceRepo); - - request.perform(new NullProgressMonitor()); - - return request.getResult(); - } - - public void setArtifactKeys(IArtifactKey[] keys) { - this.keysToMirror = keys; - } - - /* - * Get the equivalent descriptor from the baseline repository - */ - private IArtifactDescriptor getBaselineDescriptor(IArtifactDescriptor descriptor) { - IArtifactDescriptor[] baselineDescriptors = baseline.getArtifactDescriptors(descriptor.getArtifactKey()); - for (int i = 0; i < baselineDescriptors.length; i++) { - if (baselineDescriptors[i].equals(descriptor)) - return baselineDescriptors[i]; - } - return null; - } - - /* - * Simple validation of a mirror to see if all source descriptors are present in the destination - */ - private IStatus validateMirror(boolean verbose) { - MultiStatus status = new MultiStatus(Activator.ID, 0, Messages.Mirroring_ValidationError, null); - - // The keys that were mirrored in this session - IArtifactKey[] keys = keysToMirror == null ? source.getArtifactKeys() : keysToMirror; - - for (int i = 0; i < keys.length; i++) { - IArtifactDescriptor[] srcDescriptors = source.getArtifactDescriptors(keys[i]); - IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(keys[i]); - - Arrays.sort(srcDescriptors, new ArtifactDescriptorComparator()); - Arrays.sort(destDescriptors, new ArtifactDescriptorComparator()); - - int src = 0; - int dest = 0; - while (src < srcDescriptors.length && dest < destDescriptors.length) { - if (!destDescriptors[dest].equals(srcDescriptors[src])) { - if (destDescriptors[dest].toString().compareTo((srcDescriptors[src].toString())) > 0) { - // Missing an artifact - if (verbose) - System.out.println(NLS.bind(Messages.Mirroring_MISSING_DESCRIPTOR, srcDescriptors[src])); - status.add(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Mirroring_MISSING_DESCRIPTOR, srcDescriptors[src++]))); - } else { - // Its okay if there are extra descriptors in the destination - dest++; - } - } else { - // check properties for differences - Map destMap = destDescriptors[dest].getProperties(); - Map srcProperties = null; - if (baseline != null) { - IArtifactDescriptor baselineDescriptor = getBaselineDescriptor(destDescriptors[dest]); - if (baselineDescriptor != null) - srcProperties = baselineDescriptor.getProperties(); - } - // Baseline not set, or could not find descriptor so we'll use the source descriptor - if (srcProperties == null) - srcProperties = srcDescriptors[src].getProperties(); - - // Cycle through properties of the originating descriptor & compare - for (Iterator iter = srcProperties.keySet().iterator(); iter.hasNext();) { - String key = (String) iter.next(); - if (!srcProperties.get(key).equals(destMap.get(key))) { - if (verbose) - System.out.println(NLS.bind(Messages.Mirroring_DIFFERENT_DESCRIPTOR_PROPERTY, new Object[] {destDescriptors[dest], key, srcProperties.get(key), destMap.get(key)})); - status.add(new Status(IStatus.WARNING, Activator.ID, NLS.bind(Messages.Mirroring_DIFFERENT_DESCRIPTOR_PROPERTY, new Object[] {destDescriptors[dest], key, srcProperties.get(key), destMap.get(key)}))); - } - } - src++; - dest++; - } - } - - // If there are still source descriptors they're missing from the destination repository - while (src < srcDescriptors.length) { - if (verbose) - System.out.println(NLS.bind(Messages.Mirroring_MISSING_DESCRIPTOR, srcDescriptors[src])); - status.add(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Mirroring_MISSING_DESCRIPTOR, srcDescriptors[src++]))); - } - } - - return status; - } - - // Simple comparator for ArtifactDescriptors - protected class ArtifactDescriptorComparator implements Comparator { - - public int compare(Object arg0, Object arg1) { - if (arg0 != null && arg1 != null) - return arg0.toString().compareTo(arg1.toString()); - else if (arg1 == null && arg0 == null) - return 0; - else if (arg1 == null) - return 1; - return -1; - } - } -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/XMLMirrorLog.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/XMLMirrorLog.java deleted file mode 100644 index 81e56d5da..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/XMLMirrorLog.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.p2.artifact.mirror; - -import java.io.*; -import java.util.Date; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.p2.artifact.repository.Messages; -import org.eclipse.equinox.internal.p2.persistence.XMLWriter; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor; - -public class XMLMirrorLog implements IArtifactMirrorLog { - private static final String DEFAULT_FORMAT = "canonical"; //$NON-NLS-1$ - // Constants used in XML tags - private static final String LOG = "log"; //$NON-NLS-1$ - private static final String TIME_ATTRIBUTE = "time"; //$NON-NLS-1$ - private static final String DESCRIPTOR_ELEMENT = "descriptor"; //$NON-NLS-1$ - private static final String DESCRIPTOR_CLASSIFIER_ATTRIBUTE = "classifier"; //$NON-NLS-1$ - private static final String DESCRIPTOR_FORMAT_ATTRIBUTE = "format"; //$NON-NLS-1$ - private static final String DESCRIPTOR_ID_ATTRIBUTE = "id"; //$NON-NLS-1$ - private static final String DESCRIPTOR_VERSION_ATTRIBUTE = "version"; //$NON-NLS-1$ - private static final String STATUS_ELEMENT = "status"; //$NON-NLS-1$ - private static final String STATUS_SEVERITY_ATTRIBUTE = "severity"; //$NON-NLS-1$ - private static final String STATUS_MESSAGE_ATTRIBUTE = "message"; //$NON-NLS-1$ - - private int minStatus = IStatus.OK; - private XMLWriter writer; - private OutputStream outputStream; - private boolean consoleMessage = false; - - public XMLMirrorLog(String location, int minStatus, String root) { - this.minStatus = minStatus; - - try { - outputStream = new FileOutputStream(location); - writer = new XMLWriter(outputStream, null); - if (root != null) - writer.start(root.toLowerCase()); - else - writer.start(LOG); - writer.attribute(TIME_ATTRIBUTE, new Date()); - } catch (UnsupportedEncodingException e) { - exceptionOccurred(e); - } catch (FileNotFoundException e) { - exceptionOccurred(e); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#log(org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor, org.eclipse.core.runtime.IStatus) - */ - public void log(IArtifactDescriptor descriptor, IStatus status) { - if (status.getSeverity() < minStatus) - return; - // Start descriptor tag - if (writer != null) { - writer.start(DESCRIPTOR_ELEMENT); - writer.attribute(DESCRIPTOR_ID_ATTRIBUTE, descriptor.getArtifactKey().getId()); - writer.attribute(DESCRIPTOR_CLASSIFIER_ATTRIBUTE, descriptor.getArtifactKey().getClassifier()); - writer.attribute(DESCRIPTOR_VERSION_ATTRIBUTE, descriptor.getArtifactKey().getVersion()); - if (descriptor.getProperties().get(IArtifactDescriptor.FORMAT) != null) - writer.attribute(DESCRIPTOR_FORMAT_ATTRIBUTE, descriptor.getProperties().get(IArtifactDescriptor.FORMAT)); - else - writer.attribute(DESCRIPTOR_FORMAT_ATTRIBUTE, DEFAULT_FORMAT); - } else - // Creation of the XML writer failed, dump results to the console - System.out.println(descriptor); - - log(status); - - // Close descriptor tag - if (writer != null) - writer.end(); - } - - /* - * (non-Javadoc) - * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#log(org.eclipse.core.runtime.IStatus) - */ - public void log(IStatus status) { - if (status.getSeverity() < minStatus) - return; - - if (writer != null) { - // Start status tag - writer.start(STATUS_ELEMENT); - // Set severity attribute - switch (status.getSeverity()) { - case IStatus.OK : - writer.attribute(STATUS_SEVERITY_ATTRIBUTE, "OK"); //$NON-NLS-1$ - break; - case IStatus.INFO : - writer.attribute(STATUS_SEVERITY_ATTRIBUTE, "INFO"); //$NON-NLS-1$ - break; - case IStatus.WARNING : - writer.attribute(STATUS_SEVERITY_ATTRIBUTE, "WARNING"); //$NON-NLS-1$ - break; - case IStatus.ERROR : - writer.attribute(STATUS_SEVERITY_ATTRIBUTE, "ERROR"); //$NON-NLS-1$ - break; - case IStatus.CANCEL : - writer.attribute(STATUS_SEVERITY_ATTRIBUTE, "CANCEL"); //$NON-NLS-1$ - break; - default : - writer.attribute(STATUS_SEVERITY_ATTRIBUTE, status.getSeverity()); - } - // Set message attribute - writer.attribute(STATUS_MESSAGE_ATTRIBUTE, status.getMessage()); - } else - // Creation of the XML writer failed, dump results to the console - System.out.println(status); - - // Log children statuses - IStatus[] nestedStatus = status.getChildren(); - if (nestedStatus != null) - for (int i = 0; i < nestedStatus.length; i++) - log(nestedStatus[i]); - - // Close status tag - if (writer != null) - writer.end(); - } - - /* - * (non-Javadoc) - * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#close() - */ - public void close() { - try { - if (writer != null) { - // Close opening tag & flush results - writer.end(); - writer.flush(); - } - } finally { - if (outputStream != null) - try { - // Close output stream - outputStream.close(); - } catch (IOException e) { - exceptionOccurred(e); - } - } - } - - /* - * Show an error message if this the first time - */ - private void exceptionOccurred(Exception e) { - if (!consoleMessage) { - System.err.println(Messages.MirrorLog_Exception_Occurred); - e.printStackTrace(System.err); - System.err.println(Messages.MirrorLog_Console_Log); - consoleMessage = true; - } - } -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5ArtifactComparator.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5ArtifactComparator.java deleted file mode 100644 index 52c61ad02..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5ArtifactComparator.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.equinox.internal.p2.artifact.processors.md5; - -import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.artifact.repository.Activator; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.osgi.util.NLS; - -public class MD5ArtifactComparator implements IArtifactComparator { - - public static String MD5_COMPARATOR_ID = "org.eclipse.equinox.artifact.md5.comparator"; //$NON-NLS-1$ - - public IStatus compare(IArtifactRepository source, IArtifactDescriptor sourceDescriptor, IArtifactRepository destination, IArtifactDescriptor destDescriptor) { - String sourceMD5 = sourceDescriptor.getProperty(IArtifactDescriptor.DOWNLOAD_MD5); - String destMD5 = destDescriptor.getProperty(IArtifactDescriptor.DOWNLOAD_MD5); - - if (sourceMD5 == null && destMD5 == null) - return new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.info_noMD5Infomation, sourceDescriptor)); - - if (sourceMD5 == null) - return new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.info_noMD5InRepository, source, sourceDescriptor)); - - if (destMD5 == null) - return new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.info_noMD5InRepository, destination, destDescriptor)); - - if (sourceMD5.equals(destMD5)) - return Status.OK_STATUS; - - return new Status(IStatus.WARNING, Activator.ID, NLS.bind(Messages.warning_differentMD5, new Object[] {URIUtil.toUnencodedString(sourceDescriptor.getRepository().getLocation()), URIUtil.toUnencodedString(destDescriptor.getRepository().getLocation()), sourceDescriptor})); - } -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5Verifier.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5Verifier.java index 3e102c43f..d79f88394 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5Verifier.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5Verifier.java @@ -11,15 +11,16 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.processors.md5; +import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor; + import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; 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.processing.ProcessingStep; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; import org.eclipse.osgi.util.NLS; public class MD5Verifier extends ProcessingStep { @@ -38,7 +39,7 @@ public class MD5Verifier extends ProcessingStep { } //This handle the case where the MD5 verification is initiated by a processing step - public void initialize(ProcessingStepDescriptor descriptor, IArtifactDescriptor context) { + public void initialize(IProcessingStepDescriptor descriptor, IArtifactDescriptor context) { super.initialize(descriptor, context); String data = descriptor.getData(); if (IArtifactDescriptor.DOWNLOAD_MD5.equals(data)) @@ -50,7 +51,7 @@ public class MD5Verifier extends ProcessingStep { basicInitialize(descriptor); } - private void basicInitialize(ProcessingStepDescriptor descriptor) { + private void basicInitialize(IProcessingStepDescriptor descriptor) { int code = (descriptor == null) ? IStatus.ERROR : descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO; if (expectedMD5 == null || expectedMD5.length() != 32) setStatus(new Status(code, Activator.ID, NLS.bind(Messages.Error_invalid_hash, expectedMD5))); 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 7ba8e6387..cf5778e67 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 @@ -11,6 +11,8 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.processors.pack200; +import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor; + import java.io.*; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -18,8 +20,7 @@ import org.eclipse.equinox.internal.p2.artifact.processing.AbstractBufferingStep import org.eclipse.equinox.internal.p2.artifact.repository.Activator; import org.eclipse.equinox.internal.p2.core.helpers.FileUtils; import org.eclipse.equinox.internal.p2.jarprocessor.UnpackStep; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor; import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor.Options; @@ -36,7 +37,7 @@ public class Pack200ProcessorStep extends AbstractBufferingStep { return new BufferedOutputStream(new FileOutputStream(incoming)); } - public void initialize(ProcessingStepDescriptor descriptor, IArtifactDescriptor context) { + public void initialize(IProcessingStepDescriptor descriptor, IArtifactDescriptor context) { super.initialize(descriptor, context); if (!UnpackStep.canUnpack()) setStatus(new Status(IStatus.ERROR, Activator.ID, "Unpack facility not configured")); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java index ee7fcd4a3..6a41d2d38 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2009 IBM Corporation 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 @@ -10,8 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; import org.osgi.framework.*; import org.osgi.util.tracker.ServiceTracker; import org.osgi.util.tracker.ServiceTrackerCustomizer; @@ -22,22 +24,28 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer { private static BundleContext context; private ServiceRegistration repositoryManagerRegistration; - private ArtifactRepositoryManager repositoryManager; - private ServiceTracker busTracker; + private static final Map<ArtifactRepositoryManager, IProvisioningAgent> createdManagers = new HashMap<ArtifactRepositoryManager, IProvisioningAgent>(); + private ServiceTracker agentTracker; public static BundleContext getContext() { return Activator.context; } + /** + * Remember an artifact repository manager so we can shut it down when the bundle stops + */ + static void addManager(ArtifactRepositoryManager manager, IProvisioningAgent agent) { + synchronized (createdManagers) { + createdManagers.put(manager, agent); + } + } + public void start(BundleContext aContext) throws Exception { Activator.context = aContext; - repositoryManager = new ArtifactRepositoryManager(); - repositoryManagerRegistration = aContext.registerService(IArtifactRepositoryManager.class.getName(), repositoryManager, null); - - // need to track event bus coming and going to make sure cache gets cleaned on - // repository removals - busTracker = new ServiceTracker(context, IProvisioningEventBus.SERVICE_NAME, this); - busTracker.open(); + // need to track agent so we can register global artifact repository manager + String filter = "(&(objectClass=" + IProvisioningAgent.SERVICE_NAME + ")(agent.current=true))"; //$NON-NLS-1$ //$NON-NLS-2$ + agentTracker = new ServiceTracker(context, aContext.createFilter(filter), this); + agentTracker.open(); } public void stop(BundleContext aContext) throws Exception { @@ -45,28 +53,33 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer { if (repositoryManagerRegistration != null) repositoryManagerRegistration.unregister(); repositoryManagerRegistration = null; - if (repositoryManager != null) { - repositoryManager.shutdown(); - repositoryManager = null; + synchronized (createdManagers) { + for (ArtifactRepositoryManager manager : createdManagers.keySet()) { + manager.shutdown(); + IProvisioningAgent agent = createdManagers.get(manager); + agent.unregisterService(IArtifactRepositoryManager.SERVICE_NAME, manager); + } + createdManagers.clear(); } - busTracker.close(); + agentTracker.close(); } public Object addingService(ServiceReference reference) { - IProvisioningEventBus bus = (IProvisioningEventBus) context.getService(reference); - if (repositoryManager != null) - repositoryManager.setEventBus(bus); - return bus; + //when someone registers the agent service, register a repository manager service + IProvisioningAgent agent = (IProvisioningAgent) context.getService(reference); + repositoryManagerRegistration = context.registerService(IArtifactRepositoryManager.SERVICE_NAME, agent.getService(IArtifactRepositoryManager.SERVICE_NAME), null); + return agent; } public void modifiedService(ServiceReference reference, Object service) { // ignored - } public void removedService(ServiceReference reference, Object service) { - if (repositoryManager != null) - repositoryManager.unsetEventBus((IProvisioningEventBus) service); + //the agent is going away so withdraw our service + if (repositoryManagerRegistration != null) { + repositoryManagerRegistration.unregister(); + repositoryManagerRegistration = null; + } } - } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java index 39f807b30..901457a8e 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java @@ -10,9 +10,11 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; +import org.eclipse.equinox.p2.core.IAgentLocation; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; /** * Service factory providing {@link IArtifactRepositoryManager} instances. @@ -20,7 +22,11 @@ import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; public class ArtifactRepositoryComponent implements IAgentServiceFactory { public Object createService(IProvisioningAgent agent) { - return new ArtifactRepositoryManager(); + final ArtifactRepositoryManager manager = new ArtifactRepositoryManager(); + manager.setEventBus((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)); + manager.setAgentLocation((IAgentLocation) agent.getService(IAgentLocation.SERVICE_NAME)); + manager.setAgent(agent); + Activator.addManager(manager, agent); + return manager; } - } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java index 46811e78f..21e54aa6f 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. + * Copyright (c) 2007, 2010 IBM Corporation 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 @@ -12,17 +12,18 @@ package org.eclipse.equinox.internal.p2.artifact.repository; import java.net.URI; -import java.util.*; +import java.util.HashMap; +import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; -import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.ArtifactRepositoryFactory; +import org.eclipse.equinox.p2.core.IAgentLocation; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.artifact.*; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory; /** * Default implementation of {@link IArtifactRepositoryManager}. @@ -30,7 +31,7 @@ import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.Artif * TODO the current assumption that the "location" is the dir/root limits us to * having just one repository in a given URL.. */ -public class ArtifactRepositoryManager extends AbstractRepositoryManager implements IArtifactRepositoryManager { +public class ArtifactRepositoryManager extends AbstractRepositoryManager<IArtifactKey> implements IArtifactRepositoryManager { public ArtifactRepositoryManager() { super(); @@ -40,25 +41,31 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme super.addRepository(repository, true, null); } - public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Properties destinationDescriptorProperties, Properties destinationRepositoryProperties) { + public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map<String, String> destinationDescriptorProperties, Map<String, String> destinationRepositoryProperties) { return new MirrorRequest(key, destination, destinationDescriptorProperties, destinationRepositoryProperties); } - public IArtifactRepository createRepository(URI location, String name, String type, Map properties) throws ProvisionException { + public IArtifactRepository createRepository(URI location, String name, String type, Map<String, String> properties) throws ProvisionException { return (IArtifactRepository) doCreateRepository(location, name, type, properties); } - protected IRepository factoryCreate(URI location, String name, String type, Map properties, IExtension extension) throws ProvisionException { + public IArtifactRepository getRepository(URI location) { + return (IArtifactRepository) basicGetRepository(location); + } + + protected IRepository<IArtifactKey> factoryCreate(URI location, String name, String type, Map<String, String> properties, IExtension extension) throws ProvisionException { ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) createExecutableExtension(extension, EL_FACTORY); if (factory == null) return null; + factory.setAgent(agent); return factory.create(location, name, type, properties); } - protected IRepository factoryLoad(URI location, IExtension extension, int flags, SubMonitor monitor) throws ProvisionException { + protected IRepository<IArtifactKey> factoryLoad(URI location, IExtension extension, int flags, SubMonitor monitor) throws ProvisionException { ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) createExecutableExtension(extension, EL_FACTORY); if (factory == null) return null; + factory.setAgent(agent); return factory.load(location, flags, monitor.newChild(10)); } @@ -102,12 +109,14 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme */ protected void restoreSpecialRepositories() { // TODO while recreating, we may want to have proxies on repo instead of the real repo object to limit what is activated. - AgentLocation location = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); + IAgentLocation location = (IAgentLocation) ServiceHelper.getService(Activator.getContext(), IAgentLocation.class.getName()); if (location == null) // TODO should do something here since we are failing to restore. return; + URI cacheLocation = URIUtil.append(location.getDataArea("org.eclipse.equinox.p2.core"), "cache/"); //$NON-NLS-1$ //$NON-NLS-2$ + try { - loadRepository(location.getArtifactRepositoryURI(), null); + loadRepository(cacheLocation, null); return; } catch (ProvisionException e) { // log but still continue and try to create a new one @@ -115,9 +124,9 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while loading download cache.", e)); //$NON-NLS-1$ } try { - Map properties = new HashMap(1); + Map<String, String> properties = new HashMap<String, String>(1); properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); - createRepository(location.getArtifactRepositoryURI(), "download cache", TYPE_SIMPLE_REPOSITORY, properties); //$NON-NLS-1$ + createRepository(cacheLocation, "download cache", TYPE_SIMPLE_REPOSITORY, properties); //$NON-NLS-1$ } catch (ProvisionException e) { LogHelper.log(e); } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRequest.java index 352daa6d1..6fe6fc267 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRequest.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRequest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2009 IBM Corporation 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 @@ -11,9 +11,9 @@ package org.eclipse.equinox.internal.p2.artifact.repository; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest; /** * Base class for all requests on an {@link IArtifactRepository}. diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java index 411fc37f7..d51ed96c4 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation and others. + * Copyright (c) 2008, 2010 IBM Corporation 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: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -18,18 +18,19 @@ import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryState; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.repository.ICompositeRepository; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; -import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.AbstractArtifactRepository; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.query.*; +import org.eclipse.equinox.p2.repository.ICompositeRepository; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.artifact.*; +import org.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository; import org.eclipse.osgi.util.NLS; -public class CompositeArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, ICompositeRepository { +public class CompositeArtifactRepository extends AbstractArtifactRepository implements ICompositeRepository<IArtifactKey> { static final public String REPOSITORY_TYPE = CompositeArtifactRepository.class.getName(); static final private Integer REPOSITORY_VERSION = new Integer(1); @@ -40,16 +41,19 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl // keep a list of the child URIs. they can be absolute or relative. they may or may not point // to a valid reachable repo - private List childrenURIs = new ArrayList(); + private List<URI> childrenURIs = new ArrayList<URI>(); // keep a list of the repositories that we have successfully loaded - private List loadedRepos = new ArrayList(); + private List<ChildInfo> loadedRepos = new ArrayList<ChildInfo>(); + private IArtifactRepositoryManager manager; /** * Create a Composite repository in memory. * @return the repository or null if unable to create one */ - public static CompositeArtifactRepository createMemoryComposite() { - IArtifactRepositoryManager manager = getManager(); + public static CompositeArtifactRepository createMemoryComposite(IProvisioningAgent agent) { + if (agent == null) + return null; + IArtifactRepositoryManager manager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); if (manager == null) return null; try { @@ -71,21 +75,23 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl return null; } - static private IArtifactRepositoryManager getManager() { - return (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); + private IArtifactRepositoryManager getManager() { + return manager; } /* * This is only called by the parser when loading a repository. */ - public CompositeArtifactRepository(CompositeRepositoryState state) { + CompositeArtifactRepository(IArtifactRepositoryManager manager, CompositeRepositoryState state) { super(state.getName(), state.getType(), state.getVersion(), state.getLocation(), state.getDescription(), state.getProvider(), state.getProperties()); + this.manager = manager; for (int i = 0; i < state.getChildren().length; i++) addChild(state.getChildren()[i], false); } - public CompositeArtifactRepository(URI location, String repositoryName, Map properties) { + CompositeArtifactRepository(IArtifactRepositoryManager manager, URI location, String repositoryName, Map<String, String> properties) { super(repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties); + this.manager = manager; save(); } @@ -103,7 +109,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl result.setProvider(getProvider()); result.setProperties(getProperties()); // it is important to directly access the field so we have the relative URIs - result.setChildren((URI[]) childrenURIs.toArray(new URI[childrenURIs.size()])); + result.setChildren(childrenURIs.toArray(new URI[childrenURIs.size()])); return result; } @@ -112,7 +118,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl * in it. Return a boolean value indicating whether or not the object was * actually added. */ - private static boolean add(List list, Object obj) { + private static <T> boolean add(List<T> list, T obj) { return list.contains(obj) ? false : list.add(obj); } @@ -163,21 +169,21 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } } - public boolean addChild(URI childURI, String comparatorID) { - try { - IArtifactRepository repo = load(childURI); - if (isSane(repo, comparatorID)) { - addChild(childURI); - //Add was successful - return true; - } - } catch (ProvisionException e) { - LogHelper.log(e); - } - - //Add was not successful - return false; - } + // public boolean addChild(URI childURI, String comparatorID) { + // try { + // IArtifactRepository repo = load(childURI); + // if (isSane(repo, comparatorID)) { + // addChild(childURI); + // //Add was successful + // return true; + // } + // } catch (ProvisionException e) { + // LogHelper.log(e); + // } + // + // //Add was not successful + // return false; + // } public void removeChild(URI childURI) { boolean removed = childrenURIs.remove(childURI); @@ -190,13 +196,12 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl if (removed) { // we removed the child from the list so remove the associated repo object as well ChildInfo found = null; - for (Iterator iter = loadedRepos.iterator(); found == null && iter.hasNext();) { - ChildInfo current = (ChildInfo) iter.next(); + for (ChildInfo current : loadedRepos) { URI repoLocation = current.repo.getLocation(); - if (URIUtil.sameURI(childURI, repoLocation)) - found = current; - else if (URIUtil.sameURI(other, repoLocation)) + if (URIUtil.sameURI(childURI, repoLocation) || URIUtil.sameURI(other, repoLocation)) { found = current; + break; + } } if (found != null) loadedRepos.remove(found); @@ -210,10 +215,18 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl save(); } - public List getChildren() { - List result = new ArrayList(); - for (Iterator iter = childrenURIs.iterator(); iter.hasNext();) - result.add(URIUtil.makeAbsolute((URI) iter.next(), location)); + public List<URI> getChildren() { + List<URI> result = new ArrayList<URI>(); + for (URI uri : childrenURIs) + result.add(URIUtil.makeAbsolute(uri, location)); + return result; + } + + public List<IArtifactRepository> getLoadedChildren() { + List<IArtifactRepository> result = new ArrayList<IArtifactRepository>(loadedRepos.size()); + for (ChildInfo info : loadedRepos) { + result.add(info.repo); + } return result; } @@ -262,8 +275,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } public boolean contains(IArtifactKey key) { - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext();) { - ChildInfo current = (ChildInfo) repositoryIterator.next(); + for (ChildInfo current : loadedRepos) { if (current.isGood() && current.repo.contains(key)) return true; } @@ -271,8 +283,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } public boolean contains(IArtifactDescriptor descriptor) { - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext();) { - ChildInfo current = (ChildInfo) repositoryIterator.next(); + for (ChildInfo current : loadedRepos) { if (current.isGood() && current.repo.contains(descriptor)) return true; } @@ -280,36 +291,24 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } public IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key) { - ArrayList result = new ArrayList(); - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext();) { - ChildInfo current = (ChildInfo) repositoryIterator.next(); + ArrayList<IArtifactDescriptor> result = new ArrayList<IArtifactDescriptor>(); + for (ChildInfo current : loadedRepos) { if (current.isGood()) { IArtifactDescriptor[] tempResult = current.repo.getArtifactDescriptors(key); for (int i = 0; i < tempResult.length; i++) add(result, tempResult[i]); } } - return (IArtifactDescriptor[]) result.toArray(new IArtifactDescriptor[result.size()]); - } - - public IArtifactKey[] getArtifactKeys() { - ArrayList result = new ArrayList(); - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext();) { - ChildInfo current = (ChildInfo) repositoryIterator.next(); - if (current.isGood()) { - IArtifactKey[] tempResult = current.repo.getArtifactKeys(); - for (int i = 0; i < tempResult.length; i++) - add(result, tempResult[i]); - } - } - return (IArtifactKey[]) result.toArray(new IArtifactKey[result.size()]); + return result.toArray(new IArtifactDescriptor[result.size()]); } public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) { SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length); MultiStatus multiStatus = new MultiStatus(Activator.ID, IStatus.OK, Messages.message_childrenRepos, null); - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext() && requests.length > 0;) { - IArtifactRepository current = ((ChildInfo) repositoryIterator.next()).repo; + for (ChildInfo childInfo : loadedRepos) { + if (requests.length == 0) + break; + IArtifactRepository current = childInfo.repo; IArtifactRequest[] applicable = getRequestsForRepository(current, requests); IStatus dlStatus = current.getArtifacts(applicable, subMonitor.newChild(requests.length)); multiStatus.add(dlStatus); @@ -333,8 +332,8 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } private IStatus getRawOrNormalArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor, boolean raw) { - for (Iterator childIterator = loadedRepos.iterator(); childIterator.hasNext();) { - ChildInfo current = (ChildInfo) childIterator.next(); + for (Iterator<ChildInfo> childIterator = loadedRepos.iterator(); childIterator.hasNext();) { + ChildInfo current = childIterator.next(); if (current.isGood() && current.repo.contains(descriptor)) { // Child hasn't failed & contains descriptor IStatus status = raw ? current.repo.getRawArtifact(descriptor, destination, monitor) : current.repo.getArtifact(descriptor, destination, monitor); @@ -360,7 +359,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } private IArtifactRequest[] filterUnfetched(IArtifactRequest[] requests) { - ArrayList filteredRequests = new ArrayList(); + ArrayList<IArtifactRequest> filteredRequests = new ArrayList<IArtifactRequest>(); for (int i = 0; i < requests.length; i++) { if (requests[i].getResult() == null || !requests[i].getResult().isOK()) { filteredRequests.add(requests[i]); @@ -373,18 +372,18 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } private IArtifactRequest[] getRequestsForRepository(IArtifactRepository repository, IArtifactRequest[] requests) { - ArrayList applicable = new ArrayList(); + ArrayList<IArtifactRequest> applicable = new ArrayList<IArtifactRequest>(); for (int i = 0; i < requests.length; i++) { if (repository.contains(requests[i].getArtifactKey())) applicable.add(requests[i]); } - return (IArtifactRequest[]) applicable.toArray(new IArtifactRequest[applicable.size()]); + return applicable.toArray(new IArtifactRequest[applicable.size()]); } private void save() { if (!isModifiable()) return; - boolean compress = "true".equalsIgnoreCase((String) properties.get(PROP_COMPRESSED)); //$NON-NLS-1$ + boolean compress = "true".equalsIgnoreCase(properties.get(PROP_COMPRESSED)); //$NON-NLS-1$ OutputStream os = null; try { URI actualLocation = getActualLocation(location, false); @@ -433,73 +432,73 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl return repo; } - /** - * A method to check if the content of a repository is consistent with the other children by - * comparing content using the artifactComparator specified by the comparatorID - * @param toCheckRepo the repository to check - * @param comparatorID - * @return <code>true</code> if toCheckRepo is consistent, <code>false</code> if toCheckRepo - * contains an equal descriptor to that of a child and they refer to different artifacts on disk. - */ - private boolean isSane(IArtifactRepository toCheckRepo, String comparatorID) { - IArtifactComparator comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID); - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext();) { - IArtifactRepository current = ((ChildInfo) repositoryIterator.next()).repo; - if (!current.equals(toCheckRepo)) { - if (!isSane(toCheckRepo, current, comparator)) - return false; - } - } - return true; - } - - /* - * Check the two given repositories against each other using the given comparator. - */ - private boolean isSane(IArtifactRepository one, IArtifactRepository two, IArtifactComparator comparator) { - IArtifactKey[] toCheckKeys = one.getArtifactKeys(); - for (int i = 0; i < toCheckKeys.length; i++) { - IArtifactKey key = toCheckKeys[i]; - if (!two.contains(key)) - continue; - IArtifactDescriptor[] toCheckDescriptors = one.getArtifactDescriptors(key); - IArtifactDescriptor[] currentDescriptors = two.getArtifactDescriptors(key); - for (int j = 0; j < toCheckDescriptors.length; j++) { - if (!two.contains(toCheckDescriptors[j])) - continue; - for (int k = 0; k < currentDescriptors.length; k++) { - if (currentDescriptors[k].equals(toCheckDescriptors[j])) { - IStatus compareResult = comparator.compare(two, currentDescriptors[k], two, toCheckDescriptors[j]); - if (!compareResult.isOK()) { - LogHelper.log(compareResult); - return false; - } - break; - } - } - } - } - return true; - } - - /** - * A method that verifies that all children with matching artifact descriptors contain the same set of bytes - * The verification is done using the artifactComparator specified by comparatorID - * Assumes more valuable logging and output is the responsibility of the artifactComparator implementation. - * @param comparatorID - * @returns true if the repository is consistent, false if two equal descriptors refer to different artifacts on disk. - */ - public boolean validate(String comparatorID) { - IArtifactComparator comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID); - ChildInfo[] repos = (ChildInfo[]) loadedRepos.toArray(new ChildInfo[loadedRepos.size()]); - for (int outer = 0; outer < repos.length; outer++) { - for (int inner = outer + 1; inner < repos.length; inner++) { - if (!isSane(repos[outer].repo, repos[inner].repo, comparator)) - return false; - } - } - return true; - } + // /** + // * A method to check if the content of a repository is consistent with the other children by + // * comparing content using the artifactComparator specified by the comparatorID + // * @param toCheckRepo the repository to check + // * @param comparatorID + // * @return <code>true</code> if toCheckRepo is consistent, <code>false</code> if toCheckRepo + // * contains an equal descriptor to that of a child and they refer to different artifacts on disk. + // */ + // private boolean isSane(IArtifactRepository toCheckRepo, String comparatorID) { + // IArtifactComparator comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID); + // for (ChildInfo childInfo : loadedRepos) { + // IArtifactRepository current = childInfo.repo; + // if (!current.equals(toCheckRepo)) { + // if (!isSane(toCheckRepo, current, comparator)) + // return false; + // } + // } + // return true; + // } + // + // /* + // * Check the two given repositories against each other using the given comparator. + // */ + // private boolean isSane(IArtifactRepository one, IArtifactRepository two, IArtifactComparator comparator) { + // IQueryResult<IArtifactKey> toCheckKeys = one.query(ArtifactKeyQuery.ALL_KEYS, null); + // for (Iterator<IArtifactKey> iterator = toCheckKeys.iterator(); iterator.hasNext();) { + // IArtifactKey key = iterator.next(); + // if (!two.contains(key)) + // continue; + // IArtifactDescriptor[] toCheckDescriptors = one.getArtifactDescriptors(key); + // IArtifactDescriptor[] currentDescriptors = two.getArtifactDescriptors(key); + // for (int j = 0; j < toCheckDescriptors.length; j++) { + // if (!two.contains(toCheckDescriptors[j])) + // continue; + // for (int k = 0; k < currentDescriptors.length; k++) { + // if (currentDescriptors[k].equals(toCheckDescriptors[j])) { + // IStatus compareResult = comparator.compare(two, currentDescriptors[k], two, toCheckDescriptors[j]); + // if (!compareResult.isOK()) { + // LogHelper.log(compareResult); + // return false; + // } + // break; + // } + // } + // } + // } + // return true; + // } + // + // /** + // * A method that verifies that all children with matching artifact descriptors contain the same set of bytes + // * The verification is done using the artifactComparator specified by comparatorID + // * Assumes more valuable logging and output is the responsibility of the artifactComparator implementation. + // * @param comparatorID + // * @returns true if the repository is consistent, false if two equal descriptors refer to different artifacts on disk. + // */ + // private boolean validate(String comparatorID) { + // IArtifactComparator comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID); + // ChildInfo[] repos = loadedRepos.toArray(new ChildInfo[loadedRepos.size()]); + // for (int outer = 0; outer < repos.length; outer++) { + // for (int inner = outer + 1; inner < repos.length; inner++) { + // if (!isSane(repos[outer].repo, repos[inner].repo, comparator)) + // return false; + // } + // } + // return true; + // } private static class ChildInfo { IArtifactRepository repo; @@ -517,4 +516,26 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl return good; } } + + public IQueryResult<IArtifactKey> query(IQuery<IArtifactKey> query, IProgressMonitor monitor) { + // Query all the all the repositories this composite repo contains + List<IArtifactRepository> repos = new ArrayList<IArtifactRepository>(); + for (ChildInfo info : loadedRepos) { + if (info.isGood()) + repos.add(info.repo); + } + CompoundQueryable<IArtifactKey> queryable = new CompoundQueryable<IArtifactKey>(repos); + return queryable.query(query, monitor); + } + + public IQueryable<IArtifactDescriptor> descriptorQueryable() { + // Query all the all the repositories this composite repo contains + List<IQueryable<IArtifactDescriptor>> repos = new ArrayList<IQueryable<IArtifactDescriptor>>(); + for (ChildInfo info : loadedRepos) { + if (info.isGood()) + repos.add(info.repo.descriptorQueryable()); + } + CompoundQueryable<IArtifactDescriptor> queryable = new CompoundQueryable<IArtifactDescriptor>(repos); + return queryable; + } } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepositoryFactory.java index e587abfca..a37216807 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepositoryFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation and others. + * Copyright (c) 2008, 2010 IBM Corporation 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 @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory; + +import org.eclipse.equinox.p2.core.ProvisionException; + import java.io.*; import java.net.URI; import java.util.Map; @@ -21,14 +25,19 @@ import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryState; import org.eclipse.equinox.internal.p2.repository.RepositoryTransport; import org.eclipse.equinox.internal.p2.repository.Transport; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; -import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.ArtifactRepositoryFactory; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; import org.eclipse.osgi.util.NLS; public class CompositeArtifactRepositoryFactory extends ArtifactRepositoryFactory { + private IArtifactRepositoryManager getManager() { + if (getAgent() != null) + return (IArtifactRepositoryManager) getAgent().getService(IArtifactRepositoryManager.SERVICE_NAME); + return null; + } + public IArtifactRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException { final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ long time = 0; @@ -95,7 +104,7 @@ public class CompositeArtifactRepositoryFactory extends ArtifactRepositoryFactor CompositeRepositoryState resultState = io.read(localFile.toURL(), descriptorStream, CompositeArtifactRepository.PI_REPOSITORY_TYPE, sub.newChild(100)); if (resultState.getLocation() == null) resultState.setLocation(location); - CompositeArtifactRepository result = new CompositeArtifactRepository(resultState); + CompositeArtifactRepository result = new CompositeArtifactRepository(getManager(), resultState); if (Tracing.DEBUG_METADATA_PARSING) { time += System.currentTimeMillis(); Tracing.debug(debugMsg + "time (ms): " + time); //$NON-NLS-1$ @@ -117,8 +126,8 @@ public class CompositeArtifactRepositoryFactory extends ArtifactRepositoryFactor } } - public IArtifactRepository create(URI location, String name, String type, Map properties) { - return new CompositeArtifactRepository(location, name, properties); + public IArtifactRepository create(URI location, String name, String type, Map<String, String> properties) { + return new CompositeArtifactRepository(getManager(), location, name, properties); } private Transport getTransport() { diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/FlatteningIterator.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/FlatteningIterator.java new file mode 100644 index 000000000..1035f1420 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/FlatteningIterator.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.internal.p2.artifact.repository; + +import java.util.*; + +/** + * An iterator over values that are provided by iterating over collections. + */ +public class FlatteningIterator<T> implements Iterator<T> { + private static final Object NO_ELEMENT = new Object(); + private final Iterator<? extends Collection<T>> collectionIterator; + private Iterator<T> currentIterator; + + private T nextObject = noElement(); + + public FlatteningIterator(Iterator<? extends Collection<T>> collectionIterator) { + this.collectionIterator = collectionIterator; + } + + public boolean hasNext() { + return positionNext(); + } + + public T next() { + if (!positionNext()) + throw new NoSuchElementException(); + + T nxt = nextObject; + nextObject = noElement(); + return nxt; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + + private boolean positionNext() { + if (nextObject != NO_ELEMENT) + return true; + + while (currentIterator == null || !currentIterator.hasNext()) { + if (!collectionIterator.hasNext()) + return false; + currentIterator = collectionIterator.next().iterator(); + } + nextObject = currentIterator.next(); + return true; + } + + @SuppressWarnings("unchecked") + private static <T> T noElement() { + return (T) NO_ELEMENT; + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java index c15f22c0d..1353e18b5 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java @@ -17,6 +17,7 @@ public class Messages extends NLS { public static String artifact_not_found; public static String available_already_in; + public static String no_location; public static String downloading; public static String error_closing_stream; public static String io_failedRead; diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java index 5623b78e5..6e2585445 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java @@ -1,54 +1,56 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation 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: + * Copyright (c) 2007, 2010 IBM Corporation 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: * IBM Corporation - initial API and implementation * Compeople AG (Stefan Liebig) - various ongoing maintenance * Genuitec LLC - various bug fixes *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository; +import org.eclipse.equinox.p2.core.ProvisionException; + import java.io.*; -import java.util.Properties; +import java.util.HashMap; +import java.util.Map; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor; +import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactDescriptor; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepHandler; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; import org.eclipse.equinox.internal.provisional.p2.repository.IStateful; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; import org.eclipse.osgi.util.NLS; /** * A request to mirror (copy) an artifact into a given destination artifact repository. */ public class MirrorRequest extends ArtifactRequest { - private static final ProcessingStepDescriptor[] EMPTY_STEPS = new ProcessingStepDescriptor[0]; - protected final IArtifactRepository target; - private final Properties targetDescriptorProperties; - private final Properties targetRepositoryProperties; + private final Map<String, String> targetDescriptorProperties; + private final Map<String, String> targetRepositoryProperties; protected IArtifactDescriptor descriptor; - public MirrorRequest(IArtifactKey key, IArtifactRepository targetRepository, Properties targetDescriptorProperties, Properties targetRepositoryProperties) { + public MirrorRequest(IArtifactKey key, IArtifactRepository targetRepository, Map<String, String> targetDescriptorProperties, Map<String, String> targetRepositoryProperties) { super(key); target = targetRepository; if (targetDescriptorProperties == null || targetDescriptorProperties.isEmpty()) { this.targetDescriptorProperties = null; } else { - this.targetDescriptorProperties = new Properties(); + this.targetDescriptorProperties = new HashMap<String, String>(); this.targetDescriptorProperties.putAll(targetDescriptorProperties); } if (targetRepositoryProperties == null || targetRepositoryProperties.isEmpty()) { this.targetRepositoryProperties = null; } else { - this.targetRepositoryProperties = new Properties(); + this.targetRepositoryProperties = new HashMap<String, String>(); this.targetRepositoryProperties.putAll(targetRepositoryProperties); } } @@ -91,7 +93,7 @@ public class MirrorRequest extends ArtifactRequest { return; } - ArtifactDescriptor destinationDescriptor = getDestinationDescriptor(descriptor); + IArtifactDescriptor destinationDescriptor = getDestinationDescriptor(descriptor); IStatus status = transfer(destinationDescriptor, descriptor, monitor); // if ok, cancelled or transfer has already been done with the canonical form return with status set if (status.getSeverity() == IStatus.CANCEL) { @@ -125,21 +127,21 @@ public class MirrorRequest extends ArtifactRequest { setResult(new MultiStatus(Activator.ID, canonicalStatus.getCode() != 0 ? canonicalStatus.getCode() : status.getCode(), new IStatus[] {status, canonicalStatus}, Messages.MirrorRequest_multipleDownloadProblems, null)); } - private ArtifactDescriptor getDestinationDescriptor(IArtifactDescriptor sourceDescriptor) { + private IArtifactDescriptor getDestinationDescriptor(IArtifactDescriptor sourceDescriptor) { // Get the descriptor to use to store the artifact // Since we are mirroring, ensure we clear out data from the original descriptor that may // not apply in the new repo location. // TODO this is brittle. perhaps the repo itself should do this? there are cases where // we really do need to give the repo the actual descriptor to use however... - ArtifactDescriptor destinationDescriptor = new ArtifactDescriptor(sourceDescriptor); - destinationDescriptor.setProcessingSteps(EMPTY_STEPS); - destinationDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, null); - destinationDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, null); - destinationDescriptor.setProperty(IArtifactDescriptor.FORMAT, null); - if (targetDescriptorProperties != null) - destinationDescriptor.addProperties(targetDescriptorProperties); - if (targetRepositoryProperties != null) - destinationDescriptor.addRepositoryProperties(targetRepositoryProperties); + IArtifactDescriptor destinationDescriptor = target.createArtifactDescriptor(sourceDescriptor.getArtifactKey()); + // destinationDescriptor.setProcessingSteps(EMPTY_STEPS); + // destinationDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, null); + // destinationDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, null); + // destinationDescriptor.setProperty(IArtifactDescriptor.FORMAT, null); + if (targetDescriptorProperties != null && destinationDescriptor instanceof ArtifactDescriptor) + ((ArtifactDescriptor) destinationDescriptor).addProperties(targetDescriptorProperties); + if (targetRepositoryProperties != null && destinationDescriptor instanceof SimpleArtifactDescriptor) + ((SimpleArtifactDescriptor) destinationDescriptor).addRepositoryProperties(targetRepositoryProperties); return destinationDescriptor; } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java index 8104d23e8..6fb6259de 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java @@ -21,7 +21,7 @@ import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.core.helpers.Tracing; import org.eclipse.equinox.internal.p2.repository.DownloadStatus; import org.eclipse.equinox.internal.p2.repository.RepositoryTransport; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepository; import org.w3c.dom.*; import org.xml.sax.InputSource; @@ -39,7 +39,7 @@ public class MirrorSelector { /** * Encapsulates information about a single mirror */ - public static class MirrorInfo implements Comparable { + public static class MirrorInfo implements Comparable<MirrorInfo> { long bytesPerSecond; int failureCount; private final int initialRank; @@ -57,10 +57,7 @@ public class MirrorSelector { /** * Comparison used to sort mirrors. */ - public int compareTo(Object o) { - if (!(o instanceof MirrorInfo)) - return 0; - MirrorInfo that = (MirrorInfo) o; + public int compareTo(MirrorInfo that) { //less failures is better if (this.failureCount != that.failureCount) return this.failureCount - that.failureCount; @@ -91,7 +88,7 @@ public class MirrorSelector { MirrorInfo[] mirrors; - private final IRepository repository; + private final IRepository<?> repository; private final Random random = new Random(); @@ -100,10 +97,10 @@ public class MirrorSelector { * not contacted and the mirrorsURL document is not parsed until a * mirror location request is sent. */ - public MirrorSelector(IRepository repository) { + public MirrorSelector(IRepository<?> repository) { this.repository = repository; try { - String base = (String) repository.getProperties().get(IRepository.PROP_MIRRORS_BASE_URL); + String base = repository.getProperties().get(IRepository.PROP_MIRRORS_BASE_URL); if (base != null) { this.baseURI = new URI(base); } else { @@ -204,7 +201,7 @@ public class MirrorSelector { private MirrorInfo[] initMirrors(IProgressMonitor monitor) { if (mirrors != null) return mirrors; - String mirrorsURL = (String) repository.getProperties().get(IRepository.PROP_MIRRORS_URL); + String mirrorsURL = repository.getProperties().get(IRepository.PROP_MIRRORS_URL); if (mirrorsURL != null) mirrors = computeMirrors(mirrorsURL, monitor); return mirrors; diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java index 3c82b5565..3c2432543 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java @@ -14,10 +14,10 @@ import java.io.OutputStream; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5Verifier; import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; 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.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; import org.eclipse.osgi.util.NLS; public class RawMirrorRequest extends MirrorRequest { diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/SignatureVerifier.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/SignatureVerifier.java index 55330678a..2108b52f4 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/SignatureVerifier.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/SignatureVerifier.java @@ -78,7 +78,7 @@ public class SignatureVerifier extends ProcessingStep { } catch (GeneralSecurityException e) { return new Status(IStatus.ERROR, Activator.ID, Messages.SignatureVerification_failedRead + inputFile, e); } - ArrayList allStatus = new ArrayList(0); + ArrayList<IStatus> allStatus = new ArrayList<IStatus>(0); SignedContentEntry[] entries = signedContent.getSignedEntries(); for (int i = 0; i < entries.length; i++) try { @@ -90,7 +90,7 @@ public class SignatureVerifier extends ProcessingStep { break; } if (allStatus.size() > 0) - return new MultiStatus(Activator.ID, IStatus.ERROR, (IStatus[]) allStatus.toArray(new IStatus[allStatus.size()]), Messages.SignatureVerification_invalidFileContent + inputFile, null); + return new MultiStatus(Activator.ID, IStatus.ERROR, allStatus.toArray(new IStatus[allStatus.size()]), Messages.SignatureVerification_invalidFileContent + inputFile, null); return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties index 9b80fc9ef..eed154d94 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties @@ -10,6 +10,7 @@ ############################################################################### artifact_not_found=Artifact not found: {0}. available_already_in=The artifact is already available in the repository {0}. +no_location=No location for {0}. downloading=Downloading {0} error_closing_stream=Error closing the output stream for {0} on repository {1}. diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java index e3697cbee..bf6fed250 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation 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 @@ -12,7 +12,6 @@ package org.eclipse.equinox.internal.p2.artifact.repository.simple; import java.io.*; import java.net.URI; -import java.util.Iterator; import java.util.Set; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.URIUtil; @@ -93,9 +92,9 @@ public class BlobStore { /** * Delete all of the blobs in the given set. */ - public void deleteBlobs(Set set) { - for (Iterator i = set.iterator(); i.hasNext();) - deleteBlob((byte[]) i.next()); + public void deleteBlobs(Set<byte[]> set) { + for (byte[] blob : set) + deleteBlob(blob); } public URI fileFor(byte[] uuid) { diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/DownloadJob.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/DownloadJob.java index 0001a2804..69aee86ef 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/DownloadJob.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/DownloadJob.java @@ -13,12 +13,12 @@ import java.util.LinkedList; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRequest; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest; public class DownloadJob extends Job { static final Object FAMILY = new Object(); - private LinkedList requestsPending; + private LinkedList<IArtifactRequest> requestsPending; private SimpleArtifactRepository repository; private IProgressMonitor masterMonitor; private MultiStatus overallStatus; @@ -28,7 +28,7 @@ public class DownloadJob extends Job { setSystem(true); } - void initialize(SimpleArtifactRepository repository, LinkedList requestsPending, IProgressMonitor masterMonitor, MultiStatus overallStatus) { + void initialize(SimpleArtifactRepository repository, LinkedList<IArtifactRequest> requestsPending, IProgressMonitor masterMonitor, MultiStatus overallStatus) { this.repository = repository; this.requestsPending = requestsPending; this.masterMonitor = masterMonitor; @@ -53,7 +53,7 @@ public class DownloadJob extends Job { synchronized (requestsPending) { if (requestsPending.isEmpty()) break; - request = (IArtifactRequest) requestsPending.removeFirst(); + request = requestsPending.removeFirst(); } if (masterMonitor.isCanceled()) return Status.CANCEL_STATUS; diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/Mapper.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/Mapper.java index de962a7c7..80b6b3e44 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/Mapper.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/Mapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2009 IBM Corporation 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 @@ -53,7 +53,7 @@ public class Mapper { public URI map(URI repositoryLocation, String classifier, String id, String version, String format) { String locationString = URIUtil.toUnencodedString(repositoryLocation); - Dictionary values = new Hashtable(5); + Dictionary<String, Object> values = new Hashtable<String, Object>(5); if (repositoryLocation != null) values.put(REPOURL, locationString); diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactDescriptor.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactDescriptor.java new file mode 100644 index 000000000..e458813ee --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactDescriptor.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.internal.p2.artifact.repository.simple; + +import java.util.Map; +import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; + +public class SimpleArtifactDescriptor extends ArtifactDescriptor { + public static final String ARTIFACT_REFERENCE = "artifact.reference"; //$NON-NLS-1$ + + protected Map<String, String> repositoryProperties = new OrderedProperties(); + + public SimpleArtifactDescriptor(IArtifactKey key) { + super(key); + } + + public SimpleArtifactDescriptor(IArtifactDescriptor base) { + super(base); + } + + public SimpleArtifactDescriptor(SimpleArtifactDescriptor base) { + super(base); + } + + public String getRepositoryProperty(String propertyKey) { + return repositoryProperties.get(propertyKey); + } + + public void setRepositoryProperty(String key, String value) { + if (value == null) + repositoryProperties.remove(key); + else + repositoryProperties.put(key, value); + } + + public void addRepositoryProperties(Map<String, String> additionalProperties) { + repositoryProperties.putAll(additionalProperties); + } + + /** + * Returns a read-only collection of the repository properties of the artifact descriptor. + * @return the repository properties of this artifact descriptor. + */ + public Map<String, String> getRepositoryProperties() { + return OrderedProperties.unmodifiableProperties(repositoryProperties); + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || !(obj instanceof SimpleArtifactDescriptor)) + return false; + + SimpleArtifactDescriptor other = (SimpleArtifactDescriptor) obj; + + //Properties affecting SimpleArtifactRepository#getLocation + String locationProperty = getRepositoryProperty(ARTIFACT_REFERENCE); + String otherProperty = other.getRepositoryProperty(ARTIFACT_REFERENCE); + // want not null and the same, or both null + if (locationProperty != null ? !locationProperty.equals(otherProperty) : otherProperty != null) + return false; + + return super.equals(obj); + } + + public int hashCode() { + int superHash = super.hashCode(); + String ref = getRepositoryProperty(ARTIFACT_REFERENCE); + if (ref != null) + return 31 * superHash + ref.hashCode(); + return superHash; + } +} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java index fc225be63..127c7851b 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java @@ -1,11 +1,11 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation 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: + * Copyright (c) 2007, 2010 IBM Corporation 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: * IBM Corporation - initial API and implementation * Genuitec, LLC - support for multi-threaded downloads *******************************************************************************/ @@ -15,6 +15,7 @@ import java.io.*; import java.net.URI; import java.net.URISyntaxException; import java.util.*; +import java.util.Map.Entry; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import org.eclipse.core.runtime.*; @@ -26,13 +27,15 @@ import org.eclipse.equinox.internal.p2.core.helpers.FileUtils; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.repository.RepositoryTransport; import org.eclipse.equinox.internal.p2.repository.Transport; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; import org.eclipse.equinox.internal.provisional.p2.repository.IStateful; -import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.AbstractArtifactRepository; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.query.*; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.artifact.*; +import org.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; import org.eclipse.osgi.util.NLS; public class SimpleArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, IFileArtifactRepository { @@ -197,12 +200,14 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme static final private Integer REPOSITORY_VERSION = new Integer(1); private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ - protected Set artifactDescriptors = new HashSet(); - protected Map artifactMap = new HashMap(); + protected Set<SimpleArtifactDescriptor> artifactDescriptors = new HashSet<SimpleArtifactDescriptor>(); + /** + * Map<IArtifactKey,List<IArtifactDescriptor>> containing the index of artifacts in the repository. + */ + protected Map<IArtifactKey, List<IArtifactDescriptor>> artifactMap = new HashMap<IArtifactKey, List<IArtifactDescriptor>>(); private transient BlobStore blobStore; transient private Mapper mapper = new Mapper(); - static final private String PACKED_FORMAT = "packed"; //$NON-NLS-1$ static final private String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings"; //$NON-NLS-1$ private static final int DEFAULT_MAX_THREADS = 4; @@ -250,19 +255,19 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme /* * This is only called by the parser when loading a repository. */ - SimpleArtifactRepository(String name, String type, String version, String description, String provider, Set artifacts, String[][] mappingRules, Map properties) { + SimpleArtifactRepository(String name, String type, String version, String description, String provider, Set<SimpleArtifactDescriptor> artifacts, String[][] mappingRules, Map<String, String> properties) { super(name, type, version, null, description, provider, properties); this.artifactDescriptors.addAll(artifacts); this.mappingRules = mappingRules; - for (Iterator it = artifactDescriptors.iterator(); it.hasNext();) - mapDescriptor((IArtifactDescriptor) it.next()); + for (SimpleArtifactDescriptor desc : artifactDescriptors) + mapDescriptor(desc); } private void mapDescriptor(IArtifactDescriptor descriptor) { IArtifactKey key = descriptor.getArtifactKey(); - Collection descriptors = (Collection) artifactMap.get(key); + List<IArtifactDescriptor> descriptors = artifactMap.get(key); if (descriptors == null) { - descriptors = new ArrayList(); + descriptors = new ArrayList<IArtifactDescriptor>(); artifactMap.put(key, descriptors); } descriptors.add(descriptor); @@ -270,7 +275,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme private void unmapDescriptor(IArtifactDescriptor descriptor) { IArtifactKey key = descriptor.getArtifactKey(); - Collection descriptors = (Collection) artifactMap.get(key); + List<IArtifactDescriptor> descriptors = artifactMap.get(key); if (descriptors == null) return; @@ -279,13 +284,13 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme artifactMap.remove(key); } - public SimpleArtifactRepository(String repositoryName, URI location, Map properties) { + public SimpleArtifactRepository(String repositoryName, URI location, Map<String, String> properties) { super(repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties); initializeAfterLoad(location); if (properties != null) { if (properties.containsKey(PUBLISH_PACK_FILES_AS_SIBLINGS)) { synchronized (this) { - String newValue = (String) properties.get(PUBLISH_PACK_FILES_AS_SIBLINGS); + String newValue = properties.get(PUBLISH_PACK_FILES_AS_SIBLINGS); if (Boolean.TRUE.toString().equals(newValue)) { mappingRules = PACKED_MAPPING_RULES; } else { @@ -299,37 +304,57 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public synchronized void addDescriptor(IArtifactDescriptor toAdd) { - // TODO perhaps the argument here should be ArtifactDescriptor. IArtifactDescriptors are for - // people who are reading the repository. - // TODO: here we may want to ensure that the artifact has not been added concurrently - ((ArtifactDescriptor) toAdd).setRepository(this); - artifactDescriptors.add(toAdd); - mapDescriptor(toAdd); + if (artifactDescriptors.contains(toAdd)) + return; + + SimpleArtifactDescriptor internalDescriptor = createInternalDescriptor(toAdd); + artifactDescriptors.add(internalDescriptor); + mapDescriptor(internalDescriptor); save(); } - public synchronized void addDescriptors(IArtifactDescriptor[] descriptors) { + public IArtifactDescriptor createArtifactDescriptor(IArtifactKey key) { + return new SimpleArtifactDescriptor(key); + } + + private SimpleArtifactDescriptor createInternalDescriptor(IArtifactDescriptor descriptor) { + SimpleArtifactDescriptor internal = new SimpleArtifactDescriptor(descriptor); + + internal.setRepository(this); + if (isFolderBased(descriptor)) + internal.setRepositoryProperty(ARTIFACT_FOLDER, Boolean.TRUE.toString()); + if (descriptor instanceof SimpleArtifactDescriptor) { + Map<String, String> repoProperties = ((SimpleArtifactDescriptor) descriptor).getRepositoryProperties(); + for (Entry<String, String> entry : repoProperties.entrySet()) { + internal.setRepositoryProperty(entry.getKey(), entry.getValue()); + } + } + return internal; + } + public synchronized void addDescriptors(IArtifactDescriptor[] descriptors) { for (int i = 0; i < descriptors.length; i++) { - ((ArtifactDescriptor) descriptors[i]).setRepository(this); - artifactDescriptors.add(descriptors[i]); - mapDescriptor(descriptors[i]); + if (artifactDescriptors.contains(descriptors[i])) + continue; + SimpleArtifactDescriptor internalDescriptor = createInternalDescriptor(descriptors[i]); + artifactDescriptors.add(internalDescriptor); + mapDescriptor(internalDescriptor); } save(); } private synchronized OutputStream addPostSteps(ProcessingStepHandler handler, IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { - ArrayList steps = new ArrayList(); + ArrayList<ProcessingStep> steps = new ArrayList<ProcessingStep>(); steps.add(new SignatureVerifier()); if (steps.isEmpty()) return destination; - ProcessingStep[] stepArray = (ProcessingStep[]) steps.toArray(new ProcessingStep[steps.size()]); + ProcessingStep[] stepArray = steps.toArray(new ProcessingStep[steps.size()]); // TODO should probably be using createAndLink here return handler.link(stepArray, destination, monitor); } private OutputStream addPreSteps(ProcessingStepHandler handler, IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { - ArrayList steps = new ArrayList(); + ArrayList<ProcessingStep> steps = new ArrayList<ProcessingStep>(); if (IArtifactDescriptor.TYPE_ZIP.equals(descriptor.getProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE))) steps.add(new ZipVerifierStep()); if (MD5_CHECK_ENABLED && descriptor.getProperty(IArtifactDescriptor.DOWNLOAD_MD5) != null) @@ -337,7 +362,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme // Add steps here if needed if (steps.isEmpty()) return destination; - ProcessingStep[] stepArray = (ProcessingStep[]) steps.toArray(new ProcessingStep[steps.size()]); + ProcessingStep[] stepArray = steps.toArray(new ProcessingStep[steps.size()]); // TODO should probably be using createAndLink here return handler.link(stepArray, destination, monitor); } @@ -367,7 +392,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public synchronized boolean contains(IArtifactDescriptor descriptor) { - return artifactDescriptors.contains(descriptor); + SimpleArtifactDescriptor simpleDescriptor = createInternalDescriptor(descriptor); + return artifactDescriptors.contains(simpleDescriptor); } public synchronized boolean contains(IArtifactKey key) { @@ -404,7 +430,12 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme * descriptor existed in the repository, and was successfully removed. */ private boolean doRemoveArtifact(IArtifactDescriptor descriptor) { - if (((ArtifactDescriptor) descriptor).getRepositoryProperty(ArtifactDescriptor.ARTIFACT_REFERENCE) == null) { + SimpleArtifactDescriptor simple = null; + if (descriptor instanceof SimpleArtifactDescriptor) + simple = (SimpleArtifactDescriptor) descriptor; + else + simple = createInternalDescriptor(descriptor); + if (simple.getRepositoryProperty(SimpleArtifactDescriptor.ARTIFACT_REFERENCE) == null) { File file = getArtifactFile(descriptor); if (file == null) return false; @@ -446,7 +477,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme //download from the best available mirror URI baseLocation = getLocation(descriptor); if (baseLocation == null) - return new Status(IStatus.ERROR, Activator.ID, "Can not find the location of " + descriptor); + return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.no_location, descriptor)); URI mirrorLocation = getMirror(baseLocation, monitor); IStatus status = downloadArtifact(descriptor, mirrorLocation, destination, monitor); IStatus result = reportStatus(descriptor, destination, status); @@ -494,6 +525,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme return mirrors.getMirrorLocation(baseLocation, monitor); } + @SuppressWarnings("rawtypes") public Object getAdapter(Class adapter) { // if we are adapting to file or writable repositories then make sure we have a file location if (adapter == IFileArtifactRepository.class) @@ -523,11 +555,11 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public synchronized IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key) { - Collection result = (Collection) artifactMap.get(key); + List<IArtifactDescriptor> result = artifactMap.get(key); if (result == null) return new IArtifactDescriptor[0]; - return (IArtifactDescriptor[]) result.toArray(new IArtifactDescriptor[result.size()]); + return result.toArray(new IArtifactDescriptor[result.size()]); } public File getArtifactFile(IArtifactDescriptor descriptor) { @@ -544,14 +576,9 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme return getArtifactFile(descriptor); } - public synchronized IArtifactKey[] getArtifactKeys() { - // there may be more descriptors than keys to collect up the unique keys - return (IArtifactKey[]) artifactMap.keySet().toArray(new IArtifactKey[artifactMap.keySet().size()]); - } - public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) { final MultiStatus overallStatus = new MultiStatus(Activator.ID, IStatus.OK, null, null); - LinkedList requestsPending = new LinkedList(Arrays.asList(requests)); + LinkedList<IArtifactRequest> requestsPending = new LinkedList<IArtifactRequest>(Arrays.asList(requests)); int numberOfJobs = Math.min(requests.length, getMaximumThreads()); if (numberOfJobs <= 1 || (!isForceThreading() && isLocal())) { @@ -591,12 +618,11 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) { - Collection descriptors = (Collection) artifactMap.get(key); + List<IArtifactDescriptor> descriptors = artifactMap.get(key); if (descriptors == null) return null; - for (Iterator iterator = descriptors.iterator(); iterator.hasNext();) { - IArtifactDescriptor desc = (IArtifactDescriptor) iterator.next(); + for (IArtifactDescriptor desc : descriptors) { // look for a descriptor that matches the key and is "complete" if (desc.getArtifactKey().equals(key) && desc.getProcessingSteps().length == 0) return desc; @@ -604,7 +630,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme return null; } - public synchronized Set getDescriptors() { + public synchronized Set<SimpleArtifactDescriptor> getDescriptors() { return artifactDescriptors; } @@ -615,7 +641,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme * this arrangement "flat but packed". */ private boolean flatButPackedEnabled(IArtifactDescriptor descriptor) { - return Boolean.TRUE.toString().equals(getProperties().get(PUBLISH_PACK_FILES_AS_SIBLINGS)) && PACKED_FORMAT.equals(descriptor.getProperty(IArtifactDescriptor.FORMAT)); + return Boolean.TRUE.toString().equals(getProperties().get(PUBLISH_PACK_FILES_AS_SIBLINGS)) && IArtifactDescriptor.FORMAT_PACKED.equals(descriptor.getProperty(IArtifactDescriptor.FORMAT)); } /** @@ -638,8 +664,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme try { // if the artifact is just a reference then return the reference location - if (descriptor instanceof ArtifactDescriptor) { - String artifactReference = ((ArtifactDescriptor) descriptor).getRepositoryProperty(ArtifactDescriptor.ARTIFACT_REFERENCE); + if (descriptor instanceof SimpleArtifactDescriptor) { + String artifactReference = ((SimpleArtifactDescriptor) descriptor).getRepositoryProperty(SimpleArtifactDescriptor.ARTIFACT_REFERENCE); if (artifactReference != null) { try { return new URI(artifactReference); @@ -672,7 +698,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme */ private int getMaximumThreads() { try { - String maxThreadString = (String) getProperties().get(PROP_MAX_THREADS); + String maxThreadString = getProperties().get(PROP_MAX_THREADS); if (maxThreadString != null) return Math.max(1, Integer.parseInt(maxThreadString)); } catch (NumberFormatException nfe) { @@ -685,9 +711,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme assertModifiable(); // Create a copy of the original descriptor that we can manipulate and add to our repo. - ArtifactDescriptor newDescriptor = new ArtifactDescriptor(descriptor); - if (isFolderBased(descriptor)) - newDescriptor.setRepositoryProperty(ARTIFACT_FOLDER, Boolean.TRUE.toString()); + ArtifactDescriptor newDescriptor = createInternalDescriptor(descriptor); // Check if the artifact is already in this repository, check the newDescriptor instead of the original // since the implementation of hash/equals on the descriptor matters here. @@ -764,13 +788,12 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } // use this method to setup any transient fields etc after the object has been restored from a stream - public synchronized void initializeAfterLoad(URI location) { - this.location = location; - blobStore = new BlobStore(getBlobStoreLocation(location), 128); + public synchronized void initializeAfterLoad(URI repoLocation) { + this.location = repoLocation; + blobStore = new BlobStore(getBlobStoreLocation(repoLocation), 128); initializeMapper(); - for (Iterator i = artifactDescriptors.iterator(); i.hasNext();) { - ((ArtifactDescriptor) i.next()).setRepository(this); - } + for (SimpleArtifactDescriptor desc : artifactDescriptors) + desc.setRepository(this); } private synchronized void initializeMapper() { @@ -779,13 +802,17 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } private boolean isFolderBased(IArtifactDescriptor descriptor) { - // if the artifact is just a reference then return the reference location - if (descriptor instanceof ArtifactDescriptor) { - String useArtifactFolder = ((ArtifactDescriptor) descriptor).getRepositoryProperty(ARTIFACT_FOLDER); + // This is called from createInternalDescriptor, so if we aren't a + // SimpleArtifactDescriptor then just check the descriptor properties instead + // of creating the interla descriptor. + SimpleArtifactDescriptor internalDescriptor = null; + if (descriptor instanceof SimpleArtifactDescriptor) + internalDescriptor = (SimpleArtifactDescriptor) descriptor; + if (internalDescriptor != null) { + String useArtifactFolder = internalDescriptor.getRepositoryProperty(ARTIFACT_FOLDER); if (useArtifactFolder != null) return Boolean.valueOf(useArtifactFolder).booleanValue(); } - //TODO: refactor this when the artifact folder property is consistently set in repository properties return Boolean.valueOf(descriptor.getProperty(ARTIFACT_FOLDER)).booleanValue(); } @@ -809,7 +836,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public synchronized void removeAll() { - IArtifactDescriptor[] toRemove = (IArtifactDescriptor[]) artifactDescriptors.toArray(new IArtifactDescriptor[artifactDescriptors.size()]); + IArtifactDescriptor[] toRemove = artifactDescriptors.toArray(new IArtifactDescriptor[artifactDescriptors.size()]); boolean changed = false; for (int i = 0; i < toRemove.length; i++) changed |= doRemoveArtifact(toRemove[i]); @@ -873,7 +900,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public void save() { - boolean compress = "true".equalsIgnoreCase((String) properties.get(PROP_COMPRESSED)); //$NON-NLS-1$ + boolean compress = "true".equalsIgnoreCase(properties.get(PROP_COMPRESSED)); //$NON-NLS-1$ save(compress); } @@ -936,7 +963,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } save(); //force repository manager to reload this repository because it caches properties - ArtifactRepositoryManager manager = (ArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); + ArtifactRepositoryManager manager = (ArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.SERVICE_NAME); if (manager.removeRepository(getLocation())) manager.addRepository(this); return oldValue; @@ -949,4 +976,18 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme public String toString() { return location.toString(); } + + public IQueryable<IArtifactDescriptor> descriptorQueryable() { + final Collection<List<IArtifactDescriptor>> descs = artifactMap.values(); + return new IQueryable<IArtifactDescriptor>() { + + public IQueryResult<IArtifactDescriptor> query(IQuery<IArtifactDescriptor> query, IProgressMonitor monitor) { + return query.perform(new FlatteningIterator<IArtifactDescriptor>(descs.iterator())); + } + }; + } + + public IQueryResult<IArtifactKey> query(IQuery<IArtifactKey> query, IProgressMonitor monitor) { + return query.perform(artifactMap.keySet().iterator()); + } } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java index d9744eadb..a3aec4822 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java @@ -1,14 +1,18 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation 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: + * Copyright (c) 2007, 2010 IBM Corporation 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: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository; +package org.eclipse.equinox.internal.p2.artifact.repository.simple; + +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory; + +import org.eclipse.equinox.p2.core.ProvisionException; import java.io.*; import java.net.URI; @@ -18,17 +22,17 @@ import java.util.jar.JarInputStream; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.artifact.repository.Activator; import org.eclipse.equinox.internal.p2.artifact.repository.Messages; -import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository; -import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepositoryIO; import org.eclipse.equinox.internal.p2.core.helpers.Tracing; import org.eclipse.equinox.internal.p2.repository.RepositoryTransport; import org.eclipse.equinox.internal.p2.repository.Transport; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; import org.eclipse.osgi.util.NLS; public class SimpleArtifactRepositoryFactory extends ArtifactRepositoryFactory { + public SimpleArtifactRepositoryFactory() { + super(); + } public IArtifactRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException { final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ @@ -119,7 +123,7 @@ public class SimpleArtifactRepositoryFactory extends ArtifactRepositoryFactory { } } - public IArtifactRepository create(URI location, String name, String type, Map properties) { + public IArtifactRepository create(URI location, String name, String type, Map<String, String> properties) { return new SimpleArtifactRepository(name, location, properties); } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java index 85333d106..477aac105 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. + * Copyright (c) 2007, 2010 IBM Corporation 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 @@ -10,8 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository.simple; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; -import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange; +import org.eclipse.equinox.p2.metadata.Version; +import org.eclipse.equinox.p2.metadata.VersionRange; + +import org.eclipse.equinox.p2.core.ProvisionException; + +import org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor; import java.io.*; import java.net.URL; @@ -25,11 +29,8 @@ import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; import org.eclipse.equinox.internal.p2.metadata.ArtifactKey; import org.eclipse.equinox.internal.p2.persistence.XMLParser; import org.eclipse.equinox.internal.p2.persistence.XMLWriter; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor; -import org.eclipse.equinox.internal.provisional.p2.core.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.artifact.*; import org.eclipse.osgi.util.NLS; import org.osgi.framework.BundleContext; import org.xml.sax.*; @@ -109,9 +110,9 @@ public class SimpleArtifactRepositoryIO { // Constants defining the structure of the XML for a SimpleArtifactRepository // A format version number for simple artifact repository XML. - public static final Version COMPATIBLE_VERSION = new Version(1, 0, 0); - public static final Version CURRENT_VERSION = new Version(1, 1, 0); - public static final VersionRange XML_TOLERANCE = new VersionRange(COMPATIBLE_VERSION, true, new Version(2, 0, 0), false); + public static final Version COMPATIBLE_VERSION = Version.createOSGi(1, 0, 0); + public static final Version CURRENT_VERSION = Version.createOSGi(1, 1, 0); + public static final VersionRange XML_TOLERANCE = new VersionRange(COMPATIBLE_VERSION, true, Version.createOSGi(2, 0, 0), false); // Constants for processing instructions public static final String PI_REPOSITORY_TARGET = "artifactRepository"; //$NON-NLS-1$ @@ -176,11 +177,10 @@ public class SimpleArtifactRepositoryIO { } } - private void writeArtifacts(Set artifactDescriptors) { + private void writeArtifacts(Set<SimpleArtifactDescriptor> artifactDescriptors) { start(ARTIFACTS_ELEMENT); attribute(COLLECTION_SIZE_ATTRIBUTE, artifactDescriptors.size()); - for (Iterator iter = artifactDescriptors.iterator(); iter.hasNext();) { - ArtifactDescriptor descriptor = (ArtifactDescriptor) iter.next(); + for (SimpleArtifactDescriptor descriptor : artifactDescriptors) { IArtifactKey key = descriptor.getArtifactKey(); start(ARTIFACT_ELEMENT); attribute(ARTIFACT_CLASSIFIER_ATTRIBUTE, key.getClassifier()); @@ -194,7 +194,7 @@ public class SimpleArtifactRepositoryIO { end(ARTIFACTS_ELEMENT); } - private void writeProcessingSteps(ProcessingStepDescriptor[] processingSteps) { + private void writeProcessingSteps(IProcessingStepDescriptor[] processingSteps) { if (processingSteps.length > 0) { start(PROCESSING_STEPS_ELEMENT); attribute(COLLECTION_SIZE_ATTRIBUTE, processingSteps.length); @@ -326,9 +326,9 @@ public class SimpleArtifactRepositoryIO { if (isValidXML()) { String[][] mappingRules = (mappingRulesHandler == null ? new String[0][0] // : mappingRulesHandler.getMappingRules()); - Map properties = (propertiesHandler == null ? new OrderedProperties(0) // + Map<String, String> properties = (propertiesHandler == null ? new OrderedProperties(0) // : propertiesHandler.getProperties()); - Set artifacts = (artifactsHandler == null ? new HashSet(0) // + Set<SimpleArtifactDescriptor> artifacts = (artifactsHandler == null ? new HashSet<SimpleArtifactDescriptor>(0) // : artifactsHandler.getArtifacts()); repository = new SimpleArtifactRepository(attrValues[0], attrValues[1], attrValues[2], attrValues[3], // attrValues[4], artifacts, mappingRules, properties); @@ -338,18 +338,18 @@ public class SimpleArtifactRepositoryIO { protected class MappingRulesHandler extends AbstractHandler { - private List mappingRules; + private List<String[]> mappingRules; public MappingRulesHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, MAPPING_RULES_ELEMENT); String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE); - mappingRules = (size != null ? new ArrayList(new Integer(size).intValue()) : new ArrayList(4)); + mappingRules = (size != null ? new ArrayList<String[]>(new Integer(size).intValue()) : new ArrayList<String[]>(4)); } public String[][] getMappingRules() { String[][] rules = new String[mappingRules.size()][2]; for (int index = 0; index < mappingRules.size(); index++) { - String[] ruleAttributes = (String[]) mappingRules.get(index); + String[] ruleAttributes = mappingRules.get(index); rules[index] = ruleAttributes; } return rules; @@ -368,7 +368,7 @@ public class SimpleArtifactRepositoryIO { private final String[] required = new String[] {MAPPING_RULE_FILTER_ATTRIBUTE, MAPPING_RULE_OUTPUT_ATTRIBUTE}; - public MappingRuleHandler(AbstractHandler parentHandler, Attributes attributes, List mappingRules) { + public MappingRuleHandler(AbstractHandler parentHandler, Attributes attributes, List<String[]> mappingRules) { super(parentHandler, MAPPING_RULE_ELEMENT); mappingRules.add(parseRequiredAttributes(attributes, required)); } @@ -380,15 +380,15 @@ public class SimpleArtifactRepositoryIO { protected class ArtifactsHandler extends AbstractHandler { - private Set artifacts; + private Set<SimpleArtifactDescriptor> artifacts; public ArtifactsHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, ARTIFACTS_ELEMENT); String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE); - artifacts = (size != null ? new LinkedHashSet(new Integer(size).intValue()) : new LinkedHashSet(4)); + artifacts = (size != null ? new LinkedHashSet<SimpleArtifactDescriptor>(new Integer(size).intValue()) : new LinkedHashSet<SimpleArtifactDescriptor>(4)); } - public Set getArtifacts() { + public Set<SimpleArtifactDescriptor> getArtifacts() { return artifacts; } @@ -405,20 +405,20 @@ public class SimpleArtifactRepositoryIO { private final String[] required = new String[] {ARTIFACT_CLASSIFIER_ATTRIBUTE, ID_ATTRIBUTE, VERSION_ATTRIBUTE}; - private Set artifacts; - ArtifactDescriptor currentArtifact = null; + private Set<SimpleArtifactDescriptor> artifacts; + SimpleArtifactDescriptor currentArtifact = null; private PropertiesHandler propertiesHandler = null; private PropertiesHandler repositoryPropertiesHandler = null; private ProcessingStepsHandler processingStepsHandler = null; - public ArtifactHandler(AbstractHandler parentHandler, Attributes attributes, Set artifacts) { + public ArtifactHandler(AbstractHandler parentHandler, Attributes attributes, Set<SimpleArtifactDescriptor> artifacts) { super(parentHandler, ARTIFACT_ELEMENT); this.artifacts = artifacts; String[] values = parseRequiredAttributes(attributes, required); Version version = checkVersion(ARTIFACT_ELEMENT, VERSION_ATTRIBUTE, values[2]); // TODO: resolve access restriction on ArtifactKey construction - currentArtifact = new ArtifactDescriptor(new ArtifactKey(values[0], values[1], version)); + currentArtifact = new SimpleArtifactDescriptor(new ArtifactKey(values[0], values[1], version)); } public void startElement(String name, Attributes attributes) { @@ -447,13 +447,13 @@ public class SimpleArtifactRepositoryIO { protected void finished() { if (isValidXML() && currentArtifact != null) { - Map properties = (propertiesHandler == null ? new OrderedProperties(0) : propertiesHandler.getProperties()); + Map<String, String> properties = (propertiesHandler == null ? new OrderedProperties(0) : propertiesHandler.getProperties()); currentArtifact.addProperties(properties); properties = (repositoryPropertiesHandler == null ? new OrderedProperties(0) : repositoryPropertiesHandler.getProperties()); currentArtifact.addRepositoryProperties(properties); - ProcessingStepDescriptor[] processingSteps = (processingStepsHandler == null ? new ProcessingStepDescriptor[0] // + IProcessingStepDescriptor[] processingSteps = (processingStepsHandler == null ? new ProcessingStepDescriptor[0] // : processingStepsHandler.getProcessingSteps()); currentArtifact.setProcessingSteps(processingSteps); artifacts.add(currentArtifact); @@ -463,16 +463,16 @@ public class SimpleArtifactRepositoryIO { protected class ProcessingStepsHandler extends AbstractHandler { - private List processingSteps; + private List<IProcessingStepDescriptor> processingSteps; public ProcessingStepsHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, PROCESSING_STEPS_ELEMENT); String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE); - processingSteps = (size != null ? new ArrayList(new Integer(size).intValue()) : new ArrayList(4)); + processingSteps = (size != null ? new ArrayList<IProcessingStepDescriptor>(new Integer(size).intValue()) : new ArrayList<IProcessingStepDescriptor>(4)); } - public ProcessingStepDescriptor[] getProcessingSteps() { - return (ProcessingStepDescriptor[]) processingSteps.toArray(new ProcessingStepDescriptor[processingSteps.size()]); + public IProcessingStepDescriptor[] getProcessingSteps() { + return processingSteps.toArray(new ProcessingStepDescriptor[processingSteps.size()]); } public void startElement(String name, Attributes attributes) { @@ -489,7 +489,7 @@ public class SimpleArtifactRepositoryIO { private final String[] required = new String[] {ID_ATTRIBUTE, STEP_REQUIRED_ATTRIBUTE}; private final String[] optional = new String[] {STEP_DATA_ATTRIBUTE}; - public ProcessingStepHandler(AbstractHandler parentHandler, Attributes attributes, List processingSteps) { + public ProcessingStepHandler(AbstractHandler parentHandler, Attributes attributes, List<IProcessingStepDescriptor> processingSteps) { super(parentHandler, PROCESSING_STEP_ELEMENT); String[] attributeValues = parseAttributes(attributes, required, optional); processingSteps.add(new ProcessingStepDescriptor(attributeValues[0], attributeValues[2], checkBoolean(PROCESSING_STEP_ELEMENT, STEP_REQUIRED_ATTRIBUTE, attributeValues[1]).booleanValue())); diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/ArtifactComparatorFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/ArtifactComparatorFactory.java deleted file mode 100644 index b9568b02d..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/ArtifactComparatorFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - * Compeople AG (Stefan Liebig) - various ongoing maintenance - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.artifact.repository; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.RegistryFactory; -import org.eclipse.equinox.internal.p2.artifact.repository.Messages; -import org.eclipse.osgi.util.NLS; - -public class ArtifactComparatorFactory { - private static final String comparatorPoint = "org.eclipse.equinox.p2.artifact.repository.artifactComparators"; //$NON-NLS-1$ - private static final String ATTR_ID = "id"; //$NON-NLS-1$ - private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ - - public static IArtifactComparator getArtifactComparator(String comparatorID) { - IConfigurationElement[] extensions = RegistryFactory.getRegistry().getConfigurationElementsFor(comparatorPoint); - - IConfigurationElement element = null; - if (comparatorID == null && extensions.length > 0) { - element = extensions[0]; //just take the first one - } else { - for (int i = 0; i < extensions.length; i++) { - if (extensions[i].getAttribute(ATTR_ID).equals(comparatorID)) { - element = extensions[i]; - break; - } - } - } - if (element != null) { - try { - Object execExt = element.createExecutableExtension(ATTR_CLASS); - if (execExt instanceof IArtifactComparator) - return (IArtifactComparator) execExt; - } catch (Exception e) { - //fall through - } - } - - if (comparatorID != null) - throw new IllegalArgumentException(NLS.bind(Messages.exception_comparatorNotFound, comparatorID)); - throw new IllegalArgumentException(Messages.exception_noComparators); - } -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/ArtifactDescriptor.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/ArtifactDescriptor.java deleted file mode 100644 index 33c526325..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/ArtifactDescriptor.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.artifact.repository; - -import java.util.Arrays; -import java.util.Map; -import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; - -/** - * This represents information about a given artifact stored on a particular byte server. - */ -public class ArtifactDescriptor implements IArtifactDescriptor { - public static final String ARTIFACT_REFERENCE = "artifact.reference"; //$NON-NLS-1$ - - private static final ProcessingStepDescriptor[] EMPTY_STEPS = new ProcessingStepDescriptor[0]; - - protected IArtifactKey key; // The key associated with this artifact - - // The list of post processing steps that must be applied one the artifact once it - // has been downloaded (e.g, unpack, then md5 checksum, then...) - protected ProcessingStepDescriptor[] processingSteps = EMPTY_STEPS; - - protected Map properties = new OrderedProperties(); - protected Map repositoryProperties = new OrderedProperties(); - - protected transient IArtifactRepository repository; - - // QUESTION: Do we need any description or user readable name - - public ArtifactDescriptor(IArtifactDescriptor base) { - super(); - key = base.getArtifactKey(); - processingSteps = base.getProcessingSteps(); - properties.putAll(base.getProperties()); - repository = base.getRepository(); - // TODO this property is hardcoded for the blob store. - // setProperty("artifact.uuid", base.getProperty("artifact.uuid")); - } - - public ArtifactDescriptor(ArtifactDescriptor base) { - super(); - key = base.key; - processingSteps = base.processingSteps; - properties = base.properties; - repository = base.repository; - } - - public ArtifactDescriptor(IArtifactKey key) { - super(); - this.key = key; - } - - public IArtifactKey getArtifactKey() { - return key; - } - - public String getProperty(String propertyKey) { - return (String) properties.get(propertyKey); - } - - public void setProperty(String key, String value) { - if (value == null) - properties.remove(key); - else - properties.put(key, value); - } - - public void addProperties(Map additionalProperties) { - properties.putAll(additionalProperties); - } - - /** - * Returns a read-only collection of the properties of the artifact descriptor. - * @return the properties of this artifact descriptor. - */ - public Map getProperties() { - return OrderedProperties.unmodifiableProperties(properties); - } - - public String getRepositoryProperty(String propertyKey) { - return (String) repositoryProperties.get(propertyKey); - } - - public void setRepositoryProperty(String key, String value) { - if (value == null) - repositoryProperties.remove(key); - else - repositoryProperties.put(key, value); - } - - public void addRepositoryProperties(Map additionalProperties) { - repositoryProperties.putAll(additionalProperties); - } - - /** - * Returns a read-only collection of the repository properties of the artifact descriptor. - * @return the repository properties of this artifact descriptor. - */ - public Map getRepositoryProperties() { - return OrderedProperties.unmodifiableProperties(repositoryProperties); - } - - public ProcessingStepDescriptor[] getProcessingSteps() { - return processingSteps; - } - - public void setProcessingSteps(ProcessingStepDescriptor[] value) { - processingSteps = value == null ? EMPTY_STEPS : value; - } - - // Implementation of both equals and hash depends on the implementation of - // SimpleArtifactRepository#getOutputStream(IArtifactDescriptor) - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ArtifactDescriptor other = (ArtifactDescriptor) obj; - if (key == null) { - if (other.key != null) - return false; - } else if (!key.equals(other.key)) - return false; - if (!Arrays.equals(processingSteps, other.processingSteps)) - return false; - - //Properties affecting SimpleArtifactRepository#getLocation - String locationProperty = getRepositoryProperty(ARTIFACT_REFERENCE); - String otherProperty = other.getRepositoryProperty(ARTIFACT_REFERENCE); - // want not null and the same, or both null - if (locationProperty != null ? !locationProperty.equals(otherProperty) : otherProperty != null) - return false; - - locationProperty = getProperty(FORMAT); - otherProperty = other.getProperty(FORMAT); - if (locationProperty != null ? !locationProperty.equals(otherProperty) : otherProperty != null) - return false; - - return true; - } - - private int hashCode(Object[] array) { - int prime = 31; - if (array == null) - return 0; - int result = 1; - for (int index = 0; index < array.length; index++) { - result = prime * result + (array[index] == null ? 0 : array[index].hashCode()); - } - return result; - } - - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - result = prime * result + hashCode(processingSteps); - - String[] hashProperties = new String[] {getRepositoryProperty(ARTIFACT_REFERENCE), getProperty(FORMAT)}; - result = prime * result + hashCode(hashProperties); - return result; - } - - public IArtifactRepository getRepository() { - return repository; - } - - public void setRepository(IArtifactRepository value) { - repository = value; - } - - public String toString() { - String format = getProperty(IArtifactDescriptor.FORMAT); - if (format == null) - return "canonical: " + key.toString(); //$NON-NLS-1$ - return format + ": " + key.toString(); //$NON-NLS-1$ - } - -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactComparator.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactComparator.java deleted file mode 100644 index 6ba7d556f..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactComparator.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 IBM Corporation 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: IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.equinox.internal.provisional.p2.artifact.repository; - -import org.eclipse.core.runtime.IStatus; - -public interface IArtifactComparator { - - /** - * Compare 2 equivalent IArtifactDescriptors from different repositories. - * - * IArtifactDescriptors with the same id and version should represent the same - * set of bytes. The comparator should ensure this is true and return an error - * or warning otherwise. - * - * @param source - The source IArtifactRepository - * @param sourceDescriptor - The IArtifactDescriptor from the source repository - * @param destination - The target IArtifactRepository - * @param destDescriptor - The IArtifactDescriptor from the target repository - * - * @return IStatus - */ - public IStatus compare(IArtifactRepository source, IArtifactDescriptor sourceDescriptor, IArtifactRepository destination, IArtifactDescriptor destDescriptor); -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactDescriptor.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactDescriptor.java deleted file mode 100644 index 835950693..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactDescriptor.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.artifact.repository; - -import java.util.Map; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; - -public interface IArtifactDescriptor { - - public static final String DOWNLOAD_SIZE = "download.size"; //$NON-NLS-1$ - public static final String ARTIFACT_SIZE = "artifact.size"; //$NON-NLS-1$ - public static final String DOWNLOAD_MD5 = "download.md5"; //$NON-NLS-1$ - public static final String DOWNLOAD_CONTENTTYPE = "download.contentType"; //$NON-NLS-1$ - public static final String TYPE_ZIP = "application/zip"; //$NON-NLS-1$ - public static final String ARTIFACT_MD5 = "artifact.md5"; //$NON-NLS-1$ - public static final String FORMAT = "format"; //$NON-NLS-1$ - - /** - * Return the key for the artifact described by this descriptor. - * @return the key associated with this descriptor - */ - public abstract IArtifactKey getArtifactKey(); - - /** - * Return the value of the given property in this descriptor <code>null</code> - * is returned if no such property exists - * @param key the property key to look for - * @return the value of the given property or <code>null</code> - */ - public abstract String getProperty(String key); - - /** - * Returns a read-only collection of the properties of the artifact descriptor. - * @return the properties of this artifact descriptor. - */ - public Map getProperties(); - - /** - * Return the list of processing steps associated with this descriptor. - * An empty set of steps implies that this descriptor describes a complete - * copy of the artifact in its native form. - * @return the list of processing steps for this descriptor - */ - public abstract ProcessingStepDescriptor[] getProcessingSteps(); - - /** - * Return the artifact repository that holds the artifact described by this descriptor. - * <code>null</code> is returned if this descriptor is not held in a repository. - * - * @return the repository holding this artifact or <code>null</code> if none. - */ - public abstract IArtifactRepository getRepository(); -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRepository.java deleted file mode 100644 index c793545ab..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRepository.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.artifact.repository; - -import java.io.OutputStream; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; -import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.AbstractArtifactRepository; - -/** - * A repository containing artifacts. - * <p> - * This interface is not intended to be implemented by clients. Artifact repository - * implementations must subclass {@link AbstractArtifactRepository} rather than - * implementing this interface directly. - * </p> - * @noimplement This interface is not intended to be implemented by clients. - */ -public interface IArtifactRepository extends IRepository { - - /** - * The return code to use when a client could/should retry a failed getArtifact() operation. - * For example, the repository may have additional mirrors that could be consulted. - */ - public static int CODE_RETRY = 13; - - /** - * Add the given descriptor to the set of descriptors in this repository. This is - * a relatively low-level operation that should be used only when the actual related - * content is in this repository and the given descriptor accurately describes - * that content. - * @param descriptor the descriptor to add. - */ - public void addDescriptor(IArtifactDescriptor descriptor); - - /** - * Add the given artifact descriptors to this repository - * @param descriptors the artifact descriptors to add - */ - public void addDescriptors(IArtifactDescriptor[] descriptors); - - /** - * Returns true if this repository contains the given descriptor. - * @param descriptor the descriptor to query - * @return true if the given descriptor is already in this repository - */ - public boolean contains(IArtifactDescriptor descriptor); - - /** - * Returns true if this repository contains the given artifact key. - * @param key the key to query - * @return true if the given key is already in this repository - */ - public boolean contains(IArtifactKey key); - - /** - * Write to the given output stream the bytes represented by the artifact descriptor processed by the processing steps of the given descriptor. - */ - public IStatus getArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor); - - /** - * Write to the given output stream the bytes represented by the artifact descriptor without processing by the steps of the given descriptor. - */ - public IStatus getRawArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor); - - /** - * Return the set of artifact descriptors describing the ways that this repository - * can supply the artifact associated with the given artifact key - * @param key the artifact key to lookup - * @return the descriptors associated with the given key - */ - public IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key); - - /** - * Returns the list of artifact keys managed by this repository - * @return list of artifact keys - */ - public IArtifactKey[] getArtifactKeys(); - - /** - * Executes the given artifact requests on this byte server. - * @param requests The artifact requests - * @param monitor - * @return a status object that is <code>OK</code> if requests were - * processed successfully. Otherwise, a status indicating information, - * warnings, or errors that occurred while executing the artifact requests - */ - public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor); - - /** - * Open an output stream to which a client can write the data for the given - * artifact descriptor. - * @param descriptor the descriptor describing the artifact data to be written to the - * resultant stream - * @return the stream to which the artifact content can be written. The returned output - * stream may implement <code>IStateful</code>. - * @throws ProvisionException if the output stream could not be created. Reasons include: - * <ul> - * <li>An I/O exception occurred (@link {@link ProvisionException#REPOSITORY_FAILED_WRITE}) .</li> - * <li>An artifact already exists at that location ({@link ProvisionException#ARTIFACT_EXISTS}).</li> - * </ul> - */ - public OutputStream getOutputStream(IArtifactDescriptor descriptor) throws ProvisionException; - - /** - * Remove the all keys, descriptors, and contents from this repository. - */ - public void removeAll(); - - /** - * Remove the given descriptor and its corresponding content in this repository. - * @param descriptor the descriptor to remove. - */ - public void removeDescriptor(IArtifactDescriptor descriptor); - - /** - * Remove the given key and all related content and descriptors from this repository. - * @param key the key to remove. - */ - public void removeDescriptor(IArtifactKey key); - -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRepositoryManager.java deleted file mode 100644 index c804670f4..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRepositoryManager.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.artifact.repository; - -import java.net.URI; -import java.util.Map; -import java.util.Properties; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; - -/** - * A metadata repository manager is used to create, access, and manipulate - * {@link IArtifactRepository} instances. See {@link IRepositoryManager} - * for a general description of the characteristics of repository managers. - * - * @noimplement This interface is not intended to be implemented by clients. - */ -public interface IArtifactRepositoryManager extends IRepositoryManager { - /** - * The name used for obtaining a reference to the metadata repository manager service - */ - public static final String SERVICE_NAME = IArtifactRepositoryManager.class.getName(); - - public static final IArtifactRequest[] NO_ARTIFACT_REQUEST = new IArtifactRequest[0]; - - /** - * Repository type for a simple repository based on a URL or local file system location. - */ - public static final String TYPE_SIMPLE_REPOSITORY = "org.eclipse.equinox.p2.artifact.repository.simpleRepository"; //$NON-NLS-1$ - public static final String TYPE_COMPOSITE_REPOSITORY = "org.eclipse.equinox.p2.artifact.repository.compositeRepository"; //$NON-NLS-1$ - - /** - * Return a new request to mirror the given artifact into the destination repository. - * @param key the artifact to mirror - * @param destination the destination where the artifact will be mirrored - * @param destinationDescriptorProperties additional properties for use in creating the repository's ArtifactDescriptor, - * or <code>null</code> to indicate no additional properties are needed - * @param destinationRepositoryProperties additional repository specific properties for use in creating the repositor's ArtifactDescriptor, - * , or <code>null</code> to indicate no additional properties are needed - * @return the newly created request object - */ - public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Properties destinationDescriptorProperties, Properties destinationRepositoryProperties); - - /** - * Creates and returns a new empty artifact repository of the given type at - * the given location. - * <p> - * The resulting repository is added to the list of repositories tracked by - * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} - * if they do not want the repository manager to remember the repository for subsequent - * load attempts. - * </p> - * - * @param location the absolute location for the new repository - * @param name the name of the new repository - * @param type the kind of repository to create - * @param properties the properties to set on the repository - * @return the newly created repository - * @throws ProvisionException if the repository could not be created. Reasons include: - * <ul> - * <li>The repository type is unknown.</li> - * <li>There was an error writing to the given repository location.</li> - * <li>A repository already exists at that location.</li> - * </ul> - */ - public IArtifactRepository createRepository(URI location, String name, String type, Map properties) throws ProvisionException; - - /** - * Loads the repository at the given location. The location is expected to contain - * data that describes a valid artifact repository of a known type. If this manager - * already knows a repository at the given location then that repository is returned. - * <p> - * The resulting repository is added to the list of repositories tracked by - * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} - * if they do not want the repository manager to remember the repository for subsequent - * load attempts. - * </p> - * - * @param location the absolute location in which to look for a repository description - * @param monitor a progress monitor, or <code>null</code> if progress - * reporting is not desired - * @return a repository object for the given location - * @throws ProvisionException if the repository could not be created. Reasons include: - * <ul> - * <li>There is no existing repository at that location.</li> - * <li>The repository at that location could not be read.</li> - * </ul> - */ - public IArtifactRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException; - - /** - * Loads the repository at the given location. The location is expected to contain - * data that describes a valid artifact repository of a known type. If this manager - * already knows a repository at the given location then that repository is returned. - * <p> - * The resulting repository is added to the list of repositories tracked by - * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} - * if they do not want the repository manager to remember the repository for subsequent - * load attempts. - * </p> - * <p> - * The flags passed in should be taken as a hint for the type of repository to load. If - * the manager cannot load a repository that satisfies these hints, it can fail fast. - * </p> - * @param location the absolute location in which to look for a repository description - * @param flags - bit-wise or of flags to consider when loading the repository - * (currently only {@link IRepositoryManager#REPOSITORY_HINT_MODIFIABLE} is supported) - * @param monitor a progress monitor, or <code>null</code> if progress - * reporting is not desired - * @return a repository object for the given location - * @throws ProvisionException if the repository could not be created. Reasons include: - * <ul> - * <li>There is no existing repository at that location.</li> - * <li>The repository at that location could not be read.</li> - * </ul> - * @see IRepositoryManager#REPOSITORY_HINT_MODIFIABLE - */ - public IArtifactRepository loadRepository(URI location, int flags, IProgressMonitor monitor) throws ProvisionException; - - /** - * Refreshes the repository corresponding to the given URL. This method discards - * any cached state held by the repository manager and reloads the repository - * contents. The provided repository location must already be known to the repository - * manager. - * - * @param location The absolute location of the repository to refresh - * @param monitor a progress monitor, or <code>null</code> if progress - * reporting is not desired - * @return The refreshed metadata repository - * @throws ProvisionException if the repository could not be created. Reasons include: - * <ul> - * <li>The location is not known to the repository manager.</li> - * <li>There is no existing repository at that location.</li> - * <li>The repository at that location could not be read.</li> - * </ul> - */ - public IArtifactRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException; - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRequest.java deleted file mode 100644 index f68e11d3c..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRequest.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.artifact.repository; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRequest; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; - -/** - * @noimplement This interface is not intended to be implemented by clients. - */ -public interface IArtifactRequest { - - public IArtifactKey getArtifactKey(); - - /** - * Returns the result of the previous call to {@link ArtifactRequest#perform(IProgressMonitor)}, - * or <code>null</code> if perform has never been called. - * - * @return The result of the previous perform call. - */ - public IStatus getResult(); - -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IFileArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IFileArtifactRepository.java deleted file mode 100644 index 6e6e07be3..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IFileArtifactRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.artifact.repository; - -import java.io.File; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; - -public interface IFileArtifactRepository extends IArtifactRepository { - /** - * Return the location of the full local file corresponding to the given - * artifact key to the given key, or <code>null</code> if not available. - * - * @return the location of the requested artifact or<code>null</code> if not available - */ - public File getArtifactFile(IArtifactKey key); - - /** - * Return the location of the local file corresponding to the given - * artifact descriptor, or <code>null</code> if not available. - * - * @return the location of the requested descriptor or<code>null</code> if not available - */ - public File getArtifactFile(IArtifactDescriptor descriptor); -} 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 15375f95d..403670e1a 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,11 +11,13 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing; +import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor; + import java.io.IOException; import java.io.OutputStream; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor; import org.eclipse.equinox.internal.provisional.p2.repository.IStateful; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; /** * ProcessingSteps process the data written to them and pass the resultant data on @@ -39,7 +41,7 @@ public abstract class ProcessingStep extends OutputStream implements IStateful { * @param descriptor description of the step * @param context the context in which the step is being used */ - public void initialize(ProcessingStepDescriptor descriptor, IArtifactDescriptor context) { + public void initialize(IProcessingStepDescriptor descriptor, IArtifactDescriptor context) { // nothing to do here! } 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 deleted file mode 100644 index f7db92d7e..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepDescriptor.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* -* 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 -*******************************************************************************/ -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; - } - - public String toString() { - return "Processor: " + processorId + (required ? "(req)" : "(notReq)") + " ,data: " + data; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ - } -} 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 508c46486..0387fcd28 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 @@ -11,13 +11,15 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing; +import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor; + 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.p2.artifact.repository.simple.SimpleArtifactRepository.ArtifactOutputStream; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor; import org.eclipse.equinox.internal.provisional.p2.repository.IStateful; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; import org.eclipse.osgi.util.NLS; /** @@ -42,7 +44,7 @@ public class ProcessingStepHandler { IExtensionPoint point = registry.getExtensionPoint(PROCESSING_STEPS_EXTENSION_ID); if (point == null) return false; - ProcessingStepDescriptor[] steps = descriptor.getProcessingSteps(); + IProcessingStepDescriptor[] steps = descriptor.getProcessingSteps(); for (int i = 0; i < steps.length; i++) { if (point.getExtension(steps[i].getProcessorId()) == null) return false; @@ -60,11 +62,11 @@ public class ProcessingStepHandler { public static IStatus getStatus(OutputStream stream, boolean deep) { if (!deep) return getStatus(stream); - ArrayList list = new ArrayList(); + ArrayList<IStatus> list = new ArrayList<IStatus>(); int severity = collectStatus(stream, list); if (severity == IStatus.OK) return Status.OK_STATUS; - IStatus[] result = (IStatus[]) list.toArray(new IStatus[list.size()]); + IStatus[] result = list.toArray(new IStatus[list.size()]); return new MultiStatus(Activator.ID, severity, result, Messages.processing_step_results, null); } @@ -74,15 +76,15 @@ public class ProcessingStepHandler { * @return the requested status */ public static IStatus getErrorStatus(OutputStream stream) { - ArrayList list = new ArrayList(); + ArrayList<IStatus> list = new ArrayList<IStatus>(); int severity = collectErrorStatus(stream, list); if (severity == IStatus.OK) return Status.OK_STATUS; - IStatus[] result = (IStatus[]) list.toArray(new IStatus[list.size()]); + IStatus[] result = list.toArray(new IStatus[list.size()]); return new MultiStatus(Activator.ID, 0, result, Messages.processing_step_results, null); } - private static int collectErrorStatus(OutputStream stream, ArrayList list) { + private static int collectErrorStatus(OutputStream stream, ArrayList<IStatus> list) { IStatus status = getStatus(stream); if (!status.isOK()) list.add(status); @@ -105,7 +107,7 @@ public class ProcessingStepHandler { return Status.OK_STATUS; } - private static int collectStatus(OutputStream stream, ArrayList list) { + private static int collectStatus(OutputStream stream, ArrayList<IStatus> list) { IStatus status = getStatus(stream); list.add(status); OutputStream destination = getDestination(stream); @@ -125,14 +127,14 @@ public class ProcessingStepHandler { return null; } - public ProcessingStep[] create(ProcessingStepDescriptor[] descriptors, IArtifactDescriptor context) { + public ProcessingStep[] create(IProcessingStepDescriptor[] 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) { + public ProcessingStep create(IProcessingStepDescriptor descriptor, IArtifactDescriptor context) { IExtensionRegistry registry = RegistryFactory.getRegistry(); IExtension extension = registry.getExtension(PROCESSING_STEPS_EXTENSION_ID, descriptor.getProcessorId()); Exception error; @@ -155,7 +157,7 @@ public class ProcessingStepHandler { return result; } - public OutputStream createAndLink(ProcessingStepDescriptor[] descriptors, IArtifactDescriptor context, OutputStream output, IProgressMonitor monitor) { + public OutputStream createAndLink(IProcessingStepDescriptor[] descriptors, IArtifactDescriptor context, OutputStream output, IProgressMonitor monitor) { if (descriptors == null) return output; ProcessingStep[] steps = create(descriptors, context); diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/AbstractArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/AbstractArtifactRepository.java deleted file mode 100644 index a5b04501b..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/AbstractArtifactRepository.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository; - -import java.io.OutputStream; -import java.net.URI; -import java.util.Map; -import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.spi.p2.repository.AbstractRepository; - -public abstract class AbstractArtifactRepository extends AbstractRepository implements IArtifactRepository { - - protected AbstractArtifactRepository(String name, String type, String version, URI location, String description, String provider, Map properties) { - super(name, type, version, location, description, provider, properties); - } - - public abstract boolean contains(IArtifactDescriptor descriptor); - - public abstract boolean contains(IArtifactKey key); - - public abstract IStatus getArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor); - - public abstract IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key); - - public abstract IArtifactKey[] getArtifactKeys(); - - public abstract IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor); - - public abstract OutputStream getOutputStream(IArtifactDescriptor descriptor) throws ProvisionException; - - public void addDescriptor(IArtifactDescriptor descriptor) { - assertModifiable(); - } - - public void addDescriptors(IArtifactDescriptor[] descriptors) { - assertModifiable(); - } - - public void removeDescriptor(IArtifactDescriptor descriptor) { - assertModifiable(); - } - - public void removeDescriptor(IArtifactKey key) { - assertModifiable(); - } - - public void removeAll() { - assertModifiable(); - } - - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof AbstractArtifactRepository)) { - return false; - } - if (URIUtil.sameURI(getLocation(), ((AbstractArtifactRepository) o).getLocation())) - return true; - return false; - } - - public int hashCode() { - return (this.getLocation().toString().hashCode()) * 87; - } - -} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/ArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/ArtifactRepositoryFactory.java deleted file mode 100644 index fce9f4e85..000000000 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/ArtifactRepositoryFactory.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository; - -import java.net.URI; -import java.util.Map; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; - -/** - * An artifact repository factory is responsible for creating and loading instances - * of a particular type of artifact repository. Factories are provided via the - * <tt>org.eclipse.equinox.p2.artifact.repository.artifactRepositories</tt> extension point. - */ -public abstract class ArtifactRepositoryFactory { - - /** - * Creates and returns a new empty artifact repository of the given type at - * the given location. - * - * @param location the location for the new repository - * @param name the name of the new repository - * @param type the kind of repository to create - * @param properties the properties to set on the repository - * @return the newly created repository - * @throws ProvisionException if the repository could not be created. Reasons include: - * <ul> - * <li>The repository type is unknown.</li> - * <li>There was an error writing to the given repository location.</li> - * <li>A repository already exists at that location.</li> - * </ul> - */ - public abstract IArtifactRepository create(URI location, String name, String type, Map properties) throws ProvisionException; - - /** - * Loads and returns the repository of this factory's type at the given location. - * <p> - * The error code returned in the case of failure is significant. In particular an - * error code of {@link ProvisionException#REPOSITORY_FAILED_READ} indicates - * that the location definitely identifies a repository of this type, but an error occurred - * while loading the repository. The repository manager will not attempt to load - * a repository from that location using any other factory. An error code of - * {@link ProvisionException#REPOSITORY_NOT_FOUND} indicates there is no - * repository of this type at the given location, and the repository manager is free - * to try again with a different repository factory. - * </p> - * <p> - * The flags passed in should be taken as a hint for the type of repository to load. If - * the factory knows it will not load a repository that satisfies these hints, it can fail - * fast and return null. - * @see IRepositoryManager#REPOSITORY_HINT_MODIFIABLE - * </p> - * @param location the location in which to look for a repository description - * @param flags to consider while loading the repository - * @param monitor a progress monitor, or <code>null</code> if progress - * reporting is not desired - * @return a repository object for the given location - * @throws ProvisionException if the repository could not be created. Reasons include: - * <ul> - * <li>There is no existing repository at that location.</li> - * <li>The repository at that location could not be read.</li> - * </ul> - */ - public abstract IArtifactRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException; -} |