[hg] main-silver: implement build artifacts provider (build log ...

  • From: Alexander Simon < >
  • To:
  • Subject: [hg] main-silver: implement build artifacts provider (build log ...
  • Date: Mon, 04 Feb 2013 04:38:35 -0800

changeset 47654d134fe3 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/47654d134fe3
description:
        implement build artifacts provider (build log provider)

diffstat:

 cnd.discovery/nbproject/project.properties                                   
                        |   2 +-
 cnd.discovery/src/org/netbeans/modules/cnd/discovery/api/DiscoveryUtils.java 
                        |  56 ++++--
 
cnd.discovery/src/org/netbeans/modules/cnd/discovery/projectimport/ImportProject.java
                |  38 +++-
 cnd.dwarfdiscovery/nbproject/project.xml                                     
                        |   2 +-
 
cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/AnalyzeExecLog.java
          |  33 ++-
 
cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/AnalyzeMakeLog.java
          |  21 ++-
 
cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/DwarfSource.java
             |  15 +-
 
cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReader.java
               |  75 ++++++++--
 
cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/RemoteJavaExecution.java
     |   8 +-
 
cnd.dwarfdiscovery/test/unit/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReaderTest.java
 |  50 ++----
 10 files changed, 187 insertions(+), 113 deletions(-)

diffs (761 lines):

diff --git a/cnd.discovery/nbproject/project.properties 
b/cnd.discovery/nbproject/project.properties
--- a/cnd.discovery/nbproject/project.properties
+++ b/cnd.discovery/nbproject/project.properties
@@ -1,6 +1,6 @@
 javac.compilerargs=-Xlint -Xlint:-serial
 javac.source=1.6
-spec.version.base=1.32
+spec.version.base=1.33
 release.external/cnd-build-trace-1.0.zip!/SunOS-x86/libBuildTrace.so        
= bin/SunOS-x86/libBuildTrace.so
 release.external/cnd-build-trace-1.0.zip!/SunOS-x86_64/libBuildTrace.so     
= bin/SunOS-x86_64/libBuildTrace.so
 release.external/cnd-build-trace-1.0.zip!/SunOS-sparc/libBuildTrace.so      
= bin/SunOS-sparc/libBuildTrace.so
diff --git 
a/cnd.discovery/src/org/netbeans/modules/cnd/discovery/api/DiscoveryUtils.java
 
b/cnd.discovery/src/org/netbeans/modules/cnd/discovery/api/DiscoveryUtils.java
--- 
a/cnd.discovery/src/org/netbeans/modules/cnd/discovery/api/DiscoveryUtils.java
+++ 
b/cnd.discovery/src/org/netbeans/modules/cnd/discovery/api/DiscoveryUtils.java
@@ -47,6 +47,7 @@
 import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -270,7 +271,7 @@
     /**
      * parse compile line
      */
-    public static List<String> gatherCompilerLine(String line, LogOrigin 
isScriptOutput, List<String> userIncludes, Map<String, String> userMacros, 
List<String> undefinedMacros, Set<String> libraries, List<String> 
languageArtifacts, ProjectBridge bridge, boolean isCpp){
+    public static List<String> gatherCompilerLine(String line, LogOrigin 
isScriptOutput, Artifacts artifacts, ProjectBridge bridge, boolean isCpp){
         List<String> list = DiscoveryUtils.scanCommandLine(line, 
isScriptOutput);
         boolean hasQuotes = false;
         for(String s : list){
@@ -308,12 +309,12 @@
                 st.next();
             }
         }
-        return gatherCompilerLine(st, isScriptOutput, userIncludes, 
userMacros, undefinedMacros, libraries, languageArtifacts, bridge, isCpp);
+        return gatherCompilerLine(st, isScriptOutput, artifacts, bridge, 
isCpp);
     }
     /**
      * parse compile line
      */
-    public static List<String> gatherCompilerLine( Iterator<String> st, 
LogOrigin isScriptOutput, List<String> userIncludes, Map<String, String> 
userMacros, List<String> undefinedMacros, Set<String> libraries, List<String> 
languageArtifacts, ProjectBridge bridge, boolean isCpp){
+    public static List<String> gatherCompilerLine( Iterator<String> st, 
LogOrigin isScriptOutput, Artifacts artifacts, ProjectBridge bridge, boolean 
isCpp){
         boolean TRACE = false;
         String option; 
         List<String> what = new ArrayList<String>(1);
@@ -376,10 +377,10 @@
                             break;
                     }
                     String key = removeEscape(macro.substring(0,i));
-                    addDef(key, value, userMacros, undefinedMacros);
+                    addDef(key, value, artifacts.userMacros, 
artifacts.undefinedMacros);
                 } else {
                     String key = removeEscape(macro);
-                    addDef(key, null, userMacros, undefinedMacros);
+                    addDef(key, null, artifacts.userMacros, 
artifacts.undefinedMacros);
                 }
             } else if (option.startsWith("-U")){ // NOI18N
                 String macro = option.substring(2);
@@ -387,35 +388,35 @@
                     macro = st.next();
                 }
                 macro = removeQuotes(macro);
-                addUndef(macro, userMacros, undefinedMacros);
+                addUndef(macro, artifacts.userMacros, 
artifacts.undefinedMacros);
             } else if (option.startsWith("-I")){ // NOI18N
                 String path = option.substring(2);
                 if (path.length()==0 && st.hasNext()){
                     path = st.next();
                 }
                 path = removeQuotes(path);
-                userIncludes.add(path);
+                artifacts.userIncludes.add(path);
             } else if (option.startsWith("-isystem")){ // NOI18N
                 String path = option.substring(8);
                 if (path.length()==0 && st.hasNext()){
                     path = st.next();
                 }
                 path = removeQuotes(path);
-                userIncludes.add(path);
+                artifacts.userIncludes.add(path);
             } else if (option.startsWith("-include")){ // NOI18N
                 String path = option.substring(8);
                 if (path.length()==0 && st.hasNext()){
                     path = st.next();
                 }
                 path = removeQuotes(path);
-                userIncludes.add(path);
+                artifacts.userIncludes.add(path);
             } else if (option.startsWith("-imacros")){ // NOI18N
                 String path = option.substring(8);
                 if (path.length()==0 && st.hasNext()){
                     path = st.next();
                 }
                 path = removeQuotes(path);
-                userIncludes.add(path);
+                artifacts.userIncludes.add(path);
             } else if (option.startsWith("-Y")){ // NOI18N
                 String defaultSearchPath = option.substring(2);
                 if (defaultSearchPath.length()==0 && st.hasNext()){
@@ -424,7 +425,7 @@
                 if (defaultSearchPath.startsWith("I,")){ // NOI18N
                     defaultSearchPath = defaultSearchPath.substring(2);
                     defaultSearchPath = removeQuotes(defaultSearchPath);
-                    userIncludes.add(defaultSearchPath);
+                    artifacts.userIncludes.add(defaultSearchPath);
                 }
             } else if (option.startsWith("-idirafter")){ // NOI18N
                 //Search dir for header files, but do it after all 
directories specified with -I and the standard system directories have been 
exhausted.
@@ -472,8 +473,8 @@
                     lib = st.next();
                 }
                 // library
-                if (lib.length()>0 && libraries != null){
-                    libraries.add(lib);
+                if (lib.length()>0){
+                    artifacts.libraries.add(lib);
                 }
             } else if (option.equals("-L")){ // NOI18N
                 // Skip library search path
@@ -493,7 +494,7 @@
             } else if (option.equals("-o")){ // NOI18N
                 // Skip result
                 if (st.hasNext()){
-                    st.next();
+                    artifacts.output = st.next();
                 }
             // generation 2 of params
             } else if (option.equals("-z")){ // NOI18N
@@ -505,24 +506,24 @@
                 // Specify explicitly the language for the following input 
files (rather than letting the compiler choose a default based on the file 
name suffix).
                 if (st.hasNext()){
                     String lang = st.next();
-                    languageArtifacts.add(lang);
+                    artifacts.languageArtifacts.add(lang);
                 }
             } else if (option.equals("-xc")){ // NOI18N
-                languageArtifacts.add("c"); // NOI18N  
+                artifacts.languageArtifacts.add("c"); // NOI18N        
             } else if (option.equals("-xc++")){ // NOI18N
-                languageArtifacts.add("c++"); // NOI18N
+                artifacts.languageArtifacts.add("c++"); // NOI18N
             } else if (option.equals("-std=c89")){ // NOI18N
-                languageArtifacts.add("c89"); // NOI18N
+                artifacts.languageArtifacts.add("c89"); // NOI18N
             } else if (option.equals("-xc99") || // NOI18N
                        option.equals("-std=c99")){ // NOI18N
-                languageArtifacts.add("c99"); // NOI18N
+                artifacts.languageArtifacts.add("c99"); // NOI18N
             } else if (option.equals("-std=c++0x") || // NOI18N
                        option.equals("-std=c++11") || // NOI18N
                        option.equals("-std=gnu++0x") || // NOI18N
                        option.equals("-std=gnu++11")){ // NOI18N
-                languageArtifacts.add("c++11"); // NOI18N
+                artifacts.languageArtifacts.add("c++11"); // NOI18N
             } else if (option.equals("-std=c++98")){ // NOI18N
-                languageArtifacts.add("c++98"); // NOI18N
+                artifacts.languageArtifacts.add("c++98"); // NOI18N
             } else if (option.equals("-xMF")){ // NOI18N
                 // ignore dependency output file
                 if (st.hasNext()){
@@ -549,7 +550,7 @@
                     st.next();
                 }
             } else if (option.startsWith("-")){ // NOI18N
-                addMacrosByFlags(option, userMacros, undefinedMacros, 
bridge, isCpp);
+                addMacrosByFlags(option, artifacts.userMacros, 
artifacts.undefinedMacros, bridge, isCpp);
             } else if (option.startsWith("ccfe")){ // NOI18N
                 // Skip option
             } else if (option.startsWith(">")){ // NOI18N
@@ -657,4 +658,15 @@
         DwarfCompileLine,
         ExecLog
     }
+    
+    public static final class Artifacts {
+        public final List<String> userIncludes = new ArrayList<String>();
+        public final Map<String, String> userMacros = new HashMap<String, 
String>();
+        public final List<String> undefinedMacros = new ArrayList<String>();
+        public final Set<String> libraries = new HashSet<String>();
+        public final List<String> languageArtifacts = new 
ArrayList<String>();
+        public String output;
+        public Artifacts() {
 }
+    }
+}
diff --git 
a/cnd.discovery/src/org/netbeans/modules/cnd/discovery/projectimport/ImportProject.java
 
