diff options
author | John Arthorne | 2008-01-11 19:44:52 +0000 |
---|---|---|
committer | John Arthorne | 2008-01-11 19:44:52 +0000 |
commit | 1f258fb6ac201453758093c8aefc9df97a8ad54d (patch) | |
tree | 4cf46b44734f7412328c02aac9fa506b20d01441 /bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact | |
parent | a88c0d834badddf3dd4a08fd15ba6b0519c9c90d (diff) | |
download | rt.equinox.p2-1f258fb6ac201453758093c8aefc9df97a8ad54d.tar.gz rt.equinox.p2-1f258fb6ac201453758093c8aefc9df97a8ad54d.tar.xz rt.equinox.p2-1f258fb6ac201453758093c8aefc9df97a8ad54d.zip |
Bug 212348 [prov] [repo] Find a way to better report the failure of repository addition
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact')
5 files changed, 89 insertions, 33 deletions
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 index eced9e191..bd6d2de73 100644 --- 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 @@ -16,6 +16,7 @@ import org.eclipse.equinox.internal.p2.artifact.repository.Activator; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.p2.artifact.repository.IArtifactRepository; import org.eclipse.equinox.p2.artifact.repository.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.core.ProvisionException; public class MirrorApplication implements IApplication { @@ -34,7 +35,7 @@ public class MirrorApplication implements IApplication { return null; } - private void setupRepositories() { + private void setupRepositories() throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) // TODO log here @@ -47,17 +48,18 @@ public class MirrorApplication implements IApplication { destination = source; } - private IArtifactRepository initializeDestination() { + private IArtifactRepository initializeDestination() throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); - IArtifactRepository repository = manager.loadRepository(destinationLocation, null); - if (repository != null) { + try { + IArtifactRepository repository = manager.loadRepository(destinationLocation, null); if (!repository.isModifiable()) throw new IllegalArgumentException("Artifact repository not modifiable: " + destinationLocation); //$NON-NLS-1$ if (!append) repository.removeAll(); return repository; + } catch (ProvisionException e) { + //fall through and create a new repository below } - // the given repo location is not an existing repo so we have to create something // TODO for now create a Simple repo by default. String repositoryName = destinationLocation + " - artifacts"; //$NON-NLS-1$ 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 fa6cec010..c533e2c2a 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 @@ -18,10 +18,12 @@ import org.eclipse.core.runtime.preferences.ConfigurationScope; import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository; import org.eclipse.equinox.internal.p2.core.helpers.*; import org.eclipse.equinox.p2.artifact.repository.*; +import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.core.location.AgentLocation; import org.eclipse.equinox.p2.core.repository.IRepository; import org.eclipse.equinox.p2.metadata.IArtifactKey; import org.eclipse.equinox.spi.p2.artifact.repository.IArtifactRepositoryFactory; +import org.eclipse.osgi.util.NLS; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; @@ -96,13 +98,20 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager { return new FileDownloadRequest(key, destination); } - private Object createExecutableExtension(IExtension extension, String element) throws CoreException { + private Object createExecutableExtension(IExtension extension, String element) throws ProvisionException { IConfigurationElement[] elements = extension.getConfigurationElements(); for (int i = 0; i < elements.length; i++) { - if (elements[i].getName().equals(element)) - return elements[i].createExecutableExtension("class"); //$NON-NLS-1$ + if (elements[i].getName().equals(element)) { + try { + return elements[i].createExecutableExtension("class"); //$NON-NLS-1$ + } catch (CoreException e) { + log("Error loading repository extension: " + extension.getUniqueIdentifier(), e); //$NON-NLS-1$ + return null; + } + } } - throw new CoreException(new Status(IStatus.ERROR, Activator.ID, "Malformed extension")); //$NON-NLS-1$ + log("Malformed repository extension: " + extension.getUniqueIdentifier(), null); //$NON-NLS-1$ + return null; } public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination) { @@ -113,25 +122,45 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager { return new MirrorRequest(key, destination, destinationDescriptorProperties, destinationRepositoryProperties); } - public IArtifactRepository createRepository(URL location, String name, String type) { - IArtifactRepository result = loadRepository(location, (IProgressMonitor) null); - if (result != null) - return result; - IExtension extension = RegistryFactory.getRegistry().getExtension(Activator.REPO_PROVIDER_XPT, type); - if (extension == null) - return null; + private void fail(URL location, int code) throws ProvisionException { + String msg = null; + switch (code) { + case ProvisionException.REPOSITORY_EXISTS : + msg = NLS.bind(Messages.repoMan_exists, location); + break; + case ProvisionException.REPOSITORY_UNKNOWN_TYPE : + msg = NLS.bind(Messages.repoMan_unknownType, location); + break; + case ProvisionException.REPOSITORY_FAILED_READ : + msg = NLS.bind(Messages.repoMan_failedRead, location); + break; + case ProvisionException.REPOSITORY_NOT_FOUND : + msg = NLS.bind(Messages.repoMan_notExists, location); + break; + } + if (msg == null) + msg = Messages.repoMan_internalError; + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, code, msg, null)); + } + + public IArtifactRepository createRepository(URL location, String name, String type) throws ProvisionException { try { - IArtifactRepositoryFactory factory = (IArtifactRepositoryFactory) createExecutableExtension(extension, EL_FACTORY); - if (factory == null) - return null; - result = factory.create(location, name, type); - if (result != null) - addRepository(result); - return result; - } catch (CoreException e) { - log("Failed to load artifact repository extension: " + location, e); //$NON-NLS-1$ - return null; + loadRepository(location, (IProgressMonitor) null); + fail(location, ProvisionException.REPOSITORY_EXISTS); + } catch (ProvisionException e) { + //expected - fall through and create a new repository } + IExtension extension = RegistryFactory.getRegistry().getExtension(Activator.REPO_PROVIDER_XPT, type); + if (extension == null) + fail(location, ProvisionException.REPOSITORY_UNKNOWN_TYPE); + IArtifactRepositoryFactory factory = (IArtifactRepositoryFactory) createExecutableExtension(extension, EL_FACTORY); + if (factory == null) + fail(location, ProvisionException.REPOSITORY_FAILED_READ); + IArtifactRepository result = factory.create(location, name, type); + if (result == null) + fail(location, ProvisionException.REPOSITORY_FAILED_READ); + addRepository(result); + return result; } private IExtension[] findMatchingRepositoryExtensions(String suffix) { @@ -247,7 +276,7 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager { } } - public IArtifactRepository loadRepository(URL location, IProgressMonitor monitor) { + public IArtifactRepository loadRepository(URL location, IProgressMonitor monitor) throws ProvisionException { // TODO do something with the monitor IArtifactRepository result = getRepository(location); if (result != null) @@ -260,6 +289,7 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager { return result; } } + fail(location, ProvisionException.REPOSITORY_NOT_FOUND); return null; } @@ -364,8 +394,12 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager { if (location == null) // TODO should do something here since we are failing to restore. return; - SimpleArtifactRepository cache = (SimpleArtifactRepository) createRepository(location.getArtifactRepositoryURL(), "download cache", "org.eclipse.equinox.p2.artifact.repository.simpleRepository"); //$NON-NLS-1$ //$NON-NLS-2$ - cache.setProperty(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); + try { + SimpleArtifactRepository cache = (SimpleArtifactRepository) createRepository(location.getArtifactRepositoryURL(), "download cache", "org.eclipse.equinox.p2.artifact.repository.simpleRepository"); //$NON-NLS-1$ //$NON-NLS-2$ + cache.setProperty(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); + } catch (ProvisionException e) { + LogHelper.log(e); + } } /* 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 73031acb6..69d1b4ab5 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. + * 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 @@ -25,6 +25,12 @@ public class Messages extends NLS { // Do not instantiate } + public static String repoMan_exists; + public static String repoMan_failedRead; + public static String repoMan_internalError; + public static String repoMan_notExists; + public static String repoMan_unknownType; + public static String FileDownloadError; public static String SimpleArtifactRepositoryIO_Parser_Error_Parsing_Repository; public static String SimpleArtifactRepositoryIO_Parser_Has_Incompatible_Version; 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 08a3f7e0e..968fdf167 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 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2007 IBM Corporation and others. +# 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 @@ -13,4 +13,11 @@ FileDownloadError=Error downloading {0} to {1}. SimpleArtifactRepositoryIO_Parser_Error_Parsing_Registry=\ Error parsing simple artifact repository SimpleArtifactRepositoryIO_Parser_Has_Incompatible_Version=\ - Simple artifact repository has incompatible version {0}; expected {1}
\ No newline at end of file + Simple artifact repository has incompatible version {0}; expected {1} + +repoMan_exists=Repository already exists at {0} +repoMan_failedRead=The repository could not be read: {0} +repoMan_internalError=Internal error +repoMan_notExists=No repository found at {0} +repoMan_unknownType=Unknown repository type at {0} +
\ No newline at end of file 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 189d7f606..a65b1d8f3 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 @@ -21,6 +21,7 @@ import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.p2.artifact.repository.*; import org.eclipse.equinox.p2.artifact.repository.processing.ProcessingStep; import org.eclipse.equinox.p2.artifact.repository.processing.ProcessingStepHandler; +import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.metadata.IArtifactKey; import org.eclipse.equinox.spi.p2.artifact.repository.AbstractArtifactRepository; @@ -95,6 +96,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme count++; } } + // TODO: optimize // we could stream right into the folder public static class ZippedFolderOutputStream extends OutputStream { @@ -135,6 +137,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme fos.write(b); } } + private static final String ARTIFACT_FOLDER = "artifact.folder"; //$NON-NLS-1$ private static final String ARTIFACT_REFERENCE = "artifact.reference"; //$NON-NLS-1$ private static final String ARTIFACT_UUID = "artifact.uuid"; //$NON-NLS-1$ @@ -695,7 +698,11 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme save(); //force repository manager to reload this repository because it caches properties IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); - manager.loadRepository(location, null); + try { + manager.loadRepository(location, null); + } catch (ProvisionException e) { + //ignore + } return oldValue; } |