1 package org.apache.maven.plugins.release;
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
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.MojoFailureException;
26 import org.apache.maven.plugins.annotations.Mojo;
27 import org.apache.maven.plugins.annotations.Parameter;
28 import org.apache.maven.shared.release.ReleaseExecutionException;
29 import org.apache.maven.shared.release.ReleaseFailureException;
30 import org.apache.maven.shared.release.config.ReleaseDescriptor;
31 import org.codehaus.plexus.util.StringUtils;
32
33
34
35
36
37
38
39
40 @Mojo( name = "stage", aggregator = true, requiresProject = false )
41 public class StageReleaseMojo
42 extends AbstractScmReleaseMojo
43 {
44
45
46
47
48
49
50 @Parameter( property = "goals" )
51 private String goals;
52
53
54
55
56
57
58 @Parameter( property = "releaseProfiles" )
59 private String releaseProfiles;
60
61
62
63
64
65
66 @Parameter( defaultValue = "${project.build.directory}/checkout", property = "workingDirectory", required = true )
67 private File workingDirectory;
68
69
70
71
72
73
74
75 @Parameter( property = "connectionUrl" )
76 private String connectionUrl;
77
78
79
80
81
82
83 @Parameter( defaultValue = "true", property = "useReleaseProfile" )
84 private boolean useReleaseProfile;
85
86
87
88
89
90
91 @Parameter( property = "stagingRepository", required = true )
92 private String stagingRepository;
93
94
95
96
97 protected String getAdditionalProfiles()
98 {
99 return releaseProfiles;
100 }
101
102
103
104
105 public void execute()
106 throws MojoExecutionException, MojoFailureException
107 {
108 super.execute();
109
110
111
112 if ( goals != null )
113 {
114 goals = StringUtils.join( StringUtils.split( goals ), " " );
115 }
116
117 try
118 {
119 addArgument( "-DaltDeploymentRepository=\"" + stagingRepository + "\"" );
120
121
122 ReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
123 if ( connectionUrl != null )
124 {
125 releaseDescriptor.setScmSourceUrl( connectionUrl );
126 }
127
128 releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() );
129 releaseDescriptor.setUseReleaseProfile( useReleaseProfile );
130
131 if ( goals == null )
132 {
133
134 goals = "deploy";
135 if ( project.getDistributionManagement() != null
136 && project.getDistributionManagement().getSite() != null )
137 {
138 goals += " site:stage-deploy";
139 }
140 }
141
142 goals = StringUtils.replace( goals, "site-deploy", "site:stage-deploy" );
143 goals = StringUtils.replace( goals, "site:deploy", "site:stage-deploy" );
144
145 releaseDescriptor.setPerformGoals( goals );
146
147 releaseManager.perform( releaseDescriptor, getReleaseEnvironment(), getReactorProjects(), false );
148 }
149 catch ( ReleaseExecutionException e )
150 {
151 throw new MojoExecutionException( e.getMessage(), e );
152 }
153 catch ( ReleaseFailureException e )
154 {
155 throw new MojoFailureException( e.getMessage(), e );
156 }
157 }
158 }