InstructionsPlugin 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.io.File;
    23  import java.io.FileNotFoundException;
    24  import java.io.IOException;
    25  import java.util.Map;
    26  import java.util.Properties;
    27
    28  import org.apache.maven.plugin.MojoExecutionException;
    29  import org.apache.maven.plugin.MojoFailureException;
    30  import org.apache.maven.project.MavenProject;
    31
    32  import aQute.bnd.osgi.Jar;
    33
    34
    35  /**
    36   * Generate BND instructions for this project
    37   *
    38   * @goal instructions
    39   * @requiresDependencyResolution test
    40   * @threadSafe
    41   */
    42  public class InstructionsPlugin extends BundlePlugin
    43  {
    44      protected void execute( MavenProject project, Map instructions, Properties properties, Jar[] classpath )
    45          throws MojoExecutionException
    46      {
    47          if ( dumpInstructions == null )
    48          {
    49              dumpInstructions = new File( getBuildDirectory(), "instructions.bnd" );
    50          }
    51
    52          try
    53          {
    54              addMavenInstructions( project, getOSGiBuilder( project, instructions, properties, classpath ) );
    55          }
    56          catch ( FileNotFoundException e )
    57          {
    58              throw new MojoExecutionException( "Cannot find " + e.getMessage(), e );
    59          }
    60          catch ( IOException e )
    61          {
    62              throw new MojoExecutionException( "Error trying to generate instructions", e );
    63          }
    64          catch ( MojoFailureException e )
    65          {
    66              getLog().error( e.getLocalizedMessage() );
    67              throw new MojoExecutionException( "Error(s) found in instructions", e );
    68          }
    69          catch ( Exception e )
    70          {
    71              getLog().error( "An internal error occurred", e );
    72              throw new MojoExecutionException( "Internal error in maven-bundle-plugin", e );
    73          }
    74      }
    75  }