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  /**
23   * @author Mark Donszelmann
24   * @version $Id$
25   */
26  public class AOL {
27  
28    private String architecture;
29  
30    private String os;
31  
32    private String linkerName;
33  
34    // FIXME, need more complicated parsing for numbers as part of os.
35    public AOL(final String aol) {
36      final int linkerIndex = 2;
37      final int osIndex = 1;
38      final int architectureIndex = 0;
39  
40      final String[] aolString = aol.split("-", linkerIndex + 1);
41      switch (aolString.length) {
42        case linkerIndex + 1:
43          this.linkerName = aolString[linkerIndex];
44        case osIndex + 1:
45          this.os = aolString[osIndex];
46        case architectureIndex + 1:
47          this.architecture = aolString[architectureIndex];
48          break;
49  
50        default:
51          throw new IllegalArgumentException("AOL '" + aol + "' cannot be parsed.");
52      }
53    }
54  
55    public AOL(final String architecture, final String os, final String linkerName) {
56      this.architecture = architecture;
57      this.os = os;
58      this.linkerName = linkerName;
59    }
60  
61    /**
62     * Returns an AOL key (arch.os.linker) to search in the properties files.
63     * 
64     * @return dot separated AOL
65     */
66    public final String getKey() {
67      String tempLinkerName = null;
68      if (this.linkerName == null) {
69        tempLinkerName = "";
70      } else if (this.linkerName.equals("g++")) {
71        tempLinkerName = ".gpp";
72      } else {
73        tempLinkerName = "." + this.linkerName;
74      }
75  
76      return this.architecture + (this.os == null ? "" : "." + this.os + tempLinkerName);
77    }
78  
79    final String getOS() {
80      return this.os;
81    }
82  
83    // FIXME, maybe change to something like isCompatible (AOL).
84    public final boolean hasLinker(final String linker) {
85      return this.linkerName.equals(linker);
86    }
87  
88    /**
89     * Returns an AOL string (arch-os-linker) to use as directory or file.
90     * 
91     * @return dash separated AOL
92     */
93    @Override
94    public final String toString() {
95      String tempLinkerName = null;
96      if (this.linkerName == null) {
97        tempLinkerName = "";
98      } else if (this.linkerName.equals("g++")) {
99        tempLinkerName = "-gpp";
100     } else {
101       tempLinkerName = "-" + this.linkerName;
102     }
103 
104     return this.architecture + (this.os == null ? "" : "-" + this.os + tempLinkerName);
105   }
106 }