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 import java.io.File;
25
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugins.annotations.Component;
28 import org.apache.maven.plugins.annotations.LifecyclePhase;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.codehaus.mojo.natives.NativeBuildException;
32 import org.codehaus.mojo.natives.linker.Manifest;
33 import org.codehaus.mojo.natives.linker.ManifestConfiguration;
34 import org.codehaus.mojo.natives.manager.ManifestManager;
35 import org.codehaus.mojo.natives.manager.NoSuchNativeProviderException;
36
37
38
39
40
41 @Mojo(name = "manifest", defaultPhase = LifecyclePhase.PACKAGE)
42 public class NativeManifestMojo
43 extends AbstractNativeMojo
44 {
45
46
47
48
49 @Parameter(defaultValue = "msvc", required = true)
50 private String provider;
51
52
53
54
55
56 @Parameter(defaultValue = "manifest", required = true)
57 private String manifestExtension;
58
59
60
61
62
63 @Parameter(defaultValue = "false")
64 private boolean checkStaleLinkage;
65
66
67
68
69
70 @Component
71 private ManifestManager manager;
72
73 public void execute()
74 throws MojoExecutionException
75 {
76 File linkerOutputFile = (File) this.getPluginContext().get( LINKER_OUTPUT_PATH );
77
78 if ( !linkerOutputFile.exists() )
79 {
80
81 return;
82 }
83
84 File linkerManifestFile = new File( linkerOutputFile.getAbsolutePath() + "." + manifestExtension );
85
86 if ( !linkerManifestFile.exists() )
87 {
88
89 return;
90 }
91
92
93 try
94 {
95 ManifestConfiguration config = new ManifestConfiguration();
96
97 config.setEnvFactory( this.getEnvFactory() );
98 config.setWorkingDirectory( this.workingDirectory );
99 config.setInputFile( linkerOutputFile );
100 config.setManifestFile( linkerManifestFile );
101
102 Manifest Manifest = this.getManifest();
103
104 Manifest.run( config );
105 }
106 catch ( NativeBuildException e )
107 {
108 throw new MojoExecutionException( "Error executing Manifest.", e );
109 }
110
111 }
112
113 private Manifest getManifest()
114 throws MojoExecutionException
115 {
116 Manifest Manifest;
117
118 try
119 {
120 Manifest = this.manager.getManifest( this.provider );
121 }
122 catch ( NoSuchNativeProviderException pe )
123 {
124 throw new MojoExecutionException( pe.getMessage() );
125 }
126
127 return Manifest;
128 }
129
130 }