View Javadoc

1   package org.apache.tomcat.maven.plugin.tomcat6;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.apache.maven.plugin.AbstractMojo;
22  import org.apache.maven.plugin.MojoExecutionException;
23  import org.apache.maven.plugins.annotations.Component;
24  import org.apache.maven.plugins.annotations.Parameter;
25  import org.apache.maven.settings.Settings;
26  import org.apache.tomcat.maven.common.deployer.TomcatManagerResponse;
27  import org.apache.tomcat.maven.common.messages.MessagesProvider;
28  
29  /**
30   * olamy: as long as maven plugin descriptor metadata generation doesn't support annotations outside of the same
31   * project, we must have those fields here
32   *
33   * @author Olivier Lamy
34   */
35  public abstract class AbstractI18NTomcat6Mojo
36      extends AbstractMojo
37  {
38  
39      @Component
40      protected Settings settings;
41  
42      @Component(role = MessagesProvider.class)
43      protected MessagesProvider messagesProvider;
44  
45      // ----------------------------------------------------------------------
46      // Mojo Parameters
47      // ----------------------------------------------------------------------
48  
49      /**
50       * The webapp context path to use for the web application being run. This must always start with a forward-slash
51       * ('/').
52       */
53      @Parameter(property = "maven.tomcat.path", defaultValue = "/${project.artifactId}", required = true)
54      protected String path;
55  
56  
57      protected String getPath()
58      {
59          return path;
60      }
61  
62      /**
63       * Check response of Tomcat to know if ok or not.
64       *
65       * @param tomcatResponse response of tomcat return by TomcatManager class
66       * @throws MojoExecutionException if HTTP status code greater than 400 (included)
67       */
68      protected void checkTomcatResponse( TomcatManagerResponse tomcatResponse )
69          throws MojoExecutionException
70      {
71          int statusCode = tomcatResponse.getStatusCode();
72  
73          if ( statusCode >= 400 )
74          {
75              getLog().error( messagesProvider.getMessage( "tomcatHttpStatusError", statusCode,
76                                                           tomcatResponse.getReasonPhrase() ) );
77  
78              throw new MojoExecutionException(
79                  messagesProvider.getMessage( "tomcatHttpStatusError", statusCode,
80                                               tomcatResponse.getReasonPhrase() ) + ": "
81                      + tomcatResponse.getHttpResponseBody() );
82          }
83      }
84  }