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 java.io.File;
23  import java.io.IOException;
24  
25  import org.apache.tools.ant.types.Environment;
26  
27  import com.github.maven_nar.cpptasks.CCTask;
28  import com.github.maven_nar.cpptasks.LinkerDef;
29  import com.github.maven_nar.cpptasks.ProcessorDef;
30  import com.github.maven_nar.cpptasks.TargetDef;
31  import com.github.maven_nar.cpptasks.TargetMatcher;
32  import com.github.maven_nar.cpptasks.VersionInfo;
33  
34  /**
35   * An abstract Linker implementation.
36   *
37   * @author Adam Murdoch
38   */
39  public abstract class AbstractLinker extends AbstractProcessor implements Linker {
40    public AbstractLinker(final String[] objExtensions, final String[] ignoredExtensions) {
41      super(objExtensions, ignoredExtensions);
42    }
43  
44    /**
45     * Adds source or object files to the bidded fileset to
46     * support version information.
47     * 
48     * @param versionInfo
49     *          version information
50     * @param linkType
51     *          link type
52     * @param isDebug
53     *          true if debug build
54     * @param outputFile
55     *          name of generated executable
56     * @param objDir
57     *          directory for generated files
58     * @param matcher
59     *          bidded fileset
60     */
61    @Override
62    public void addVersionFiles(final VersionInfo versionInfo, final LinkType linkType, final File outputFile,
63        final boolean isDebug, final File objDir, final TargetMatcher matcher) throws IOException {
64      if (versionInfo == null) {
65        throw new NullPointerException("versionInfo");
66      }
67      if (linkType == null) {
68        throw new NullPointerException("linkType");
69      }
70      if (outputFile == null) {
71        throw new NullPointerException("outputFile");
72      }
73      if (objDir == null) {
74        throw new NullPointerException("objDir");
75      }
76    }
77  
78    /**
79     * Returns the bid of the processor for the file.
80     * 
81     * A linker will bid 1 on any unrecognized file type.
82     * 
83     * @param inputFile
84     *          filename of input file
85     * @return bid for the file, 0 indicates no interest, 1 indicates that the
86     *         processor recognizes the file but doesn't process it (header
87     *         files, for example), 100 indicates strong interest
88     */
89    @Override
90    public int bid(final String inputFile) {
91      final int bid = super.bid(inputFile);
92      switch (bid) {
93      //
94      // unrecognized extension, take the file
95      //
96        case 0:
97          return 1;
98          //
99          // discard the ignored extensions
100         //
101       case 1:
102         return 0;
103     }
104     return bid;
105   }
106 
107   @Override
108   public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
109     return this;
110   }
111 
112   abstract protected LinkerConfiguration createConfiguration(CCTask task, LinkType linkType,
113       ProcessorDef[] baseConfigs, LinkerDef specificConfig, TargetDef targetPlatform, VersionInfo versionInfo);
114 
115   @Override
116   public ProcessorConfiguration createConfiguration(final CCTask task, final LinkType linkType,
117       final ProcessorDef[] baseConfigs, final ProcessorDef specificConfig, final TargetDef targetPlatform,
118       final VersionInfo versionInfo) {
119     if (specificConfig == null) {
120       throw new NullPointerException("specificConfig");
121     }
122     return createConfiguration(task, linkType, baseConfigs, (LinkerDef) specificConfig, targetPlatform, versionInfo);
123   }
124 
125   @Override
126   public String getLibraryKey(final File libfile) {
127     return libfile.getName();
128   }
129 
130   @Override
131   public abstract String[] getOutputFileNames(String fileName, VersionInfo versionInfo);
132 
133 }