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.tomcat.maven.common.deployer.TomcatManagerException;
24 import org.apache.tomcat.maven.common.deployer.TomcatManagerResponse;
25
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.IOException;
29
30
31
32
33
34
35 public class AbstractDeployWarMojo
36 extends AbstractDeployMojo
37 {
38
39
40
41
42
43
44
45
46
47
48 private File warFile;
49
50
51
52
53
54
55
56
57 @Override
58 protected File getWarFile()
59 {
60 return warFile;
61 }
62
63
64
65
66 @Override
67 protected void validateWarFile()
68 throws MojoExecutionException
69 {
70 if ( !warFile.exists() || !warFile.isFile() )
71 {
72 throw new MojoExecutionException(
73 messagesProvider.getMessage( "DeployMojo.missingWar", warFile.getPath() ) );
74 }
75 }
76
77
78
79
80 @Override
81 protected void deployWar()
82 throws MojoExecutionException, TomcatManagerException, IOException
83 {
84 validateWarFile();
85
86 getLog().info( messagesProvider.getMessage( "AbstractDeployMojo.deployingWar", getDeployedURL() ) );
87
88 TomcatManagerResponse tomcatManagerResponse =
89 getManager().deploy( getPath(), new FileInputStream( warFile ), isUpdate(), getTag(), warFile.length() );
90
91 getLog().info( "tomcatManager status code:" + tomcatManagerResponse.getStatusCode() + ", ReasonPhrase:"
92 + tomcatManagerResponse.getReasonPhrase() );
93
94 log( tomcatManagerResponse.getHttpResponseBody() );
95 }
96 }