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.makeproject.api.compilers;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import java.util.List;
047: import org.netbeans.modules.cnd.api.compilers.CompilerSet.CompilerFlavor;
048: import org.netbeans.modules.cnd.api.utils.IpeUtils;
049: import org.openide.DialogDisplayer;
050: import org.openide.NotifyDescriptor;
051: import org.openide.util.NbBundle;
052:
053: public abstract class SunCCCCompiler extends CCCCompiler {
054: protected PersistentList systemIncludeDirectoriesList = null;
055: protected PersistentList systemPreprocessorSymbolsList = null;
056:
057: public SunCCCCompiler(CompilerFlavor flavor, int kind, String name,
058: String displayName, String path) {
059: super (flavor, kind, name, displayName, path);
060: }
061:
062: @Override
063: public boolean setSystemIncludeDirectories(List values) {
064: assert values != null;
065: if (values.equals(systemIncludeDirectoriesList)) {
066: return false;
067: }
068: systemIncludeDirectoriesList = new PersistentList(values);
069: normalizePaths(systemIncludeDirectoriesList);
070: saveSystemIncludesAndDefines();
071: return true;
072: }
073:
074: @Override
075: public boolean setSystemPreprocessorSymbols(List values) {
076: assert values != null;
077: if (values.equals(systemPreprocessorSymbolsList)) {
078: return false;
079: }
080: systemPreprocessorSymbolsList = new PersistentList(values);
081: saveSystemIncludesAndDefines();
082: return true;
083: }
084:
085: @Override
086: public List getSystemPreprocessorSymbols() {
087: if (systemPreprocessorSymbolsList != null)
088: return systemPreprocessorSymbolsList;
089:
090: getSystemIncludesAndDefines();
091: return systemPreprocessorSymbolsList;
092: }
093:
094: @Override
095: public List getSystemIncludeDirectories() {
096: if (systemIncludeDirectoriesList != null)
097: return systemIncludeDirectoriesList;
098:
099: getSystemIncludesAndDefines();
100: return systemIncludeDirectoriesList;
101: }
102:
103: @Override
104: public void saveSystemIncludesAndDefines() {
105: if (systemIncludeDirectoriesList != null)
106: systemIncludeDirectoriesList.saveList(getUniqueID()
107: + "systemIncludeDirectoriesList"); // NOI18N
108: if (systemPreprocessorSymbolsList != null)
109: systemPreprocessorSymbolsList.saveList(getUniqueID()
110: + "systemPreprocessorSymbolsList"); // NOI18N
111: }
112:
113: private void restoreSystemIncludesAndDefines() {
114: systemIncludeDirectoriesList = PersistentList
115: .restoreList(getUniqueID()
116: + "systemIncludeDirectoriesList"); // NOI18N
117: systemPreprocessorSymbolsList = PersistentList
118: .restoreList(getUniqueID()
119: + "systemPreprocessorSymbolsList"); // NOI18N
120: }
121:
122: private void getSystemIncludesAndDefines() {
123: restoreSystemIncludesAndDefines();
124: if (systemIncludeDirectoriesList == null
125: || systemPreprocessorSymbolsList == null) {
126: getFreshSystemIncludesAndDefines();
127: }
128: }
129:
130: protected abstract String getDefaultPath();
131:
132: protected abstract String getCompilerStderrCommand();
133:
134: protected abstract String getCompilerStderrCommand2();
135:
136: private void getFreshSystemIncludesAndDefines() {
137: systemIncludeDirectoriesList = new PersistentList();
138: systemPreprocessorSymbolsList = new PersistentList();
139: String path = getPath();
140: if (path == null || !new File(path).exists()) {
141: path = getDefaultPath();
142: }
143: try {
144: getSystemIncludesAndDefines(IpeUtils.getDirName(path), path
145: + getCompilerStderrCommand(), false);
146: if (getCompilerStderrCommand2() != null)
147: getSystemIncludesAndDefines(IpeUtils.getDirName(path),
148: path + getCompilerStderrCommand2(), false);
149: systemIncludeDirectoriesList.addUnique("/usr/include"); // NOI18N
150:
151: saveSystemIncludesAndDefines();
152: } catch (IOException ioe) {
153: System.err.println("IOException " + ioe);
154: String errormsg = NbBundle.getMessage(getClass(),
155: "CANTFINDCOMPILER", path); // NOI18N
156: DialogDisplayer.getDefault().notify(
157: new NotifyDescriptor.Message(errormsg,
158: NotifyDescriptor.ERROR_MESSAGE));
159: }
160: }
161:
162: @Override
163: public void resetSystemIncludesAndDefines() {
164: getFreshSystemIncludesAndDefines();
165: }
166:
167: }
|