You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2014/12/13 16:50:13 UTC

svn commit: r1645249 - /maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java

Author: khmarbaise
Date: Sat Dec 13 15:50:13 2014
New Revision: 1645249

URL: http://svn.apache.org/r1645249
Log:
Improved code to reduce the checkstyle reported errors.

Modified:
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java?rev=1645249&r1=1645248&r2=1645249&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java Sat Dec 13 15:50:13 2014
@@ -323,28 +323,95 @@ public class EarMojo
         final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion( version );
 
         // Initializes unpack types
-        List<String> unpackTypesList = new ArrayList<String>();
-        if ( unpackTypes != null )
+        List<String> unpackTypesList = createUnpackList();
+
+        // Copy modules
+        copyModules( javaEEVersion, unpackTypesList );
+
+        // Copy source files
+        try
         {
-            unpackTypesList = Arrays.asList( unpackTypes.split( "," ) );
-            for ( String type : unpackTypesList )
+            File earSourceDir = earSourceDirectory;
+            if ( earSourceDir.exists() )
             {
-                if ( !EarModuleFactory.STANDARD_ARTIFACT_TYPE.contains( type ) )
+                getLog().info( "Copy ear sources to " + getWorkDirectory().getAbsolutePath() );
+                String[] fileNames = getEarFiles( earSourceDir );
+                for ( String fileName : fileNames )
                 {
-                    throw new MojoExecutionException( "Invalid type [" + type + "] supported types are "
-                        + EarModuleFactory.STANDARD_ARTIFACT_TYPE );
+                    copyFile( new File( earSourceDir, fileName ), new File( getWorkDirectory(), fileName ) );
                 }
             }
-            getLog().debug( "Initialized unpack types " + unpackTypesList );
+
+            if ( applicationXml != null && !"".equals( applicationXml ) )
+            {
+                // rename to application.xml
+                getLog().info( "Including custom application.xml[" + applicationXml + "]" );
+                File metaInfDir = new File( getWorkDirectory(), META_INF );
+                copyFile( new File( applicationXml ), new File( metaInfDir, "/application.xml" ) );
+            }
+
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error copying EAR sources", e );
+        }
+        catch ( MavenFilteringException e )
+        {
+            throw new MojoExecutionException( "Error filtering EAR sources", e );
         }
 
