1 package org.apache.maven.plugin.cxx;
2
3 /*
4 * Copyright (C) 2011-2016, Neticoa SAS France - Tous droits réservés.
5 * Author(s) : Franck Bonin, Neticoa SAS France
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 */
20
21 import org.apache.maven.plugins.annotations.Parameter;
22 import org.apache.maven.plugins.annotations.Component;
23 import java.io.File;
24 import org.apache.maven.shared.release.env.DefaultReleaseEnvironment;
25 import org.apache.maven.shared.release.env.ReleaseEnvironment;
26 import org.apache.maven.plugin.cxx.utils.release.CxxReleaseDescriptor;
27 import org.apache.maven.plugin.cxx.utils.release.CxxReleaseManager;
28
29 /**
30 * Branch a project in SCM
31 *
32 * @author
33 * @version
34 * @since 0.0.6
35 */
36 public abstract class AbstractPerformBranchReleaseMojo
37 extends AbstractCxxMojo
38 {
39 /**
40 * The {@code M2_HOME} parameter to use for forked Maven invocations.
41 *
42 * @since 0.0.6
43 */
44 @Parameter( defaultValue = "${maven.home}" )
45 protected File mavenHome;
46
47 /**
48 * The {@code JAVA_HOME} parameter to use for forked Maven invocations.
49 *
50 * @since 0.0.6
51 */
52 @Parameter( defaultValue = "${java.home}" )
53 protected File javaHome;
54
55 /**
56 * The command-line local repository directory in use for this build (if specified).
57 *
58 * @since 0.0.6
59 */
60 @Parameter ( defaultValue = "${maven.repo.local}" )
61 protected File localRepoDirectory;
62
63 /**********************************************************************************************/
64 /**********************************************************************************************/
65 /**********************************************************************************************/
66
67 /**
68 * The user name (used by svn).
69 *
70 * You may use maven setting to store username.
71 * See http://maven.apache.org/guides/mini/guide-encryption.html
72 *
73 * @since 0.0.6
74 */
75 @Parameter( property = "username" )
76 protected String username = null;
77
78 /**
79 * The user password (used by svn).
80 *
81 * You may use maven setting to store encrypted password.
82 * See http://maven.apache.org/guides/mini/guide-encryption.html
83 *
84 * @since 0.0.6
85 */
86 @Parameter( property = "password" )
87 private String password = null;
88
89 /**
90 * The server id to use in maven settings to retrieve credential.
91 * Optionnal, by defaut each scm url "hostname[:port]" is taken as server id to search potential
92 * credentials in maven settings
93 *
94 * See http://maven.apache.org/guides/mini/guide-encryption.html
95 *
96 * @since 0.0.6
97 */
98 @Parameter( property = "settingsServerId" )
99 protected String settingsServerId = null;
100
101 /**********************************************************************************************/
102 /**********************************************************************************************/
103 /**********************************************************************************************/
104
105 /**
106 * Dry run: don't checkin or tag anything in the scm repository, or modify the checkout.
107 * Running <code>mvn -DdryRun=true cxx:branch</code> is useful in order to check that modifications to
108 * poms and scm operations (only listed on the console) are working as expected.
109 * Modified POMs are written alongside the originals without modifying them.
110 *
111 * @since 0.0.6
112 */
113 @Parameter( defaultValue = "false", property = "dryRun" )
114 protected boolean dryRun;
115
116 /**********************************************************************************************/
117 /**********************************************************************************************/
118 /**********************************************************************************************/
119
120 /**
121 * Specify the new version for the working copy.
122 * This parameter is only meaningful if {@link #updateWorkingCopyVersions} = {@code true}.
123 *
124 * @since 0.0.6
125 */
126 @Parameter( property = "developmentVersion" )
127 private String developmentVersion;
128
129 /**
130 * Shall developpment version use -SNAPSHOT suffix
131 */
132 @Parameter( defaultValue = "false", property = "snapshotDevelopmentVersion" )
133 protected boolean snapshotDevelopmentVersion = false;
134
135 /**
136 * new artifact id, if provided
137 */
138 @Parameter( property = "artifactId" )
139 protected String artifactId = null;
140
141 /**
142 * Whether to automatically assign submodules the parent (main) version.
143 * If set to true, each submodule (if any) will be update to computed main version
144 * If set to false :
145 * - the user will be prompted for each submodules version
146 * if settings.isInteractiveMode()/-B,--batch-mode flag not set
147 * - auto-computed if !settings.isInteractiveMode()/-B,--batch-mode flag set
148 * !!PLUS!! :
149 * Submodule version are updated only if they are "real" child of main module, according to SCM tree.
150 * Aka. Only and only if :
151 * - submodule dir is under scm configuration
152 * - submodule dir is not an external dir
153 * - (futur ?) submodule dir is an external dir AND settings.isInteractiveMode()/-B,--batch-mode flag not set
154 * AND user confirm branch and version update
155 *
156 * @since 0.0.6
157 */
158 @Parameter( defaultValue = "false", property = "autoVersionSubmodules" )
159 protected boolean autoVersionSubmodules;
160
161 /**
162 * Whether to update dependencies version to the next development version.
163 *
164 * @since 0.0.6
165 */
166 @Parameter( defaultValue = "true", property = "updateDependencies" )
167 protected boolean updateDependencies;
168
169
170 /**********************************************************************************************/
171 /**********************************************************************************************/
172 /**********************************************************************************************/
173
174 /**
175 * Whether to add a XML schema to the POM if it was previously missing on.
176 *
177 * @since 0.0.6
178 */
179 @Parameter( defaultValue = "true", property = "addSchema" )
180 protected boolean addSchema;
181
182 /**
183 * The checkout directory.
184 */
185 @Parameter( defaultValue = "${project.build.directory}/checkout", property = "workingDirectory", required = true )
186 protected File workingDirectory;
187
188 /**
189 * phases manager.
190 */
191 @Component
192 protected CxxReleaseManager releaseManager;
193
194 /**
195 * Gets the enviroment settings configured for this release.
196 *
197 * @return The release environment, never <code>null</code>.
198 */
199 protected ReleaseEnvironment getReleaseEnvironment()
200 {
201 return new DefaultReleaseEnvironment().setSettings( settings )
202 .setJavaHome( javaHome )
203 .setMavenHome( mavenHome )
204 .setLocalRepositoryDirectory( localRepoDirectory )
205 ; //.setMavenExecutorId( mavenExecutorId );
206 }
207
208 /**
209 * Creates the release descriptor from the various goal parameters.
210 *
211 * @return The release descriptor, never <code>null</code>.
212 */
213 protected CxxReleaseDescriptor createReleaseDescriptor()
214 {
215 // Our release descriptor doesn't think, it carries our data, in their inital form
216 CxxReleaseDescriptor descriptor = new CxxReleaseDescriptor();
217
218 // -B,--batch-mode flag set weather Maven Run in non-interactive (batch) mode
219 descriptor.setInteractive( settings.isInteractiveMode() );
220 descriptor.setWorkingDirectory( basedir.getAbsolutePath() );
221 descriptor.setDryRun( dryRun );
222 descriptor.setScmPassword( password );
223 descriptor.setScmUsername( username );
224 descriptor.setScmId( settingsServerId );
225 descriptor.setArtifactId( artifactId );
226 descriptor.setAutoVersionSubmodules( autoVersionSubmodules );
227 descriptor.setUpdateDependencies( updateDependencies );
228 descriptor.setAddSchema( addSchema );
229 descriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() );
230 descriptor.setDefaultDevelopmentVersion( developmentVersion ); // version to fallback after tag or branch
231 descriptor.setSnapshotDevelopmentVersion( snapshotDevelopmentVersion ); // developmentVersion shall be a SnapShot version
232 //descriptor.setProjectVersionPolicyId( projectVersionPolicyId ); // TODO ?
233
234 /* descriptor.setPomFileName( pomFileName );
235
236 List<String> profileIds = getActiveProfileIds();
237 String additionalProfiles = getAdditionalProfiles();
238
239 String args = this.arguments;
240 if ( !profileIds.isEmpty() || StringUtils.isNotBlank( additionalProfiles ) )
241 {
242 if ( !StringUtils.isEmpty( args ) )
243 {
244 args += " -P ";
245 }
246 else
247 {
248 args = "-P ";
249 }
250
251 for ( Iterator<String> it = profileIds.iterator(); it.hasNext(); )
252 {
253 args += it.next();
254 if ( it.hasNext() )
255 {
256 args += ",";
257 }
258 }
259
260 if ( additionalProfiles != null )
261 {
262 if ( !profileIds.isEmpty() )
263 {
264 args += ",";
265 }
266 args += additionalProfiles;
267 }
268 }
269 descriptor.setAdditionalArguments( args );
270 */
271 return descriptor;
272 }
273 }