VersionCleanerPlugin xref

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