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 org.apache.maven.plugin.MojoExecutionException;
25 import org.codehaus.mojo.natives.NativeBuildException;
26 import org.codehaus.mojo.natives.NativeSources;
27 import org.codehaus.mojo.natives.compiler.ResourceCompiler;
28 import org.codehaus.mojo.natives.compiler.ResourceCompilerConfiguration;
29 import org.codehaus.mojo.natives.manager.NoSuchNativeProviderException;
30 import org.codehaus.mojo.natives.manager.ResourceCompilerManager;
31 import org.codehaus.plexus.util.FileUtils;
32
33 import java.io.File;
34 import java.util.List;
35 import org.apache.maven.plugins.annotations.Component;
36 import org.apache.maven.plugins.annotations.LifecyclePhase;
37 import org.apache.maven.plugins.annotations.Mojo;
38 import org.apache.maven.plugins.annotations.Parameter;
39
40
41
42
43 @Mojo(name = "resource-compile", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
44 public class NativeResourceCompileMojo
45 extends AbstractNativeMojo
46 {
47
48
49
50
51
52 @Parameter(defaultValue = "msvc", required = true)
53 private String provider;
54
55
56
57
58
59 @Parameter
60 private String resourceCompilerExecutable;
61
62
63
64
65
66 @Parameter
67 private List resourceCompilerOptions;
68
69
70
71
72
73 @Parameter
74 private NativeSources[] resources;
75
76
77
78
79 @Parameter(defaultValue = "${project.build.directory}", required = true)
80 protected File resourceCompilerOutputDirectory;
81
82
83
84
85
86 @Component
87 private ResourceCompilerManager manager;
88
89 public void execute()
90 throws MojoExecutionException
91 {
92
93 if ( !this.resourceCompilerOutputDirectory.exists() )
94 {
95 this.resourceCompilerOutputDirectory.mkdirs();
96 }
97
98 FileUtils.mkdir( project.getBuild().getDirectory() );
99
100 ResourceCompiler compiler = this.getResourceCompiler();
101
102 ResourceCompilerConfiguration config = new ResourceCompilerConfiguration();
103 config.setExecutable( this.resourceCompilerExecutable );
104 config.setWorkingDirectory( this.workingDirectory );
105 config.setOptions( NativeMojoUtils.trimParams( this.resourceCompilerOptions ) );
106 config.setOutputDirectory( this.resourceCompilerOutputDirectory );
107 config.setEnvFactory( this.getEnvFactory() );
108
109 try
110 {
111 List resourceOutputFiles;
112 resourceOutputFiles = compiler.compile( config, this.resources );
113
114 this.saveCompilerOutputFilePaths( resourceOutputFiles );
115 }
116 catch ( NativeBuildException e )
117 {
118 throw new MojoExecutionException( e.getMessage(), e );
119 }
120
121 }
122
123 private ResourceCompiler getResourceCompiler()
124 throws MojoExecutionException
125 {
126 ResourceCompiler rc;
127
128 try
129 {
130 rc = this.manager.getResourceCompiler( this.provider );
131
132 }
133 catch ( NoSuchNativeProviderException pe )
134 {
135 throw new MojoExecutionException( pe.getMessage() );
136 }
137
138 return rc;
139 }
140 }