View Javadoc

1   package org.apache.tomcat.maven.plugin.tomcat7.deploy;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.MojoExecutionException;
23  import org.apache.maven.plugins.annotations.Parameter;
24  import org.apache.tomcat.maven.common.deployer.TomcatManagerException;
25  import org.apache.tomcat.maven.common.deployer.TomcatManagerResponse;
26  
27  import java.io.File;
28  import java.io.IOException;
29  
30  /**
31   * @author olamy
32   * @since 1.0-alpha-2
33   */
34  public class AbstractDeployWarMojo
35      extends AbstractDeployMojo
36  {
37      // ----------------------------------------------------------------------
38      // Mojo Parameters
39      // ----------------------------------------------------------------------
40  
41      /**
42       * The path of the WAR file to deploy.
43       */
44      @Parameter( defaultValue = "${project.build.directory}/${project.build.finalName}.war", required = true )
45      private File warFile;
46  
47      // ----------------------------------------------------------------------
48      // Protected Methods
49      // ----------------------------------------------------------------------
50  
51      /**
52       * {@inheritDoc}
53       */
54      @Override
55      protected File getWarFile()
56      {
57          return warFile;
58      }
59  
60      /**
61       * {@inheritDoc}
62       */
63      @Override
64      protected void validateWarFile()
65          throws MojoExecutionException
66      {
67          if ( !warFile.exists() || !warFile.isFile() )
68          {
69              throw new MojoExecutionException(
70                  messagesProvider.getMessage( "DeployMojo.missingWar", warFile.getPath() ) );
71          }
72      }
73  
74      /**
75       * {@inheritDoc}
76       */
77      @Override
78      protected void deployWar()
79          throws MojoExecutionException, TomcatManagerException, IOException
80      {
81          validateWarFile();
82  
83          getLog().info( messagesProvider.getMessage( "AbstractDeployMojo.deployingWar", getDeployedURL() ) );
84  
85          TomcatManagerResponse tomcatManagerResponse =
86              getManager().deploy( getPath(), warFile, isUpdate(), getTag(), warFile.length() );
87  
88          getLog().info( "tomcatManager status code:" + tomcatManagerResponse.getStatusCode() + ", ReasonPhrase:"
89                             + tomcatManagerResponse.getReasonPhrase() );
90  
91          log( tomcatManagerResponse.getHttpResponseBody() );
92      }
93  }