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.io.File;
23  
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.apache.maven.plugin.MojoFailureException;
26  import org.apache.maven.plugins.annotations.LifecyclePhase;
27  import org.apache.maven.plugins.annotations.Mojo;
28  import org.apache.maven.plugins.annotations.Parameter;
29  import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
30  
31  /**
32   * Validates the configuration of the NAR project (aol and pom)
33   *
34   * @author Mark Donszelmann
35   */
36  @Mojo(name = "nar-validate", defaultPhase = LifecyclePhase.VALIDATE)
37  public class NarValidateMojo extends AbstractCompileMojo {
38    /**
39     * Source directory for GNU style project
40     */
41    @Parameter(defaultValue = "${basedir}/src/gnu", required = true)
42    private File gnuSourceDirectory;
43  
44    @Override
45    protected ScopeFilter/* <Artifact> */getArtifactScopeFilter() {
46      return null;
47    }
48  
49    @Override
50    public final void narExecute() throws MojoExecutionException, MojoFailureException {
51      // super.narExecute();
52      if (this.skip) {
53        getLog().info(getClass().getName() + " skipped");
54        return;
55      }
56      
57      // check aol
58      final AOL aol = getAOL();
59      getLog().info("Using AOL: " + aol);
60  
61      // check linker exists in retrieving the version number
62      final Linker linker = getLinker();
63      getLog().debug("Using linker version: " + linker.getVersion(this));
64  
65      // check compilers
66      int noOfCompilers = 0;
67      if (this.onlySpecifiedCompilers) {
68        if (getCpp() != null && getCpp().getName() != null) {
69          noOfCompilers++;
70          // need includes
71          if (getCpp().getIncludes(Compiler.MAIN).isEmpty()) {
72            throw new MojoExecutionException("No includes defined for compiler " + getCpp().getName());
73          }
74        }
75  
76        if (getC() != null && getC().getName() != null) {
77          noOfCompilers++;
78          // need includes
79          if (getC().getIncludes(Compiler.MAIN).isEmpty()) {
80            throw new MojoExecutionException("No includes defined for compiler " + getC().getName());
81          }
82        }
83  
84        if (getFortran() != null && getFortran().getName() != null) {
85          noOfCompilers++;
86          // need includes
87          if (getFortran().getIncludes(Compiler.MAIN).isEmpty()) {
88            throw new MojoExecutionException("No includes defined for compiler " + getFortran().getName());
89          }
90        }
91  
92        // at least one compiler has to be defined
93        // OR
94        // a <gnuSourceDirectory> is configured.
95        if (noOfCompilers == 0 && (this.gnuSourceDirectory == null || !this.gnuSourceDirectory.exists())) {
96          throw new MojoExecutionException("No compilers defined for linker " + linker.getName() + ", and no"
97              + " <gnuSourceDirectory> is defined.  Either define a compiler or a linker.");
98        }
99      }
100   }
101 }