changeset 50:89220bce43c8

skipped source indexing of pdb's which weren't built during current build; the reason is that its impossible to construct url's for sources in this case
author Evgeniy.Koshkin
date Wed, 13 Nov 2013 21:26:53 +0400
parents 4c3322e901e1
children 39a530910a6a
files agent/src/jetbrains/buildServer/symbols/FileUrlProvider.java agent/src/jetbrains/buildServer/symbols/FileUrlProviderFactory.java agent/src/jetbrains/buildServer/symbols/PdbFilePatcher.java agent/src/jetbrains/buildServer/symbols/SrcSrvStreamBuilder.java agent/src/jetbrains/buildServer/symbols/SymbolsIndexer.java tests/src/PdbFilePatcherTest.java
diffstat 6 files changed, 55 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/agent/src/jetbrains/buildServer/symbols/FileUrlProvider.java	Wed Nov 13 19:49:28 2013 +0400
+++ b/agent/src/jetbrains/buildServer/symbols/FileUrlProvider.java	Wed Nov 13 21:26:53 2013 +0400
@@ -1,5 +1,8 @@
 package jetbrains.buildServer.symbols;
 
+import org.apache.log4j.Logger;
+import org.jetbrains.annotations.Nullable;
+
 import java.io.File;
 import java.io.IOException;
 
