View Javadoc
1   package org.codehaus.mojo.natives.plugin;
2   
3   /*
4    * The MIT License
5    *
6    * Copyright (c) 2004, The Codehaus
7    *
8    * Permission is hereby granted, free of charge, to any person obtaining a copy of
9    * this software and associated documentation files (the "Software"), to deal in
10   * the Software without restriction, including without limitation the rights to
11   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12   * of the Software, and to permit persons to whom the Software is furnished to do
13   * so, subject to the following conditions:
14   *
15   * The above copyright notice and this permission notice shall be included in all
16   * copies or substantial portions of the Software.
17   *
18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24   * SOFTWARE.
25   */
26  
27  import java.io.File;
28  
29  import org.apache.maven.plugin.MojoExecutionException;
30  import org.apache.maven.plugins.annotations.Component;
31  import org.apache.maven.plugins.annotations.LifecyclePhase;
32  import org.apache.maven.plugins.annotations.Mojo;
33  import org.apache.maven.plugins.annotations.Parameter;
34  import org.codehaus.mojo.natives.NativeBuildException;
35  import org.codehaus.mojo.natives.linker.Ranlib;
36  import org.codehaus.mojo.natives.manager.NoSuchNativeProviderException;
37  import org.codehaus.mojo.natives.manager.RanlibManager;
38  
39  /**
40   * ranlib a Unix linker output file
41   */
42  @Mojo(name = "ranlib", defaultPhase = LifecyclePhase.PACKAGE)
43  public class NativeRanlibMojo
44      extends AbstractNativeMojo
45  {
46  
47      /**
48       * Where to place the final packaging
49       * @since 1.0-alpha-2
50       */
51      @Parameter(defaultValue = "${project.build.directory}", required = true)
52      protected File ranlibOutputDirectory;
53  
54      /**
55       * Ranlib Provider.
56       * @since 1.0-alpha-2
57       */
58      @Parameter(defaultValue = "default", required = true)
59      private String provider;
60  
61      /**
62       * To look up ranlib implementation
63       * @since 1.0-alpha-2
64       */
65      @Component
66      private RanlibManager manager;
67  
68      public void execute()
69          throws MojoExecutionException
70      {
71  
72          try
73          {
74              String finalName = this.project.getBuild().getFinalName();
75  
76              String fileExt = this.project.getArtifact().getArtifactHandler().getExtension();
77  
78              File outputFile = new File( this.ranlibOutputDirectory.getAbsolutePath() + "/" + finalName + "." + fileExt );
79  
80              Ranlib ranlib = this.getRanlib();
81  
82              ranlib.run( outputFile );
83          }
84          catch ( NativeBuildException e )
85          {
86              throw new MojoExecutionException( "Error executing ranlib.", e );
87          }
88      }
89  
90      private Ranlib getRanlib()
91          throws MojoExecutionException
92      {
93          Ranlib ranlib;
94  
95          try
96          {
97              ranlib = this.manager.getRanlib( this.provider );
98  
99          }
100         catch ( NoSuchNativeProviderException pe )
101         {
102             throw new MojoExecutionException( pe.getMessage() );
103         }
104 
105         return ranlib;
106     }
107 
108 }