View Javadoc

1   package com.sourcesense.maven;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.text.MessageFormat;
20  
21  import org.apache.maven.plugin.AbstractMojo;
22  import org.apache.maven.plugin.MojoExecutionException;
23  import org.apache.maven.project.MavenProject;
24  
25  /***
26   * Goal which pushes a stripped version number in the maven project properties,
27   * removing the suffix after the configured separator into the project variable
28   * noSnapshotVersion
29   * 
30   * @goal strip
31   * @phase initialize
32   * 
33   */
34  public class StripMojo extends AbstractMojo {
35  	private static final String RESULT_PROPERTY_NAME = "noSnapshotVersion";
36  	
37  	/***
38  	 * Current version of the project
39  	 * 
40  	 * @parameter expression="${project.version}" default-value="3.0.0-SNAPSHOT"
41  	 * @required
42  	 */
43  	private String version;
44  
45  	public MavenProject getProject() {
46  		return project;
47  	}
48  
49  	/***
50  	 * The Maven project
51  	 * 
52  	 * @parameter expression="${project}"
53  	 * @required
54  	 */
55  	private MavenProject project;
56  
57  	/***
58  	 * The separator used to identify and strip the suffix
59  	 * 
60  	 * @parameter expression="${separator}" default-value="-"
61  	 * @required
62  	 */
63  	private String separator;
64  	
65  	/***
66  	 * The Maven Projec property the stripped version is pushed into
67  	 * 
68  	 * @parameter expression="${propertyName}" default-value="noSnapshotVersion"
69  	 * @required
70  	 */
71  	private String propertyName;
72  
73  
74  	public void execute() throws MojoExecutionException {
75  		int separatorIndex = version.indexOf(separator);
76  		String noSnapshotVersion = version;
77  		if (separatorIndex > -1) {
78  			noSnapshotVersion = version.substring(0, separatorIndex);
79  		}
80  		getLog().info(
81  				MessageFormat.format("Storing " + propertyName
82  						+ ": {0} ", new Object[] { noSnapshotVersion }));
83  		project.getProperties().put(propertyName, noSnapshotVersion);
84  	}
85  
86  	public String getPropertyName() {
87  		return propertyName;
88  	}
89  
90  	public void setPropertyName(String propertyName) {
91  		this.propertyName = propertyName;
92  	}
93  
94  	public void setSeparator(String separator) {
95  		this.separator = separator;
96  	}
97  }