1 package org.apache.tomcat.maven.plugin.tomcat6;
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
26 import java.io.File;
27 import java.io.IOException;
28
29 /**
30 * @author olamy
31 * @since 1.0-alpha-2
32 */
33 public class AbstractDeployWarMojo
34 extends AbstractDeployMojo
35 {
36 // ----------------------------------------------------------------------
37 // Mojo Parameters
38 // ----------------------------------------------------------------------
39
40 /**
41 * The path of the WAR file to deploy.
42 */
43 @Parameter( defaultValue = "${project.build.directory}/${project.build.finalName}.war", required = true )
44 private File warFile;
45
46 // ----------------------------------------------------------------------
47 // Protected Methods
48 // ----------------------------------------------------------------------
49
50 /**
51 * {@inheritDoc}
52 */
53 @Override
54 protected File getWarFile()
55 {
56 return warFile;
57 }
58
59 /**
60 * {@inheritDoc}
61 */
62 @Override
63 protected void validateWarFile()
64 throws MojoExecutionException
65 {
66 if ( !warFile.exists() || !warFile.isFile() )
67 {
68 throw new MojoExecutionException(
69 messagesProvider.getMessage( "DeployMojo.missingWar", warFile.getPath() ) );
70 }
71 }
72
73 /**
74 * {@inheritDoc}
75 */
76 @Override
77 protected void deployWar()
78 throws MojoExecutionException, TomcatManagerException, IOException
79 {
80 validateWarFile();
81
82 getLog().info( messagesProvider.getMessage( "AbstractDeployMojo.deployingWar", getDeployedURL() ) );
83
84 log( getManager().deploy( getPath(), warFile, isUpdate(), getTag(), warFile.length() ).getHttpResponseBody() );
85 }
86 }