1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.plugin;
20
21 import java.io.IOException;
22
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugins.annotations.Mojo;
25 import org.apache.maven.plugins.annotations.Parameter;
26 import org.apache.maven.project.MavenProject;
27 import org.apache.maven.scm.ScmException;
28 import org.apache.maven.scm.command.update.UpdateScmResult;
29 import org.apache.maven.scm.command.update.UpdateScmResultWithRevision;
30 import org.apache.maven.scm.repository.ScmRepository;
31
32
33
34
35
36 @Mojo(name = "update-subprojects")
37 public class UpdateSubprojectsMojo extends AbstractScmMojo {
38
39
40
41 @Parameter(property = "scmVersionType")
42 private String scmVersionType;
43
44
45
46
47 @Parameter(property = "scmVersion")
48 private String scmVersion;
49
50
51
52
53 @Parameter(property = "revisionKey", defaultValue = "scm.revision")
54 private String revisionKey;
55
56
57
58
59 @Parameter(defaultValue = "${project}", required = true, readonly = true)
60 private MavenProject project;
61
62
63 public void execute() throws MojoExecutionException {
64 super.execute();
65
66 try {
67 ScmRepository repository = getScmRepository();
68
69 UpdateScmResult result =
70 getScmManager().update(repository, getFileSet(), getScmVersion(scmVersionType, scmVersion));
71
72 checkResult(result);
73
74 if (result instanceof UpdateScmResultWithRevision) {
75 getLog().info("Storing revision in '" + revisionKey + "' project property.");
76
77 if (project.getProperties() != null)
78 {
79 project.getProperties().put(revisionKey, ((UpdateScmResultWithRevision) result).getRevision());
80 }
81 }
82 } catch (IOException | ScmException e) {
83 throw new MojoExecutionException("Cannot run update command : ", e);
84 }
85 }
86 }