b/cnd.discovery/src/org/netbeans/modules/cnd/discovery/projectimport/ImportProject.java
--- 
a/cnd.discovery/src/org/netbeans/modules/cnd/discovery/projectimport/ImportProject.java
+++ 
b/cnd.discovery/src/org/netbeans/modules/cnd/discovery/projectimport/ImportProject.java
@@ -1337,17 +1337,7 @@
                 try {
                     done = true;
                     extension.apply(map, makeProject);
-                    if (false) {
-                        List<String> buildArtifacts = (List<String>) 
map.get(DiscoveryWizardDescriptor.BUILD_ARTIFACTS);
-                        if (buildArtifacts != null) {
-                            ConfigurationDescriptorProvider pdp = 
makeProject.getLookup().lookup(ConfigurationDescriptorProvider.class);
-                            MakeConfigurationDescriptor 
makeConfigurationDescriptor = pdp.getConfigurationDescriptor();
-                            Folder externalFileItems = 
makeConfigurationDescriptor.getExternalFileItems();
-                            for(String binary : buildArtifacts) {
-                                
externalFileItems.addItem(Item.createInFileSystem(makeConfigurationDescriptor.getBaseDirFileSystem(),binary));
-                            }
-                        }
-                    }
+                    setBuildResults((List<String>) 
map.get(DiscoveryWizardDescriptor.BUILD_ARTIFACTS));
                     importResult.put(Step.DiscoveryLog, State.Successful);
                 } catch (IOException ex) {
                     ex.printStackTrace(System.err);
@@ -1362,6 +1352,31 @@
         return done;
     }
 
