From 1333ce0b66c488537cc6fa5b9bdd38002278abb5 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Wed, 5 Oct 2005 07:02:55 +0000 Subject: [PATCH] cleanup error handling on assembly plugin git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@295007 13f79535-47bb-0310-9956-ffa450edef68 --- .../assembly/AbstractUnpackingMojo.java | 13 +++---- .../maven/plugin/assembly/AssemblyMojo.java | 8 ++--- .../maven/plugin/assembly/UnpackMojo.java | 35 +++++-------------- 3 files changed, 19 insertions(+), 37 deletions(-) diff --git a/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java b/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java index 4c38964d4d..1c4d8197e2 100644 --- a/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java +++ b/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java @@ -18,6 +18,7 @@ package org.apache.maven.plugin.assembly; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.UnArchiver; import org.codehaus.plexus.archiver.manager.ArchiverManager; @@ -36,7 +37,7 @@ import java.util.Set; public abstract class AbstractUnpackingMojo extends AbstractMojo { - static protected final String[] EMPTY_STRING_ARRAY = {}; + protected static final String[] EMPTY_STRING_ARRAY = {}; /** * The output directory of the assembled distribution file. @@ -89,7 +90,7 @@ public abstract class AbstractUnpackingMojo */ protected void unpack( File file, File location ) - throws MojoExecutionException + throws MojoExecutionException, MojoFailureException { String archiveExt = FileUtils.getExtension( file.getAbsolutePath() ).toLowerCase(); @@ -103,7 +104,7 @@ public abstract class AbstractUnpackingMojo } catch ( NoSuchArchiverException e ) { - throw new MojoExecutionException( "Unknown archive file: " + file ); + throw new MojoFailureException( "Unable to obtain unarchiver for extension '" + archiveExt + "'" ); } try @@ -114,13 +115,13 @@ public abstract class AbstractUnpackingMojo 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 ) { - throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location ); + throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location, e ); } } 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 f1405c52e7..d5a2a3a16f 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 @@ -150,7 +150,7 @@ public class AssemblyMojo } catch ( NoSuchArchiverException e ) { - throw new MojoExecutionException( e.getMessage() ); + throw new MojoFailureException( "Unable to obtain archiver for extension '" + format + "'" ); } catch ( ArchiverException e ) { @@ -166,7 +166,7 @@ public class AssemblyMojo } protected File createArchive( Archiver archiver, Assembly assembly, String filename ) - throws ArchiverException, IOException, MojoExecutionException + throws ArchiverException, IOException, MojoExecutionException, MojoFailureException { File destFile; processDependencySets( archiver, assembly.getDependencySets(), assembly.isIncludeBaseDirectory() ); @@ -200,7 +200,7 @@ public class AssemblyMojo InputStream resourceAsStream = getClass().getResourceAsStream( "/assemblies/" + descriptorId + ".xml" ); 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 ); } @@ -238,7 +238,7 @@ public class AssemblyMojo * @param 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(); ) { diff --git a/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java b/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java index c3724804f5..0cad49a64d 100644 --- a/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java +++ b/maven-plugins/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java @@ -1,11 +1,5 @@ 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. * @@ -22,6 +16,12 @@ import java.util.Iterator; * 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. @@ -39,28 +39,8 @@ public class UnpackMojo * @throws MojoExecutionException */ 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(); ) { Artifact artifact = (Artifact) j.next(); @@ -86,4 +66,5 @@ public class UnpackMojo } } } + } \ No newline at end of file