tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1163136 [2/5] - in /tomcat/maven-plugin/trunk: ./ src/ src/site/ tomcat-maven-plugin-it/ tomcat-maven-plugin-it/src/ tomcat-maven-plugin-it/src/test/ tomcat-maven-plugin-it/src/test/java/ tomcat-maven-plugin-it/src/test/java/org/ tomcat-ma...
Date Tue, 30 Aug 2011 08:31:36 GMT
Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/tomcat-run-multi-config/src/test/java/WaitIT.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/tomcat-run-multi-config/src/test/java/WaitIT.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/tomcat-run-multi-config/src/test/java/WaitIT.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/tomcat-run-multi-config/src/test/java/WaitIT.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,30 @@
+import org.junit.Test;
+
+/*
+ * 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.
+ */
+
+
+@SuppressWarnings({"WrongPackageStatement"})
+public final class WaitIT {
+  @Test
+  public void testWait() throws Exception {
+    System.out.println("Just wait a while...");
+    Thread.sleep(${it.sleep.time});
+  }
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/pom.xml
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/pom.xml?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/pom.xml (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/pom.xml Tue Aug 30 08:31:33 2011
@@ -0,0 +1,107 @@
+<?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
+  ~ 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.
+  -->
+<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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.codehaus.mojo.tomcat.it</groupId>
+  <artifactId>usage-contextpath</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>war</packaging>
+  <properties>
+    <pluginVersion>${project.version}</pluginVersion>
+    <maven.compiler.source>${maven.compiler.source}</maven.compiler.source>
+    <maven.compiler.target>${maven.compiler.target}</maven.compiler.target>
+    <project.build.sourceEncoding>${project.build.sourceEncoding}</project.build.sourceEncoding>
+    <failOnMissingWebXml>false</failOnMissingWebXml>
+  </properties>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.codehaus.mojo</groupId>
+          <artifactId>tomcat-maven-plugin</artifactId>
+          <version>${project.version}</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>tomcat-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>tomcat-run</id>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <phase>pre-integration-test</phase>
+            <configuration>
+              <fork>true</fork>
+              <path>/lorem</path>
+            </configuration>
+          </execution>
+          <execution>
+            <id>tomcat-shutdown</id>
+            <goals>
+              <goal>shutdown</goal>
+            </goals>
+            <phase>post-integration-test</phase>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-failsafe-plugin</artifactId>
+        <version>${failsafe.version}</version>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <goals>
+              <goal>integration-test</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>verify</id>
+            <goals>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context-support</artifactId>
+      <version>2.5.6</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junit.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/src/main/webapp/index.html?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/src/main/webapp/index.html (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/src/main/webapp/index.html Tue Aug 30 08:31:33 2011
@@ -0,0 +1,29 @@
+<!--
+  ~ 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.
+  -->
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+        "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+    <title>Usage-Example: Contextpath</title>
+</head>
+<body>
+Success!
+</body>
+</html>

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/src/test/java/WaitIT.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/src/test/java/WaitIT.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/src/test/java/WaitIT.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/project-resources/usage-contextpath/src/test/java/WaitIT.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,31 @@
+import org.junit.Test;
+
+/*
+ * 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.
+ */
+
+
+
+@SuppressWarnings({"WrongPackageStatement"})
+public final class WaitIT {
+  @Test
+  public void testWait() throws Exception {
+    System.out.println("Just wait a while...");
+    Thread.sleep(${it.sleep.time});
+  }
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/resources/logback-test.xml
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/resources/logback-test.xml?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/resources/logback-test.xml (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin-it/src/test/resources/logback-test.xml Tue Aug 30 08:31:33 2011
@@ -0,0 +1,34 @@
+<!--
+  ~ 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.
+  -->
+
+<configuration>
+
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <!-- encoders are assigned the type
+         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+    <encoder>
+      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+    </encoder>
+  </appender>
+
+  <root level="debug">
+    <appender-ref ref="STDOUT"/>
+  </root>
+  
+</configuration>

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/pom.xml?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/pom.xml (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/pom.xml Tue Aug 30 08:31:33 2011
@@ -0,0 +1,176 @@
+<!--
+  ~ 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.
+  -->
+
+<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">
+  <parent>
+    <groupId>org.codehaus.mojo</groupId>
+    <artifactId>tomcat-maven-plugin-parent</artifactId>
+    <version>1.2-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>tomcat-maven-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <name>Tomcat Maven Plugin</name>
+  <description>The Tomcat Maven Plugin provides goals to manipulate WAR projects within the Tomcat servlet
+    container.
+  </description>
+
+  <prerequisites>
+    <maven>${mavenVersion}</maven>
+  </prerequisites>
+  <inceptionYear>2005</inceptionYear>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact-manager</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-provider-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-archiver</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-classworlds</artifactId>
+    </dependency>
+
+    <!-- tomcat dependencies -->
+
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>catalina</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>catalina-ha</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>tribes</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>el-api</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>jasper</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jdt.core.compiler</groupId>
+      <artifactId>ecj</artifactId>
+    </dependency>    
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>jasper-el</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>jsp-api</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>servlet-api</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>coyote</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>dbcp</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-component-metadata</artifactId>
+        <version>1.5.1</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>generate-metadata</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <reporting>
+    <plugins>
+      <plugin>
+        <artifactId>maven-pmd-plugin</artifactId>
+        <version>2.4</version>
+        <configuration>
+          <targetJdk>${compileSource}</targetJdk>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-plugin-plugin</artifactId>
+        <version>2.5</version>
+        <configuration>
+          <requirements>
+            <jdk>${maven.compiler.target}</jdk>
+          </requirements>
+        </configuration>
+      </plugin>
+    </plugins>
+  </reporting>
+
+</project>

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractCatalinaMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractCatalinaMojo.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractCatalinaMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractCatalinaMojo.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,275 @@
+package org.codehaus.mojo.tomcat;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.StringTokenizer;
+
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Abstract goal that provides common configuration for Catalina-based goals.
+ * 
+ * @author Mark Hobson <markhobson@gmail.com>
+ * @version $Id: AbstractCatalinaMojo.java 12852 2010-10-12 22:04:32Z thragor $
+ */
+public abstract class AbstractCatalinaMojo
+    extends AbstractI18NMojo
+{
+    // ----------------------------------------------------------------------
+    // Constants
+    // ----------------------------------------------------------------------
+
+    /**
+     * The name of this Maven plugin. Used to produce the user agent when communicating with Tomcat manager.
+     */
+    private String name = "Tomcat Maven Plugin";
+
+    /**
+     * The default username to use when authenticating with Tomcat manager.
+     */
+    private static final String DEFAULT_USERNAME = "admin";
+
+    /**
+     * The default password to use when authenticating with Tomcat manager.
+     */
+    private static final String DEFAULT_PASSWORD = "";
+
+    // ----------------------------------------------------------------------
+    // Mojo Parameters
+    // ----------------------------------------------------------------------
+
+    /**
+     * The Maven Wagon manager to use when obtaining server authentication details.
+     * 
+     * @component role="org.apache.maven.artifact.manager.WagonManager"
+     * @required
+     * @readonly
+     */
+    private WagonManager wagonManager;
+
+    /**
+     * The full URL of the Tomcat manager instance to use.
+     * 
+     * @parameter expression="${maven.tomcat.url}" default-value="http://localhost:8080/manager"
+     * @required
+     */
+    private URL url;
+
+    /**
+     * The server id in settings.xml to use when authenticating with Tomcat manager, or <code>null</code> to use
+     * defaults of username <code>admin</code> and no password.
+     * 
+     * @parameter expression="${maven.tomcat.server}"
+     */
+    private String server;
+
+    /**
+     * The URL encoding charset to use when communicating with Tomcat manager.
+     * 
+     * @parameter expression="${maven.tomcat.charset}" default-value="ISO-8859-1"
+     * @required
+     */
+    private String charset;
+
+    /**
+     * The tomcat username to use for deployment
+     * 
+     * @parameter expression="${tomcat.username}"
+     * @since 1.0-alpha-2
+     */
+    private String username;
+
+    /**
+     * The password to use for deployment
+     * 
+     * @parameter expression="${tomcat.password}"
+     * @since 1.0-alpha-2
+     */
+    private String password;
+
+    /**
+     * @parameter expression="${plugin.version}"
+     * @required
+     * @readonly
+     */
+    private String version;
+
+    // ----------------------------------------------------------------------
+    // Fields
+    // ----------------------------------------------------------------------
+
+    /**
+     * The Tomcat manager wrapper object.
+     */
+    private TomcatManager manager;
+
+    // ----------------------------------------------------------------------
+    // Mojo Implementation
+    // ----------------------------------------------------------------------
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute()
+        throws MojoExecutionException
+    {
+        try
+        {
+            invokeManager();
+        }
+        catch ( TomcatManagerException exception )
+        {
+            throw new MojoExecutionException( getMessage( "AbstractCatalinaMojo.managerError", exception.getMessage() ) );
+        }
+        catch ( IOException exception )
+        {
+            throw new MojoExecutionException( getMessage( "AbstractCatalinaMojo.managerIOError" ), exception );
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    // Protected Methods
+    // ----------------------------------------------------------------------
+
+    /**
+     * Invokes Tomcat manager when this Mojo is executed.
+     * 
+     * @throws MojoExecutionException if there was a problem executing this goal
+     * @throws TomcatManagerException if the Tomcat manager request fails
+     * @throws IOException if an i/o error occurs
+     */
+    protected abstract void invokeManager()
+        throws MojoExecutionException, TomcatManagerException, IOException;
+
+    /**
+     * Gets the Tomcat manager wrapper object configured for this goal.
+     * 
+     * @return the Tomcat manager wrapper object
+     * @throws MojoExecutionException if there was a problem obtaining the authentication details
+     */
+    protected TomcatManager getManager()
+        throws MojoExecutionException
+    {
+        // lazily instantiate when config values have been injected
+        if ( manager == null )
+        {
+            String userName;
+            String password;
+
+            if ( server == null )
+            {
+                // no server set, use defaults
+                getLog().debug( getMessage( "AbstractCatalinaMojo.defaultAuth" ) );
+                userName = DEFAULT_USERNAME;
+                password = DEFAULT_PASSWORD;
+            }
+            else
+            {
+                // obtain authenication details for specified server from wagon
+                AuthenticationInfo info = wagonManager.getAuthenticationInfo( server );
+                if ( info == null )
+                {
+                    throw new MojoExecutionException( getMessage( "AbstractCatalinaMojo.unknownServer", server ) );
+                }
+
+                // derive username
+                userName = info.getUserName();
+                if ( userName == null )
+                {
+                    getLog().debug( getMessage( "AbstractCatalinaMojo.defaultUserName" ) );
+                    userName = DEFAULT_USERNAME;
+                }
+
+                // derive password
+                password = info.getPassword();
+                if ( password == null )
+                {
+                    getLog().debug( getMessage( "AbstractCatalinaMojo.defaultPassword" ) );
+                    password = DEFAULT_PASSWORD;
+                }
+            }
+
+            // if userName/password are defined in the mojo or the cli they override
+            if ( !StringUtils.isEmpty( this.username ) )
+            {
+                userName = this.username;
+                password = this.password == null ? "" : this.password;
+            }
+
+            manager = new TomcatManager( url, userName, password, charset );
+            manager.setUserAgent( name + "/" + version );
+        }
+
+        return manager;
+    }
+
+    /**
+     * Gets the full URL of the Tomcat manager instance.
+     * 
+     * @return the full URL of the Tomcat manager instance to use
+     */
+    protected URL getURL()
+    {
+        return url;
+    }
+
+    /**
+     * Gets the webapp context path to use when communicating with Tomcat manager.
+     * 
+     * @return the webapp context path to use
+     */
+    protected String getPath()
+    {
+        return path;
+    }
+
+    /**
+     * Gets the URL of the deployed webapp.
+     * 
+     * @return the URL of the deployed webapp
+     * @throws MalformedURLException if the deployed webapp URL is invalid
+     */
+    protected URL getDeployedURL()
+        throws MalformedURLException
+    {
+        return new URL( getURL(), getPath() );
+    }
+
+    /**
+     * Splits the given string into lines and writes each one separately to the log at info level.
+     * 
+     * @param string the string to write
+     */
+    protected void log( String string )
+    {
+        StringTokenizer tokenizer = new StringTokenizer( string, "\n\r" );
+
+        while ( tokenizer.hasMoreTokens() )
+        {
+            getLog().info( tokenizer.nextToken() );
+        }
+    }
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractDeployMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractDeployMojo.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractDeployMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractDeployMojo.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,215 @@
+package org.codehaus.mojo.tomcat;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Deploy a WAR to Tomcat.
+ * 
+ * @author Mark Hobson <markhobson@gmail.com>
+ * @version $Id: AbstractDeployMojo.java 12852 2010-10-12 22:04:32Z thragor $
+ */
+public abstract class AbstractDeployMojo
+    extends AbstractWarCatalinaMojo
+{
+    // ----------------------------------------------------------------------
+    // Mojo Parameters
+    // ----------------------------------------------------------------------
+
+    /**
+     * The deployment mode to use. This must be either <code>war</code> to deploy the war, <code>context</code> to
+     * deploy the context XML file, or <code>both</code> to deploy the war with the context XML file.
+     * 
+     * @parameter expression = "${maven.tomcat.mode}" default-value = "war"
+     * @required
+     */
+    private String mode;
+
+    /**
+     * The path of the Tomcat context XML file. This is not used for war deployment mode.
+     * 
+     * @parameter expression = "${project.build.directory}/${project.build.finalName}/META-INF/context.xml"
+     */
+    private File contextFile;
+
+    /**
+     * Whether Tomcat should automatically undeploy webapps that already exist when deploying.
+     * 
+     * @parameter expression = "${maven.tomcat.update}" default-value = "false"
+     * @required
+     */
+    private boolean update;
+
+    /**
+     * The Tomcat webapp tag name to use.
+     * 
+     * @parameter expression = "${maven.tomcat.tag}"
+     */
+    private String tag;
+
+    // ----------------------------------------------------------------------
+    // Protected Methods
+    // ----------------------------------------------------------------------
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void invokeManager()
+        throws MojoExecutionException, TomcatManagerException, IOException
+    {
+        if ( "war".equals( mode ) )
+        {
+            deployWar();
+        }
+        else if ( "context".equals( mode ) )
+        {
+            deployContext();
+        }
+        else if ( "both".equals( mode ) )
+        {
+            deployWarAndContext();
+        }
+        else
+        {
+            throw new MojoExecutionException( getMessage( "AbstractDeployMojo.unknownMode", mode ) );
+        }
+    }
+
+    /**
+     * Gets the Tomcat WAR file. This may be a file or a directory depending on the deployment mode.
+     * 
+     * @return the Tomcat WAR file.
+     */
+    protected abstract File getWarFile();
+
+    /**
+     * Ensures that the Tomcat WAR file exists and is the correct type for the deployment mode.
+     * 
+     * @throws MojoExecutionException if the WAR file does not exist or is not the correct type for the deployment mode
+     */
+    protected abstract void validateWarFile()
+        throws MojoExecutionException;
+
+    /**
+     * Gets the Tomcat context XML file.
+     * 
+     * @return the Tomcat context XML file.
+     */
+    protected File getContextFile()
+    {
+        return contextFile;
+    }
+
+    /**
+     * Ensures that the Tomcat context XML file exists and is indeed a file.
+     * 
+     * @throws MojoExecutionException if the context file does not exist or is not a file
+     */
+    protected void validateContextFile()
+        throws MojoExecutionException
+    {
+        if ( !contextFile.exists() || !contextFile.isFile() )
+        {
+            throw new MojoExecutionException( getMessage( "AbstractDeployMojo.missingContext", contextFile.getPath() ) );
+        }
+    }
+
+    /**
+     * Gets whether Tomcat should automatically undeploy webapps that already exist when deploying.
+     * 
+     * @return whether Tomcat should automatically undeploy webapps that already exist when deploying
+     */
+    protected boolean isUpdate()
+    {
+        return update;
+    }
+
+    /**
+     * Gets the Tomcat webapp tag name to use.
+     * 
+     * @return the Tomcat webapp tag name to use
+     */
+    protected String getTag()
+    {
+        return tag;
+    }
+
+    /**
+     * Deploys the WAR to Tomcat.
+     * 
+     * @throws MojoExecutionException if there was a problem locating the WAR
+     * @throws TomcatManagerException if the Tomcat manager request fails
+     * @throws IOException if an i/o error occurs
+     */
+    protected void deployWar()
+        throws MojoExecutionException, TomcatManagerException, IOException
+    {
+        validateWarFile();
+
+        getLog().info( getMessage( "AbstractDeployMojo.deployingWar", getDeployedURL() ) );
+
+        URL warURL = getWarFile().toURL();
+        log( getManager().deploy( getPath(), warURL, isUpdate(), getTag() ) );
+    }
+
+    /**
+     * Deploys the context XML file to Tomcat.
+     * 
+     * @throws MojoExecutionException if there was a problem locating the context XML file
+     * @throws TomcatManagerException if the Tomcat manager request fails
+     * @throws IOException if an i/o error occurs
+     */
+    protected void deployContext()
+        throws MojoExecutionException, TomcatManagerException, IOException
+    {
+        validateContextFile();
+
+        getLog().info( getMessage( "AbstractDeployMojo.deployingContext", getDeployedURL() ) );
+
+        URL contextURL = getContextFile().toURL();
+        log( getManager().deployContext( getPath(), contextURL, isUpdate(), getTag() ) );
+    }
+
+    /**
+     * Deploys the WAR and context XML file to Tomcat.
+     * 
+     * @throws MojoExecutionException if there was a problem locating either the WAR or the context XML file
+     * @throws TomcatManagerException if the Tomcat manager request fails
+     * @throws IOException if an i/o error occurs
+     */
+    protected void deployWarAndContext()
+        throws MojoExecutionException, TomcatManagerException, IOException
+    {
+        validateWarFile();
+        validateContextFile();
+
+        getLog().info( getMessage( "AbstractDeployMojo.deployingWarContext", getDeployedURL() ) );
+
+        URL warURL = getWarFile().toURL();
+        URL contextURL = getContextFile().toURL();
+        log( getManager().deployContext( getPath(), contextURL, warURL, isUpdate(), getTag() ) );
+    }
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractDeployWarMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractDeployWarMojo.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractDeployWarMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractDeployWarMojo.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,87 @@
+package org.codehaus.mojo.tomcat;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * @author olamy
+ * @version $Id: AbstractDeployWarMojo.java 12852 2010-10-12 22:04:32Z thragor $
+ * @since 1.0-alpha-2
+ */
+public class AbstractDeployWarMojo
+    extends AbstractDeployMojo
+{
+    // ----------------------------------------------------------------------
+    // Mojo Parameters
+    // ----------------------------------------------------------------------
+
+    /**
+     * The path of the WAR file to deploy.
+     * 
+     * @parameter expression = "${project.build.directory}/${project.build.finalName}.war"
+     * @required
+     */
+    private File warFile;
+
+    // ----------------------------------------------------------------------
+    // Protected Methods
+    // ----------------------------------------------------------------------
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected File getWarFile()
+    {
+        return warFile;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void validateWarFile()
+        throws MojoExecutionException
+    {
+        if ( !warFile.exists() || !warFile.isFile() )
+        {
+            throw new MojoExecutionException( getMessage( "DeployMojo.missingWar", warFile.getPath() ) );
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void deployWar()
+        throws MojoExecutionException, TomcatManagerException, IOException
+    {
+        validateWarFile();
+
+        getLog().info( getMessage( "AbstractDeployMojo.deployingWar", getDeployedURL() ) );
+
+        log( getManager().deploy( getPath(), new FileInputStream( warFile ), isUpdate(), getTag() ) );
+    }
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractI18NMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractI18NMojo.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractI18NMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractI18NMojo.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,139 @@
+package org.codehaus.mojo.tomcat;
+
+/*
+ * 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.
+ */
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.apache.maven.plugin.AbstractMojo;
+
+/**
+ * Abstract goal that provides i18n support.
+ * 
+ * @author Mark Hobson <markhobson@gmail.com>
+ * @version $Id: AbstractI18NMojo.java 12852 2010-10-12 22:04:32Z thragor $
+ */
+public abstract class AbstractI18NMojo
+    extends AbstractMojo
+{
+    // ----------------------------------------------------------------------
+    // Mojo Parameters
+    // ----------------------------------------------------------------------
+
+    /**
+     * The webapp context path to use for the web application being run. This must always start with a forward-slash
+     * ('/').
+     * 
+     * @parameter expression="${maven.tomcat.path}" default-value="/${project.artifactId}"
+     * @required
+     */
+    protected String path;
+
+    // ----------------------------------------------------------------------
+    // Fields
+    // ----------------------------------------------------------------------
+
+    /**
+     * The plugin messages.
+     */
+    private ResourceBundle messages;
+
+    // ----------------------------------------------------------------------
+    // Constructors
+    // ----------------------------------------------------------------------
+
+    /**
+     * Creates a new <code>AbstractI18NMojo</code>.
+     */
+    public AbstractI18NMojo()
+    {
+        String packageName = getClass().getPackage().getName();
+
+        messages = ResourceBundle.getBundle( packageName + ".messages" );
+    }
+
+    // ----------------------------------------------------------------------
+    // Protected Methods
+    // ----------------------------------------------------------------------
+
+    /**
+     * Gets the message for the given key from this packages resource bundle.
+     * 
+     * @param key the key for the required message
+     * @return the message
+     */
+    protected String getMessage( String key )
+    {
+        try
+        {
+            return messages.getString( key );
+        }
+        catch ( NullPointerException exception )
+        {
+            return "???" + key + "???";
+        }
+        catch ( MissingResourceException exception )
+        {
+            return "???" + key + "???";
+        }
+        catch ( ClassCastException exception )
+        {
+            return "???" + key + "???";
+        }
+    }
+
+    /**
+     * Gets the message for the given key from this packages resource bundle and formats it with the given parameter.
+     * 
+     * @param key the key for the required message
+     * @param param the parameter to be used to format the message with
+     * @return the formatted message
+     */
+    protected String getMessage( String key, Object param )
+    {
+        return MessageFormat.format( getMessage( key ), new Object[] { param } );
+    }
+
+    /**
+     * Gets the message for the given key from this packages resource bundle and formats it with the given parameters.
+     * 
+     * @param key the key for the required message
+     * @param param1 the first parameter to be used to format the message with
+     * @param param2 the second parameter to be used to format the message with
+     * @return the formatted message
+     */
+    protected String getMessage( String key, Object param1, Object param2 )
+    {
+        return MessageFormat.format( getMessage( key ), new Object[] { param1, param2 } );
+    }
+
+    /**
+     * Gets the message for the given key from this packages resource bundle and formats it with the given parameters.
+     * 
+     * @param key the key for the required message
+     * @param params the parameters to be used to format the message with
+     * @return the formatted message
+     */
+    protected String getMessage( String key, Object[] params )
+    {
+        return MessageFormat.format( getMessage( key ), params );
+    }
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractRunMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractRunMojo.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractRunMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractRunMojo.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,847 @@
+package org.codehaus.mojo.tomcat;
+
+/*
+ * 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.
+ */
+
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.loader.WebappLoader;
+import org.apache.catalina.realm.MemoryRealm;
+import org.apache.catalina.startup.Catalina;
+import org.apache.catalina.startup.Embedded;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
+import org.codehaus.plexus.classworlds.ClassWorld;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+/**
+ * Abstract goal that provides common configuration for embedded Tomcat goals.
+ * 
+ * @author Jurgen Lust
+ * @author Mark Hobson <markhobson@gmail.com>
+ * @version $Id: AbstractRunMojo.java 14033 2011-05-04 17:51:15Z bimargulies $
+ */
+public abstract class AbstractRunMojo
+    extends AbstractI18NMojo
+{
+    // ----------------------------------------------------------------------
+    // Mojo Parameters
+    // ----------------------------------------------------------------------
+
+    /**
+     * The packaging of the Maven project that this goal operates upon.
+     * 
+     * @parameter expression = "${project.packaging}"
+     * @required
+     * @readonly
+     */
+    private String packaging;
+
+    /**
+     * The directory to create the Tomcat server configuration under.
+     * 
+     * @parameter expression="${project.build.directory}/tomcat"
+     */
+    private File configurationDir;
+
+    /**
+     * The port to run the Tomcat server on.
+     * 
+     * @parameter expression="${maven.tomcat.port}" default-value="8080"
+     */
+    private int port;
+    
+    /**
+     * The AJP port to run the Tomcat server on.
+     * By default it's 0 this means won't be started. 
+     * The ajp connector will be started only for value > 0. 
+     * @since 1.2
+     * @parameter expression="${maven.tomcat.ajp.port}" default-value="0"
+     */
+    private int ajpPort;
+    
+    /**
+     * The AJP protocol to run the Tomcat server on.
+     * By default it's ajp. 
+     * NOTE The ajp connector will be started only if {@link #ajpPort} > 0. 
+     * @since 1.2
+     * @parameter expression="${maven.tomcat.ajp.protocol}" default-value="ajp"
+     */    
+    private String ajpProtocol;
+    
+    /**
+     * The https port to run the Tomcat server on.
+     * By default it's 0 this means won't be started. 
+     * The https connector will be started only for value > 0. 
+     * @since 1.0
+     * @parameter expression="${maven.tomcat.httpsPort}" default-value="0"
+     */
+    private int httpsPort;
+
+    /**
+     * The character encoding to use for decoding URIs.
+     * @since 1.0
+     * @parameter expression="${maven.tomcat.uriEncoding}" default-value="ISO-8859-1"
+     */
+    private String uriEncoding;
+
+    /**
+     * List of System properties to pass to the Tomcat Server.
+     * 
+     * @parameter
+     * @since 1.0-alpha-2
+     */
+    private Map<String, String> systemProperties;
+
+    /**
+     * The directory contains additional configuration Files that copied in the Tomcat conf Directory.
+     * 
+     * @parameter expression = "${maven.tomcat.additionalConfigFilesDir}" default-value="${basedir}/src/main/tomcatconf"
+     * @since 1.0-alpha-2
+     */
+    private File additionalConfigFilesDir;
+
+    /**
+     * server.xml to use <b>Note if you use this you must configure in this file your webapp paths</b>.
+     * 
+     * @parameter expression="${maven.tomcat.serverXml}"
+     * @since 1.0-alpha-2
+     */
+    private File serverXml;
+
+    /**
+     * overriding the providing web.xml to run tomcat
+     * 
+     * @parameter expression="${maven.tomcat.webXml}"
+     * @since 1.0-alpha-2
+     */
+    private File tomcatWebXml;
+    
+    /**
+     * Set this to true to allow Maven to continue to execute after invoking 
+     * the run goal.
+     * 
+     * @parameter expression="${maven.tomcat.fork}" default-value="false"
+     * @since 1.0
+     */
+    private boolean fork;
+    
+    /**
+     * Will create a tomcat context for each dependencies of war type with 'scope' set to 'tomcat'.
+     * In other words, dependencies with:
+     * <pre>
+     *    &lt;type&gt;war&lt;/type&gt;
+     *    &lt;scope&gt;tomcat&lt;/scope&gt;
+     * </pre>
+     * To preserve backward compatibility it's false by default.
+     * @parameter expression="${maven.tomcat.addContextWarDependencies}" default-value="false"
+     * @since 1.0
+     */
+    private boolean addContextWarDependencies;
+        
+    /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @since 1.0
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+
+    /**
+     * The archive manager.
+     * @since 1.0
+     * @component
+     */
+    private ArchiverManager archiverManager;
+    
+    /**
+     * if <code>true</code> a new classLoader separated from maven core will be created to start tomcat.
+     * @parameter expression="${tomcat.useSeparateTomcatClassLoader}" default-value="false"
+     * @since 1.0
+     */
+    protected boolean useSeparateTomcatClassLoader;
+        
+    /**
+     * @parameter expression="${plugin.artifacts}"
+     * @required
+     * @since 1.0
+     */
+    @SuppressWarnings("rawtypes")
+    private List pluginArtifacts;
+   
+    /**
+     * If set to true ignore if packaging of project is not 'war'.
+     * @since 1.0
+     * @parameter expression="${tomcat.ignorePackaging}" default-value="false"
+     */
+    private boolean ignorePackaging;
+
+    /**
+     * Override the default keystoreFile for the HTTPS connector (if enabled)
+     * @since 1.1
+     * @parameter
+     */
+    private String keystoreFile;
+
+    /**
+     * Override the default keystorePass for the HTTPS connector (if enabled)
+     * @since 1.1
+     * @parameter
+     */
+    private String keystorePass;
+
+    /**
+     * <p>
+     * Enables or disables naming support for the embedded Tomcat server. By default the embedded Tomcat
+     * in Tomcat 6 comes with naming enabled. In contrast to this the embedded Tomcat 7 comes with
+     * naming disabled by default.
+     * </p>
+     * <p>
+     * With release 1.2 of this plugin useNaming defaults to false as it does for Tomcat 7. To enable it,
+     * set this parameter to true or set the property <code>maven.tomcat.useNaming</code>.
+     * </p>
+     * <p>
+     * <strong>Note:</strong> This setting is ignored if you provide a <code>server.xml</code> for your
+     * Tomcat. Instead please configure naming in the <code>server.xml</code>.
+     * </p>
+     * @see <a href="http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/startup/Embedded.html">org.apache.catalina.startup.Embedded</a>
+     * @see <a href="http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/startup/Tomcat.html">org.apache.catalina.startup.Tomcat</a>
+     * @parameter expression="${maven.tomcat.useNaming}" default-value="false"
+     * @since 1.2
+     * @todo adopt documentation once Tomcat 7 is supported (MTOMCAT-62)
+     */
+    private boolean useNaming;
+    
+    /**
+     * Force context scanning if you don't use a context file with reloadable = "true".
+     * The other way to use contextReloadable is to add attribute reloadable = "true"
+     * in your context file.
+     * @parameter expression="${maven.tomcat.contextReloadable}" default-value="false"
+     * @since 1.2
+     */
+    protected boolean contextReloadable;
+    
+
+    /**
+     * The path of the Tomcat context XML file.
+     * 
+     * @parameter expression = "src/main/webapp/META-INF/context.xml"
+     */
+    protected File contextFile;    
+
+    // ----------------------------------------------------------------------
+    // Fields
+    // ----------------------------------------------------------------------
+
+    /**
+     * @since 1.0
+     */
+    private ClassRealm tomcatRealm;
+    
+    // ----------------------------------------------------------------------
+    // Mojo Implementation
+    // ----------------------------------------------------------------------
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+        // ensure project is a web application
+        if ( !isWar() )
+        {
+            getLog().info( getMessage( "AbstractRunMojo.nonWar" ) );
+            return;
+        }
+        ClassLoader originalClassLoaser = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            if ( useSeparateTomcatClassLoader )
+            {
+                Thread.currentThread().setContextClassLoader( getTomcatClassLoader() );
+            }
+            getLog().info( getMessage( "AbstractRunMojo.runningWar", getWebappUrl() ) );
+
+            initConfiguration();
+            startContainer();
+            if ( !fork )
+            {
+                waitIndefinitely();
+            }
+        }
+        catch ( LifecycleException exception )
+        {
+            throw new MojoExecutionException( getMessage( "AbstractRunMojo.cannotStart" ), exception );
+        }
+        catch ( IOException exception )
+        {
+            throw new MojoExecutionException( getMessage( "AbstractRunMojo.cannotCreateConfiguration" ), exception );
+        } finally
+        {
+            if (useSeparateTomcatClassLoader)
+            {
+                Thread.currentThread().setContextClassLoader( originalClassLoaser );
+            }
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    // Protected Methods
+    // ----------------------------------------------------------------------
+
+    /**
+     * Gets the webapp context path to use for the web application being run.
+     * 
+     * @return the webapp context path
+     */
+    protected String getPath()
+    {
+        return path;
+    }
+
+    /**
+     * Gets the context to run this web application under for the specified embedded Tomcat.
+     * 
+     * @param container the embedded Tomcat container being used
+     * @return the context to run this web application under
+     * @throws IOException if the context could not be created
+     * @throws MojoExecutionException in case of an error creating the context
+     */
+    protected Context createContext( Embedded container )
+        throws IOException, MojoExecutionException
+    {
+        String contextPath = getPath();
+        Context context = container.createContext( "/".equals( contextPath ) ? "" : contextPath, getDocBase()
+            .getAbsolutePath() );
+
+        if ( useSeparateTomcatClassLoader )
+        {
+            context.setParentClassLoader( getTomcatClassLoader() );
+        }
+
+        context.setLoader( createWebappLoader() );
+        File contextFile = getContextFile();
+        if (contextFile != null)
+        {
+            context.setConfigFile( getContextFile().getAbsolutePath() );
+        }
+        return context;
+    }
+
+    /**
+     * Gets the webapp loader to run this web application under.
+     * 
+     * @return the webapp loader to use
+     * @throws IOException if the webapp loader could not be created
+     * @throws MojoExecutionException in case of an error creating the webapp loader
+     */
+    protected WebappLoader createWebappLoader()
+        throws IOException, MojoExecutionException
+    {
+        if ( useSeparateTomcatClassLoader )
+        {
+            return ( isContextReloadable() )
+                    ? new ExternalRepositoriesReloadableWebappLoader( getTomcatClassLoader(), getLog() )
+                    : new WebappLoader( getTomcatClassLoader() );
+        }
+
+        return ( isContextReloadable() )
+                ? new ExternalRepositoriesReloadableWebappLoader( Thread.currentThread().getContextClassLoader(), getLog()  )
+                : new WebappLoader( Thread.currentThread().getContextClassLoader() );
+    }
+
+    /**
+     * Determine whether the passed context.xml file declares the context as reloadable or not.
+     * @return false by default, true if  reloadable="true" in context.xml.
+     */
+    protected boolean isContextReloadable() throws MojoExecutionException
+    {
+        if ( contextReloadable )
+        {
+            return true;
+        }
+        // determine whether to use a reloadable Loader or not (default is false).
+        boolean reloadable = false;
+        try
+        {
+            if ( contextFile !=null && contextFile.exists() )
+            {
+                DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+                DocumentBuilder builder = builderFactory.newDocumentBuilder();
+                Document contextDoc = builder.parse( contextFile );
+                contextDoc.getDocumentElement().normalize();
+
+                NamedNodeMap nodeMap = contextDoc.getDocumentElement().getAttributes();
+                Node reloadableAttribute = nodeMap.getNamedItem( "reloadable" );
+
+                reloadable = ( reloadableAttribute != null ) ? Boolean.valueOf( reloadableAttribute.getNodeValue() )
+                                                            : false;
+            }
+            getLog().debug( "context reloadable: " + reloadable );
+        }
+        catch ( IOException ioe )
+        {
+            getLog().error( "Could not parse file: [" + contextFile.getAbsolutePath() + "]", ioe );
+        }
+        catch ( ParserConfigurationException pce )
+        {
+            getLog().error( "Could not configure XML parser", pce );
+        }
+        catch ( SAXException se )
+        {
+            getLog().error( "Could not parse file: [" + contextFile.getAbsolutePath() + "]", se );
+        }
+
+        return reloadable;
+    }
+
+
+    /**
+     * Gets the webapp directory to run.
+     * 
+     * @return the webapp directory
+     */
+    protected abstract File getDocBase();
+
+    /**
+     * Gets the Tomcat context XML file to use.
+     * 
+     * @return the context XML file
+     */
+    protected abstract File getContextFile() throws MojoExecutionException;
+
+    // ----------------------------------------------------------------------
+    // Private Methods
+    // ----------------------------------------------------------------------
+
+    /**
+     * Gets whether this project uses WAR packaging.
+     * 
+     * @return whether this project uses WAR packaging
+     */
+    protected boolean isWar()
+    {
+        return "war".equals( packaging ) || ignorePackaging;
+    }
+
+    /**
+     * Gets the URL of the running webapp.
+     * 
+     * @return the URL of the running webapp
+     * @throws MalformedURLException if the running webapp URL is invalid
+     */
+    private URL getWebappUrl()
+        throws MalformedURLException
+    {
+        return new URL( "http", "localhost", port, getPath() );
+    }
+
+    /**
+     * Creates the Tomcat configuration directory with the necessary resources.
+     * 
+     * @throws IOException if the Tomcat configuration could not be created
+     * @throws MojoExecutionException if the Tomcat configuration could not be created
+     */
+    private void initConfiguration()
+        throws IOException, MojoExecutionException
+    {
+        if ( configurationDir.exists() )
+        {
+            getLog().info( getMessage( "AbstractRunMojo.usingConfiguration", configurationDir ) );
+        }
+        else
+        {
+            getLog().info( getMessage( "AbstractRunMojo.creatingConfiguration", configurationDir ) );
+
+            configurationDir.mkdirs();
+
+            File confDir = new File( configurationDir, "conf");
+            confDir.mkdir();
+
+            copyFile("/conf/tomcat-users.xml", new File( confDir, "tomcat-users.xml" ) );
+            if ( tomcatWebXml != null )
+            {
+                if ( !tomcatWebXml.exists() )
+                {
+                    throw new MojoExecutionException( " tomcatWebXml " + tomcatWebXml.getPath() + " not exists" );
+                }
+                //MTOMCAT-42  here it's a real file resources not a one coming with the mojo 
+                FileUtils.copyFile( tomcatWebXml, new File( confDir, "web.xml" ) );
+                //copyFile( tomcatWebXml.getPath(), new File( confDir, "web.xml" ) );
+            }
+            else
+            {
+                copyFile("/conf/web.xml", new File( confDir, "web.xml" ) );
+            }
+
+            File logDir = new File( configurationDir, "logs" );
+            logDir.mkdir();
+
+            File webappsDir = new File( configurationDir, "webapps" );
+            webappsDir.mkdir();
+
+            if ( additionalConfigFilesDir != null && additionalConfigFilesDir.exists() )
+            {
+                DirectoryScanner scanner = new DirectoryScanner();
+                scanner.addDefaultExcludes();
+                scanner.setBasedir( additionalConfigFilesDir.getPath() );
+                scanner.scan();
+
+                String[] files = scanner.getIncludedFiles();
+
+                if ( files != null && files.length > 0 )
+                {
+                    getLog().info( "Coping additional tomcat config files" );
+
+                    for ( int i = 0; i < files.length; i++ )
+                    {
+                        File file = new File( additionalConfigFilesDir, files[i] );
+
+                        getLog().info( " copy " + file.getName() );
+
+                        FileUtils.copyFileToDirectory( file, confDir );
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Copies the specified class resource to the specified file.
+     * 
+     * @param fromPath the path of the class resource to copy
+     * @param toFile the file to copy to
+     * @throws IOException if the file could not be copied
+     */
+    private void copyFile( String fromPath, File toFile )
+        throws IOException
+    {
+        URL fromURL = getClass().getResource( fromPath );
+
+        if ( fromURL == null )
+        {
+            throw new FileNotFoundException( fromPath );
+        }
+
+        FileUtils.copyURLToFile( fromURL, toFile );
+    }
+
+    /**
+     * Starts the embedded Tomcat server.
+     * 
+     * @throws IOException if the server could not be configured
+     * @throws LifecycleException if the server could not be started
+     * @throws MojoExecutionException if the server could not be configured
+     */
+    private void startContainer()
+        throws IOException, LifecycleException, MojoExecutionException
+    {
+        
+        // Set the system properties
+        setupSystemProperties();
+        final Embedded container;
+        if ( serverXml != null )
+        {
+            if ( !serverXml.exists() )
+            {
+                throw new MojoExecutionException( serverXml.getPath() + " not exists" );
+            }
+
+            container = new Catalina();
+            container.setCatalinaHome( configurationDir.getAbsolutePath() );
+            ( (Catalina) container).setConfigFile( serverXml.getPath() );
+            container.start();
+        }
+        else
+        {
+            // create server
+            container = new Embedded();
+            container.setCatalinaHome( configurationDir.getAbsolutePath() );
+            container.setRealm( new MemoryRealm() );
+            container.setUseNaming( useNaming );
+
+            //container.createLoader( getTomcatClassLoader() ).
+
+            // create context
+            Context context = createContext(container);
+
+
+            // create host
+            String appBase = new File( configurationDir, "webapps" ).getAbsolutePath();
+            Host host = container.createHost( "localHost", appBase );
+            
+            host.addChild( context );
+            
+            if ( addContextWarDependencies )
+            {
+                Collection<Context> dependecyContexts = createDependencyContexts(container);
+                for ( Context extraContext : dependecyContexts )
+                {
+                    host.addChild( extraContext );
+                }
+            }
+
+            // create engine
+            Engine engine = container.createEngine();
+            engine.setName( "localEngine" );
+            engine.addChild( host );
+            engine.setDefaultHost( host.getName() );
+            container.addEngine( engine );
+            if ( useSeparateTomcatClassLoader )
+            {
+                engine.setParentClassLoader( getTomcatClassLoader() );
+            }
+            // create http connector
+            Connector httpConnector = container.createConnector( (InetAddress) null, port, false );
+            if ( httpsPort > 0 )
+            {
+                httpConnector.setRedirectPort( httpsPort );
+            }
+            httpConnector.setURIEncoding( uriEncoding );
+            container.addConnector( httpConnector );
+
+            // create https connector
+            if ( httpsPort > 0 )
+            {
+                Connector httpsConnector = container.createConnector( (InetAddress) null, httpsPort, true );
+                if ( keystoreFile!=null)
+                {
+                    httpsConnector.setAttribute("keystoreFile", keystoreFile);
+                }
+                if ( keystorePass!=null)
+                {
+                    httpsConnector.setAttribute("keystorePass", keystorePass);
+                }
+                container.addConnector( httpsConnector );
+
+            }
+
+            // create ajp connector
+            if ( ajpPort > 0 )
+            {
+                Connector ajpConnector = container.createConnector( (InetAddress) null, ajpPort, ajpProtocol );
+                ajpConnector.setURIEncoding( uriEncoding );
+                container.addConnector( ajpConnector );
+            }
+        }
+        container.start();
+        
+        EmbeddedRegistry.getInstance().register(container);
+    }
+
+    protected ClassRealm getTomcatClassLoader()
+        throws MojoExecutionException
+    {
+        if ( this.tomcatRealm != null )
+        {
+            return tomcatRealm;
+        }
+        try
+        {
+            ClassWorld world = new ClassWorld();
+            ClassRealm root = world.newRealm( "tomcat", Thread.currentThread().getContextClassLoader() );
+
+            for ( @SuppressWarnings("rawtypes")
+            Iterator i = pluginArtifacts.iterator(); i.hasNext(); )
+            {
+                Artifact pluginArtifact = (Artifact) i.next();
+                if ( "org.apache.tomcat".equals( pluginArtifact.getGroupId() ) )
+                {
+                    if ( pluginArtifact.getFile() != null )
+                    {
+                        root.addURL( pluginArtifact.getFile().toURI().toURL() );
+                    }
+                }
+            }
+            tomcatRealm = root;
+            return root;
+        }
+        catch ( DuplicateRealmException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+        catch ( MalformedURLException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+    }
+        
+    @SuppressWarnings( "unchecked" )
+    public Set<Artifact> getProjectArtifacts()
+    {
+        return project.getArtifacts();
+    }    
+
+    /**
+     * Causes the current thread to wait indefinitely. This method does not return.
+     */
+    private void waitIndefinitely()
+    {
+        Object lock = new Object();
+
+        synchronized ( lock )
+        {
+            try
+            {
+                lock.wait();
+            }
+            catch ( InterruptedException exception )
+            {
+                getLog().warn( getMessage( "AbstractRunMojo.interrupted" ), exception );
+            }
+        }
+    }
+    
+
+    /**
+     * Set the SystemProperties from the configuration.
+     */
+    private void setupSystemProperties()
+    {
+        if ( systemProperties != null && !systemProperties.isEmpty() )
+        {
+            getLog().info( "setting SystemProperties:" );
+
+            for ( String key : systemProperties.keySet() )
+            {
+                String value = systemProperties.get( key );
+
+                if ( value != null )
+                {
+                    getLog().info( " " + key + "=" + value );
+                    System.setProperty( key, value );
+                }
+                else
+                {
+                    getLog().info( "skip sysProps " + key + " with empty value" );
+                }
+            }
+        }
+    }
+    
+        
+    /**
+     * Allows the startup of additional webapps in the tomcat container by declaration with scope
+     * "tomcat".
+     * 
+     * @param container tomcat
+     * @return dependency tomcat contexts of warfiles in scope "tomcat"
+     */
+    private Collection<Context> createDependencyContexts( Embedded container ) throws MojoExecutionException
+    {
+        getLog().info( "Deploying dependency wars" );
+        // Let's add other modules
+        List<Context> contexts = new ArrayList<Context>();
+
+        ScopeArtifactFilter filter = new ScopeArtifactFilter( "tomcat" );
+        @SuppressWarnings("unchecked")
+        Set<Artifact> artifacts = project.getArtifacts();
+        for ( Artifact artifact : artifacts )
+        {
+
+            // Artifact is not yet registered and it has neither test, nor a
+            // provided scope, not is it optional
+            if ( "war".equals( artifact.getType() ) && !artifact.isOptional() && filter.include( artifact ) )
+            {
+                getLog().info( "Deploy warfile: " + String.valueOf( artifact.getFile() ) );
+                File webapps = new File( configurationDir, "webapps" );
+                File artifactWarDir = new File( webapps, artifact.getArtifactId() );
+                if ( !artifactWarDir.exists() )
+                {
+                    //dont extract if exists
+                    artifactWarDir.mkdir();
+                    try
+                    {
+                        UnArchiver unArchiver = archiverManager.getUnArchiver( "zip" );
+                        unArchiver.setSourceFile( artifact.getFile() );
+                        unArchiver.setDestDirectory( artifactWarDir );
+
+                        // Extract the module
+                        unArchiver.extract();
+                    }
+                    catch ( IOException e )
+                    {
+                        getLog().error( e );
+                        continue;
+                    }
+                    catch ( NoSuchArchiverException e )
+                    {
+                        getLog().error( e );
+                        continue;
+                    }
+                    catch ( ArchiverException e )
+                    {
+                        getLog().error( e );
+                        continue;
+                    }
+                }
+                WebappLoader webappLoader = new WebappLoader( Thread.currentThread().getContextClassLoader() );
+                Context context = container.createContext( "/" + artifact.getArtifactId(), artifactWarDir.getAbsolutePath() );
+                context.setLoader( webappLoader );
+                File contextFile = getContextFile();
+                if (contextFile != null)
+                {
+                    context.setConfigFile( getContextFile().getAbsolutePath() );
+                }
+                contexts.add( context );
+                
+            }
+        }
+        return contexts;
+    }
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractRunWarMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractRunWarMojo.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractRunWarMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractRunWarMojo.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,76 @@
+package org.codehaus.mojo.tomcat;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+/**
+ * Runs the current project as a packaged web application using an embedded Tomcat server.
+ * 
+ * @requiresDependencyResolution runtime
+ * @author Mark Hobson <markhobson@gmail.com>
+ * @version $Id: AbstractRunWarMojo.java 12852 2010-10-12 22:04:32Z thragor $
+ * @todo depend on war:exploded when MNG-1649 resolved
+ */
+public abstract class AbstractRunWarMojo
+    extends AbstractRunMojo
+{
+    // ----------------------------------------------------------------------
+    // Mojo Parameters
+    // ----------------------------------------------------------------------
+
+    /**
+     * The path of the exploded WAR directory to run.
+     * 
+     * @parameter expression = "${project.build.directory}/${project.build.finalName}"
+     * @required
+     */
+    private File warDirectory;
+
+    /**
+     * The path of the Tomcat context XML file.
+     * 
+     * @parameter expression =
+     *            "${project.build.directory}/${project.build.finalName}/META-INF/context.xml"
+     */
+    private File contextFile;
+
+    // ----------------------------------------------------------------------
+    // AbstractRunMojo Implementation
+    // ----------------------------------------------------------------------
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected File getDocBase()
+    {
+        return warDirectory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected File getContextFile()
+    {
+        return contextFile;
+    }
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractWarCatalinaMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractWarCatalinaMojo.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractWarCatalinaMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/AbstractWarCatalinaMojo.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,86 @@
+package org.codehaus.mojo.tomcat;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Abstract goal that provides common configuration for Catalina-based goals.
+ * 
+ * @author Mark Hobson <markhobson@gmail.com>
+ * @version $Id: AbstractWarCatalinaMojo.java 12852 2010-10-12 22:04:32Z thragor $
+ */
+public abstract class AbstractWarCatalinaMojo
+    extends AbstractCatalinaMojo
+{
+    // ----------------------------------------------------------------------
+    // Mojo Parameters
+    // ----------------------------------------------------------------------
+
+    /**
+     * The packaging of the Maven project that this goal operates upon.
+     * 
+     * @parameter expression = "${project.packaging}"
+     * @required
+     * @readonly
+     */
+    private String packaging;
+
+    /**
+     * If set to true ignore if packaging of project is not 'war'.
+     * @since 1.1
+     * @parameter expression="${tomcat.ignorePackaging}" default-value="false"
+     */
+    private boolean ignorePackaging;
+    
+    // ----------------------------------------------------------------------
+    // Mojo Implementation
+    // ----------------------------------------------------------------------
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void execute()
+        throws MojoExecutionException
+    {
+        if ( !isWar() )
+        {
+            getLog().info( getMessage( "AbstractWarCatalinaMojo.nonWar" ) );
+            return;
+        }
+
+        super.execute();
+    }
+
+    // ----------------------------------------------------------------------
+    // Protected Methods
+    // ----------------------------------------------------------------------
+
+    /**
+     * Gets whether this project uses WAR packaging.
+     * 
+     * @return whether this project uses WAR packaging
+     */
+    protected boolean isWar()
+    {
+    	return "war".equals( packaging ) || ignorePackaging;
+    }
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/DeployMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/DeployMojo.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/DeployMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/DeployMojo.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,34 @@
+package org.codehaus.mojo.tomcat;
+
+/*
+ * 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.
+ */
+
+/**
+ * Deploy a WAR to Tomcat.
+ * 
+ * @goal deploy
+ * @execute phase="package"
+ * @author Mark Hobson <markhobson@gmail.com>
+ * @version $Id: DeployMojo.java 12852 2010-10-12 22:04:32Z thragor $
+ */
+public class DeployMojo
+    extends AbstractDeployWarMojo
+{
+    // no-op : only mojo metadata overriding
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/DeployOnlyMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/DeployOnlyMojo.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/DeployOnlyMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/DeployOnlyMojo.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,34 @@
+package org.codehaus.mojo.tomcat;
+
+/*
+ * 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.
+ */
+
+/**
+ * Deploy a WAR to Tomcat witjout forking the package lifecycle
+ * 
+ * @goal deploy-only
+ * @author olamy
+ * @version $Id: DeployOnlyMojo.java 12852 2010-10-12 22:04:32Z thragor $
+ * @since 1.0-alpha-2
+ */
+public class DeployOnlyMojo
+    extends AbstractDeployWarMojo
+{
+    // no-op : only mojo metadata overriding
+}

Added: tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/EmbeddedRegistry.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/EmbeddedRegistry.java?rev=1163136&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/EmbeddedRegistry.java (added)
+++ tomcat/maven-plugin/trunk/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/EmbeddedRegistry.java Tue Aug 30 08:31:33 2011
@@ -0,0 +1,151 @@
+package org.codehaus.mojo.tomcat;
+
+/*
+ * 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.
+ */
+
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.startup.Embedded;
+import org.apache.maven.plugin.logging.Log;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * Registry which collects all embedded Tomcat Servers so that they will be shutdown
+ * through a shutdown hook when the JVM terminates or you can ask the registry to
+ * shutdown all started servers.
+ * @author Mark Michaelis
+ * @since 1.1
+ */
+public final class EmbeddedRegistry
+{
+    private static EmbeddedRegistry instance;
+
+    private Set<Embedded> containers = new HashSet<Embedded>( 1 );
+
+    /**
+     * Don't instantiate - use the instance through {@link #getInstance()}.
+     */
+    private EmbeddedRegistry()
+    {
+        // no op
+    }
+
+    /**
+     * Retrieve the lazily initialized instance of the registry.
+     * 
+     * @return singleton instance of the registry
+     */
+    public static EmbeddedRegistry getInstance()
+    {
+        if ( instance == null )
+        {
+            instance = new EmbeddedRegistry();
+            Runtime.getRuntime().addShutdownHook( new Thread()
+            {
+                @Override
+                public void run()
+                {
+                    try
+                    {
+                        getInstance().shutdownAll( null );
+                    }
+                    catch ( LifecycleException e )
+                    {
+                        // ignore, the exception should already have been reported
+                    }
+                }
+            } );
+        }
+        return instance;
+    }
+
+    /**
+     * Adds the given container to the registry which automatically registers it for the shutdown
+     * hook.
+     * 
+     * @param container the container to register
+     * @return true if it got added; false if not
+     */
+    public synchronized boolean register( final Embedded container )
+    {
+        return containers.add( container );
+    }
+
+    /**
+     * Shuts down all registered embedded tomcats. All tomcats which successfully shut down will be
+     * removed from the registry.
+     * 
+     * @param log the log to write possible shutdown exceptions to
+     * @throws LifecycleException the first exception which occurred will be rethrown
+     */
+    public synchronized void shutdownAll( final Log log )
+        throws LifecycleException
+    {
+        LifecycleException firstException = null;
+        for ( Iterator<Embedded> iterator = containers.iterator(); iterator.hasNext(); )
+        {
+            Embedded embedded = iterator.next();
+            try
+            {
+                embedded.stop();
+                iterator.remove();
+            }
+            catch ( LifecycleException e )
+            {
+                if ( firstException == null )
+                {
+                    firstException = e;
+                    error( log, e, "Error while shutting down embedded Tomcat. Will be rethrown." );
+                }
+                else
+                {
+                    error( log, e, "Error while shutting down embedded Tomcat." );
+                }
+            }
+        }
+        if ( firstException != null )
+        {
+            throw firstException;
+        }
+    }
+
+    /**
+     * Reports the exception. If a log is given (typically when called from within a Mojo) the
+     * message will be printed to the log. Otherwise it will be printed to StdErr.
+     * 
+     * @param log the log to write the message to; null to write to stderr
+     * @param e exception which shall be reported
+     * @param message message which shall be reported
+     */
+    private void error( final Log log, final LifecycleException e, final String message )
+    {
+        if ( log == null )
+        {
+            System.err.println( "ERROR: " + message );
+            e.printStackTrace();
+        }
+        else
+        {
+            log.error( message, e );
+        }
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message