private void ProcessLineCoverage(TraceFile trace, Archive archive, Config config, Config.ConfigForProcess processConfig, IUpload upload, LineCoverageMerger coverageMerger) { logger.Debug("Preparing line coverage from {traceFile} for {upload}", trace.FilePath, upload.Describe()); RevisionFileUtils.RevisionOrTimestamp timestampOrRevision = ParseRevisionFile(trace, processConfig); Dictionary <string, FileCoverage> lineCoverage = ConvertTraceFileToLineCoverage(trace, archive, processConfig); if (timestampOrRevision == null || lineCoverage == null) { return; } if (config.ArchiveLineCoverage) { archive.ArchiveLineCoverage(Path.GetFileName(trace.FilePath) + ".simple", LineCoverageSynthesizer.ConvertToLineCoverageReport(lineCoverage)); } if (processConfig.MergeLineCoverage) { logger.Debug("Merging line coverage from {traceFile} into previous line coverage", trace.FilePath); coverageMerger.AddLineCoverage(trace.FilePath, timestampOrRevision, upload, lineCoverage); return; } logger.Debug("Uploading line coverage from {traceFile} to {upload}", trace.FilePath, upload.Describe()); string report = LineCoverageSynthesizer.ConvertToLineCoverageReport(lineCoverage); if (RunSync(upload.UploadLineCoverageAsync(trace.FilePath, report, timestampOrRevision))) { archive.ArchiveUploadedFile(trace.FilePath); } else { logger.Error("Failed to upload line coverage from {traceFile} to {upload}. Will retry later", trace.FilePath, upload.Describe()); } }
public Task <bool> UploadLineCoverageAsync(string originalTraceFilePath, string lineCoverageReport, RevisionFileUtils.RevisionOrTimestamp revisionOrTimestamp) { long unixSeconds = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); string filePath = Path.Combine(targetDirectory, $"{unixSeconds}.simple"); string metadataFilePath = Path.Combine(targetDirectory, $"{unixSeconds}.metadata"); try { fileSystem.File.WriteAllText(filePath, lineCoverageReport); fileSystem.File.WriteAllText(metadataFilePath, revisionOrTimestamp.ToRevisionFileContent()); return(Task.FromResult(true)); } catch (Exception e) { logger.Error(e, "Failed to upload line coverage from {trace} to {targetDirectory}. Will retry later", originalTraceFilePath, targetDirectory); return(Task.FromResult(false)); } }
public async Task <bool> UploadLineCoverageAsync(string originalTraceFilePath, string lineCoverageReport, RevisionFileUtils.RevisionOrTimestamp revisionOrTimestamp) { try { CloudStorageAccount account = GetStorageAccount(); logger.Debug("Uploading line coverage from {trace} to {azure}/{directory}/", originalTraceFilePath, account.FileStorageUri, storage.Directory); CloudFileShare share = await GetOrCreateShareAsync(account); CloudFileDirectory directory = await GetOrCreateTargetDirectoryAsync(share); long unixSeconds = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); await UploadTextAsync(lineCoverageReport, $"{unixSeconds}.simple", directory); await UploadTextAsync(revisionOrTimestamp.ToRevisionFileContent(), $"{unixSeconds}.metadata", directory); logger.Info("Successfully uploaded line coverage from {trace} to {azure}/{directory}", originalTraceFilePath, account.FileStorageUri, storage.Directory); return(true); } catch (Exception e) { logger.Error(e, "Upload of line coverage from {trace} to Azure File Storage failed", originalTraceFilePath); return(false); } }
public CoverageBatch(IUpload upload, RevisionFileUtils.RevisionOrTimestamp revisionOrTimestamp) { this.Upload = upload; this.RevisionOrTimestamp = revisionOrTimestamp; }
public async Task <bool> UploadLineCoverageAsync(string originalTraceFilePath, string lineCoverageReport, RevisionFileUtils.RevisionOrTimestamp revisionOrTimestamp) { string timestampParameter; if (revisionOrTimestamp.IsRevision) { timestampParameter = "revision"; } else { timestampParameter = "t"; } string message = messageFormatter.Format(timestampParameter); string encodedMessage = HttpUtility.UrlEncode(message); string encodedProject = HttpUtility.UrlEncode(server.Project); string encodedTimestamp = HttpUtility.UrlEncode(revisionOrTimestamp.Value); string encodedPartition = HttpUtility.UrlEncode(server.Partition); string url = $"{server.Url}/p/{encodedProject}/external-report?format=SIMPLE" + $"&message={encodedMessage}&partition={encodedPartition}&adjusttimestamp=true&movetolastcommit=true" + $"&{timestampParameter}={encodedTimestamp}"; logger.Debug("Uploading line coverage from {trace} to {teamscale} ({url})", originalTraceFilePath, server.ToString(), url); try { byte[] reportBytes = Encoding.UTF8.GetBytes(lineCoverageReport); using (MemoryStream stream = new MemoryStream(reportBytes)) { return(await PerformLineCoverageUpload(originalTraceFilePath, timestampParameter, revisionOrTimestamp.Value, url, stream)); } } catch (Exception e) { logger.Error(e, "Upload of line coverage from {trace} to {teamscale} failed due to an exception." + " Will retry later", originalTraceFilePath, server.ToString()); return(false); } }