View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.felix.bundleplugin;
20  
21  
22  import java.util.LinkedHashMap;
23  import java.util.Map;
24  
25  import org.apache.maven.plugin.AbstractMojo;
26  import org.apache.maven.plugin.MojoExecutionException;
27  import org.apache.maven.plugin.MojoFailureException;
28  import org.apache.maven.plugins.annotations.Mojo;
29  import org.apache.maven.plugins.annotations.Parameter;
30  import org.apache.maven.project.MavenProject;
31  import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
32  import org.apache.maven.shared.osgi.Maven2OsgiConverter;
33  
34  
35  /**
36   * Clean OSGi versions, ie convert a group of versions to OSGi format.
37   */
38  @Mojo( name = "cleanVersions", threadSafe = true )
39  public class VersionCleanerPlugin extends AbstractMojo
40  {
41  
42      /**
43       * The BND instructions for the bundle.
44       */
45      @Parameter
46      private Map<String, String> versions = new LinkedHashMap<String, String>();
47  
48      /**
49       * The Maven project.
50       */
51      @Parameter( defaultValue = "${project}", readonly = true, required = true )
52      private MavenProject project;
53  
54      private Maven2OsgiConverter maven2OsgiConverter = new DefaultMaven2OsgiConverter();
55  
56  
57      public Maven2OsgiConverter getMaven2OsgiConverter()
58      {
59          return maven2OsgiConverter;
60      }
61  
62  
63      public void setMaven2OsgiConverter( Maven2OsgiConverter maven2OsgiConverter )
64      {
65          this.maven2OsgiConverter = maven2OsgiConverter;
66      }
67  
68  
69      public void execute() throws MojoExecutionException, MojoFailureException
70      {
71          for ( String name : versions.keySet() )
72          {
73              String version = versions.get( name );
74              String osgi = maven2OsgiConverter.getVersion( version );
75              project.getProperties().put( name, osgi );
76          }
77      }
78  }