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.gcc;
21  
22  import java.io.File;
23  
24  import org.apache.tools.ant.BuildException;
25  
26  import com.github.maven_nar.cpptasks.CCTask;
27  import com.github.maven_nar.cpptasks.VersionInfo;
28  import com.github.maven_nar.cpptasks.compiler.CommandLineLinker;
29  import com.github.maven_nar.cpptasks.compiler.CommandLineLinkerConfiguration;
30  import com.github.maven_nar.cpptasks.types.LibraryTypeEnum;
31  
32  /**
33   * Adapter for the "ar" tool
34   *
35   * @author Adam Murdoch
36   * @author Curt Arnold
37   */
38  public abstract class AbstractArLibrarian extends CommandLineLinker {
39    private final/* final */
40    String outputPrefix;
41  
42    protected AbstractArLibrarian(final String command, final String identificationArg, final String[] inputExtensions,
43        final String[] ignoredExtensions, final String outputPrefix, final String outputExtension,
44        final boolean isLibtool, final AbstractArLibrarian libtoolLibrarian) {
45      super(command, identificationArg, inputExtensions, ignoredExtensions, outputExtension, isLibtool, libtoolLibrarian);
46      this.outputPrefix = outputPrefix;
47    }
48  
49    @Override
50    public String getCommandFileSwitch(final String commandFile) {
51      return null;
52    }
53  
54    @Override
55    public File[] getLibraryPath() {
56      return new File[0];
57    }
58  
59    @Override
60    public String[] getLibraryPatterns(final String[] libnames, final LibraryTypeEnum libType) {
61      return new String[0];
62    }
63  
64    @Override
65    public int getMaximumCommandLength() {
66      return Integer.MAX_VALUE;
67    }
68  
69    @Override
70    public String[] getOutputFileNames(final String baseName, final VersionInfo versionInfo) {
71      final String[] baseNames = super.getOutputFileNames(baseName, versionInfo);
72      if (this.outputPrefix.length() > 0) {
73        for (int i = 0; i < baseNames.length; i++) {
74          baseNames[i] = this.outputPrefix + baseNames[i];
75        }
76      }
77      return baseNames;
78    }
79  
80    @Override
81    public String[] getOutputFileSwitch(final String outputFile) {
82      return GccProcessor.getOutputFileSwitch("rvs", outputFile);
83    }
84  
85    @Override
86    public boolean isCaseSensitive() {
87      return true;
88    }
89  
90    @Override
91    public void link(final CCTask task, final File outputFile, final String[] sourceFiles,
92        final CommandLineLinkerConfiguration config) throws BuildException {
93      //
94      // if there is an existing library then
95      // we must delete it before executing "ar"
96      if (outputFile.exists()) {
97        if (!outputFile.delete()) {
98          throw new BuildException("Unable to delete " + outputFile.getAbsolutePath());
99        }
100     }
101     //
102     // delegate to CommandLineLinker
103     //
104     super.link(task, outputFile, sourceFiles, config);
105   }
106 }