Author: ptahchiev Date: Sun May 18 03:34:06 2008 New Revision: 657533 URL: http://svn.apache.org/viewvc?rev=657533&view=rev Log: improved the cactifywar mojo and also the shared-api.
Modified: jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyEarMojo.java jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/CactifyUtils.java jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/FilterRedirector.java Modified: jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyEarMojo.java URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyEarMojo.java?rev=657533&r1=657532&r2=657533&view=diff ============================================================================== --- jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyEarMojo.java (original) +++ jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyEarMojo.java Sun May 18 03:34:06 2008 @@ -1,9 +1,36 @@ +/* + * ======================================================================== + * + * 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.cactus.maven2.mojos; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; - +/** + * A maven2 mojo that injects elements necessary to run Cactus tests into an + * existing EAR file. + * + * @version $Id: CactifyEarMojo.java 394252 2008-04-29 04:20:17Z ptahchiev $ + * @goal cactifyear + * @requiresDependencyResolution compile + */ public class CactifyEarMojo extends AbstractMojo { Modified: jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java?rev=657533&r1=657532&r2=657533&view=diff ============================================================================== --- jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java (original) +++ jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java Sun May 18 03:34:06 2008 @@ -32,23 +32,31 @@ import org.apache.cactus.integration.api.cactify.CactifyUtils; import org.apache.maven.archiver.MavenArchiveConfiguration; import org.apache.maven.archiver.MavenArchiver; +import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.installer.ArtifactInstallationException; +import org.apache.maven.artifact.installer.ArtifactInstaller; +import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException; import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils; import org.apache.maven.project.MavenProject; +import org.apache.tools.ant.BuildException; import org.apache.tools.ant.types.XMLCatalog; import org.codehaus.cargo.container.internal.util.ResourceUtils; +import org.codehaus.cargo.maven2.log.MavenLogger; import org.codehaus.cargo.module.webapp.DefaultWarArchive; import org.codehaus.cargo.module.webapp.EjbRef; import org.codehaus.cargo.module.webapp.WarArchive; import org.codehaus.cargo.module.webapp.WebXml; import org.codehaus.cargo.module.webapp.WebXmlIo; import org.codehaus.cargo.module.webapp.WebXmlUtils; +import org.codehaus.cargo.module.webapp.WebXmlVersion; import org.codehaus.cargo.module.webapp.merge.WebXmlMerger; +import org.codehaus.cargo.util.log.Logger; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.ManifestException; import org.codehaus.plexus.archiver.manager.ArchiverManager; @@ -73,6 +81,13 @@ */ private static Random rand = new Random(System.currentTimeMillis() + Runtime.getRuntime().freeMemory()); + + /** + * Used to create artifacts + * + * @component + */ + private ArtifactFactory artifactFactory; /** * For resolving entities such as DTDs. @@ -155,6 +170,13 @@ * @plexus.requirement */ private ArtifactFactory factory; + + /** + * @parameter expression="${component.org.apache.maven.artifact.installer.ArtifactInstaller}" + * @required + * @readonly + */ + protected ArtifactInstaller installer; /** * The file that we want to produce. @@ -163,6 +185,58 @@ private File destFile; /** + * @parameter expression="${localRepository}" + * @required + * @readonly + */ + protected ArtifactRepository localRepository; + + + + /** + * GroupId of the artifact to be installed. Retrieved from POM file if specified. + * + * @parameter expression="${project.groupId}" + */ + protected String groupId; + + /** + * ArtifactId of the artifact to be installed. Retrieved from POM file if specified. + * + * @parameter expression="${project.artifactId}" + */ + protected String artifactId; + + /** + * Version of the artifact to be installed. Retrieved from POM file if specified + * + * @parameter expression="${project.version}" + */ + protected String projectVersion; + + /** + * Version of the artifact to be installed. Retrieved from POM file if specified + * + * @parameter expression="${project.version}" + */ + protected String version; + + /** + * Packaging type of the artifact to be installed. Retrieved from POM file if specified + * + * @parameter expression="${project.packaging}" + */ + protected String packaging; + + /** + * Classifier type of the artifact to be installed. For example, "sources" or "javadoc". + * Defaults to none which means this is the project's main jar. + * + * @parameter expression="${project.classifier}" + */ + protected String classifier; + + /** * The "main" method of the mojo. * @throws MojoExecutionException in case an error occurs. * @throws MojoFailureException in case a failure occurs. @@ -176,35 +250,83 @@ } WebXml webXml = null; - MavenArchiver archiver = new MavenArchiver(); - archiver.setArchiver( warArchiver ); - archiver.setOutputFile( destFile ); File tmpWebXml = null; + File tempLocation = null; try { - webXml = getOriginalWebXml(); + if (srcFile != null) + { + webXml = getOriginalWebXml(); + if (webXml == null) + { + if(this.version == null) + { + throw new MojoExecutionException("Your source file does not contain a web.xml. Please provide a war with" + + "a web.xml or specify the [version] attribute."); + } + WebXmlVersion webXmlVersion = null; + if (this.version.equals("2.2")) + { + webXmlVersion = WebXmlVersion.V2_2; + } + else if (this.version.equals("2.3")) + { + webXmlVersion = WebXmlVersion.V2_3; + } + else + { + webXmlVersion = WebXmlVersion.V2_4; + } + webXml = WebXmlIo.newWebXml(webXmlVersion); + } + } + else + { + if(this.version == null) + { + throw new MojoExecutionException("You need to specify either the " + + "[srcFile] or the [version] attribute"); + } + else + { + WebXmlVersion webXmlVersion = null; + if (this.version.equals("2.2")) + { + webXmlVersion = WebXmlVersion.V2_2; + } + else if (this.version.equals("2.3")) + { + webXmlVersion = WebXmlVersion.V2_3; + } + else + { + webXmlVersion = WebXmlVersion.V2_4; + } + webXml = WebXmlIo.newWebXml(webXmlVersion); + } + } tmpWebXml = cactifyWebXml(webXml); //Add the required libs for Cactus. - warArchiver.addLib(addJarWithClass("org.aspectj.lang.JoinPoint", - "AspectJ Runtime")); - warArchiver.addLib(addJarWithClass("org.apache.cactus." + - "ServletTestCase", "Cactus Framework")); - warArchiver.addLib(addJarWithClass("org.apache.commons.logging.Log", - "Commons-Logging")); - warArchiver.addLib(addJarWithClass("org.apache.commons." + - "httpclient.HttpClient", "Commons-HttpClient")); - warArchiver.addLib(addJarWithClass("junit.framework." + - "TestCase", "JUnit")); + addJarWithClass("org.aspectj.lang.JoinPoint", + "AspectJ Runtime"); + addJarWithClass("org.apache.cactus." + + "ServletTestCase", "Cactus Framework"); + addJarWithClass("org.apache.commons.logging.Log", + "Commons-Logging"); + addJarWithClass("org.apache.commons." + + "httpclient.HttpClient", "Commons-HttpClient"); + addJarWithClass("junit.framework." + + "TestCase", "JUnit"); - File tempLocation = createTempFile("cactus", "explode.tmp.dir", - getProject().getBasedir(), true); + tempLocation = createTempFile("cactus", "explode.tmp.dir", + getProject().getBasedir(), true); tempLocation.mkdirs(); tempLocation.deleteOnExit(); @@ -218,7 +340,8 @@ } try { - AssemblyFileUtils.unpack( this.srcFile, tempLocation, + if(this.srcFile != null) + AssemblyFileUtils.unpack( this.srcFile, tempLocation, archiverManager ); } catch (ArchiveExpansionException e) { throw new MojoExecutionException("Error extracting the" + @@ -230,8 +353,27 @@ warArchiver.addDirectory(tempLocation); warArchiver.setWebxml(tmpWebXml); archiver.createArchive( getProject(), getArchive() ); + + if(installLocally) + { + getLog().info("Installing "+destFile.getName()+" ..."); + Artifact artifact = + artifactFactory.createArtifactWithClassifier( groupId, artifactId, projectVersion, packaging, classifier ); + + String localPath = localRepository.pathOf( artifact ); + + File destination = new File( localRepository.getBasedir(), localPath ); + + getLog().info("!!!!!!!!"+destination.getAbsolutePath()); + + try { + installer.install(destFile, artifact, localRepository); + } catch (ArtifactInstallationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } - FileUtils.deleteDirectory(tempLocation); } catch (ArchiverException e) { @@ -258,6 +400,16 @@ throw new MojoExecutionException("Error resolving your " + "dependencies", e); } + finally + { + try { + if (tempLocation != null) + FileUtils.deleteDirectory(tempLocation); + } catch (IOException e) { + throw new MojoExecutionException("Error deleting temporary " + + "folder", e); + } + } } /** @@ -273,6 +425,7 @@ MojoExecutionException { CactifyUtils utils = new CactifyUtils(); + utils.setLogger(createLogger()); utils.addRedirectorDefinitions(theWebXml, redirectors); addJspRedirector(); addEjbRefs(theWebXml); @@ -418,6 +571,7 @@ * to the user in log messages */ private File addJarWithClass(String theClassName, String theDescription) + throws ArchiverException { String resourceName = "/" + theClassName.replace('.', '/') + ".class"; if (srcFile != null) @@ -426,10 +580,11 @@ { WarArchive srcWar = new DefaultWarArchive( new FileInputStream(srcFile)); + getLog().info("Inspecting.."); if (srcWar.containsClass(theClassName)) { - getLog().debug("The " + theDescription + " JAR is " + - "already present in the WAR"); + getLog().info("The " + theDescription + " JAR is " + + "already present in the WAR. Will skip."); return null; } } @@ -440,6 +595,13 @@ } } File file = utils.getResourceLocation(resourceName); + + if (file !=null) + { + getLog().info("Adding: "+file.getName()); + warArchiver.addLib(file); + } + return file; } @@ -501,4 +663,17 @@ { return archive; } + + /** + * Create a logger. If a <code><log></code> configuration element has been specified + * by the user then use it. If none is specified then log to the Maven 2 logging subsystem. + * + * @return the logger to use for logging this plugin's activity + */ + protected Logger createLogger() + { + Logger logger; + logger = new MavenLogger(getLog()); + return logger; + } } \ No newline at end of file Modified: jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/CactifyUtils.java URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/CactifyUtils.java?rev=657533&r1=657532&r2=657533&view=diff ============================================================================== --- jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/CactifyUtils.java (original) +++ jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/CactifyUtils.java Sun May 18 03:34:06 2008 @@ -11,6 +11,7 @@ import org.codehaus.cargo.module.webapp.WarArchive; import org.codehaus.cargo.module.webapp.WebXml; import org.codehaus.cargo.util.internal.log.AbstractLogger; +import org.codehaus.cargo.util.log.Logger; /** * Util class for cactifying purposes. @@ -25,7 +26,7 @@ /** * The abstract cargo logger used both by Ant and Maven2. */ - private AbstractLogger logger; + private Logger logger; /** @@ -106,7 +107,7 @@ * Getter method for the logger. * @return AbstractLogger */ - public AbstractLogger getLogger() { + public Logger getLogger() { return logger; } @@ -114,7 +115,7 @@ * Setter method for the logger. * @param logger */ - public void setLogger(AbstractLogger logger) { + public void setLogger(Logger logger) { this.logger = logger; } Modified: jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/FilterRedirector.java URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/FilterRedirector.java?rev=657533&r1=657532&r2=657533&view=diff ============================================================================== --- jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/FilterRedirector.java (original) +++ jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/FilterRedirector.java Sun May 18 03:34:06 2008 @@ -82,8 +82,9 @@ + this.name + " mapping. Cactus is adding another one " + "which may prevent your container from starting.", "WARNING"); } + WebXmlUtils.addFilter(theWebXml, this.name, FILTER_REDIRECTOR_CLASS); - + // WebXmlTag s = new WebXmlTag(theWebXml.getDescriptorType(), ""); @@ -104,7 +105,7 @@ filterMapping.setFilterName(this.name); - theWebXml.addTag(filterMapping); + //theWebXml.addTag(filterMapping); // // theWebXml.addTag(filterM); // --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]