improved error handling and other clean up

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163979 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-20 16:41:36 +00:00
parent 4fe1c64276
commit a75e7d2577
26 changed files with 336 additions and 276 deletions

View File

@ -64,7 +64,7 @@ public class MyMojo
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new PluginExecutionException( "Error creating file " + touch ); throw new PluginExecutionException( "Error creating file " + touch, e );
} }
finally finally
{ {

View File

@ -20,6 +20,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.embed.Embedder; import org.codehaus.plexus.embed.Embedder;
@ -85,7 +86,7 @@ public abstract class AbstractArtifactTask
{ {
embedder.start(); embedder.start();
} }
catch ( Exception e ) catch ( PlexusContainerException e )
{ {
throw new BuildException( "Unable to start embedder", e ); throw new BuildException( "Unable to start embedder", e );
} }

View File

@ -107,7 +107,7 @@ public class DependenciesTask
} }
catch ( ArtifactPathFormatException e ) 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(); FileList.FileName file = new FileList.FileName();

View File

@ -79,12 +79,6 @@ public class DefaultWagonManager
return wagon; return wagon;
} }
private void releaseWagon( Wagon wagon )
throws ComponentLifecycleException
{
container.release( wagon );
}
public void putArtifact( File source, Artifact artifact, ArtifactRepository repository ) public void putArtifact( File source, Artifact artifact, ArtifactRepository repository )
throws TransferFailedException throws TransferFailedException
{ {
@ -147,9 +141,6 @@ public class DefaultWagonManager
wagon.connect( repository, getProxy( repository.getProtocol() ) ); wagon.connect( repository, getProxy( repository.getProtocol() ) );
wagon.put( source, remotePath ); wagon.put( source, remotePath );
// TODO [BP]: put all disconnects in finally
wagon.disconnect();
} }
catch ( ConnectionException e ) catch ( ConnectionException e )
{ {
@ -169,15 +160,10 @@ public class DefaultWagonManager
} }
finally finally
{ {
try disconnectWagon( wagon );
{
releaseWagon( wagon ); releaseWagon( wagon );
} }
catch ( Exception e )
{
throw new TransferFailedException( "Unable to release wagon", e );
}
}
} }
public void getArtifact( Artifact artifact, List remoteRepositories, File destination ) public void getArtifact( Artifact artifact, List remoteRepositories, File destination )
@ -289,9 +275,6 @@ public class DefaultWagonManager
wagon.connect( repository, getProxy( repository.getProtocol() ) ); wagon.connect( repository, getProxy( repository.getProtocol() ) );
wagon.get( remotePath, temp ); wagon.get( remotePath, temp );
// TODO [BP]: put all disconnects in finally
wagon.disconnect();
} }
catch ( ConnectionException e ) catch ( ConnectionException e )
{ {
@ -307,19 +290,14 @@ public class DefaultWagonManager
} }
finally finally
{ {
try disconnectWagon( wagon );
{
releaseWagon( wagon ); releaseWagon( wagon );
} }
catch ( Exception e )
{
throw new TransferFailedException( "Release of wagon failed: ", e );
}
}
if ( !temp.exists() ) 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 // 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 ) private ProxyInfo getProxy( String protocol )
{ {
return (ProxyInfo) proxies.get( protocol ); return (ProxyInfo) proxies.get( protocol );

View File

@ -147,17 +147,15 @@ public class SnapshotArtifactMetadata
File destination = File.createTempFile( "maven-artifact", null ); File destination = File.createTempFile( "maven-artifact", null );
destination.deleteOnExit(); destination.deleteOnExit();
try
{
wagonManager.getArtifactMetadata( snapshotMetadata, remoteRepository, destination ); wagonManager.getArtifactMetadata( snapshotMetadata, remoteRepository, destination );
snapshotMetadata.readFromFile( destination ); snapshotMetadata.readFromFile( destination );
} }
catch ( ResourceDoesNotExistException e ) catch ( ResourceDoesNotExistException e )
{ {
// No problem...
// this just means that there is no snapshot version file, so we keep timestamp = null, build = 0 // this just means that there is no snapshot version file, so we keep timestamp = null, build = 0
} }
}
catch ( TransferFailedException e ) catch ( TransferFailedException e )
{ {
throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata", e ); throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata", e );

View File

@ -7,6 +7,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>maven-core</artifactId> <artifactId>maven-core</artifactId>
<name>Maven</name> <name>Maven</name>
<version>2.0-SNAPSHOT</version>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.maven.wagon</groupId> <groupId>org.apache.maven.wagon</groupId>

View File

@ -87,11 +87,6 @@ public class DefaultMaven
public MavenExecutionResponse execute( MavenExecutionRequest request ) public MavenExecutionResponse execute( MavenExecutionRequest request )
throws ReactorException throws ReactorException
{ {
if ( request.getGoals().isEmpty() )
{
throw new ReactorException( "You must specify at least one goal. Try 'install'." );
}
if ( request.getSettings().getActiveProfile().isOffline() ) if ( request.getSettings().getActiveProfile().isOffline() )
{ {
getLogger().info( "Maven is running in offline mode." ); getLogger().info( "Maven is running in offline mode." );
@ -103,8 +98,6 @@ public class DefaultMaven
// TODO: goals are outer loop // TODO: goals are outer loop
dispatcher.dispatchStart( event, request.getBaseDirectory() ); dispatcher.dispatchStart( event, request.getBaseDirectory() );
try
{
List projects; List projects;
try try
@ -131,6 +124,8 @@ public class DefaultMaven
throw new ReactorException( "Error processing projects for the reactor: ", e ); throw new ReactorException( "Error processing projects for the reactor: ", e );
} }
try
{
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); ) for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
{ {
MavenProject project = (MavenProject) iterator.next(); MavenProject project = (MavenProject) iterator.next();
@ -143,13 +138,13 @@ public class DefaultMaven
try try
{ {
MavenExecutionResponse response = processProject( request, project, dispatcher, request.getGoals() ); MavenExecutionResponse response = processProject( request, project, dispatcher );
if ( response.isExecutionFailure() ) if ( response.isExecutionFailure() )
{ {
return response; return response;
} }
} }
catch ( Exception e ) catch ( LifecycleExecutionException e )
{ {
throw new ReactorException( "Error executing project within the reactor", e ); throw new ReactorException( "Error executing project within the reactor", e );
} }
@ -188,7 +183,7 @@ public class DefaultMaven
if ( includes.indexOf( ".." ) >= 0 ) 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 ); List moduleFiles = FileUtils.getFiles( project.getFile().getParentFile(), includes, null );
@ -203,9 +198,11 @@ public class DefaultMaven
} }
private MavenExecutionResponse processProject( MavenExecutionRequest request, MavenProject project, private MavenExecutionResponse processProject( MavenExecutionRequest request, MavenProject project,
EventDispatcher dispatcher, List goals ) EventDispatcher dispatcher )
throws LifecycleExecutionException throws LifecycleExecutionException
{ {
List goals = request.getGoals();
MavenSession session = createSession( request, project ); MavenSession session = createSession( request, project );
try try
@ -252,6 +249,7 @@ public class DefaultMaven
} }
else else
{ {
// TODO: throw exceptions like this, so "failures" are just that
logError( response ); logError( response );
} }
} }
@ -423,13 +421,29 @@ public class DefaultMaven
secs = secs % 60; 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 else
{ {
return secs + " seconds"; msg += "< 1 second";
} }
return msg;
} }
} }

