From 70ff436ddfaa556cc51609906bd16bc4b88eaee7 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Wed, 12 Oct 2005 16:27:15 +0000 Subject: [PATCH] clean up ear plugin exception handling git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@314956 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/ear/AbstractEarModule.java | 17 +++++----- .../maven/plugin/ear/AbstractEarMojo.java | 3 +- .../apache/maven/plugin/ear/EarModule.java | 5 +-- .../org/apache/maven/plugin/ear/EarMojo.java | 5 +-- .../ear/GenerateApplicationXmlMojo.java | 34 ++++++++----------- .../apache/maven/plugin/ear/WebModule.java | 3 +- 6 files changed, 34 insertions(+), 33 deletions(-) diff --git a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java index a89b74029f..f07b3e1883 100644 --- a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java +++ b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java @@ -17,6 +17,7 @@ package org.apache.maven.plugin.ear; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoFailureException; import java.util.Iterator; import java.util.Set; @@ -71,17 +72,13 @@ public abstract class AbstractEarModule } public void resolveArtifact( Set artifacts ) - throws EarPluginException + throws MojoFailureException { - if ( artifact != null ) - { - return; - } - else + if ( artifact == null ) { if ( groupId == null || artifactId == null ) { - throw new EarPluginException( + throw new MojoFailureException( "Could not resolve artifact[" + groupId + ":" + artifactId + ":" + getType() + "]" ); } @@ -98,9 +95,13 @@ public abstract class AbstractEarModule } // Artifact has not been found - throw new EarPluginException( "Artifact[" + groupId + ":" + artifactId + ":" + getType() + "] " + + throw new MojoFailureException( "Artifact[" + groupId + ":" + artifactId + ":" + getType() + "] " + "is not a dependency of the project." ); } + else + { + return; + } } /** diff --git a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java index eaea6e26ec..8bb7c67e6a 100644 --- a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java +++ b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java @@ -19,6 +19,7 @@ package org.apache.maven.plugin.ear; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import java.io.File; @@ -68,7 +69,7 @@ public abstract class AbstractEarMojo private List allModules; public void execute() - throws MojoExecutionException + throws MojoExecutionException, MojoFailureException { getLog().debug( "Resolving ear modules ..." ); diff --git a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java index e0f26614a7..0eb642fb1b 100644 --- a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java +++ b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java @@ -17,6 +17,7 @@ package org.apache.maven.plugin.ear; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.util.xml.XMLWriter; import java.util.Set; @@ -58,7 +59,7 @@ public interface EarModule /** * Appends the XML representation of this module. * - * @param writer the writer to use + * @param writer the writer to use * @param version the version of the application.xml file */ public void appendModule( XMLWriter writer, String version ); @@ -70,6 +71,6 @@ public interface EarModule * @throws EarPluginException if the artifact could not be resolved */ public void resolveArtifact( Set artifacts ) - throws EarPluginException; + throws EarPluginException, MojoFailureException; } diff --git a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java index e7a35e8e7f..e1742889dd 100644 --- a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java +++ b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java @@ -19,6 +19,7 @@ package org.apache.maven.plugin.ear; import org.apache.maven.archiver.MavenArchiveConfiguration; import org.apache.maven.archiver.MavenArchiver; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; @@ -103,7 +104,7 @@ public class EarMojo public void execute() - throws MojoExecutionException + throws MojoExecutionException, MojoFailureException { // Initializes ear modules super.execute(); @@ -207,7 +208,7 @@ public class EarMojo private void includeCustomManifestFile() { File customManifestFile = manifestFile; - + if ( !customManifestFile.exists() ) { getLog().info( "Could not find manifest file: " + manifestFile + " - Generating one" ); diff --git a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java index 4a3501d5d1..37c4ed9cb5 100644 --- a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java +++ b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java @@ -17,6 +17,7 @@ package org.apache.maven.plugin.ear; */ import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.util.FileUtils; import java.io.File; @@ -89,7 +90,7 @@ public class GenerateApplicationXmlMojo private String generatedDescriptorLocation; public void execute() - throws MojoExecutionException + throws MojoExecutionException, MojoFailureException { // Initializes ear modules super.execute(); @@ -115,47 +116,42 @@ public class GenerateApplicationXmlMojo } // Generate deployment descriptor and copy it to the build directory + getLog().info( "Generating application.xml" ); try { - getLog().info( "Generating application.xml" ); generateDeploymentDescriptor(); + } + catch ( EarPluginException e ) + { + throw new MojoExecutionException( "Failed to generate application.xml", e ); + } + + try + { FileUtils.copyFileToDirectory( new File( generatedDescriptorLocation, "application.xml" ), new File( getWorkDirectory(), "META-INF" ) ); } catch ( IOException e ) { - throw new MojoExecutionException( "Failed to generate application.xml", e ); + throw new MojoExecutionException( "Unable to copy application.xml to final destination", e ); } } /** * Generates the deployment descriptor if necessary. - * - * @throws IOException */ protected void generateDeploymentDescriptor() - throws IOException + throws EarPluginException { File outputDir = new File( generatedDescriptorLocation ); if ( !outputDir.exists() ) { - outputDir.mkdir(); + outputDir.mkdirs(); } File descriptor = new File( outputDir, "application.xml" ); - if ( !descriptor.exists() ) - { - descriptor.createNewFile(); - } ApplicationXmlWriter writer = new ApplicationXmlWriter( version, encoding ); - try - { - writer.write( descriptor, getModules(), displayName, description ); - } - catch ( EarPluginException e ) - { - throw new IOException( "Unable to generate application.xml[" + e.getMessage() + "]" ); - } + writer.write( descriptor, getModules(), displayName, description ); } } diff --git a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java index 0464e747ad..5e062359ed 100644 --- a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java +++ b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java @@ -17,6 +17,7 @@ package org.apache.maven.plugin.ear; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.util.xml.XMLWriter; import java.util.Set; @@ -63,7 +64,7 @@ public class WebModule } public void resolveArtifact( Set artifacts ) - throws EarPluginException + throws MojoFailureException { // Let's resolve the artifact super.resolveArtifact( artifacts );