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;
043:
044: import java.io.File;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.Map;
048: import org.netbeans.api.project.Project;
049: import org.netbeans.modules.cnd.discovery.api.Configuration;
050: import org.netbeans.modules.cnd.discovery.api.FolderProperties;
051: import org.netbeans.modules.cnd.discovery.api.ItemProperties;
052: import org.netbeans.modules.cnd.discovery.api.ProjectProperties;
053: import org.netbeans.modules.cnd.discovery.api.ProjectProxy;
054: import org.netbeans.modules.cnd.dwarfdiscovery.provider.*;
055:
056: /**
057: *
058: * @author Alexander Simon
059: */
060: public class DwarfAnalyzer {
061:
062: public static void analyze(String[] files) {
063: DwarfProvider provider = new DwarfProvider() {
064: public int canAnalyze(ProjectProxy project) {
065: return 1;
066: }
067: };
068: provider.getProperty(DwarfProvider.EXECUTABLES_KEY).setValue(
069: files);
070: dumpProject(provider, new ProjectProxy() {
071: public boolean createSubProjects() {
072: return false;
073: }
074:
075: public Project getProject() {
076: return null;
077: }
078:
079: public String getMakefile() {
080: return null;
081: }
082:
083: public String getSourceRoot() {
084: return null;
085: }
086:
087: public String getExecutable() {
088: return null;
089: }
090:
091: public String getWorkingFolder() {
092: return null;
093: }
094: });
095: }
096:
097: private static void dumpProject(DwarfProvider provider,
098: ProjectProxy project) {
099: List<Configuration> confs = provider.analyze(project);
100: for (Iterator<Configuration> it = confs.iterator(); it
101: .hasNext();) {
102: Configuration conf = it.next();
103: List<ProjectProperties> langList = conf
104: .getProjectConfiguration();
105: for (Iterator<ProjectProperties> it2 = langList.iterator(); it2
106: .hasNext();) {
107: ProjectProperties proj = it2.next();
108: String lang = ItemProperties.LanguageKind.CPP == proj
109: .getLanguageKind() ? "c++" : "c"; // NOI18N
110: System.out.println("Project " + lang); // NOI18N
111: System.out.println("User include paths:"); // NOI18N
112: StringBuilder buf = new StringBuilder();
113: for (String elem : proj.getUserInludePaths()) {
114: System.out.println(elem);
115: if (elem.startsWith(File.separator)) {
116: if (buf.length() > 0) {
117: buf.append(":"); // NOI18N
118: }
119: buf.append(elem);
120: }
121: }
122: System.out.println("Configuration string:"); // NOI18N
123: System.out.println(" " + buf.toString()); // NOI18N
124: System.out.println("User macros:"); // NOI18N
125: for (Map.Entry<String, String> elem : proj
126: .getUserMacros().entrySet()) {
127: System.out.println(elem.getKey() + "="
128: + elem.getValue()); // NOI18N
129: }
130: List<FolderProperties> folders = proj
131: .getConfiguredFolders();
132: for (FolderProperties folder : folders) {
133: dumpFolder(folder);
134: }
135: }
136: }
137: }
138:
139: private static void dumpFolder(FolderProperties folder) {
140: System.out.println("Folder " + folder.getItemPath()); // NOI18N
141: System.out.println("User include paths:"); // NOI18N
142: StringBuilder buf = new StringBuilder();
143: for (String elem : folder.getUserInludePaths()) {
144: System.out.println(elem);
145: if (elem.startsWith(File.separator)) {
146: if (buf.length() > 0) {
147: buf.append(":"); // NOI18N
148: }
149: buf.append(elem);
150: }
151: }
152: System.out.println("Configuration string:"); // NOI18N
153: System.out.println(" " + buf.toString()); // NOI18N
154: System.out.println("User macros:"); // NOI18N
155: for (Map.Entry<String, String> elem : folder.getUserMacros()
156: .entrySet()) {
157: System.out.println(elem.getKey() + "=" + elem.getValue()); // NOI18N
158: }
159: }
160: }
|