View File

@ -29,8 +29,11 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.wagon.util.IoUtils; 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.FileReader;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -111,10 +114,18 @@ public class MavenMetadataSource
Model model = this.reader.read( reader ); Model model = this.reader.read( reader );
dependencies = model.getDependencies(); 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 ); throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
} }
catch ( XmlPullParserException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to parse the metadata file", e );
}
finally finally
{ {
IoUtils.close( reader ); IoUtils.close( reader );

View File

@ -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.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
/** /**
* Attach a POM to an artifact. * Attach a POM to an artifact.
@ -80,7 +83,15 @@ public class MavenMetadata
MavenXpp3Writer modelWriter = new MavenXpp3Writer(); MavenXpp3Writer modelWriter = new MavenXpp3Writer();
modelWriter.write( writer, model ); 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 ); throw new ArtifactMetadataRetrievalException( "Error rewriting POM", e );
} }

View File

@ -1,7 +1,7 @@
package org.apache.maven.cli; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,7 +14,6 @@ package org.apache.maven.cli;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* ====================================================================
*/ */
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
@ -91,6 +90,16 @@ public class MavenCli
return 1; 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", "<unknown>" ) );
return 1;
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// 1) maven user configuration directory ( ~/.m2 ) // 1) maven user configuration directory ( ~/.m2 )
@ -194,6 +203,15 @@ public class MavenCli
return 1; 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; MavenExecutionResponse response = null;
try try
{ {
@ -463,6 +481,8 @@ public class MavenCli
public void displayHelp() public void displayHelp()
{ {
System.out.println();
HelpFormatter formatter = new HelpFormatter(); HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "maven [options] [goal [goal2 [goal3] ...]]", "\nOptions:", options, "\n" ); formatter.printHelp( "maven [options] [goal [goal2 [goal3] ...]]", "\nOptions:", options, "\n" );
} }

View File

@ -19,6 +19,7 @@ package org.apache.maven.lifecycle;
import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException; 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.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.MavenExecutionResponse; import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
@ -86,6 +87,38 @@ public class DefaultLifecycleExecutor
response.setStart( new Date() ); response.setStart( new Date() );
try
{
processGoals( session, tasks );
}
catch ( PluginExecutionException e )
{
response.setException( e );
}
catch ( PluginNotFoundException e )
{
response.setException( e );
}
catch ( ArtifactHandlerNotFoundException e )
{
response.setException( e );
}
catch ( ArtifactResolutionException e )
{
response.setException( e );
}
finally
{
response.setFinish( new Date() );
}
return response;
}
private void processGoals( MavenSession session, List tasks )
throws ArtifactHandlerNotFoundException, LifecycleExecutionException, PluginNotFoundException,
PluginExecutionException, ArtifactResolutionException
{
Map phaseMap = new HashMap(); Map phaseMap = new HashMap();
for ( Iterator i = phases.iterator(); i.hasNext(); ) for ( Iterator i = phases.iterator(); i.hasNext(); )
@ -96,8 +129,6 @@ public class DefaultLifecycleExecutor
phaseMap.put( p.getId(), new Phase( p ) ); phaseMap.put( p.getId(), new Phase( p ) );
} }
try
{
MavenProject project = session.getProject(); MavenProject project = session.getProject();
ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( project.getPackaging() ); ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( project.getPackaging() );
@ -128,6 +159,8 @@ public class DefaultLifecycleExecutor
processGoalChain( task, session, phaseMap ); processGoalChain( task, session, phaseMap );
try
{
if ( phaseMap.containsKey( task ) ) if ( phaseMap.containsKey( task ) )
{ {
executePhase( task, session, phaseMap ); executePhase( task, session, phaseMap );
@ -137,25 +170,11 @@ public class DefaultLifecycleExecutor
executeMojo( task, session ); executeMojo( task, session );
} }
} }
} catch ( PluginManagerException e )
catch ( PluginExecutionException e )
{ {
response.setException( e ); throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
} }
catch ( PluginNotFoundException e )
{
response.setException( e );
} }
catch ( ArtifactHandlerNotFoundException e )
{
response.setException( e );
}
finally
{
response.setFinish( new Date() );
}
return response;
} }
private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId ) private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId )
@ -389,7 +408,7 @@ public class DefaultLifecycleExecutor
} }
private void executePhase( String phase, MavenSession session, Map phaseMap ) private void executePhase( String phase, MavenSession session, Map phaseMap )
throws PluginExecutionException, PluginNotFoundException throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException
{ {
// only execute up to the given phase // only execute up to the given phase
int index = phases.indexOf( phaseMap.get( phase ) ); int index = phases.indexOf( phaseMap.get( phase ) );
@ -424,13 +443,23 @@ public class DefaultLifecycleExecutor
dispatcher.dispatchError( event, p.getId(), e ); dispatcher.dispatchError( event, p.getId(), e );
throw 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() ); dispatcher.dispatchEnd( event, p.getId() );
} }
} }
protected void executeMojo( String id, MavenSession session ) protected void executeMojo( String id, MavenSession session )
throws PluginExecutionException, PluginNotFoundException throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException
{ {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// We have something of the form <pluginId>:<mojoId>, so this might be // We have something of the form <pluginId>:<mojoId>, so this might be

View File

@ -262,21 +262,8 @@ public class DefaultPluginManager
} }
catch ( ComponentLookupException e ) catch ( ComponentLookupException e )
{ {
throw new PluginManagerException( "Internal configuration error while retrieving " + groupId + ":" + artifactId, 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 );
}
}
} }
} }
} }
@ -304,44 +291,35 @@ public class DefaultPluginManager
{ {
if ( artifactResolver != null ) if ( artifactResolver != null )
{ {
try releaseComponent( artifactResolver );
{
container.release( artifactResolver );
}
catch ( ComponentLifecycleException e )
{
getLogger().error( "Error releasing component - ignoring", e );
}
} }
if ( mavenProjectBuilder != null ) if ( mavenProjectBuilder != null )
{
releaseComponent( mavenProjectBuilder );
}
}
}
private void releaseComponent( Object component )
{ {
try try
{ {
container.release( mavenProjectBuilder ); container.release( component );
} }
catch ( ComponentLifecycleException e ) catch ( ComponentLifecycleException e )
{ {
getLogger().error( "Error releasing component - ignoring", e ); getLogger().error( "Error releasing component - ignoring", e );
} }
} }
}
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Plugin execution // Plugin execution
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public void executeMojo( MavenSession session, String goalName ) public void executeMojo( MavenSession session, String goalName )
throws PluginExecutionException, PluginNotFoundException throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException
{
try
{ {
verifyPluginForGoal( goalName, session ); verifyPluginForGoal( goalName, session );
}
catch ( Exception e )
{
throw new PluginExecutionException( "Unable to execute goal: " + goalName, e );
}
PluginExecutionRequest request = null; PluginExecutionRequest request = null;
@ -351,8 +329,6 @@ public class DefaultPluginManager
throw new PluginExecutionException( "Unable to find goal: " + goalName ); throw new PluginExecutionException( "Unable to find goal: " + goalName );
} }
try
{
if ( mojoDescriptor.getRequiresDependencyResolution() != null ) if ( mojoDescriptor.getRequiresDependencyResolution() != null )
{ {
@ -368,24 +344,22 @@ public class DefaultPluginManager
mojoDescriptor.getRequiresDependencyResolution() ); mojoDescriptor.getRequiresDependencyResolution() );
downloadDependencies( session, artifactResolver ); downloadDependencies( session, artifactResolver );
} }
catch ( ComponentLookupException e )
{
throw new PluginManagerException( "Internal configuration error in plugin manager", e );
}
finally finally
{ {
// TODO: watch out for the exceptions being thrown
if ( artifactResolver != null ) if ( artifactResolver != null )
{ {
container.release( artifactResolver ); releaseComponent( artifactResolver );
} }
if ( mavenProjectBuilder != null ) 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; Plugin plugin = null;
@ -421,9 +395,10 @@ public class DefaultPluginManager
configuration = new XmlPlexusConfiguration( dom ); configuration = new XmlPlexusConfiguration( dom );
} }
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator );
configuration = mergeConfiguration( configuration, mojoDescriptor.getConfiguration() ); configuration = mergeConfiguration( configuration, mojoDescriptor.getConfiguration() );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator );
try try
{ {
if ( newMojoTechnique ) if ( newMojoTechnique )
@ -486,15 +461,7 @@ public class DefaultPluginManager
} }
finally finally
{ {
try releaseComponent( plugin );
{
container.release( plugin );
}
catch ( Exception e )
{
// TODO: better error handling, needed!
e.printStackTrace();
}
} }
} }
@ -634,11 +601,11 @@ public class DefaultPluginManager
} }
catch ( NoSuchFieldException e ) 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 ) catch ( IllegalAccessException e )
{ {
throw new PluginConfigurationException( "Unable to set field '" + key + "' on '" + clazz + "'" ); throw new PluginConfigurationException( "Unable to set field '" + key + "' on '" + clazz + "'", e );
} }
} }
} }

