Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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 Code 9 - ongoing development Sonatype, Inc. - transport split /
 
 package org.eclipse.equinox.internal.p2.updatesite.artifact;
 
 import java.net.URI;
 import java.util.*;
 import  org.eclipse.equinox.p2.publisher.eclipse.*;
 
 
 	/* (non-Javadoc)
 	 * @see org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.ArtifactRepositoryFactory#create(java.net.URL, java.lang.String, java.lang.String, java.util.Map)
 	 */
 	public IArtifactRepository create(URI locationString nameString typeMap<StringStringproperties) {
 		return null;
 	}
 
 	private static final String PROP_ARTIFACT_REFERENCE = "artifact.reference"//$NON-NLS-1$
 	private static final String PROP_FORCE_THREADING = "eclipse.p2.force.threading"//$NON-NLS-1$
 	private static final String PROP_SITE_CHECKSUM = "site.checksum"//$NON-NLS-1$
 	private static final String PROTOCOL_FILE = "file"//$NON-NLS-1$
 
 	/* (non-Javadoc)
 	 * @see org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.ArtifactRepositoryFactory#load(java.net.URL, org.eclipse.core.runtime.IProgressMonitor)
 	 */
 	public IArtifactRepository load(URI locationint flagsIProgressMonitor monitorthrows ProvisionException {
 		//return null if the caller wanted a modifiable repo
 		if ((flags & .) > 0) {
 			return null;
 		}
 		IArtifactRepository repository = loadRepository(locationmonitor);
 		try {
 			initializeRepository(repositorylocationmonitor);
 		} catch (Exception e) {
 			resetCache(repository);
 			if (e instanceof ProvisionException)
 				throw (ProvisionExceptione;
 			if (e instanceof OperationCanceledException)
 		}
 		return new UpdateSiteArtifactRepository(locationrepository);
 	}
 
 	private void resetCache(IArtifactRepository repository) {
 		repository.setProperty("0"); //$NON-NLS-1$
 		repository.removeAll();
 	}
 
 	public IArtifactRepository loadRepository(URI locationIProgressMonitor monitor) {
 		URI localRepositoryURL = UpdateSiteMetadataRepositoryFactory.getLocalRepositoryLocation(location);
 		factory.setAgent(getAgent());
 		try {
 			return factory.load(localRepositoryURL, 0, monitor);
 		} catch (ProvisionException e) {
 			//fall through and create a new repository
 		}
 		String repositoryName = "update site: " + location//$NON-NLS-1$
 		return factory.create(localRepositoryURLrepositoryNamenullnull);
 	}
 
 	public void initializeRepository(IArtifactRepository repositoryURI locationIProgressMonitor monitorthrows ProvisionException {
 		UpdateSite updateSite = UpdateSite.load(location, (TransportgetAgent().getService(.), monitor);
 		String savedChecksum = repository.getProperties().get();
 		if (savedChecksum != null && savedChecksum.equals(updateSite.getChecksum()))
 			return;
 
 		if (!location.getScheme().equals())
 			repository.setProperty("true"); //$NON-NLS-1$
 		repository.setProperty(updateSite.getChecksum());
 		if (updateSite.getSite().getMirrorsURI() != null)
 		repository.removeAll();
 		generateArtifactDescriptors(updateSiterepositorymonitor);
	}
	private void generateArtifactDescriptors(UpdateSite updateSiteIArtifactRepository repositoryIProgressMonitor monitorthrows ProvisionException {
		final String PACK_EXT = ".pack.gz"//$NON-NLS-1$
		Feature[] features = updateSite.loadFeatures(monitor);
		Set<IArtifactDescriptorallSiteArtifacts = new HashSet<IArtifactDescriptor>();
		boolean packSupported = updateSite.getSite().isPack200Supported();
		for (int i = 0; i < features.length; i++) {
			Feature feature = features[i];
			IArtifactKey featureKey = FeaturesAction.createFeatureArtifactKey(feature.getId(), feature.getVersion());
			SimpleArtifactDescriptor featureArtifactDescriptor = new SimpleArtifactDescriptor(featureKey);
			URI featureURL = updateSite.getFeatureURI(feature.getId(), feature.getVersion());
			featureArtifactDescriptor.setRepositoryProperty(featureURL.toString());
			allSiteArtifacts.add(featureArtifactDescriptor);
			if (packSupported) {
				// Update site supports pack200, create a packed descriptor
				featureArtifactDescriptor = new SimpleArtifactDescriptor(featureKey);
				featureURL = updateSite.getFeatureURI(feature.getId(), feature.getVersion());
				featureArtifactDescriptor.setRepositoryProperty(featureURL.toString() + PACK_EXT);
				IProcessingStepDescriptor[] steps = new IProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker"nulltrue)}; //$NON-NLS-1$
				featureArtifactDescriptor.setProcessingSteps(steps);
				allSiteArtifacts.add(featureArtifactDescriptor);
			}
			FeatureEntry[] featureEntries = feature.getEntries();
			for (int j = 0; j < featureEntries.length; j++) {
				FeatureEntry entry = featureEntries[j];
				if (entry.isPlugin() && !entry.isRequires()) {
					IArtifactKey key = BundlesAction.createBundleArtifactKey(entry.getId(), entry.getVersion());
					SimpleArtifactDescriptor artifactDescriptor = new SimpleArtifactDescriptor(key);
					URI pluginURL = updateSite.getPluginURI(entry);
					artifactDescriptor.setRepositoryProperty(pluginURL.toString());
					allSiteArtifacts.add(artifactDescriptor);
					if (packSupported) {
						// Update site supports pack200, create a packed descriptor
						key = BundlesAction.createBundleArtifactKey(entry.getId(), entry.getVersion());
						artifactDescriptor = new SimpleArtifactDescriptor(key);
						pluginURL = updateSite.getPluginURI(entry);
						artifactDescriptor.setRepositoryProperty(pluginURL.toString() + PACK_EXT);
						IProcessingStepDescriptor[] steps = new IProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker"nulltrue)}; //$NON-NLS-1$
						artifactDescriptor.setProcessingSteps(steps);
						allSiteArtifacts.add(artifactDescriptor);
					}
				}
			}
		}
		IArtifactDescriptor[] descriptors = allSiteArtifacts.toArray(new IArtifactDescriptor[allSiteArtifacts.size()]);
		repository.addDescriptors(descriptors);
	}
New to GrepCode? Check out our FAQ X