Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TagMojo |
|
| 9.0;9 |
1 | package org.apache.maven.scm.plugin; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import org.apache.maven.plugin.MojoExecutionException; | |
23 | import org.apache.maven.scm.ScmException; | |
24 | import org.apache.maven.scm.ScmTagParameters; | |
25 | import org.apache.maven.scm.command.tag.TagScmResult; | |
26 | import org.apache.maven.scm.provider.ScmProvider; | |
27 | import org.apache.maven.scm.repository.ScmRepository; | |
28 | ||
29 | import java.io.IOException; | |
30 | import java.text.SimpleDateFormat; | |
31 | import java.util.Date; | |
32 | ||
33 | /** | |
34 | * Tag the project. | |
35 | * | |
36 | * @author <a href="evenisse@apache.org">Emmanuel Venisse</a> | |
37 | * @author <a href="saden1@gmil.com">Sharmarke Aden</a> | |
38 | * @version $Id: TagMojo.java 757186 2009-03-22 13:23:00Z olamy $ | |
39 | * @goal tag | |
40 | * @aggregator | |
41 | */ | |
42 | 0 | public class TagMojo |
43 | extends AbstractScmMojo | |
44 | { | |
45 | /** | |
46 | * The tag name. | |
47 | * | |
48 | * @parameter expression="${tag}" | |
49 | * @required | |
50 | */ | |
51 | private String tag; | |
52 | ||
53 | /** | |
54 | * The message applied to the tag creation. | |
55 | * | |
56 | * @parameter expression="${message}" | |
57 | */ | |
58 | private String message; | |
59 | ||
60 | /** | |
61 | * Set the timestamp format. | |
62 | * | |
63 | * @parameter expression="${timestampFormat}" default-value="yyyyMMddHHmmss" | |
64 | */ | |
65 | private String timestampFormat; | |
66 | ||
67 | /** | |
68 | * Use timestamp tagging. | |
69 | * | |
70 | * @parameter expression="${addTimestamp}" default-value="false" | |
71 | */ | |
72 | private boolean addTimestamp; | |
73 | ||
74 | /** | |
75 | * Define the timestamp position (end or begin). | |
76 | * | |
77 | * @parameter expression="${timestampPosition}" default-value="end" | |
78 | */ | |
79 | private String timestampPosition; | |
80 | ||
81 | /** | |
82 | * Timestamp tag prefix. | |
83 | * | |
84 | * @parameter expression="${timestampPrefix}" default-value="-" | |
85 | */ | |
86 | private String timestampPrefix; | |
87 | ||
88 | /** | |
89 | * currently only implemented with svn scm. Enable a workaround to prevent issue | |
90 | * due to svn client > 1.5.0 (http://jira.codehaus.org/browse/SCM-406) | |
91 | * | |
92 | * | |
93 | * @parameter expression="${remoteTagging}" default-value="true" | |
94 | * @since 1.2 | |
95 | */ | |
96 | private boolean remoteTagging; | |
97 | ||
98 | /** {@inheritDoc} */ | |
99 | public void execute() | |
100 | throws MojoExecutionException | |
101 | { | |
102 | 0 | super.execute(); |
103 | ||
104 | try | |
105 | { | |
106 | 0 | SimpleDateFormat dateFormat = null; |
107 | 0 | String tagTimestamp = ""; |
108 | 0 | String finalTag = tag; |
109 | ||
110 | 0 | if ( addTimestamp ) |
111 | { | |
112 | try | |
113 | { | |
114 | 0 | getLog().info( "Using timestamp pattern '" + timestampFormat + "'" ); |
115 | 0 | dateFormat = new SimpleDateFormat( timestampFormat ); |
116 | 0 | tagTimestamp = dateFormat.format( new Date() ); |
117 | 0 | getLog().info( "Using timestamp '" + tagTimestamp + "'" ); |
118 | } | |
119 | 0 | catch ( IllegalArgumentException e ) |
120 | { | |
121 | 0 | String msg = "The timestamp format '" + timestampFormat + "' is invalid."; |
122 | 0 | getLog().error( msg, e ); |
123 | 0 | throw new MojoExecutionException( msg, e ); |
124 | 0 | } |
125 | ||
126 | 0 | if ( "end".equals( timestampPosition ) ) |
127 | { | |
128 | 0 | finalTag += timestampPrefix + tagTimestamp; |
129 | } | |
130 | else | |
131 | { | |
132 | 0 | finalTag = tagTimestamp + timestampPrefix + finalTag; |
133 | } | |
134 | } | |
135 | ||
136 | 0 | ScmRepository repository = getScmRepository(); |
137 | 0 | ScmProvider provider = getScmManager().getProviderByRepository( repository ); |
138 | ||
139 | 0 | finalTag = provider.sanitizeTagName( finalTag ); |
140 | 0 | getLog().info( "Final Tag Name: '" + finalTag + "'" ); |
141 | ||
142 | 0 | ScmTagParameters scmTagParameters = new ScmTagParameters( message); |
143 | 0 | scmTagParameters.setRemoteTagging( remoteTagging ); |
144 | ||
145 | 0 | TagScmResult result = provider.tag( repository, getFileSet(), finalTag, scmTagParameters); |
146 | ||
147 | 0 | checkResult( result ); |
148 | } | |
149 | 0 | catch ( IOException e ) |
150 | { | |
151 | 0 | throw new MojoExecutionException( "Cannot run tag command : ", e ); |
152 | } | |
153 | 0 | catch ( ScmException e ) |
154 | { | |
155 | 0 | throw new MojoExecutionException( "Cannot run tag command : ", e ); |
156 | 0 | } |
157 | 0 | } |
158 | } |