@@ -111,29 +111,16 @@ $buildRootPath = Split-Path $antBuildFile -Parent
111111$reportDirectoryName = " ReportDirectory75C12DBC"
112112$reportDirectory = Join-Path $buildRootPath $reportDirectoryName
113113
114- try
114+ if ( $isCoverageEnabled )
115115{
116- if ( Test-Path $reportDirectory )
116+ if ( $codeCoverageTool -eq " Cobertura " )
117117 {
118- # delete any previous code coverage data
119- rm - r $reportDirectory - force | Out-Null
118+ $summaryFileName = " coverage.xml"
119+ }
120+ ElseIf ($codeCoverageTool -eq " JaCoCo" )
121+ {
122+ $summaryFileName = " summary.xml"
120123 }
121- }
122- catch
123- {
124- Write-Verbose " Failed to delete report directory"
125- }
126-
127- if ($isCoverageEnabled )
128- {
129- if ($codeCoverageTool -eq " Cobertura" )
130- {
131- $summaryFileName = " coverage.xml"
132- }
133- ElseIf ($codeCoverageTool -eq " JaCoCo" )
134- {
135- $summaryFileName = " summary.xml"
136- }
137124}
138125
139126$summaryFile = Join-Path $buildRootPath $reportDirectoryName
@@ -145,61 +132,37 @@ $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 SilentlyContinue
143+ Get-ChildItem - LiteralPath $env: BUILD_SOURCESDIRECTORY - Filter ' *.xml' - Recurse |
144+ ForEach-Object {
145+ Set-ItemProperty - LiteralPath $_.FullName - Name Attributes - Value Normal - Force - ErrorAction SilentlyContinue
146+ }
147+
148+ try
151149 {
152- # delete any previous code coverage report build file
153- rm - r $reportBuildFile - force | Out-Null
150+ # Enable code coverage in build file
151+ if ($codeCoverageTool -eq " Cobertura" )
152+ {
153+ $coberturaCCFile = Join-Path $buildRootPath " cobertura.ser"
154+ Remove-Item - Recurse - Force $coberturaCCFile - ErrorAction SilentlyContinue
155+ Remove-Item - Recurse - Force $instrumentedClassesDirectory - ErrorAction SilentlyContinue
156+ }
157+
158+ Enable-CodeCoverage - BuildTool ' Ant' - BuildFile $antBuildFile - CodeCoverageTool $codeCoverageTool - ClassFilter $classFilter - ClassFilesDirectories $classFilesDirectories - SourceDirectories $srcDirectories - SummaryFile $summaryFileName - ReportDirectory $reportDirectory - CCReportTask $CCReportTask - ReportBuildFile $reportBuildFile
159+ Write-Verbose " Code coverage is successfully enabled." - Verbose
154160 }
155- }
156- catch
157- {
158- Write-Verbose " Failed to delete report build file"
159- }
160-
161- try
162- {
163- if (Test-Path $instrumentedClassesDirectory )
161+ catch
164162 {
165- # delete any previous instrumented classes directory
166- rm - r $instrumentedClassesDirectory - force | Out-Null
163+ Write-Warning " Enabling code coverage failed. Check the build logs for errors" - Verbose
167164 }
168165}
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- }
203166else
204167{
205168 Write-Verbose " Option to enable code coverage was not selected and is being skipped." - Verbose
@@ -222,19 +185,19 @@ if($publishJUnitResultsFromAntBuild)
222185 else
223186 {
224187 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- }
188+ $runTitleMemberExists = CmdletHasMember " RunTitle"
189+ if ($runTitleMemberExists )
190+ {
191+ Publish-TestResults - TestRunner " JUnit" - TestResultsFiles $matchingTestResultsFiles - Context $distributedTaskContext - RunTitle $testRunTitle - MergeResults $true
192+ }
193+ else
194+ {
195+ if (! ([string ]::IsNullOrWhiteSpace($testRunTitle )))
196+ {
197+ Write-Warning " Update the build agent to be able to use the custom run title feature."
198+ }
199+ Publish-TestResults - TestRunner " JUnit" - TestResultsFiles $matchingTestResultsFiles - Context $distributedTaskContext - MergeResults $true
200+ }
238201 }
239202}
240203else
@@ -245,40 +208,43 @@ else
245208# check if code coverage has been enabled
246209if ($isCoverageEnabled )
247210{
248-
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- }
211+
212+ # run report code coverage task which generates code coverage reports.
213+ $reportsGenerationFailed = $false
214+ Write-Verbose " Collecting code coverage reports" - Verbose
215+ try
216+ {
217+ if (Test-Path $reportBuildFile )
218+ {
219+ # This will handle compat between S91 and S92
220+ Invoke-Ant - AntBuildFile $reportBuildFile - Targets $CCReportTask
221+ }
222+ else
223+ {
224+ Invoke-Ant - AntBuildFile $antBuildFile - Targets $CCReportTask
225+ }
226+ }
227+ catch
228+ {
229+ $reportsGenerationFailed = $true
230+ }
268231
269-
270- if (-not $reportsGenerationFailed -and (Test-Path $summaryFile ))
271- {
272- Write-Verbose " Summary file = $summaryFile " - Verbose
273- Write-Verbose " Report directory = $reportDirectory " - Verbose
274- Write-Verbose " Calling Publish-CodeCoverage" - Verbose
275- Publish-CodeCoverage - CodeCoverageTool $codeCoverageTool - SummaryFileLocation $summaryFile - ReportDirectory $reportDirectory - Context $distributedTaskContext
276- }
277- else
278- {
279- Write-Host " ##vso[task.logissue type=warning;code=006003;]"
280- 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
281- }
232+ if (-not $reportsGenerationFailed -and (Test-Path $summaryFile ))
233+ {
234+ Write-Verbose " Summary file = $summaryFile " - Verbose
235+ Write-Verbose " Report directory = $reportDirectory " - Verbose
236+ Write-Verbose " Calling Publish-CodeCoverage" - Verbose
237+ Publish-CodeCoverage - CodeCoverageTool $codeCoverageTool - SummaryFileLocation $summaryFile - ReportDirectory $reportDirectory - Context $distributedTaskContext
238+ }
239+ else
240+ {
241+ Write-Host " ##vso[task.logissue type=warning;code=006003;]"
242+ 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
243+ }
244+
245+ # Reset temp copy and file permissions are reset by default
246+ Copy-Item " $antBuildFile .tmp" $antBuildFile - Force - ErrorAction SilentlyContinue
247+ Remove-Item " $antBuildFile .tmp" - Force - ErrorAction SilentlyContinue
282248}
283249
284250Write-Verbose " Leaving script Ant.ps1"
0 commit comments