You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/12/20 09:33:59 UTC

[maven-ear-plugin] 42/45: clean up ear plugin exception handling

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to annotated tag maven-ear-plugin-2.0
in repository https://gitbox.apache.org/repos/asf/maven-ear-plugin.git

commit 0f8aa698038cd06ff210883f43de3e5da1b4e72e
Author: Brett Leslie Porter <br...@apache.org>
AuthorDate: Wed Oct 12 16:27:15 2005 +0000

    clean up ear plugin exception handling
    
    git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-ear-plugin@314956 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/maven/plugin/ear/AbstractEarModule.java | 17 ++++++-----
 .../apache/maven/plugin/ear/AbstractEarMojo.java   |  3 +-
 .../org/apache/maven/plugin/ear/EarModule.java     |  5 ++--
 .../java/org/apache/maven/plugin/ear/EarMojo.java  |  5 ++--
 .../plugin/ear/GenerateApplicationXmlMojo.java     | 34 ++++++++++------------
 .../org/apache/maven/plugin/ear/WebModule.java     |  3 +-
 6 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java b/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
index a89b740..f07b3e1 100644
--- a/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
+++ b/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/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java b/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
index eaea6e2..8bb7c67 100644
--- a/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
+++ b/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/src/main/java/org/apache/maven/plugin/ear/EarModule.java b/src/main/java/org/apache/maven/plugin/ear/EarModule.java
index e0f2661..0eb642f 100644
--- a/src/main/java/org/apache/maven/plugin/ear/EarModule.java
+++ b/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 <tt>XML</tt> representation of this module.
      *
-     * @param writer  the writer to use
+     * @param writer the writer to use
      * @param version the version of the <tt>application.xml</tt> 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/src/main/java/org/apache/maven/plugin/ear/EarMojo.java b/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
index e7a35e8..e174288 100644
--- a/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
+++ b/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/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java b/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
index 4a3501d..37c4ed9 100644
--- a/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
+++ b/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/src/main/java/org/apache/maven/plugin/ear/WebModule.java b/src/main/java/org/apache/maven/plugin/ear/WebModule.java
index 0464e74..5e06235 100644
--- a/src/main/java/org/apache/maven/plugin/ear/WebModule.java
+++ b/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 );

-- 
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.