View File

@ -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.execution.MavenSession;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
@ -30,7 +31,7 @@ public interface PluginManager
String ROLE = PluginManager.class.getName(); String ROLE = PluginManager.class.getName();
void executeMojo( MavenSession session, String goalName ) void executeMojo( MavenSession session, String goalName )
throws PluginExecutionException, PluginNotFoundException; throws PluginExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException;
MojoDescriptor getMojoDescriptor( String goalId ); MojoDescriptor getMojoDescriptor( String goalId );

View File

@ -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.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -162,7 +163,11 @@ public class DefaultMavenProjectBuilder
{ {
settings = mavenSettingsBuilder.buildSettings(); 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 ); throw new ProjectBuildingException( "Cannot read settings.", e );
} }
@ -193,7 +198,7 @@ public class DefaultMavenProjectBuilder
} }
catch ( ArtifactResolutionException e ) 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() ); model = readModel( artifact.getFile() );
} }
@ -267,28 +272,14 @@ public class DefaultMavenProjectBuilder
project = new MavenProject( model ); project = new MavenProject( model );
try
{
project.setPluginArtifactRepositories( buildPluginRepositories( model.getPluginRepositories() ) ); project.setPluginArtifactRepositories( buildPluginRepositories( model.getPluginRepositories() ) );
}
catch ( Exception e )
{
throw new ProjectBuildingException( "Error building plugin repository list.", e );
}
DistributionManagement dm = model.getDistributionManagement(); DistributionManagement dm = model.getDistributionManagement();
if ( dm != null ) if ( dm != null )
{
try
{ {
project.setDistributionManagementArtifactRepository( buildDistributionManagementRepository( project.setDistributionManagementArtifactRepository( buildDistributionManagementRepository(
dm.getRepository() ) ); dm.getRepository() ) );
} }
catch ( Exception e )
{
throw new ProjectBuildingException( "Error building distribution management repository.", e );
}
}
project.setParent( parentProject ); project.setParent( parentProject );
project.setRemoteArtifactRepositories( remoteRepositories ); project.setRemoteArtifactRepositories( remoteRepositories );
@ -472,13 +463,18 @@ public class DefaultMavenProjectBuilder
} }
catch ( FileNotFoundException e ) 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( throw new ProjectBuildingException(
"Error while reading model from file '" + file.getAbsolutePath() + "'.", e ); "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 finally
{ {
IOUtil.close( reader ); IOUtil.close( reader );
@ -488,17 +484,23 @@ public class DefaultMavenProjectBuilder
private Model readModel( URL url ) private Model readModel( URL url )
throws ProjectBuildingException throws ProjectBuildingException
{ {
InputStreamReader reader = null;
try try
{ {
return modelReader.read( new InputStreamReader( url.openStream() ) ); reader = new InputStreamReader( url.openStream() );
return modelReader.read( reader );
} }
catch ( IOException e ) 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 );
} }
} }

