You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jt...@apache.org on 2006/05/03 07:45:15 UTC
svn commit: r399152 - in /maven/plugins/trunk/maven-ejb-plugin: ./ src/test/
src/test/java/ src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/maven/ src/test/java/org/apache/maven/plugin/
src/test/java/org/apache/maven/plugin/ejb/ s...
Author: jtolentino
Date: Tue May 2 22:45:12 2006
New Revision: 399152
URL: http://svn.apache.org/viewcvs?rev=399152&view=rev
Log:
PR: MEJB-9
Submitted by: Pete Marvin King
Unit tests patch for maven-ear-plugin using the plugin testing harness.
Added:
maven/plugins/trunk/maven-ejb-plugin/src/test/
maven/plugins/trunk/maven-ejb-plugin/src/test/java/
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/EjbMojoTest.java
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/ArtifactStub.java
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectBasicStub.java
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectBuildStub.java
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectResourcesStub.java
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/ModelStub.java
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/utils/
maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/utils/JarContentChecker.java
maven/plugins/trunk/maven-ejb-plugin/src/test/resources/
maven/plugins/trunk/maven-ejb-plugin/src/test/resources/unit/
maven/plugins/trunk/maven-ejb-plugin/src/test/resources/unit/ejbmojotest/
maven/plugins/trunk/maven-ejb-plugin/src/test/resources/unit/ejbmojotest/plugin-config.xml
Modified:
maven/plugins/trunk/maven-ejb-plugin/pom.xml
Modified: maven/plugins/trunk/maven-ejb-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ejb-plugin/pom.xml?rev=399152&r1=399151&r2=399152&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-ejb-plugin/pom.xml Tue May 2 22:45:12 2006
@@ -25,5 +25,11 @@
<artifactId>maven-archiver</artifactId>
<version>2.0.1</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Added: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/EjbMojoTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/EjbMojoTest.java?rev=399152&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/EjbMojoTest.java (added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/EjbMojoTest.java Tue May 2 22:45:12 2006
@@ -0,0 +1,413 @@
+package org.apache.maven.plugin.ejb;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.File;
+import java.util.LinkedList;
+import java.util.jar.JarFile;
+
+import org.apache.maven.plugin.ejb.stub.MavenProjectResourcesStub;
+import org.apache.maven.plugin.ejb.utils.JarContentChecker;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+
+/**
+ * EJB plugin Test Case
+ */
+
+public class EjbMojoTest
+ extends AbstractMojoTestCase
+{
+ private static final String defaultPOMPath = "target/test-classes/unit/ejbmojotest/plugin-config.xml";
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+ }
+
+ public void tearDown()
+ throws Exception
+ {
+
+ }
+
+ /**
+ * check test environment
+ *
+ * @throws Exception
+ */
+ public void testTestEnvironment()
+ throws Exception
+ {
+ File pomFile = new File( getBasedir(), defaultPOMPath );
+ EjbMojo mojo = (EjbMojo) lookupMojo( "ejb", pomFile );
+
+ assertNotNull( mojo );
+ }
+
+ /**
+ * basic jar creation test
+ *
+ * @throws Exception
+ */
+ public void testJarCreation_WithoutClientJar()
+ throws Exception
+ {
+ File pomFile = new File( getBasedir(), defaultPOMPath );
+ EjbMojo mojo = (EjbMojo) lookupMojo( "ejb", pomFile );
+
+ assertNotNull( mojo );
+
+ // this will automatically create the isolated
+ // test environment
+ MavenProjectResourcesStub project = new MavenProjectResourcesStub( "jarCreation_WithoutClientJar" );
+
+ // create the necessary test files
+
+ // put this on the target dir
+ project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE );
+ // put this on the root dir
+ project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE );
+ // start creating the environment
+ project.setupBuildEnvironment();
+
+ // configure mojo
+ String jarName = "testJar";
+
+ setVariableValueToObject( mojo, "basedir", project.getBuild().getDirectory() );
+ setVariableValueToObject( mojo, "outputDirectory", project.getBuild().getOutputDirectory() );
+ setVariableValueToObject( mojo, "jarName", jarName );
+ setVariableValueToObject( mojo, "generateClient", "false" );
+ setVariableValueToObject( mojo, "clientExcludes", new LinkedList() );
+ setVariableValueToObject( mojo, "clientIncludes", new LinkedList() );
+ setVariableValueToObject( mojo, "project", project );
+
+ mojo.execute();
+
+ // validate jar creation
+ String checkedJarFile = project.getBuild().getDirectory() + "/" + jarName + ".jar";
+ String checkedClientJarFile = project.getBuild().getDirectory() + "/" + jarName + "-client.jar";
+
+ assertTrue( FileUtils.fileExists( checkedJarFile ) );
+ assertFalse( FileUtils.fileExists( checkedClientJarFile ) );
+ }
+
+ /**
+ * basic jar creation test with client jar
+ *
+ * @throws Exception
+ */
+ public void testJarCreation_WithClientJar()
+ throws Exception
+ {
+ File pomFile = new File( getBasedir(), defaultPOMPath );
+ EjbMojo mojo = (EjbMojo) lookupMojo( "ejb", pomFile );
+
+ assertNotNull( mojo );
+
+ // this will automatically create the isolated
+ // test environment
+ MavenProjectResourcesStub project = new MavenProjectResourcesStub( "jarCreation_WithClientJar" );
+
+ // set up test files
+
+ // put this on the target dir
+ project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE );
+ // put this on the root dir
+ project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE );
+ // start creating the environment
+ project.setupBuildEnvironment();
+
+ // configure mojo
+ String jarName = "testJar";
+
+ setVariableValueToObject( mojo, "basedir", project.getBuild().getDirectory() );
+ setVariableValueToObject( mojo, "outputDirectory", project.getBuild().getOutputDirectory() );
+ setVariableValueToObject( mojo, "jarName", jarName );
+ setVariableValueToObject( mojo, "generateClient", "true" );
+ setVariableValueToObject( mojo, "clientExcludes", new LinkedList() );
+ setVariableValueToObject( mojo, "clientIncludes", new LinkedList() );
+ setVariableValueToObject( mojo, "project", project );
+
+ mojo.execute();
+
+ // validate jar creation
+ String checkedJarFile = project.getBuild().getDirectory() + "/" + jarName + ".jar";
+ String checkedClientJarFile = project.getBuild().getDirectory() + "/" + jarName + "-client.jar";
+
+ assertTrue( FileUtils.fileExists( checkedJarFile ) );
+ assertTrue( FileUtils.fileExists( checkedClientJarFile ) );
+ }
+
+ /**
+ * default ejb jar inclusion and exclusion
+ *
+ * @throws Exception
+ */
+ public void testDefaultInclusionsExclusions()
+ throws Exception
+ {
+ File pomFile = new File( getBasedir(), defaultPOMPath );
+ EjbMojo mojo = (EjbMojo) lookupMojo( "ejb", pomFile );
+
+ assertNotNull( mojo );
+
+ // this will automatically create the isolated
+ // test environment
+ MavenProjectResourcesStub project = new MavenProjectResourcesStub( "defaultInclusionsExclusions" );
+
+ // 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 );
+
+ // put this on the root dir
+ project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE );
+
+ // start creating the environment
+ project.setupBuildEnvironment();
+
+ // set up test data
+ String jarName = "testJar";
+
+ setVariableValueToObject( mojo, "basedir", project.getBuild().getDirectory() );
+ setVariableValueToObject( mojo, "outputDirectory", project.getBuild().getOutputDirectory() );
+ setVariableValueToObject( mojo, "jarName", jarName );
+ setVariableValueToObject( mojo, "generateClient", "false" );
+ setVariableValueToObject( mojo, "clientExcludes", new LinkedList() );
+ setVariableValueToObject( mojo, "clientIncludes", new LinkedList() );
+ setVariableValueToObject( mojo, "project", project );
+
+ mojo.execute();
+
+ // validate jar creation
+ JarContentChecker inclusionChecker = new JarContentChecker();
+ String checkedJarFile = project.getBuild().getDirectory() + "/" + jarName + ".jar";
+
+ // set expected jar contents
+ inclusionChecker.addFile( new File( "META-INF/MANIFEST.MF" ) );
+ inclusionChecker.addFile( new File( "META-INF/ejb-jar.xml" ) );
+ inclusionChecker.addFile( new File( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) );
+ inclusionChecker.addFile( new File( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) );
+ inclusionChecker.addFile( new File( "org/sample/ejb/AppBean.class" ) );
+ inclusionChecker.addFile( new File( "org/sample/ejb/AppCMP.class" ) );
+ inclusionChecker.addFile( new File( "org/sample/ejb/AppSession.class" ) );
+
+ assertTrue( FileUtils.fileExists( checkedJarFile ) );
+ assertTrue( inclusionChecker.isOK( new JarFile( checkedJarFile ) ) );
+ }
+
+ /**
+ * client jar default inclusion and exclusion test
+ *
+ * @throws Exception
+ */
+ public void testClientJarDefaultInclusionsExclusions()
+ throws Exception
+ {
+ File pomFile = new File( getBasedir(), defaultPOMPath );
+ EjbMojo mojo = (EjbMojo) lookupMojo( "ejb", pomFile );
+
+ assertNotNull( mojo );
+
+ // this will automatically create the isolated
+ // test environment
+ MavenProjectResourcesStub project = new MavenProjectResourcesStub( "clientJarDefaultInclusionsExclusions" );
+
+ // 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 );
+
+ // put this on the root dir
+ project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE );
+
+ // start creating the environment
+ project.setupBuildEnvironment();
+
+ // set up test data
+ String jarName = "testJar";
+
+ setVariableValueToObject( mojo, "basedir", project.getBuild().getDirectory() );
+ setVariableValueToObject( mojo, "outputDirectory", project.getBuild().getOutputDirectory() );
+ setVariableValueToObject( mojo, "jarName", jarName );
+ setVariableValueToObject( mojo, "generateClient", "true" );
+ setVariableValueToObject( mojo, "clientExcludes", new LinkedList() );
+ setVariableValueToObject( mojo, "clientIncludes", new LinkedList() );
+ setVariableValueToObject( mojo, "project", project );
+
+ mojo.execute();
+
+ // validate jar creation
+ JarContentChecker inclusionChecker = new JarContentChecker();
+ JarContentChecker exclusionChecker = new JarContentChecker();
+ String checkedJarFile = project.getBuild().getDirectory() + "/" + jarName + "-client.jar";
+
+ // set expected jar contents
+ inclusionChecker.addFile( new File( "META-INF/MANIFEST.MF" ) );
+ inclusionChecker.addFile( new File( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) );
+ inclusionChecker.addFile( new File( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) );
+ inclusionChecker.addFile( new File( "org/sample/ejb/AppStub.class" ) );
+
+ // files not included
+ exclusionChecker.addFile( new File( "META-INF/ejb-jar.xml" ) );
+ exclusionChecker.addFile( new File( "org/sample/ejb/AppBean.class" ) );
+ exclusionChecker.addFile( new File( "org/sample/ejb/AppCMP.class" ) );
+ exclusionChecker.addFile( new File( "org/sample/ejb/AppSession.class" ) );
+
+ assertTrue( FileUtils.fileExists( checkedJarFile ) );
+ assertTrue( inclusionChecker.isOK( new JarFile( checkedJarFile ) ) );
+ assertFalse( exclusionChecker.isOK( new JarFile( checkedJarFile ) ) );
+ }
+
+ /**
+ * client jar inclusion test
+ *
+ * @throws Exception
+ */
+ public void testClientJarInclusions()
+ throws Exception
+ {
+ File pomFile = new File( getBasedir(), defaultPOMPath );
+ EjbMojo mojo = (EjbMojo) lookupMojo( "ejb", pomFile );
+
+ assertNotNull( mojo );
+
+ // this will automatically create the isolated
+ // test environment
+ MavenProjectResourcesStub project = new MavenProjectResourcesStub( "clientJarInclusions" );
+
+ // 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 );
+
+ // put this on the root dir
+ project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE );
+
+ // start creating the environment
+ project.setupBuildEnvironment();
+
+ // set up test data
+ String jarName = "testJar";
+ LinkedList inclusions = new LinkedList();
+
+ inclusions.add( "**/*Include.class" );
+
+ setVariableValueToObject( mojo, "basedir", project.getBuild().getDirectory() );
+ setVariableValueToObject( mojo, "outputDirectory", project.getBuild().getOutputDirectory() );
+ setVariableValueToObject( mojo, "jarName", jarName );
+ setVariableValueToObject( mojo, "generateClient", "true" );
+ setVariableValueToObject( mojo, "clientExcludes", new LinkedList() );
+ setVariableValueToObject( mojo, "clientIncludes", inclusions );
+ setVariableValueToObject( mojo, "project", project );
+
+ mojo.execute();
+
+ // validate jar creation
+ JarContentChecker inclusionChecker = new JarContentChecker();
+ JarContentChecker exclusionChecker = new JarContentChecker();
+ String checkedJarFile = project.getBuild().getDirectory() + "/" + jarName + "-client.jar";
+
+ // set expected jar contents
+ inclusionChecker.addFile( new File( "META-INF/MANIFEST.MF" ) );
+ inclusionChecker.addFile( new File( "org/sample/ejb/AppInclude.class" ) );
+
+ // read the packaging conventions first for this one
+ inclusionChecker.addFile( new File( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) );
+ inclusionChecker.addFile( new File( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) );
+
+ // files not included
+ exclusionChecker.addFile( new File( "META-INF/ejb-jar.xml" ) );
+ exclusionChecker.addFile( new File( "org/sample/ejb/AppExclude.class" ) );
+
+ assertTrue( FileUtils.fileExists( checkedJarFile ) );
+ assertTrue( inclusionChecker.isOK( new JarFile( checkedJarFile ) ) );
+ assertFalse( exclusionChecker.isOK( new JarFile( checkedJarFile ) ) );
+ }
+
+ /**
+ * client jar exclusions test
+ *
+ * @throws Exception
+ */
+ public void testClientJarExclusions()
+ throws Exception
+ {
+ File pomFile = new File( getBasedir(), defaultPOMPath );
+ EjbMojo mojo = (EjbMojo) lookupMojo( "ejb", pomFile );
+
+ assertNotNull( mojo );
+
+ // this will automatically create the isolated
+ // test environment
+ MavenProjectResourcesStub project = new MavenProjectResourcesStub( "clientJarExclusions" );
+
+ // 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 );
+
+ // put this on the root dir
+ project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE );
+
+ // start creating the environment
+ project.setupBuildEnvironment();
+
+ // set up test data
+ String jarName = "testJar";
+ LinkedList exclusions = new LinkedList();
+
+ exclusions.add( "**/*Exclude.class" );
+
+ setVariableValueToObject( mojo, "basedir", project.getBuild().getDirectory() );
+ setVariableValueToObject( mojo, "outputDirectory", project.getBuild().getOutputDirectory() );
+ setVariableValueToObject( mojo, "jarName", jarName );
+ setVariableValueToObject( mojo, "generateClient", "true" );
+ setVariableValueToObject( mojo, "clientExcludes", exclusions );
+ setVariableValueToObject( mojo, "clientIncludes", new LinkedList() );
+ setVariableValueToObject( mojo, "project", project );
+
+ mojo.execute();
+
+ // validate jar creation
+ JarContentChecker inclusionChecker = new JarContentChecker();
+ JarContentChecker exclusionChecker = new JarContentChecker();
+ String checkedJarFile = project.getBuild().getDirectory() + "/" + jarName + "-client.jar";
+
+ // set expected jar contents
+ inclusionChecker.addFile( new File( "META-INF/MANIFEST.MF" ) );
+ inclusionChecker.addFile( new File( "org/sample/ejb/AppInclude.class" ) );
+
+ // read the packaging conventions first for this one
+ inclusionChecker.addFile( new File( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) );
+ inclusionChecker.addFile( new File( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) );
+
+ // files not included
+ exclusionChecker.addFile( new File( "META-INF/ejb-jar.xml" ) );
+ exclusionChecker.addFile( new File( "org/sample/ejb/AppExclude.class" ) );
+
+ assertTrue( FileUtils.fileExists( checkedJarFile ) );
+ assertTrue( inclusionChecker.isOK( new JarFile( checkedJarFile ) ) );
+ assertFalse( exclusionChecker.isOK( new JarFile( checkedJarFile ) ) );
+ }
+}
Added: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/ArtifactStub.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/ArtifactStub.java?rev=399152&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/ArtifactStub.java (added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/ArtifactStub.java Tue May 2 22:45:12 2006
@@ -0,0 +1,329 @@
+package org.apache.maven.plugin.ejb.stub;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.File;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+
+/**
+ * Stub
+ */
+public class ArtifactStub
+ implements Artifact
+{
+
+ boolean hasClassifier;
+
+ boolean resolved;
+
+ boolean optional;
+
+ boolean release;
+
+ ArtifactHandler artifactHandler;
+
+ File file;
+
+ String baseVersion;
+
+ String type;
+
+ String classifier;
+
+ String identifier;
+
+ String dependencyConflictId;
+
+ String downloadUrl;
+
+ String selectedVersion;
+
+ String artifactId;
+
+ String groupId;
+
+ String resolvedVersion;
+
+ String scope;
+
+ String version;
+
+ VersionRange versionRange;
+
+
+ public ArtifactStub()
+ {
+ type = "testtype";
+ scope = "testscope";
+ classifier = "testclassifier";
+ artifactHandler = new DefaultArtifactHandler();
+ }
+
+ public void populate( MavenProjectBasicStub project )
+ {
+ groupId = project.getGroupId();
+ artifactId = project.getArtifactId();
+ version = project.getVersion();
+ versionRange = VersionRange.createFromVersion( version );
+ }
+
+ public boolean hasClassifier()
+ {
+ return true;
+ }
+
+ public String getBaseVersion()
+ {
+ return "Test Version";
+ }
+
+ public void setBaseVersion( String version )
+ {
+ baseVersion = version;
+ }
+
+ public void setFile( File _file )
+ {
+ file = _file;
+ }
+
+ public File getFile()
+ {
+ return new File( "testfile" );
+ }
+
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion( String _version )
+ {
+ version = _version;
+ }
+
+ public String getScope()
+ {
+ return scope;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public String getClassifier()
+ {
+ return classifier;
+ }
+
+ public String getId()
+ {
+ return identifier;
+ }
+
+ public String getDependencyConflictId()
+ {
+ return dependencyConflictId;
+ }
+
+ public void addMetadata( ArtifactMetadata metadata )
+ {
+
+ }
+
+ public Collection getMetadataList()
+ {
+ return new LinkedList();
+ }
+
+ public void setRepository( ArtifactRepository remoteRepository )
+ {
+
+ }
+
+ public ArtifactRepository getRepository()
+ {
+ return null;
+ }
+
+ public void updateVersion( String version, ArtifactRepository localRepository )
+ {
+
+ }
+
+ public String getDownloadUrl()
+ {
+ return downloadUrl;
+ }
+
+ public void setDownloadUrl( String _downloadUrl )
+ {
+ downloadUrl = _downloadUrl;
+ }
+
+ public ArtifactFilter getDependencyFilter()
+ {
+ return null;
+ }
+
+ public void setDependencyFilter( ArtifactFilter artifactFilter )
+ {
+
+ }
+
+ public ArtifactHandler getArtifactHandler()
+ {
+ return artifactHandler;
+ }
+
+ public List getDependencyTrail()
+ {
+ return new LinkedList();
+ }
+
+ public void setDependencyTrail( List dependencyTrail )
+ {
+
+ }
+
+ public void setScope( String _scope )
+ {
+ scope = _scope;
+ }
+
+ public VersionRange getVersionRange()
+ {
+ return versionRange;
+ }
+
+ public void setVersionRange( VersionRange newRange )
+ {
+
+ }
+
+ public void selectVersion( String version )
+ {
+ selectedVersion = version;
+ }
+
+ public void setGroupId( String _groupId )
+ {
+ groupId = _groupId;
+ }
+
+ public void setArtifactId( String _artifactId )
+ {
+ artifactId = _artifactId;
+ }
+
+ public boolean isSnapshot()
+ {
+ return true;
+ }
+
+ public void setResolved( boolean _resolved )
+ {
+ resolved = _resolved;
+ }
+
+ public boolean isResolved()
+ {
+ return true;
+ }
+
+ public void setResolvedVersion( String version )
+ {
+ resolvedVersion = version;
+ }
+
+
+ public void setArtifactHandler( ArtifactHandler handler )
+ {
+
+ }
+
+ public boolean isRelease()
+ {
+ return true;
+ }
+
+ public void setRelease( boolean _release )
+ {
+ release = _release;
+ }
+
+ public List getAvailableVersions()
+ {
+ return new LinkedList();
+ }
+
+ public void setAvailableVersions( List versions )
+ {
+
+ }
+
+ public boolean isOptional()
+ {
+ return true;
+ }
+
+ public void setOptional( boolean _optional )
+ {
+ optional = _optional;
+ }
+
+ public ArtifactVersion getSelectedVersion()
+ throws OverConstrainedVersionException
+ {
+ return null;
+ }
+
+ public boolean isSelectedVersionKnown()
+ throws OverConstrainedVersionException
+ {
+ return true;
+ }
+
+ public int compareTo( Object object )
+ {
+ return 0;
+ }
+}
Added: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectBasicStub.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectBasicStub.java?rev=399152&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectBasicStub.java (added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectBasicStub.java Tue May 2 22:45:12 2006
@@ -0,0 +1,163 @@
+package org.apache.maven.plugin.ejb.stub;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Properties;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Model;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Stub
+ */
+public class MavenProjectBasicStub
+ extends MavenProject
+{
+ protected String identifier;
+
+ protected String testRootDir;
+
+ protected Properties properties;
+
+ protected String description;
+
+ protected ModelStub model;
+
+ protected File file;
+
+ protected ArtifactStub artifact;
+
+ public MavenProjectBasicStub( String id )
+ throws Exception
+ {
+ // most values are hardcoded to have a controlled environment
+ super( new ModelStub() );
+
+ model = (ModelStub) getModel();
+ properties = new Properties();
+ artifact = new ArtifactStub();
+ identifier = id;
+
+ // set isolated root directory
+ testRootDir = PlexusTestCase.getBasedir() + "/target/test-classes/unit/test-dir/" + identifier;
+
+ if ( !FileUtils.fileExists( testRootDir ) )
+ {
+ FileUtils.mkdir( testRootDir );
+ }
+
+ artifact.populate( this );
+
+ // this is ugly but needed to ensure that the copy constructor
+ // works correctly
+ initializeParentFields();
+ }
+
+ public String getName()
+ {
+ return "Test Project " + identifier;
+ }
+
+ public void setDescription( String desc )
+ {
+ description = desc;
+ }
+
+ public Model getModel()
+ {
+ return model;
+ }
+
+ public String getDescription()
+ {
+ if ( description == null )
+ {
+ return "this is a test project";
+ }
+ else
+ {
+ return description;
+ }
+ }
+
+ public File getBasedir()
+ {
+ // create an isolated environment
+ // see setupTestEnvironment for details
+ return new File( testRootDir );
+ }
+
+ public Artifact getArtifact()
+ {
+ return artifact;
+ }
+
+ public String getGroupId()
+ {
+ return "org.apache.maven.plugin.test";
+ }
+
+ public String getArtifactId()
+ {
+ return "maven-resource-plugin-test#" + identifier;
+ }
+
+ public String getPackaging()
+ {
+ return "ejb";
+ }
+
+ public String getVersion()
+ {
+ return identifier;
+ }
+
+ public void addProperty( String key, String value )
+ {
+ properties.put( key, value );
+ }
+
+ public Properties getProperties()
+ {
+ return properties;
+ }
+
+ // to prevent the MavenProject copy constructor from blowing up
+ private void initializeParentFields()
+ {
+ // the pom should be located in the isolated dummy root
+ super.setFile( new File( getBasedir(), "pom.xml" ) );
+ super.setDependencyArtifacts( new HashSet() );
+ super.setArtifacts( new HashSet() );
+ super.setPluginArtifacts( new HashSet() );
+ super.setReportArtifacts( new HashSet() );
+ super.setExtensionArtifacts( new HashSet() );
+ super.setRemoteArtifactRepositories( new LinkedList() );
+ super.setPluginArtifactRepositories( new LinkedList() );
+ super.setCollectedProjects( new LinkedList() );
+ super.setActiveProfiles( new LinkedList() );
+ super.setOriginalModel( null );
+ super.setExecutionProject( this );
+ super.setArtifact( artifact );
+ }
+}
Added: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectBuildStub.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectBuildStub.java?rev=399152&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectBuildStub.java (added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectBuildStub.java Tue May 2 22:45:12 2006
@@ -0,0 +1,343 @@
+package org.apache.maven.plugin.ejb.stub;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.maven.model.Build;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Stub
+ */
+public class MavenProjectBuildStub
+ extends MavenProjectBasicStub
+{
+ public static final int RESOURCES_FILE = 1;
+
+ public static final int ROOT_FILE = 2;
+
+ public static final int OUTPUT_FILE = 3;
+
+ public static final int SOURCE_FILE = 4;
+
+ protected Build build;
+
+ protected String srcDirectory;
+
+ protected String targetDirectory;
+
+ protected String buildDirectory;
+
+ protected String outputDirectory;
+
+ protected String testOutputDirectory;
+
+ protected String resourcesDirectory;
+
+ protected String testResourcesDirectory;
+
+ protected String targetResourceDirectory;
+
+ protected String targetTestResourcesDirectory;
+
+ protected ArrayList targetClassesList;
+
+ protected ArrayList sourceFileList;
+
+ protected ArrayList resourcesFileList;
+
+ protected ArrayList rootFileList;
+
+ protected ArrayList directoryList;
+
+ protected HashMap dataMap;
+
+ public MavenProjectBuildStub( String key )
+ throws Exception
+ {
+ super( key );
+
+ build = new Build();
+ resourcesFileList = new ArrayList();
+ sourceFileList = new ArrayList();
+ rootFileList = new ArrayList();
+ directoryList = new ArrayList();
+ targetClassesList = new ArrayList();
+ dataMap = new HashMap();
+ setupBuild();
+ }
+
+ public void addDirectory( String name )
+ {
+ if ( isValidPath( name ) )
+ {
+ directoryList.add( name );
+ }
+ }
+
+ public void setOutputDirectory( String dir )
+ {
+ outputDirectory = buildDirectory + "/" + dir;
+ build.setOutputDirectory( outputDirectory );
+ }
+
+ public void addFile( String name, int type )
+ {
+ if ( isValidPath( name ) )
+ {
+ List list = getList( type );
+
+ list.add( name );
+ }
+ }
+
+ public void addFile( String name, String data, int type )
+ {
+ File fileName = new File( name );
+
+ addFile( name, type );
+ dataMap.put( fileName.getName(), data );
+ }
+
+ public String getOutputDirectory()
+ {
+ return outputDirectory;
+ }
+
+ public String getTestOutputDirectory()
+ {
+ return testOutputDirectory;
+ }
+
+ public String getResourcesDirectory()
+ {
+ return resourcesDirectory;
+ }
+
+ public String getTestResourcesDirectory()
+ {
+ return testResourcesDirectory;
+ }
+
+ public Build getBuild()
+ {
+ return build;
+ }
+
+ /**
+ * returns true if the path is relative
+ * and false if absolute
+ * also returns false if it is relative to
+ * the parent
+ *
+ * @param path
+ * @return
+ */
+ private boolean isValidPath( String path )
+ {
+ boolean bRetVal = true;
+
+ if ( path.startsWith( "c:" ) || path.startsWith( ".." ) || path.startsWith( "/" ) || path.startsWith( "\\" ) )
+ {
+ bRetVal = false;
+ }
+
+ return bRetVal;
+ }
+
+ private void setupBuild()
+ {
+ // check getBasedir method for the exact path
+ // we need to recreate the dir structure in
+ // an isolated environment
+ srcDirectory = testRootDir + "/src";
+ buildDirectory = testRootDir + "/target";
+ outputDirectory = buildDirectory + "/classes";
+ testOutputDirectory = buildDirectory + "/test-classes";
+ resourcesDirectory = srcDirectory + "/main/resources/";
+ testResourcesDirectory = srcDirectory + "/test/resources/";
+
+ build.setDirectory( buildDirectory );
+ build.setOutputDirectory( outputDirectory );
+ build.setTestOutputDirectory( testOutputDirectory );
+ }
+
+ 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( testResourcesDirectory ) )
+ {
+ FileUtils.mkdir( testResourcesDirectory );
+ }
+
+ createDirectories( resourcesDirectory, testResourcesDirectory );
+ createFiles( resourcesDirectory, testResourcesDirectory );
+ setupRootFiles();
+
+ // setup target dir
+ if ( !FileUtils.fileExists( outputDirectory ) )
+ {
+ FileUtils.mkdir( outputDirectory );
+ }
+
+ if ( !FileUtils.fileExists( testOutputDirectory ) )
+ {
+ FileUtils.mkdir( testOutputDirectory );
+ }
+
+ setupTargetFiles();
+ }
+
+ private void createDirectories( String parent, String testparent )
+ {
+ File currentDirectory;
+
+ for ( int nIndex = 0; nIndex < directoryList.size(); nIndex++ )
+ {
+ currentDirectory = new File( parent, "/" + (String) directoryList.get( nIndex ) );
+
+ if ( !currentDirectory.exists() )
+ {
+ currentDirectory.mkdirs();
+ }
+
+ // duplicate dir structure in test resources
+ currentDirectory = new File( testparent, "/" + (String) directoryList.get( nIndex ) );
+
+ if ( !currentDirectory.exists() )
+ {
+ currentDirectory.mkdirs();
+ }
+ }
+ }
+
+ private List getList( int type )
+ {
+ ArrayList retVal = null;
+
+ switch ( type )
+ {
+ case SOURCE_FILE :
+ retVal = sourceFileList;
+ break;
+ case OUTPUT_FILE :
+ retVal = targetClassesList;
+ break;
+ case RESOURCES_FILE :
+ retVal = resourcesFileList;
+ break;
+ case ROOT_FILE :
+ retVal = rootFileList;
+ break;
+ }
+
+ return retVal;
+ }
+
+ private void createFiles( String parent, int type )
+ {
+ File currentFile;
+ ArrayList list = (ArrayList) getList( type );
+
+ // guard
+ if ( list == null )
+ {
+ return;
+ }
+
+ for ( int nIndex = 0; nIndex < list.size(); nIndex++ )
+ {
+ currentFile = new File( parent, (String) list.get( nIndex ) );
+
+ // create the necessary parent directories
+ // before we create the files
+ if ( !currentFile.getParentFile().exists() )
+ {
+ currentFile.getParentFile().mkdirs();
+ }
+
+ if ( !currentFile.exists() )
+ {
+ try
+ {
+ currentFile.createNewFile();
+ populateFile( currentFile, RESOURCES_FILE );
+ }
+ catch ( IOException io )
+ {
+ //TODO: handle exception
+ }
+ }
+ }
+ }
+
+ private void setupRootFiles()
+ {
+ createFiles( testRootDir, ROOT_FILE );
+ }
+
+ private void setupTargetFiles()
+ {
+ createFiles( getOutputDirectory(), OUTPUT_FILE );
+ }
+
+ private void setupSourceFiles()
+ {
+ createFiles( srcDirectory, SOURCE_FILE );
+ }
+
+ private void createFiles( String parent, String testparent )
+ {
+ createFiles( parent, RESOURCES_FILE );
+ createFiles( testparent, RESOURCES_FILE );
+ }
+
+ private void populateFile( File file, int type )
+ {
+ FileOutputStream outputStream;
+ String data = 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 )
+ {
+ // TODO: handle exception here
+ }
+ }
+ }
+}
Added: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectResourcesStub.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectResourcesStub.java?rev=399152&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectResourcesStub.java (added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/MavenProjectResourcesStub.java Tue May 2 22:45:12 2006
@@ -0,0 +1,112 @@
+package org.apache.maven.plugin.ejb.stub;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.maven.model.Resource;
+
+
+/**
+ * Stub
+ */
+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 addExclude( String pattern )
+ {
+ ( (Resource) build.getResources().get( 0 ) ).addExclude( 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 setTargetPath( String path )
+ {
+ ( (Resource) build.getResources().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 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 );
+ }
+ }
+
+ 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 );
+ }
+
+ 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 );
+ }
+}
Added: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/ModelStub.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/ModelStub.java?rev=399152&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/ModelStub.java (added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/stub/ModelStub.java Tue May 2 22:45:12 2006
@@ -0,0 +1,87 @@
+package org.apache.maven.plugin.ejb.stub;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Parent;
+
+/**
+ * Stub
+ */
+public class ModelStub
+ extends Model
+{
+ public ModelStub()
+ {
+
+ }
+
+ public String getVersion()
+ {
+ return "0.0-TEST";
+ }
+
+ public String getModelVersion()
+ {
+ return "0.0-TEST";
+ }
+
+ public String getName()
+ {
+ return "Test Model";
+ }
+
+ public String getGroupId()
+ {
+ return "org.apache.maven.test";
+ }
+
+ public String getPackaging()
+ {
+ return "jar";
+ }
+
+ public Parent getParent()
+ {
+ //return new Parent();
+ return null;
+ }
+
+ public String getArtifactId()
+ {
+ return "maven-test-plugin";
+ }
+
+ public Properties getProperties()
+ {
+ return new Properties();
+ }
+
+ public List getPackages()
+ {
+ return new LinkedList();
+ }
+
+ public List getProfiles()
+ {
+ return new LinkedList();
+ }
+}
Added: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/utils/JarContentChecker.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/utils/JarContentChecker.java?rev=399152&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/utils/JarContentChecker.java (added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/utils/JarContentChecker.java Tue May 2 22:45:12 2006
@@ -0,0 +1,177 @@
+package org.apache.maven.plugin.ejb.utils;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+
+/**
+ * Jar Content Checker
+ */
+public class JarContentChecker
+{
+ private final static String FOUND = "1";
+
+ private final static String NOT_FOUND = "0";
+
+ private HashMap fileMap;
+
+ private HashMap directoryMap;
+
+ private HashMap dataMap;
+
+
+ public JarContentChecker()
+ {
+ fileMap = new HashMap();
+ directoryMap = new HashMap();
+ dataMap = new HashMap();
+ }
+
+ public void addDirectory( File dir )
+ {
+ directoryMap.put( dir, NOT_FOUND );
+ }
+
+ public void addFile( File file )
+ {
+ fileMap.put( file, NOT_FOUND );
+ }
+
+ public void addFile( String file, String data )
+ {
+ fileMap.put( file, NOT_FOUND );
+ dataMap.put( file, data );
+ }
+
+
+ /**
+ * checks whether the jar file contains the files for this checker,
+ * files with the same file name but with different data will not
+ * be considered.
+ *
+ * @param File
+ * @return boolean
+ */
+ public boolean isOK( JarFile jarFile )
+ {
+ boolean bRetVal = false;
+ Enumeration zipentries = jarFile.entries();
+ ZipEntry entry;
+ File entryFile;
+
+ resetList();
+
+ while ( zipentries.hasMoreElements() )
+ {
+ entry = (ZipEntry) zipentries.nextElement();
+ entryFile = new File( entry.getName() );
+
+ 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 );
+ }
+ }
+ else if ( fileMap.containsKey( entryFile ) )
+ {
+ try
+ {
+ if ( checkContent( entryFile, jarFile.getInputStream( entry ) ) )
+ {
+ fileMap.put( entryFile, FOUND );
+ }
+ }
+ catch ( IOException ex )
+ {
+ // TODO: handle exception
+ }
+ }
+ }
+
+ bRetVal = checkFinalResult();
+
+ return bRetVal;
+ }
+
+
+ private boolean checkContent( File file, InputStream istream )
+ {
+ boolean bRetVal = true;
+
+ if ( dataMap.containsKey( file ) )
+ {
+ // TODO: do content checking here
+ }
+
+ return bRetVal;
+ }
+
+ private boolean checkFinalResult()
+ {
+ boolean bRetVal = true;
+
+ Iterator keys = fileMap.keySet().iterator();
+
+ 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 ) )
+ {
+ bRetVal = false;
+ }
+ }
+
+ return bRetVal;
+ }
+
+ private void resetList()
+ {
+ Iterator keys = fileMap.keySet().iterator();
+
+ while ( keys.hasNext() )
+ {
+ fileMap.put( keys.next(), NOT_FOUND );
+ }
+
+ keys = directoryMap.keySet().iterator();
+
+ while ( keys.hasNext() )
+ {
+ directoryMap.put( keys.next(), NOT_FOUND );
+ }
+ }
+}
Added: maven/plugins/trunk/maven-ejb-plugin/src/test/resources/unit/ejbmojotest/plugin-config.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-ejb-plugin/src/test/resources/unit/ejbmojotest/plugin-config.xml?rev=399152&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/test/resources/unit/ejbmojotest/plugin-config.xml (added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/test/resources/unit/ejbmojotest/plugin-config.xml Tue May 2 22:45:12 2006
@@ -0,0 +1,11 @@
+<project>
+ <name>ejb-plugin-test</name>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-ejb-plugin</artifactId>
+ <configuration></configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>