View Javadoc

1   /*
2    * #%L
3    * Native ARchive plugin for Maven
4    * %%
5    * Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   * http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package com.github.maven_nar;
21  
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.plugins.annotations.Parameter;
27  import org.apache.tools.ant.Project;
28  
29  /**
30   * @author Mark Donszelmann
31   */
32  public abstract class AbstractCompileMojo extends AbstractDependencyMojo {
33  
34    /**
35     * C++ Compiler
36     */
37    @Parameter
38    private Cpp cpp;
39  
40    /**
41     * C Compiler
42     */
43    @Parameter
44    private C c;
45  
46    /**
47     * Fortran Compiler
48     */
49    @Parameter
50    private Fortran fortran;
51  
52    /**
53     * Resource Compiler
54     */
55    @Parameter
56    private Resource resource;
57  
58    /**
59     * IDL Compiler
60     */
61    @Parameter
62    private IDL idl;
63  
64    /**
65     * Message Compiler
66     */
67    @Parameter
68    private Message message;
69  
70    /**
71     * By default NAR compile will attempt to compile using all known compilers
72     * against files in the directories specified by convention.
73     * This allows configuration to a reduced set, you will have to specify each
74     * compiler to use in the configuration.
75     */
76    @Parameter(defaultValue = "false")
77    protected boolean onlySpecifiedCompilers;
78  
79    /**
80     * Do we log commands that is executed to produce the end-result?
81     * Conception was to allow eclipse to sniff out include-paths from compile.
82     */
83    @Parameter
84    protected int commandLogLevel = Project.MSG_VERBOSE;
85  
86    /**
87     * Maximum number of Cores/CPU's to use. 0 means unlimited.
88     */
89    @Parameter
90    private int maxCores = 0;
91  
92    /**
93     * Fail on compilation/linking error.
94     */
95    @Parameter(defaultValue = "true", required = true)
96    private boolean failOnError;
97  
98    /**
99     * Sets the type of runtime library, possible values "dynamic", "static".
100    */
101   @Parameter(defaultValue = "dynamic", required = true)
102   private String runtime;
103 
104   /**
105    * Set use of libtool. If set to true, the "libtool " will be prepended to the
106    * command line for compatible
107    * processors.
108    */
109   @Parameter(defaultValue = "false", required = true)
110   private boolean libtool;
111 
112   /**
113    * List of tests to create
114    */
115   @Parameter
116   private List tests;
117 
118   /**
119    * Java info for includes and linking
120    */
121   @Parameter
122   private Java java;
123 
124   /**
125    * Flag to cpptasks to indicate whether linker options should be decorated or
126    * not
127    */
128   @Parameter
129   protected boolean decorateLinkerOptions;
130 
131   private List/* <String> */dependencyLibOrder;
132 
133   private Project antProject;
134 
135   protected final boolean failOnError(final AOL aol) throws MojoExecutionException {
136     return getNarInfo().getProperty(aol, "failOnError", this.failOnError);
137   }
138 
139   protected final Project getAntProject() {
140     if (this.antProject == null) {
141       // configure ant project
142       this.antProject = new Project();
143       this.antProject.setName("NARProject");
144       this.antProject.addBuildListener(new NarLogger(getLog()));
145     }
146     return this.antProject;
147   }
148 
149   protected final C getC() {
150     if (this.c == null && !this.onlySpecifiedCompilers) {
151       setC(new C());
152     }
153     return this.c;
154   }
155 
156   protected final Cpp getCpp() {
157     if (this.cpp == null && !this.onlySpecifiedCompilers) {
158       setCpp(new Cpp());
159     }
160     return this.cpp;
161   }
162 
163   protected final List/* <String> */getDependencyLibOrder() {
164     return this.dependencyLibOrder;
165   }
166 
167   protected final Fortran getFortran() {
168     if (this.fortran == null && !this.onlySpecifiedCompilers) {
169       setFortran(new Fortran());
170     }
171     return this.fortran;
172   }
173 
174   protected final IDL getIdl() {
175     if (this.idl == null && !this.onlySpecifiedCompilers) {
176       setIdl(new IDL());
177     }
178     return this.idl;
179   }
180 
181   protected final Java getJava() {
182     if (this.java == null) {
183       this.java = new Java();
184     }
185     this.java.setAbstractCompileMojo(this);
186     return this.java;
187   }
188 
189   protected final int getMaxCores(final AOL aol) throws MojoExecutionException {
190     return getNarInfo().getProperty(aol, "maxCores", this.maxCores);
191   }
192 
193   protected final Message getMessage() {
194     if (this.message == null && !this.onlySpecifiedCompilers) {
195       setMessage(new Message());
196     }
197     return this.message;
198   }
199 
200   protected final String getOutput(final AOL aol, final String type) throws MojoExecutionException {
201     return getNarInfo().getOutput(aol, getOutput(!Library.EXECUTABLE.equals(type)));
202   }
203 
204   protected final Resource getResource() {
205     if (this.resource == null && !this.onlySpecifiedCompilers) {
206       setResource(new Resource());
207     }
208     return this.resource;
209   }
210 
211   protected final String getRuntime(final AOL aol) throws MojoExecutionException {
212     return getNarInfo().getProperty(aol, "runtime", this.runtime);
213   }
214 
215   protected final List getTests() {
216     if (this.tests == null) {
217       this.tests = Collections.emptyList();
218     }
219     return this.tests;
220   }
221 
222   public void setC(final C c) {
223     this.c = c;
224     c.setAbstractCompileMojo(this);
225   }
226 
227   public void setCpp(final Cpp cpp) {
228     this.cpp = cpp;
229     cpp.setAbstractCompileMojo(this);
230   }
231 
232   public final void setDependencyLibOrder(final List/* <String> */order) {
233     this.dependencyLibOrder = order;
234   }
235 
236   public void setFortran(final Fortran fortran) {
237     this.fortran = fortran;
238     fortran.setAbstractCompileMojo(this);
239   }
240 
241   public void setIdl(final IDL idl) {
242     this.idl = idl;
243     idl.setAbstractCompileMojo(this);
244   }
245 
246   public void setMessage(final Message message) {
247     this.message = message;
248     message.setAbstractCompileMojo(this);
249   }
250 
251   public void setResource(final Resource resource) {
252     this.resource = resource;
253     resource.setAbstractCompileMojo(this);
254   }
255 
256   protected final boolean useLibtool(final AOL aol) throws MojoExecutionException {
257     return getNarInfo().getProperty(aol, "libtool", this.libtool);
258   }
259 
260 }