1 package org.apache.tomcat.maven.plugin.tomcat7.deploy;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
32
33
34 public class AbstractDeployWarMojo
35 extends AbstractDeployMojo
36 {
37
38
39
40
41
42
43
44 @Parameter( defaultValue = "${project.build.directory}/${project.build.finalName}.war", required = true )
45 private File warFile;
46
47
48
49
50
51
52
53
54 @Override
55 protected File getWarFile()
56 {
57 return warFile;
58 }
59
60
61
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
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 }