diff --git a/maven-archetype/maven-archetypes/maven-archetype-mojo/src/main/resources/archetype-resources/src/main/java/MyMojo.java b/maven-archetype/maven-archetypes/maven-archetype-mojo/src/main/resources/archetype-resources/src/main/java/MyMojo.java index 91f8edee22..7685b5d49e 100644 --- a/maven-archetype/maven-archetypes/maven-archetype-mojo/src/main/resources/archetype-resources/src/main/java/MyMojo.java +++ b/maven-archetype/maven-archetypes/maven-archetype-mojo/src/main/resources/archetype-resources/src/main/java/MyMojo.java @@ -64,7 +64,7 @@ public class MyMojo } catch ( IOException e ) { - throw new PluginExecutionException( "Error creating file " + touch ); + throw new PluginExecutionException( "Error creating file " + touch, e ); } finally { diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java index 92ea734433..b125f662b8 100755 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java @@ -20,6 +20,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; +import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.embed.Embedder; @@ -85,7 +86,7 @@ public abstract class AbstractArtifactTask { embedder.start(); } - catch ( Exception e ) + catch ( PlexusContainerException e ) { throw new BuildException( "Unable to start embedder", e ); } diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java index 85e51181d1..edbaae13a6 100755 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java @@ -107,7 +107,7 @@ public class DependenciesTask } catch ( ArtifactPathFormatException e ) { - throw new BuildException( "Unable to determine path to artifact: " + artifact ); + throw new BuildException( "Unable to determine path to artifact: " + artifact, e ); } FileList.FileName file = new FileList.FileName(); diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java b/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java index a78ea92517..8cd5c17b1d 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java @@ -79,12 +79,6 @@ public class DefaultWagonManager return wagon; } - private void releaseWagon( Wagon wagon ) - throws ComponentLifecycleException - { - container.release( wagon ); - } - public void putArtifact( File source, Artifact artifact, ArtifactRepository repository ) throws TransferFailedException { @@ -147,9 +141,6 @@ public class DefaultWagonManager wagon.connect( repository, getProxy( repository.getProtocol() ) ); wagon.put( source, remotePath ); - - // TODO [BP]: put all disconnects in finally - wagon.disconnect(); } catch ( ConnectionException e ) { @@ -169,14 +160,9 @@ public class DefaultWagonManager } finally { - try - { - releaseWagon( wagon ); - } - catch ( Exception e ) - { - throw new TransferFailedException( "Unable to release wagon", e ); - } + disconnectWagon( wagon ); + + releaseWagon( wagon ); } } @@ -289,9 +275,6 @@ public class DefaultWagonManager wagon.connect( repository, getProxy( repository.getProtocol() ) ); wagon.get( remotePath, temp ); - - // TODO [BP]: put all disconnects in finally - wagon.disconnect(); } catch ( ConnectionException e ) { @@ -307,19 +290,14 @@ public class DefaultWagonManager } finally { - try - { - releaseWagon( wagon ); - } - catch ( Exception e ) - { - throw new TransferFailedException( "Release of wagon failed: ", e ); - } + disconnectWagon( wagon ); + + releaseWagon( wagon ); } if ( !temp.exists() ) { - throw new TransferFailedException( "Downloaded file does not exist: " + temp ); + throw new ResourceDoesNotExistException( "Downloaded file does not exist: " + temp ); } // The temporary file is named destination + ".tmp" and is done this @@ -347,6 +325,30 @@ public class DefaultWagonManager } } + private void disconnectWagon( Wagon wagon ) + { + try + { + wagon.disconnect(); + } + catch ( ConnectionException e ) + { + getLogger().error( "Problem disconnecting from wagon - ignoring: " + e.getMessage() ); + } + } + + private void releaseWagon( Wagon wagon ) + { + try + { + container.release( wagon ); + } + catch ( ComponentLifecycleException e ) + { + getLogger().error( "Problem releasing wagon - ignoring: " + e.getMessage() ); + } + } + private ProxyInfo getProxy( String protocol ) { return (ProxyInfo) proxies.get( protocol ); diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java index d83210e6c7..f1f7a04659 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java @@ -147,16 +147,14 @@ public class SnapshotArtifactMetadata File destination = File.createTempFile( "maven-artifact", null ); destination.deleteOnExit(); - try - { - wagonManager.getArtifactMetadata( snapshotMetadata, remoteRepository, destination ); + wagonManager.getArtifactMetadata( snapshotMetadata, remoteRepository, destination ); - snapshotMetadata.readFromFile( destination ); - } - catch ( ResourceDoesNotExistException e ) - { - // this just means that there is no snapshot version file, so we keep timestamp = null, build = 0 - } + snapshotMetadata.readFromFile( destination ); + } + catch ( ResourceDoesNotExistException e ) + { + // No problem... + // this just means that there is no snapshot version file, so we keep timestamp = null, build = 0 } catch ( TransferFailedException e ) { diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 6ff7b0f439..0be90a2b1e 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -7,6 +7,7 @@ 4.0.0 maven-core Maven + 2.0-SNAPSHOT org.apache.maven.wagon 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 509998e47a..9455b65866 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -87,11 +87,6 @@ public class DefaultMaven public MavenExecutionResponse execute( MavenExecutionRequest request ) throws ReactorException { - if ( request.getGoals().isEmpty() ) - { - throw new ReactorException( "You must specify at least one goal. Try 'install'." ); - } - if ( request.getSettings().getActiveProfile().isOffline() ) { getLogger().info( "Maven is running in offline mode." ); @@ -103,34 +98,34 @@ public class DefaultMaven // TODO: goals are outer loop dispatcher.dispatchStart( event, request.getBaseDirectory() ); + List projects; + try { - List projects; + projects = collectProjects( request.getFiles(), request.getLocalRepository(), request.isRecursive() ); - try - { - projects = collectProjects( request.getFiles(), request.getLocalRepository(), request.isRecursive() ); + projects = MavenProject.getSortedProjects( projects ); - projects = MavenProject.getSortedProjects( projects ); - - if ( projects.isEmpty() ) - { - projects.add( projectBuilder.buildStandaloneSuperProject( request.getLocalRepository() ) ); - } - } - catch ( IOException e ) - { - throw new ReactorException( "Error processing projects for the reactor: ", e ); - } - catch ( ProjectBuildingException e ) - { - throw new ReactorException( "Error processing projects for the reactor: ", e ); - } - catch ( CycleDetectedException e ) - { - throw new ReactorException( "Error processing projects for the reactor: ", e ); - } + if ( projects.isEmpty() ) + { + projects.add( projectBuilder.buildStandaloneSuperProject( request.getLocalRepository() ) ); + } + } + catch ( IOException e ) + { + throw new ReactorException( "Error processing projects for the reactor: ", e ); + } + catch ( ProjectBuildingException e ) + { + throw new ReactorException( "Error processing projects for the reactor: ", e ); + } + catch ( CycleDetectedException e ) + { + throw new ReactorException( "Error processing projects for the reactor: ", e ); + } + try + { for ( Iterator iterator = projects.iterator(); iterator.hasNext(); ) { MavenProject project = (MavenProject) iterator.next(); @@ -143,13 +138,13 @@ public class DefaultMaven try { - MavenExecutionResponse response = processProject( request, project, dispatcher, request.getGoals() ); + MavenExecutionResponse response = processProject( request, project, dispatcher ); if ( response.isExecutionFailure() ) { return response; } } - catch ( Exception e ) + catch ( LifecycleExecutionException e ) { throw new ReactorException( "Error executing project within the reactor", e ); } @@ -188,7 +183,7 @@ public class DefaultMaven if ( includes.indexOf( ".." ) >= 0 ) { - throw new ReactorException( "Modules may not include '..'" ); + throw new ProjectBuildingException( "Modules may not include '..'" ); } List moduleFiles = FileUtils.getFiles( project.getFile().getParentFile(), includes, null ); @@ -203,9 +198,11 @@ public class DefaultMaven } private MavenExecutionResponse processProject( MavenExecutionRequest request, MavenProject project, - EventDispatcher dispatcher, List goals ) + EventDispatcher dispatcher ) throws LifecycleExecutionException { + List goals = request.getGoals(); + MavenSession session = createSession( request, project ); try @@ -252,6 +249,7 @@ public class DefaultMaven } else { + // TODO: throw exceptions like this, so "failures" are just that logError( response ); } } @@ -423,13 +421,29 @@ public class DefaultMaven secs = secs % 60; - if ( min > 0 ) + String msg = ""; + + if ( min > 1 ) { - return min + " minutes " + secs + " seconds"; + msg = min + " minutes "; + } + else if ( min == 1 ) + { + msg = "1 minute "; + } + + if ( secs > 1 ) + { + msg += secs + " seconds"; + } + else if ( secs == 1 ) + { + msg += "1 second"; } else { - return secs + " seconds"; + msg += "< 1 second"; } + return msg; } } diff --git a/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java index 6bd5b44cea..a9f9635bd3 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java @@ -29,8 +29,11 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.wagon.util.IoUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.IOException; import java.util.List; import java.util.Set; @@ -111,10 +114,18 @@ public class MavenMetadataSource Model model = this.reader.read( reader ); dependencies = model.getDependencies(); } - catch ( Exception e ) + catch ( FileNotFoundException e ) + { + throw new ArtifactMetadataRetrievalException( "Unable to find the metadata file", e ); + } + catch ( IOException e ) { throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e ); } + catch ( XmlPullParserException e ) + { + throw new ArtifactMetadataRetrievalException( "Unable to parse the metadata file", e ); + } finally { IoUtils.close( reader ); diff --git a/maven-core/src/main/java/org/apache/maven/artifact/metadata/MavenMetadata.java b/maven-core/src/main/java/org/apache/maven/artifact/metadata/MavenMetadata.java index a5cedb5cce..fe3e1fe54c 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/metadata/MavenMetadata.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/metadata/MavenMetadata.java @@ -24,10 +24,13 @@ import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; +import java.io.IOException; /** * Attach a POM to an artifact. @@ -80,7 +83,15 @@ public class MavenMetadata MavenXpp3Writer modelWriter = new MavenXpp3Writer(); modelWriter.write( writer, model ); } - catch ( Exception e ) + catch ( FileNotFoundException e ) + { + throw new ArtifactMetadataRetrievalException( "Error rewriting POM", e ); + } + catch ( IOException e ) + { + throw new ArtifactMetadataRetrievalException( "Error rewriting POM", e ); + } + catch ( XmlPullParserException e ) { throw new ArtifactMetadataRetrievalException( "Error rewriting POM", e ); } 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 81a112f981..0540665606 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 @@ -1,20 +1,19 @@ package org.apache.maven.cli; -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. +/* + * Copyright 2001-2005 The Apache Software Foundation. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ import org.apache.commons.cli.CommandLine; @@ -91,6 +90,16 @@ public class MavenCli return 1; } + // TODO: maybe classworlds could handle this requirement... + if ( System.getProperty( "java.class.version", "44.0" ).compareTo( "48.0" ) < 0 ) + { + System.err.println( "Sorry, but JDK 1.4 or above is required to execute Maven" ); + System.err.println( + "You appear to be using Java version: " + System.getProperty( "java.version", "" ) ); + + return 1; + } + // ---------------------------------------------------------------------- // // 1) maven user configuration directory ( ~/.m2 ) @@ -194,6 +203,15 @@ public class MavenCli return 1; } + // TODO: this should be in default maven, and should accommodate default goals + if ( request.getGoals().isEmpty() ) + { + System.err.println( "You must specify at least one goal. Try 'install'" ); + + cliManager.displayHelp(); + return 1; + } + MavenExecutionResponse response = null; try { @@ -463,6 +481,8 @@ public class MavenCli public void displayHelp() { + System.out.println(); + HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "maven [options] [goal [goal2 [goal3] ...]]", "\nOptions:", options, "\n" ); } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 11c310808a..d16e1f80b6 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -19,6 +19,7 @@ package org.apache.maven.lifecycle; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.execution.MavenExecutionResponse; import org.apache.maven.execution.MavenSession; @@ -86,57 +87,9 @@ public class DefaultLifecycleExecutor response.setStart( new Date() ); - Map phaseMap = new HashMap(); - - for ( Iterator i = phases.iterator(); i.hasNext(); ) - { - Phase p = (Phase) i.next(); - - // Make a copy of the phase as we will modify it - phaseMap.put( p.getId(), new Phase( p ) ); - } - try { - MavenProject project = session.getProject(); - - ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( project.getPackaging() ); - - if ( artifactHandler != null ) - { - if ( artifactHandler.packageGoal() != null ) - { - verifyMojoPhase( artifactHandler.packageGoal(), session, phaseMap ); - } - - if ( artifactHandler.additionalPlugin() != null ) - { - String additionalPluginGroupId = PluginDescriptor.getDefaultPluginGroupId(); - - String additionalPluginArtifactId = PluginDescriptor.getDefaultPluginArtifactId( - artifactHandler.additionalPlugin() ); - - injectHandlerPluginConfiguration( project, additionalPluginGroupId, additionalPluginArtifactId ); - } - } - - processPluginConfiguration( session.getProject(), session, phaseMap ); - - for ( Iterator i = tasks.iterator(); i.hasNext(); ) - { - String task = (String) i.next(); - - processGoalChain( task, session, phaseMap ); - - if ( phaseMap.containsKey( task ) ) - { - executePhase( task, session, phaseMap ); - } - else - { - executeMojo( task, session ); - } - } + processGoals( session, tasks ); } catch ( PluginExecutionException e ) { @@ -150,6 +103,10 @@ public class DefaultLifecycleExecutor { response.setException( e ); } + catch ( ArtifactResolutionException e ) + { + response.setException( e ); + } finally { response.setFinish( new Date() ); @@ -158,6 +115,68 @@ public class DefaultLifecycleExecutor return response; } + private void processGoals( MavenSession session, List tasks ) + throws ArtifactHandlerNotFoundException, LifecycleExecutionException, PluginNotFoundException, + PluginExecutionException, ArtifactResolutionException + { + Map phaseMap = new HashMap(); + + for ( Iterator i = phases.iterator(); i.hasNext(); ) + { + Phase p = (Phase) i.next(); + + // Make a copy of the phase as we will modify it + phaseMap.put( p.getId(), new Phase( p ) ); + } + + MavenProject project = session.getProject(); + + ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( project.getPackaging() ); + + if ( artifactHandler != null ) + { + if ( artifactHandler.packageGoal() != null ) + { + verifyMojoPhase( artifactHandler.packageGoal(), session, phaseMap ); + } + + if ( artifactHandler.additionalPlugin() != null ) + { + String additionalPluginGroupId = PluginDescriptor.getDefaultPluginGroupId(); + + String additionalPluginArtifactId = PluginDescriptor.getDefaultPluginArtifactId( + artifactHandler.additionalPlugin() ); + + injectHandlerPluginConfiguration( project, additionalPluginGroupId, additionalPluginArtifactId ); + } + } + + processPluginConfiguration( session.getProject(), session, phaseMap ); + + for ( Iterator i = tasks.iterator(); i.hasNext(); ) + { + String task = (String) i.next(); + + processGoalChain( task, session, phaseMap ); + + try + { + if ( phaseMap.containsKey( task ) ) + { + executePhase( task, session, phaseMap ); + } + else + { + executeMojo( task, session ); + } + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Internal error in the plugin manager", e ); + } + } + } + private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId ) { // TODO: this is a bit of a hack to get the version from plugin management - please fix @@ -389,7 +408,7 @@ public class DefaultLifecycleExecutor } private void executePhase( String phase, MavenSession session, Map phaseMap ) - throws PluginExecutionException, PluginNotFoundException + throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException { // only execute up to the given phase int index = phases.indexOf( phaseMap.get( phase ) ); @@ -424,13 +443,23 @@ public class DefaultLifecycleExecutor dispatcher.dispatchError( event, p.getId(), e ); throw e; } + catch ( PluginManagerException e ) + { + dispatcher.dispatchError( event, p.getId(), e ); + throw e; + } + catch ( ArtifactResolutionException e ) + { + dispatcher.dispatchError( event, p.getId(), e ); + throw e; + } dispatcher.dispatchEnd( event, p.getId() ); } } protected void executeMojo( String id, MavenSession session ) - throws PluginExecutionException, PluginNotFoundException + throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException { // ---------------------------------------------------------------------- // We have something of the form :, so this might be 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 43c579d9ca..183717f11f 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 @@ -262,21 +262,8 @@ public class DefaultPluginManager } catch ( ComponentLookupException e ) { - throw new PluginManagerException( "Internal configuration error while retrieving " + groupId + ":" + artifactId, e ); - } - finally - { - if ( artifactFactory != null ) - { - try - { - container.release( artifactFactory ); - } - catch ( ComponentLifecycleException e ) - { - getLogger().error( "Error releasing component - ignoring", e ); - } - } + throw new PluginManagerException( + "Internal configuration error while retrieving " + groupId + ":" + artifactId, e ); } } } @@ -304,44 +291,35 @@ public class DefaultPluginManager { if ( artifactResolver != null ) { - try - { - container.release( artifactResolver ); - } - catch ( ComponentLifecycleException e ) - { - getLogger().error( "Error releasing component - ignoring", e ); - } + releaseComponent( artifactResolver ); } if ( mavenProjectBuilder != null ) { - try - { - container.release( mavenProjectBuilder ); - } - catch ( ComponentLifecycleException e ) - { - getLogger().error( "Error releasing component - ignoring", e ); - } + releaseComponent( mavenProjectBuilder ); } } } + private void releaseComponent( Object component ) + { + try + { + container.release( component ); + } + catch ( ComponentLifecycleException e ) + { + getLogger().error( "Error releasing component - ignoring", e ); + } + } + // ---------------------------------------------------------------------- // Plugin execution // ---------------------------------------------------------------------- public void executeMojo( MavenSession session, String goalName ) - throws PluginExecutionException, PluginNotFoundException + throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException { - try - { - verifyPluginForGoal( goalName, session ); - } - catch ( Exception e ) - { - throw new PluginExecutionException( "Unable to execute goal: " + goalName, e ); - } + verifyPluginForGoal( goalName, session ); PluginExecutionRequest request = null; @@ -351,41 +329,37 @@ public class DefaultPluginManager throw new PluginExecutionException( "Unable to find goal: " + goalName ); } - try + if ( mojoDescriptor.getRequiresDependencyResolution() != null ) { - if ( mojoDescriptor.getRequiresDependencyResolution() != null ) + + ArtifactResolver artifactResolver = null; + MavenProjectBuilder mavenProjectBuilder = null; + + try { + artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE ); + mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE ); - ArtifactResolver artifactResolver = null; - MavenProjectBuilder mavenProjectBuilder = null; - - try + resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder, + mojoDescriptor.getRequiresDependencyResolution() ); + downloadDependencies( session, artifactResolver ); + } + catch ( ComponentLookupException e ) + { + throw new PluginManagerException( "Internal configuration error in plugin manager", e ); + } + finally + { + if ( artifactResolver != null ) { - artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE ); - mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE ); - - resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder, - mojoDescriptor.getRequiresDependencyResolution() ); - downloadDependencies( session, artifactResolver ); + releaseComponent( artifactResolver ); } - finally + if ( mavenProjectBuilder != null ) { - // TODO: watch out for the exceptions being thrown - if ( artifactResolver != null ) - { - container.release( artifactResolver ); - } - if ( mavenProjectBuilder != null ) - { - container.release( mavenProjectBuilder ); - } + releaseComponent( mavenProjectBuilder ); } } } - catch ( Exception e ) - { - throw new PluginExecutionException( "Unable to resolve required dependencies for goal", e ); - } Plugin plugin = null; @@ -421,9 +395,10 @@ public class DefaultPluginManager configuration = new XmlPlexusConfiguration( dom ); } + ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator ); + configuration = mergeConfiguration( configuration, mojoDescriptor.getConfiguration() ); - ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator ); try { if ( newMojoTechnique ) @@ -486,15 +461,7 @@ public class DefaultPluginManager } finally { - try - { - container.release( plugin ); - } - catch ( Exception e ) - { - // TODO: better error handling, needed! - e.printStackTrace(); - } + releaseComponent( plugin ); } } @@ -634,11 +601,11 @@ public class DefaultPluginManager } catch ( NoSuchFieldException e ) { - throw new PluginConfigurationException( "Unable to set field '" + key + "' on '" + clazz + "'" ); + throw new PluginConfigurationException( "Unable to set field '" + key + "' on '" + clazz + "'", e ); } catch ( IllegalAccessException e ) { - throw new PluginConfigurationException( "Unable to set field '" + key + "' on '" + clazz + "'" ); + throw new PluginConfigurationException( "Unable to set field '" + key + "' on '" + clazz + "'", e ); } } } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java index d71f991ac6..6042f7b5ae 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java @@ -17,6 +17,7 @@ package org.apache.maven.plugin; * ==================================================================== */ +import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; @@ -30,7 +31,7 @@ public interface PluginManager String ROLE = PluginManager.class.getName(); void executeMojo( MavenSession session, String goalName ) - throws PluginExecutionException, PluginNotFoundException; + throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException; MojoDescriptor getMojoDescriptor( String goalId ); diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 472ee6f30a..b31df3795c 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -51,6 +51,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.File; import java.io.FileNotFoundException; @@ -162,7 +163,11 @@ public class DefaultMavenProjectBuilder { settings = mavenSettingsBuilder.buildSettings(); } - catch ( Exception e ) + catch ( IOException e ) + { + throw new ProjectBuildingException( "Cannot read settings.", e ); + } + catch ( XmlPullParserException e ) { throw new ProjectBuildingException( "Cannot read settings.", e ); } @@ -193,7 +198,7 @@ public class DefaultMavenProjectBuilder } catch ( ArtifactResolutionException e ) { - throw new ProjectBuildingException( "Unable to find artifact: " + artifact.toString() ); + throw new ProjectBuildingException( "Unable to find artifact: " + artifact.toString(), e ); } model = readModel( artifact.getFile() ); } @@ -267,27 +272,13 @@ public class DefaultMavenProjectBuilder project = new MavenProject( model ); - try - { - project.setPluginArtifactRepositories( buildPluginRepositories( model.getPluginRepositories() ) ); - } - catch ( Exception e ) - { - throw new ProjectBuildingException( "Error building plugin repository list.", e ); - } + project.setPluginArtifactRepositories( buildPluginRepositories( model.getPluginRepositories() ) ); DistributionManagement dm = model.getDistributionManagement(); if ( dm != null ) { - try - { - project.setDistributionManagementArtifactRepository( buildDistributionManagementRepository( - dm.getRepository() ) ); - } - catch ( Exception e ) - { - throw new ProjectBuildingException( "Error building distribution management repository.", e ); - } + project.setDistributionManagementArtifactRepository( buildDistributionManagementRepository( + dm.getRepository() ) ); } project.setParent( parentProject ); @@ -472,13 +463,18 @@ public class DefaultMavenProjectBuilder } catch ( FileNotFoundException e ) { - throw new ProjectBuildingException( "Could not find the model file '" + file.getAbsolutePath() + "'." ); + throw new ProjectBuildingException( "Could not find the model file '" + file.getAbsolutePath() + "'.", e ); } - catch ( Exception e ) + catch ( IOException e ) { throw new ProjectBuildingException( "Error while reading model from file '" + file.getAbsolutePath() + "'.", e ); } + catch ( XmlPullParserException e ) + { + throw new ProjectBuildingException( + "Error while parsing model from file '" + file.getAbsolutePath() + "'.", e ); + } finally { IOUtil.close( reader ); @@ -488,17 +484,23 @@ public class DefaultMavenProjectBuilder private Model readModel( URL url ) throws ProjectBuildingException { + InputStreamReader reader = null; try { - return modelReader.read( new InputStreamReader( url.openStream() ) ); + reader = new InputStreamReader( url.openStream() ); + return modelReader.read( reader ); } catch ( IOException e ) { - throw new ProjectBuildingException( "Error while reading model.", e ); + throw new ProjectBuildingException( "Error while building model from " + url.toExternalForm(), e ); } - catch ( Exception ex ) + catch ( XmlPullParserException e ) { - throw new ProjectBuildingException( "Error while building model from " + url.toExternalForm(), ex ); + throw new ProjectBuildingException( "Error while building model from " + url.toExternalForm(), e ); + } + finally + { + IOUtil.close( reader ); } } diff --git a/maven-core/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java b/maven-core/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java index a8ae1c89ac..dd2ca0afea 100644 --- a/maven-core/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java +++ b/maven-core/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java @@ -23,7 +23,9 @@ import org.apache.maven.util.introspection.ReflectionValueExtractor; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.util.regex.Matcher; @@ -52,7 +54,7 @@ public class RegexBasedModelInterpolator { writer.write( sWriter, model ); } - catch ( Exception e ) + catch ( IOException e ) { throw new ModelInterpolationException( "Cannot serialize project model for interpolation.", e ); } @@ -67,7 +69,12 @@ public class RegexBasedModelInterpolator { model = modelReader.read( sReader ); } - catch ( Exception e ) + catch ( IOException e ) + { + throw new ModelInterpolationException( + "Cannot read project model from interpolating filter of serialized version.", e ); + } + catch ( XmlPullParserException e ) { throw new ModelInterpolationException( "Cannot read project model from interpolating filter of serialized version.", e ); diff --git a/maven-core/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java b/maven-core/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java index 03c97dd9dd..9109e35cfe 100644 --- a/maven-core/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java +++ b/maven-core/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java @@ -22,7 +22,6 @@ import org.apache.maven.model.Resource; import java.io.File; import java.util.Iterator; -import java.util.List; public class DefaultPathTranslator implements PathTranslator diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index 71673722b8..4802088cb0 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -67,9 +67,6 @@ public class PluginParameterExpressionEvaluatorTest String actual = new File( value.toString() ).getCanonicalPath(); - System.out.println( "Expected value: " + expected ); - System.out.println( "Resolved value: " + actual ); - assertEquals( expected, actual ); } diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java b/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java index 2c31f7a465..f60d3385eb 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java @@ -30,8 +30,11 @@ import org.apache.maven.artifact.resolver.DefaultArtifactResolver; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.File; +import java.io.IOException; import java.io.InputStreamReader; import java.util.List; import java.util.Set; @@ -52,18 +55,28 @@ public class ProjectClasspathArtifactResolver public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException { - MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = null; + InputStreamReader r = null; try { String scope = artifact.getArtifactId().substring( "scope-".length() ); String name = "/projects/scope/transitive-" + scope + "-dep.xml"; - model = reader.read( new InputStreamReader( getClass().getResourceAsStream( name ) ) ); + r = new InputStreamReader( getClass().getResourceAsStream( name ) ); + MavenXpp3Reader reader = new MavenXpp3Reader(); + model = reader.read( r ); } - catch ( Exception e ) + catch ( IOException e ) { throw new ArtifactMetadataRetrievalException( e ); } + catch ( XmlPullParserException e ) + { + throw new ArtifactMetadataRetrievalException( e ); + } + finally + { + IOUtil.close( r ); + } return artifactFactory.createArtifacts( model.getDependencies(), localRepository, artifact.getScope() ); } } diff --git a/maven-core/src/test/java/org/apache/maven/project/inheritance/ProjectInheritanceTestCase.java b/maven-core/src/test/java/org/apache/maven/project/inheritance/ProjectInheritanceTestCase.java index b072c753d5..35e3a63871 100644 --- a/maven-core/src/test/java/org/apache/maven/project/inheritance/ProjectInheritanceTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/project/inheritance/ProjectInheritanceTestCase.java @@ -16,10 +16,9 @@ package org.apache.maven.project.inheritance; * limitations under the License. */ -import java.io.File; - import org.apache.maven.MavenTestCase; -import org.apache.maven.project.MavenProjectBuilder; + +import java.io.File; /** * @author Jason van Zyl diff --git a/maven-core/src/test/java/org/apache/maven/util/introspection/ReflectionValueExtractorTest.java b/maven-core/src/test/java/org/apache/maven/util/introspection/ReflectionValueExtractorTest.java index 829c9319aa..1137dba4e1 100644 --- a/maven-core/src/test/java/org/apache/maven/util/introspection/ReflectionValueExtractorTest.java +++ b/maven-core/src/test/java/org/apache/maven/util/introspection/ReflectionValueExtractorTest.java @@ -19,7 +19,6 @@ package org.apache.maven.util.introspection; import org.apache.maven.MavenTestCase; import org.apache.maven.model.Build; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuilder; import java.io.File; import java.util.List; diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java index 6dd7ffc99c..e9b89b5ff9 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java @@ -20,13 +20,13 @@ public class PluginUtilsTest public void testShouldTrimArtifactIdToFindPluginId() { Model model = new Model(); - model.setArtifactId( "test-artifactId-plugin" ); + model.setArtifactId( "maven-artifactId-plugin" ); MavenProject project = new MavenProject( model ); String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() ); - System.out.println( pluginId ); + assertEquals( "artifactId", pluginId ); } public void testShouldWriteDependencies() diff --git a/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java b/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java index a933c2d366..7551832818 100755 --- a/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java +++ b/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AssemblyMojo.java @@ -110,15 +110,14 @@ public class AssemblyMojo InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + descriptorId + ".xml" ); if ( resourceAsStream == null ) { - // TODO: better exception - throw new Exception( "Descriptor with ID '" + descriptorId + "' not found" ); + throw new PluginExecutionException( "Descriptor with ID '" + descriptorId + "' not found" ); } r = new InputStreamReader( resourceAsStream ); } else { // TODO: better exception - throw new Exception( "You must specify descriptor or descriptorId" ); + throw new PluginExecutionException( "You must specify descriptor or descriptorId" ); } try diff --git a/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanPlugin.java b/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanPlugin.java index b37cdd0459..a71664b5f3 100644 --- a/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanPlugin.java +++ b/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanPlugin.java @@ -53,14 +53,7 @@ public class CleanPlugin if ( dir.exists() && dir.isDirectory() ) { getLog().info( "Deleting directory " + dir.getAbsolutePath() ); - try - { - removeDir( dir ); - } - catch ( Exception e ) - { - throw new PluginExecutionException( "Unable to delete directory", e ); - } + removeDir( dir ); } } } diff --git a/maven-plugins/maven-install-plugin/pom.xml b/maven-plugins/maven-install-plugin/pom.xml index fd2fd485b8..25276f4644 100644 --- a/maven-plugins/maven-install-plugin/pom.xml +++ b/maven-plugins/maven-install-plugin/pom.xml @@ -19,7 +19,7 @@ org.apache.maven maven-artifact - 2.0-alpha-1 + 2.0-SNAPSHOT diff --git a/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java b/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java index bed320c933..b146ce3d0b 100644 --- a/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java +++ b/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java @@ -32,7 +32,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeMap; -import java.util.Map.Entry; /** * @author Michal Maczka @@ -67,7 +66,7 @@ public class ResourcesMojo { for ( Iterator i = getJarResources( resources ).entrySet().iterator(); i.hasNext(); ) { - Map.Entry entry = (Entry) i.next(); + Map.Entry entry = (Map.Entry) i.next(); String source = (String) entry.getKey(); String destination = (String) entry.getValue(); diff --git a/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/MarmaladeMojo.java b/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/MarmaladeMojo.java index a497147f65..009dfe99e1 100644 --- a/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/MarmaladeMojo.java +++ b/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/MarmaladeMojo.java @@ -16,9 +16,7 @@ package org.apache.maven.script.marmalade; * limitations under the License. */ -import org.apache.maven.monitor.logging.Log; import org.apache.maven.plugin.AbstractPlugin; -import org.apache.maven.plugin.FailureResponse; import org.apache.maven.plugin.PluginExecutionRequest; import org.apache.maven.plugin.PluginExecutionResponse; import org.codehaus.marmalade.model.MarmaladeScript;