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