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