View File

@ -23,7 +23,9 @@ import org.apache.maven.util.introspection.ReflectionValueExtractor;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils; 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.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -52,7 +54,7 @@ public class RegexBasedModelInterpolator
{ {
writer.write( sWriter, model ); writer.write( sWriter, model );
} }
catch ( Exception e ) catch ( IOException e )
{ {
throw new ModelInterpolationException( "Cannot serialize project model for interpolation.", e ); throw new ModelInterpolationException( "Cannot serialize project model for interpolation.", e );
} }
@ -67,7 +69,12 @@ public class RegexBasedModelInterpolator
{ {
model = modelReader.read( sReader ); 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( throw new ModelInterpolationException(
"Cannot read project model from interpolating filter of serialized version.", e ); "Cannot read project model from interpolating filter of serialized version.", e );

View File

@ -22,7 +22,6 @@ import org.apache.maven.model.Resource;
import java.io.File; import java.io.File;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
public class DefaultPathTranslator public class DefaultPathTranslator
implements PathTranslator implements PathTranslator

View File

@ -67,9 +67,6 @@ public class PluginParameterExpressionEvaluatorTest
String actual = new File( value.toString() ).getCanonicalPath(); String actual = new File( value.toString() ).getCanonicalPath();
System.out.println( "Expected value: " + expected );
System.out.println( "Resolved value: " + actual );
assertEquals( expected, actual ); assertEquals( expected, actual );
} }

