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 this software and
9    * associated documentation files (the "Software"), to deal in the Software without restriction,
10   * including without limitation the rights to use, copy, modify, merge, publish, distribute,
11   * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
12   * furnished to do so, subject to the following conditions:
13   *
14   * The above copyright notice and this permission notice shall be included in all copies or
15   * substantial portions of the Software.
16   *
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
18   * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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   * Compile Windows message files
40   */
41  @Mojo(name = "compile-message", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
42  public class NativeMessageCompileMojo
43      extends AbstractNativeMojo
44  {
45  
46      /**
47       * Compiler Provider Type
48       * @since 1.0-alpha-2
49       */
50      @Parameter(defaultValue = "msvc", required = true)
51      private String provider;
52  
53      /**
54       * Use this field to override provider specific message compiler executable
55       * @since 1.0-alpha-2
56       */
57      @Parameter
58      private String messageCompilerExecutable;
59  
60      /**
61       * Additional Compiler options
62       * @since 1.0-alpha-2
63       */
64      @Parameter
65      private List messageCompilerOptions;
66  
67      /**
68       * List of message files to compile
69       * @since 1.0-alpha-2
70       */
71      @Parameter(required = true)
72      protected File[] messageFiles;
73  
74      /**
75       * Where to place the compiler object files
76       * @since 1.0-alpha-2
77       */
78      @Parameter(defaultValue = "${project.build.directory}", required = true)
79      protected File messageCompilerOutputDirectory;
80  
81      /**
82       * Internal
83       * @since 1.0-alpha-2
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 }