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.dwarfdiscovery.provider;
043:
044: import java.io.File;
045: import java.util.ArrayList;
046: import java.util.HashMap;
047: import java.util.HashSet;
048: import java.util.List;
049: import java.util.Map;
050: import org.netbeans.modules.cnd.discovery.api.Configuration;
051: import org.netbeans.modules.cnd.discovery.api.ProjectProperties;
052: import org.netbeans.modules.cnd.discovery.api.ProjectProxy;
053: import org.netbeans.modules.cnd.discovery.api.ProviderProperty;
054: import org.netbeans.modules.cnd.discovery.api.SourceFileProperties;
055: import org.openide.filesystems.FileUtil;
056: import org.openide.util.NbBundle;
057:
058: /**
059: *
060: * @author Alexander Simon
061: */
062: abstract public class DwarfProvider extends BaseDwarfProvider {
063: private Map<String, ProviderProperty> myProperties = new HashMap<String, ProviderProperty>();
064: public static final String EXECUTABLES_KEY = "binaries"; // NOI18N
065:
066: public DwarfProvider() {
067: clean();
068: }
069:
070: public void clean() {
071: myProperties.clear();
072: myProperties.put(EXECUTABLES_KEY, new ProviderProperty() {
073: private String[] myPath;
074:
075: public String getName() {
076: return i18n("Binaries_Files_Name"); // NOI18N
077: }
078:
079: public String getDescription() {
080: return i18n("Binaries_Files_Description"); // NOI18N
081: }
082:
083: public Object getValue() {
084: return myPath;
085: }
086:
087: public void setValue(Object value) {
088: if (value instanceof String[]) {
089: myPath = (String[]) value;
090: }
091: }
092:
093: public ProviderProperty.PropertyKind getKind() {
094: return ProviderProperty.PropertyKind.BinaryFiles;
095: }
096: });
097: }
098:
099: public String getID() {
100: return "dwarf-binaries"; // NOI18N
101: }
102:
103: public String getName() {
104: return i18n("Binaries_Provider_Name"); // NOI18N
105: }
106:
107: public String getDescription() {
108: return i18n("Binaries_Provider_Description"); // NOI18N
109: }
110:
111: public List<String> getPropertyKeys() {
112: return new ArrayList<String>(myProperties.keySet());
113: }
114:
115: public ProviderProperty getProperty(String key) {
116: return myProperties.get(key);
117: }
118:
119: public List<Configuration> analyze(ProjectProxy project) {
120: isStoped = false;
121: List<Configuration> confs = new ArrayList<Configuration>();
122: setCommpilerSettings(project);
123: if (!isStoped) {
124: Configuration conf = new Configuration() {
125: private List<SourceFileProperties> myFileProperties;
126: private List<String> myIncludedFiles;
127:
128: public List<ProjectProperties> getProjectConfiguration() {
129: return divideByLanguage(getSourcesConfiguration());
130: }
131:
132: public List<Configuration> getDependencies() {
133: return null;
134: }
135:
136: public List<SourceFileProperties> getSourcesConfiguration() {
137: if (myFileProperties == null) {
138: String[] objFileNames = (String[]) getProperty(
139: EXECUTABLES_KEY).getValue();
140: if (objFileNames != null) {
141: myFileProperties = getSourceFileProperties(objFileNames);
142: }
143: }
144: return myFileProperties;
145: }
146:
147: public List<String> getIncludedFiles() {
148: if (myIncludedFiles == null) {
149: HashSet<String> set = new HashSet<String>();
150: for (SourceFileProperties source : getSourcesConfiguration()) {
151: if (isStoped) {
152: break;
153: }
154: set.addAll(((DwarfSource) source)
155: .getIncludedFiles());
156: set.add(source.getItemPath());
157: }
158: HashSet<String> unique = new HashSet<String>();
159: for (String path : set) {
160: if (isStoped) {
161: break;
162: }
163: File file = new File(path);
164: if (file.exists()) {
165: unique.add(FileUtil.normalizeFile(file)
166: .getAbsolutePath());
167: }
168: }
169: myIncludedFiles = new ArrayList<String>(unique);
170: }
171: return myIncludedFiles;
172: }
173: };
174: confs.add(conf);
175: }
176: return confs;
177: }
178:
179: private static String i18n(String id) {
180: return NbBundle.getMessage(DwarfProvider.class, id);
181: }
182: }
|