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