@@ -7,22 +10,31 @@
  * @author Evgeniy.Koshkin
  */
 public class FileUrlProvider {
+
+  private static final Logger LOG = Logger.getLogger(FileUrlProvider.class);
+
   private final String myUrlPrefix;
   private final long myBuildId;
-  private final File mySourcesRootDirectory;
+  private String mySourcesRootDirectoryCanonicalPath;
 
-  public FileUrlProvider(String serverUrl, long buildId, File sourcesRootDirectory) {
+  public FileUrlProvider(String serverUrl, long buildId, File sourcesRootDirectory) throws IOException {
     myUrlPrefix = serverUrl;
     myBuildId = buildId;
-    mySourcesRootDirectory = sourcesRootDirectory;
+    mySourcesRootDirectoryCanonicalPath = sourcesRootDirectory.getCanonicalPath();
   }
 
   public String getHttpAlias() {
     return String.format("%s/builds/id-%d/sources/files", myUrlPrefix, myBuildId);
   }
 
-  public String getFileUrl(String path) throws IOException {
-    String sourcesRootDirectoryPath = mySourcesRootDirectory.getCanonicalPath();
-    return path.substring(sourcesRootDirectoryPath.length() + 1).replace(File.separator, "/");
+  @Nullable
+  public String getFileUrl(File file) throws IOException {
+    final File canonicalFile = file.getCanonicalFile();
+    final String canonicalFilePath = canonicalFile.getPath();
+    if(!canonicalFilePath.startsWith(mySourcesRootDirectoryCanonicalPath)){
+      LOG.debug(String.format("Failed to construct URL for file %s. It locates outside of source root directory %s.", canonicalFile, mySourcesRootDirectoryCanonicalPath));
+      return null;
+    }
+    return canonicalFilePath.substring(mySourcesRootDirectoryCanonicalPath.length() + 1).replace(File.separator, "/");
   }
 }
--- a/agent/src/jetbrains/buildServer/symbols/FileUrlProviderFactory.java	Wed Nov 13 19:49:28 2013 +0400
+++ b/agent/src/jetbrains/buildServer/symbols/FileUrlProviderFactory.java	Wed Nov 13 21:26:53 2013 +0400
@@ -22,6 +22,8 @@
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import java.io.IOException;
+
 /**
  * @author Evgeniy.Koshkin
  */
@@ -32,7 +34,7 @@
   public static FileUrlProvider getProvider(@NotNull AgentRunningBuild build, @NotNull BuildProgressLogger buildLogger){
     String sourceServerUrlPrefix = build.getSharedConfigParameters().get(SymbolsConstants.SOURCES_SERVER_URL_PARAM_NAME);
     if(sourceServerUrlPrefix == null){
-      final String message = String.format("Configuration parameter %s was not set. ", SymbolsConstants.SOURCES_SERVER_URL_PARAM_NAME);
+      final String message = String.format("%s configuration parameter was not set. ", SymbolsConstants.SOURCES_SERVER_URL_PARAM_NAME);
       LOG.warn(message);
       buildLogger.warning(message);
       return null;
@@ -41,6 +43,11 @@
     buildLogger.message(message);
     LOG.debug(message);
     sourceServerUrlPrefix = sourceServerUrlPrefix.substring(0, sourceServerUrlPrefix.length() - 1); //cut last '/'
-    return new FileUrlProvider(sourceServerUrlPrefix, build.getBuildId(), build.getCheckoutDirectory());
+    try {
+      return new FileUrlProvider(sourceServerUrlPrefix, build.getBuildId(), build.getCheckoutDirectory());
+    } catch (IOException e) {
+      buildLogger.exception(e);
+      return null;
+    }
   }
 }
--- a/agent/src/jetbrains/buildServer/symbols/PdbFilePatcher.java	Wed Nov 13 19:49:28 2013 +0400
+++ b/agent/src/jetbrains/buildServer/symbols/PdbFilePatcher.java	Wed Nov 13 21:26:53 2013 +0400
@@ -32,14 +32,20 @@
 
   public void patch(File symbolsFile, BuildProgressLogger buildLogger) throws Exception {
     final Collection<File> sourceFiles = mySrcToolExe.getReferencedSourceFiles(symbolsFile);
+    final String symbolsFileCanonicalPath = symbolsFile.getCanonicalPath();
     if(sourceFiles.isEmpty()){
-      final String message = "No source information found in pdb file " + symbolsFile.getCanonicalPath();
+      final String message = "No source information found in pdb file " + symbolsFileCanonicalPath;
       buildLogger.warning(message);
       LOG.debug(message);
       return;
     }
     final File tmpFile = FileUtil.createTempFile(myWorkingDir, "pdb-", ".patch", false);
-    mySrcSrvStreamBuilder.dumpStreamToFile(tmpFile, sourceFiles);
+    int processedFilesCount = mySrcSrvStreamBuilder.dumpStreamToFile(tmpFile, sourceFiles);
+    if(processedFilesCount == 0){
+      buildLogger.warning(String.format("Sources appeared in file %s weren't actually indexed. Looks like related binary file wasn't built during current build.", symbolsFileCanonicalPath));
+    } else {
+      buildLogger.message(String.format("Information about %d source files was updated", processedFilesCount));
+    }
     myPdbStrExe.doCommand(PdbStrExeCommands.WRITE, symbolsFile, tmpFile, PdbStrExe.SRCSRV_STREAM_NAME);
   }
 }
--- a/agent/src/jetbrains/buildServer/symbols/SrcSrvStreamBuilder.java	Wed Nov 13 19:49:28 2013 +0400
+++ b/agent/src/jetbrains/buildServer/symbols/SrcSrvStreamBuilder.java	Wed Nov 13 21:26:53 2013 +0400
@@ -1,5 +1,7 @@
 package jetbrains.buildServer.symbols;
 
+import jetbrains.buildServer.agent.BuildProgressLogger;
+
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -11,12 +13,15 @@
 public class SrcSrvStreamBuilder {
 
   private final FileUrlProvider myUrlProvider;
+  private final BuildProgressLogger myProgressLogger;
 
-  public SrcSrvStreamBuilder(final FileUrlProvider urlProvider) {
+  public SrcSrvStreamBuilder(final FileUrlProvider urlProvider, BuildProgressLogger progressLogger) {
     myUrlProvider = urlProvider;
+    myProgressLogger = progressLogger;
   }
 
-  public void dumpStreamToFile(File targetFile, Collection<File> sourceFiles) throws IOException {
+  public int dumpStreamToFile(File targetFile, Collection<File> sourceFiles) throws IOException {
+    int processedFilesCount = 0;
     final FileWriter fileWriter = new FileWriter(targetFile.getPath(), true);
 
     try {
@@ -32,13 +37,22 @@
       fileWriter.write("SRCSRVCMD=\r\n");
       fileWriter.write("SRCSRV: source files ------------------------------------------\r\n");
       for(File sourceFile : sourceFiles){
-        final String sourceFileCanonical = sourceFile.getCanonicalPath();
-        fileWriter.write(String.format("%s*%s\r\n", sourceFileCanonical, myUrlProvider.getFileUrl(sourceFileCanonical)));
+        String url = null;
+        try{
+          url = myUrlProvider.getFileUrl(sourceFile);
+        } catch (Exception ex){
+          myProgressLogger.warning("Failed to calculate url for source file " + sourceFile);
+          myProgressLogger.exception(ex);
+        }
+        if(url == null) continue;
+        processedFilesCount++;
+        fileWriter.write(String.format("%s*%s\r\n", sourceFile, url));
       }
       fileWriter.write("SRCSRV: end ------------------------------------------------");
     }
     finally {
       fileWriter.close();
     }
+    return processedFilesCount;
   }
 }
--- a/agent/src/jetbrains/buildServer/symbols/SymbolsIndexer.java	Wed Nov 13 19:49:28 2013 +0400
+++ b/agent/src/jetbrains/buildServer/symbols/SymbolsIndexer.java	Wed Nov 13 21:26:53 2013 +0400
@@ -105,7 +105,7 @@
     final Collection<File> pdbFiles = getArtifactPathsByFileExtension(artifacts, PDB_FILE_EXTENSION);
     if(pdbFiles.isEmpty()) return;
 
-    final PdbFilePatcher pdbFilePatcher = new PdbFilePatcher(myBuildTempDirectory, mySrcSrvHomeDir, new SrcSrvStreamBuilder(myFileUrlProvider));
+    final PdbFilePatcher pdbFilePatcher = new PdbFilePatcher(myBuildTempDirectory, mySrcSrvHomeDir, new SrcSrvStreamBuilder(myFileUrlProvider, myProgressLogger));
     for(File pdbFile : pdbFiles){
       if(mySymbolsToProcess.contains(pdbFile)){
         LOG.debug(String.format("File %s already processed. Skipped.", pdbFile.getAbsolutePath()));
--- a/tests/src/PdbFilePatcherTest.java	Wed Nov 13 19:49:28 2013 +0400
+++ b/tests/src/PdbFilePatcherTest.java	Wed Nov 13 21:26:53 2013 +0400
@@ -20,7 +20,7 @@
   public void setUp() throws Exception {
     super.setUp();
     myTestHomeDir = createTempDir();
-    myPatcher = new PdbFilePatcher(myTestHomeDir, myTestHomeDir, new SrcSrvStreamBuilder(null));
+    myPatcher = new PdbFilePatcher(myTestHomeDir, myTestHomeDir, new SrcSrvStreamBuilder(null, null));
   }
 
   @Test