1 | |
package org.apache.maven.plugin.deploy; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.util.Map; |
24 | |
|
25 | |
import org.apache.maven.artifact.Artifact; |
26 | |
import org.apache.maven.artifact.deployer.ArtifactDeployer; |
27 | |
import org.apache.maven.artifact.deployer.ArtifactDeploymentException; |
28 | |
import org.apache.maven.artifact.factory.ArtifactFactory; |
29 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
30 | |
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; |
31 | |
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; |
32 | |
import org.apache.maven.plugin.AbstractMojo; |
33 | |
import org.apache.maven.plugin.MojoExecutionException; |
34 | |
import org.apache.maven.plugin.MojoFailureException; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 42 | public abstract class AbstractDeployMojo |
40 | |
extends AbstractMojo |
41 | |
{ |
42 | |
|
43 | |
|
44 | |
|
45 | |
private ArtifactDeployer deployer; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
protected ArtifactFactory artifactFactory; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
ArtifactRepositoryFactory repositoryFactory; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
private Map repositoryLayouts; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
private ArtifactRepository localRepository; |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
private boolean offline; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
protected boolean updateReleaseInfo; |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
private int retryFailedDeploymentCount; |
98 | |
|
99 | |
|
100 | |
|
101 | |
public ArtifactDeployer getDeployer() |
102 | |
{ |
103 | 24 | return deployer; |
104 | |
} |
105 | |
|
106 | |
public void setDeployer( ArtifactDeployer deployer ) |
107 | |
{ |
108 | 2 | this.deployer = deployer; |
109 | 2 | } |
110 | |
|
111 | |
public ArtifactRepository getLocalRepository() |
112 | |
{ |
113 | 48 | return localRepository; |
114 | |
} |
115 | |
|
116 | |
public void setLocalRepository( ArtifactRepository localRepository ) |
117 | |
{ |
118 | 28 | this.localRepository = localRepository; |
119 | 28 | } |
120 | |
|
121 | |
void failIfOffline() |
122 | |
throws MojoFailureException |
123 | |
{ |
124 | 24 | if ( offline ) |
125 | |
{ |
126 | 0 | throw new MojoFailureException( "Cannot deploy artifacts when Maven is in offline mode" ); |
127 | |
} |
128 | 24 | } |
129 | |
|
130 | |
ArtifactRepositoryLayout getLayout( String id ) |
131 | |
throws MojoExecutionException |
132 | |
{ |
133 | 12 | ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( id ); |
134 | |
|
135 | 12 | if ( layout == null ) |
136 | |
{ |
137 | 0 | throw new MojoExecutionException( "Invalid repository layout: " + id ); |
138 | |
} |
139 | |
|
140 | 12 | return layout; |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
protected void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository, |
153 | |
ArtifactRepository localRepository ) |
154 | |
throws ArtifactDeploymentException |
155 | |
{ |
156 | 24 | int retryFailedDeploymentCount = Math.max( 1, Math.min( 10, this.retryFailedDeploymentCount ) ); |
157 | 24 | ArtifactDeploymentException exception = null; |
158 | 24 | for ( int count = 0; count < retryFailedDeploymentCount; count++ ) |
159 | |
{ |
160 | |
try |
161 | |
{ |
162 | 24 | if (count > 0) |
163 | |
{ |
164 | 0 | getLog().info( |
165 | |
"Retrying deployment attempt " + ( count + 1 ) + " of " + retryFailedDeploymentCount ); |
166 | |
} |
167 | 24 | getDeployer().deploy( source, artifact, deploymentRepository, localRepository ); |
168 | 24 | exception = null; |
169 | 24 | break; |
170 | |
} |
171 | 0 | catch ( ArtifactDeploymentException e ) |
172 | |
{ |
173 | 0 | if (count + 1 < retryFailedDeploymentCount) { |
174 | 0 | getLog().warn( "Encountered issue during deployment: " + e.getLocalizedMessage()); |
175 | 0 | getLog().debug( e ); |
176 | |
} |
177 | 0 | if ( exception == null ) |
178 | |
{ |
179 | 0 | exception = e; |
180 | |
} |
181 | |
} |
182 | |
} |
183 | 24 | if ( exception != null ) |
184 | |
{ |
185 | 0 | throw exception; |
186 | |
} |
187 | 24 | } |
188 | |
} |