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 @Mojo( name = "update-subprojects" )
38 public class UpdateSubprojectsMojo
39 extends AbstractScmMojo
40 {
41
42
43
44 @Parameter( property = "scmVersionType" )
45 private String scmVersionType;
46
47
48
49
50 @Parameter( property = "scmVersion" )
51 private String scmVersion;
52
53
54
55
56 @Parameter( property = "revisionKey", defaultValue = "scm.revision" )
57 private String revisionKey;
58
59
60
61
62 @Parameter( defaultValue = "${project}", required = true, readonly = true )
63 private MavenProject project;
64
65
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 )
85 {
86 project.getProperties().put( revisionKey, ( (UpdateScmResultWithRevision) result ).getRevision() );
87 }
88 }
89 }
90 catch ( IOException e )
91 {
92 throw new MojoExecutionException( "Cannot run update command : ", e );
93 }
94 catch ( ScmException e )
95 {
96 throw new MojoExecutionException( "Cannot run update command : ", e );
97 }
98 }
99 }