mirror of https://github.com/apache/maven.git
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:
parent
4fe1c64276
commit
a75e7d2577
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-core</artifactId>
|
||||
<name>Maven</name>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.wagon</groupId>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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", "<unknown>" ) );
|
||||
|
||||
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" );
|
||||
}
|
||||
|
|
|
@ -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 <pluginId>:<mojoId>, so this might be
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-artifact</artifactId>
|
||||
<version>2.0-alpha-1</version>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
||||
|
|
|
@ -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 <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(); )
|
||||
{
|
||||
Map.Entry entry = (Entry) i.next();
|
||||
Map.Entry entry = (Map.Entry) i.next();
|
||||
String source = (String) entry.getKey();
|
||||
String destination = (String) entry.getValue();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue