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 Ray Braithwood (ray@genuitec.com) - fix for bug 220605 Code 9 - ongoing development Sonatype, Inc. - transport split /
 
 package org.eclipse.equinox.internal.p2.updatesite.metadata;
 
 import java.io.File;
 import java.net.URI;
 import java.util.Map;
 
 	private static final String PROP_SITE_CHECKSUM = "site.checksum"//$NON-NLS-1$
 
 	public static URI getLocalRepositoryLocation(URI location) {
 		String stateDirName = Integer.toString(location.hashCode());
 		File bundleData = Activator.getBundleContext().getDataFile(null);
 		File stateDir = new File(bundleDatastateDirName);
 		return stateDir.toURI();
 	}
 
 	/* (non-Javadoc)
 	 * @see org.eclipse.equinox.p2.repository.metadata.spi.MetadataRepositoryFactory#create(java.net.URL, java.lang.String, java.lang.String, java.util.Map)
 	 */
 	public IMetadataRepository create(URI locationString nameString typeMap<StringStringproperties) {
 		return null;
 	}
 
 	public IMetadataRepository load(URI locationint flagsIProgressMonitor monitorthrows ProvisionException {
 		//return null if the caller wanted a modifiable repo
 		if ((flags & .) > 0) {
 			return null;
 		}
 
 		IMetadataRepository repository = loadRepository(locationmonitor);
 		try {
 			initializeRepository(repositorylocationmonitor);
 		} catch (Exception e) {
 			resetCache(repository);
 			if (e instanceof ProvisionException)
 				throw (ProvisionExceptione;
 			if (e instanceof OperationCanceledException)
 		}
 		return new UpdateSiteMetadataRepository(locationrepository);
 	}
 
 	private void resetCache(IMetadataRepository repository) {
 		repository.setProperty("0"); //$NON-NLS-1$
 		repository.removeAll();
 	}
 
 	public IMetadataRepository loadRepository(URI locationIProgressMonitor monitor) {
 		URI localRepositoryURL = 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(IMetadataRepository 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;
 		repository.setProperty(updateSite.getChecksum());
 		repository.removeAll();
 		IStatus status = generateMetadata(updateSiterepositorymonitor);
 		//site references should be published on load
 		if (repository instanceof LocalMetadataRepository)
 		if (monitor.isCanceled())
 		if (!status.isOK())
			throw new ProvisionException(status);
	}
	private IStatus generateMetadata(UpdateSite updateSiteIMetadataRepository repositoryIProgressMonitor monitor) {
		PublisherInfo info = new PublisherInfo();
		info.setMetadataRepository(repository);
		IPublisherAction[] actions = new IPublisherAction[] {new RemoteUpdateSiteAction(updateSitenull)};
		Publisher publisher = new Publisher(info);
		return publisher.publish(actionsmonitor);
	}
New to GrepCode? Check out our FAQ X