This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch parent in repository https://gitbox.apache.org/repos/asf/maven-ejb-plugin.git
commit 57958221f7c046862f345c2044235c54af1ef3c9 Author: Elliotte Rusty Harold <elh...@ibiblio.org> AuthorDate: Fri Mar 24 11:30:51 2023 -0400 format --- pom.xml | 8 +- .../org/apache/maven/plugins/ejb/EjbHelper.java | 69 +-- .../java/org/apache/maven/plugins/ejb/EjbMojo.java | 343 +++++------- .../apache/maven/plugins/ejb/IncludesExcludes.java | 69 +-- .../apache/maven/plugins/ejb/EjbHelperTest.java | 73 +-- .../org/apache/maven/plugins/ejb/EjbMojoTest.java | 613 ++++++++++----------- .../maven/plugins/ejb/IncludesExcludesTest.java | 108 ++-- .../plugins/ejb/stub/MavenProjectBasicStub.java | 108 ++-- .../plugins/ejb/stub/MavenProjectBuildStub.java | 208 +++---- .../ejb/stub/MavenProjectResourcesStub.java | 100 ++-- .../apache/maven/plugins/ejb/stub/ModelStub.java | 56 +- .../maven/plugins/ejb/utils/JarContentChecker.java | 89 ++- 12 files changed, 893 insertions(+), 951 deletions(-) diff --git a/pom.xml b/pom.xml index 18be480..7d83478 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,4 @@ -<?xml version='1.0' encoding='UTF-8'?> - +<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -18,7 +17,6 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -43,8 +41,8 @@ under the License. <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-ejb-plugin.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-ejb-plugin.git</developerConnection> - <url>https://github.com/apache/maven-ejb-plugin/tree/${project.scm.tag}</url> <tag>HEAD</tag> + <url>https://github.com/apache/maven-ejb-plugin/tree/${project.scm.tag}</url> </scm> <issueManagement> <system>JIRA</system> @@ -159,8 +157,8 @@ under the License. <build> <resources> <resource> - <directory>src/main/filtered-resources</directory> <filtering>true</filtering> + <directory>src/main/filtered-resources</directory> </resource> </resources> </build> diff --git a/src/main/java/org/apache/maven/plugins/ejb/EjbHelper.java b/src/main/java/org/apache/maven/plugins/ejb/EjbHelper.java index a6a5b77..d9deb35 100644 --- a/src/main/java/org/apache/maven/plugins/ejb/EjbHelper.java +++ b/src/main/java/org/apache/maven/plugins/ejb/EjbHelper.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb; /* @@ -23,36 +41,32 @@ import java.io.File; /** * This class contains some helper methods which do not belong to {@link EjbMojo}. - * + * * <pre> * Think about this helper class, cause i've got the impression this can be made better. * </pre> - * + * * @author <a href="mailto:khmarba...@apache.org">Karl Heinz Marbaise</a> */ -public final class EjbHelper -{ - private EjbHelper() - { +public final class EjbHelper { + private EjbHelper() { // prevent instantiation } /** * Check if a <code>classifier</code> is valid or not. - * + * * @param classifier The classifier which should be checked. * @return true in case of a valid <code>classifier</code> false otherwise which includes the case where * <code>classifier</code> is {@code null}. */ - public static boolean isClassifierValid( String classifier ) - { + public static boolean isClassifierValid(String classifier) { // @FIXME: Check classifier for trailing dash? "a-0" valid? // What are the rules for a valid classifier? Somewhere documented? which can be used as a reference? boolean result = false; // The following check is only based on an educated guess ;-) - if ( hasClassifier( classifier ) && classifier.matches( "^[a-zA-Z]+[0-9a-zA-Z\\-]*" ) ) - { + if (hasClassifier(classifier) && classifier.matches("^[a-zA-Z]+[0-9a-zA-Z\\-]*")) { result = true; } @@ -62,15 +76,13 @@ public final class EjbHelper /** * Check if the given classifier exists in the meaning of not being {@code null} and contain something else than * only white spaces. - * + * * @param classifier The classifier to be used. * @return true in case when the given classifier is not {@code null} and contains something else than white spaces. */ - public static boolean hasClassifier( String classifier ) - { + public static boolean hasClassifier(String classifier) { boolean result = false; - if ( classifier != null && classifier.trim().length() > 0 ) - { + if (classifier != null && classifier.trim().length() > 0) { result = true; } return result; @@ -84,27 +96,22 @@ public final class EjbHelper * @param classifier an optional classifier * @return the file to generate */ - public static File getJarFile( File basedir, String finalName, String classifier ) - { - if ( basedir == null ) - { - throw new IllegalArgumentException( "basedir is not allowed to be null" ); + public static File getJarFile(File basedir, String finalName, String classifier) { + if (basedir == null) { + throw new IllegalArgumentException("basedir is not allowed to be null"); } - if ( finalName == null ) - { - throw new IllegalArgumentException( "finalName is not allowed to be null" ); + if (finalName == null) { + throw new IllegalArgumentException("finalName is not allowed to be null"); } - StringBuilder fileName = new StringBuilder( finalName ); + StringBuilder fileName = new StringBuilder(finalName); - if ( hasClassifier( classifier ) ) - { - fileName.append( "-" ).append( classifier ); + if (hasClassifier(classifier)) { + fileName.append("-").append(classifier); } - fileName.append( ".jar" ); + fileName.append(".jar"); - return new File( basedir, fileName.toString() ); + return new File(basedir, fileName.toString()); } - } diff --git a/src/main/java/org/apache/maven/plugins/ejb/EjbMojo.java b/src/main/java/org/apache/maven/plugins/ejb/EjbMojo.java index 6ac6cf4..2e86080 100644 --- a/src/main/java/org/apache/maven/plugins/ejb/EjbMojo.java +++ b/src/main/java/org/apache/maven/plugins/ejb/EjbMojo.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb; /* @@ -55,25 +73,18 @@ import org.codehaus.plexus.util.FileUtils; * @author <a href="eveni...@apache.org">Emmanuel Venisse</a> * @version $Id$ */ -@Mojo( name = "ejb", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true, - defaultPhase = LifecyclePhase.PACKAGE ) -public class EjbMojo - extends AbstractMojo -{ - private static final List<String> DEFAULT_INCLUDES_LIST = - Collections.unmodifiableList( Arrays.asList( "**/**" ) ); - - //@formatter:off - private static final List<String> DEFAULT_CLIENT_EXCLUDES_LIST = - Collections.unmodifiableList( - Arrays.asList( - "**/*Bean.class", - "**/*CMP.class", - "**/*Session.class", - "**/package.html" - ) - ); - //@formatter:on +@Mojo( + name = "ejb", + requiresDependencyResolution = ResolutionScope.RUNTIME, + threadSafe = true, + defaultPhase = LifecyclePhase.PACKAGE) +public class EjbMojo extends AbstractMojo { + private static final List<String> DEFAULT_INCLUDES_LIST = Collections.unmodifiableList(Arrays.asList("**/**")); + + // @formatter:off + private static final List<String> DEFAULT_CLIENT_EXCLUDES_LIST = Collections.unmodifiableList( + Arrays.asList("**/*Bean.class", "**/*CMP.class", "**/*Session.class", "**/package.html")); + // @formatter:on /** * Default value for {@link #clientClassifier} @@ -88,19 +99,19 @@ public class EjbMojo /** * The directory location for the generated EJB. */ - @Parameter( defaultValue = "${project.build.directory}", required = true, readonly = true ) + @Parameter(defaultValue = "${project.build.directory}", required = true, readonly = true) private File outputDirectory; /** * Directory that contains the resources which are packaged into the created archive {@code target/classes}. */ - @Parameter( defaultValue = "${project.build.outputDirectory}", required = true ) + @Parameter(defaultValue = "${project.build.outputDirectory}", required = true) private File sourceDirectory; /** * The name of the EJB file to generate. */ - @Parameter( defaultValue = "${project.build.finalName}", readonly = true ) + @Parameter(defaultValue = "${project.build.finalName}", readonly = true) private String jarName; /** @@ -111,35 +122,35 @@ public class EjbMojo /** * Classifier which is used for the client artifact. - * + * * @since 3.0.0 */ - @Parameter( defaultValue = DEFAULT_CLIENT_CLASSIFIER ) + @Parameter(defaultValue = DEFAULT_CLIENT_CLASSIFIER) private String clientClassifier; /** * You can define the location of <code>ejb-jar.xml</code> file. */ - @Parameter( defaultValue = DEFAULT_EJBJAR ) + @Parameter(defaultValue = DEFAULT_EJBJAR) private String ejbJar; /** * Whether the EJB client jar should be generated or not. */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean generateClient; /** * The files and directories to exclude from the client jar. Usage: * <p/> - * + * * <pre> * <clientExcludes> * <clientExclude>**/*Ejb.class</clientExclude> * <clientExclude>**/*Bean.class</clientExclude> * </clientExcludes> * </pre> - * + * * <br/> * Attribute is used only if client jar is generated. <br/> * Default exclusions: **/*Bean.class, **/*CMP.class, **/*Session.class, **/package.html @@ -150,13 +161,13 @@ public class EjbMojo /** * The files and directories to include in the client jar. Usage: * <p/> - * + * * <pre> * <clientIncludes> * <clientInclude>**/*</clientInclude> * </clientIncludes> * </pre> - * + * * <br/> * Attribute is used only if client jar is generated. <br/> * Default value: **/** @@ -167,14 +178,14 @@ public class EjbMojo /** * The files and directories to exclude from the main EJB jar. Usage: * <p/> - * + * * <pre> * <excludes> * <exclude>**/*Ejb.class</exclude> * <exclude>**/*Bean.class</exclude> * </excludes> * </pre> - * + * * <br/> * Default exclusions: META-INF/ejb-jar.xml, **/package.html */ @@ -184,13 +195,13 @@ public class EjbMojo /** * The Maven project. */ - @Parameter( defaultValue = "${project}", readonly = true, required = true ) + @Parameter(defaultValue = "${project}", readonly = true, required = true) private MavenProject project; /** * The Jar archiver. */ - @Component( role = Archiver.class, hint = "jar" ) + @Component(role = Archiver.class, hint = "jar") private JarArchiver jarArchiver; /** @@ -198,20 +209,20 @@ public class EjbMojo * When ejbVersion is "2.x", the <code>ejb-jar.xml</code> file is mandatory. * <p/> * Usage: - * + * * <pre> * <ejbVersion>3.0</ejbVersion> * </pre> - * + * * @since 2.1 */ - @Parameter( defaultValue = "3.1" ) + @Parameter(defaultValue = "3.1") private String ejbVersion; /** * The client Jar archiver. */ - @Component( role = Archiver.class, hint = "jar" ) + @Component(role = Archiver.class, hint = "jar") private JarArchiver clientJarArchiver; /** @@ -232,7 +243,7 @@ public class EjbMojo * * @since 2.3 */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean escapeBackslashesInFilePath; /** @@ -248,7 +259,7 @@ public class EjbMojo * * @since 2.3 */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean filterDeploymentDescriptor; /** @@ -262,13 +273,13 @@ public class EjbMojo /** * @since 2.3 */ - @Component( role = MavenFileFilter.class, hint = "default" ) + @Component(role = MavenFileFilter.class, hint = "default") private MavenFileFilter mavenFileFilter; /** * @since 2.3 */ - @Parameter( defaultValue = "${session}", readonly = true, required = true ) + @Parameter(defaultValue = "${session}", readonly = true, required = true) private MavenSession session; /** @@ -278,7 +289,7 @@ public class EjbMojo * * @since 3.1.0 */ - @Parameter( defaultValue = "${project.build.outputTimestamp}" ) + @Parameter(defaultValue = "${project.build.outputTimestamp}") private String outputTimestamp; private static final String EJB_TYPE = "ejb"; @@ -288,245 +299,202 @@ public class EjbMojo /** * Generates an EJB jar and optionally an ejb-client jar. */ - public void execute() - throws MojoExecutionException - { - - if ( !sourceDirectory.exists() ) - { - getLog().warn( "The created EJB jar will be empty cause the " + sourceDirectory.getPath() - + " did not exist." ); + public void execute() throws MojoExecutionException { + + if (!sourceDirectory.exists()) { + getLog().warn("The created EJB jar will be empty cause the " + sourceDirectory.getPath() + + " did not exist."); sourceDirectory.mkdirs(); } File jarFile = generateEjb(); - if ( hasClassifier() ) - { - if ( !isClassifierValid() ) - { + if (hasClassifier()) { + if (!isClassifierValid()) { String message = "The given classifier '" + getClassifier() + "' is not valid."; - getLog().error( message ); - throw new MojoExecutionException( message ); + getLog().error(message); + throw new MojoExecutionException(message); } // TODO: We should check the attached artifacts to be sure we don't attach // the same file twice... - projectHelper.attachArtifact( project, EJB_TYPE, getClassifier(), jarFile ); - } - else - { - if ( projectHasAlreadySetAnArtifact() ) - { - throw new MojoExecutionException( "You have to use a classifier " - + "to attach supplemental artifacts to the project instead of replacing them." ); + projectHelper.attachArtifact(project, EJB_TYPE, getClassifier(), jarFile); + } else { + if (projectHasAlreadySetAnArtifact()) { + throw new MojoExecutionException("You have to use a classifier " + + "to attach supplemental artifacts to the project instead of replacing them."); } - project.getArtifact().setFile( jarFile ); + project.getArtifact().setFile(jarFile); } - if ( generateClient ) - { + if (generateClient) { File clientJarFile = generateEjbClient(); - if ( hasClientClassifier() ) - { - if ( !isClientClassifierValid() ) - { + if (hasClientClassifier()) { + if (!isClientClassifierValid()) { String message = "The given client classifier '" + getClientClassifier() + "' is not valid."; - getLog().error( message ); - throw new MojoExecutionException( message ); + getLog().error(message); + throw new MojoExecutionException(message); } - projectHelper.attachArtifact( project, EJB_CLIENT_TYPE, getClientClassifier(), clientJarFile ); - } - else - { + projectHelper.attachArtifact(project, EJB_CLIENT_TYPE, getClientClassifier(), clientJarFile); + } else { // FIXME: This does not make sense, cause a classifier for the client should always exist otherwise // Failure! - projectHelper.attachArtifact( project, "ejb-client", getClientClassifier(), clientJarFile ); + projectHelper.attachArtifact(project, "ejb-client", getClientClassifier(), clientJarFile); } - } } - private boolean projectHasAlreadySetAnArtifact() - { - if ( getProject().getArtifact().getFile() != null ) - { + private boolean projectHasAlreadySetAnArtifact() { + if (getProject().getArtifact().getFile() != null) { return getProject().getArtifact().getFile().isFile(); - } - else - { + } else { return false; } } - private File generateEjb() - throws MojoExecutionException - { - File jarFile = EjbHelper.getJarFile( outputDirectory, jarName, getClassifier() ); + private File generateEjb() throws MojoExecutionException { + File jarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClassifier()); - getLog().info( "Building EJB " + jarName + " with EJB version " + ejbVersion ); + getLog().info("Building EJB " + jarName + " with EJB version " + ejbVersion); MavenArchiver archiver = new MavenArchiver(); - archiver.setArchiver( jarArchiver ); + archiver.setArchiver(jarArchiver); - archiver.setCreatedBy( "Maven EJB Plugin", "org.apache.maven.plugins", "maven-ejb-plugin" ); + archiver.setCreatedBy("Maven EJB Plugin", "org.apache.maven.plugins", "maven-ejb-plugin"); - archiver.setOutputFile( jarFile ); + archiver.setOutputFile(jarFile); // configure for Reproducible Builds based on outputTimestamp value - archiver.configureReproducible( outputTimestamp ); + archiver.configureReproducible(outputTimestamp); - File deploymentDescriptor = new File( sourceDirectory, ejbJar ); + File deploymentDescriptor = new File(sourceDirectory, ejbJar); - checkEJBVersionCompliance( deploymentDescriptor ); + checkEJBVersionCompliance(deploymentDescriptor); - try - { - List<String> defaultExcludes = Arrays.asList( ejbJar, "**/package.html" ); + try { + List<String> defaultExcludes = Arrays.asList(ejbJar, "**/package.html"); List<String> defaultIncludes = DEFAULT_INCLUDES_LIST; IncludesExcludes ie = - new IncludesExcludes( Collections.<String>emptyList(), excludes, defaultIncludes, defaultExcludes ); + new IncludesExcludes(Collections.<String>emptyList(), excludes, defaultIncludes, defaultExcludes); - archiver.getArchiver().addDirectory( sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes() ); + archiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes()); // FIXME: We should be able to filter more than just the deployment descriptor? - if ( deploymentDescriptor.exists() ) - { + if (deploymentDescriptor.exists()) { // EJB-34 Filter ejb-jar.xml - if ( filterDeploymentDescriptor ) - { - filterDeploymentDescriptor( deploymentDescriptor ); + if (filterDeploymentDescriptor) { + filterDeploymentDescriptor(deploymentDescriptor); } - archiver.getArchiver().addFile( deploymentDescriptor, ejbJar ); + archiver.getArchiver().addFile(deploymentDescriptor, ejbJar); } // create archive - archiver.createArchive( session, project, archive ); - } - catch ( ArchiverException | ManifestException | IOException | DependencyResolutionRequiredException e ) - { - throw new MojoExecutionException( "There was a problem creating the EJB archive: " + e.getMessage(), e ); - } - catch ( MavenFilteringException e ) - { - throw new MojoExecutionException( "There was a problem filtering the deployment descriptor: " - + e.getMessage(), e ); + archiver.createArchive(session, project, archive); + } catch (ArchiverException | ManifestException | IOException | DependencyResolutionRequiredException e) { + throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e); + } catch (MavenFilteringException e) { + throw new MojoExecutionException( + "There was a problem filtering the deployment descriptor: " + e.getMessage(), e); } return jarFile; - } - private File generateEjbClient() - throws MojoExecutionException - { - File clientJarFile = EjbHelper.getJarFile( outputDirectory, jarName, getClientClassifier() ); + private File generateEjbClient() throws MojoExecutionException { + File clientJarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClientClassifier()); - getLog().info( "Building EJB client " + clientJarFile.getPath() ); + getLog().info("Building EJB client " + clientJarFile.getPath()); MavenArchiver clientArchiver = new MavenArchiver(); - clientArchiver.setArchiver( clientJarArchiver ); + clientArchiver.setArchiver(clientJarArchiver); - clientArchiver.setCreatedBy( "Maven EJB Plugin", "org.apache.maven.plugins", "maven-ejb-plugin" ); + clientArchiver.setCreatedBy("Maven EJB Plugin", "org.apache.maven.plugins", "maven-ejb-plugin"); - clientArchiver.setOutputFile( clientJarFile ); + clientArchiver.setOutputFile(clientJarFile); // configure for Reproducible Builds based on outputTimestamp value - clientArchiver.configureReproducible( outputTimestamp ); + clientArchiver.configureReproducible(outputTimestamp); - try - { + try { List<String> defaultExcludes = DEFAULT_CLIENT_EXCLUDES_LIST; List<String> defaultIncludes = DEFAULT_INCLUDES_LIST; IncludesExcludes ie = - new IncludesExcludes( clientIncludes, clientExcludes, defaultIncludes, defaultExcludes ); + new IncludesExcludes(clientIncludes, clientExcludes, defaultIncludes, defaultExcludes); - clientArchiver.getArchiver().addDirectory( sourceDirectory, ie.resultingIncludes(), - ie.resultingExcludes() ); + clientArchiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes()); - clientArchiver.createArchive( session, project, archive ); + clientArchiver.createArchive(session, project, archive); - } - catch ( ArchiverException | ManifestException | IOException | DependencyResolutionRequiredException e ) - { - throw new MojoExecutionException( "There was a problem creating the EJB client archive: " + e.getMessage(), - e ); + } catch (ArchiverException | ManifestException | IOException | DependencyResolutionRequiredException e) { + throw new MojoExecutionException( + "There was a problem creating the EJB client archive: " + e.getMessage(), e); } return clientJarFile; } - static void validateEjbVersion( String ejbVersion ) - throws MojoExecutionException - { - if ( !ejbVersion.matches( "\\A[2-4]\\.[0-9]\\z" ) ) - { - throw new MojoExecutionException( "ejbVersion is not valid: " + ejbVersion - + ". Must be 2.x, 3.x or 4.x (where x is a digit)" ); + static void validateEjbVersion(String ejbVersion) throws MojoExecutionException { + if (!ejbVersion.matches("\\A[2-4]\\.[0-9]\\z")) { + throw new MojoExecutionException( + "ejbVersion is not valid: " + ejbVersion + ". Must be 2.x, 3.x or 4.x (where x is a digit)"); } } - private void checkEJBVersionCompliance( File deploymentDescriptor ) - throws MojoExecutionException - { - validateEjbVersion( ejbVersion ); + private void checkEJBVersionCompliance(File deploymentDescriptor) throws MojoExecutionException { + validateEjbVersion(ejbVersion); - if ( ejbVersion.matches( "\\A2\\.[0-9]\\z" ) && !deploymentDescriptor.exists() ) - { - throw new MojoExecutionException( "Error assembling EJB: " + ejbJar + " is required for ejbVersion 2.x" ); + 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." ); + 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 ); + 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( sourceDirectory, ejbJar + ".unfiltered" ); - FileUtils.copyFile( deploymentDescriptor, unfilteredDeploymentDescriptor ); - mavenFileFilter.copyFile( unfilteredDeploymentDescriptor, deploymentDescriptor, true, filterWrappers, - getEncoding( unfilteredDeploymentDescriptor ) ); + File unfilteredDeploymentDescriptor = new File(sourceDirectory, ejbJar + ".unfiltered"); + FileUtils.copyFile(deploymentDescriptor, unfilteredDeploymentDescriptor); + mavenFileFilter.copyFile( + unfilteredDeploymentDescriptor, + deploymentDescriptor, + true, + filterWrappers, + getEncoding(unfilteredDeploymentDescriptor)); // Remove the temporary file - FileUtils.forceDelete( unfilteredDeploymentDescriptor ); + FileUtils.forceDelete(unfilteredDeploymentDescriptor); } /** * @return true in case where the classifier is not {@code null} and contains something else than white spaces. */ - private boolean hasClassifier() - { - return EjbHelper.hasClassifier( getClassifier() ); + private boolean hasClassifier() { + return EjbHelper.hasClassifier(getClassifier()); } /** * @return true in case where the clientClassifier is not {@code null} and contains something else than white * spaces. */ - private boolean hasClientClassifier() - { - return EjbHelper.hasClassifier( getClientClassifier() ); + private boolean hasClientClassifier() { + return EjbHelper.hasClassifier(getClientClassifier()); } - private boolean isClassifierValid() - { - return EjbHelper.isClassifierValid( getClassifier() ); + private boolean isClassifierValid() { + return EjbHelper.isClassifierValid(getClassifier()); } - private boolean isClientClassifierValid() - { - return EjbHelper.isClassifierValid( getClientClassifier() ); + private boolean isClientClassifierValid() { + return EjbHelper.isClassifierValid(getClientClassifier()); } /** @@ -536,29 +504,22 @@ public class EjbMojo * @return The encoding of the XML file, or UTF-8 if it's not specified in the file * @throws IOException if an error occurred while reading the file */ - private String getEncoding( File xmlFile ) - throws IOException - { - try ( XmlStreamReader xmlReader = new XmlStreamReader( xmlFile ) ) - { + private String getEncoding(File xmlFile) throws IOException { + try (XmlStreamReader xmlReader = new XmlStreamReader(xmlFile)) { final String encoding = xmlReader.getEncoding(); return encoding; } } - public String getClassifier() - { + public String getClassifier() { return classifier; } - public String getClientClassifier() - { + public String getClientClassifier() { return clientClassifier; } - public MavenProject getProject() - { + public MavenProject getProject() { return project; } - } diff --git a/src/main/java/org/apache/maven/plugins/ejb/IncludesExcludes.java b/src/main/java/org/apache/maven/plugins/ejb/IncludesExcludes.java index 9013109..3dd26dc 100644 --- a/src/main/java/org/apache/maven/plugins/ejb/IncludesExcludes.java +++ b/src/main/java/org/apache/maven/plugins/ejb/IncludesExcludes.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb; /* @@ -25,8 +43,7 @@ import java.util.List; /** * @author <a href="mailto:khmarba...@apache.org">Karl Heinz Marbaise</a> */ -public class IncludesExcludes -{ +public class IncludesExcludes { private List<String> includes; private List<String> defaultIncludes; @@ -35,47 +52,35 @@ public class IncludesExcludes private List<String> defaultExcludes; - public IncludesExcludes( List<String> includes, List<String> excludes, List<String> defaultIncludes, - List<String> defaultExcludes ) - { - this.includes = makeNonNullList( includes ); - this.excludes = makeNonNullList( excludes ); - this.defaultIncludes = makeNonNullList( defaultIncludes ); - this.defaultExcludes = makeNonNullList( defaultExcludes ); + public IncludesExcludes( + List<String> includes, List<String> excludes, List<String> defaultIncludes, List<String> defaultExcludes) { + this.includes = makeNonNullList(includes); + this.excludes = makeNonNullList(excludes); + this.defaultIncludes = makeNonNullList(defaultIncludes); + this.defaultExcludes = makeNonNullList(defaultExcludes); } - public String[] resultingIncludes() - { - return resultingXcludes( includes, defaultIncludes ); + public String[] resultingIncludes() { + return resultingXcludes(includes, defaultIncludes); } - public String[] resultingExcludes() - { - return resultingXcludes( excludes, defaultExcludes ); + public String[] resultingExcludes() { + return resultingXcludes(excludes, defaultExcludes); } - private static String[] resultingXcludes( List<String> currentXcludes, List<String> defaultXcludes ) - { - if ( currentXcludes.isEmpty() ) - { - return defaultXcludes.toArray( new String[0] ); - } - else - { - return currentXcludes.toArray( new String[0] ); + private static String[] resultingXcludes(List<String> currentXcludes, List<String> defaultXcludes) { + if (currentXcludes.isEmpty()) { + return defaultXcludes.toArray(new String[0]); + } else { + return currentXcludes.toArray(new String[0]); } } - private List<String> makeNonNullList( List<String> in ) - { - if ( in == null ) - { + private List<String> makeNonNullList(List<String> in) { + if (in == null) { return Collections.<String>emptyList(); - } - else - { + } else { return in; } } - } diff --git a/src/test/java/org/apache/maven/plugins/ejb/EjbHelperTest.java b/src/test/java/org/apache/maven/plugins/ejb/EjbHelperTest.java index 62241f7..579cd1a 100644 --- a/src/test/java/org/apache/maven/plugins/ejb/EjbHelperTest.java +++ b/src/test/java/org/apache/maven/plugins/ejb/EjbHelperTest.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb; /* @@ -19,73 +37,60 @@ package org.apache.maven.plugins.ejb; * under the License. */ - import java.io.File; import org.junit.Assert; import org.junit.Test; -public class EjbHelperTest -{ +public class EjbHelperTest { @Test - public void validClassifier() - { - Assert.assertTrue( EjbHelper.isClassifierValid( "anton" ) ); + public void validClassifier() { + Assert.assertTrue(EjbHelper.isClassifierValid("anton")); } @Test - public void anOtherValidClassifier() - { - Assert.assertTrue( EjbHelper.isClassifierValid( "jdk15" ) ); + public void anOtherValidClassifier() { + Assert.assertTrue(EjbHelper.isClassifierValid("jdk15")); } @Test - public void moreValidClassifier() - { - Assert.assertTrue( EjbHelper.isClassifierValid( "client-classifier" ) ); + public void moreValidClassifier() { + Assert.assertTrue(EjbHelper.isClassifierValid("client-classifier")); } @Test - public void isClassifierValidShouldReturnFalseIfClassifierIsPrefixedByDash() - { - Assert.assertFalse( EjbHelper.isClassifierValid( "-anton" ) ); + public void isClassifierValidShouldReturnFalseIfClassifierIsPrefixedByDash() { + Assert.assertFalse(EjbHelper.isClassifierValid("-anton")); } @Test - public void isClassifierValidShouldReturnFalseIfClassifierIsNull() - { - Assert.assertFalse( EjbHelper.isClassifierValid( null ) ); + public void isClassifierValidShouldReturnFalseIfClassifierIsNull() { + Assert.assertFalse(EjbHelper.isClassifierValid(null)); } @Test - public void hasClassifierShouldReturnFalseForNull() - { - Assert.assertFalse( EjbHelper.hasClassifier( null ) ); + public void hasClassifierShouldReturnFalseForNull() { + Assert.assertFalse(EjbHelper.hasClassifier(null)); } @Test - public void hasClassifierShouldReturnFalseForEmptyString() - { - Assert.assertFalse( EjbHelper.hasClassifier( "" ) ); + public void hasClassifierShouldReturnFalseForEmptyString() { + Assert.assertFalse(EjbHelper.hasClassifier("")); } @Test - public void hasClassifierShouldReturnTrueForNonEmptyString() - { - Assert.assertTrue( EjbHelper.hasClassifier( "x" ) ); + public void hasClassifierShouldReturnTrueForNonEmptyString() { + Assert.assertTrue(EjbHelper.hasClassifier("x")); } @Test - public void getJarFileNameShouldReturnFileNameWithoutClassifier() - { - Assert.assertEquals( EjbHelper.getJarFile( new File( "base" ), "test", null ), new File( "base/test.jar" ) ); + public void getJarFileNameShouldReturnFileNameWithoutClassifier() { + Assert.assertEquals(EjbHelper.getJarFile(new File("base"), "test", null), new File("base/test.jar")); } @Test - public void getJarFileNameShouldReturnFileNameWithClassifier() - { - Assert.assertEquals( EjbHelper.getJarFile( new File( "base" ), "test", - "alpha" ), new File( "base/test-alpha.jar" ) ); + public void getJarFileNameShouldReturnFileNameWithClassifier() { + Assert.assertEquals(EjbHelper.getJarFile(new File("base"), "test", "alpha"), new File("base/test-alpha.jar")); } } diff --git a/src/test/java/org/apache/maven/plugins/ejb/EjbMojoTest.java b/src/test/java/org/apache/maven/plugins/ejb/EjbMojoTest.java index c6225be..fe727ca 100644 --- a/src/test/java/org/apache/maven/plugins/ejb/EjbMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/ejb/EjbMojoTest.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb; /* @@ -35,9 +53,7 @@ import org.codehaus.plexus.util.FileUtils; /** * EJB plugin Test Case */ -public class EjbMojoTest - extends AbstractMojoTestCase -{ +public class EjbMojoTest extends AbstractMojoTestCase { static final String DEFAULT_POM_PATH = "target/test-classes/unit/ejbmojotest/plugin-config.xml"; static final String DEFAULT_JAR_NAME = "testJar"; @@ -47,9 +63,7 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testTestEnvironment() - throws Exception - { + public void testTestEnvironment() throws Exception { // Perform lookup on the Mojo to make sure everything is ok lookupMojo(); } @@ -59,20 +73,18 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testDefaultWithoutClientJar() - throws Exception - { - final MavenProjectResourcesStub project = createTestProject( "default-noclient" ); - final EjbMojo mojo = lookupMojoWithDefaultSettings( project ); + public void testDefaultWithoutClientJar() throws Exception { + final MavenProjectResourcesStub project = createTestProject("default-noclient"); + final EjbMojo mojo = lookupMojoWithDefaultSettings(project); - setupDefaultProject( project ); + setupDefaultProject(project); - setVariableValueToObject( mojo, "generateClient", Boolean.FALSE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + setVariableValueToObject(mojo, "generateClient", Boolean.FALSE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); mojo.execute(); - assertJarCreation( project, true, false ); + assertJarCreation(project, true, false); } /** @@ -80,21 +92,19 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testClassifiedJarWithoutClientJar() - throws Exception - { - final MavenProjectResourcesStub project = createTestProject( "classified-noclient" ); - final EjbMojo mojo = lookupMojoWithDefaultSettings( project ); + public void testClassifiedJarWithoutClientJar() throws Exception { + final MavenProjectResourcesStub project = createTestProject("classified-noclient"); + final EjbMojo mojo = lookupMojoWithDefaultSettings(project); - setupDefaultProject( project ); + setupDefaultProject(project); - setVariableValueToObject( mojo, "generateClient", Boolean.FALSE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); - setVariableValueToObject( mojo, "classifier", "classified" ); + setVariableValueToObject(mojo, "generateClient", Boolean.FALSE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); + setVariableValueToObject(mojo, "classifier", "classified"); mojo.execute(); - assertJarCreation( project, true, false, "classified" ); + assertJarCreation(project, true, false, "classified"); } /** @@ -102,20 +112,18 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testDefaultWithClientJar() - throws Exception - { - final MavenProjectResourcesStub project = createTestProject( "default-client" ); - final EjbMojo mojo = lookupMojoWithDefaultSettings( project ); + public void testDefaultWithClientJar() throws Exception { + final MavenProjectResourcesStub project = createTestProject("default-client"); + final EjbMojo mojo = lookupMojoWithDefaultSettings(project); - setupDefaultProject( project ); + setupDefaultProject(project); - setVariableValueToObject( mojo, "generateClient", Boolean.TRUE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + setVariableValueToObject(mojo, "generateClient", Boolean.TRUE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); mojo.execute(); - assertJarCreation( project, true, true ); + assertJarCreation(project, true, true); } /** @@ -123,22 +131,20 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testClassifiedJarWithClientJar() - throws Exception - { - final MavenProjectResourcesStub project = createTestProject( "classified-client" ); - final EjbMojo mojo = lookupMojoWithDefaultSettings( project ); + public void testClassifiedJarWithClientJar() throws Exception { + final MavenProjectResourcesStub project = createTestProject("classified-client"); + final EjbMojo mojo = lookupMojoWithDefaultSettings(project); - setupDefaultProject( project ); + setupDefaultProject(project); - setVariableValueToObject( mojo, "generateClient", Boolean.TRUE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); - setVariableValueToObject( mojo, "classifier", "classified" ); - setVariableValueToObject( mojo, "clientClassifier", "classified-client" ); + setVariableValueToObject(mojo, "generateClient", Boolean.TRUE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); + setVariableValueToObject(mojo, "classifier", "classified"); + setVariableValueToObject(mojo, "clientClassifier", "classified-client"); mojo.execute(); - assertJarCreation( project, true, true, "classified" ); + assertJarCreation(project, true, true, "classified"); } /** @@ -146,38 +152,41 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testDefaultInclusionsExclusions() - throws Exception - { + public void testDefaultInclusionsExclusions() throws Exception { - final MavenProjectResourcesStub project = createTestProject( "includes-excludes-default" ); - final EjbMojo mojo = lookupMojoWithDefaultSettings( project ); + final MavenProjectResourcesStub project = createTestProject("includes-excludes-default"); + final EjbMojo mojo = lookupMojoWithDefaultSettings(project); // put this on the target output dir - project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppBean.class", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppCMP.class", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppSession.class", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile("META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppBean.class", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppCMP.class", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppSession.class", MavenProjectResourcesStub.OUTPUT_FILE); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "generateClient", Boolean.FALSE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + setVariableValueToObject(mojo, "generateClient", Boolean.FALSE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); mojo.execute(); - assertJarCreation( project, true, false ); - assertJarContent( project, - new String[] { "META-INF/MANIFEST.MF", "META-INF/ejb-jar.xml", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", - "org/sample/ejb/AppBean.class", "org/sample/ejb/AppCMP.class", - "org/sample/ejb/AppSession.class" }, - null ); + assertJarCreation(project, true, false); + assertJarContent( + project, + new String[] { + "META-INF/MANIFEST.MF", + "META-INF/ejb-jar.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", + "org/sample/ejb/AppBean.class", + "org/sample/ejb/AppCMP.class", + "org/sample/ejb/AppSession.class" + }, + null); } /** @@ -185,39 +194,44 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testClientJarDefaultInclusionsExclusions() - throws Exception - { + public void testClientJarDefaultInclusionsExclusions() throws Exception { - final MavenProjectResourcesStub project = createTestProject( "includes-excludes-client" ); - final EjbMojo mojo = lookupMojoWithDefaultSettings( project ); + final MavenProjectResourcesStub project = createTestProject("includes-excludes-client"); + final EjbMojo mojo = lookupMojoWithDefaultSettings(project); // put this on the target output dir - project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppBean.class", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppCMP.class", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppSession.class", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppStub.class", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile("META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppBean.class", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppCMP.class", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppSession.class", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppStub.class", MavenProjectResourcesStub.OUTPUT_FILE); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "generateClient", Boolean.TRUE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + setVariableValueToObject(mojo, "generateClient", Boolean.TRUE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); mojo.execute(); - assertJarCreation( project, true, true ); - assertClientJarContent( project, - new String[] { "META-INF/MANIFEST.MF", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", - "org/sample/ejb/AppStub.class" }, - new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/AppBean.class", - "org/sample/ejb/AppCMP.class", "org/sample/ejb/AppSession.class" } ); + assertJarCreation(project, true, true); + assertClientJarContent( + project, + new String[] { + "META-INF/MANIFEST.MF", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", + "org/sample/ejb/AppStub.class" + }, + new String[] { + "META-INF/ejb-jar.xml", + "org/sample/ejb/AppBean.class", + "org/sample/ejb/AppCMP.class", + "org/sample/ejb/AppSession.class" + }); } /** @@ -225,38 +239,39 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testClientJarInclusions() - throws Exception - { + public void testClientJarInclusions() throws Exception { final List<String> inclusions = new LinkedList<String>(); - inclusions.add( "**/*Include.class" ); + inclusions.add("**/*Include.class"); - final MavenProjectResourcesStub project = createTestProject( "client-includes" ); - final EjbMojo mojo = lookupMojoWithSettings( project, inclusions, new LinkedList<String>(), null ); + final MavenProjectResourcesStub project = createTestProject("client-includes"); + final EjbMojo mojo = lookupMojoWithSettings(project, inclusions, new LinkedList<String>(), null); // put this on the target output dir - project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppInclude.class", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppExclude.class", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile("META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppInclude.class", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppExclude.class", MavenProjectResourcesStub.OUTPUT_FILE); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "generateClient", Boolean.TRUE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + setVariableValueToObject(mojo, "generateClient", Boolean.TRUE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); mojo.execute(); - assertJarCreation( project, true, true ); - assertClientJarContent( project, - new String[] { "META-INF/MANIFEST.MF", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", - "org/sample/ejb/AppInclude.class" }, - new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/AppExclude.class" } ); + assertJarCreation(project, true, true); + assertClientJarContent( + project, + new String[] { + "META-INF/MANIFEST.MF", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", + "org/sample/ejb/AppInclude.class" + }, + new String[] {"META-INF/ejb-jar.xml", "org/sample/ejb/AppExclude.class"}); } /** @@ -264,40 +279,40 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testClientJarExclusions() - throws Exception - { + public void testClientJarExclusions() throws Exception { final List<String> exclusions = new LinkedList<String>(); - exclusions.add( "**/*Exclude.class" ); + exclusions.add("**/*Exclude.class"); - final MavenProjectResourcesStub project = createTestProject( "client-excludes" ); - final EjbMojo mojo = lookupMojoWithSettings( project, new LinkedList<String>(), exclusions, null ); + final MavenProjectResourcesStub project = createTestProject("client-excludes"); + final EjbMojo mojo = lookupMojoWithSettings(project, new LinkedList<String>(), exclusions, null); // put this on the target output dir - project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppInclude.class", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppExclude.class", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile("META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppInclude.class", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppExclude.class", MavenProjectResourcesStub.OUTPUT_FILE); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "generateClient", Boolean.TRUE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + setVariableValueToObject(mojo, "generateClient", Boolean.TRUE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); mojo.execute(); - assertJarCreation( project, true, true ); - assertClientJarContent( project, - new String[] { "META-INF/MANIFEST.MF", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", - "org/sample/ejb/AppInclude.class" }, - new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/AppExclude.class" } ); - + assertJarCreation(project, true, true); + assertClientJarContent( + project, + new String[] { + "META-INF/MANIFEST.MF", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", + "org/sample/ejb/AppInclude.class" + }, + new String[] {"META-INF/ejb-jar.xml", "org/sample/ejb/AppExclude.class"}); } /** @@ -305,40 +320,40 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testMainJarExclusions() - throws Exception - { + public void testMainJarExclusions() throws Exception { final List<String> exclusions = new LinkedList<String>(); - exclusions.add( "**/*Exclude.class" ); + exclusions.add("**/*Exclude.class"); - final MavenProjectResourcesStub project = createTestProject( "main-excludes" ); + final MavenProjectResourcesStub project = createTestProject("main-excludes"); final EjbMojo mojo = - lookupMojoWithSettings( project, new LinkedList<String>(), new LinkedList<String>(), exclusions ); + lookupMojoWithSettings(project, new LinkedList<String>(), new LinkedList<String>(), exclusions); // put this on the target output dir - project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppInclude.class", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppExclude.class", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile("META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppInclude.class", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppExclude.class", MavenProjectResourcesStub.OUTPUT_FILE); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "generateClient", Boolean.TRUE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + setVariableValueToObject(mojo, "generateClient", Boolean.TRUE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); mojo.execute(); - assertJarCreation( project, true, true ); - assertJarContent( project, - new String[] { "META-INF/MANIFEST.MF", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", - "org/sample/ejb/AppInclude.class" }, - new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/AppExclude.class" } ); - + assertJarCreation(project, true, true); + assertJarContent( + project, + new String[] { + "META-INF/MANIFEST.MF", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", + "org/sample/ejb/AppInclude.class" + }, + new String[] {"META-INF/ejb-jar.xml", "org/sample/ejb/AppExclude.class"}); } /** @@ -346,40 +361,40 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testClientJarInclusionsWithSubPackage() - throws Exception - { + public void testClientJarInclusionsWithSubPackage() throws Exception { final List<String> inclusions = new LinkedList<String>(); - inclusions.add( "org/sample/ejb/*.class" ); + inclusions.add("org/sample/ejb/*.class"); - final MavenProjectResourcesStub project = createTestProject( "client-includes-subpackage" ); + final MavenProjectResourcesStub project = createTestProject("client-includes-subpackage"); - final EjbMojo mojo = lookupMojoWithSettings( project, inclusions, new LinkedList<String>(), null ); + final EjbMojo mojo = lookupMojoWithSettings(project, inclusions, new LinkedList<String>(), null); // put this on the target output dir - project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/App.class", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/impl/AppImpl.class", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile("META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/App.class", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/impl/AppImpl.class", MavenProjectResourcesStub.OUTPUT_FILE); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "generateClient", Boolean.TRUE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + setVariableValueToObject(mojo, "generateClient", Boolean.TRUE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); mojo.execute(); - assertJarCreation( project, true, true ); - assertClientJarContent( project, - new String[] { "META-INF/MANIFEST.MF", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", - "org/sample/ejb/App.class" }, - new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/impl/AppImpl.class", - "org/sample/ejb/impl" } ); + assertJarCreation(project, true, true); + assertClientJarContent( + project, + new String[] { + "META-INF/MANIFEST.MF", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", + "org/sample/ejb/App.class" + }, + new String[] {"META-INF/ejb-jar.xml", "org/sample/ejb/impl/AppImpl.class", "org/sample/ejb/impl"}); } /** @@ -387,43 +402,42 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testClientJarExclusionsWithEmptyPackage() - throws Exception - { + public void testClientJarExclusionsWithEmptyPackage() throws Exception { final LinkedList<String> exclusions = new LinkedList<String>(); - exclusions.add( "org/sample/ejb/**" ); + exclusions.add("org/sample/ejb/**"); - final MavenProjectResourcesStub project = createTestProject( "client-excludes-emptypackage" ); - final EjbMojo mojo = lookupMojoWithSettings( project, new LinkedList<String>(), exclusions, null ); + final MavenProjectResourcesStub project = createTestProject("client-excludes-emptypackage"); + final EjbMojo mojo = lookupMojoWithSettings(project, new LinkedList<String>(), exclusions, null); // put this on the target output dir - project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb/AppOne.class", MavenProjectResourcesStub.OUTPUT_FILE ); - project.addFile( "org/sample/ejb2/AppTwo.class", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile("META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb/AppOne.class", MavenProjectResourcesStub.OUTPUT_FILE); + project.addFile("org/sample/ejb2/AppTwo.class", MavenProjectResourcesStub.OUTPUT_FILE); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "generateClient", Boolean.TRUE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + setVariableValueToObject(mojo, "generateClient", Boolean.TRUE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); mojo.execute(); - assertJarCreation( project, true, true ); + assertJarCreation(project, true, true); // We check that the created jar does not contain the org/sample/ejb package empty - assertClientJarContent( project, - new String[] { "META-INF/MANIFEST.MF", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", - "org/sample/ejb2/AppTwo.class" }, - new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/AppOne.class", - "org/sample/ejb" } ); - + assertClientJarContent( + project, + new String[] { + "META-INF/MANIFEST.MF", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", + "org/sample/ejb2/AppTwo.class" + }, + new String[] {"META-INF/ejb-jar.xml", "org/sample/ejb/AppOne.class", "org/sample/ejb"}); } /** @@ -432,28 +446,23 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testEjbComplianceVersionTwoDotOneWithoutDescriptor() - throws Exception - { - final MavenProjectResourcesStub project = createTestProject( "compliance-nodescriptor-2.1" ); - final EjbMojo mojo = lookupMojoWithDefaultSettings( project ); + public void testEjbComplianceVersionTwoDotOneWithoutDescriptor() throws Exception { + final MavenProjectResourcesStub project = createTestProject("compliance-nodescriptor-2.1"); + final EjbMojo mojo = lookupMojoWithDefaultSettings(project); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "generateClient", Boolean.FALSE ); - setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + setVariableValueToObject(mojo, "generateClient", Boolean.FALSE); + setVariableValueToObject(mojo, "ejbVersion", "2.1"); - try - { + try { mojo.execute(); - fail( "Exception should be thrown: No deployment descriptor present." ); - } - catch ( MojoExecutionException e ) - { + fail("Exception should be thrown: No deployment descriptor present."); + } catch (MojoExecutionException e) { // OK } } @@ -463,29 +472,26 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testEjbComplianceVersionThreeWithDescriptor() - throws Exception - { + public void testEjbComplianceVersionThreeWithDescriptor() throws Exception { - final MavenProjectResourcesStub project = createTestProject( "compliance-descriptor-3" ); - final EjbMojo mojo = lookupMojoWithDefaultSettings( project ); + final MavenProjectResourcesStub project = createTestProject("compliance-descriptor-3"); + final EjbMojo mojo = lookupMojoWithDefaultSettings(project); // put this on the target dir - project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile("META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "generateClient", Boolean.FALSE ); - setVariableValueToObject( mojo, "ejbVersion", "3.0" ); + setVariableValueToObject(mojo, "generateClient", Boolean.FALSE); + setVariableValueToObject(mojo, "ejbVersion", "3.0"); mojo.execute(); - assertJarCreation( project, true, false ); - + assertJarCreation(project, true, false); } /** @@ -493,183 +499,152 @@ public class EjbMojoTest * * @throws Exception if any exception occurs */ - public void testEjbCompliance_3_0_WithoutDescriptor() - throws Exception - { - final MavenProjectResourcesStub project = createTestProject( "compliance-nodescriptor-3" ); - final EjbMojo mojo = lookupMojoWithDefaultSettings( project ); + public void testEjbCompliance_3_0_WithoutDescriptor() throws Exception { + final MavenProjectResourcesStub project = createTestProject("compliance-nodescriptor-3"); + final EjbMojo mojo = lookupMojoWithDefaultSettings(project); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "generateClient", Boolean.FALSE ); - setVariableValueToObject( mojo, "ejbVersion", "3.0" ); + setVariableValueToObject(mojo, "generateClient", Boolean.FALSE); + setVariableValueToObject(mojo, "ejbVersion", "3.0"); mojo.execute(); - assertJarCreation( project, true, false ); + assertJarCreation(project, true, false); } - public void testEjb1VersionValidation() - { - try - { - EjbMojo.validateEjbVersion( "1.1" ); - fail( "MojoException is expected" ); - } - catch ( MojoExecutionException mex ) - { + public void testEjb1VersionValidation() { + try { + EjbMojo.validateEjbVersion("1.1"); + fail("MojoException is expected"); + } catch (MojoExecutionException mex) { } } - public void testEjb2VersionValidation() - throws MojoExecutionException - { - EjbMojo.validateEjbVersion( "2.1" ); + public void testEjb2VersionValidation() throws MojoExecutionException { + EjbMojo.validateEjbVersion("2.1"); } - public void testEjb3VersionValidation() - throws MojoExecutionException - { - EjbMojo.validateEjbVersion( "3.2" ); + public void testEjb3VersionValidation() throws MojoExecutionException { + EjbMojo.validateEjbVersion("3.2"); } - public void testEjb4VersionValidation() - throws MojoExecutionException - { - EjbMojo.validateEjbVersion( "4.0" ); + public void testEjb4VersionValidation() throws MojoExecutionException { + EjbMojo.validateEjbVersion("4.0"); } - protected EjbMojo lookupMojo() - throws Exception - { - File pomFile = new File( getBasedir(), DEFAULT_POM_PATH ); - EjbMojo mojo = (EjbMojo) lookupMojo( "ejb", pomFile ); + protected EjbMojo lookupMojo() throws Exception { + File pomFile = new File(getBasedir(), DEFAULT_POM_PATH); + EjbMojo mojo = (EjbMojo) lookupMojo("ejb", pomFile); - assertNotNull( mojo ); + assertNotNull(mojo); return mojo; } - protected MavenProjectResourcesStub createTestProject( final String testName ) - throws Exception - { + protected MavenProjectResourcesStub createTestProject(final String testName) throws Exception { // this will automatically create the isolated // test environment - return new MavenProjectResourcesStub( testName ); + return new MavenProjectResourcesStub(testName); } - protected void setupDefaultProject( final MavenProjectResourcesStub project ) - throws Exception - { + protected void setupDefaultProject(final MavenProjectResourcesStub project) throws Exception { // put this on the target dir - project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile("META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE); // put this on the root dir - project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + project.addFile("pom.xml", MavenProjectResourcesStub.ROOT_FILE); // start creating the environment project.setupBuildEnvironment(); - } - protected EjbMojo lookupMojoWithSettings( final MavenProject project, List<String> clientIncludes, - List<String> clientExcludes, List<String> excludes ) - throws Exception - { + protected EjbMojo lookupMojoWithSettings( + final MavenProject project, List<String> clientIncludes, List<String> clientExcludes, List<String> excludes) + throws Exception { final EjbMojo mojo = lookupMojo(); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getDirectory() ) ); - setVariableValueToObject( mojo, "sourceDirectory", new File( project.getBuild().getOutputDirectory() ) ); - setVariableValueToObject( mojo, "jarName", DEFAULT_JAR_NAME ); - setVariableValueToObject( mojo, "ejbJar", EjbMojo.DEFAULT_EJBJAR ); - setVariableValueToObject( mojo, "clientExcludes", clientExcludes ); - setVariableValueToObject( mojo, "clientIncludes", clientIncludes ); - setVariableValueToObject( mojo, "excludes", excludes ); - setVariableValueToObject( mojo, "clientClassifier", EjbMojo.DEFAULT_CLIENT_CLASSIFIER ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getDirectory())); + setVariableValueToObject( + mojo, "sourceDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "jarName", DEFAULT_JAR_NAME); + setVariableValueToObject(mojo, "ejbJar", EjbMojo.DEFAULT_EJBJAR); + setVariableValueToObject(mojo, "clientExcludes", clientExcludes); + setVariableValueToObject(mojo, "clientIncludes", clientIncludes); + setVariableValueToObject(mojo, "excludes", excludes); + setVariableValueToObject(mojo, "clientClassifier", EjbMojo.DEFAULT_CLIENT_CLASSIFIER); return mojo; } - protected EjbMojo lookupMojoWithDefaultSettings( final MavenProject project ) - throws Exception - { - return lookupMojoWithSettings( project, new LinkedList<String>(), new LinkedList<String>(), null ); + protected EjbMojo lookupMojoWithDefaultSettings(final MavenProject project) throws Exception { + return lookupMojoWithSettings(project, new LinkedList<String>(), new LinkedList<String>(), null); } - protected void assertJarCreation( final MavenProject project, boolean ejbJarCreated, boolean ejbClientJarCreated, - String classifier ) - { + protected void assertJarCreation( + final MavenProject project, boolean ejbJarCreated, boolean ejbClientJarCreated, String classifier) { String checkedJarFile; String checkedClientJarFile; - if ( classifier == null ) - { + if (classifier == null) { checkedJarFile = project.getBuild().getDirectory() + "/" + DEFAULT_JAR_NAME + ".jar"; checkedClientJarFile = project.getBuild().getDirectory() + "/" + DEFAULT_JAR_NAME + "-client.jar"; - } - else - { + } else { checkedJarFile = project.getBuild().getDirectory() + "/" + DEFAULT_JAR_NAME + "-" + classifier + ".jar"; checkedClientJarFile = - project.getBuild().getDirectory() + "/" + DEFAULT_JAR_NAME + "-" + classifier + "-client.jar"; + project.getBuild().getDirectory() + "/" + DEFAULT_JAR_NAME + "-" + classifier + "-client.jar"; } - assertEquals( "Invalid value for ejb-jar creation", ejbJarCreated, FileUtils.fileExists( checkedJarFile ) ); - assertEquals( "Invalid value for ejb-jar client creation", ejbClientJarCreated, - FileUtils.fileExists( checkedClientJarFile ) ); - + assertEquals("Invalid value for ejb-jar creation", ejbJarCreated, FileUtils.fileExists(checkedJarFile)); + assertEquals( + "Invalid value for ejb-jar client creation", + ejbClientJarCreated, + FileUtils.fileExists(checkedClientJarFile)); } - protected void assertJarCreation( final MavenProject project, boolean ejbJarCreated, boolean ejbClientJarCreated ) - { - assertJarCreation( project, ejbJarCreated, ejbClientJarCreated, null ); - + protected void assertJarCreation(final MavenProject project, boolean ejbJarCreated, boolean ejbClientJarCreated) { + assertJarCreation(project, ejbJarCreated, ejbClientJarCreated, null); } - private void doAssertJarContent( final MavenProject project, final String fileName, final String[] expectedFiles, - final String[] unexpectedFiles ) - throws IOException - { + private void doAssertJarContent( + final MavenProject project, + final String fileName, + final String[] expectedFiles, + final String[] unexpectedFiles) + throws IOException { String checkedJarFile = project.getBuild().getDirectory() + "/" + fileName; - if ( expectedFiles != null ) - { + if (expectedFiles != null) { final JarContentChecker inclusionChecker = new JarContentChecker(); // set expected jar contents - for ( String expectedFile : expectedFiles ) - { - inclusionChecker.addFile( new File( expectedFile ) ); + for (String expectedFile : expectedFiles) { + inclusionChecker.addFile(new File(expectedFile)); } - assertTrue( inclusionChecker.isOK( new JarFile( checkedJarFile ) ) ); + assertTrue(inclusionChecker.isOK(new JarFile(checkedJarFile))); } - if ( unexpectedFiles != null ) - { + if (unexpectedFiles != null) { final JarContentChecker exclusionChecker = new JarContentChecker(); - for ( String unexpectedFile : unexpectedFiles ) - { - exclusionChecker.addFile( new File( unexpectedFile ) ); + for (String unexpectedFile : unexpectedFiles) { + exclusionChecker.addFile(new File(unexpectedFile)); } - assertFalse( exclusionChecker.isOK( new JarFile( checkedJarFile ) ) ); + assertFalse(exclusionChecker.isOK(new JarFile(checkedJarFile))); } - } - protected void assertJarContent( final MavenProject project, final String[] expectedFiles, - final String[] unexpectedFiles ) - throws IOException - { + protected void assertJarContent( + final MavenProject project, final String[] expectedFiles, final String[] unexpectedFiles) + throws IOException { - doAssertJarContent( project, DEFAULT_JAR_NAME + ".jar", expectedFiles, unexpectedFiles ); + doAssertJarContent(project, DEFAULT_JAR_NAME + ".jar", expectedFiles, unexpectedFiles); } - protected void assertClientJarContent( final MavenProject project, final String[] expectedFiles, - final String[] unexpectedFiles ) - throws IOException - { - - doAssertJarContent( project, DEFAULT_JAR_NAME + "-client.jar", expectedFiles, unexpectedFiles ); + protected void assertClientJarContent( + final MavenProject project, final String[] expectedFiles, final String[] unexpectedFiles) + throws IOException { + doAssertJarContent(project, DEFAULT_JAR_NAME + "-client.jar", expectedFiles, unexpectedFiles); } } diff --git a/src/test/java/org/apache/maven/plugins/ejb/IncludesExcludesTest.java b/src/test/java/org/apache/maven/plugins/ejb/IncludesExcludesTest.java index 36c07a5..33689c1 100644 --- a/src/test/java/org/apache/maven/plugins/ejb/IncludesExcludesTest.java +++ b/src/test/java/org/apache/maven/plugins/ejb/IncludesExcludesTest.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb; /* @@ -19,81 +37,81 @@ package org.apache.maven.plugins.ejb; * under the License. */ - import java.util.Arrays; import java.util.Collections; import org.junit.Assert; import org.junit.Test; -public class IncludesExcludesTest -{ +public class IncludesExcludesTest { @Test - public void emptyListsShouldResultInZeroSizeResults() - { - IncludesExcludes ie = new IncludesExcludes( Collections.<String>emptyList(), Collections.<String>emptyList(), - Collections.<String>emptyList(), Collections.<String>emptyList() ); + public void emptyListsShouldResultInZeroSizeResults() { + IncludesExcludes ie = new IncludesExcludes( + Collections.<String>emptyList(), Collections.<String>emptyList(), + Collections.<String>emptyList(), Collections.<String>emptyList()); - Assert.assertArrayEquals( ie.resultingIncludes(), new String[0] ); - Assert.assertArrayEquals( ie.resultingExcludes(), new String[0] ); + Assert.assertArrayEquals(ie.resultingIncludes(), new String[0]); + Assert.assertArrayEquals(ie.resultingExcludes(), new String[0]); } @Test - public void nullForIncludesShouldResultInZeroSizeResults() - { - IncludesExcludes ie = new IncludesExcludes( null, Collections.<String>emptyList(), - Collections.<String>emptyList(), Collections.<String>emptyList() ); - - Assert.assertArrayEquals( ie.resultingIncludes(), new String[0] ); - Assert.assertArrayEquals( ie.resultingExcludes(), new String[0] ); + public void nullForIncludesShouldResultInZeroSizeResults() { + IncludesExcludes ie = new IncludesExcludes( + null, + Collections.<String>emptyList(), + Collections.<String>emptyList(), + Collections.<String>emptyList()); + + Assert.assertArrayEquals(ie.resultingIncludes(), new String[0]); + Assert.assertArrayEquals(ie.resultingExcludes(), new String[0]); } @Test - public void nullForExcludesShouldResultInZeroSizeResults() - { - IncludesExcludes ie = new IncludesExcludes( Collections.<String>emptyList(), null, - Collections.<String>emptyList(), Collections.<String>emptyList() ); - - Assert.assertArrayEquals( ie.resultingIncludes(), new String[0] ); - Assert.assertArrayEquals( ie.resultingExcludes(), new String[0] ); + public void nullForExcludesShouldResultInZeroSizeResults() { + IncludesExcludes ie = new IncludesExcludes( + Collections.<String>emptyList(), + null, + Collections.<String>emptyList(), + Collections.<String>emptyList()); + + Assert.assertArrayEquals(ie.resultingIncludes(), new String[0]); + Assert.assertArrayEquals(ie.resultingExcludes(), new String[0]); } @Test - public void nonNullForDefaultExcludesShouldResultInExcludesWithDefaultExcludes() - { - IncludesExcludes ie = new IncludesExcludes( null, null, Collections.<String>emptyList(), - Arrays.asList( "**/package.html" ) ); + public void nonNullForDefaultExcludesShouldResultInExcludesWithDefaultExcludes() { + IncludesExcludes ie = + new IncludesExcludes(null, null, Collections.<String>emptyList(), Arrays.asList("**/package.html")); - Assert.assertArrayEquals( ie.resultingIncludes(), new String[0] ); - Assert.assertArrayEquals( ie.resultingExcludes(), new String[] { "**/package.html" } ); + Assert.assertArrayEquals(ie.resultingIncludes(), new String[0]); + Assert.assertArrayEquals(ie.resultingExcludes(), new String[] {"**/package.html"}); } @Test - public void nonNullForDefaultIncludesShouldResultInIncludesWithDefaultIncludes() - { - IncludesExcludes ie = new IncludesExcludes( null, null, Arrays.asList( "**/package.html" ), - Collections.<String>emptyList() ); + public void nonNullForDefaultIncludesShouldResultInIncludesWithDefaultIncludes() { + IncludesExcludes ie = + new IncludesExcludes(null, null, Arrays.asList("**/package.html"), Collections.<String>emptyList()); - Assert.assertArrayEquals( ie.resultingIncludes(), new String[] { "**/package.html" } ); - Assert.assertArrayEquals( ie.resultingExcludes(), new String[0] ); + Assert.assertArrayEquals(ie.resultingIncludes(), new String[] {"**/package.html"}); + Assert.assertArrayEquals(ie.resultingExcludes(), new String[0]); } @Test - public void nonNullIncludesShouldResultInTheSameIncludes() - { - IncludesExcludes ie = new IncludesExcludes( Arrays.asList( "**/package.html" ), null, - Arrays.asList( "**/site.html" ), null ); + public void nonNullIncludesShouldResultInTheSameIncludes() { + IncludesExcludes ie = new IncludesExcludes( + Arrays.asList("**/package.html"), null, + Arrays.asList("**/site.html"), null); - Assert.assertArrayEquals( ie.resultingIncludes(), new String[] { "**/package.html" } ); + Assert.assertArrayEquals(ie.resultingIncludes(), new String[] {"**/package.html"}); } @Test - public void nonNullExcludesShouldResultInTheSameExcludes() - { - IncludesExcludes ie = new IncludesExcludes( null, Arrays.asList( "**/package.html" ), - null, Arrays.asList( "**/site.html" ) ); + public void nonNullExcludesShouldResultInTheSameExcludes() { + IncludesExcludes ie = new IncludesExcludes( + null, Arrays.asList("**/package.html"), + null, Arrays.asList("**/site.html")); - Assert.assertArrayEquals( ie.resultingExcludes(), new String[] { "**/package.html" } ); + Assert.assertArrayEquals(ie.resultingExcludes(), new String[] {"**/package.html"}); } } diff --git a/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBasicStub.java b/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBasicStub.java index 6383026..97c7893 100644 --- a/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBasicStub.java +++ b/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBasicStub.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb.stub; /* @@ -35,9 +53,7 @@ import org.codehaus.plexus.util.FileUtils; /** * Stub */ -public class MavenProjectBasicStub - extends MavenProject -{ +public class MavenProjectBasicStub extends MavenProject { protected String identifier; protected String testRootDir; @@ -52,11 +68,9 @@ public class MavenProjectBasicStub protected DefaultArtifact artifact; - public MavenProjectBasicStub( String id ) - throws Exception - { + public MavenProjectBasicStub(String id) throws Exception { // most values are hardcoded to have a controlled environment - super( new ModelStub() ); + super(new ModelStub()); model = (ModelStub) super.getModel(); properties = new Properties(); @@ -67,9 +81,8 @@ public class MavenProjectBasicStub // set isolated root directory testRootDir = PlexusTestCase.getBasedir() + "/target/test-classes/unit/test-dir/" + identifier; - if ( !FileUtils.fileExists( testRootDir ) ) - { - FileUtils.mkdir( testRootDir ); + if (!FileUtils.fileExists(testRootDir)) { + FileUtils.mkdir(testRootDir); } // this is ugly but needed to ensure that the copy constructor @@ -77,94 +90,77 @@ public class MavenProjectBasicStub initializeParentFields(); } - public String getName() - { + public String getName() { return "Test Project " + identifier; } - public void setDescription( String desc ) - { + public void setDescription(String desc) { description = desc; } - public Model getModel() - { + public Model getModel() { return model; } - public String getDescription() - { - if ( description == null ) - { + public String getDescription() { + if (description == null) { return "this is a test project"; - } - else - { + } else { return description; } } - public File getBasedir() - { + public File getBasedir() { // create an isolated environment // see setupTestEnvironment for details - return new File( testRootDir ); + return new File(testRootDir); } - public Artifact getArtifact() - { + public Artifact getArtifact() { return artifact; } - public String getGroupId() - { + public String getGroupId() { String groupId = getModel().getGroupId(); - if ( ( groupId == null ) && ( getModel().getParent() != null ) ) - { + if ((groupId == null) && (getModel().getParent() != null)) { groupId = getModel().getParent().getGroupId(); } return groupId; } - public String getArtifactId() - { + public String getArtifactId() { return getModel().getArtifactId(); } - public String getPackaging() - { + public String getPackaging() { return "ejb"; } - public String getVersion() - { + public String getVersion() { return identifier; } - public void addProperty( String key, String value ) - { - properties.put( key, value ); + public void addProperty(String key, String value) { + properties.put(key, value); } - public Properties getProperties() - { + public Properties getProperties() { return properties; } // to prevent the MavenProject copy constructor from blowing up - private void initializeParentFields() - { + private void initializeParentFields() { // the pom should be located in the isolated dummy root - super.setFile( new File( getBasedir(), "pom.xml" ) ); - super.setDependencyArtifacts( Collections.<Artifact>emptySet() ); - super.setArtifacts( Collections.<Artifact>emptySet() ); - super.setExtensionArtifacts( Collections.<Artifact>emptySet() ); - super.setRemoteArtifactRepositories( Collections.<ArtifactRepository>emptyList() ); - super.setPluginArtifactRepositories( Collections.<ArtifactRepository>emptyList() ); - super.setCollectedProjects( Collections.<MavenProject>emptyList() ); - super.setActiveProfiles( Collections.<Profile>emptyList() ); - super.setOriginalModel( null ); - super.setExecutionProject( this ); - super.setArtifact( artifact ); + super.setFile(new File(getBasedir(), "pom.xml")); + super.setDependencyArtifacts(Collections.<Artifact>emptySet()); + super.setArtifacts(Collections.<Artifact>emptySet()); + super.setExtensionArtifacts(Collections.<Artifact>emptySet()); + super.setRemoteArtifactRepositories(Collections.<ArtifactRepository>emptyList()); + super.setPluginArtifactRepositories(Collections.<ArtifactRepository>emptyList()); + super.setCollectedProjects(Collections.<MavenProject>emptyList()); + super.setActiveProfiles(Collections.<Profile>emptyList()); + super.setOriginalModel(null); + super.setExecutionProject(this); + super.setArtifact(artifact); } } diff --git a/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBuildStub.java b/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBuildStub.java index fa54d03..44a64ce 100644 --- a/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBuildStub.java +++ b/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBuildStub.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb.stub; /* @@ -33,9 +51,7 @@ import org.codehaus.plexus.util.FileUtils; /** * Stub */ -public class MavenProjectBuildStub - extends MavenProjectBasicStub -{ +public class MavenProjectBuildStub extends MavenProjectBasicStub { public static final int RESOURCES_FILE = 1; public static final int ROOT_FILE = 2; @@ -76,10 +92,8 @@ public class MavenProjectBuildStub protected Map<String, String> dataMap; - public MavenProjectBuildStub( String key ) - throws Exception - { - super( key ); + public MavenProjectBuildStub(String key) throws Exception { + super(key); this.build = new Build(); this.resourcesFileList = new ArrayList<String>(); @@ -90,63 +104,52 @@ public class MavenProjectBuildStub this.dataMap = new HashMap<String, String>(); setupBuild(); - model.setBuild( build ); + model.setBuild(build); } - public void addDirectory( String name ) - { - if ( isValidPath( name ) ) - { - directoryList.add( name ); + public void addDirectory(String name) { + if (isValidPath(name)) { + directoryList.add(name); } } - public void setOutputDirectory( String dir ) - { + public void setOutputDirectory(String dir) { outputDirectory = buildDirectory + "/" + dir; - build.setOutputDirectory( outputDirectory ); + build.setOutputDirectory(outputDirectory); } - public void addFile( String name, int type ) - { - if ( isValidPath( name ) ) - { - List<String> list = getList( type ); + public void addFile(String name, int type) { + if (isValidPath(name)) { + List<String> list = getList(type); - list.add( name ); + list.add(name); } } - public void addFile( String name, String data, int type ) - { - File fileName = new File( name ); + public void addFile(String name, String data, int type) { + File fileName = new File(name); - addFile( name, type ); - dataMap.put( fileName.getName(), data ); + addFile(name, type); + dataMap.put(fileName.getName(), data); } - public String getOutputDirectory() - { + public String getOutputDirectory() { return outputDirectory; } - public String getTestOutputDirectory() - { + public String getTestOutputDirectory() { return testOutputDirectory; } - public String getResourcesDirectory() - { + public String getResourcesDirectory() { return resourcesDirectory; } - public String getTestResourcesDirectory() - { + public String getTestResourcesDirectory() { return testResourcesDirectory; } - public Build getBuild() - { + public Build getBuild() { return build; } @@ -156,20 +159,17 @@ public class MavenProjectBuildStub * @param path * @return */ - private boolean isValidPath( String path ) - { + private boolean isValidPath(String path) { boolean bRetVal = true; - if ( path.startsWith( "c:" ) || path.startsWith( ".." ) || path.startsWith( "/" ) || path.startsWith( "\\" ) ) - { + if (path.startsWith("c:") || path.startsWith("..") || path.startsWith("/") || path.startsWith("\\")) { bRetVal = false; } return bRetVal; } - private void setupBuild() - { + private void setupBuild() { // check getBasedir method for the exact path // we need to recreate the dir structure in // an isolated environment @@ -180,74 +180,62 @@ public class MavenProjectBuildStub resourcesDirectory = srcDirectory + "/main/resources/"; testResourcesDirectory = srcDirectory + "/test/resources/"; - build.setDirectory( buildDirectory ); - build.setOutputDirectory( outputDirectory ); - build.setTestOutputDirectory( testOutputDirectory ); + build.setDirectory(buildDirectory); + build.setOutputDirectory(outputDirectory); + build.setTestOutputDirectory(testOutputDirectory); } - public void setupBuildEnvironment() - throws Exception - { + public void setupBuildEnvironment() throws Exception { // populate dummy resources and dummy test resources // setup src dir - if ( !FileUtils.fileExists( resourcesDirectory ) ) - { - FileUtils.mkdir( resourcesDirectory ); + if (!FileUtils.fileExists(resourcesDirectory)) { + FileUtils.mkdir(resourcesDirectory); } - if ( !FileUtils.fileExists( testResourcesDirectory ) ) - { - FileUtils.mkdir( testResourcesDirectory ); + if (!FileUtils.fileExists(testResourcesDirectory)) { + FileUtils.mkdir(testResourcesDirectory); } - createDirectories( resourcesDirectory, testResourcesDirectory ); - createFiles( resourcesDirectory, testResourcesDirectory ); + createDirectories(resourcesDirectory, testResourcesDirectory); + createFiles(resourcesDirectory, testResourcesDirectory); setupRootFiles(); // setup target dir - if ( !FileUtils.fileExists( outputDirectory ) ) - { - FileUtils.mkdir( outputDirectory ); + if (!FileUtils.fileExists(outputDirectory)) { + FileUtils.mkdir(outputDirectory); } - if ( !FileUtils.fileExists( testOutputDirectory ) ) - { - FileUtils.mkdir( testOutputDirectory ); + if (!FileUtils.fileExists(testOutputDirectory)) { + FileUtils.mkdir(testOutputDirectory); } setupTargetFiles(); } - private void createDirectories( String parent, String testparent ) - { + private void createDirectories(String parent, String testparent) { File currentDirectory; - for ( Object aDirectoryList : directoryList ) - { - currentDirectory = new File( parent, "/" + aDirectoryList ); + for (Object aDirectoryList : directoryList) { + currentDirectory = new File(parent, "/" + aDirectoryList); - if ( !currentDirectory.exists() ) - { + if (!currentDirectory.exists()) { currentDirectory.mkdirs(); } // duplicate dir structure in test resources - currentDirectory = new File( testparent, "/" + aDirectoryList ); + currentDirectory = new File(testparent, "/" + aDirectoryList); - if ( !currentDirectory.exists() ) - { + if (!currentDirectory.exists()) { currentDirectory.mkdirs(); } } } - private List<String> getList( int type ) - { + private List<String> getList(int type) { List<String> retVal = null; - switch ( type ) - { + switch (type) { case SOURCE_FILE: retVal = sourceFileList; break; @@ -265,75 +253,59 @@ public class MavenProjectBuildStub return retVal; } - private void createFiles( String parent, int type ) - { + private void createFiles(String parent, int type) { File currentFile; - List<String> list = getList( type ); + List<String> list = getList(type); // guard - if ( list == null ) - { + if (list == null) { return; } - for ( String aList : list ) - { - currentFile = new File( parent, aList ); + for (String aList : list) { + currentFile = new File(parent, aList); // create the necessary parent directories // before we create the files - if ( !currentFile.getParentFile().exists() ) - { + if (!currentFile.getParentFile().exists()) { currentFile.getParentFile().mkdirs(); } - if ( !currentFile.exists() ) - { - try - { + if (!currentFile.exists()) { + try { currentFile.createNewFile(); - populateFile( currentFile, RESOURCES_FILE ); - } - catch ( IOException io ) - { + populateFile(currentFile, RESOURCES_FILE); + } catch (IOException io) { // TODO: handle exception } } } } - private void setupRootFiles() - { - createFiles( testRootDir, ROOT_FILE ); + private void setupRootFiles() { + createFiles(testRootDir, ROOT_FILE); } - private void setupTargetFiles() - { - createFiles( getOutputDirectory(), OUTPUT_FILE ); + private void setupTargetFiles() { + createFiles(getOutputDirectory(), OUTPUT_FILE); } - private void createFiles( String parent, String testparent ) - { - createFiles( parent, RESOURCES_FILE ); - createFiles( testparent, RESOURCES_FILE ); + private void createFiles(String parent, String testparent) { + createFiles(parent, RESOURCES_FILE); + createFiles(testparent, RESOURCES_FILE); } - private void populateFile( File file, int type ) - { + private void populateFile(File file, int type) { FileOutputStream outputStream; - String data = (String) dataMap.get( file.getName() ); - - if ( ( data != null ) && file.exists() ) - { - try - { - outputStream = new FileOutputStream( file ); - outputStream.write( data.getBytes() ); + String data = (String) dataMap.get(file.getName()); + + if ((data != null) && file.exists()) { + try { + outputStream = new FileOutputStream(file); + outputStream.write(data.getBytes()); outputStream.flush(); outputStream.close(); - } - catch ( IOException ex ) - { + } catch (IOException ex) { // TODO: handle exception here } } diff --git a/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectResourcesStub.java b/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectResourcesStub.java index 5984b03..125d8b4 100644 --- a/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectResourcesStub.java +++ b/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectResourcesStub.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb.stub; /* @@ -24,91 +42,75 @@ import org.apache.maven.model.Resource; /** * Stub */ -public class MavenProjectResourcesStub - extends MavenProjectBuildStub -{ - - public MavenProjectResourcesStub( String id ) - throws Exception - { - super( id ); +public class MavenProjectResourcesStub extends MavenProjectBuildStub { + + public MavenProjectResourcesStub(String id) throws Exception { + super(id); setupResources(); setupTestResources(); } - public void addInclude( String pattern ) - { - ( (Resource) build.getResources().get( 0 ) ).addInclude( pattern ); + public void addInclude(String pattern) { + ((Resource) build.getResources().get(0)).addInclude(pattern); } - public void addExclude( String pattern ) - { - ( (Resource) build.getResources().get( 0 ) ).addExclude( pattern ); + public void addExclude(String pattern) { + ((Resource) build.getResources().get(0)).addExclude(pattern); } - public void addTestInclude( String pattern ) - { - ( (Resource) build.getTestResources().get( 0 ) ).addInclude( pattern ); + public void addTestInclude(String pattern) { + ((Resource) build.getTestResources().get(0)).addInclude(pattern); } - public void addTestExclude( String pattern ) - { - ( (Resource) build.getTestResources().get( 0 ) ).addExclude( pattern ); + public void addTestExclude(String pattern) { + ((Resource) build.getTestResources().get(0)).addExclude(pattern); } - public void setTargetPath( String path ) - { - ( (Resource) build.getResources().get( 0 ) ).setTargetPath( path ); + public void setTargetPath(String path) { + ((Resource) build.getResources().get(0)).setTargetPath(path); } - public void setTestTargetPath( String path ) - { - ( (Resource) build.getTestResources().get( 0 ) ).setTargetPath( path ); + public void setTestTargetPath(String path) { + ((Resource) build.getTestResources().get(0)).setTargetPath(path); } - public void setDirectory( String dir ) - { - ( (Resource) build.getResources().get( 0 ) ).setDirectory( dir ); + public void setDirectory(String dir) { + ((Resource) build.getResources().get(0)).setDirectory(dir); } - public void setTestDirectory( String dir ) - { - ( (Resource) build.getTestResources().get( 0 ) ).setDirectory( dir ); + public void setTestDirectory(String dir) { + ((Resource) build.getTestResources().get(0)).setDirectory(dir); } - public void setResourceFiltering( int nIndex, boolean filter ) - { - if ( build.getResources().size() > nIndex ) - { - ( (Resource) build.getResources().get( nIndex ) ).setFiltering( filter ); + public void setResourceFiltering(int nIndex, boolean filter) { + if (build.getResources().size() > nIndex) { + ((Resource) build.getResources().get(nIndex)).setFiltering(filter); } } - private void setupResources() - { + private void setupResources() { Resource resource = new Resource(); // see MavenProjectBasicStub for details // of getBasedir // setup default resources - resource.setDirectory( getBasedir().getPath() + "/src/main/resources" ); - resource.setFiltering( false ); - resource.setTargetPath( null ); - build.addResource( resource ); + resource.setDirectory(getBasedir().getPath() + "/src/main/resources"); + resource.setFiltering(false); + resource.setTargetPath(null); + build.addResource(resource); } - private void setupTestResources() - { + private void setupTestResources() { Resource resource = new Resource(); // see MavenProjectBasicStub for details // of getBasedir // setup default test resources - resource.setDirectory( getBasedir().getPath() + "/src/test/resources" ); - resource.setFiltering( false ); - resource.setTargetPath( null ); - build.addTestResource( resource ); + resource.setDirectory(getBasedir().getPath() + "/src/test/resources"); + resource.setFiltering(false); + resource.setTargetPath(null); + build.addTestResource(resource); } } diff --git a/src/test/java/org/apache/maven/plugins/ejb/stub/ModelStub.java b/src/test/java/org/apache/maven/plugins/ejb/stub/ModelStub.java index b8d37b5..0fb3555 100644 --- a/src/test/java/org/apache/maven/plugins/ejb/stub/ModelStub.java +++ b/src/test/java/org/apache/maven/plugins/ejb/stub/ModelStub.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb.stub; /* @@ -30,62 +48,48 @@ import org.apache.maven.model.Profile; /** * Stub */ -public class ModelStub - extends Model -{ +public class ModelStub extends Model { /** - * + * */ private static final long serialVersionUID = -6823174384695495659L; - public ModelStub() - { - - } + public ModelStub() {} - public String getVersion() - { + public String getVersion() { return "0.0-TEST"; } - public String getModelVersion() - { + public String getModelVersion() { return "0.0-TEST"; } - public String getName() - { + public String getName() { return "Test Model"; } - public String getGroupId() - { + public String getGroupId() { return "org.apache.maven.test"; } - public String getPackaging() - { + public String getPackaging() { return "jar"; } - public Parent getParent() - { + public Parent getParent() { // return new Parent(); return null; } - public String getArtifactId() - { + public String getArtifactId() { return "maven-test-plugin"; } - public Properties getProperties() - { + public Properties getProperties() { return new Properties(); } - public List<Profile> getProfiles() - { + public List<Profile> getProfiles() { return new LinkedList<Profile>(); } } diff --git a/src/test/java/org/apache/maven/plugins/ejb/utils/JarContentChecker.java b/src/test/java/org/apache/maven/plugins/ejb/utils/JarContentChecker.java index 05749e5..a7e56ea 100644 --- a/src/test/java/org/apache/maven/plugins/ejb/utils/JarContentChecker.java +++ b/src/test/java/org/apache/maven/plugins/ejb/utils/JarContentChecker.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.plugins.ejb.utils; /* @@ -30,31 +48,26 @@ import java.util.jar.JarFile; /** * Jar Content Checker */ -public class JarContentChecker -{ - private final static Boolean FOUND = Boolean.TRUE; +public class JarContentChecker { + private static final Boolean FOUND = Boolean.TRUE; - private final static Boolean NOT_FOUND = Boolean.FALSE; + private static final Boolean NOT_FOUND = Boolean.FALSE; private Map<File, Boolean> fileMap; private Map<File, Boolean> directoryMap; - - public JarContentChecker() - { + public JarContentChecker() { fileMap = new HashMap<File, Boolean>(); directoryMap = new HashMap<File, Boolean>(); } - public void addDirectory( File dir ) - { - directoryMap.put( dir, NOT_FOUND ); + public void addDirectory(File dir) { + directoryMap.put(dir, NOT_FOUND); } - public void addFile( File file ) - { - fileMap.put( file, NOT_FOUND ); + public void addFile(File file) { + fileMap.put(file, NOT_FOUND); } /** @@ -65,8 +78,7 @@ public class JarContentChecker * @param jarFile the Jar file * @return boolean */ - public boolean isOK( JarFile jarFile ) - { + public boolean isOK(JarFile jarFile) { boolean bRetVal; Enumeration<JarEntry> zipentries = jarFile.entries(); JarEntry entry; @@ -74,24 +86,19 @@ public class JarContentChecker resetList(); - while ( zipentries.hasMoreElements() ) - { + while (zipentries.hasMoreElements()) { entry = zipentries.nextElement(); - entryFile = new File( entry.getName() ); + entryFile = new File(entry.getName()); - if ( entry.isDirectory() ) - { + if (entry.isDirectory()) { // cross out all files found in the jar file // found files with incorrect content will not // be counted - if ( directoryMap.containsKey( entryFile ) ) - { - directoryMap.put( entryFile, FOUND ); + if (directoryMap.containsKey(entryFile)) { + directoryMap.put(entryFile, FOUND); } - } - else if ( fileMap.containsKey( entryFile ) ) - { - fileMap.put( entryFile, FOUND ); + } else if (fileMap.containsKey(entryFile)) { + fileMap.put(entryFile, FOUND); } } @@ -100,26 +107,21 @@ public class JarContentChecker return bRetVal; } - private boolean checkFinalResult() - { + private boolean checkFinalResult() { boolean bRetVal = true; Iterator<File> keys = fileMap.keySet().iterator(); - while ( keys.hasNext() && bRetVal ) - { - if ( fileMap.get( keys.next() ).equals( NOT_FOUND ) ) - { + while (keys.hasNext() && bRetVal) { + if (fileMap.get(keys.next()).equals(NOT_FOUND)) { bRetVal = false; } } keys = directoryMap.keySet().iterator(); - while ( keys.hasNext() && bRetVal ) - { - if ( directoryMap.get( keys.next() ).equals( NOT_FOUND ) ) - { + while (keys.hasNext() && bRetVal) { + if (directoryMap.get(keys.next()).equals(NOT_FOUND)) { bRetVal = false; } } @@ -127,20 +129,17 @@ public class JarContentChecker return bRetVal; } - private void resetList() - { + private void resetList() { Iterator<File> keys = fileMap.keySet().iterator(); - while ( keys.hasNext() ) - { - fileMap.put( keys.next(), NOT_FOUND ); + while (keys.hasNext()) { + fileMap.put(keys.next(), NOT_FOUND); } keys = directoryMap.keySet().iterator(); - while ( keys.hasNext() ) - { - directoryMap.put( keys.next(), NOT_FOUND ); + while (keys.hasNext()) { + directoryMap.put(keys.next(), NOT_FOUND); } } }