+    private void setBuildResults(List<String> buildArtifacts) {
+        if (buildArtifacts == null || buildArtifacts.isEmpty()) {
+            return;
+        }
+        ConfigurationDescriptorProvider pdp = 
makeProject.getLookup().lookup(ConfigurationDescriptorProvider.class);
+        MakeConfigurationDescriptor makeConfigurationDescriptor = 
pdp.getConfigurationDescriptor();
+        if (buildArtifacts.size() == 1) {
+            MakeConfiguration activeConfiguration = 
makeConfigurationDescriptor.getActiveConfiguration();
+            if (activeConfiguration != null) {
+                String value = 
activeConfiguration.getMakefileConfiguration().getOutput().getValue();
+                if (value == null || value.isEmpty()) {
+                    buildResult = buildArtifacts.get(0);
+                    buildResult = 
ProjectSupport.toProperPath(projectFolder.getPath(), 
CndPathUtilitities.naturalizeSlashes(buildResult), pathMode);
+                    buildResult = 
CndPathUtilitities.normalizeSlashes(buildResult);
+                    
activeConfiguration.getMakefileConfiguration().getOutput().setValue(buildResult);
+                }
+            }
+        }
+        //Folder externalFileItems = 
makeConfigurationDescriptor.getExternalFileItems();
+        //for(String binary : buildArtifacts) {
+        //    
externalFileItems.addItem(Item.createInFileSystem(makeConfigurationDescriptor.getBaseDirFileSystem(),binary));
+        //}
+     }
+
+    
     private boolean discoveryByDwarfOrBuildLog(boolean done) {
         final DiscoveryExtensionInterface extension = 
(DiscoveryExtensionInterface) 
Lookup.getDefault().lookup(IteratorExtension.class);
         if (extension != null) {
@@ -1413,6 +1428,7 @@
                 try {
                     done = true;
                     extension.apply(map, makeProject);
+                    setBuildResults((List<String>) 
map.get(DiscoveryWizardDescriptor.BUILD_ARTIFACTS));
                     importResult.put(Step.DiscoveryLog, State.Successful);
                 } catch (IOException ex) {
                     ex.printStackTrace(System.err);
diff --git a/cnd.dwarfdiscovery/nbproject/project.xml 
b/cnd.dwarfdiscovery/nbproject/project.xml
--- a/cnd.dwarfdiscovery/nbproject/project.xml
+++ b/cnd.dwarfdiscovery/nbproject/project.xml
@@ -28,7 +28,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.31</specification-version>
+                        <specification-version>1.33</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git 
a/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/AnalyzeExecLog.java
 
b/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/AnalyzeExecLog.java
--- 
a/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/AnalyzeExecLog.java
+++ 
b/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/AnalyzeExecLog.java
@@ -65,6 +65,7 @@
 import org.netbeans.modules.cnd.discovery.api.Configuration;
 import org.netbeans.modules.cnd.discovery.api.DiscoveryExtensionInterface;
 import org.netbeans.modules.cnd.discovery.api.DiscoveryUtils;
+import org.netbeans.modules.cnd.discovery.api.DiscoveryUtils.Artifacts;
 import org.netbeans.modules.cnd.discovery.api.ItemProperties;
 import org.netbeans.modules.cnd.discovery.api.ItemProperties.LanguageKind;
 import org.netbeans.modules.cnd.discovery.api.Progress;
@@ -514,12 +515,8 @@
                 // skip tool
                 iterator.next();
             }
-            List<String> aUserIncludes = new ArrayList<String>();
-            Map<String,String> aUserMacros = new HashMap<String, String>();
-            List<String> aUndefinedMacros= new ArrayList<String>();
-            List<String> languageArtifacts = new ArrayList<String>();
-            List<String> sourcesList = 
DiscoveryUtils.gatherCompilerLine(iterator, DiscoveryUtils.LogOrigin.ExecLog, 
aUserIncludes, aUserMacros, aUndefinedMacros,
-                    null, languageArtifacts, 
compilerSettings.getProjectBridge(), language == LanguageKind.CPP);
+            Artifacts artifacts = new Artifacts();
+            List<String> sourcesList = 
DiscoveryUtils.gatherCompilerLine(iterator, DiscoveryUtils.LogOrigin.ExecLog, 
artifacts, compilerSettings.getProjectBridge(), language == LanguageKind.CPP);
             for (String what : sourcesList) {
                 if (what == null) {
                     continue;
@@ -531,8 +528,8 @@
                 }
                 String fullName;
                 String sourceName;
-                List<String> userIncludes = new 
ArrayList<String>(aUserIncludes.size());
-                for(String s : aUserIncludes){
+                List<String> userIncludes = new 
ArrayList<String>(artifacts.userIncludes.size());
+                for(String s : artifacts.userIncludes){
                     if (s.startsWith("/") && pathMapper != null) { // NOI18N
                         String mapped = pathMapper.getLocalPath(s);
                         if (mapped != null) {
@@ -541,8 +538,8 @@
                     }
                     userIncludes.add(PathCache.getString(s));
                 }
-                Map<String, String> userMacros = new HashMap<String, 
String>(aUserMacros.size());
-                for(Map.Entry<String,String> e : aUserMacros.entrySet()){
+                Map<String, String> userMacros = new HashMap<String, 
String>(artifacts.userMacros.size());
+                for(Map.Entry<String,String> e : 
artifacts.userMacros.entrySet()){
                     if (e.getValue() == null) {
                         userMacros.put(PathCache.getString(e.getKey()), 
null);
                     } else {
@@ -565,9 +562,9 @@
                 FileObject f = fileSystem.findResource(fullName);
                 if (f != null && f.isValid() && f.isData()) {
                     fullName = PathCache.getString(f.getPath());
-                    if (languageArtifacts.contains("c")) { // NOI18N
+                    if (artifacts.languageArtifacts.contains("c")) { // 
NOI18N
                         language = ItemProperties.LanguageKind.C;
-                    } else if (languageArtifacts.contains("c++")) { // NOI18N
+                    } else if (artifacts.languageArtifacts.contains("c++")) 
{ // NOI18N
                         language = ItemProperties.LanguageKind.CPP;
                     } else {
                         if (language == LanguageKind.Unknown) {
@@ -593,8 +590,8 @@
                     res.language = language;
                     res.userIncludes = userIncludes;
                     res.userMacros = userMacros;
-                    res.undefinedMacros = aUndefinedMacros;
-                    for(String lang : languageArtifacts) {
+                    res.undefinedMacros = artifacts.undefinedMacros;
+                    for(String lang : artifacts.languageArtifacts) {
                         if ("c89".equals(lang)) { //NOI18N
                             res.standard = 
ItemProperties.LanguageStandard.C89;
                         } else if ("c99".equals(lang)) { //NOI18N
@@ -702,6 +699,14 @@
                         fullName = compilePath+"/"+binary; //NOI18N
                     }
                     FileObject f = fileSystem.findResource(fullName);
+                    if (f == null) {
+                        // probably it is just created binary. Try to 
refresh folder.
+                        FileObject folder = 
fileSystem.findResource(compilePath);
+                        if (folder != null && folder.isValid() && 
folder.isFolder()) {
+                            folder.refresh();
+                            f = fileSystem.findResource(fullName);
+                        }
+                    }
                     if (f != null && f.isValid() && f.isData()) {
                         buildArtifacts.add(fullName);
                     }
diff --git 
a/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/AnalyzeMakeLog.java
 
b/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/AnalyzeMakeLog.java
--- 
a/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/AnalyzeMakeLog.java
+++ 
b/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/AnalyzeMakeLog.java
@@ -258,16 +258,17 @@
         if (p != null) {
             root = (String)p.getValue();
         }
-        List<SourceFileProperties> res = runLogReader(objFileName, root, 
progress, project, storage);
+        List<SourceFileProperties> res = runLogReader(objFileName, root, 
progress, project, buildArtifacts, storage);
         progress = null;
         return res;
 
     }
     
-    /* package-local */ List<SourceFileProperties> runLogReader(String 
objFileName, String root, Progress progress, ProjectProxy project, 
CompileLineStorage storage){
+    /* package-local */ List<SourceFileProperties> runLogReader(String 
objFileName, String root, Progress progress, ProjectProxy project, 
List<String> buildArtifacts, CompileLineStorage storage){
         FileSystem fileSystem = getFileSystem(project);
         LogReader clrf = new LogReader(objFileName, root, project, 
getRelocatablePathMapper(), fileSystem);
         List<SourceFileProperties> list = clrf.getResults(progress, 
isStoped, storage);
+        buildArtifacts.addAll(clrf.getArtifacts(progress, isStoped, 
storage));
         return list;
     }
 
@@ -281,6 +282,7 @@
         if (!isStoped.get()){
             Configuration conf = new Configuration(){
                 private List<SourceFileProperties> myFileProperties;
+                private List<String> myBuildArtifacts;
                 private List<String> myIncludedFiles;
                 @Override
                 public List<ProjectProperties> getProjectConfiguration() {
@@ -294,7 +296,17 @@
 
                 @Override
                 public List<String> getBuildArtifacts() {
-                    return null;
+                    if (myBuildArtifacts == null){
+                        String set = 
(String)getProperty(MAKE_LOG_KEY).getValue();
+                        if (set == null || set.length() == 0) {
+                            set = detectMakeLog(project);
+                        }
+                        if (set != null && set.length() > 0) {
+                            myBuildArtifacts = 
Collections.synchronizedList(new ArrayList<String>());
+                            myFileProperties = getSourceFileProperties(new 
String[]{set},null, project, null, myBuildArtifacts, new 
CompileLineStorage());
+                        }
+                    }
+                    return myBuildArtifacts;
                 }
                 
                 @Override
@@ -305,7 +317,8 @@
                             set = detectMakeLog(project);
                         }
                         if (set != null && set.length() > 0) {
-                            myFileProperties = getSourceFileProperties(new 
String[]{set},null, project, null, null, new CompileLineStorage());
+                            myBuildArtifacts = 
Collections.synchronizedList(new ArrayList<String>());
+                            myFileProperties = getSourceFileProperties(new 
String[]{set},null, project, null, myBuildArtifacts, new 
CompileLineStorage());
                         }
                     }
                     return myFileProperties;
diff --git 
a/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/DwarfSource.java
 
b/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/DwarfSource.java
--- 
a/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/DwarfSource.java
+++ 
b/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/DwarfSource.java
@@ -62,6 +62,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.netbeans.modules.cnd.discovery.api.DiscoveryUtils;
+import org.netbeans.modules.cnd.discovery.api.DiscoveryUtils.Artifacts;
 import org.netbeans.modules.cnd.discovery.api.ItemProperties;
 import org.netbeans.modules.cnd.discovery.api.SourceFileProperties;
 import 
org.netbeans.modules.cnd.dwarfdiscovery.provider.BaseDwarfProvider.GrepEntry;
@@ -489,20 +490,16 @@
         if (DwarfSource.LOG.isLoggable(Level.FINE)) {
             DwarfSource.LOG.log(Level.FINE, "Process command line {0}", 
line); // NOI18N
         }
-        List<String> aUserIncludes = new ArrayList<String>();
-        Map<String, String> aUserMacros = new HashMap<String, String>();
-        List<String> languageArtifacts = new ArrayList<String>();
-        List<String> aUndefinedMacros = new ArrayList<String>();
-        DiscoveryUtils.gatherCompilerLine(line, 
DiscoveryUtils.LogOrigin.DwarfCompileLine, aUserIncludes, aUserMacros, 
aUndefinedMacros,
-                null, languageArtifacts, 
compilerSettings.getProjectBridge(), this.language == LanguageKind.CPP);
-        for(String s : aUserIncludes) {
+        Artifacts artifacts = new Artifacts();
+        DiscoveryUtils.gatherCompilerLine(line, 
DiscoveryUtils.LogOrigin.DwarfCompileLine, artifacts, 
compilerSettings.getProjectBridge(), this.language == LanguageKind.CPP);
+        for(String s : artifacts.userIncludes) {
             String include = PathCache.getString(s);
             addUserIncludePath(include);
         }
-        for(String s : aUndefinedMacros) {
+        for(String s : artifacts.undefinedMacros) {
             undefinedMacros.add(PathCache.getString(s));
         }
-        for(Map.Entry<String, String> entry : aUserMacros.entrySet()) {
+        for(Map.Entry<String, String> entry : 
artifacts.userMacros.entrySet()) {
             userMacros.put(PathCache.getString(entry.getKey()), 
entry.getValue());
         }
     }
diff --git 
a/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReader.java
 
b/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReader.java
--- 
a/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReader.java
+++ 
b/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReader.java
@@ -64,6 +64,7 @@
 import org.netbeans.modules.cnd.api.remote.RemoteSyncSupport;
 import org.netbeans.modules.cnd.api.toolchain.PredefinedToolKind;
 import org.netbeans.modules.cnd.discovery.api.DiscoveryUtils;
+import org.netbeans.modules.cnd.discovery.api.DiscoveryUtils.Artifacts;
 import org.netbeans.modules.cnd.discovery.api.ItemProperties;
 import org.netbeans.modules.cnd.discovery.api.Progress;
 import org.netbeans.modules.cnd.discovery.api.ProjectProxy;
@@ -99,6 +100,7 @@
     private final String root;
     private final String fileName;
     private List<SourceFileProperties> result;
+    private List<String> buildArtifacts;
     private final PathMap pathMapper;
     private final ProjectProxy project;
     private final CompilerSettings compilerSettings;
@@ -247,6 +249,7 @@
         }
         Pattern pattern = Pattern.compile(";|\\|\\||&&"); // ;, ||, && 
//NOI18N
         result = new ArrayList<SourceFileProperties>();
+        buildArtifacts = new ArrayList<String>();
         File file = new File(fileName);
         if (file.exists() && file.canRead()){
             try {
@@ -334,6 +337,20 @@
         }
         return result;
     }
+    public List<String> getArtifacts(Progress progress, AtomicBoolean 
isStoped, CompileLineStorage storage) {
+        if (buildArtifacts == null) {
+            // XXX
+            setWorkingDir(root);
+            run(progress, isStoped, storage);
+            if (subFolders != null) {
+                subFolders.clear();
+                subFolders = null;
+                findBase.clear();
+                findBase = null;
+            }
+        }
+        return buildArtifacts;
+    }
 
     private final ArrayList<List<String>> makeStack = new 
ArrayList<List<String>>();
 
@@ -850,12 +867,8 @@
 
     private void gatherLine(LineInfo li, CompileLineStorage storage) {
         String line = li.compileLine;
-        List<String> userIncludes = new ArrayList<String>();
-        Map<String, String> userMacros = new HashMap<String, String>();
-        List<String> undefinedMacros = new ArrayList<String>();
-        List<String> languageArtifacts = new ArrayList<String>();
-        List<String> sourcesList = DiscoveryUtils.gatherCompilerLine(line, 
DiscoveryUtils.LogOrigin.BuildLog, userIncludes, userMacros, undefinedMacros,
-                null, languageArtifacts, 
compilerSettings.getProjectBridge(), li.compilerType == CompilerType.CPP);
+        Artifacts artifacts = new Artifacts();
+        List<String> sourcesList = DiscoveryUtils.gatherCompilerLine(line, 
DiscoveryUtils.LogOrigin.BuildLog, artifacts, 
compilerSettings.getProjectBridge(), li.compilerType == CompilerType.CPP);
         for(String what : sourcesList) {
             if (what == null){
                 continue;
@@ -874,13 +887,13 @@
             } else {
                 file = workingDir+"/"+what;  //NOI18N
             }
-            List<String> userIncludesCached = new 
ArrayList<String>(userIncludes.size());
-            for(String s : userIncludes){
+            List<String> userIncludesCached = new 
ArrayList<String>(artifacts.userIncludes.size());
+            for(String s : artifacts.userIncludes){
                 s = convertWindowsRelativePath(s);
                 userIncludesCached.add(PathCache.getString(s));
             }
-            Map<String, String> userMacrosCached = new HashMap<String, 
String>(userMacros.size());
-            for(Map.Entry<String,String> e : userMacros.entrySet()){
+            Map<String, String> userMacrosCached = new HashMap<String, 
String>(artifacts.userMacros.size());
+            for(Map.Entry<String,String> e : 
artifacts.userMacros.entrySet()){
                 if (e.getValue() == null) {
                     userMacrosCached.put(PathCache.getString(e.getKey()), 
null);
                 } else {
@@ -892,7 +905,7 @@
                 if (DwarfSource.LOG.isLoggable(Level.FINE)) {
                     DwarfSource.LOG.log(Level.FINE, "**** Gotcha: {0}", 
file);
                 }
-                result.add(new CommandLineSource(li, languageArtifacts, 
workingDir, what, userIncludesCached, userMacrosCached, undefinedMacros, 
storage));
+                result.add(new CommandLineSource(li, 
artifacts.languageArtifacts, workingDir, what, userIncludesCached, 
userMacrosCached, artifacts.undefinedMacros, storage));
                 continue;
             }
             if (!isRelative) {
@@ -904,7 +917,7 @@
                         if (DwarfSource.LOG.isLoggable(Level.FINE)) {
                             DwarfSource.LOG.log(Level.FINE, "**** Gotcha: 
{0}", file);
                         }
-                        result.add(new CommandLineSource(li, 
languageArtifacts, workingDir, what, userIncludesCached, userMacrosCached, 
undefinedMacros, storage));
+                        result.add(new CommandLineSource(li, 
artifacts.languageArtifacts, workingDir, what, userIncludesCached, 
userMacrosCached, artifacts.undefinedMacros, storage));
                         continue;
                     }
                 }
@@ -916,14 +929,14 @@
                     if (DwarfSource.LOG.isLoggable(Level.FINE)) {
                         DwarfSource.LOG.log(Level.FINE, "**** Gotcha guess: 
{0}", file);
                     }
-                    result.add(new CommandLineSource(li, languageArtifacts, 
guessWorkingDir, what, userIncludesCached, userMacrosCached, undefinedMacros, 
storage));
+                    result.add(new CommandLineSource(li, 
artifacts.languageArtifacts, guessWorkingDir, what, userIncludesCached, 
userMacrosCached, artifacts.undefinedMacros, storage));
                     continue;
                 }
             }
             if (DwarfSource.LOG.isLoggable(Level.FINE)) {
                 DwarfSource.LOG.log(Level.FINE, "**** Not found {0}", file); 
//NOI18N
             }
-            if (!what.startsWith("/") && 
userIncludes.size()+userMacros.size() > 0){  //NOI18N
+            if (!what.startsWith("/") && 
artifacts.userIncludes.size()+artifacts.userMacros.size() > 0){  //NOI18N
                 List<String> res = findFiles(what);
                 if (res == null || res.isEmpty()) {
                     if (DwarfSource.LOG.isLoggable(Level.FINE)) {
@@ -931,7 +944,7 @@
                     }
                 } else {
                     if (res.size() == 1) {
-                        result.add(new CommandLineSource(li, 
languageArtifacts, res.get(0), what, userIncludes, userMacros, 
undefinedMacros, storage));
+                        result.add(new CommandLineSource(li, 
artifacts.languageArtifacts, res.get(0), what, userIncludesCached, 
userMacrosCached, artifacts.undefinedMacros, storage));
                         if (DwarfSource.LOG.isLoggable(Level.FINE)) {
                             DwarfSource.LOG.log(Level.FINE, "** Gotcha: 
{0}{1}{2}", new Object[]{res.get(0), File.separator, what});
                         }
@@ -949,6 +962,38 @@
                 }
             }
         }
+        if (artifacts.output != null) {
+            String what = artifacts.output;
+            String baseName = CndPathUtilitities.getBaseName(what);
+            if (!(baseName.endsWith(".exe") || baseName.indexOf(".") < 0)) {
+                return;
+            }
+            String file;
+            boolean isRelative = true;
+            if (isPathAbsolute(what)){
+                what = convertWindowsRelativePath(what);
+                isRelative = false;
+                file = what;
+            } else {
+                file = workingDir+"/"+what;  //NOI18N
+            }
+            File f = new File(file);
+            if (f.exists() && f.isFile()) {
+                if (!buildArtifacts.contains(file)) {
+                    buildArtifacts.add(file);
+                }
+            } else if (!isRelative) {
+                file = convertPath(what);
+                if (!file.equals(what)) {
+                    f = new File(file);
+                    if (f.exists() && f.isFile()) {
+                        if (!buildArtifacts.contains(file)) {
+                            buildArtifacts.add(file);
+                        }
+                    }
+                }
+            }
+        }
     }
     
     //copy of CndPathUtilitities.isPathAbsolute(CharSequence)
diff --git 
a/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/RemoteJavaExecution.java
 
b/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/RemoteJavaExecution.java
--- 
a/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/RemoteJavaExecution.java
+++ 
b/cnd.dwarfdiscovery/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/RemoteJavaExecution.java
@@ -22,6 +22,7 @@
 import org.netbeans.modules.cnd.api.toolchain.CompilerSet;
 import org.netbeans.modules.cnd.api.toolchain.CompilerSetManager;
 import org.netbeans.modules.cnd.discovery.api.DiscoveryUtils;
+import org.netbeans.modules.cnd.discovery.api.DiscoveryUtils.Artifacts;
 import org.netbeans.modules.cnd.dwarfdump.CompileLineService;
 import org.netbeans.modules.cnd.dwarfdump.CompileLineService.SourceFile;
 import org.netbeans.modules.cnd.dwarfdump.LddService;
@@ -226,11 +227,8 @@
     public String getSourceRoot(List<SourceFile> compileLines) {
         TreeMap<String,AtomicInteger> realRoots = new 
TreeMap<String,AtomicInteger>();
         for(SourceFile file : compileLines) {
-            List<String> userIncludes = new ArrayList<String>();
-            Map<String, String> userMacros = new HashMap<String, String>();
-            List<String> undefinedMacros = new ArrayList<String>();
-            List<String> languageArtifacts = new ArrayList<String>();
-            List<String> sourcesList = 
DiscoveryUtils.gatherCompilerLine(file.getCompileLine(), 
DiscoveryUtils.LogOrigin.DwarfCompileLine, userIncludes, userMacros, 
undefinedMacros, null, languageArtifacts, null, true);
+            Artifacts artifacts = new Artifacts();
+            List<String> sourcesList = 
DiscoveryUtils.gatherCompilerLine(file.getCompileLine(), 
DiscoveryUtils.LogOrigin.DwarfCompileLine, artifacts, null, true);
             for(String what : sourcesList) {
                 if (what == null){
                     continue;
diff --git 
a/cnd.dwarfdiscovery/test/unit/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReaderTest.java
 
b/cnd.dwarfdiscovery/test/unit/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReaderTest.java
--- 
a/cnd.dwarfdiscovery/test/unit/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReaderTest.java
+++ 
b/cnd.dwarfdiscovery/test/unit/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReaderTest.java
@@ -42,15 +42,14 @@
 
 package org.netbeans.modules.cnd.dwarfdiscovery.provider;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.regex.Pattern;
 import junit.framework.TestCase;
 import org.netbeans.modules.cnd.discovery.api.DiscoveryUtils;
+import org.netbeans.modules.cnd.discovery.api.DiscoveryUtils.Artifacts;
 import org.netbeans.modules.cnd.discovery.api.ItemProperties;
 import 
org.netbeans.modules.cnd.dwarfdiscovery.provider.LogReader.CommandLineSource;
 
@@ -923,15 +922,12 @@
     }
 
     private String processLine(String[] line, DiscoveryUtils.LogOrigin 
isScriptOutput) {
-        List<String> userIncludes = new ArrayList<String>();
-        Map<String, String> userMacros = new TreeMap<String, String>();
-        List<String> undefs = new ArrayList<String>();
-        List<String> languageArtifacts = new ArrayList<String>();
-        String what = 
DiscoveryUtils.gatherCompilerLine(Arrays.asList(line).iterator(), 
isScriptOutput, userIncludes, userMacros, undefs, null, languageArtifacts, 
null, false).get(0);
+        Artifacts artifacts = new Artifacts();
+        String what = 
DiscoveryUtils.gatherCompilerLine(Arrays.asList(line).iterator(), 
isScriptOutput, artifacts, null, false).get(0);
         StringBuilder res = new StringBuilder();
         res.append("Source:").append(what).append("\n");
         res.append("Macros:");
-        for (Map.Entry<String, String> entry : userMacros.entrySet()) {
+        for (Map.Entry<String, String> entry : new 
TreeMap<String,String>(artifacts.userMacros).entrySet()) {
             res.append("\n");
             res.append(entry.getKey());
             if (entry.getValue() != null) {
@@ -939,15 +935,15 @@
                 res.append(entry.getValue());
             }
         }
-        if (!undefs.isEmpty()) {
+        if (!artifacts.undefinedMacros.isEmpty()) {
             res.append("\nUndefs:");
-            for (String undef : undefs) {
+            for (String undef : artifacts.undefinedMacros) {
                 res.append("\n");
                 res.append(undef);
             }
         }
         res.append("\nPaths:");
-        for (String path : userIncludes) {
+        for (String path : artifacts.userIncludes) {
             res.append("\n");
             res.append(path);
         }
@@ -955,18 +951,15 @@
     }
     
     private String processLine(String line, DiscoveryUtils.LogOrigin 
isScriptOutput) {
-        List<String> userIncludes = new ArrayList<String>();
-        Map<String, String> userMacros = new TreeMap<String, String>();
-        List<String> undefs = new ArrayList<String>();
-        List<String> languageArtifacts = new ArrayList<String>();
         line = LogReader.trimBackApostropheCalls(line, null);
         Pattern pattern = Pattern.compile(";|\\|\\||&&"); // ;, ||, && 
//NOI18N
         String[] cmds = pattern.split(line);
-        String what = DiscoveryUtils.gatherCompilerLine(cmds[0], 
isScriptOutput, userIncludes, userMacros, undefs, null, languageArtifacts, 
null, false).get(0);
+        Artifacts artifacts = new Artifacts();
+        String what = DiscoveryUtils.gatherCompilerLine(cmds[0], 
isScriptOutput, artifacts, null, false).get(0);
         StringBuilder res = new StringBuilder();
         res.append("Source:").append(what).append("\n");
         res.append("Macros:");
-        for (Map.Entry<String, String> entry : userMacros.entrySet()) {
+        for (Map.Entry<String, String> entry : new 
TreeMap<String,String>(artifacts.userMacros).entrySet()) {
             res.append("\n");
             res.append(entry.getKey());
             if (entry.getValue() != null) {
@@ -974,15 +967,15 @@
                 res.append(entry.getValue());
             }
         }
-        if (!undefs.isEmpty()) {
+        if (!artifacts.undefinedMacros.isEmpty()) {
             res.append("\nUndefs:");
-            for (String undef : undefs) {
+            for (String undef : artifacts.undefinedMacros) {
                 res.append("\n");
                 res.append(undef);
             }
         }
         res.append("\nPaths:");
-        for (String path : userIncludes) {
+        for (String path : artifacts.userIncludes) {
             res.append("\n");
             res.append(path);
         }
@@ -1036,23 +1029,18 @@
         } else {
             assertNotSame(ItemProperties.LanguageKind.Unknown, 
li.getLanguage());
         }
-        List<String> userIncludes = new ArrayList<String>();
-        Map<String, String> userMacros = new HashMap<String, String>();
-        List<String> undefs = new ArrayList<String>();
-        List<String> languageArtifacts = new ArrayList<String>();
-        List<String> sourcesList = DiscoveryUtils.gatherCompilerLine(line, 
DiscoveryUtils.LogOrigin.BuildLog, userIncludes, userMacros, undefs, null, 
languageArtifacts, null, false);
+        Artifacts artifacts = new Artifacts();
+        List<String> sourcesList = DiscoveryUtils.gatherCompilerLine(line, 
DiscoveryUtils.LogOrigin.BuildLog, artifacts, null, false);
         assertTrue(sourcesList.size() == size);
         for(String what :sourcesList) {
-            CommandLineSource cs = new CommandLineSource(li, 
languageArtifacts, "/", what, userIncludes, userMacros, undefs, null);
+            CommandLineSource cs = new CommandLineSource(li, 
artifacts.languageArtifacts, "/", what, artifacts.userIncludes, 
artifacts.userMacros, artifacts.undefinedMacros, null);
             assertEquals(ct, cs.getLanguageKind());
         }
     }
 
     private void testLanguageArtifact(String artifact, String line) {
-        List<String> userIncludes = new ArrayList<String>();
-        Map<String, String> userMacros = new HashMap<String, String>();
-        List<String> languageArtifacts = new ArrayList<String>();
-        DiscoveryUtils.gatherCompilerLine(line, 
DiscoveryUtils.LogOrigin.BuildLog, userIncludes, userMacros, null, null, 
languageArtifacts, null, false);
-        assert languageArtifacts.contains(artifact);
+        Artifacts artifacts = new Artifacts();
+        DiscoveryUtils.gatherCompilerLine(line, 
DiscoveryUtils.LogOrigin.BuildLog, artifacts, null, false);
+        assert artifacts.languageArtifacts.contains(artifact);
     }
 }

[hg] main-silver: implement build artifacts provider (build log ...

Alexander Simon 02/04/2013

Project Features

About this Project

CND was started in November 2009, is owned by Leonid Lenyashin, and has 130 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close