View File

@ -30,8 +30,11 @@ import org.apache.maven.artifact.resolver.DefaultArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; 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.File;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -52,18 +55,28 @@ public class ProjectClasspathArtifactResolver
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException throws ArtifactMetadataRetrievalException
{ {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = null; Model model = null;
InputStreamReader r = null;
try try
{ {
String scope = artifact.getArtifactId().substring( "scope-".length() ); String scope = artifact.getArtifactId().substring( "scope-".length() );
String name = "/projects/scope/transitive-" + scope + "-dep.xml"; 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 ); throw new ArtifactMetadataRetrievalException( e );
} }
catch ( XmlPullParserException e )
{
throw new ArtifactMetadataRetrievalException( e );
}
finally
{
IOUtil.close( r );
}
return artifactFactory.createArtifacts( model.getDependencies(), localRepository, artifact.getScope() ); return artifactFactory.createArtifacts( model.getDependencies(), localRepository, artifact.getScope() );
} }
} }

View File

@ -16,10 +16,9 @@ package org.apache.maven.project.inheritance;
* limitations under the License. * limitations under the License.
*/ */
import java.io.File;
import org.apache.maven.MavenTestCase; import org.apache.maven.MavenTestCase;
import org.apache.maven.project.MavenProjectBuilder;
import java.io.File;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>

