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
37 @Mojo(name = "update", aggregator = true)
38 public class UpdateMojo extends AbstractScmMojo {
39
40
41
42 @Parameter(property = "scmVersionType")
43 private String scmVersionType;
44
45
46
47
48 @Parameter(property = "scmVersion")
49 private String scmVersion;
50
51
52
53
54 @Parameter(property = "revisionKey", defaultValue = "scm.revision")
55 private String revisionKey;
56
57
58
59
60 @Parameter(defaultValue = "${project}", required = true, readonly = true)
61 private MavenProject project;
62
63
64
65
66 @Parameter(property = "runChangelog", defaultValue = "false")
67 private boolean runChangelog = false;
68
69
70 public void execute() throws MojoExecutionException {
71 super.execute();
72
73 try {
74 ScmRepository repository = getScmRepository();
75
76 UpdateScmResult result = getScmManager()
77 .update(repository, getFileSet(), getScmVersion(scmVersionType, scmVersion), runChangelog);
78
79 checkResult(result);
80
81 if (result instanceof UpdateScmResultWithRevision) {
82 String revision = ((UpdateScmResultWithRevision) result).getRevision();
83
84 getLog().info("Storing revision in '" + revisionKey + "' project property.");
85
86 if (project.getProperties() != null)
87 {
88 project.getProperties().put(revisionKey, revision);
89 }
90
91 getLog().info("Project at revision " + revision);
92 }
93 } catch (IOException | ScmException e) {
94 throw new MojoExecutionException("Cannot run update command : ", e);
95 }
96 }
97 }