@@ -111,19 +111,6 @@ $buildRootPath = Split-Path $antBuildFile -Parent
111111$reportDirectoryName = " ReportDirectory75C12DBC"
112112$reportDirectory = Join-Path $buildRootPath $reportDirectoryName
113113
114- try
115- {
116- if (Test-Path $reportDirectory )
117- {
118- # delete any previous code coverage data
119- rm - r $reportDirectory - force | Out-Null
120- }
121- }
122- catch
123- {
124- Write-Verbose " Failed to delete report directory"
125- }
126-
127114if ($isCoverageEnabled )
128115{
129116 if ($codeCoverageTool -eq " Cobertura" )
@@ -145,61 +132,34 @@ $reportBuildFileName = "ReportBuildFile9B5907FC.xml"
145132$reportBuildFile = Join-Path $buildRootPath $reportBuildFileName
146133$instrumentedClassesDirectory = Join-Path $buildRootPath " InstrumentedClasses"
147134
148- try
135+ if ( $isCoverageEnabled )
149136{
150- if (Test-Path $reportBuildFile )
137+ Remove-Item - Recurse - Force $reportDirectory - ErrorAction SilentlyContinue
138+ Remove-Item - Recurse - Force $reportBuildFile - ErrorAction SilentlyContinue
139+ Remove-Item - Recurse - Force $instrumentedClassesDirectory - ErrorAction SilentlyContinue
140+
141+ # Create temp copy - requried in case of TFVC
142+ Copy-Item $antBuildFile " $antBuildFile .tmp" - Force - ErrorAction Continue
143+ Set-ItemProperty $antBuildFile - Name Attributes - Value Normal
144+
145+ try
151146 {
152- # delete any previous code coverage report build file
153- rm - r $reportBuildFile - force | Out-Null
147+ # Enable code coverage in build file
148+ if ($codeCoverageTool -eq " Cobertura" )
149+ {
150+ $coberturaCCFile = Join-Path $buildRootPath " cobertura.ser"
151+ Remove-Item - Recurse - Force $coberturaCCFile - ErrorAction SilentlyContinue
152+ Remove-Item - Recurse - Force $instrumentedClassesDirectory - ErrorAction SilentlyContinue
153+ }
154+
155+ Enable-CodeCoverage - BuildTool ' Ant' - BuildFile $antBuildFile - CodeCoverageTool $codeCoverageTool - ClassFilter $classFilter - ClassFilesDirectories $classFilesDirectories - SourceDirectories $srcDirectories - SummaryFile $summaryFileName - ReportDirectory $reportDirectory - CCReportTask $CCReportTask - ReportBuildFile $reportBuildFile
156+ Write-Verbose " Code coverage is successfully enabled." - Verbose
154157 }
155- }
156- catch
157- {
158- Write-Verbose " Failed to delete report build file"
159- }
160-
161- try
162- {
163- if (Test-Path $instrumentedClassesDirectory )
158+ catch
164159 {
165- # delete any previous instrumented classes directory
166- rm - r $instrumentedClassesDirectory - force | Out-Null
160+ Write-Warning " Enabling code coverage failed. Check the build logs for errors" - Verbose
167161 }
168162}
169- catch
170- {
171- Write-Verbose " Failed to delete instrumented classes directory"
172- }
173-
174- if ($isCoverageEnabled )
175- {
176- try
177- {
178- # Enable code coverage in build file
179- if ($codeCoverageTool -eq " Cobertura" )
180- {
181- $coberturaCCFile = Join-Path $buildRootPath " cobertura.ser"
182- if (Test-Path $coberturaCCFile )
183- {
184- # delete any previous cobertura code coverage file
185- rm - r $coberturaCCFile - force | Out-Null
186- }
187-
188- if (Test-Path $instrumentedClassesDirectory )
189- {
190- # delete any previous cobertura instrumented classes
191- rm - r $instrumentedClassesDirectory - force | Out-Null
192- }
193- }
194-
195- Enable-CodeCoverage - BuildTool ' Ant' - BuildFile $antBuildFile - CodeCoverageTool $codeCoverageTool - ClassFilter $classFilter - ClassFilesDirectories $classFilesDirectories - SourceDirectories $srcDirectories - SummaryFile $summaryFileName - ReportDirectory $reportDirectory - CCReportTask $CCReportTask - ReportBuildFile $reportBuildFile
196- Write-Verbose " Code coverage is successfully enabled." - Verbose
197- }
198- catch
199- {
200- Write-Warning " Enabling code coverage failed. Check the build logs for errors" - Verbose
201- }
202- }
203163else
204164{
205165 Write-Verbose " Option to enable code coverage was not selected and is being skipped." - Verbose
@@ -222,19 +182,19 @@ if($publishJUnitResultsFromAntBuild)
222182 else
223183 {
224184 Write-Verbose " Calling Publish-TestResults"
225- $runTitleMemberExists = CmdletHasMember " RunTitle"
226- if ($runTitleMemberExists )
227- {
228- Publish-TestResults - TestRunner " JUnit" - TestResultsFiles $matchingTestResultsFiles - Context $distributedTaskContext - RunTitle $testRunTitle - MergeResults $true
229- }
230- else
231- {
232- if (! ([string ]::IsNullOrWhiteSpace($testRunTitle )))
233- {
234- Write-Warning " Update the build agent to be able to use the custom run title feature."
235- }
236- Publish-TestResults - TestRunner " JUnit" - TestResultsFiles $matchingTestResultsFiles - Context $distributedTaskContext - MergeResults $true
237- }
185+ $runTitleMemberExists = CmdletHasMember " RunTitle"
186+ if ($runTitleMemberExists )
187+ {
188+ Publish-TestResults - TestRunner " JUnit" - TestResultsFiles $matchingTestResultsFiles - Context $distributedTaskContext - RunTitle $testRunTitle - MergeResults $true
189+ }
190+ else
191+ {
192+ if (! ([string ]::IsNullOrWhiteSpace($testRunTitle )))
193+ {
194+ Write-Warning " Update the build agent to be able to use the custom run title feature."
195+ }
196+ Publish-TestResults - TestRunner " JUnit" - TestResultsFiles $matchingTestResultsFiles - Context $distributedTaskContext - MergeResults $true
197+ }
238198 }
239199}
240200else
@@ -246,27 +206,26 @@ else
246206if ($isCoverageEnabled )
247207{
248208
249- # run report code coverage task which generates code coverage reports.
250- $reportsGenerationFailed = $false
251- Write-Verbose " Collecting code coverage reports" - Verbose
252- try
253- {
254- if (Test-Path $reportBuildFile )
255- {
256- # This will handle compat between S91 and S92
257- Invoke-Ant - AntBuildFile $reportBuildFile - Targets $CCReportTask
258- }
259- else
260- {
261- Invoke-Ant - AntBuildFile $antBuildFile - Targets $CCReportTask
262- }
263- }
264- catch
265- {
266- $reportsGenerationFailed = $true
267- }
209+ # run report code coverage task which generates code coverage reports.
210+ $reportsGenerationFailed = $false
211+ Write-Verbose " Collecting code coverage reports" - Verbose
212+ try
213+ {
214+ if (Test-Path $reportBuildFile )
215+ {
216+ # This will handle compat between S91 and S92
217+ Invoke-Ant - AntBuildFile $reportBuildFile - Targets $CCReportTask
218+ }
219+ else
220+ {
221+ Invoke-Ant - AntBuildFile $antBuildFile - Targets $CCReportTask
222+ }
223+ }
224+ catch
225+ {
226+ $reportsGenerationFailed = $true
227+ }
268228
269-
270229 if (-not $reportsGenerationFailed -and (Test-Path $summaryFile ))
271230 {
272231 Write-Verbose " Summary file = $summaryFile " - Verbose
@@ -276,9 +235,13 @@ if($isCoverageEnabled)
276235 }
277236 else
278237 {
279- Write-Host " ##vso[task.logissue type=warning;code=006003;]"
238+ Write-Host " ##vso[task.logissue type=warning;code=006003;]"
280239 Write-Warning " No code coverage results found to be published. This could occur if there were no tests executed or there was a build failure. Check the ant output for details." - Verbose
281240 }
241+
242+ # Reset temp copy and file permissions are reset by default
243+ Copy-Item " $antBuildFile .tmp" $antBuildFile - Force - ErrorAction Continue
244+ Remove-Item " $antBuildFile .tmp" - Force - ErrorAction Continue
282245}
283246
284247Write-Verbose " Leaving script Ant.ps1"
0 commit comments