1 package org.apache.maven.scm.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
35
36
37
38 @Mojo( name = "update", aggregator = true )
39 public class UpdateMojo
40 extends AbstractScmMojo
41 {
42
43
44
45 @Parameter( property = "scmVersionType" )
46 private String scmVersionType;
47
48
49
50
51 @Parameter( property = "scmVersion" )
52 private String scmVersion;
53
54
55
56
57 @Parameter( property = "revisionKey", defaultValue = "scm.revision" )
58 private String revisionKey;
59
60
61
62
63 @Parameter( defaultValue = "${project}", required = true, readonly = true )
64 private MavenProject project;
65
66
67
68
69 @Parameter( property = "runChangelog", defaultValue = "false" )
70 private boolean runChangelog = false;
71
72
73 public void execute()
74 throws MojoExecutionException
75 {
76 super.execute();
77
78 try
79 {
80 ScmRepository repository = getScmRepository();
81
82 UpdateScmResult result = getScmManager().update( repository, getFileSet(),
83 getScmVersion( scmVersionType, scmVersion ),
84 runChangelog );
85
86 checkResult( result );
87
88 if ( result instanceof UpdateScmResultWithRevision )
89 {
90 String revision = ( (UpdateScmResultWithRevision) result ).getRevision();
91
92 getLog().info( "Storing revision in '" + revisionKey + "' project property." );
93
94 if ( project.getProperties() != null )
95 {
96 project.getProperties().put( revisionKey, revision );
97 }
98
99 getLog().info( "Project at revision " + revision );
100 }
101 }
102 catch ( IOException e )
103 {
104 throw new MojoExecutionException( "Cannot run update command : ", e );
105 }
106 catch ( ScmException e )
107 {
108 throw new MojoExecutionException( "Cannot run update command : ", e );
109 }
110 }
111 }