1 package org.codehaus.mojo.natives.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
41
42 @Mojo(name = "ranlib", defaultPhase = LifecyclePhase.PACKAGE)
43 public class NativeRanlibMojo
44 extends AbstractNativeMojo
45 {
46
47
48
49
50
51 @Parameter(defaultValue = "${project.build.directory}", required = true)
52 protected File ranlibOutputDirectory;
53
54
55
56
57
58 @Parameter(defaultValue = "default", required = true)
59 private String provider;
60
61
62
63
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 }