cleanup error handling on assembly plugin

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@295007 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-05 07:02:55 +00:00
parent 731940edd2
commit 1333ce0b66
3 changed files with 19 additions and 37 deletions

View File

@ -18,6 +18,7 @@ package org.apache.maven.plugin.assembly;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver; import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager; import org.codehaus.plexus.archiver.manager.ArchiverManager;
@ -36,7 +37,7 @@ import java.util.Set;
public abstract class AbstractUnpackingMojo public abstract class AbstractUnpackingMojo
extends AbstractMojo extends AbstractMojo
{ {
static protected final String[] EMPTY_STRING_ARRAY = {}; protected static final String[] EMPTY_STRING_ARRAY = {};
/** /**
* The output directory of the assembled distribution file. * The output directory of the assembled distribution file.
@ -89,7 +90,7 @@ public abstract class AbstractUnpackingMojo
*/ */
protected void unpack( File file, File location ) protected void unpack( File file, File location )
throws MojoExecutionException throws MojoExecutionException, MojoFailureException
{ {
String archiveExt = FileUtils.getExtension( file.getAbsolutePath() ).toLowerCase(); String archiveExt = FileUtils.getExtension( file.getAbsolutePath() ).toLowerCase();
@ -103,7 +104,7 @@ public abstract class AbstractUnpackingMojo
} }
catch ( NoSuchArchiverException e ) catch ( NoSuchArchiverException e )
{ {
throw new MojoExecutionException( "Unknown archive file: " + file ); throw new MojoFailureException( "Unable to obtain unarchiver for extension '" + archiveExt + "'" );
} }
try try
@ -114,13 +115,13 @@ public abstract class AbstractUnpackingMojo
unArchiver.extract(); unArchiver.extract();
} }
catch ( IOException ioe ) catch ( IOException e )
{ {
throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location ); throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location, e );
} }
catch ( ArchiverException e ) catch ( ArchiverException e )
{ {
throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location ); throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location, e );
} }
} }

View File

@ -150,7 +150,7 @@ public class AssemblyMojo
} }
catch ( NoSuchArchiverException e ) catch ( NoSuchArchiverException e )
{ {
throw new MojoExecutionException( e.getMessage() ); throw new MojoFailureException( "Unable to obtain archiver for extension '" + format + "'" );
} }
catch ( ArchiverException e ) catch ( ArchiverException e )
{ {
@ -166,7 +166,7 @@ public class AssemblyMojo
} }
protected File createArchive( Archiver archiver, Assembly assembly, String filename ) protected File createArchive( Archiver archiver, Assembly assembly, String filename )
throws ArchiverException, IOException, MojoExecutionException throws ArchiverException, IOException, MojoExecutionException, MojoFailureException
{ {
File destFile; File destFile;
processDependencySets( archiver, assembly.getDependencySets(), assembly.isIncludeBaseDirectory() ); processDependencySets( archiver, assembly.getDependencySets(), assembly.isIncludeBaseDirectory() );
@ -200,7 +200,7 @@ public class AssemblyMojo
InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + descriptorId + ".xml" ); InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + descriptorId + ".xml" );
if ( resourceAsStream == null ) if ( resourceAsStream == null )
{ {
throw new MojoExecutionException( "Descriptor with ID '" + descriptorId + "' not found" ); throw new MojoFailureException( "Descriptor with ID '" + descriptorId + "' not found" );
} }
r = new InputStreamReader( resourceAsStream ); r = new InputStreamReader( resourceAsStream );
} }
@ -238,7 +238,7 @@ public class AssemblyMojo
* @param includeBaseDirectory * @param includeBaseDirectory
*/ */
protected void processDependencySets( Archiver archiver, List dependencySets, boolean includeBaseDirectory ) protected void processDependencySets( Archiver archiver, List dependencySets, boolean includeBaseDirectory )
throws ArchiverException, IOException, MojoExecutionException throws ArchiverException, IOException, MojoExecutionException, MojoFailureException
{ {
for ( Iterator i = dependencySets.iterator(); i.hasNext(); ) for ( Iterator i = dependencySets.iterator(); i.hasNext(); )
{ {

View File

@ -1,11 +1,5 @@
package org.apache.maven.plugin.assembly; package org.apache.maven.plugin.assembly;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File;
import java.util.Iterator;
/* /*
* Copyright 2001-2005 The Apache Software Foundation. * Copyright 2001-2005 The Apache Software Foundation.
* *
@ -22,6 +16,12 @@ import java.util.Iterator;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import java.io.File;
import java.util.Iterator;
/** /**
* Unpack project dependencies. Currently supports dependencies of type jar and zip. * Unpack project dependencies. Currently supports dependencies of type jar and zip.
@ -39,28 +39,8 @@ public class UnpackMojo
* @throws MojoExecutionException * @throws MojoExecutionException
*/ */
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException, MojoFailureException
{ {
try
{
doExecute();
}
catch ( Exception e )
{
// TODO: don't catch exception
throw new MojoExecutionException( "Error unpacking", e );
}
}
/**
* Unpacks the project dependencies.
*
* @throws Exception
*/
private void doExecute()
throws Exception
{
for ( Iterator j = dependencies.iterator(); j.hasNext(); ) for ( Iterator j = dependencies.iterator(); j.hasNext(); )
{ {
Artifact artifact = (Artifact) j.next(); Artifact artifact = (Artifact) j.next();
@ -86,4 +66,5 @@ public class UnpackMojo
} }
} }
} }
} }