comparison agent/src/jetbrains/buildServer/symbols/SymbolsIndexer.java @ 12:662a0be55de7

- source indexing works! - few tests added
author Evgeniy.Koshkin
date Tue, 30 Jul 2013 22:10:30 +0400
parents 5fb218a7e574
children 5856cab1ca05
comparison
equal deleted inserted replaced
11:5fb218a7e574 12:662a0be55de7
24 public class SymbolsIndexer extends ArtifactsBuilderAdapter { 24 public class SymbolsIndexer extends ArtifactsBuilderAdapter {
25 25
26 private static final Logger LOG = Logger.getLogger(SymbolsIndexer.class); 26 private static final Logger LOG = Logger.getLogger(SymbolsIndexer.class);
27 27
28 public static final String PDB_FILE_EXTENSION = "pdb"; 28 public static final String PDB_FILE_EXTENSION = "pdb";
29 public static final String EXE_FILE_EXTENSION = "exe";
30 public static final String DLL_FILE_EXTENSION = "dll";
31 29
32 public static final String SYMBOLS_EXE = "JetBrains.CommandLine.Symbols.exe"; 30 public static final String SYMBOLS_EXE = "JetBrains.CommandLine.Symbols.exe";
33 public static final String DUMP_SYMBOL_SIGN_CMD = "dumpSymbolSign"; 31 public static final String DUMP_SYMBOL_SIGN_CMD = "dumpSymbolSign";
34 32
35 @NotNull private final ArtifactsWatcher myArtifactsWatcher; 33 @NotNull private final ArtifactsWatcher myArtifactsWatcher;
36 @NotNull private final File myNativeToolPath; 34 @NotNull private final File myNativeToolPath;
37 @Nullable private AgentRunningBuild myBuild; 35 @Nullable private AgentRunningBuild myBuild;
38 @Nullable private Collection<File> myBinariesToProcess;
39 @Nullable private Collection<File> mySymbolsToProcess; 36 @Nullable private Collection<File> mySymbolsToProcess;
40 37
41 public SymbolsIndexer(@NotNull final PluginDescriptor pluginDescriptor, @NotNull final EventDispatcher<AgentLifeCycleListener> agentDispatcher, @NotNull final ArtifactsWatcher artifactsWatcher) { 38 public SymbolsIndexer(@NotNull final PluginDescriptor pluginDescriptor, @NotNull final EventDispatcher<AgentLifeCycleListener> agentDispatcher, @NotNull final ArtifactsWatcher artifactsWatcher) {
39 myArtifactsWatcher = artifactsWatcher;
42 myNativeToolPath = new File(new File(pluginDescriptor.getPluginRoot(), "bin"), SYMBOLS_EXE); 40 myNativeToolPath = new File(new File(pluginDescriptor.getPluginRoot(), "bin"), SYMBOLS_EXE);
43 myArtifactsWatcher = artifactsWatcher; 41
44 agentDispatcher.addListener(new AgentLifeCycleAdapter() { 42 agentDispatcher.addListener(new AgentLifeCycleAdapter() {
45 @Override 43 @Override
46 public void buildStarted(@NotNull final AgentRunningBuild runningBuild) { 44 public void buildStarted(@NotNull final AgentRunningBuild runningBuild) {
47 myBuild = runningBuild; 45 myBuild = runningBuild;
48 myBinariesToProcess = new HashSet<File>();
49 mySymbolsToProcess = new HashSet<File>(); 46 mySymbolsToProcess = new HashSet<File>();
50 } 47 }
51 48
52 @Override 49 @Override
53 public void afterAtrifactsPublished(@NotNull AgentRunningBuild build, @NotNull BuildFinishedStatus buildStatus) { 50 public void afterAtrifactsPublished(@NotNull AgentRunningBuild build, @NotNull BuildFinishedStatus buildStatus) {
54 super.afterAtrifactsPublished(build, buildStatus); 51 super.afterAtrifactsPublished(build, buildStatus);
55 if (myBuild == null || mySymbolsToProcess == null || myBinariesToProcess == null) return; 52 if (myBuild == null || mySymbolsToProcess == null) return;
56 if(myBuild.getBuildFeaturesOfType(SymbolsConstants.BUILD_FEATURE_TYPE).isEmpty()) return; 53 if(myBuild.getBuildFeaturesOfType(SymbolsConstants.BUILD_FEATURE_TYPE).isEmpty()) return;
57 54
58 if (mySymbolsToProcess.isEmpty()) { 55 if (mySymbolsToProcess.isEmpty()) {
59 myBuild.getBuildLogger().warning("Symbols weren't found in artifacts to be published."); 56 myBuild.getBuildLogger().warning("Symbols weren't found in artifacts to be published.");
60 LOG.debug("Symbols weren't found in artifacts to be published."); 57 LOG.debug("Symbols weren't found in artifacts to be published.");
61 } else { 58 } else {
62 final File targetDir = myBuild.getBuildTempDirectory();
63 try { 59 try {
64 final File symbolSignaturesFile = dumpSymbolSignatures(mySymbolsToProcess, targetDir, myBuild.getBuildLogger()); 60 final File symbolSignaturesFile = dumpSymbolSignatures(mySymbolsToProcess, myBuild.getBuildTempDirectory(), myBuild.getBuildLogger());
65 if(symbolSignaturesFile.exists()){ 61 if(symbolSignaturesFile.exists()){
66 myArtifactsWatcher.addNewArtifactsPath(symbolSignaturesFile + "=>" + ".teamcity/symbols"); 62 myArtifactsWatcher.addNewArtifactsPath(symbolSignaturesFile + "=>" + ".teamcity/symbols");
67 } 63 }
68 } catch (IOException e) { 64 } catch (IOException e) {
69 LOG.error("Error while dumping symbols/binaries signatures.", e); 65 LOG.error("Error while dumping symbols/binaries signatures.", e);
70 myBuild.getBuildLogger().error("Error while dumping symbols/binaries signatures."); 66 myBuild.getBuildLogger().error("Error while dumping symbols/binaries signatures.");
71 myBuild.getBuildLogger().exception(e); 67 myBuild.getBuildLogger().exception(e);
72 } 68 }
73 } 69 }
74 mySymbolsToProcess = null; 70 mySymbolsToProcess = null;
75 myBinariesToProcess = null;
76 myBuild = null; 71 myBuild = null;
77 } 72 }
78 }); 73 });
79 } 74 }
80 75
81 @Override 76 @Override
82 public void afterCollectingFiles(@NotNull List<ArtifactsCollection> artifacts) { 77 public void afterCollectingFiles(@NotNull List<ArtifactsCollection> artifacts) {
83 super.afterCollectingFiles(artifacts); 78 super.afterCollectingFiles(artifacts);
84 if(myBuild == null || mySymbolsToProcess == null || myBinariesToProcess == null) return; 79 if(myBuild == null || mySymbolsToProcess == null) return;
85 if(myBuild.getBuildFeaturesOfType(SymbolsConstants.BUILD_FEATURE_TYPE).isEmpty()){ 80 if(myBuild.getBuildFeaturesOfType(SymbolsConstants.BUILD_FEATURE_TYPE).isEmpty()){
86 myBuild.getBuildLogger().warning(SymbolsConstants.BUILD_FEATURE_TYPE + " build feature disabled. No indexing performed."); 81 myBuild.getBuildLogger().warning(SymbolsConstants.BUILD_FEATURE_TYPE + " build feature disabled. No indexing performed.");
87 LOG.debug(SymbolsConstants.BUILD_FEATURE_TYPE + " build feature disabled. No indexing performed."); 82 LOG.debug(SymbolsConstants.BUILD_FEATURE_TYPE + " build feature disabled. No indexing performed.");
88 return; 83 return;
89 } 84 }
90 myBuild.getBuildLogger().message(SymbolsConstants.BUILD_FEATURE_TYPE + " build feature enabled. Searching for suitable files.");
91 LOG.debug(SymbolsConstants.BUILD_FEATURE_TYPE + " build feature enabled. Searching for suitable files."); 85 LOG.debug(SymbolsConstants.BUILD_FEATURE_TYPE + " build feature enabled. Searching for suitable files.");
92 mySymbolsToProcess.addAll(getArtifactPathsByFileExtension(artifacts, PDB_FILE_EXTENSION)); 86 Collection<File> pdbFiles = getArtifactPathsByFileExtension(artifacts, PDB_FILE_EXTENSION);
93 myBinariesToProcess.addAll(getArtifactPathsByFileExtension(artifacts, EXE_FILE_EXTENSION)); 87 final PdbFilePatcher pdbFilePatcher = new PdbFilePatcher(myBuild.getBuildTempDirectory(), new SrcSrvStreamProvider(myBuild.getBuildId(), myBuild.getCheckoutDirectory()));
94 myBinariesToProcess.addAll(getArtifactPathsByFileExtension(artifacts, DLL_FILE_EXTENSION)); 88 for(File pdbFile : pdbFiles){
89 try {
90 myBuild.getBuildLogger().message("Indexing sources appeared in file " + pdbFile.getAbsolutePath());
91 pdbFilePatcher.patch(pdbFile);
92 mySymbolsToProcess.add(pdbFile);
93 } catch (Throwable e) {
94 LOG.error("Error occurred while patching symbols file " + pdbFile, e);
95 myBuild.getBuildLogger().error("Error occurred while patching symbols file " + pdbFile);
96 myBuild.getBuildLogger().exception(e);
97 }
98 }
95 } 99 }
96 100
97 private Collection<File> getArtifactPathsByFileExtension(List<ArtifactsCollection> artifactsCollections, String fileExtension){ 101 private Collection<File> getArtifactPathsByFileExtension(List<ArtifactsCollection> artifactsCollections, String fileExtension){
98 final Collection<File> result = new HashSet<File>(); 102 final Collection<File> result = new HashSet<File>();
99 for(ArtifactsCollection artifactsCollection : artifactsCollections){ 103 for(ArtifactsCollection artifactsCollection : artifactsCollections){
106 return result; 110 return result;
107 } 111 }
108 112
109 private File dumpSymbolSignatures(Collection<File> files, File targetDir, BuildProgressLogger buildLogger) throws IOException { 113 private File dumpSymbolSignatures(Collection<File> files, File targetDir, BuildProgressLogger buildLogger) throws IOException {
110 final File tempFile = FileUtil.createTempFile(targetDir, "symbol-signatures-", ".xml", false); 114 final File tempFile = FileUtil.createTempFile(targetDir, "symbol-signatures-", ".xml", false);
111 runTool(DUMP_SYMBOL_SIGN_CMD, files, tempFile, buildLogger); 115 runNativeTool(DUMP_SYMBOL_SIGN_CMD, files, tempFile, buildLogger);
112 return tempFile; 116 return tempFile;
113 } 117 }
114 118
115 private void runTool(String cmd, Collection<File> files, File output, BuildProgressLogger buildLogger){ 119 private void runNativeTool(String cmd, Collection<File> files, File output, BuildProgressLogger buildLogger){
116 final GeneralCommandLine commandLine = new GeneralCommandLine(); 120 final GeneralCommandLine commandLine = new GeneralCommandLine();
117 commandLine.setExePath(myNativeToolPath.getPath()); 121 commandLine.setExePath(myNativeToolPath.getPath());
118 commandLine.addParameter(cmd); 122 commandLine.addParameter(cmd);
119 commandLine.addParameter(String.format("/o=\"%s\"", output.getPath())); 123 commandLine.addParameter(String.format("/o=\"%s\"", output.getPath()));
120 for(File file : files){ 124 for(File file : files){