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  
30  /**
31   * Runs make on the GNU style generated Makefile
32   * 
33   * @author Mark Donszelmann
34   */
35  @Mojo(name = "nar-gnu-make", requiresProject = true, defaultPhase = LifecyclePhase.COMPILE)
36  public class NarGnuMakeMojo extends AbstractGnuMojo {
37    /**
38     * Space delimited list of arguments to pass to make
39     */
40    @Parameter(defaultValue = "")
41    private String gnuMakeArgs;
42  
43    /**
44     * Comma delimited list of environment variables to setup before running make
45     */
46    @Parameter(defaultValue = "")
47    private String gnuMakeEnv;
48    
49    /**
50     * Skip running of make.
51     * Useful if you just want to run the configure step for generating source.
52     */
53    @Parameter(property = "nar.gnu.make.skip")
54    private boolean gnuMakeSkip;
55  
56    /**
57     * Boolean to control if we should skip 'make install' after the make
58     */
59    @Parameter
60    private boolean gnuMakeInstallSkip;
61  
62    @Override
63    public final void narExecute() throws MojoExecutionException, MojoFailureException {
64      if (!useGnu() || gnuMakeSkip) {
65        return;
66      }
67  
68      final File srcDir = getGnuAOLSourceDirectory();
69      if (srcDir.exists()) {
70        String[] args = null;
71        String[] env = null;
72  
73        if (this.gnuMakeArgs != null) {
74          args = this.gnuMakeArgs.split(" ");
75        }
76        if (this.gnuMakeEnv != null) {
77          env = this.gnuMakeEnv.split(",");
78        }
79  
80        getLog().info("Running GNU make");
81        int result = NarUtil.runCommand("make", args, srcDir, env, getLog());
82        if (result != 0) {
83          throw new MojoExecutionException("'make' errorcode: " + result);
84        }
85  
86        if (!this.gnuMakeInstallSkip) {
87          getLog().info("Running make install");
88          if (args != null) {
89            this.gnuMakeArgs = this.gnuMakeArgs + " install";
90            args = this.gnuMakeArgs.split(" ");
91          } else {
92            args = new String[] {
93              "install"
94            };
95          }
96          result = NarUtil.runCommand("make", args, srcDir, null, getLog());
97          if (result != 0) {
98            throw new MojoExecutionException("'make install' errorcode: " + result);
99          }
100       }
101     }
102   }
103 }