-        // Copy modules
+        // Check if deployment descriptor is there
+        File ddFile = new File( getWorkDirectory(), APPLICATION_XML_URI );
+        if ( !ddFile.exists() && ( javaEEVersion.lt( JavaEEVersion.FIVE ) ) )
+        {
+            // CHECKSTYLE_OFF: LineLength
+            throw new MojoExecutionException( "Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist." );
+            // CHECKSTYLE_ON: LineLength
+        }
+
+        try
+        {
+            File earFile = getEarFile( outputDirectory, finalName, classifier );
+            final MavenArchiver archiver = new EarMavenArchiver( getModules() );
+            final JarArchiver jarArchiver = getJarArchiver();
+            getLog().debug( "Jar archiver implementation [" + jarArchiver.getClass().getName() + "]" );
+            archiver.setArchiver( jarArchiver );
+            archiver.setOutputFile( earFile );
+
+            // Include custom manifest if necessary
+            includeCustomManifestFile();
+
+            getLog().debug( "Excluding " + Arrays.asList( getPackagingExcludes() ) + " from the generated EAR." );
+            getLog().debug( "Including " + Arrays.asList( getPackagingIncludes() ) + " in the generated EAR." );
+
+            archiver.getArchiver().addDirectory( getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes() );
+            archiver.createArchive( session, getProject(), archive );
+
+            if ( classifier != null )
+            {
+                projectHelper.attachArtifact( getProject(), "ear", classifier, earFile );
+            }
+            else
+            {
+                getProject().getArtifact().setFile( earFile );
+            }
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Error assembling EAR", e );
+        }
+    }
+
+    private void copyModules( final JavaEEVersion javaEEVersion, List<String> unpackTypesList )
+        throws MojoExecutionException, MojoFailureException
+    {
         try
         {
             // TODO: With the next major release the modules
             // should be identified by a unique id instead of the
             // the artifactId's only which means this
             // check can be removed.
+            // http://jira.codehaus.org/browse/MEAR-209
             checkModuleUniqueness();
 
             for ( EarModule module : getModules() )
@@ -421,79 +488,26 @@ public class EarMojo
         {
             throw new MojoExecutionException( "No Archiver found for EAR modules", e );
         }
+    }
 
-        // Copy source files
-        try
+    private List<String> createUnpackList()
+        throws MojoExecutionException
+    {
+        List<String> unpackTypesList = new ArrayList<String>();
+        if ( unpackTypes != null )
         {
-            File earSourceDir = earSourceDirectory;
-            if ( earSourceDir.exists() )
+            unpackTypesList = Arrays.asList( unpackTypes.split( "," ) );
+            for ( String type : unpackTypesList )
             {
-                getLog().info( "Copy ear sources to " + getWorkDirectory().getAbsolutePath() );
-                String[] fileNames = getEarFiles( earSourceDir );
-                for ( String fileName : fileNames )
+                if ( !EarModuleFactory.STANDARD_ARTIFACT_TYPE.contains( type ) )
                 {
-                    copyFile( new File( earSourceDir, fileName ), new File( getWorkDirectory(), fileName ) );
+                    throw new MojoExecutionException( "Invalid type [" + type + "] supported types are "
+                        + EarModuleFactory.STANDARD_ARTIFACT_TYPE );
                 }
             }
-
-            if ( applicationXml != null && !"".equals( applicationXml ) )
-            {
-                // rename to application.xml
-                getLog().info( "Including custom application.xml[" + applicationXml + "]" );
-                File metaInfDir = new File( getWorkDirectory(), META_INF );
-                copyFile( new File( applicationXml ), new File( metaInfDir, "/application.xml" ) );
-            }
-
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( "Error copying EAR sources", e );
-        }
-        catch ( MavenFilteringException e )
-        {
-            throw new MojoExecutionException( "Error filtering EAR sources", e );
-        }
-
-        // Check if deployment descriptor is there
-        File ddFile = new File( getWorkDirectory(), APPLICATION_XML_URI );
-        if ( !ddFile.exists() && ( javaEEVersion.lt( JavaEEVersion.FIVE ) ) )
-        {
-            // CHECKSTYLE_OFF: LineLength
-            throw new MojoExecutionException( "Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist." );
-            // CHECKSTYLE_ON: LineLength
-        }
-
-        try
-        {
-            File earFile = getEarFile( outputDirectory, finalName, classifier );
-            final MavenArchiver archiver = new EarMavenArchiver( getModules() );
-            final JarArchiver jarArchiver = getJarArchiver();
-            getLog().debug( "Jar archiver implementation [" + jarArchiver.getClass().getName() + "]" );
-            archiver.setArchiver( jarArchiver );
-            archiver.setOutputFile( earFile );
-
-            // Include custom manifest if necessary
-            includeCustomManifestFile();
-
-            getLog().debug( "Excluding " + Arrays.asList( getPackagingExcludes() ) + " from the generated EAR." );
-            getLog().debug( "Including " + Arrays.asList( getPackagingIncludes() ) + " in the generated EAR." );
-
-            archiver.getArchiver().addDirectory( getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes() );
-            archiver.createArchive( session, getProject(), archive );
-
-            if ( classifier != null )
-            {
-                projectHelper.attachArtifact( getProject(), "ear", classifier, earFile );
-            }
-            else
-            {
-                getProject().getArtifact().setFile( earFile );
-            }
-        }
-        catch ( Exception e )
-        {
-            throw new MojoExecutionException( "Error assembling EAR", e );
+            getLog().debug( "Initialized unpack types " + unpackTypesList );
         }
+        return unpackTypesList;
     }
 
     public String getApplicationXml()