Debian Codegraph @

maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/UpdateSubprojectsMojo.java

raw
1 package org.apache.maven.scm.plugin;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugins.annotations.Mojo;
24 import org.apache.maven.plugins.annotations.Parameter;
25 import org.apache.maven.project.MavenProject;
26 import org.apache.maven.scm.ScmException;
27 import org.apache.maven.scm.command.update.UpdateScmResult;
28 import org.apache.maven.scm.command.update.UpdateScmResultWithRevision;
29 import org.apache.maven.scm.repository.ScmRepository;
30
31 import java.io.IOException;
32
33 /**
34 * Updates all projects in a multi project build. This is useful for users who have adopted the flat project structure
35 * where the aggregator project is a sibling of the sub projects rather than sitting in the parent directory.
36 */
37 @Mojo( name = "update-subprojects" )
38 public class UpdateSubprojectsMojo
39 extends AbstractScmMojo
40 {
41 /**
42 * The version type (branch/tag/revision) of scmVersion.
43 */
44 @Parameter( property = "scmVersionType" )
45 private String scmVersionType;
46
47 /**
48 * The version (revision number/branch name/tag name).
49 */
50 @Parameter( property = "scmVersion" )
51 private String scmVersion;
52
53 /**
54 * The project property where to store the revision name.
55 */
56 @Parameter( property = "revisionKey", defaultValue = "scm.revision" )
57 private String revisionKey;
58
59 /**
60 * The Maven project.
61 */
62 @Parameter( defaultValue = "${project}", required = true, readonly = true )
63 private MavenProject project;
64
65 /** {@inheritDoc} */
66 public void execute()
67 throws MojoExecutionException
68 {
69 super.execute();
70
71 try
72 {
73 ScmRepository repository = getScmRepository();
74
75 UpdateScmResult result =
76 getScmManager().update( repository, getFileSet(), getScmVersion( scmVersionType, scmVersion ) );
77
78 checkResult( result );
79
80 if ( result instanceof UpdateScmResultWithRevision )
81 {
82 getLog().info( "Storing revision in '" + revisionKey + "' project property." );
83
84 if ( project.getProperties() != null ) // Remove the test when we'll use plugin-test-harness 1.0-alpha-2
85 {
86 project.getProperties().put( revisionKey, ( (UpdateScmResultWithRevision) result ).getRevision() );
87 }
88 }
89 }
90 catch ( IOException | ScmException e )
91 {
92 throw new MojoExecutionException( "Cannot run update command : ", e );
93 }
94 }
95 }