Author: khmarbaise Date: Sat Dec 27 15:50:36 2014 New Revision: 1648057 URL: http://svn.apache.org/r1648057 Log: Refactored code to get shorter methods.
Modified: maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java Modified: maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java?rev=1648057&r1=1648056&r2=1648057&view=diff ============================================================================== --- maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java (original) +++ maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java Sat Dec 27 15:50:36 2014 @@ -277,16 +277,7 @@ public class EjbMojo File deploymentDescriptor = new File( outputDirectory, ejbJar ); /* test EJB version compliance */ - if ( !ejbVersion.matches( "\\A[2-3]\\.[0-9]\\z" ) ) - { - throw new MojoExecutionException( "ejbVersion is not valid: " + ejbVersion - + ". Must be 2.x or 3.x (where x is a digit)" ); - } - - if ( ejbVersion.matches( "\\A2\\.[0-9]\\z" ) && !deploymentDescriptor.exists() ) - { - throw new MojoExecutionException( "Error assembling EJB: " + ejbJar + " is required for ejbVersion 2.x" ); - } + ejbVersionCompliance( deploymentDescriptor ); try { @@ -306,20 +297,7 @@ public class EjbMojo // EJB-34 Filter ejb-jar.xml if ( filterDeploymentDescriptor ) { - getLog().debug( "Filtering deployment descriptor." ); - MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(); - mavenResourcesExecution.setEscapeString( escapeString ); - List<FilterWrapper> filterWrappers = - mavenFileFilter.getDefaultFilterWrappers( project, filters, escapeBackslashesInFilePath, - this.session, mavenResourcesExecution ); - - // Create a temporary file that we can copy-and-filter - File unfilteredDeploymentDescriptor = new File( outputDirectory, ejbJar + ".unfiltered" ); - FileUtils.copyFile( deploymentDescriptor, unfilteredDeploymentDescriptor ); - mavenFileFilter.copyFile( unfilteredDeploymentDescriptor, deploymentDescriptor, true, - filterWrappers, getEncoding( unfilteredDeploymentDescriptor ) ); - // Remove the temporary file - FileUtils.forceDelete( unfilteredDeploymentDescriptor ); + filterDeploymentDescriptor( deploymentDescriptor ); } archiver.getArchiver().addFile( deploymentDescriptor, ejbJar ); } @@ -361,74 +339,114 @@ public class EjbMojo if ( generateClient ) { - String clientJarName = jarName; - if ( classifier != null ) - { - clientJarName += "-" + classifier; - } + generateEjbClient(); + } + } - getLog().info( "Building EJB client " + clientJarName + "-client" ); + private void generateEjbClient() + throws MojoExecutionException + { + String clientJarName = jarName; + if ( classifier != null ) + { + clientJarName += "-" + classifier; + } - String[] excludes = DEFAULT_CLIENT_EXCLUDES; - String[] includes = DEFAULT_INCLUDES; + getLog().info( "Building EJB client " + clientJarName + "-client" ); - if ( clientIncludes != null && !clientIncludes.isEmpty() ) - { - includes = (String[]) clientIncludes.toArray( new String[clientIncludes.size()] ); - } + String[] excludes = DEFAULT_CLIENT_EXCLUDES; + String[] includes = DEFAULT_INCLUDES; - if ( clientExcludes != null && !clientExcludes.isEmpty() ) - { - excludes = (String[]) clientExcludes.toArray( new String[clientExcludes.size()] ); - } + if ( clientIncludes != null && !clientIncludes.isEmpty() ) + { + includes = (String[]) clientIncludes.toArray( new String[clientIncludes.size()] ); + } - File clientJarFile = new File( basedir, clientJarName + "-client.jar" ); + if ( clientExcludes != null && !clientExcludes.isEmpty() ) + { + excludes = (String[]) clientExcludes.toArray( new String[clientExcludes.size()] ); + } - MavenArchiver clientArchiver = new MavenArchiver(); + File clientJarFile = new File( basedir, clientJarName + "-client.jar" ); - clientArchiver.setArchiver( clientJarArchiver ); + MavenArchiver clientArchiver = new MavenArchiver(); - clientArchiver.setOutputFile( clientJarFile ); + clientArchiver.setArchiver( clientJarArchiver ); - try - { - clientArchiver.getArchiver().addDirectory( outputDirectory, includes, excludes ); + clientArchiver.setOutputFile( clientJarFile ); - // create archive - clientArchiver.createArchive( session, project, archive ); + try + { + clientArchiver.getArchiver().addDirectory( outputDirectory, includes, excludes ); - } - catch ( ArchiverException e ) - { - throw new MojoExecutionException( "There was a problem creating the EJB client archive: " - + e.getMessage(), e ); - } - catch ( ManifestException e ) - { - throw new MojoExecutionException( "There was a problem creating the EJB client archive: " - + e.getMessage(), e ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "There was a problem creating the EJB client archive: " - + e.getMessage(), e ); - } - catch ( DependencyResolutionRequiredException e ) - { - throw new MojoExecutionException( "There was a problem creating the EJB client archive: " - + e.getMessage(), e ); - } + // create archive + clientArchiver.createArchive( session, project, archive ); - // TODO: shouldn't need classifer - if ( classifier != null ) - { - projectHelper.attachArtifact( project, "ejb-client", classifier + "-client", clientJarFile ); - } - else - { - projectHelper.attachArtifact( project, "ejb-client", "client", clientJarFile ); - } } + catch ( ArchiverException e ) + { + throw new MojoExecutionException( "There was a problem creating the EJB client archive: " + + e.getMessage(), e ); + } + catch ( ManifestException e ) + { + throw new MojoExecutionException( "There was a problem creating the EJB client archive: " + + e.getMessage(), e ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "There was a problem creating the EJB client archive: " + + e.getMessage(), e ); + } + catch ( DependencyResolutionRequiredException e ) + { + throw new MojoExecutionException( "There was a problem creating the EJB client archive: " + + e.getMessage(), e ); + } + + // TODO: shouldn't need classifer + if ( classifier != null ) + { + projectHelper.attachArtifact( project, "ejb-client", classifier + "-client", clientJarFile ); + } + else + { + projectHelper.attachArtifact( project, "ejb-client", "client", clientJarFile ); + } + } + + private void ejbVersionCompliance( File deploymentDescriptor ) + throws MojoExecutionException + { + if ( !ejbVersion.matches( "\\A[2-3]\\.[0-9]\\z" ) ) + { + throw new MojoExecutionException( "ejbVersion is not valid: " + ejbVersion + + ". Must be 2.x or 3.x (where x is a digit)" ); + } + + if ( ejbVersion.matches( "\\A2\\.[0-9]\\z" ) && !deploymentDescriptor.exists() ) + { + throw new MojoExecutionException( "Error assembling EJB: " + ejbJar + " is required for ejbVersion 2.x" ); + } + } + + private void filterDeploymentDescriptor( File deploymentDescriptor ) + throws MavenFilteringException, IOException + { + getLog().debug( "Filtering deployment descriptor." ); + MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(); + mavenResourcesExecution.setEscapeString( escapeString ); + List<FilterWrapper> filterWrappers = + mavenFileFilter.getDefaultFilterWrappers( project, filters, escapeBackslashesInFilePath, + this.session, mavenResourcesExecution ); + + // Create a temporary file that we can copy-and-filter + File unfilteredDeploymentDescriptor = new File( outputDirectory, ejbJar + ".unfiltered" ); + FileUtils.copyFile( deploymentDescriptor, unfilteredDeploymentDescriptor ); + mavenFileFilter.copyFile( unfilteredDeploymentDescriptor, deploymentDescriptor, true, + filterWrappers, getEncoding( unfilteredDeploymentDescriptor ) ); + // Remove the temporary file + FileUtils.forceDelete( unfilteredDeploymentDescriptor ); } /**