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