001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.cnd.api.compilers;
043:
044: import java.io.File;
045: import java.util.ResourceBundle;
046: import org.netbeans.modules.cnd.api.compilers.CompilerSet.CompilerFlavor;
047: import org.netbeans.modules.cnd.api.utils.IpeUtils;
048: import org.openide.util.NbBundle;
049: import org.openide.util.Utilities;
050:
051: public class Tool {
052:
053: // Compiler types
054: public static int CCompiler = 0;
055: public static int CCCompiler = 1;
056: public static int FortranCompiler = 2;
057: public static int CustomTool = 3;
058: public static int Assembler = 4;
059: public static int MakeTool = 5;
060: public static int DebuggerTool = 6;
061:
062: private static final String[] TOOL_NAMES = {
063: getString("CCompiler"), // NOI18N
064: getString("CCCompiler"), // NOI18N
065: getString("FortranCompiler"), // NOI18N
066: getString("CustomBuildTool"), // NOI18N
067: getString("Assembler"), // NOI18N
068: getString("MakeTool"), // NOI18N
069: getString("DebuggerTool"), // NOI18N
070: };
071:
072: private static final String[] COMPILER_TOOL_NAMES = {
073: getString("CCompiler"), // NOI18N
074: getString("CCCompiler"), // NOI18N
075: getString("FortranCompiler"), // NOI18N
076: getString("Assembler"), // NOI18N
077: getString("CustomBuildTool"), // NOI18N
078: };
079:
080: private CompilerFlavor flavor;
081: private int kind;
082: private String name;
083: private String displayName;
084: private String path;
085: private String includeFilePrefix = null;
086:
087: /** Creates a new instance of GenericCompiler */
088: public Tool(CompilerFlavor flavor, int kind, String name,
089: String displayName, String path) {
090: this .flavor = flavor;
091: this .kind = kind;
092: this .name = name;
093: this .displayName = displayName;
094: this .path = name.length() > 0 ? path + File.separator + name
095: : path;
096: }
097:
098: public CompilerFlavor getFlavor() {
099: return flavor;
100: }
101:
102: public int getKind() {
103: return kind;
104: }
105:
106: public String getName() {
107: return name;
108: }
109:
110: public String getPath() {
111: return path;
112: }
113:
114: public void setPath(String p) {
115: if (p == null) {
116:
117: } else {
118: path = p;
119: name = IpeUtils.getBaseName(path);
120: }
121: }
122:
123: public static String[] getCompilerToolNames() {
124: return COMPILER_TOOL_NAMES;
125: }
126:
127: public static int getTool(String name) {
128: for (int i = 0; i < TOOL_NAMES.length; i++) {
129: if (TOOL_NAMES[i].equals(name)) {
130: return i;
131: }
132: }
133: return 0; // ????
134: }
135:
136: public static String getName(int kind) {
137: if (kind >= 0 && kind <= TOOL_NAMES.length) {
138: return TOOL_NAMES[kind];
139: } else {
140: return null;
141: }
142: }
143:
144: public String getDisplayName() {
145: return displayName;
146: }
147:
148: // public String getGenericName() {
149: // String name = getName();
150: // if (name.length() > 0) {
151: // return TOOL_NAMES[getKind()] + " - " + getName(); // NOI18N
152: // } else {
153: // return TOOL_NAMES[getKind()];
154: // }
155: // }
156:
157: public static String getToolDisplayName(int kind) {
158: return TOOL_NAMES[kind];
159: }
160:
161: public String toString() {
162: String name = getName();
163: if (Utilities.isWindows() && name.endsWith(".exe")) { // NOI18N
164: return name.substring(0, name.length() - 4);
165: } else {
166: return name;
167: }
168: }
169:
170: public String getIncludeFilePathPrefix() {
171: if (includeFilePrefix == null) {
172: includeFilePrefix = ""; // NOI18N
173: if (getFlavor() == CompilerFlavor.Cygwin
174: || getFlavor() == CompilerFlavor.MinGW
175: || getFlavor() == CompilerFlavor.DJGPP
176: || getFlavor() == CompilerFlavor.Interix) {
177: int i = getPath().toLowerCase().indexOf("\\bin"); // NOI18N
178: if (i < 0)
179: i = getPath().toLowerCase().indexOf("/bin"); // NOI18N
180: if (i > 0) {
181: includeFilePrefix = getPath().substring(0, i);
182: includeFilePrefix = includeFilePrefix.replaceAll(
183: "\\\\", "/"); // NOI18N
184: //includeFilePrefix = FilePathAdaptor.normalize(includeFilePrefix);
185: }
186: }
187: }
188: return includeFilePrefix;
189: }
190:
191: public boolean exists() {
192: if (getPath() == null || getPath().length() == 0)
193: return false;
194: return new File(getPath()).exists();
195: }
196:
197: private static ResourceBundle bundle = null;
198:
199: protected static String getString(String s) {
200: if (bundle == null) {
201: bundle = NbBundle.getBundle(Tool.class);
202: }
203: return bundle.getString(s);
204: }
205: }
|