View File

@ -19,7 +19,6 @@ package org.apache.maven.util.introspection;
import org.apache.maven.MavenTestCase; import org.apache.maven.MavenTestCase;
import org.apache.maven.model.Build; import org.apache.maven.model.Build;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;

View File

@ -20,13 +20,13 @@ public class PluginUtilsTest
public void testShouldTrimArtifactIdToFindPluginId() public void testShouldTrimArtifactIdToFindPluginId()
{ {
Model model = new Model(); Model model = new Model();
model.setArtifactId( "test-artifactId-plugin" ); model.setArtifactId( "maven-artifactId-plugin" );
MavenProject project = new MavenProject( model ); MavenProject project = new MavenProject( model );
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() ); String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() );
System.out.println( pluginId ); assertEquals( "artifactId", pluginId );
} }
public void testShouldWriteDependencies() public void testShouldWriteDependencies()

View File

@ -110,15 +110,14 @@ public class AssemblyMojo
InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + descriptorId + ".xml" ); InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + descriptorId + ".xml" );
if ( resourceAsStream == null ) if ( resourceAsStream == null )
{ {
// TODO: better exception throw new PluginExecutionException( "Descriptor with ID '" + descriptorId + "' not found" );
throw new Exception( "Descriptor with ID '" + descriptorId + "' not found" );
} }
r = new InputStreamReader( resourceAsStream ); r = new InputStreamReader( resourceAsStream );
} }
else else
{ {
// TODO: better exception // TODO: better exception
throw new Exception( "You must specify descriptor or descriptorId" ); throw new PluginExecutionException( "You must specify descriptor or descriptorId" );
} }
try try

View File

@ -53,15 +53,8 @@ public class CleanPlugin
if ( dir.exists() && dir.isDirectory() ) if ( dir.exists() && dir.isDirectory() )
{ {
getLog().info( "Deleting directory " + dir.getAbsolutePath() ); getLog().info( "Deleting directory " + dir.getAbsolutePath() );
try
{
removeDir( dir ); removeDir( dir );
} }
catch ( Exception e )
{
throw new PluginExecutionException( "Unable to delete directory", e );
}
}
} }
} }

View File

@ -19,7 +19,7 @@
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId> <artifactId>maven-artifact</artifactId>
<version>2.0-alpha-1</version> <version>2.0-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</model> </model>

View File

@ -32,7 +32,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.Map.Entry;
/** /**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
@ -67,7 +66,7 @@ public class ResourcesMojo
{ {
for ( Iterator i = getJarResources( resources ).entrySet().iterator(); i.hasNext(); ) 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 source = (String) entry.getKey();
String destination = (String) entry.getValue(); String destination = (String) entry.getValue();

View File

@ -16,9 +16,7 @@ package org.apache.maven.script.marmalade;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.maven.monitor.logging.Log;
import org.apache.maven.plugin.AbstractPlugin; import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.FailureResponse;
import org.apache.maven.plugin.PluginExecutionRequest; import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse; import org.apache.maven.plugin.PluginExecutionResponse;
import org.codehaus.marmalade.model.MarmaladeScript; import org.codehaus.marmalade.model.MarmaladeScript;