From 24a108a674209394edd8b1ef32c36439ef226eb8 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Fri, 23 Sep 2005 14:23:08 +0000 Subject: [PATCH] Resolving: MNG-767, MNG-768 o We should have a viable offline mode now. Plugin sensitivity updates to follow. o See it0069 and it1014 for offline mode tests. o Brett, building maven-plugins in offline mode with org/apache/maven/plugin/* removed will now give a nice error message. :) git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@291124 13f79535-47bb-0310-9956-ffa450edef68 --- .../deployer/DefaultArtifactDeployer.java | 6 ++ .../artifact/manager/DefaultWagonManager.java | 26 +++++++- .../maven/artifact/manager/WagonManager.java | 4 ++ .../DefaultArtifactRepositoryFactory.java | 14 ++-- .../metadata/AbstractRepositoryMetadata.java | 12 ++++ .../DefaultRepositoryMetadataManager.java | 18 +++++ .../resolver/DefaultArtifactResolver.java | 7 ++ .../AbstractVersionTransformation.java | 9 +++ .../transform/SnapshotTransformation.java | 9 +++ .../metadata/AbstractArtifactMetadata.java | 12 ++++ .../artifact/metadata/ArtifactMetadata.java | 2 + .../repository/ArtifactRepositoryFactory.java | 3 + .../resolver/ArtifactResolutionException.java | 65 ++++++++++++++----- maven-core-it/it0068/verifier.properties | 1 + maven-core-it/it0069/cli-options.txt | 1 + maven-core-it/it0069/expected-results.txt | 1 + maven-core-it/it0069/goals.txt | 1 + maven-core-it/it0069/pom.xml | 14 ++++ .../maven/it0069/ProjectBasedThing.java | 9 +++ maven-core-it/it1014/cli-options.txt | 1 + maven-core-it/it1014/expected-results.txt | 1 + maven-core-it/it1014/goals.txt | 1 + maven-core-it/it1014/pom.xml | 14 ++++ maven-core-it/it1014/prebuild-hook.txt | 1 + .../maven/it0069/ProjectBasedThing.java | 6 ++ .../java/org/apache/maven/DefaultMaven.java | 63 ++++++++++++++++-- .../java/org/apache/maven/cli/MavenCli.java | 5 +- .../maven/plugin/DefaultPluginManager.java | 28 +++++--- .../plugin/PluginContainerException.java | 38 +++++++++++ .../usability/ArtifactResolverDiagnoser.java | 53 +++++++-------- .../maven/usability/DiagnosisUtils.java | 6 ++ .../usability/PluginContainerDiagnoser.java | 51 +++++++++++++++ .../resources/META-INF/plexus/components.xml | 10 +++ .../plugins/release/PrepareReleaseMojo.java | 4 +- .../project/DefaultMavenProjectBuilder.java | 2 +- 35 files changed, 416 insertions(+), 82 deletions(-) create mode 100644 maven-core-it/it0068/verifier.properties create mode 100644 maven-core-it/it0069/cli-options.txt create mode 100644 maven-core-it/it0069/expected-results.txt create mode 100644 maven-core-it/it0069/goals.txt create mode 100644 maven-core-it/it0069/pom.xml create mode 100644 maven-core-it/it0069/src/main/java/org/apache/maven/it0069/ProjectBasedThing.java create mode 100644 maven-core-it/it1014/cli-options.txt create mode 100644 maven-core-it/it1014/expected-results.txt create mode 100644 maven-core-it/it1014/goals.txt create mode 100644 maven-core-it/it1014/pom.xml create mode 100644 maven-core-it/it1014/prebuild-hook.txt create mode 100644 maven-core-it/it1014/src/main/java/org/apache/maven/it0069/ProjectBasedThing.java create mode 100644 maven-core/src/main/java/org/apache/maven/plugin/PluginContainerException.java create mode 100644 maven-core/src/main/java/org/apache/maven/usability/PluginContainerDiagnoser.java diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java index 24e5f41355..b0f847fc8c 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -57,6 +57,12 @@ public class DefaultArtifactDeployer ArtifactRepository localRepository ) throws ArtifactDeploymentException { + if ( !wagonManager.isOnline() ) + { + getLogger().warn( "System is offline. Cannot deploy artifact: " + artifact.getId() + "." ); + return; + } + try { transformationManager.transformForDeployment( artifact, deploymentRepository, localRepository ); diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java index 52c09b73b5..dcbe2975d0 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java @@ -69,6 +69,8 @@ public class DefaultWagonManager private Map mirrors = new HashMap(); private TransferListener downloadMonitor; + + private boolean online = true; public Wagon getWagon( String protocol ) throws UnsupportedProtocolException @@ -105,6 +107,8 @@ public class DefaultWagonManager TransferListener downloadMonitor ) throws TransferFailedException { + failIfNotOnline(); + String protocol = repository.getProtocol(); Wagon wagon; @@ -277,7 +281,9 @@ public class DefaultWagonManager throws TransferFailedException, ResourceDoesNotExistException, ChecksumFailedException { // TODO: better excetpions - transfer failed is not enough? - + + failIfNotOnline(); + Wagon wagon; ArtifactRepository mirror = getMirror( repository.getId() ); @@ -454,6 +460,14 @@ public class DefaultWagonManager } } + private void failIfNotOnline() throws TransferFailedException + { + if ( !isOnline() ) + { + throw new TransferFailedException( "System is offline." ); + } + } + private void handleChecksumFailure( String checksumPolicy, String message, Throwable cause ) throws ChecksumFailedException { @@ -640,4 +654,14 @@ public class DefaultWagonManager mirrors.put( mirrorOf, mirror ); } + + public void setOnline( boolean online ) + { + this.online = online; + } + + public boolean isOnline() + { + return online; + } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java index 6d035b49ed..8269137485 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java @@ -56,6 +56,10 @@ public interface WagonManager void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository, File destination, String checksumPolicy ) throws TransferFailedException, ResourceDoesNotExistException; + + void setOnline( boolean online ); + + boolean isOnline(); void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts ); diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java index bfe8bd0544..020f08437f 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java @@ -29,8 +29,6 @@ public class DefaultArtifactRepositoryFactory private String globalChecksumPolicy; - private boolean globalEnable = true; - public ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout ) { @@ -64,13 +62,6 @@ public class DefaultArtifactRepositoryFactory releases.setChecksumPolicy( globalChecksumPolicy ); } - // TODO: needed, or can offline cover it? - if ( !globalEnable ) - { - snapshots.setEnabled( false ); - releases.setEnabled( false ); - } - return new DefaultArtifactRepository( id, url, repositoryLayout, snapshots, releases ); } @@ -84,8 +75,11 @@ public class DefaultArtifactRepositoryFactory this.globalChecksumPolicy = checksumPolicy; } + /** + * @deprecated. Not needed, use WagonManager.set/isOnline() instead. + */ public void setGlobalEnable( boolean enable ) { - this.globalEnable = enable; + // TODO: Remove this method from the API. } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java index ef93a33c37..7240efb663 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java @@ -178,4 +178,16 @@ public abstract class AbstractRepositoryMetadata AbstractRepositoryMetadata repoMetadata = (AbstractRepositoryMetadata) metadata; this.metadata.merge( repoMetadata.getMetadata() ); } + + public String extendedToString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append( "\nRepository Metadata\n--------------------------" ); + buffer.append( "\nGroupId: " ).append( getGroupId() ); + buffer.append( "\nArtifactId: " ).append( getArtifactId() ); + buffer.append( "\nMetadata Type: " ).append(getClass().getName() ); + + return buffer.toString(); + } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java index 00551ee9fb..2a9319518b 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java @@ -183,6 +183,12 @@ public class DefaultRepositoryMetadataManager ArtifactRepository remoteRepository ) throws ArtifactMetadataRetrievalException { + if ( !wagonManager.isOnline() ) + { + getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" ); + return; + } + File file = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) ); @@ -199,6 +205,12 @@ public class DefaultRepositoryMetadataManager String checksumPolicy ) throws ArtifactMetadataRetrievalException { + if ( !wagonManager.isOnline() ) + { + getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" ); + return; + } + try { wagonManager.getArtifactMetadata( metadata, repository, file, checksumPolicy ); @@ -228,6 +240,12 @@ public class DefaultRepositoryMetadataManager ArtifactRepository deploymentRepository ) throws ArtifactMetadataRetrievalException { + if ( !wagonManager.isOnline() ) + { + getLogger().warn( "System is offline. Cannot deploy metadata:\n" + metadata.extendedToString() + "\n\n" ); + return; + } + getLogger().info( "Retrieving previous metadata from " + deploymentRepository.getId() ); File file = new File( localRepository.getBasedir(), diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index 315c86846a..ceb2f03720 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -113,6 +113,13 @@ public class DefaultArtifactResolver File destination = artifact.getFile(); if ( !destination.exists() || force ) { + if ( !wagonManager.isOnline() ) + { + getLogger().debug( "System is offline. Cannot resolve artifact: " + artifact.getId() + "." ); + + return; + } + try { if ( artifact.getRepository() != null ) diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java index 82a399dd66..aff61ea5bd 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java @@ -154,6 +154,15 @@ public abstract class AbstractVersionTransformation boolean alreadyResolved = alreadyResolved( artifact ); if ( !alreadyResolved ) { + if ( !wagonManager.isOnline() ) + { + LegacyArtifactMetadata metadata = createLegacyMetadata( artifact ); + getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" ); + + return null; + } + + boolean checkedUpdates = false; for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); ) { diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java index ac40147367..403d36e82c 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java @@ -126,6 +126,15 @@ public class SnapshotTransformation { RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + if ( !wagonManager.isOnline() ) + { + getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" ); + + getLogger().info( "System is offline. Assuming build number of 0 for " + metadata.getGroupId() + ":" + metadata.getArtifactId() + " snapshot." ); + + return 0; + } + getLogger().info( "Retrieving previous build number from " + remoteRepository.getId() ); repositoryMetadataManager.resolveAlways( metadata, localRepository, remoteRepository ); diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java index cefc52dcae..69aaab1951 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java @@ -48,4 +48,16 @@ public abstract class AbstractArtifactMetadata { return artifact.getArtifactId(); } + + public String extendedToString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append( "\nArtifact Metadata\n--------------------------" ); + buffer.append( "\nGroupId: " ).append( getGroupId() ); + buffer.append( "\nArtifactId: " ).append( getArtifactId() ); + buffer.append( "\nMetadata Type: " ).append(getClass().getName() ); + + return buffer.toString(); + } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java index 2b5d488875..dca5e85d3b 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java @@ -78,4 +78,6 @@ public interface ArtifactMetadata */ void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository ) throws ArtifactMetadataRetrievalException; + + String extendedToString(); } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java index 33b65476a3..b8600fe221 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java @@ -35,5 +35,8 @@ public interface ArtifactRepositoryFactory void setGlobalChecksumPolicy( String checksumPolicy ); + /** + * @deprecated. Not needed, use WagonManager.set/isOnline() instead. + */ void setGlobalEnable( boolean enable ); } \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java index f11dbc5894..60b73d85ef 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java @@ -41,18 +41,24 @@ public class ArtifactResolutionException private List remoteRepositories; + private final String originalMessage; + + private final String path; + public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type, List remoteRepositories, String downloadUrl, List path, Throwable t ) { super( constructMessage( message, groupId, artifactId, version, type, remoteRepositories, downloadUrl, path ), t ); - + + this.originalMessage = message; this.groupId = groupId; this.artifactId = artifactId; this.type = type; this.version = version; this.remoteRepositories = remoteRepositories; this.downloadUrl = downloadUrl; + this.path = constructArtifactPath( path ); } public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type, @@ -66,16 +72,46 @@ public class ArtifactResolutionException { super( constructMessage( message, groupId, artifactId, version, type, remoteRepositories, downloadUrl, path ) ); + this.originalMessage = message; this.groupId = groupId; this.artifactId = artifactId; this.type = type; this.version = version; this.remoteRepositories = remoteRepositories; this.downloadUrl = downloadUrl; + this.path = constructArtifactPath( path ); + } + + public String getOriginalMessage() + { + return originalMessage; } private static final String LS = System.getProperty( "line.separator" ); + private static String constructArtifactPath( List path ) + { + StringBuffer sb = new StringBuffer(); + + if ( path != null ) + { + sb.append( LS ); + sb.append( "Path to dependency: " ); + sb.append( LS ); + int num = 1; + for ( Iterator i = path.iterator(); i.hasNext(); ) + { + sb.append( "\t" ); + sb.append( num++ ); + sb.append( ") " ); + sb.append( i.next() ); + sb.append( LS ); + } + } + + return sb.toString(); + } + private static String constructMessage( String message, String groupId, String artifactId, String version, String type, List remoteRepositories, String downloadUrl, List path ) { @@ -106,22 +142,8 @@ public class ArtifactResolutionException } } - if ( path != null ) - { - sb.append( LS ); - sb.append( "Path to dependency: " ); - sb.append( LS ); - int num = 1; - for ( Iterator i = path.iterator(); i.hasNext(); ) - { - sb.append( "\t" ); - sb.append( num++ ); - sb.append( ") " ); - sb.append( i.next() ); - sb.append( LS ); - } - sb.append( LS ); - } + sb.append( constructArtifactPath( path ) ); + sb.append( LS ); if ( downloadUrl != null && !type.equals( "pom" ) ) { @@ -168,6 +190,9 @@ public class ArtifactResolutionException public ArtifactResolutionException( String message, Throwable cause ) { super( message, cause ); + + this.originalMessage = message; + this.path = ""; } public String getGroupId() @@ -199,4 +224,10 @@ public class ArtifactResolutionException { return downloadUrl; } + + public String getArtifactPath() + { + return path; + } + } diff --git a/maven-core-it/it0068/verifier.properties b/maven-core-it/it0068/verifier.properties new file mode 100644 index 0000000000..68cb43fc45 --- /dev/null +++ b/maven-core-it/it0068/verifier.properties @@ -0,0 +1 @@ +failOnErrorOutput=false diff --git a/maven-core-it/it0069/cli-options.txt b/maven-core-it/it0069/cli-options.txt new file mode 100644 index 0000000000..30169ae34d --- /dev/null +++ b/maven-core-it/it0069/cli-options.txt @@ -0,0 +1 @@ +-o diff --git a/maven-core-it/it0069/expected-results.txt b/maven-core-it/it0069/expected-results.txt new file mode 100644 index 0000000000..3a104a5258 --- /dev/null +++ b/maven-core-it/it0069/expected-results.txt @@ -0,0 +1 @@ +target/classes/org/apache/maven/it0069/ProjectBasedThing.class diff --git a/maven-core-it/it0069/goals.txt b/maven-core-it/it0069/goals.txt new file mode 100644 index 0000000000..582d9721c9 --- /dev/null +++ b/maven-core-it/it0069/goals.txt @@ -0,0 +1 @@ +compile diff --git a/maven-core-it/it0069/pom.xml b/maven-core-it/it0069/pom.xml new file mode 100644 index 0000000000..ac4fc61047 --- /dev/null +++ b/maven-core-it/it0069/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + org.apache.maven.it0069 + maven-it0069 + 1.0-SNAPSHOT + + + + org.apache.maven + maven-project + 2.0-beta-2-SNAPSHOT + + + diff --git a/maven-core-it/it0069/src/main/java/org/apache/maven/it0069/ProjectBasedThing.java b/maven-core-it/it0069/src/main/java/org/apache/maven/it0069/ProjectBasedThing.java new file mode 100644 index 0000000000..0423b00744 --- /dev/null +++ b/maven-core-it/it0069/src/main/java/org/apache/maven/it0069/ProjectBasedThing.java @@ -0,0 +1,9 @@ +package org.apache.maven.it0069; + +import org.apache.maven.project.MavenProject; + +public class ProjectBasedThing +{ + private MavenProject project; +} + diff --git a/maven-core-it/it1014/cli-options.txt b/maven-core-it/it1014/cli-options.txt new file mode 100644 index 0000000000..30169ae34d --- /dev/null +++ b/maven-core-it/it1014/cli-options.txt @@ -0,0 +1 @@ +-o diff --git a/maven-core-it/it1014/expected-results.txt b/maven-core-it/it1014/expected-results.txt new file mode 100644 index 0000000000..3a104a5258 --- /dev/null +++ b/maven-core-it/it1014/expected-results.txt @@ -0,0 +1 @@ +target/classes/org/apache/maven/it0069/ProjectBasedThing.class diff --git a/maven-core-it/it1014/goals.txt b/maven-core-it/it1014/goals.txt new file mode 100644 index 0000000000..582d9721c9 --- /dev/null +++ b/maven-core-it/it1014/goals.txt @@ -0,0 +1 @@ +compile diff --git a/maven-core-it/it1014/pom.xml b/maven-core-it/it1014/pom.xml new file mode 100644 index 0000000000..fb61077b38 --- /dev/null +++ b/maven-core-it/it1014/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + org.apache.maven.it1014 + maven-it1014 + 1.0-SNAPSHOT + + + + commons-logging + commons-logging + 1.0.3 + + + diff --git a/maven-core-it/it1014/prebuild-hook.txt b/maven-core-it/it1014/prebuild-hook.txt new file mode 100644 index 0000000000..7c145a4a94 --- /dev/null +++ b/maven-core-it/it1014/prebuild-hook.txt @@ -0,0 +1 @@ +rm ${artifact:commons-logging:commons-logging:1.0.3:jar} diff --git a/maven-core-it/it1014/src/main/java/org/apache/maven/it0069/ProjectBasedThing.java b/maven-core-it/it1014/src/main/java/org/apache/maven/it0069/ProjectBasedThing.java new file mode 100644 index 0000000000..374d292a7c --- /dev/null +++ b/maven-core-it/it1014/src/main/java/org/apache/maven/it0069/ProjectBasedThing.java @@ -0,0 +1,6 @@ +package org.apache.maven.it0069; + +public class ProjectBasedThing +{ +} + diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 3a83656567..0659869770 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -103,7 +103,31 @@ public class DefaultMaven { if ( request.getSettings().isOffline() ) { - getLogger().info( "Maven is running in offline mode." ); + getLogger().info( "\n\nNOTE: Maven is running in offline mode.\n\n" ); + + WagonManager wagonManager = null; + + try + { + wagonManager = (WagonManager) container.lookup( WagonManager.ROLE ); + + wagonManager.setOnline( false ); + } + catch ( ComponentLookupException e ) + { + throw new ReactorException( "Cannot retrieve WagonManager in order to set offline mode.", e ); + } + finally + { + try + { + container.release( wagonManager ); + } + catch ( ComponentLifecycleException e ) + { + getLogger().warn( "Cannot release WagonManager.", e ); + } + } } try @@ -239,6 +263,8 @@ public class DefaultMaven } catch ( LifecycleExecutionException e ) { + logFatal( e ); + throw new ReactorException( "Error executing project within the reactor", e ); } @@ -504,6 +530,19 @@ public class DefaultMaven // ---------------------------------------------------------------------- // Reporting / Logging // ---------------------------------------------------------------------- + + protected void logFatal( Throwable error ) + { + line(); + + getLogger().error( "FATAL ERROR" ); + + line(); + + diagnoseError( error ); + + line(); + } protected void logError( MavenExecutionResponse r ) { @@ -513,8 +552,17 @@ public class DefaultMaven line(); - Throwable error = r.getException(); + diagnoseError( r.getException() ); + + line(); + stats( r.getStart(), r.getFinish() ); + + line(); + } + + private void diagnoseError( Throwable error ) + { String message = null; if ( errorDiagnosers != null ) { @@ -538,13 +586,14 @@ public class DefaultMaven line(); - getLogger().error( "Cause: ", r.getException() ); + // TODO: needs to honour -e + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( "Trace:\n", error ); - line(); + line(); + } - stats( r.getStart(), r.getFinish() ); - - line(); } protected void logFailure( MavenExecutionResponse r, Throwable error, String longMessage ) diff --git a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java index 3fb8354005..a53983b11e 100644 --- a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java @@ -413,7 +413,7 @@ public class MavenCli ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE ); - + String url = settings.getLocalRepository(); if ( !url.startsWith( "file:" ) ) @@ -427,8 +427,7 @@ public class MavenCli if ( commandLine.hasOption( CLIManager.OFFLINE ) ) { settings.setOffline( true ); - - artifactRepositoryFactory.setGlobalEnable( false ); + snapshotPolicySet = true; } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 5791a33960..04beab398f 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -188,11 +188,6 @@ public class DefaultPluginManager project.addPlugin( plugin ); } - catch ( PlexusContainerException e ) - { - throw new PluginManagerException( - "Error occurred in the artifact container attempting to download plugin " + plugin.getKey(), e ); - } catch ( ArtifactResolutionException e ) { String groupId = plugin.getGroupId(); @@ -261,7 +256,7 @@ public class DefaultPluginManager protected void addPlugin( Plugin plugin, Artifact pluginArtifact, MavenProject project, ArtifactRepository localRepository ) - throws ArtifactResolutionException, PlexusContainerException + throws ArtifactResolutionException, PluginManagerException { // TODO: share with MMS? Not sure if it belongs here if ( project.getProjectReferences() != null && !project.getProjectReferences().isEmpty() ) @@ -276,11 +271,24 @@ public class DefaultPluginManager } artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository ); + + if ( !pluginArtifact.isResolved() ) + { + throw new PluginContainerException( plugin, "Cannot resolve artifact for plugin." ); + } - PlexusContainer child = container.createChildContainer( plugin.getKey(), - Collections.singletonList( pluginArtifact.getFile() ), - Collections.EMPTY_MAP, - Collections.singletonList( pluginCollector ) ); + PlexusContainer child; + try + { + child = container.createChildContainer( plugin.getKey(), + Collections.singletonList( pluginArtifact.getFile() ), + Collections.EMPTY_MAP, + Collections.singletonList( pluginCollector ) ); + } + catch ( PlexusContainerException e ) + { + throw new PluginContainerException( plugin, "Failed to create plugin container.", e ); + } // this plugin's descriptor should have been discovered in the child creation, so we should be able to // circle around and set the artifacts and class realm diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginContainerException.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginContainerException.java new file mode 100644 index 0000000000..c11945084c --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginContainerException.java @@ -0,0 +1,38 @@ +package org.apache.maven.plugin; + +import org.apache.maven.model.Plugin; + +public class PluginContainerException + extends PluginManagerException +{ + + private final Plugin plugin; + private final String originalMessage; + + public PluginContainerException( Plugin plugin, String message, Exception e ) + { + super( "Error configuring container for: " + plugin.getKey() + ". Message was: " + message, e ); + + this.plugin = plugin; + this.originalMessage = message; + } + + public PluginContainerException( Plugin plugin, String message ) + { + super( "Error configuring container for: " + plugin.getKey() + ". Message was: " + message ); + + this.plugin = plugin; + this.originalMessage = message; + } + + public String getOriginalMessage() + { + return originalMessage; + } + + public Plugin getPlugin() + { + return plugin; + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/usability/ArtifactResolverDiagnoser.java b/maven-core/src/main/java/org/apache/maven/usability/ArtifactResolverDiagnoser.java index 0f4832a5a4..96fd8b8bdf 100644 --- a/maven-core/src/main/java/org/apache/maven/usability/ArtifactResolverDiagnoser.java +++ b/maven-core/src/main/java/org/apache/maven/usability/ArtifactResolverDiagnoser.java @@ -18,7 +18,6 @@ package org.apache.maven.usability; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.TransitiveArtifactResolutionException; -import org.apache.maven.project.ProjectBuildingException; public class ArtifactResolverDiagnoser implements ErrorDiagnoser @@ -26,45 +25,37 @@ public class ArtifactResolverDiagnoser public boolean canDiagnose( Throwable error ) { - return error instanceof ArtifactResolutionException; + return DiagnosisUtils.containsInCausality( error, ArtifactResolutionException.class ); } public String diagnose( Throwable error ) { - Throwable root = DiagnosisUtils.getRootCause( error ); + ArtifactResolutionException exception = (ArtifactResolutionException) DiagnosisUtils.getFromCausality( error, ArtifactResolutionException.class ); - String message = null; - - if ( root instanceof ProjectBuildingException ) + StringBuffer message = new StringBuffer(); + + message.append( "Failed to resolve artifact." ); + message.append( "\n"); + message.append( "\nGroupId: " ).append( exception.getGroupId() ); + message.append( "\nArtifactId: " ).append( exception.getArtifactId() ); + message.append( "\nVersion: " ).append( exception.getVersion() ); + message.append( "\nType: " ).append( exception.getType() ); + + if ( exception instanceof TransitiveArtifactResolutionException ) { - StringBuffer messageBuffer = new StringBuffer(); - - if ( DiagnosisUtils.containsInCausality( error, TransitiveArtifactResolutionException.class ) ) - { - messageBuffer.append( - "Error while transitively resolving artifacts (transitive path trace currently unavailable):\n\n" ); - } - else - { - messageBuffer.append( "Error while resolving artifacts:\n\n" ); - } - - messageBuffer.append( "Root Error:\n " ).append( root.getMessage() ); - - message = messageBuffer.toString(); + message.append( exception.getArtifactPath() ); } - else + + message.append( DiagnosisUtils.getOfflineWarning() ); + + Throwable root = DiagnosisUtils.getRootCause( exception ); + + if ( root != null ) { - StringBuffer messageBuffer = new StringBuffer(); - - messageBuffer.append( "Main Error:\n " ).append( error.getMessage() ); - - messageBuffer.append( "\n\nRoot error:\n " ).append( root.getMessage() ); - - message = messageBuffer.toString(); + message.append( "\n\nRoot Cause: " ).append( root.getMessage() ).append( "\n" ); } - - return message; + + return message.toString(); } } diff --git a/maven-core/src/main/java/org/apache/maven/usability/DiagnosisUtils.java b/maven-core/src/main/java/org/apache/maven/usability/DiagnosisUtils.java index e927de936a..2c8ff105c7 100644 --- a/maven-core/src/main/java/org/apache/maven/usability/DiagnosisUtils.java +++ b/maven-core/src/main/java/org/apache/maven/usability/DiagnosisUtils.java @@ -23,6 +23,12 @@ public final class DiagnosisUtils { } + public static String getOfflineWarning() + { + return "\nNOTE: If Maven is executing in offline mode, some artifacts may be missing from your" + + "\nlocal repository.\n"; + } + public static boolean containsInCausality( Throwable error, Class test ) { Throwable cause = error; diff --git a/maven-core/src/main/java/org/apache/maven/usability/PluginContainerDiagnoser.java b/maven-core/src/main/java/org/apache/maven/usability/PluginContainerDiagnoser.java new file mode 100644 index 0000000000..0caaa29bdb --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/usability/PluginContainerDiagnoser.java @@ -0,0 +1,51 @@ +package org.apache.maven.usability; + +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.PluginContainerException; + +public class PluginContainerDiagnoser + implements ErrorDiagnoser +{ + + public boolean canDiagnose( Throwable error ) + { + return DiagnosisUtils.containsInCausality( error, PluginContainerException.class ); + } + + public String diagnose( Throwable error ) + { + PluginContainerException exception = (PluginContainerException) DiagnosisUtils.getFromCausality( error, PluginContainerException.class ); + + // this is a little hackish, but it's simple. + String originalMessage = exception.getOriginalMessage(); + Plugin plugin = exception.getPlugin(); + + StringBuffer message = new StringBuffer(); + + message.append( "Failed to prepare plugin for execution."); + message.append( "\n" ); + message.append( "\nGroupId: " ).append( plugin.getGroupId() ); + message.append( "\nArtifactId: " ).append( plugin.getArtifactId() ); + message.append( "\nVersion: " ).append( plugin.getVersion() ); + message.append( "\nReason: " ).append( originalMessage ); + + if ( originalMessage.startsWith( "Cannot resolve artifact" ) ) + { + message.append( DiagnosisUtils.getOfflineWarning() ); + } + else + { + Throwable rootCause = DiagnosisUtils.getRootCause( exception ); + + if ( rootCause != null ) + { + message.append( "\nRoot Cause: " ).append( rootCause.getMessage() ); + } + } + + message.append( "\n\n" ); + + return message.toString(); + } + +} diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml index 584f980943..42865e6ff7 100644 --- a/maven-core/src/main/resources/META-INF/plexus/components.xml +++ b/maven-core/src/main/resources/META-INF/plexus/components.xml @@ -101,6 +101,16 @@ PluginConfigurationDiagnoser org.apache.maven.usability.PluginConfigurationDiagnoser + + + org.apache.maven.usability.ErrorDiagnoser + PluginContainerDiagnoser + org.apache.maven.usability.PluginContainerDiagnoser +