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.cpptasks.compiler;
21  
22  import org.apache.tools.ant.BuildException;
23  
24  import com.github.maven_nar.cpptasks.CCTask;
25  import com.github.maven_nar.cpptasks.LinkerParam;
26  import com.github.maven_nar.cpptasks.ProcessorParam;
27  import com.github.maven_nar.cpptasks.TargetInfo;
28  import com.github.maven_nar.cpptasks.VersionInfo;
29  
30  /**
31   * A configuration for a command line linker
32   *
33   * @author Curt Arnold
34   */
35  public final class CommandLineLinkerConfiguration implements LinkerConfiguration {
36    private/* final */String[][] args;
37    private final/* final */String identifier;
38    private String[] libraryNames;
39    private final/* final */CommandLineLinker linker;
40    private final/* final */boolean map;
41    private final/* final */ProcessorParam[] params;
42    private final/* final */boolean rebuild;
43    private/* final */String commandPath;
44    private final boolean debug;
45    private final String startupObject;
46  
47    public CommandLineLinkerConfiguration(final CommandLineLinker linker, final String identifier, final String[][] args,
48        final ProcessorParam[] params, final boolean rebuild, final boolean map, final boolean debug,
49        final String[] libraryNames, final String startupObject) {
50      this(linker, identifier, args, params, rebuild, map, debug, libraryNames, startupObject, null);
51    }
52  
53    public CommandLineLinkerConfiguration(final CommandLineLinker linker, final String identifier, final String[][] args,
54        final ProcessorParam[] params, final boolean rebuild, final boolean map, final boolean debug,
55        final String[] libraryNames, final String startupObject, final String commandPath) {
56      if (linker == null) {
57        throw new NullPointerException("linker");
58      }
59      if (args == null) {
60        throw new NullPointerException("args");
61      } else {
62        this.args = args.clone();
63      }
64      this.linker = linker;
65      this.params = params.clone();
66      this.rebuild = rebuild;
67      this.identifier = identifier;
68      this.map = map;
69      this.debug = debug;
70      if (libraryNames == null) {
71        this.libraryNames = new String[0];
72      } else {
73        this.libraryNames = libraryNames.clone();
74      }
75      this.startupObject = startupObject;
76      this.commandPath = commandPath;
77    }
78  
79    @Override
80    public int bid(final String filename) {
81      return this.linker.bid(filename);
82    }
83  
84    public final String getCommandPath() {
85      return this.commandPath;
86    }
87  
88    public String[] getEndArguments() {
89      final String[] clone = this.args[1].clone();
90      return clone;
91    }
92  
93    /**
94     * Returns a string representation of this configuration. Should be
95     * canonical so that equivalent configurations will have equivalent string
96     * representations
97     */
98    @Override
99    public String getIdentifier() {
100     return this.identifier;
101   }
102 
103   public String[] getLibraryNames() {
104     final String[] clone = this.libraryNames.clone();
105     return clone;
106   }
107 
108   @Override
109   public Linker getLinker() {
110     return this.linker;
111   }
112 
113   public boolean getMap() {
114     return this.map;
115   }
116 
117   @Override
118   public String[] getOutputFileNames(final String inputFile, final VersionInfo versionInfo) {
119     return this.linker.getOutputFileNames(inputFile, versionInfo);
120   }
121 
122   @Override
123   public LinkerParam getParam(final String name) {
124     for (final ProcessorParam param : this.params) {
125       if (name.equals(param.getName())) {
126         return (LinkerParam) param;
127       }
128     }
129     return null;
130   }
131 
132   @Override
133   public ProcessorParam[] getParams() {
134     return this.params;
135   }
136 
137   public String[] getPreArguments() {
138     final String[] clone = this.args[0].clone();
139     return clone;
140   }
141 
142   @Override
143   public boolean getRebuild() {
144     return this.rebuild;
145   }
146 
147   public String getStartupObject() {
148     return this.startupObject;
149   }
150 
151   @Override
152   public boolean isDebug() {
153     return this.debug;
154   }
155 
156   @Override
157   public void link(final CCTask task, final TargetInfo linkTarget) throws BuildException {
158     //
159     // AllSourcePath's include any syslibsets
160     //
161     final String[] sourcePaths = linkTarget.getAllSourcePaths();
162     this.linker.link(task, linkTarget.getOutput(), sourcePaths, this);
163   }
164 
165   public final void setCommandPath(final String commandPath) {
166     this.commandPath = commandPath;
167   }
168 
169   @Override
170   public String toString() {
171     return this.identifier;
172   }
173 }