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.project.MavenProject;
29  import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
30  import org.apache.maven.shared.osgi.Maven2OsgiConverter;
31  
32  
33  /**
34   * Convert a group of versions to OSGi format.
35   *
36   * @goal cleanVersions
37   * @description clean OSGi versions
38   * @threadSafe
39   */
40  public class VersionCleanerPlugin extends AbstractMojo
41  {
42  
43      /**
44       * The BND instructions for the bundle.
45       *
46       * @parameter
47       */
48      private Map versions = new LinkedHashMap();
49  
50      /**
51       * The Maven project.
52       *
53       * @parameter expression="${project}"
54       * @required
55       * @readonly
56       */
57      private MavenProject project;
58  
59      private Maven2OsgiConverter maven2OsgiConverter = new DefaultMaven2OsgiConverter();
60  
61  
62      public Maven2OsgiConverter getMaven2OsgiConverter()
63      {
64          return maven2OsgiConverter;
65      }
66  
67  
68      public void setMaven2OsgiConverter( Maven2OsgiConverter maven2OsgiConverter )
69      {
70          this.maven2OsgiConverter = maven2OsgiConverter;
71      }
72  
73  
74      public void execute() throws MojoExecutionException, MojoFailureException
75      {
76          for ( Object key : versions.keySet() )
77          {
78              String name = ( String ) key;
79              String version = ( String ) versions.get( key );
80              String osgi = maven2OsgiConverter.getVersion( version );
81              project.getProperties().put( name, osgi );
82          }
83      }
84  }