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.ArrayList;
23  import java.util.List;
24  
25  import org.apache.maven.plugins.annotations.Parameter;
26  
27  /**
28   * Sets up a library to create
29   *
30   * @author Mark Donszelmann
31   */
32  public class Library implements Executable {
33  
34    public static final String STATIC = "static";
35  
36    public static final String SHARED = "shared";
37  
38    public static final String EXECUTABLE = "executable";
39  
40    public static final String JNI = "jni";
41  
42    public static final String PLUGIN = "plugin";
43  
44    public static final String NONE = "none"; // no library produced
45  
46    /**
47     * Type of the library to generate. Possible choices are: "plugin", "shared",
48     * "static", "jni" or "executable".
49     * Defaults to "shared".
50     */
51    @Parameter
52    private String type = SHARED;
53  
54    /**
55     * Type of subsystem to generate: "gui", "console", "other". Defaults to
56     * "console".
57     */
58    @Parameter
59    private String subSystem = "console";
60  
61    /**
62     * Link with stdcpp if necessary Defaults to true.
63     */
64    @Parameter(defaultValue = "true")
65    private boolean linkCPP = true;
66  
67    /**
68     * Link with fortran runtime if necessary Defaults to false.
69     */
70    @Parameter
71    private boolean linkFortran = false;
72  
73    /**
74     * Link with fortran startup, so that the gcc linker can find the "main" of
75     * fortran. Defaults to false.
76     */
77    @Parameter
78    private boolean linkFortranMain = false;
79  
80    /**
81     * If specified will create the NarSystem class with methods to load a JNI
82     * library.
83     */
84    @Parameter
85    private String narSystemPackage = null;
86  
87    /**
88     * Name of the NarSystem class
89     */
90    @Parameter(defaultValue = "NarSystem", required = true)
91    private String narSystemName = "NarSystem";
92  
93    /**
94     * The target directory into which to generate the output.
95     */
96    @Parameter(defaultValue = "${project.build.dir}/nar/nar-generated", required = true)
97    private String narSystemDirectory = "nar-generated";
98  
99    /**
100    * When true and if type is "executable" run this executable. Defaults to
101    * false;
102    */
103   @Parameter
104   private boolean run = false;
105 
106   /**
107    * Arguments to be used for running this executable. Defaults to empty list.
108    * This option is only used if run=true
109    * and type=executable.
110    */
111   @Parameter
112   private List/* <String> */args = new ArrayList();
113 
114   /**
115    * List of artifact:binding  for type of dependency to link against when there is a choice.
116    */
117   @Parameter
118   private List<String> dependencyBindings = new ArrayList<>();
119   
120   @Override
121   public final List/* <String> */getArgs() {
122     return this.args;
123   }
124 
125   public String getBinding(NarArtifact dependency) {
126     for (String dependBind : dependencyBindings ) {
127       String[] pair = dependBind.trim().split( ":", 2 );
128       if( dependency.getArtifactId().equals(pair[0].trim()) ){
129         String result = pair[1].trim();
130         if( !result.isEmpty() )
131           return result;
132       }
133     }
134     return null;
135   }
136 
137   public final String getNarSystemDirectory() {
138     return this.narSystemDirectory;
139   }
140 
141   public final String getNarSystemName() {
142     return this.narSystemName;
143   }
144 
145   public final String getNarSystemPackage() {
146     return this.narSystemPackage;
147   }
148 
149   public String getSubSystem() {
150     return this.subSystem;
151   }
152 
153   public final String getType() {
154     return this.type;
155   }
156 
157   public final boolean linkCPP() {
158     return this.linkCPP;
159   }
160 
161   public final boolean linkFortran() {
162     return this.linkFortran;
163   }
164 
165   public final boolean linkFortranMain() {
166     return this.linkFortranMain;
167   }
168 
169   @Override
170   public final boolean shouldRun() {
171     return this.run;
172   }
173 
174   // FIXME incomplete
175   @Override
176   public final String toString() {
177     final String sb = "Library: " + "type: " +
178         getType();
179     return sb;
180   }
181 }