├── .github ├── CODEOWNERS ├── dependabot.yml └── workflows │ └── jenkins-security-scan.yml ├── .gitignore ├── .mvn ├── extensions.xml └── maven.config ├── .travis.yml ├── Jenkinsfile ├── LICENSE ├── README.md ├── pom.xml └── src ├── main ├── java │ └── hudson │ │ └── plugins │ │ ├── jacoco │ │ ├── ExecutionFileLoader.java │ │ ├── JacocoBuildAction.java │ │ ├── JacocoHealthReportDeltaThresholds.java │ │ ├── JacocoHealthReportThresholds.java │ │ ├── JacocoProjectAction.java │ │ ├── JacocoPublisher.java │ │ ├── JacocoReportDir.java │ │ ├── Rule.java │ │ ├── model │ │ │ ├── Coverage.java │ │ │ ├── CoverageElement.java │ │ │ ├── CoverageGraphLayout.java │ │ │ ├── CoverageObject.java │ │ │ └── ModuleInfo.java │ │ ├── portlet │ │ │ ├── JacocoLoadData.java │ │ │ ├── bean │ │ │ │ ├── JacocoCoverageResultSummary.java │ │ │ │ └── JacocoDeltaCoverageResultSummary.java │ │ │ ├── chart │ │ │ │ └── JacocoBuilderTrendChart.java │ │ │ ├── grid │ │ │ │ └── JacocoBuilderGrid.java │ │ │ └── utils │ │ │ │ ├── Constants.java │ │ │ │ └── Utils.java │ │ ├── report │ │ │ ├── AbstractReport.java │ │ │ ├── AggregatedReport.java │ │ │ ├── ClassReport.java │ │ │ ├── CoverageReport.java │ │ │ ├── MethodReport.java │ │ │ ├── PackageReport.java │ │ │ ├── SourceAnnotator.java │ │ │ └── SourceFileReport.java │ │ └── rules │ │ │ └── LineCoveragePerSourceFileRule.java │ │ └── jacococoveragecolumn │ │ ├── AbstractJaCoCoCoverageColumn.java │ │ ├── BranchCoverageColumn.java │ │ ├── CoverageRange.java │ │ └── JaCoCoColumn.java ├── resources │ ├── hudson │ │ └── plugins │ │ │ ├── jacoco │ │ │ ├── JacocoBuildAction │ │ │ │ └── summary.jelly │ │ │ ├── JacocoProjectAction │ │ │ │ ├── floatingBox.jelly │ │ │ │ ├── floatingBox_de.properties │ │ │ │ ├── floatingBox_es.properties │ │ │ │ ├── floatingBox_ja.properties │ │ │ │ ├── index.jelly │ │ │ │ ├── index_de.properties │ │ │ │ ├── index_es.properties │ │ │ │ └── index_ja.properties │ │ │ ├── JacocoPublisher │ │ │ │ ├── config.jelly │ │ │ │ ├── config.properties │ │ │ │ ├── config_es.properties │ │ │ │ ├── config_ja.properties │ │ │ │ ├── global.jelly │ │ │ │ ├── help-buildOverBuild.html │ │ │ │ ├── help-changeBuildStatus.html │ │ │ │ ├── help-classPattern.html │ │ │ │ ├── help-deltaBranchCoverage.html │ │ │ │ ├── help-deltaClassCoverage.html │ │ │ │ ├── help-deltaComplexityCoverage.html │ │ │ │ ├── help-deltaInstructionCoverage.html │ │ │ │ ├── help-deltaLineCoverage.html │ │ │ │ ├── help-deltaMethodCoverage.html │ │ │ │ ├── help-exclusionPattern.html │ │ │ │ ├── help-execPattern.html │ │ │ │ ├── help-inclusionPattern.html │ │ │ │ ├── help-maximumBranchCoverage.html │ │ │ │ ├── help-maximumClassCoverage.html │ │ │ │ ├── help-maximumComplexityCoverage.html │ │ │ │ ├── help-maximumInstructionCoverage.html │ │ │ │ ├── help-maximumLineCoverage.html │ │ │ │ ├── help-maximumMethodCoverage.html │ │ │ │ ├── help-minimumBranchCoverage.html │ │ │ │ ├── help-minimumClassCoverage.html │ │ │ │ ├── help-minimumComplexityCoverage.html │ │ │ │ ├── help-minimumInstructionCoverage.html │ │ │ │ ├── help-minimumLineCoverage.html │ │ │ │ ├── help-minimumMethodCoverage.html │ │ │ │ ├── help-runAlways.html │ │ │ │ ├── help-skipCopyOfSrcFiles.html │ │ │ │ ├── help-sourceExclusionPattern.html │ │ │ │ ├── help-sourceInclusionPattern.html │ │ │ │ ├── help-sourcePattern.html │ │ │ │ └── help.html │ │ │ ├── Messages.properties │ │ │ ├── Messages_de.properties │ │ │ ├── Messages_es.properties │ │ │ ├── Messages_ja.properties │ │ │ ├── portlet │ │ │ │ ├── Messages.properties │ │ │ │ ├── chart │ │ │ │ │ └── JacocoBuilderTrendChart │ │ │ │ │ │ ├── config.jelly │ │ │ │ │ │ ├── config.properties │ │ │ │ │ │ ├── help-daysNumber.jelly │ │ │ │ │ │ ├── help-height.jelly │ │ │ │ │ │ ├── help-width.jelly │ │ │ │ │ │ ├── main.jelly │ │ │ │ │ │ ├── main.properties │ │ │ │ │ │ ├── portlet.jelly │ │ │ │ │ │ └── portlet.properties │ │ │ │ └── grid │ │ │ │ │ └── JacocoBuilderGrid │ │ │ │ │ ├── portlet.jelly │ │ │ │ │ └── portlet.properties │ │ │ ├── report │ │ │ │ ├── ClassReport │ │ │ │ │ ├── index.jelly │ │ │ │ │ ├── index_es.properties │ │ │ │ │ └── index_ja.properties │ │ │ │ ├── CoverageReport │ │ │ │ │ ├── index.jelly │ │ │ │ │ ├── index_es.properties │ │ │ │ │ └── index_ja.properties │ │ │ │ ├── MethodReport │ │ │ │ │ ├── index.jelly │ │ │ │ │ ├── index_es.properties │ │ │ │ │ └── index_ja.properties │ │ │ │ ├── PackageReport │ │ │ │ │ ├── index.jelly │ │ │ │ │ ├── index_es.properties │ │ │ │ │ └── index_ja.properties │ │ │ │ └── SourceFileReport │ │ │ │ │ ├── index.jelly │ │ │ │ │ ├── index_es.properties │ │ │ │ │ └── index_ja.properties │ │ │ └── tags │ │ │ │ ├── breakdownMethodsTable.jelly │ │ │ │ ├── breakdownTable.jelly │ │ │ │ ├── captionLine.jelly │ │ │ │ ├── captionLine_de.properties │ │ │ │ ├── captionLine_es.properties │ │ │ │ ├── captionLine_ja.properties │ │ │ │ ├── floatingTrendGraph.jelly │ │ │ │ ├── summaryMethod.jelly │ │ │ │ ├── summaryTable.jelly │ │ │ │ └── taglib │ │ │ └── jacococoveragecolumn │ │ │ ├── BranchCoverageColumn │ │ │ ├── column.jelly │ │ │ ├── columnHeader.jelly │ │ │ ├── columnHeader_de.properties │ │ │ ├── column_de.properties │ │ │ ├── config.jelly │ │ │ └── config_de.properties │ │ │ └── JaCoCoColumn │ │ │ ├── column.jelly │ │ │ ├── columnHeader.jelly │ │ │ ├── columnHeader_de.properties │ │ │ ├── column_de.properties │ │ │ ├── config.jelly │ │ │ └── config_de.properties │ └── index.jelly └── webapp │ ├── css │ ├── class.gif │ ├── greenbar.gif │ ├── method.gif │ ├── package.gif │ ├── redbar.gif │ └── style.css │ └── icons │ └── jacoco-48x48.png └── test ├── java └── hudson │ └── plugins │ ├── jacoco │ ├── AbstractJacocoTestBase.java │ ├── BuildOverBuildTest.java │ ├── CoverageReportTest.java │ ├── CoverageTest.java │ ├── ExecutionFileLoaderTest.java │ ├── JacocoBuildActionTest.java │ ├── JacocoConfigSubmitTest.java │ ├── JacocoHealthReportDeltaThresholdsTest.java │ ├── JacocoHealthReportThresholdsTest.java │ ├── JacocoPublisherTest.java │ ├── RunBuilder.java │ ├── WorkspaceBuilder.java │ ├── e2e │ │ └── E2ETest.java │ ├── model │ │ ├── CoverageGraphLayoutTest.java │ │ ├── CoverageObjectGraphTest.java │ │ ├── CoverageObjectTest.java │ │ └── TestCoverageObject.java │ ├── portlet │ │ ├── JacocoDeltaCoverageResultSummaryTest.java │ │ ├── JacocoLoadDataHudsonTest.java │ │ ├── bean │ │ │ └── JacocoCoverageResultSummaryTest.java │ │ ├── chart │ │ │ └── JacocoBuilderTrendChartTest.java │ │ └── utils │ │ │ ├── UtilsComparisonTest.java │ │ │ ├── UtilsHudsonTest.java │ │ │ └── UtilsParameterizedTest.java │ └── report │ │ ├── AbstractReportTest.java │ │ ├── AggregatedReportTest.java │ │ ├── ClassReportTest.java │ │ ├── CoverageReportTest.java │ │ ├── MethodReportTest.java │ │ ├── PackageReportTest.java │ │ ├── ReportFactory.java │ │ ├── SourceAnnotatorTest.java │ │ └── SourceFileReportTest.java │ └── jacococoveragecolumn │ ├── AbstractJaCoCoCoverageColumnTest.java │ ├── BranchCoverageColumnTest.java │ ├── CoverageRangeTest.java │ └── JaCoCoColumnTest.java └── resources ├── Font Monkey License.txt ├── baseStroke.png ├── baseStroke_2.png ├── baseStroke_3.png ├── belligerent.ttf ├── crop100.png ├── crop100_2.png ├── crop100_3.png ├── crop5.png ├── crop5_2.png ├── crop5_3.png ├── multiple.png ├── multiple_2.png ├── multiple_3.png ├── simple.png ├── simple_2.png ├── simple_3.png ├── singleBuild.png ├── singleBuild_2.png ├── singleBuild_3.png ├── skipzero.png ├── skipzero_2.png └── skipzero_3.png /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @jenkinsci/jacoco-plugin-developers 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /.github/workflows/jenkins-security-scan.yml: -------------------------------------------------------------------------------- 1 | name: Jenkins Security Scan 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | types: [ opened, synchronize, reopened ] 9 | workflow_dispatch: 10 | 11 | permissions: 12 | security-events: write 13 | contents: read 14 | actions: read 15 | 16 | jobs: 17 | security-scan: 18 | uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2 19 | with: 20 | java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate. 21 | # java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | work 3 | 4 | # IntelliJ project files 5 | *.iml 6 | *.ipr 7 | *.iws 8 | .idea 9 | 10 | # eclipse project file 11 | .settings 12 | .classpath 13 | .project 14 | build 15 | 16 | # Generated images from CoverageObjectGraphTest 17 | /*.png 18 | 19 | # other 20 | *~ 21 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | io.jenkins.tools.incrementals 4 | git-changelist-maven-extension 5 | 1.7 6 | 7 | 8 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -Pconsume-incrementals 2 | -Pmight-produce-incrementals 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Use xenial to still have OpenJDK 8 available 2 | dist: xenial 3 | language: java 4 | jdk: 5 | - openjdk8 6 | - openjdk11 7 | 8 | sudo: false 9 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env groovy 2 | 3 | /* `buildPlugin` step provided by: https://github.com/jenkins-infra/pipeline-library */ 4 | buildPlugin(useContainerAgent: true, configurations: [ 5 | [platform: 'linux', jdk: 21], 6 | [platform: 'windows', jdk: 17], 7 | ]) 8 | 9 | // More complex Jenkinsfile sample: https://github.com/jenkinsci/graphql-server-plugin/blob/master/Jenkinsfile 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Jenkins JaCoCo Plugin Community 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## This plugin reached end-of-life. 2 | 3 | All functionality has been integrated into the [Coverage Plugin](https://github.com/jenkinsci/coverage-plugin). Please use that plugin instead. It is available in the Jenkins update center. 4 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/ExecutionFileLoader.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import hudson.FilePath; 4 | 5 | import java.io.BufferedInputStream; 6 | import java.io.File; 7 | import java.io.FileInputStream; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.Serializable; 11 | import java.util.ArrayList; 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | import org.codehaus.plexus.util.FileUtils; 16 | import org.jacoco.core.analysis.Analyzer; 17 | import org.jacoco.core.analysis.CoverageBuilder; 18 | import org.jacoco.core.analysis.IBundleCoverage; 19 | import org.jacoco.core.data.ExecutionDataReader; 20 | import org.jacoco.core.data.ExecutionDataStore; 21 | import org.jacoco.core.data.SessionInfoStore; 22 | 23 | 24 | public class ExecutionFileLoader implements Serializable { 25 | private static final long serialVersionUID = 1L; 26 | private final static String[] STARSTAR = {"**"}; 27 | private final static String[] ITEM_ZERO = {"{0}"}; 28 | 29 | private String name; 30 | private FilePath srcDir; 31 | private FilePath classDir; 32 | private FilePath generatedHTMLsDir; 33 | private String[] includes; 34 | private String[] excludes; 35 | 36 | private transient ExecutionDataStore executionDataStore; 37 | private transient SessionInfoStore sessionInfoStore; 38 | 39 | private transient IBundleCoverage bundleCoverage; 40 | 41 | private ArrayList execFiles; 42 | 43 | public ExecutionFileLoader() { 44 | execFiles= new ArrayList<>(); 45 | } 46 | 47 | public void addExecFile(FilePath execFile) { 48 | execFiles.add(execFile); 49 | } 50 | 51 | public IBundleCoverage getBundleCoverage() { 52 | return bundleCoverage; 53 | } 54 | public String getName() { 55 | return name; 56 | } 57 | public void setName(String name) { 58 | this.name = name; 59 | } 60 | public void setBundleCoverage(IBundleCoverage bundleCoverage) { 61 | this.bundleCoverage = bundleCoverage; 62 | } 63 | public FilePath getGeneratedHTMLsDir() { 64 | return generatedHTMLsDir; 65 | } 66 | public void setGeneratedHTMLsDir(FilePath generatedHTMLsDir) { 67 | this.generatedHTMLsDir = generatedHTMLsDir; 68 | } 69 | public FilePath getSrcDir() { 70 | return srcDir; 71 | } 72 | public void setSrcDir(FilePath srcDir) { 73 | this.srcDir = srcDir; 74 | } 75 | public FilePath getClassDir() { 76 | return classDir; 77 | } 78 | public void setClassDir(FilePath classDir) { 79 | this.classDir = classDir; 80 | } 81 | private void loadExecutionData() throws IOException { 82 | 83 | executionDataStore = new ExecutionDataStore(); 84 | sessionInfoStore = new SessionInfoStore(); 85 | 86 | for (FilePath filePath : execFiles) { 87 | File executionDataFile = new File(filePath.getRemote()); 88 | try { 89 | try (final InputStream inputStream = new BufferedInputStream( 90 | new FileInputStream(executionDataFile))) { 91 | final ExecutionDataReader reader = new ExecutionDataReader(inputStream); 92 | reader.setSessionInfoVisitor(sessionInfoStore); 93 | reader.setExecutionDataVisitor(executionDataStore); 94 | reader.read(); 95 | } 96 | } catch (final IOException e) { 97 | throw new IOException("While reading execution data-file: " + executionDataFile, e); 98 | } 99 | } 100 | } 101 | private IBundleCoverage analyzeStructure() throws IOException { 102 | 103 | File classDirectory = new File(classDir.getRemote()); 104 | if (!classDirectory.exists()) { 105 | return null; 106 | } 107 | final CoverageBuilder coverageBuilder = new CoverageBuilder(); 108 | final Analyzer analyzer = new Analyzer(executionDataStore, 109 | coverageBuilder); 110 | 111 | if (includes==null) { 112 | includes = STARSTAR; 113 | } else if (includes.length == 0) { 114 | includes = STARSTAR; 115 | } else if ((includes.length == 1) && ("".equals(includes[0]))) { 116 | includes = STARSTAR; 117 | } 118 | if (excludes==null) { 119 | excludes = ITEM_ZERO; 120 | } else if (excludes.length==0) { 121 | excludes = ITEM_ZERO; 122 | } 123 | 124 | try { 125 | final List filesToAnalyze = FileUtils.getFiles(classDirectory, String.join(",", includes), String.join(",", excludes)); 126 | for (final File file : filesToAnalyze) { 127 | analyzer.analyzeAll(file); 128 | } 129 | } catch (IOException e) { 130 | throw new IOException("While reading class directory: " + classDirectory, e); 131 | } catch (RuntimeException e) { 132 | throw new RuntimeException("While reading class directory: " + classDirectory, e); 133 | } 134 | return coverageBuilder.getBundle(name); 135 | } 136 | public IBundleCoverage loadBundleCoverage() throws IOException { 137 | loadExecutionData(); 138 | this.bundleCoverage = analyzeStructure(); 139 | return this.bundleCoverage; 140 | } 141 | 142 | public void setIncludes(String... includes) { 143 | this.includes = includes; 144 | } 145 | 146 | public void setExcludes(String... excludes) { 147 | this.excludes = excludes; 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/JacocoHealthReportDeltaThresholds.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import hudson.plugins.jacoco.portlet.utils.Constants; 4 | 5 | import java.math.BigDecimal; 6 | 7 | /** 8 | * This class encapsulates delta thresholds configured by the user. 9 | * The threshold values are interpreted as percentages 10 | */ 11 | public class JacocoHealthReportDeltaThresholds { 12 | 13 | /** 14 | * Variables to hold delta threshold values for different types of percentage coverages 15 | */ 16 | private float deltaInstruction; 17 | private float deltaBranch; 18 | private float deltaComplexity; 19 | private float deltaLine; 20 | private float deltaMethod; 21 | private float deltaClass; 22 | 23 | public JacocoHealthReportDeltaThresholds() { 24 | } 25 | 26 | // Constructor used for bounding user-configured string threshold values to corresponding big decimal thresholds 27 | public JacocoHealthReportDeltaThresholds(String deltaInstruction, String deltaBranch, String deltaComplexity, String deltaLine, String deltaMethod, String deltaClass){ 28 | this.deltaInstruction = deltaInstruction!=null ? Float.parseFloat(deltaInstruction) : 0f; 29 | this.deltaBranch = deltaBranch!=null ? Float.parseFloat(deltaBranch) : 0f; 30 | this.deltaComplexity = deltaComplexity!=null ? Float.parseFloat(deltaComplexity) : 0f; 31 | this.deltaLine = deltaLine!=null ? Float.parseFloat(deltaLine) : 0f; 32 | this.deltaMethod = deltaMethod!=null ? Float.parseFloat(deltaMethod) : 0f; 33 | this.deltaClass = deltaClass!=null ? Float.parseFloat(deltaClass): 0f; 34 | this.ensureValid(); // Validate threshold values while creating new object to encapsulate these 35 | } 36 | 37 | // Used to apply [0,100] range over threshold values 38 | // 0 is set if threshold is smaller than 0 and 100 is set if threshold is bigger than 100, else remains unchanged 39 | private float applyRange(float min, float value, float max){ 40 | if(value < min) 41 | return min; 42 | else if(value > max) 43 | return max; 44 | else 45 | return value; 46 | 47 | } 48 | 49 | // Ensure if the threshold values are within [0, 100] percentage range 50 | public void ensureValid(){ 51 | float min = 0f; 52 | float max = 100f; 53 | 54 | this.deltaInstruction = applyRange(min, this.deltaInstruction, max); 55 | this.deltaBranch = applyRange(min, this.deltaBranch, max); 56 | this.deltaComplexity = applyRange(min, this.deltaComplexity, max); 57 | this.deltaLine = applyRange(min, this.deltaLine, max); 58 | this.deltaMethod = applyRange(min, this.deltaMethod, max); 59 | this.deltaClass = applyRange(min, this.deltaClass, max); 60 | } 61 | 62 | public float getDeltaInstruction() { 63 | return deltaInstruction; 64 | } 65 | 66 | public void setDeltaInstruction(float deltaInstruction) { 67 | this.deltaInstruction = deltaInstruction; 68 | } 69 | 70 | public float getDeltaBranch() { 71 | return deltaBranch; 72 | } 73 | 74 | public void setDeltaBranch(float deltaBranch) { 75 | this.deltaBranch = deltaBranch; 76 | } 77 | 78 | public float getDeltaComplexity() { 79 | return deltaComplexity; 80 | } 81 | 82 | public void setDeltaComplexity(float deltaComplexity) { 83 | this.deltaComplexity = deltaComplexity; 84 | } 85 | 86 | public float getDeltaLine() { 87 | return deltaLine; 88 | } 89 | 90 | public void setDeltaLine(float deltaLine) { 91 | this.deltaLine = deltaLine; 92 | } 93 | 94 | public float getDeltaMethod() { 95 | return deltaMethod; 96 | } 97 | 98 | public void setDeltaMethod(float deltaMethod) { 99 | this.deltaMethod = deltaMethod; 100 | } 101 | 102 | public float getDeltaClass() { 103 | return deltaClass; 104 | } 105 | 106 | public void setDeltaClass(float deltaClass) { 107 | this.deltaClass = deltaClass; 108 | } 109 | 110 | @Override 111 | public String toString() { 112 | return "JacocoHealthReportDeltaThresholds [" + 113 | "deltaInstruction=" + deltaInstruction + 114 | ", deltaBranch=" + deltaBranch + 115 | ", deltaComplexity=" + deltaComplexity + 116 | ", deltaLine=" + deltaLine + 117 | ", deltaMethod=" + deltaMethod + 118 | ", deltaClass=" + deltaClass + 119 | ']'; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/JacocoProjectAction.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import hudson.model.Action; 4 | import hudson.model.Job; 5 | import hudson.model.Result; 6 | import hudson.model.Run; 7 | 8 | import java.io.IOException; 9 | 10 | import org.kohsuke.stapler.StaplerRequest; 11 | import org.kohsuke.stapler.StaplerResponse; 12 | 13 | /** 14 | * Project view extension by JaCoCo plugin. 15 | * 16 | * @author Kohsuke Kawaguchi 17 | */ 18 | public final class JacocoProjectAction implements Action { 19 | public final Job project; 20 | 21 | public JacocoProjectAction(Job project) { 22 | this.project = project; 23 | } 24 | 25 | public String getIconFileName() { 26 | return "graph.gif"; 27 | } 28 | 29 | public String getDisplayName() { 30 | return Messages.ProjectAction_DisplayName(); 31 | } 32 | 33 | public String getUrlName() { 34 | return "jacoco"; 35 | } 36 | 37 | /** 38 | * Gets the most recent {@link JacocoBuildAction} object. 39 | * @return the most recent jacoco coverage report 40 | */ 41 | public JacocoBuildAction getLastResult() { 42 | for (Run b = project.getLastBuild(); b != null; b = b.getPreviousBuild()) { 43 | if (b.isBuilding() || b.getResult() == Result.FAILURE || b.getResult() == Result.ABORTED) 44 | continue; 45 | JacocoBuildAction r = b.getAction(JacocoBuildAction.class); 46 | if (r != null) 47 | return r; 48 | } 49 | return null; 50 | } 51 | 52 | public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException { 53 | if (getLastResult() != null) 54 | getLastResult().doGraph(req,rsp); 55 | } 56 | 57 | //private static final Logger logger = Logger.getLogger(JacocoBuildAction.class.getName()); 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/JacocoReportDir.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import hudson.FilePath; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import edu.umd.cs.findbugs.annotations.NonNull; 10 | 11 | /** 12 | * Encapsulates the directory structure in $JENKINS_HOME where we store jacoco related files. 13 | * 14 | * @author Kohsuke Kawaguchi 15 | */ 16 | public class JacocoReportDir { 17 | private final File root; 18 | 19 | public JacocoReportDir(File rootDir) { 20 | root = new File(rootDir, "jacoco"); 21 | } 22 | 23 | /** 24 | * Where we store *.class files, honoring package names as directories. 25 | * @return Directory to which we store *.class files, honoring package names as directories. 26 | */ 27 | public File getClassesDir() { 28 | return new File(root,"classes"); 29 | } 30 | 31 | public int saveClassesFrom(@NonNull FilePath dir, @NonNull String fileMask) throws IOException, InterruptedException { 32 | FilePath d = new FilePath(getClassesDir()); 33 | d.mkdirs(); 34 | return dir.copyRecursiveTo(fileMask, d); 35 | } 36 | 37 | /** 38 | * Where we store *.java files, honoring package names as directories. 39 | * @return Directory to which we store *.java files, honoring package names as directories. 40 | */ 41 | public File getSourcesDir() { 42 | return new File(root,"sources"); 43 | } 44 | 45 | public int saveSourcesFrom(@NonNull FilePath dir, @NonNull String inclusionMask, @NonNull String exclusionMask) throws IOException, InterruptedException { 46 | FilePath d = new FilePath(getSourcesDir()); 47 | d.mkdirs(); 48 | return dir.copyRecursiveTo(inclusionMask, exclusionMask, d); 49 | } 50 | 51 | /** 52 | * Root directory that stores jacoco.exec files. 53 | * Each exec file is stored in its own directory. 54 | * @return Directory that stores jacoco.exec files. 55 | * 56 | * @see #getExecFiles() 57 | */ 58 | public File getExecFilesDir() { 59 | return new File(root,"execFiles"); 60 | } 61 | 62 | /** 63 | * Lists up existing jacoco.exec files. 64 | * @return List of existing jacoco.exec files. 65 | */ 66 | public List getExecFiles() { 67 | List r = new ArrayList<>(); 68 | int i = 0; 69 | File root = getExecFilesDir(); 70 | File checkPath; 71 | while ((checkPath = new File(root, "exec" + i)).exists()) { 72 | r.add(new File(checkPath,"jacoco.exec")); 73 | i++; 74 | } 75 | 76 | return r; 77 | } 78 | 79 | public void addExecFiles(Iterable execFiles) throws IOException, InterruptedException { 80 | FilePath root = new FilePath(getExecFilesDir()); 81 | int i=0; 82 | for (FilePath file : execFiles) { 83 | FilePath separateExecDir; 84 | do { 85 | separateExecDir = new FilePath(root, "exec"+(i++)); 86 | } while (separateExecDir.exists()); 87 | 88 | FilePath fullExecName = separateExecDir.child("jacoco.exec"); 89 | file.copyTo(fullExecName); 90 | } 91 | } 92 | 93 | /** 94 | * Parses the saved "jacoco.exec" files into an {@link ExecutionFileLoader}. 95 | * @param includes see {@link ExecutionFileLoader#setIncludes} 96 | * @param excludes see {@link ExecutionFileLoader#setExcludes} 97 | * @return the configured {@code ExecutionFileLoader} 98 | * @throws IOException if any I/O error occurs 99 | */ 100 | public ExecutionFileLoader parse(String[] includes, String... excludes) throws IOException { 101 | ExecutionFileLoader efl = new ExecutionFileLoader(); 102 | for (File exec : getExecFiles()) { 103 | efl.addExecFile(new FilePath(exec)); 104 | } 105 | 106 | efl.setIncludes(includes); 107 | efl.setExcludes(excludes); 108 | efl.setClassDir(new FilePath(getClassesDir())); 109 | efl.setSrcDir(new FilePath(getSourcesDir())); 110 | efl.loadBundleCoverage(); 111 | 112 | return efl; 113 | } 114 | 115 | @Override 116 | public String toString() { 117 | return root.toString(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/Rule.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import hudson.ExtensionPoint; 4 | import hudson.model.Build; 5 | import hudson.model.TaskListener; 6 | import hudson.plugins.jacoco.model.CoverageObject; 7 | import hudson.plugins.jacoco.report.CoverageReport; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * Rule object encapsulates the logic to mark {@link CoverageObject}s as "failed". 13 | * Such logic is used to mark builds as unstable when certain condition is met. 14 | * 15 | *

16 | * For example, one can define a rule where "line coverage must be better than 50% 17 | * for any class", and if this rule is violated, the build will be marked as 18 | * unstable. 19 | * 20 | *

21 | * The rule instances are persisted as a part of {@link Build}, so make sure 22 | * to make your class serializable. This is so that we can consistently mark 23 | * coverage results even if the job configuration changes. 24 | * 25 | * @author Kohsuke Kawaguchi 26 | */ 27 | public abstract class Rule implements Serializable, ExtensionPoint { 28 | public abstract void enforce(CoverageReport report, TaskListener listener); 29 | 30 | private static final long serialVersionUID = 1L; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/model/Coverage.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.model; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.kohsuke.stapler.export.Exported; 6 | import org.kohsuke.stapler.export.ExportedBean; 7 | 8 | /** 9 | * Represents {@code x/y} where x={@link #missed} and y={@link #covered}. 10 | * 11 | * @author Kohsuke Kawaguchi 12 | * @author Jonathan Fuerth 13 | */ 14 | @ExportedBean 15 | final public class Coverage implements Serializable { 16 | 17 | private int missed = 0; 18 | private int covered = 0; 19 | private CoverageElement.Type type; 20 | boolean initialized = false; 21 | 22 | public Coverage(int missed, int covered) { 23 | this.missed = missed; 24 | this.covered = covered; 25 | this.initialized = true; 26 | } 27 | 28 | public Coverage() { 29 | } 30 | 31 | @Exported 32 | public int getMissed() { 33 | return missed; 34 | } 35 | 36 | @Exported 37 | public int getCovered() { 38 | return covered; 39 | } 40 | 41 | @Exported 42 | public int getTotal() { 43 | return missed + covered; 44 | } 45 | 46 | /** 47 | * Gets "missed/covered (%)" representation. 48 | */ 49 | @Override 50 | public String toString() { 51 | return missed + "/" + covered; 52 | } 53 | 54 | /** 55 | * Gets the percentage as an integer between 0 and 100. 56 | * @return the coverage percentage as a rounded integer between 0 and 100. 57 | * @see #getPercentageFloat() 58 | */ 59 | @Exported 60 | public int getPercentage() { 61 | return Math.round(getPercentageFloat()); 62 | } 63 | 64 | /** 65 | * Gets the percentage as a float between 0f and 100f. 66 | * @return the coverage percentage as a float between 0f and 100f. 67 | * returns 100f if no coverage data was recorded at all, i.e. covered and missed are zero 68 | * @see #getPercentage() 69 | */ 70 | @Exported 71 | public float getPercentageFloat() { 72 | float numerator = covered; 73 | float denominator = missed + covered; 74 | 75 | // there are two cases that we cannot distinguish easily 76 | // a) covered and missing are zero because no code was covered 77 | // b) covered and missing are zero because there is no code to cover in this class, e.g. interfaces 78 | 79 | // we use b) here for now, see JENKINS-56123 for more discussion on this 80 | return denominator <= 0 ? 100 : 100 * (numerator / denominator); 81 | } 82 | 83 | public CoverageElement.Type getType() { 84 | return type; 85 | } 86 | 87 | public void setType(CoverageElement.Type type) { 88 | this.type = type; 89 | } 90 | 91 | @Override 92 | public boolean equals(Object o) { 93 | if (this == o) return true; 94 | if (o == null || getClass() != o.getClass()) return false; 95 | 96 | Coverage ratio = (Coverage) o; 97 | 98 | return ratio.covered == covered 99 | && ratio.missed == missed; 100 | 101 | } 102 | 103 | @Override 104 | public int hashCode() { 105 | int result; 106 | result = missed; 107 | result = 31 * result + covered; 108 | return result; 109 | } 110 | 111 | /** 112 | * Adds the given missed and covered values to the ones already 113 | * contained in this ratio. 114 | * 115 | * @param missed The amount to add to the missed. 116 | * @param covered The amount to add to the covered. 117 | */ 118 | public void accumulate(int missed, int covered) { 119 | this.missed = missed; 120 | this.covered = covered; 121 | initialized = true; 122 | } 123 | public void accumulatePP(int missed, int covered) { 124 | this.missed += missed; 125 | this.covered += covered; 126 | initialized = true; 127 | } 128 | 129 | public boolean isInitialized() { 130 | return initialized; 131 | } 132 | 133 | private static final long serialVersionUID = 1L; 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/model/CoverageElement.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.model; 2 | 3 | import java.io.IOException; 4 | 5 | import hudson.plugins.jacoco.report.AbstractReport; 6 | 7 | /** 8 | * This is a transitive object used during the parsing, but not a part of 9 | * the final tree built. 10 | * 11 | * @author Kohsuke Kawaguchi 12 | */ 13 | public final class CoverageElement { 14 | 15 | /** 16 | * Enumeration of coverage types that appear in a JaCoCo report. 17 | * 18 | * @author Jonathan Fuerth <jfuerth@gmail.com> 19 | */ 20 | public enum Type { 21 | INSTRUCTION { 22 | @Override 23 | public Coverage getAssociatedRatio(AbstractReport from) { 24 | return from.instruction; 25 | } 26 | }, 27 | BRANCH { 28 | @Override 29 | public Coverage getAssociatedRatio(AbstractReport from) { 30 | return from.branch; 31 | } 32 | }, 33 | LINE { 34 | @Override 35 | public Coverage getAssociatedRatio(AbstractReport from) { 36 | return from.line; 37 | } 38 | }, 39 | COMPLEXITY { 40 | @Override 41 | public Coverage getAssociatedRatio(AbstractReport from) { 42 | return from.complexity; 43 | } 44 | }, 45 | METHOD { 46 | @Override 47 | public Coverage getAssociatedRatio(AbstractReport from) { 48 | return from.method; 49 | } 50 | }, 51 | CLASS { 52 | @Override 53 | public Coverage getAssociatedRatio(AbstractReport from) { 54 | return from.clazz; 55 | } 56 | }; 57 | 58 | /** 59 | * Returns the ratio object on the given report that tracks this type of coverage. 60 | * 61 | * @param from The report to return the appropriate Coverage object from. Not null. 62 | * @return the ratio object on the given report that tracks this type of coverage. 63 | */ 64 | public abstract Coverage getAssociatedRatio(AbstractReport from); 65 | } 66 | 67 | private Type type; 68 | private int missed; 69 | private int covered; 70 | 71 | /** 72 | * Returns the enum constant that says what type of coverage this bean 73 | * represents. 74 | *

75 | * Warning: don't call this method getType() because that confuses the 76 | * Digester. 77 | * @return the enum constant that says what type of coverage this bean represents. 78 | */ 79 | public Type getTypeAsEnum() { 80 | return type; 81 | } 82 | 83 | // set by attributes 84 | public void setType(String type) { 85 | this.type = Type.valueOf(type); 86 | } 87 | 88 | // set by attributes 89 | public void setMissed(int missed) { 90 | this.missed = missed; 91 | } 92 | 93 | // set by attributes 94 | public void setCovered(int covered) { 95 | this.covered = covered; 96 | } 97 | 98 | public void addTo(AbstractReport report) throws IOException { 99 | type.getAssociatedRatio(report).accumulate(missed, covered); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/model/ModuleInfo.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.model; 2 | 3 | import hudson.FilePath; 4 | 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.IOException; 8 | 9 | import org.jacoco.core.analysis.Analyzer; 10 | import org.jacoco.core.analysis.CoverageBuilder; 11 | import org.jacoco.core.analysis.IBundleCoverage; 12 | import org.jacoco.core.data.ExecutionDataReader; 13 | import org.jacoco.core.data.ExecutionDataStore; 14 | import org.jacoco.core.data.SessionInfoStore; 15 | 16 | @Deprecated 17 | public class ModuleInfo { 18 | 19 | private String name; 20 | private FilePath srcDir; 21 | private FilePath classDir; 22 | private FilePath execFile; 23 | private FilePath generatedHTMLsDir; 24 | //private String title; 25 | 26 | private ExecutionDataStore executionDataStore; 27 | private SessionInfoStore sessionInfoStore; 28 | 29 | private IBundleCoverage bundleCoverage; 30 | 31 | public IBundleCoverage getBundleCoverage() { 32 | return bundleCoverage; 33 | } 34 | public String getName() { 35 | return name; 36 | } 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | public void setBundleCoverage(IBundleCoverage bundleCoverage) { 41 | this.bundleCoverage = bundleCoverage; 42 | } 43 | public FilePath getGeneratedHTMLsDir() { 44 | return generatedHTMLsDir; 45 | } 46 | public void setGeneratedHTMLsDir(FilePath generatedHTMLsDir) { 47 | this.generatedHTMLsDir = generatedHTMLsDir; 48 | } 49 | public FilePath getSrcDir() { 50 | return srcDir; 51 | } 52 | public void setSrcDir(FilePath srcDir) { 53 | this.srcDir = srcDir; 54 | } 55 | public FilePath getClassDir() { 56 | return classDir; 57 | } 58 | public void setClassDir(FilePath classDir) { 59 | this.classDir = classDir; 60 | } 61 | public FilePath getExecFile() { 62 | return execFile; 63 | } 64 | public void setExecFile(FilePath execFile) { 65 | this.execFile = execFile; 66 | } 67 | private void loadExecutionData() throws IOException { 68 | File executionDataFile = new File(execFile.getRemote()); 69 | final FileInputStream fis = new FileInputStream(executionDataFile); 70 | final ExecutionDataReader executionDataReader = new ExecutionDataReader( 71 | fis); 72 | executionDataStore = new ExecutionDataStore(); 73 | sessionInfoStore = new SessionInfoStore(); 74 | 75 | executionDataReader.setExecutionDataVisitor(executionDataStore); 76 | executionDataReader.setSessionInfoVisitor(sessionInfoStore); 77 | 78 | while (executionDataReader.read()) { 79 | } 80 | 81 | fis.close(); 82 | } 83 | private IBundleCoverage analyzeStructure() throws IOException { 84 | File classDirectory = new File(classDir.getRemote()); 85 | final CoverageBuilder coverageBuilder = new CoverageBuilder(); 86 | final Analyzer analyzer = new Analyzer(executionDataStore, 87 | coverageBuilder); 88 | 89 | analyzer.analyzeAll(classDirectory); 90 | 91 | return coverageBuilder.getBundle(name); 92 | } 93 | public IBundleCoverage loadBundleCoverage() throws IOException { 94 | loadExecutionData(); 95 | this.bundleCoverage = analyzeStructure(); 96 | return this.bundleCoverage; 97 | } 98 | } -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/portlet/bean/JacocoDeltaCoverageResultSummary.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.portlet.bean; 2 | 3 | import hudson.model.Job; 4 | import hudson.model.Run; 5 | import hudson.plugins.jacoco.portlet.JacocoLoadData; 6 | 7 | /** 8 | * This class encapsulates actual delta coverage of current build. 9 | * It calculates absolute difference between coverage of last successful build and current build 10 | */ 11 | public class JacocoDeltaCoverageResultSummary { 12 | 13 | /** 14 | * Variables to capture delta coverage of current build 15 | */ 16 | private float instructionCoverage; 17 | 18 | private float branchCoverage; 19 | 20 | private float complexityCoverage; 21 | 22 | private float lineCoverage; 23 | 24 | private float methodCoverage; 25 | 26 | private float classCoverage; 27 | 28 | public JacocoDeltaCoverageResultSummary() { 29 | } 30 | 31 | // Used to extract coverage result of current and last successful build and encapsulate delta coverage values 32 | public static JacocoDeltaCoverageResultSummary build(Run run){ 33 | Run lastSuccessfulBuild = run.getParent().getLastSuccessfulBuild(); 34 | JacocoCoverageResultSummary lastBuildCoverage = lastSuccessfulBuild!=null ? JacocoLoadData.getResult(lastSuccessfulBuild):new JacocoCoverageResultSummary(); 35 | JacocoCoverageResultSummary currentBuildCoverage = JacocoLoadData.getResult(run); 36 | 37 | JacocoDeltaCoverageResultSummary jacocoDeltaCoverageResultSummary = new JacocoDeltaCoverageResultSummary(); 38 | jacocoDeltaCoverageResultSummary.instructionCoverage = currentBuildCoverage.getInstructionCoverage() - lastBuildCoverage.getInstructionCoverage(); 39 | jacocoDeltaCoverageResultSummary.branchCoverage = currentBuildCoverage.getBranchCoverage() - lastBuildCoverage.getBranchCoverage(); 40 | jacocoDeltaCoverageResultSummary.complexityCoverage = currentBuildCoverage.getComplexityScore() - lastBuildCoverage.getComplexityScore(); 41 | jacocoDeltaCoverageResultSummary.lineCoverage = currentBuildCoverage.getLineCoverage() - lastBuildCoverage.getLineCoverage(); 42 | jacocoDeltaCoverageResultSummary.methodCoverage = currentBuildCoverage.getMethodCoverage() - lastBuildCoverage.getMethodCoverage(); 43 | jacocoDeltaCoverageResultSummary.classCoverage = currentBuildCoverage.getClassCoverage() - lastBuildCoverage.getClassCoverage(); 44 | 45 | return jacocoDeltaCoverageResultSummary; 46 | } 47 | 48 | public float getInstructionCoverage() { 49 | return instructionCoverage; 50 | } 51 | 52 | public float getBranchCoverage() { 53 | return branchCoverage; 54 | } 55 | 56 | public float getComplexityCoverage() { 57 | return complexityCoverage; 58 | } 59 | 60 | public float getLineCoverage() { 61 | return lineCoverage; 62 | } 63 | 64 | public float getMethodCoverage() { 65 | return methodCoverage; 66 | } 67 | 68 | public float getClassCoverage() { 69 | return classCoverage; 70 | } 71 | 72 | public void setInstructionCoverage(float instructionCoverage) { 73 | this.instructionCoverage = instructionCoverage; 74 | } 75 | 76 | public void setBranchCoverage(float branchCoverage) { 77 | this.branchCoverage = branchCoverage; 78 | } 79 | 80 | public void setComplexityCoverage(float complexityCoverage) { 81 | this.complexityCoverage = complexityCoverage; 82 | } 83 | 84 | public void setLineCoverage(float lineCoverage) { 85 | this.lineCoverage = lineCoverage; 86 | } 87 | 88 | public void setMethodCoverage(float methodCoverage) { 89 | this.methodCoverage = methodCoverage; 90 | } 91 | 92 | public void setClassCoverage(float classCoverage) { 93 | this.classCoverage = classCoverage; 94 | } 95 | 96 | @Override 97 | public String toString() { 98 | return "JacocoDeltaCoverageResultSummary [" + 99 | "instructionCoverage=" + instructionCoverage + 100 | ", branchCoverage=" + branchCoverage + 101 | ", complexityCoverage=" + complexityCoverage + 102 | ", lineCoverage=" + lineCoverage + 103 | ", methodCoverage=" + methodCoverage + 104 | ", classCoverage=" + classCoverage + 105 | ']'; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/portlet/grid/JacocoBuilderGrid.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /* 26 | * @author Allyn Pierre (Allyn.GreyDeAlmeidaLimaPierre@sonyericsson.com) 27 | * @author Eduardo Palazzo (Eduardo.Palazzo@sonyericsson.com) 28 | * @author Mauro Durante (Mauro.DuranteJunior@sonyericsson.com) 29 | */ 30 | package hudson.plugins.jacoco.portlet.grid; 31 | 32 | import java.util.Collection; 33 | 34 | import org.kohsuke.stapler.DataBoundConstructor; 35 | 36 | import hudson.Extension; 37 | import hudson.model.Descriptor; 38 | import hudson.model.Job; 39 | import hudson.plugins.jacoco.portlet.JacocoLoadData; 40 | import hudson.plugins.jacoco.portlet.Messages; 41 | import hudson.plugins.jacoco.portlet.bean.JacocoCoverageResultSummary; 42 | import hudson.plugins.view.dashboard.DashboardPortlet; 43 | 44 | /** 45 | * A portlet for JaCoCo Coverage results - Grid data. 46 | * 47 | * See http://wiki.hudson-ci.org/display/HUDSON/Dashboard+View 48 | */ 49 | public class JacocoBuilderGrid extends DashboardPortlet { 50 | 51 | /** 52 | * Constructor with grid name as parameter. DataBoundConstructor 53 | * annotation helps the Stapler class to find which constructor that 54 | * should be used when automatically copying values from a web form 55 | * to a class. 56 | * 57 | * @param name 58 | * grid name 59 | */ 60 | @DataBoundConstructor 61 | public JacocoBuilderGrid(String name) { 62 | super(name); 63 | } 64 | 65 | /** 66 | * This method will be called by portlet.jelly to load data and 67 | * create the grid. 68 | * 69 | * @param jobs 70 | * a Collection of Job objects 71 | * @return JacocoCoverageResultSummary a coverage result summary 72 | */ 73 | public JacocoCoverageResultSummary getJaCoCoCoverageResultSummary(Collection> jobs) { 74 | return JacocoLoadData.getResultSummary(jobs); 75 | } 76 | 77 | /** 78 | * Descriptor that will be shown on Dashboard Portlets view. 79 | */ 80 | @Extension(optional = true) 81 | public static class JacocoGridDescriptor extends Descriptor { 82 | 83 | @Override 84 | public String getDisplayName() { 85 | return Messages.gridTitle(); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/portlet/utils/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /* 26 | * @author Allyn Pierre (Allyn.GreyDeAlmeidaLimaPierre@sonyericsson.com) 27 | * @author Eduardo Palazzo (Eduardo.Palazzo@sonyericsson.com) 28 | * @author Mauro Durante (Mauro.DuranteJunior@sonyericsson.com) 29 | */ 30 | package hudson.plugins.jacoco.portlet.utils; 31 | 32 | /** 33 | * Defines the variables with pre-defined values. 34 | */ 35 | public final class Constants { 36 | /** 37 | * Private constructor: class contains only static methods. 38 | */ 39 | private Constants() { 40 | } 41 | 42 | /** 43 | * Default width of the Graph. 44 | */ 45 | public static final int DEFAULT_WIDTH = 500; 46 | 47 | /** 48 | * Default height of the Graph. 49 | */ 50 | public static final int DEFAULT_HEIGHT = 250; 51 | 52 | /** 53 | * Default number of days of the Graph. 54 | */ 55 | public static final int DEFAULT_DAYS_NUMBER = 30; 56 | 57 | /** 58 | * The default foreground alpha transparency. 59 | */ 60 | public static final float FOREGROUND_ALPHA = 0.8f; 61 | 62 | /** 63 | * The chart axis label. 64 | */ 65 | public static final String AXIS_LABEL = "Days"; 66 | 67 | /** 68 | * The chart axis label value. 69 | */ 70 | public static final String AXIS_LABEL_VALUE = "Coverage(%)"; 71 | 72 | /** 73 | * The chart upper bound value. 74 | */ 75 | public static final int UPPER_BOUND = 100; 76 | 77 | /** 78 | * The chart lower bound value. 79 | */ 80 | public static final int LOWER_BOUND = 0; 81 | 82 | /** 83 | * The chart line thickness value. 84 | */ 85 | public static final float LINE_THICKNESS = 3.5f; 86 | 87 | /** 88 | * The chart default margin value. 89 | */ 90 | public static final double DEFAULT_MARGIN = 0.0; 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/portlet/utils/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /* 26 | * @author Allyn Pierre (Allyn.GreyDeAlmeidaLimaPierre@sonyericsson.com) 27 | * @author Eduardo Palazzo (Eduardo.Palazzo@sonyericsson.com) 28 | * @author Mauro Durante (Mauro.DuranteJunior@sonyericsson.com) 29 | */ 30 | package hudson.plugins.jacoco.portlet.utils; 31 | 32 | import java.math.BigDecimal; 33 | import java.math.RoundingMode; 34 | import java.util.Calendar; 35 | import java.util.List; 36 | 37 | import hudson.model.Job; 38 | import hudson.model.Result; 39 | import hudson.model.Run; 40 | 41 | /** 42 | * Defines common methods that are used for the whole project. 43 | */ 44 | public final class Utils { 45 | 46 | /** 47 | * Private constructor: class contains only static methods. 48 | */ 49 | private Utils() { 50 | } 51 | 52 | /** 53 | * Validate chart attributes returning a valid value to the object. 54 | * 55 | * @param attribute 56 | * the attribute: width, height, number of days 57 | * @param defaultValue 58 | * default value for the attribute 59 | * @return int attribute valid value 60 | */ 61 | public static int validateChartAttributes(String attribute, int defaultValue) { 62 | 63 | // If user fills the attributes with negative, empty or not number 64 | // values, Hudson will not show an invalid message, it will assume 65 | // default values 66 | 67 | if (attribute != null) { 68 | if (attribute.equals("") || attribute.equals("0")) { 69 | return defaultValue; 70 | } 71 | 72 | // Check if attribute value is a number 73 | try { 74 | int validAttributeValue = Integer.parseInt(attribute); 75 | // Attribute value is a number - check if it is negative 76 | if (validAttributeValue < 0) { 77 | return defaultValue; 78 | } 79 | return validAttributeValue; 80 | } catch (NumberFormatException e) { 81 | return defaultValue; 82 | } 83 | } 84 | 85 | return defaultValue; 86 | } 87 | 88 | /** 89 | * For the given list of jobs, this will search all jobs and return 90 | * the last run date of all. 91 | * 92 | * @param jobs 93 | * a list of jobs from the DashBoard Portlet view 94 | * @return LocalDate the last date of all jobs that belongs to 95 | * Dashboard View. 96 | */ 97 | public static Calendar getLastDate(List> jobs) { 98 | Calendar lastDate = null; 99 | for (Job job : jobs) { 100 | Run lastRun = job.getLastCompletedBuild(); 101 | if (lastRun != null) { 102 | Calendar date = lastRun.getTimestamp(); 103 | if (lastDate == null) { 104 | lastDate = date; 105 | } 106 | if (date.after(lastDate)) { 107 | lastDate = date; 108 | } 109 | } 110 | } 111 | return lastDate; 112 | } 113 | 114 | /** 115 | * Method for rounding float values according to the requested mode. 116 | * 117 | * @param scale 118 | * the rounding scale 119 | * @param roundingMode 120 | * the rounding direction @see java.math.RoundingMode 121 | * @param value 122 | * the value to be rounded 123 | * @return the rounded value 124 | */ 125 | public static float roundFloat(int scale, RoundingMode roundingMode, float value) { 126 | BigDecimal bigDecimal = new BigDecimal(value); 127 | bigDecimal = bigDecimal.setScale(scale, roundingMode); 128 | return bigDecimal.floatValue(); 129 | } 130 | 131 | 132 | public static int nthOccurrence(String str, char c, int n) { 133 | int pos = str.indexOf(c, 0); 134 | while (n-- > 0 && pos != -1) 135 | pos = str.indexOf(c, pos+1); 136 | return pos; 137 | } 138 | 139 | /** Logical AND operation of Jenkins build results: 140 | * Success AND Success = Success 141 | * Unstable AND Unstable = Unstable 142 | * Failure AND Failure = Failure 143 | * X AND Failure = Failure, Failure AND X = Failure, X = Success/Unstable/Failure 144 | * Y AND Unstable = Unstable, Unstable AND Y = Unstable, Y = Success/Unstable 145 | * @param op1 first result 146 | * @param op2 second result 147 | * @return Logical AND operation of {@code op1 AND op2} 148 | */ 149 | public static Result applyLogicalAnd(Result op1, Result op2){ 150 | 151 | if(op1.toString().equals("FAILURE") || op2.toString().equals("FAILURE")) 152 | return Result.FAILURE; 153 | 154 | if(op1.toString().equals("UNSTABLE") || op2.toString().equals("UNSTABLE")) 155 | return Result.UNSTABLE; 156 | 157 | if(op1.toString().equals("SUCCESS") && op2.toString().equals("SUCCESS")) 158 | return Result.SUCCESS; 159 | 160 | return Result.FAILURE; 161 | 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/report/AbstractReport.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import hudson.model.ModelObject; 4 | import hudson.model.Run; 5 | import hudson.plugins.jacoco.model.CoverageElement; 6 | import hudson.plugins.jacoco.model.CoverageObject; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * Base class of the coverage report tree, 12 | * which maintains the details of the coverage report. 13 | * 14 | * @author Kohsuke Kawaguchi 15 | * @param Parent type 16 | * @param Self type 17 | */ 18 | public abstract class AbstractReport, 19 | SELF extends CoverageObject> extends CoverageObject implements ModelObject { 20 | 21 | private String name; 22 | 23 | private PARENT parent; 24 | 25 | public void addCoverage(CoverageElement cv) throws IOException { 26 | cv.addTo(this); 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = sanitizeName(name); 35 | } 36 | 37 | protected static String sanitizeName(String name) { 38 | // sanitize names contained in .class files 39 | return name 40 | .replace(':', '_') 41 | .replace(';', '_') 42 | .replace('&', '_') 43 | .replace('%', '_') 44 | .replace('<', '_') 45 | .replace('>', '_'); 46 | } 47 | 48 | public String getDisplayName() { 49 | return getName(); 50 | } 51 | 52 | /** 53 | * Called at the last stage of the tree construction, 54 | * to set the back pointer. 55 | * @param p parent 56 | */ 57 | protected void setParent(PARENT p) { 58 | this.parent = p; 59 | } 60 | 61 | /** 62 | * Gets the back pointer to the parent coverage object. 63 | */ 64 | @Override 65 | public PARENT getParent() { 66 | return parent; 67 | } 68 | 69 | @Override 70 | public SELF getPreviousResult() { 71 | PARENT p = parent; 72 | while(true) { 73 | p = p.getPreviousResult(); 74 | if(p==null) 75 | return null; 76 | SELF prev = (SELF)p.getChildren().get(name); 77 | if(prev!=null) 78 | return prev; 79 | } 80 | } 81 | 82 | @Override 83 | public Run getBuild() { 84 | return parent.getBuild(); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/report/AggregatedReport.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import org.kohsuke.stapler.StaplerRequest; 4 | import org.kohsuke.stapler.StaplerResponse; 5 | 6 | import java.io.IOException; 7 | import java.util.Map; 8 | import java.util.TreeMap; 9 | 10 | /** 11 | * Reports that have children. 12 | * 13 | * @author Kohsuke Kawaguchi 14 | * @param Parent type 15 | * @param Self type 16 | * @param Child type 17 | */ 18 | public abstract class AggregatedReport, 19 | SELF extends AggregatedReport, 20 | CHILD extends AbstractReport> extends AbstractReport { 21 | 22 | private final Map children = new TreeMap<>(); 23 | 24 | public void add(CHILD child) { 25 | children.put(child.getName(),child); 26 | } 27 | 28 | public Map getChildren() { 29 | return children; 30 | } 31 | 32 | @Override 33 | protected void setParent(PARENT p) { 34 | super.setParent(p); 35 | for (CHILD c : children.values()) 36 | c.setParent((SELF)this); 37 | } 38 | 39 | public CHILD getDynamic(String token, StaplerRequest req, StaplerResponse rsp ) throws IOException { 40 | return getChildren().get(token); 41 | } 42 | 43 | @Override 44 | public void setFailed() { 45 | super.setFailed(); 46 | 47 | if (getParent() != null) 48 | getParent().setFailed(); 49 | } 50 | 51 | public boolean hasChildren() { 52 | return getChildren().size() > 0; 53 | } 54 | 55 | public boolean hasChildrenLineCoverage() { 56 | for (CHILD child : getChildren().values()){ 57 | if (child.hasLineCoverage()) { 58 | return true; 59 | } 60 | } 61 | return false; 62 | } 63 | 64 | public boolean hasChildrenClassCoverage() { 65 | for (CHILD child : getChildren().values()){ 66 | if (child.hasClassCoverage()) { 67 | return true; 68 | } 69 | } 70 | return false; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/report/ClassReport.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import java.io.File; 4 | import java.io.Writer; 5 | 6 | import org.jacoco.core.analysis.IClassCoverage; 7 | 8 | /** 9 | * @author Kohsuke Kawaguchi 10 | */ 11 | public final class ClassReport extends AggregatedReport { 12 | 13 | private String sourceFilePath; 14 | private IClassCoverage classCov; 15 | 16 | @Override 17 | public void setName(String name) { 18 | super.setName(name.replace('/', '.')); 19 | //logger.log(Level.INFO, "ClassReport"); 20 | } 21 | 22 | @Override 23 | public void add(MethodReport child) { 24 | String newChildName = child.getName(); 25 | child.setName(newChildName); 26 | getChildren().put(child.getName(), child); 27 | } 28 | 29 | public void setSrcFileInfo(IClassCoverage classCov, String sourceFilePath) { 30 | this.sourceFilePath = sourceFilePath; 31 | this.classCov = classCov; 32 | } 33 | 34 | /** 35 | * Read the source Java file for this class. 36 | * @return the source Java file for this class. 37 | */ 38 | public File getSourceFilePath() { 39 | return new File(sourceFilePath); 40 | } 41 | 42 | public void printHighlightedSrcFile(Writer output) { 43 | new SourceAnnotator(getSourceFilePath()).printHighlightedSrcFile(classCov,output); 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return getClass().getSimpleName() + ":" 49 | + " instruction=" + instruction 50 | + " branch=" + branch 51 | + " complexity=" + complexity 52 | + " line=" + line 53 | + " method=" + method; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/report/MethodReport.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import hudson.plugins.jacoco.model.CoverageElement; 4 | 5 | import java.io.Writer; 6 | 7 | import org.jacoco.core.analysis.IMethodCoverage; 8 | 9 | /** 10 | * @author Kohsuke Kawaguchi 11 | * @author David Carver 12 | * @author Ognjen Bubalo 13 | */ 14 | //AggregatedReport - AbstractReport 15 | public final class MethodReport extends AggregatedReport { 16 | 17 | private IMethodCoverage methodCov; 18 | 19 | @Override 20 | public String printFourCoverageColumns() { 21 | StringBuilder buf = new StringBuilder(); 22 | instruction.setType(CoverageElement.Type.INSTRUCTION); 23 | complexity.setType(CoverageElement.Type.COMPLEXITY); 24 | branch.setType(CoverageElement.Type.BRANCH); 25 | line.setType(CoverageElement.Type.LINE); 26 | method.setType(CoverageElement.Type.METHOD); 27 | printRatioCell(isFailed(), this.instruction, buf); 28 | printRatioCell(isFailed(), this.branch, buf); 29 | printRatioCell(isFailed(), this.complexity, buf); 30 | printRatioCell(isFailed(), this.line, buf); 31 | printRatioCell(isFailed(), this.method, buf); 32 | //logger.log(Level.INFO, "Printing Ratio cells within MethodReport."); 33 | return buf.toString(); 34 | } 35 | 36 | @Override 37 | public void add(SourceFileReport child) { 38 | String newChildName = child.getName().replace(this.getName() + ".", ""); 39 | child.setName(newChildName); 40 | getChildren().put(child.getName(), child); 41 | //logger.log(Level.INFO, "SourceFileReport"); 42 | } 43 | 44 | @Override 45 | public boolean hasClassCoverage() { 46 | return false; 47 | } 48 | 49 | public void setSrcFileInfo(IMethodCoverage methodCov) { 50 | this.methodCov = methodCov; 51 | } 52 | 53 | public void printHighlightedSrcFile(Writer output) { 54 | new SourceAnnotator(getParent().getSourceFilePath()).printHighlightedSrcFile(methodCov,output); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/report/PackageReport.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | 4 | /** 5 | * @author Kohsuke Kawaguchi 6 | * @author David Carver 7 | */ 8 | public final class PackageReport extends AggregatedReport { 9 | 10 | /** 11 | * Give the default no-name package a non-empty name. 12 | */ 13 | @Override 14 | public String getName() { 15 | String n = super.getName(); 16 | return n.length() == 0 ? "(default)" : n; 17 | } 18 | 19 | @Override 20 | public void setName(String name) { 21 | super.setName(name.replace('/', '.')); 22 | } 23 | 24 | @Override 25 | public void add(ClassReport child) { 26 | String newChildName = child.getName().replace(this.getName() + ".", ""); 27 | child.setName(newChildName); 28 | this.getChildren().put(child.getName(), child); 29 | //logger.log(Level.INFO, "PackageReport"); 30 | } 31 | 32 | //private static final Logger logger = Logger.getLogger(CoverageObject.class.getName()); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/report/SourceAnnotator.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.InputStreamReader; 7 | import java.io.IOException; 8 | import java.io.Writer; 9 | import java.nio.charset.StandardCharsets; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | import org.jacoco.core.analysis.ICounter; 14 | import org.jacoco.core.analysis.ILine; 15 | import org.jacoco.core.analysis.ISourceNode; 16 | 17 | /** 18 | * Parses source file and annotates that with the coverage information. 19 | * 20 | * @author Kohsuke Kawaguchi 21 | * @author Marcus Bauer 22 | */ 23 | public class SourceAnnotator { 24 | private final File src; 25 | 26 | public SourceAnnotator(File src) { 27 | this.src = src; 28 | } 29 | 30 | /** 31 | * Parses the source file into individual lines. 32 | */ 33 | private List readLines() throws IOException { 34 | try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(src), StandardCharsets.UTF_8))) { 35 | ArrayList aList = new ArrayList<>(); 36 | String line; 37 | while ((line = br.readLine()) != null) { 38 | aList.add(line.replaceAll("\\t", "        ").replaceAll("<", "<").replaceAll(">", ">")); 39 | } 40 | return aList; 41 | } 42 | } 43 | 44 | public void printHighlightedSrcFile(ISourceNode cov, Writer output) { 45 | try { 46 | StringBuilder buf = new StringBuilder(); 47 | List sourceLines; 48 | try { 49 | sourceLines = readLines(); 50 | } catch (IOException e) { 51 | e.printStackTrace(); 52 | output.write("ERROR: Error while reading the sourcefile!"); 53 | return; 54 | } 55 | output.write(""); 56 | for (int i = 1; i <= sourceLines.size(); ++i) { 57 | buf.setLength(0); 58 | 59 | ILine line = cov.getLine(i); 60 | ICounter branches = line.getBranchCounter(); 61 | int status = line.getStatus(); 62 | if (status != ICounter.EMPTY) { 63 | printHighlightedLine(buf, i, branches, sourceLines.get(i - 1), status); 64 | } else { 65 | buf.append(i).append(": ").append(sourceLines.get(i - 1)).append("
"); 66 | } 67 | output.write(buf.toString()); 68 | } 69 | output.write("
"); 70 | 71 | //logger.log(Level.INFO, "lines: " + buf); 72 | } catch (IOException e) { 73 | throw new RuntimeException(e); 74 | } 75 | } 76 | 77 | /** 78 | * Formats a source code line 79 | * 80 | * @param buf 81 | * source to write to. 82 | * @param lineNumber 83 | * line number to output 84 | * @param cov 85 | * branch coverage data for this line 86 | * @param sourceLine 87 | * source code line 88 | * @param status 89 | * coverage status of this line 90 | */ 91 | private void printHighlightedLine(StringBuilder buf, int lineNumber, ICounter cov, String sourceLine, int status) { 92 | buf.append(lineNumber).append(":"); 93 | 94 | String tooltip = getTooltip(cov); 95 | if (tooltip != null) { 96 | buf.append("•").append(sourceLine).append("").append("
"); 102 | } 103 | 104 | /** 105 | * Returns a tooltip for the branch coverage data. 106 | * 107 | * @param cov 108 | * branch coverage data 109 | * @return Tooltip if branch coverage data exists for the given line, 110 | * otherwise null 111 | */ 112 | private String getTooltip(ICounter cov) { 113 | switch (cov.getStatus()) { 114 | case ICounter.FULLY_COVERED: 115 | return "All " + cov.getTotalCount() + " branches covered."; 116 | 117 | case ICounter.PARTLY_COVERED: 118 | return cov.getMissedCount() + " of " + cov.getTotalCount() + " branches missed."; 119 | 120 | case ICounter.NOT_COVERED: 121 | return "All " + cov.getTotalCount() + " branches missed."; 122 | 123 | default: 124 | return null; 125 | } 126 | } 127 | 128 | /** 129 | * Returns a HTML color for each line status 130 | * 131 | * @param status 132 | * Status of the line 133 | * @return HTML color code for the background of the line, "none" if none 134 | * @see ICounter#getStatus() 135 | */ 136 | private String getStatusColor(int status) { 137 | switch (status) { 138 | case ICounter.FULLY_COVERED: 139 | return "#ccffcc"; 140 | 141 | case ICounter.PARTLY_COVERED: 142 | return "#ffff80"; 143 | 144 | case ICounter.NOT_COVERED: 145 | return "#ffaaaa"; 146 | 147 | default: 148 | return "none"; 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/report/SourceFileReport.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | 4 | /** 5 | * @author Kohsuke Kawaguchi 6 | */ 7 | public final class SourceFileReport extends AbstractReport { 8 | 9 | @Override 10 | public void setName(String name) { 11 | super.setName(name.replace('/', '.')); 12 | //logger.log(Level.INFO, "SourceFileReport"); 13 | } 14 | 15 | //private static final Logger logger = Logger.getLogger(SourceFileReport.class.getName()); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacoco/rules/LineCoveragePerSourceFileRule.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.rules; 2 | 3 | import hudson.model.TaskListener; 4 | import hudson.plugins.jacoco.Rule; 5 | import hudson.plugins.jacoco.report.CoverageReport; 6 | 7 | /** 8 | * Flags a failure if the line coverage of a source file 9 | * goes below a certain threshold. 10 | */ 11 | public class LineCoveragePerSourceFileRule extends Rule { 12 | 13 | private static final long serialVersionUID = -2869893039051762047L; 14 | 15 | //private final float minPercentage; 16 | 17 | public LineCoveragePerSourceFileRule(float minPercentage) { 18 | //this.minPercentage = minPercentage; 19 | } 20 | 21 | @Override 22 | public void enforce(CoverageReport report, TaskListener listener) { 23 | // for (PackageReport pack : report.getChildren().values()) { 24 | // for (SourceFileReport sfReport : pack.getChildren().values()) { 25 | // float percentage = sfReport.getLineCoverage().getPercentageFloat(); 26 | // 27 | // if (percentage < minPercentage) { 28 | // listener.getLogger().println("Emma: " + sfReport.getDisplayName() + " failed (below " + minPercentage + "%)."); 29 | // sfReport.setFailed(); 30 | // } 31 | // } 32 | // } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacococoveragecolumn/AbstractJaCoCoCoverageColumn.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacococoveragecolumn; 2 | 3 | import hudson.model.Job; 4 | import hudson.model.Run; 5 | import hudson.plugins.jacoco.JacocoBuildAction; 6 | import hudson.plugins.jacoco.model.Coverage; 7 | import hudson.views.ListViewColumn; 8 | 9 | import java.awt.*; 10 | import java.math.BigDecimal; 11 | import java.math.RoundingMode; 12 | import java.util.function.Function; 13 | 14 | /** 15 | * Abstract view column to show the code coverage percentage 16 | * 17 | */ 18 | public abstract class AbstractJaCoCoCoverageColumn extends ListViewColumn { 19 | 20 | protected abstract Float getPercentageFloat(final Run build); 21 | 22 | protected Float getPercentageFloat(final Run lastSuccessfulBuild, 23 | Function percentageFunction) { 24 | if(lastSuccessfulBuild == null) { 25 | return 0f; 26 | } 27 | 28 | final JacocoBuildAction action = lastSuccessfulBuild 29 | .getAction(JacocoBuildAction.class); 30 | 31 | if(action == null) { 32 | return 0f; 33 | } 34 | 35 | return percentageFunction.apply(action); 36 | } 37 | 38 | 39 | public boolean hasCoverage(final Job job) { 40 | final Run lastSuccessfulBuild = job.getLastSuccessfulBuild(); 41 | return lastSuccessfulBuild != null && 42 | lastSuccessfulBuild.getAction(JacocoBuildAction.class) != null; 43 | } 44 | 45 | public String getPercent(final Job job) { 46 | final StringBuilder stringBuilder = new StringBuilder(); 47 | 48 | if (!hasCoverage(job)) { 49 | stringBuilder.append("N/A"); 50 | } else { 51 | final Run lastSuccessfulBuild = job.getLastSuccessfulBuild(); 52 | final Double percent = getPercent(lastSuccessfulBuild); 53 | stringBuilder.append(percent); 54 | } 55 | 56 | return stringBuilder.toString(); 57 | } 58 | 59 | public String getColor(final Job job, final BigDecimal amount) { 60 | if (amount == null) { 61 | return null; 62 | } 63 | 64 | if(job != null && !hasCoverage(job)) { 65 | return CoverageRange.NA.getLineHexString(); 66 | } 67 | 68 | return CoverageRange.valueOf(amount.doubleValue()).getLineHexString(); 69 | } 70 | 71 | public String getFillColor(final Job job, final BigDecimal amount) { 72 | if (amount == null) { 73 | return null; 74 | } 75 | 76 | if(job != null && !hasCoverage(job)) { 77 | return CoverageRange.NA.getFillHexString(); 78 | } 79 | 80 | final Color c = CoverageRange.fillColorOf(amount.doubleValue()); 81 | return CoverageRange.colorAsHexString(c); 82 | } 83 | 84 | public BigDecimal getCoverage(final Job job) { 85 | final Run lastSuccessfulBuild = job.getLastSuccessfulBuild(); 86 | return BigDecimal.valueOf(getPercent(lastSuccessfulBuild)); 87 | } 88 | 89 | private Double getPercent(final Run lastSuccessfulBuild) { 90 | final Float percentageFloat = getPercentageFloat(lastSuccessfulBuild); 91 | final double doubleValue = percentageFloat.doubleValue(); 92 | 93 | final int decimalPlaces = 2; 94 | BigDecimal bigDecimal = new BigDecimal(doubleValue); 95 | 96 | // setScale is immutable 97 | bigDecimal = bigDecimal.setScale(decimalPlaces, 98 | RoundingMode.HALF_UP); 99 | return bigDecimal.doubleValue(); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacococoveragecolumn/BranchCoverageColumn.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacococoveragecolumn; 2 | 3 | import hudson.Extension; 4 | import hudson.model.Descriptor; 5 | import hudson.model.Run; 6 | import hudson.views.ListViewColumn; 7 | import hudson.views.ListViewColumnDescriptor; 8 | import net.sf.json.JSONObject; 9 | import org.kohsuke.stapler.DataBoundConstructor; 10 | import org.kohsuke.stapler.StaplerRequest; 11 | 12 | import edu.umd.cs.findbugs.annotations.NonNull; 13 | 14 | /** 15 | * View column that shows the code branch coverage percentage 16 | * 17 | */ 18 | public class BranchCoverageColumn extends AbstractJaCoCoCoverageColumn { 19 | 20 | @DataBoundConstructor 21 | public BranchCoverageColumn() { 22 | } 23 | 24 | @Override 25 | protected Float getPercentageFloat(final Run lastSuccessfulBuild) { 26 | return getPercentageFloat(lastSuccessfulBuild, 27 | (a) -> a.getBranchCoverage().getPercentageFloat()); 28 | } 29 | 30 | @Extension 31 | public static final Descriptor DESCRIPTOR = new DescriptorImpl(); 32 | 33 | @Override 34 | public Descriptor getDescriptor() { 35 | return DESCRIPTOR; 36 | } 37 | 38 | private static class DescriptorImpl extends ListViewColumnDescriptor { 39 | @Override 40 | public ListViewColumn newInstance(final StaplerRequest req, 41 | @NonNull final JSONObject formData) { 42 | return new BranchCoverageColumn(); 43 | } 44 | 45 | @Override 46 | public boolean shownByDefault() { 47 | return false; 48 | } 49 | 50 | @NonNull 51 | @Override 52 | public String getDisplayName() { 53 | return "JaCoCo Branch Coverage"; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacococoveragecolumn/CoverageRange.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacococoveragecolumn; 2 | 3 | import java.awt.Color; 4 | 5 | public enum CoverageRange { 6 | /* 7 | * This ordering is important for the lookup; the lowest value should be 8 | * last 9 | */ 10 | PERFECT(100.0, new Color(0x00, 0x8B, 0x00), new Color(0xEE, 0xEE, 0xEE)), // 11 | EXCELLENT(97.0, new Color(0x00, 0xCD, 0x00), new Color(0x00, 0x00, 0x00)), // 12 | GOOD(92.0, new Color(0x7A, 0xFF, 0x3F), new Color(0x00, 0x00, 0x00)), // 13 | SUFFICIENT(85.0, new Color(0xC8, 0xFF, 0x3F), new Color(0x00, 0x00, 0x00)), // 14 | FAIR(75.0, new Color(0xFF, 0xFF, 0x00), new Color(0x00, 0x00, 0x00)), // 15 | POOR(50.0, new Color(0xFF, 0x7F, 0x00), new Color(0x00, 0x00, 0x00)), // 16 | TRAGIC(25.0, new Color(0xFF, 0x00, 0x00), new Color(0xEE, 0xEE, 0xEE)), // 17 | ABYSSMAL(0.0, new Color(0x00, 0x00, 0x00), new Color(0xEE, 0xEE, 0xEE)), 18 | NA(0.0, new Color(0xFF, 0xFF, 0xFF), new Color(0x00, 0x00, 0x00)); 19 | 20 | /** 21 | * Minimum coverage amount for this range 22 | */ 23 | private final double floor; 24 | 25 | private final Color fillColor; 26 | private final Color lineColor; 27 | 28 | CoverageRange(final double floor, final Color fillColor, 29 | final Color lineColor) { 30 | this.floor = floor; 31 | this.fillColor = fillColor; 32 | this.lineColor = lineColor; 33 | } 34 | 35 | public static CoverageRange valueOf(final Double amount) { 36 | for (final CoverageRange range : values()) { 37 | if (amount >= range.floor) { 38 | return range; 39 | } 40 | } 41 | return ABYSSMAL; 42 | } 43 | 44 | public static Color fillColorOf(final double amount) { 45 | for (int i = 0; i < values().length; i++) { 46 | final CoverageRange range = values()[i]; 47 | if (amount == range.floor) { 48 | return range.fillColor; 49 | } else if (amount > range.floor) { 50 | if (i == 0) { 51 | // This method used to throw ArrayIndexOutOfBoundsException 52 | // in this case, catch it and return this value: 53 | return ABYSSMAL.fillColor; 54 | } 55 | final CoverageRange range1 = values()[i - 1]; 56 | final double t0 = amount - range.floor; 57 | final double t1 = range1.floor - amount; 58 | return blendedColor(range.fillColor, range1.fillColor, t0, 59 | t1); 60 | } 61 | } 62 | return ABYSSMAL.fillColor; 63 | } 64 | 65 | private static Color blendedColor(final Color fillColor0, 66 | final Color fillColor1, final double t0, final double t1) { 67 | final double total = t0 + t1; 68 | if (total == 0) { 69 | return ABYSSMAL.fillColor; 70 | } 71 | final int r = (int) ((fillColor0.getRed() * t1 + fillColor1.getRed() 72 | * t0) / total); 73 | final int g = (int) ((fillColor0.getGreen() * t1 + fillColor1 74 | .getGreen() * t0) / total); 75 | final int b = (int) ((fillColor0.getBlue() * t1 + fillColor1.getBlue() 76 | * t0) / total); 77 | return new Color(r, g, b); 78 | } 79 | 80 | public Color getFillColor() { 81 | return fillColor; 82 | } 83 | 84 | public Color getLineColor() { 85 | return lineColor; 86 | } 87 | 88 | public String getFillHexString() { 89 | return colorAsHexString(fillColor); 90 | } 91 | 92 | public String getLineHexString() { 93 | return colorAsHexString(lineColor); 94 | } 95 | 96 | public static String colorAsHexString(final Color c) { 97 | return String.format("%02X%02X%02X", c.getRed(), c.getGreen(), 98 | c.getBlue()); 99 | } 100 | 101 | public double getFloor() { 102 | return floor; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/jacococoveragecolumn/JaCoCoColumn.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacococoveragecolumn; 2 | 3 | import hudson.Extension; 4 | import hudson.model.Descriptor; 5 | import hudson.model.Run; 6 | import hudson.views.ListViewColumnDescriptor; 7 | import hudson.views.ListViewColumn; 8 | 9 | import net.sf.json.JSONObject; 10 | 11 | import org.kohsuke.stapler.DataBoundConstructor; 12 | import org.kohsuke.stapler.StaplerRequest; 13 | 14 | import edu.umd.cs.findbugs.annotations.NonNull; 15 | 16 | /** 17 | * View column that shows the code line coverage percentage 18 | * 19 | */ 20 | public class JaCoCoColumn extends AbstractJaCoCoCoverageColumn { 21 | 22 | @DataBoundConstructor 23 | public JaCoCoColumn() { 24 | } 25 | 26 | @Override 27 | protected Float getPercentageFloat(final Run lastSuccessfulBuild) { 28 | return getPercentageFloat(lastSuccessfulBuild, 29 | (a) -> a.getLineCoverage().getPercentageFloat()); 30 | } 31 | 32 | @Extension 33 | public static final Descriptor DESCRIPTOR = new DescriptorImpl(); 34 | 35 | @Override 36 | public Descriptor getDescriptor() { 37 | return DESCRIPTOR; 38 | } 39 | 40 | private static class DescriptorImpl extends ListViewColumnDescriptor { 41 | @Override 42 | public ListViewColumn newInstance(final StaplerRequest req, 43 | @NonNull final JSONObject formData) { 44 | return new JaCoCoColumn(); 45 | } 46 | 47 | @Override 48 | public boolean shownByDefault() { 49 | return false; 50 | } 51 | 52 | @NonNull 53 | @Override 54 | public String getDisplayName() { 55 | return "JaCoCo Line Coverage"; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoBuildAction/summary.jelly: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Jacoco - ${%Overall Coverage Summary} 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
${coverageRatio.key.type}${coverageRatio.key.percentage}%
17 |
18 |
19 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoProjectAction/floatingBox.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | ${%Code Coverage Trend} 5 |
6 |
7 | 8 |
9 |
10 | ${%enlarge} 11 |
12 | 13 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoProjectAction/floatingBox_de.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/resources/hudson/plugins/jacoco/JacocoProjectAction/floatingBox_de.properties -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoProjectAction/floatingBox_es.properties: -------------------------------------------------------------------------------- 1 | Code\ Coverage\ Trend=Tendencia de la cobertura de c\ufffddigo 2 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoProjectAction/floatingBox_ja.properties: -------------------------------------------------------------------------------- 1 | Code\ Coverage\ Trend=\u30b3\u30fc\u30c9\u30ab\u30d0\u30ec\u30c3\u30b8\u306e\u63a8\u79fb 2 | enlarge=\u62e1\u5927 -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoProjectAction/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

${%JaCoCo Coverage Trend}

7 | 8 |
9 | 10 |
11 |
12 |
13 |
14 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoProjectAction/index_de.properties: -------------------------------------------------------------------------------- 1 | JaCoCo\ Coverage\ Trend=Trend der JaCoCo-Code-Abdeckung 2 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoProjectAction/index_es.properties: -------------------------------------------------------------------------------- 1 | JaCoCo\ Coverage\ Trend=Tendencia de cobertura JaCoCo 2 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoProjectAction/index_ja.properties: -------------------------------------------------------------------------------- 1 | JaCoCo\ Coverage\ Trend=JaCoCo\u30ab\u30d0\u30ec\u30c3\u30b8\u306e\u63a8\u79fb 2 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/config.properties: -------------------------------------------------------------------------------- 1 | 2 | entry.title=Folders or files containing JaCoCo XML reports 3 | includes.description=\ 4 | Specify the path to the JaCoCo''s XML report files, relative to \ 5 | the workspace root
\ 6 | - If you left this field blank the plugin will look for files matching the pattern: **/jacoco/jacoco*.xml in the workspace.
\ 7 | - Or you can enclose the search specifying a list of files and folders separated by semicolon.
\ 8 | - Or use an Ant 'Fileset' pattern. 9 | 10 | minLineCoveragePerSource.description=\ 11 | % min line coverage - 0 (or empty) is as if you disable MinLineCoverage-Enforcer. 12 | MinLine\ Coverage=Minimal line coverage 13 | 14 | Instructions=% Instructions 15 | Branch=% Branch 16 | Complexity=% Complexity 17 | Line=% Line 18 | Method=% Method 19 | Class=% Class 20 | 21 | 22 | 23 | 24 | health.100.title=Report health as 100% when coverage is greater than 25 | health.0.title=Report health as 0% when coverage is less than 26 | 27 | #thresholds.description=\ 28 | # Configure health reporting thresholds.
\ 29 | # For the \ 30 | # row, leave blank to use the default values (i.e. 80, 80, 80, 80, 70 and 100 for instruction, method, line, \ 31 | # complexity, instructions, and branch respectively).
\ 32 | # For the row, leave blank to \ 33 | # use the default values (i.e. 0, 0, 0, 0, 0, 0, 0). 34 | 35 | 36 | Health\ reporting=Health reporting 37 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/config_es.properties: -------------------------------------------------------------------------------- 1 | 2 | entry.title=Directorios o archivos donde JaCoCo deja la informaci\u00f3n. 3 | includes.description=\ 4 | Especifica la ruta donde est\u00e1n los ficheros XML de JaCoCo. Esta ruta es relativa al directorio de trabajo.
\ 5 | - Si dejas este campo vac\u00edo, el plugin buscar\u00e1 todos los ficheros en todo el espacio de trabajo que cumplan el patr\u00f3n:
\ 6 |    **/jacoco/jacoco*.xml
\ 7 | - O bien puedes especificar una lista de ficheros y/o directorios donde buscar separados por punto y coma.
\ 8 | - O usar un patr\u00f3n 'Fileset' de Ant 9 | 10 | minLineCoveragePerSource.description=\ 11 | Umbral (%) de cobertura m\u00ednima de l\u00edneas de c\u00f3digo necesario para no marcar el proyecto como fallido.
\ 12 | Un valor 0 o dejar el campo vac\u00edo significa desactivar esta restricci\u00f3n. 13 | MinLine\ Coverage=Cobertura m\u00ednima de l\u00edneas 14 | 15 | Class=% Clases 16 | Method=% M\u00e9todos 17 | Block=% Bloques 18 | Line=% L\u00edneas 19 | 20 | health.100.title=Muestra un estado de salud como si fuera de 100% cuando la cobertura es mayor a este valor. 21 | health.0.title=Muestra un estado de salud como si fuera de 0% cuando la cobertura es inferior a este valor. 22 | 23 | thresholds.description=\ 24 | Configuraci\u00f3n de los umbrales de salud del c\u00f3digo.
\ 25 | Para el estado: \ 26 | deja las casillas en blanco si quieres usar los valores por defecto \ 27 | (100, 70, 80, y 80 para clases, m\u00e9todos, bloques y l\u00edneas respectivamente).
\ 28 | Para el estado \ 29 | deja las casillas en blanco para usar los valores por defecto (0, 0, 0, 0). 30 | 31 | 32 | Health\ reporting=Estado de salud del proyecto 33 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/config_ja.properties: -------------------------------------------------------------------------------- 1 | 2 | entry.title=\u30ec\u30dd\u30fc\u30c8\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea/\u30d5\u30a1\u30a4\u30eb 3 | includes.description=\ 4 | JaCoCo\u306eXML\u5f62\u5f0f\u306e\u30ec\u30dd\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u30d1\u30b9\u3092\u3001\u30ef\u30fc\u30af\u30b9\u30da\u30fc\u30b9\u304b\u3089\u306e\u76f8\u5bfe\u30d1\u30b9\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002
\ 5 | - \u672a\u5165\u529b\u306e\u5834\u5408\u3001\u30ef\u30fc\u30af\u30b9\u30da\u30fc\u30b9\u306e **/jacoco/jacoco*.xml \u306b\u4e00\u81f4\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u3092\u691c\u7d22\u3057\u307e\u3059\u3002
\ 6 | - \u691c\u7d22\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u30ea\u30b9\u30c8\u3092\u30bb\u30df\u30b3\u30ed\u30f3\u533a\u5207\u308a\u3067\u6307\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
\ 7 | - Ant\u306e'Fileset'\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002 8 | 9 | minLineCoveragePerSource.description=\ 10 | % min line coverage - 0 (or empty) is as if you disable MinLineCoverage-Enforcer. 11 | MinLine\ Coverage=Minimal line coverage 12 | 13 | Class=% \u30af\u30e9\u30b9 14 | Method=% \u30e1\u30bd\u30c3\u30c9 15 | Block=% \u30d6\u30ed\u30c3\u30af 16 | Line=% \u884c 17 | 18 | health.100.title=\u30ab\u30d0\u30ec\u30c3\u30b8\u304c\u3053\u306e\u5024\u3088\u308a\u5927\u304d\u3044\u5834\u5408\u3001\u72b6\u614b\u3092100%\u3068\u5831\u544a\u3057\u307e\u3059\u3002 19 | health.0.title=\u30ab\u30d0\u30ec\u30c3\u30b8\u304c\u3053\u306e\u5024\u3088\u308a\u5c0f\u3055\u3044\u5834\u5408\u3001\u72b6\u614b\u30920%\u3068\u5831\u544a\u3057\u307e\u3059\u3002 20 | 21 | thresholds.description=\ 22 | \u72b6\u614b\u306e\u95be\u5024\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002
\ 23 | \u306e\u884c\u304c\u672a\u5165\u529b\u306e\u5834\u5408\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u4f7f\u7528\u3057\u307e\u3059 \ 24 | (\u30af\u30e9\u30b9\u3001\u30e1\u30bd\u30c3\u30c9\u3001\u30d6\u30ed\u30c3\u30af\u304a\u3088\u3073\u884c\u306e\u5024\u3068\u3057\u3066\u3001100, 70, 80, 80)\u3002
\ 25 | \u306e\u884c\u304c\u672a\u5165\u529b\u306e\u5834\u5408\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u4f7f\u7528\u3057\u307e\u3059(0, 0, 0 ,0)\u3002 26 | 27 | 28 | Health\ reporting=\u72b6\u614b\u30ec\u30dd\u30fc\u30c8 29 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/global.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-buildOverBuild.html: -------------------------------------------------------------------------------- 1 |
2 | Check this to set the build status to failure if the delta coverage thresholds are violated. Delta coverage is the difference between coverage of last successful and current build. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-changeBuildStatus.html: -------------------------------------------------------------------------------- 1 |
2 | Check this to set the build status to unstable if coverage thresholds are violated. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-classPattern.html: -------------------------------------------------------------------------------- 1 |
2 | Path to the Java class directories that should be included in coverage reporting. 3 | Ant path wildcards are understood. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-deltaBranchCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status if coverage degrades. 3 | The build status degrades to unstable (or failed) if branch coverage decreases by more than this delta threshold compared to the previous build. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-deltaClassCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status if coverage degrades. 3 | The build status degrades to unstable (or failed) if class coverage decreases by more than this delta threshold compared to the previous build. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-deltaComplexityCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status if coverage degrades. 3 | The build status degrades to unstable (or failed) if complexity coverage decreases by more than this delta threshold compared to the previous build. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-deltaInstructionCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status if coverage degrades. 3 | The build status degrades to unstable (or failed) if instruction coverage decreases by more than this delta threshold compared to the previous build. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-deltaLineCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status if coverage degrades. 3 | The build status degrades to unstable (or failed) if line coverage decreases by more than this delta threshold compared to the previous build. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-deltaMethodCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status if coverage degrades. 3 | The build status degrades to unstable (or failed) if method coverage decreases by more than this delta threshold compared to the previous build. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-exclusionPattern.html: -------------------------------------------------------------------------------- 1 |
2 | Path to the Java class files that should be excluded from coverage reporting. 3 | Ant path wildcards are understood. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-execPattern.html: -------------------------------------------------------------------------------- 1 |
2 | Path to the exec files generated by JaCoCo. 3 | Ant path wildcards are understood. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-inclusionPattern.html: -------------------------------------------------------------------------------- 1 |
2 | Path to the Java class files that should be included in coverage reporting. 3 | Ant path wildcards are understood. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-maximumBranchCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the branch coverage is below minimumBranchCoverage
  • 5 |
  • The build is unstable if the branch coverage is above minimumBranchCoverage and below maximumBranchCoverage
  • 6 |
  • The build succeeds if the branch coverage is above maximumBranchCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-maximumClassCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the class coverage is below minimumClassCoverage
  • 5 |
  • The build is unstable if the class coverage is above minimumClassCoverage and below maximumClassCoverage
  • 6 |
  • The build succeeds if the class coverage is above maximumClassCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-maximumComplexityCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the complexity coverage is below minimumComplexityCoverage
  • 5 |
  • The build is unstable if the complexity coverage is above minimumComplexityCoverage and below maximumComplexityCoverage
  • 6 |
  • The build succeeds if the complexity coverage is above maximumComplexityCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-maximumInstructionCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the instruction coverage is below minimumInstructionCoverage
  • 5 |
  • The build is unstable if the instruction coverage is above minimumInstructionCoverage and below maximumInstructionCoverage
  • 6 |
  • The build succeeds if the instruction coverage is above maximumInstructionCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-maximumLineCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the line coverage is below minimumLineCoverage
  • 5 |
  • The build is unstable if the line coverage is above minimumLineCoverage and below maximumLineCoverage
  • 6 |
  • The build succeeds if the line coverage is above maximumLineCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-maximumMethodCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the method coverage is below minimumMethodCoverage
  • 5 |
  • The build is unstable if the method coverage is above minimumMethodCoverage and below maximumMethodCoverage
  • 6 |
  • The build succeeds if the method coverage is above maximumMethodCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-minimumBranchCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the branch coverage is below minimumBranchCoverage
  • 5 |
  • The build is unstable if the branch coverage is above minimumBranchCoverage and below maximumBranchCoverage
  • 6 |
  • The build succeeds if the branch coverage is above maximumBranchCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-minimumClassCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the class coverage is below minimumClassCoverage
  • 5 |
  • The build is unstable if the class coverage is above minimumClassCoverage and below maximumClassCoverage
  • 6 |
  • The build succeeds if the class coverage is above maximumClassCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-minimumComplexityCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the complexity coverage is below minimumComplexityCoverage
  • 5 |
  • The build is unstable if the complexity coverage is above minimumComplexityCoverage and below maximumComplexityCoverage
  • 6 |
  • The build succeeds if the complexity coverage is above maximumComplexityCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-minimumInstructionCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the instruction coverage is below minimumInstructionCoverage
  • 5 |
  • The build is unstable if the instruction coverage is above minimumInstructionCoverage and below maximumInstructionCoverage
  • 6 |
  • The build succeeds if the instruction coverage is above maximumInstructionCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-minimumLineCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the line coverage is below minimumLineCoverage
  • 5 |
  • The build is unstable if the line coverage is above minimumLineCoverage and below maximumLineCoverage
  • 6 |
  • The build succeeds if the line coverage is above maximumLineCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-minimumMethodCoverage.html: -------------------------------------------------------------------------------- 1 |
2 | Change build status based on coverage results. 3 |
    4 |
  • The build fails if the method coverage is below minimumMethodCoverage
  • 5 |
  • The build is unstable if the method coverage is above minimumMethodCoverage and below maximumMethodCoverage
  • 6 |
  • The build succeeds if the method coverage is above maximumMethodCoverage
  • 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-runAlways.html: -------------------------------------------------------------------------------- 1 |
2 | Run coverage collection even if the build fails or is aborted. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-skipCopyOfSrcFiles.html: -------------------------------------------------------------------------------- 1 |
2 | Check this to disable display of source files for each line coverage 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-sourceExclusionPattern.html: -------------------------------------------------------------------------------- 1 |
2 | Path to the Java source files that should be excluded from coverage reporting. 3 | Ant path wildcards are understood. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-sourceInclusionPattern.html: -------------------------------------------------------------------------------- 1 |
2 | Path to the Java source files that should be included in coverage reporting. 3 | Ant path wildcards are understood. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help-sourcePattern.html: -------------------------------------------------------------------------------- 1 |
2 | Path to the Java source directories that should be included in coverage reporting. 3 | Ant path wildcards are understood. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/JacocoPublisher/help.html: -------------------------------------------------------------------------------- 1 |
2 | Allows to configure various aspects of the JaCoCo code coverage report. The paths define where the various types of files 3 | can be found in the workspace, inclusions and exclusions allow to exclude certain class files. 4 | 5 | And the coverage thresholds allow to configure how much coverage is necessary to make the build green (if changing the build 6 | status is enabled). 7 |
8 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/Messages.properties: -------------------------------------------------------------------------------- 1 | BuildAction.Description=Coverage: {0} {1} {2} {3} {4} 2 | BuildAction.Classes=Classes {0} ({1}%). 3 | BuildAction.Methods=Methods {0} ({1}%). 4 | BuildAction.Blocks=Blocks {0} ({1}%). 5 | BuildAction.Lines=Lines {0} ({1}%). 6 | BuildAction.Branches=Branches {0} ({1}%). 7 | BuildAction.Instructions=Instructions {0} ({1}%). 8 | BuildAction.Perfect=All coverage targets have been met. 9 | BuildAction.DisplayName=Coverage Report 10 | ProjectAction.DisplayName=Coverage Trend 11 | JacocoPublisher.DisplayName=Record JaCoCo coverage report 12 | CoverageObject.Legend.Covered={0} covered 13 | CoverageObject.Legend.Missed={0} missed 14 | CoverageObject.Legend.Class=class 15 | CoverageObject.Legend.Line=line 16 | CoverageObject.Legend.Method=method 17 | CoverageObject.Legend.Branch=branch 18 | CoverageObject.Legend.Instructions=instructions 19 | CoverageObject.Legend.Complexity=complexity 20 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/Messages_de.properties: -------------------------------------------------------------------------------- 1 | BuildAction.Description=Testabdeckung: {0} {1} {2} {3} {4} 2 | BuildAction.Classes=Klassen {0} ({1}%). 3 | BuildAction.Methods=Methoden {0} ({1}%). 4 | BuildAction.Blocks=Bl\u00f6cke {0} ({1}%). 5 | BuildAction.Lines=Zeilen {0} ({1}%). 6 | BuildAction.Branches=Branches {0} ({1}%). 7 | BuildAction.Instructions=Anweisungen {0} ({1}%). 8 | BuildAction.Perfect=Alle Testabdeckungsziele wurden erreicht. 9 | BuildAction.DisplayName=Testabdeckung 10 | ProjectAction.DisplayName=Trend der Testabdeckung 11 | JacocoPublisher.DisplayName=Ver\u00f6ffentliche die JaCoCo Testabdeckung 12 | CoverageObject.Legend.Class=Klassen 13 | CoverageObject.Legend.Line=Zeilen 14 | CoverageObject.Legend.Covered={0} abgedeckt 15 | CoverageObject.Legend.Missed={0} nicht abgedeckt 16 | CoverageObject.Legend.Method=Methoden 17 | CoverageObject.Legend.Branch=Branch 18 | CoverageObject.Legend.Instructions=Anweisungen 19 | CoverageObject.Legend.Complexity=Komplexit\u00e4t 20 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/Messages_es.properties: -------------------------------------------------------------------------------- 1 | BuildAction.Description=Cobertura: {0} {1} {2} {3} {4} 2 | BuildAction.Classes=Clases {0} ({1}%). 3 | BuildAction.Methods=M\u00e9todos {0} ({1}%). 4 | BuildAction.Blocks=Bloques {0} ({1}%). 5 | BuildAction.Lines=L\u00edneas {0} ({1}%). 6 | BuildAction.Perfect=Inspecci\u00f3n de cobertura finalizada. 7 | BuildAction.DisplayName=Informes de cobertura 8 | ProjectAction.DisplayName=Tendencia de cobertura 9 | JacocoPublisher.DisplayName=Recoger informes de cobertura JaCoCo 10 | 11 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/Messages_ja.properties: -------------------------------------------------------------------------------- 1 | BuildAction.Description=\u30ab\u30d0\u30ec\u30c3\u30b8: {0} {1} {2} {3} {4} 2 | BuildAction.Classes=\u30af\u30e9\u30b9 {0} ({1}%). 3 | BuildAction.Methods=\u30e1\u30bd\u30c3\u30c9 {0} ({1}%). 4 | BuildAction.Blocks=\u30d6\u30ed\u30c3\u30af {0} ({1}%). 5 | BuildAction.Lines=\u884c {0} ({1}%). 6 | BuildAction.Perfect=All coverage targets have been met. 7 | BuildAction.DisplayName=\u30ab\u30d0\u30ec\u30c3\u30b8\u30ec\u30dd\u30fc\u30c8 8 | ProjectAction.DisplayName=\u30ab\u30d0\u30ec\u30c3\u30b8\u306e\u63a8\u79fb 9 | JacocoPublisher.DisplayName=JaCoCo\u30ab\u30d0\u30ec\u30c3\u30b8\u30ec\u30dd\u30fc\u30c8\u3092\u8a18\u9332 10 | CoverageObject.Legend.Class=\u30af\u30e9\u30b9 11 | CoverageObject.Legend.Block=\u30d6\u30ed\u30c3\u30af 12 | CoverageObject.Legend.LineCovered=\u884c Covered 13 | CoverageObject.Legend.LineMissed=\u884c Missed 14 | CoverageObject.Legend.Method=\u30e1\u30bd\u30c3\u30c9 15 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/Messages.properties: -------------------------------------------------------------------------------- 1 | chartTitle=JaCoCo Coverage Trend Chart 2 | gridTitle=JaCoCo Coverage Statistics Grid -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/chart/JacocoBuilderTrendChart/config.jelly: -------------------------------------------------------------------------------- 1 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/chart/JacocoBuilderTrendChart/config.properties: -------------------------------------------------------------------------------- 1 | Name=Name 2 | Width=Width 3 | Height=Height 4 | NumberOfDays=Number of Days 5 | chartTitle=JaCoCo Coverage Trend Chart -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/chart/JacocoBuilderTrendChart/help-daysNumber.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 |

The default value is 30. The chart will consider only the builds within the specified number of days from the last build date (including it) of all jobs chosen on Dashboard View.

4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/chart/JacocoBuilderTrendChart/help-height.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 |

The default value is 250. This field will set the height of the chart. The chart will consider the default value if some negative, null or non-numeric value is filled in this field.

4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/chart/JacocoBuilderTrendChart/help-width.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 |

The default value is 500. This field will set the width of the chart. The chart will consider the default value if some negative, null or non-numeric value is filled in this field.

4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/chart/JacocoBuilderTrendChart/main.jelly: -------------------------------------------------------------------------------- 1 | 29 | 30 | 31 | 32 | 33 | 34 |
35 | ${%chartTitle} 36 |
37 | 38 |
39 |
40 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/chart/JacocoBuilderTrendChart/main.properties: -------------------------------------------------------------------------------- 1 | chartTitle=JaCoCo Coverage Trend Chart -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/chart/JacocoBuilderTrendChart/portlet.jelly: -------------------------------------------------------------------------------- 1 | 29 | 30 | 31 | 32 | 33 | 34 |
35 | ${%chartTitle} 36 |
37 | 38 |
39 |
40 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/chart/JacocoBuilderTrendChart/portlet.properties: -------------------------------------------------------------------------------- 1 | chartTitle=JaCoCo Coverage Trend Chart -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/grid/JacocoBuilderGrid/portlet.jelly: -------------------------------------------------------------------------------- 1 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ${%Job} 38 | % ${%Instruction} 39 | % ${%Branch} 40 | % ${%Complexity} 41 | % ${%Line} 42 | % ${%Method} 43 | % ${%Class} 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | ${tr.instructionCoverage} 52 | ${tr.branchCoverage} 53 | ${tr.complexityScore} 54 | ${tr.lineCoverage} 55 | ${tr.methodCoverage} 56 | ${tr.classCoverage} 57 | 58 | 59 | 60 | ${%Total} 61 | ${summary.totalInstructionCoverage} 62 | ${summary.totalBranchCoverage} 63 | ${summary.totalComplexityScore} 64 | ${summary.totalLineCoverage} 65 | ${summary.totalMethodCoverage} 66 | ${summary.totalClassCoverage} 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/portlet/grid/JacocoBuilderGrid/portlet.properties: -------------------------------------------------------------------------------- 1 | gridTitle=JaCoCo Coverage Statistics Grid -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/ClassReport/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

${%Package}: ${it.name}

7 | 8 | 9 |

${it.name}

10 | 11 | 12 |

${%Coverage}

13 | 14 | ${it.printHighlightedSrcFile(output.asWriter())} 15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/ClassReport/index_es.properties: -------------------------------------------------------------------------------- 1 | Coverage\ Summary=Resumen de cobertura 2 | Package=Paquete 3 | Coverage\ Breakdown\ by\ Source\ File=Cobertura por fichero fuente 4 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/ClassReport/index_ja.properties: -------------------------------------------------------------------------------- 1 | Coverage\ Summary=\u30ab\u30d0\u30ec\u30c3\u30b8\u6982\u8981 2 | Package=\u30d1\u30c3\u30b1\u30fc\u30b8 3 | Coverage\ Breakdown\ by\ Source\ File=\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u3054\u3068\u306e\u30ab\u30d0\u30ec\u30c3\u30b8 4 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/CoverageReport/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

${%JaCoCo Coverage Report}

7 | 12 | 13 | 14 | 15 |

${%Overall Coverage Summary}

16 | 17 | 18 |

${%Coverage Breakdown by Package}

19 | 20 |
21 |
22 |
23 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/CoverageReport/index_es.properties: -------------------------------------------------------------------------------- 1 | JaCoCo\ Coverage\ Report=Informe JaCoCo de cobertura. 2 | all\ classes=Todas las clases 3 | Coverage\ Breakdown\ by\ Package=Informe de cobertura por paquete 4 | Overall\ Coverage\ Summary=Resumen global de la cobertura 5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/CoverageReport/index_ja.properties: -------------------------------------------------------------------------------- 1 | JaCoCo\ Coverage\ Report=JaCoCo\u30ab\u30d0\u30ec\u30c3\u30b8\u30ec\u30dd\u30fc\u30c8 2 | all\ classes=\u5168\u30af\u30e9\u30b9 3 | Coverage\ Breakdown\ by\ Package=\u30d1\u30c3\u30b1\u30fc\u30b8\u3054\u3068\u306e\u30ab\u30d0\u30ec\u30c3\u30b8 4 | Overall\ Coverage\ Summary=\u30ab\u30d0\u30ec\u30c3\u30b8\u306e\u6982\u8981 5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/MethodReport/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

${%Method}: ${it.name}

7 | 8 | ${it.printHighlightedSrcFile(output.asWriter())} 9 |
10 |
11 |
12 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/MethodReport/index_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/resources/hudson/plugins/jacoco/report/MethodReport/index_es.properties -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/MethodReport/index_ja.properties: -------------------------------------------------------------------------------- 1 | Source\ File=\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb 2 | Coverage\ Summary=\u30ab\u30d0\u30ec\u30c3\u30b8\u6982\u8981 3 | Coverage\ Breakdown\ by\ Class\ and\ Method=\u30af\u30e9\u30b9/\u30e1\u30bd\u30c3\u30c9\u3054\u3068\u306e\u30ab\u30d0\u30ec\u30c3\u30b8 4 | Class=\u30af\u30e9\u30b9 -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/PackageReport/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

${%Package}: ${it.name}

7 | 8 | 9 |

${%Coverage Summary}

10 | 11 | 12 |

${%Coverage Breakdown by Source File}

13 | 14 |
15 |
16 |
17 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/PackageReport/index_es.properties: -------------------------------------------------------------------------------- 1 | Coverage\ Summary=Resumen de cobertura 2 | Package=Paquete 3 | Coverage\ Breakdown\ by\ Source\ File=Cobertura por fichero fuente 4 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/PackageReport/index_ja.properties: -------------------------------------------------------------------------------- 1 | Coverage\ Summary=\u30ab\u30d0\u30ec\u30c3\u30b8\u6982\u8981 2 | Package=\u30d1\u30c3\u30b1\u30fc\u30b8 3 | Coverage\ Breakdown\ by\ Source\ File=\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u3054\u3068\u306e\u30ab\u30d0\u30ec\u30c3\u30b8 4 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/SourceFileReport/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

${%Source File}: ${it.name}

7 | 8 |

${%Coverage Summary}

9 | 10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/SourceFileReport/index_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/resources/hudson/plugins/jacoco/report/SourceFileReport/index_es.properties -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/report/SourceFileReport/index_ja.properties: -------------------------------------------------------------------------------- 1 | Source\ File=\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb 2 | Coverage\ Summary=\u30ab\u30d0\u30ec\u30c3\u30b8\u6982\u8981 3 | Coverage\ Breakdown\ by\ Class\ and\ Method=\u30af\u30e9\u30b9/\u30e1\u30bd\u30c3\u30c9\u3054\u3068\u306e\u30ab\u30d0\u30ec\u30c3\u30b8 4 | Class=\u30af\u30e9\u30b9 -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/tags/breakdownMethodsTable.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 |
8 | 9 |
14 |
15 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/tags/breakdownTable.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 |
8 | 9 |
14 |
15 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/tags/captionLine.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ${%name} 6 | ${%instruction} 7 | ${%branch} 8 | ${%complexity} 9 | 10 | ${%line} 11 | 12 | ${%method} 13 | 14 | ${%class} 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/tags/captionLine_de.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/resources/hudson/plugins/jacoco/tags/captionLine_de.properties -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/tags/captionLine_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/resources/hudson/plugins/jacoco/tags/captionLine_es.properties -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/tags/captionLine_ja.properties: -------------------------------------------------------------------------------- 1 | name=\u540d\u524d 2 | block=\u30d6\u30ed\u30c3\u30af 3 | method=\u30e1\u30bd\u30c3\u30c9 4 | class=\u30af\u30e9\u30b9 5 | line=\u884c 6 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/tags/floatingTrendGraph.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/tags/summaryMethod.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
${title}
10 |
11 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/tags/summaryTable.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
${title}
10 |
11 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacoco/tags/taglib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/resources/hudson/plugins/jacoco/tags/taglib -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/BranchCoverageColumn/column.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | ${coveragePercent}% 24 | 25 | 26 | 27 | N/A 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/BranchCoverageColumn/columnHeader.jelly: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 | ${%Branch Coverage} 28 | 29 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/BranchCoverageColumn/columnHeader_de.properties: -------------------------------------------------------------------------------- 1 | Branch\ Coverage=Branchabdeckung 2 | Percentage\ of\ branches\ of\ code\ that\ are\ covered\ in\ unit\ tests=Prozentuale Branch-Testabdeckung -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/BranchCoverageColumn/column_de.properties: -------------------------------------------------------------------------------- 1 | Percentage\ of\ branches\ of\ code\ that\ are\ covered\ in\ unit\ tests=Prozentuale Branch-Testabdeckung -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/BranchCoverageColumn/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

${%Shows the Java code branch coverage measured with JaCoCo.}

5 |
6 |
-------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/BranchCoverageColumn/config_de.properties: -------------------------------------------------------------------------------- 1 | Shows\ the\ Java\ code\ branch\ coverage\ measured\ with\ JaCoCo.=Zeigt die Java-Code-Branchabdeckung, die durch JaCoCo gemessen wurde. 2 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/JaCoCoColumn/column.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | ${coveragePercent}% 24 | 25 | 26 | 27 | N/A 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/JaCoCoColumn/columnHeader.jelly: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 | ${%Line Coverage} 28 | 29 | -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/JaCoCoColumn/columnHeader_de.properties: -------------------------------------------------------------------------------- 1 | Line\ Coverage=Zeilenabdeckung 2 | Percentage\ of\ lines\ of\ code\ that\ are\ covered\ in\ unit\ tests=Prozentuale Zeilen-Testabdeckung -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/JaCoCoColumn/column_de.properties: -------------------------------------------------------------------------------- 1 | Percentage\ of\ lines\ of\ code\ that\ are\ covered\ in\ unit\ tests=Prozentuale Zeilen-Testabdeckung -------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/JaCoCoColumn/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

${%Shows the Java code lines coverage measured with JaCoCo.}

5 |
6 |
-------------------------------------------------------------------------------- /src/main/resources/hudson/plugins/jacococoveragecolumn/JaCoCoColumn/config_de.properties: -------------------------------------------------------------------------------- 1 | Shows\ the\ Java\ code\ lines\ coverage\ measured\ with\ JaCoCo.=Zeigt die Java-Code-Zeilenabdeckung, die durch JaCoCo gemessen wurde. -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 | This plugin integrates JaCoCo code coverage reports to Jenkins. 4 |
5 | -------------------------------------------------------------------------------- /src/main/webapp/css/class.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/webapp/css/class.gif -------------------------------------------------------------------------------- /src/main/webapp/css/greenbar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/webapp/css/greenbar.gif -------------------------------------------------------------------------------- /src/main/webapp/css/method.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/webapp/css/method.gif -------------------------------------------------------------------------------- /src/main/webapp/css/package.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/webapp/css/package.gif -------------------------------------------------------------------------------- /src/main/webapp/css/redbar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/webapp/css/redbar.gif -------------------------------------------------------------------------------- /src/main/webapp/css/style.css: -------------------------------------------------------------------------------- 1 | table.source { 2 | border-style: solid; 3 | border-color: #bbb; 4 | border-spacing: 0; 5 | /*border-collapse: collapse;*/ 6 | /*width: 100%;*/ 7 | } 8 | 9 | table.source .text { 10 | margin-top: -1px; 11 | } 12 | 13 | table.source th { 14 | padding-left: 0.5em; 15 | font-weight: bold; 16 | background-color: #f0f0f0; 17 | } 18 | 19 | .nowrap { 20 | white-space: nowrap; 21 | } 22 | .red { 23 | background-color: red; 24 | } 25 | 26 | 27 | div.percentgraph { 28 | background-color: #80ff80; 29 | border: #808080 0px solid; 30 | height: 1.3em; 31 | margin: 0px; 32 | padding: 0px; 33 | /* width: 100px;*/ 34 | } 35 | 36 | div.percentgraph div.greenbar { 37 | background-color: #80ff80; 38 | height: 1.3em; 39 | margin: 0px; 40 | padding: 0px; 41 | } 42 | div.percentgraph div.redbar { 43 | background-color: #ff9090; 44 | height: 1.3em; 45 | margin: 0px; 46 | padding: 0px; 47 | } 48 | 49 | div.percentgraph div.na { 50 | background-color: #eaeaea; 51 | height: 1.3em; 52 | margin: 0px; 53 | padding: 0px; 54 | } 55 | 56 | div.percentgraph span.text { 57 | display: block; 58 | text-align: center; 59 | position: absolute; 60 | width: 100px; 61 | } 62 | 63 | table.percentgraph { 64 | border: 0px; 65 | font-size: 100%; 66 | margin: 0px; 67 | margin-left: 0px; 68 | margin-right: 0px; 69 | padding: 0px; 70 | text-align: left; 71 | } 72 | 73 | table.percentgraph tr.percentgraph { 74 | border: 0px; 75 | margin: 0px; 76 | padding: 0px; 77 | } 78 | 79 | table.percentgraph td.percentgraph { 80 | border: 0px; 81 | margin: 0px; 82 | padding: 0px; 83 | padding-left: 4px; 84 | } 85 | 86 | table.percentgraph td.data { 87 | padding-top: 3px; 88 | padding-bottom: 0px; 89 | text-align: right; 90 | } 91 | -------------------------------------------------------------------------------- /src/main/webapp/icons/jacoco-48x48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/main/webapp/icons/jacoco-48x48.png -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/AbstractJacocoTestBase.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import hudson.plugins.jacoco.model.Coverage; 4 | import static org.junit.Assert.*; 5 | 6 | /** 7 | * @author Kohsuke Kawaguchi 8 | */ 9 | public abstract class AbstractJacocoTestBase { 10 | protected final void assertRatio(Coverage r, float numerator, float denominator) { 11 | fail("Replaced by assertCoverage()"); 12 | } 13 | 14 | protected final void assertCoverage(Coverage coverage, int missed, int covered) { 15 | assertEquals(missed + "/" + covered, coverage.getMissed() + "/" + coverage.getCovered()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/CoverageReportTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import org.junit.Ignore; 6 | import org.junit.Test; 7 | 8 | /** 9 | * @author Kohsuke Kawaguchi 10 | * @author David Carver - Refactored for cleaner seperation of tests 11 | */ 12 | public class CoverageReportTest extends AbstractJacocoTestBase { 13 | //private Map map = Collections.emptyMap(); 14 | 15 | @Test 16 | public void testLoad() throws Exception { 17 | /*final BuildListener listener = EasyMock.createNiceMock(BuildListener.class); 18 | EasyMock.replay(listener); 19 | 20 | JacocoBuildAction action = new JacocoBuildAction(null, null, map, null, listener, null, null); 21 | 22 | CoverageReport r = new CoverageReport(action, new ExecutionFileLoader()); 23 | PackageReport pkg = r.getChildren().get("hudson.plugins.jacoco"); 24 | System.out.println(pkg); 25 | assertCoverage(pkg.getLineCoverage(), 393, 196); 26 | assertEquals(595, r.getLineCoverage().getMissed()); 27 | 28 | EasyMock.verify(listener);*/ 29 | } 30 | 31 | /** 32 | * Ensures the coverage after loading two reports represents the combined metrics of both reports. 33 | * @throws Exception if any error occurs 34 | */ 35 | @Test 36 | public void testLoadMultipleReports() throws Exception { 37 | /*CoverageReport r = new CoverageReport(null, 38 | getClass().getResourceAsStream("jacoco.xml"), 39 | getClass().getResourceAsStream("jacoco2.xml")); 40 | 41 | assertCoverage(r.getLineCoverage(), 513, 361); 42 | 43 | PackageReport pkg = r.getChildren().get("hudson.plugins.jacoco.portlet.bean"); 44 | assertCoverage(pkg.getLineCoverage(), 34, 41); 45 | 46 | pkg = r.getChildren().get("hudson.plugins.jacoco.portlet.chart"); 47 | assertCoverage(pkg.getLineCoverage(), 68, 1);*/ 48 | assertTrue(true); 49 | 50 | } 51 | 52 | @Test 53 | public void testCoverageReport() throws Exception { 54 | //CoverageReport r = new CoverageReport(null,getClass().getResourceAsStream("jacoco2.xml")); 55 | //assertCoverage(r.getLineCoverage(), 513, 361); 56 | assertTrue(true); 57 | } 58 | 59 | @Test 60 | public void testPackageReport() throws Exception { 61 | //CoverageReport r = new CoverageReport(null,getClass().getResourceAsStream("jacoco2.xml")); 62 | //PackageReport pkg = r.getChildren().get("hudson.plugins.jacoco.portlet.bean"); 63 | //assertCoverage(pkg.getLineCoverage(), 34, 41); 64 | assertTrue(true); 65 | } 66 | 67 | @Test 68 | @Ignore 69 | public void testSourceFileReport() throws Exception { 70 | //CoverageReport r = new CoverageReport(null,getClass().getResourceAsStream("jacoco2.xml")); 71 | //PackageReport pkg = r.getChildren().get("hudson.plugins.jacoco.portlet.bean"); 72 | // SourceFileReport src = pkg.getChildren().get("JacocoCoverageResultSummary.java"); 73 | // assertCoverage(src.getLineCoverage(), 34, 41); 74 | assertTrue(true); 75 | } 76 | 77 | @Test 78 | public void testClassReport() throws Exception { 79 | //CoverageReport r = new CoverageReport(null,getClass().getResourceAsStream("jacoco2.xml")); 80 | //PackageReport pkg = r.getChildren().get("hudson.plugins.jacoco.portlet.bean"); 81 | //ClassReport clz = pkg.getChildren().get("JacocoCoverageResultSummary"); 82 | 83 | //assertCoverage(clz.getLineCoverage(),34, 41); 84 | //assertTrue(clz.hasClassCoverage()); 85 | assertTrue(true); 86 | } 87 | 88 | @Test 89 | public void testMethodReport() throws Exception { 90 | /* 91 | CoverageReport r = new CoverageReport(null,getClass().getResourceAsStream("jacoco2.xml")); 92 | PackageReport pkg = r.getChildren().get("hudson.plugins.jacoco.portlet.bean"); 93 | ClassReport clz = pkg.getChildren().get("JacocoCoverageResultSummary"); 94 | MethodReport mth = clz.getChildren().get("getJacocoCoverageResults"); 95 | assertCoverage(mth.getLineCoverage(), 1, 0); 96 | assertFalse("Found Class coverage on Method. ", mth.hasClassCoverage());*/ 97 | assertTrue(true); 98 | } 99 | 100 | @Test 101 | public void testEmptyPackage() throws Exception { 102 | /*CoverageReport r = new CoverageReport(null,getClass().getResourceAsStream("jacoco.xml")); 103 | 104 | PackageReport pkg = r.getChildren().get("fake.empty.package"); 105 | assertCoverage(pkg.getLineCoverage(), 0, 0); 106 | assertFalse(pkg.hasChildren()); 107 | assertFalse(pkg.hasChildrenClassCoverage()); 108 | assertFalse(pkg.hasChildrenLineCoverage()); 109 | 110 | pkg = r.getChildren().get("fake.empty.package.without.lines"); 111 | assertCoverage(pkg.getLineCoverage(), 0, 0); 112 | assertFalse(pkg.hasChildren()); 113 | assertFalse(pkg.hasChildrenClassCoverage()); 114 | assertFalse(pkg.hasChildrenLineCoverage());*/ 115 | assertTrue(true); 116 | 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/CoverageTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import hudson.plugins.jacoco.portlet.utils.Utils; 4 | import org.junit.Test; 5 | 6 | import hudson.plugins.jacoco.model.Coverage; 7 | 8 | import java.math.RoundingMode; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * JUnit test for {@link Coverage} 14 | */ 15 | public class CoverageTest extends AbstractJacocoTestBase { 16 | 17 | @Test 18 | public void testPercentageCalculation() throws Exception { 19 | Coverage c = new Coverage(1, 2); 20 | assertEquals(67, c.getPercentage()); 21 | } 22 | 23 | @Test 24 | public void testUninitialized() throws Exception { 25 | Coverage c = new Coverage(); 26 | assertFalse(c.isInitialized()); 27 | } 28 | 29 | @Test 30 | public void testAccumulateInitializes() throws Exception { 31 | Coverage c = new Coverage(); 32 | c.accumulate(3, 2); 33 | assertTrue(c.isInitialized()); 34 | } 35 | 36 | @Test 37 | public void testNormalConstructorInitializes() throws Exception { 38 | Coverage c = new Coverage(1, 2); 39 | assertTrue(c.isInitialized()); 40 | } 41 | 42 | @Test 43 | public void testVacuousCoverage() throws Exception { 44 | final Coverage c = new Coverage(0, 0); 45 | assertEquals(100, c.getPercentage()); 46 | } 47 | 48 | @Test 49 | public void testHalfCoverage() throws Exception { 50 | Coverage c = new Coverage(1, 1); 51 | assertEquals(50, c.getPercentage()); 52 | 53 | c = new Coverage(12, 12); 54 | assertEquals(50, c.getPercentage()); 55 | } 56 | 57 | @Test 58 | public void testFullCoverage() throws Exception { 59 | Coverage c = new Coverage(0, 1); 60 | assertEquals(100, c.getPercentage()); 61 | 62 | c = new Coverage(0, 12); 63 | assertEquals(100, c.getPercentage()); 64 | } 65 | 66 | @Test 67 | public void testStringRepresentation() { 68 | int coverageInt = 67; 69 | float coverageDouble = 2f/3; 70 | assertEquals(0.666666667, coverageDouble, 0.000001); 71 | 72 | //noinspection StringBufferReplaceableByString 73 | StringBuilder buf = new StringBuilder(); 74 | buf.append(coverageInt).append("/") 75 | .append(coverageDouble).append("/") 76 | .append(Utils.roundFloat(6, RoundingMode.HALF_EVEN, 100*coverageDouble)); 77 | assertEquals("67/0.6666667/66.66667", buf.toString()); 78 | } 79 | } -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/JacocoBuildActionTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | 4 | import hudson.util.LogTaskListener; 5 | import org.junit.Test; 6 | 7 | import java.io.File; 8 | import java.util.logging.Level; 9 | import java.util.logging.Logger; 10 | 11 | import static java.nio.file.Files.createDirectories; 12 | import static org.junit.Assert.assertFalse; 13 | import static org.junit.Assert.assertNotNull; 14 | 15 | /** 16 | * @author Kohsuke Kawaguchi 17 | */ 18 | public class JacocoBuildActionTest extends AbstractJacocoTestBase { 19 | private static final Logger logger = Logger.getLogger(JacocoBuildActionTest.class.getName()); 20 | 21 | @Test 22 | public void testConstruct() throws Exception { 23 | File testDir = new File("target/test/JacocoBuildActionTest"); 24 | createDirectories(new File(testDir, "jacoco/classes").toPath()); 25 | JacocoBuildAction r = JacocoBuildAction.load( 26 | new JacocoHealthReportThresholds(30, 90, 25, 80, 15, 60, 15, 60, 20, 70, 0, 0), 27 | new LogTaskListener(logger, Level.INFO), 28 | new JacocoReportDir(testDir), null, null); 29 | assertNotNull(r); 30 | } 31 | 32 | @Test 33 | public void testConstructNonExistingTestDir() throws Exception { 34 | File testDir = new File("target/test/notExistingTest"); 35 | assertFalse("Expecting " + testDir.getAbsolutePath() + " to not exist, but was found", 36 | testDir.exists()); 37 | JacocoBuildAction r = JacocoBuildAction.load( 38 | new JacocoHealthReportThresholds(30, 90, 25, 80, 15, 60, 15, 60, 20, 70, 0, 0), 39 | new LogTaskListener(logger, Level.INFO), 40 | new JacocoReportDir(testDir), null, null); 41 | assertNotNull(r); 42 | } 43 | 44 | /*@Test 45 | public void testLoadReport1() throws Exception { 46 | JacocoBuildAction r = JacocoBuildAction.load(null,null, 47 | new JacocoHealthReportThresholds(30, 90, 25, 80, 15, 60, 15, 60, 20, 70, 0, 0), 48 | getClass().getResourceAsStream("jacoco.xml")); 49 | assertEquals(54, r.clazz.getPercentage()); 50 | assertEquals(33, r.line.getPercentage()); 51 | assertCoverage(r.clazz, 17, 20); 52 | assertCoverage(r.method, 167, 69); 53 | assertCoverage(r.line, 595, 293); 54 | assertCoverage(r.branch, 223, 67); 55 | assertCoverage(r.instruction, 2733, 1351); 56 | assertCoverage(r.complexity, 289, 92); 57 | assertEquals("Coverage: Classes 17/20 (54%). Methods 167/69 (29%). Lines 595/293 (33%). Branches 223/67 (23%). Instructions 2733/1351 (33%).", 58 | r.getBuildHealth().getDescription()); 59 | } 60 | 61 | @Test 62 | public void testLoadReport2() throws Exception { 63 | JacocoBuildAction r = JacocoBuildAction.load(null,null, 64 | new JacocoHealthReportThresholds(30, 90, 25, 80, 15, 60, 15, 60, 20, 70, 0, 0), 65 | getClass().getResourceAsStream("jacoco2.xml")); 66 | assertEquals(76, r.clazz.getPercentage()); 67 | assertEquals(41, r.line.getPercentage()); 68 | assertCoverage(r.clazz, 9, 28); 69 | assertCoverage(r.method, 122, 116); 70 | assertCoverage(r.line, 513, 361); 71 | assertCoverage(r.branch, 224, 66); 72 | assertCoverage(r.instruction, 2548, 1613); 73 | assertCoverage(r.complexity, 246, 137); 74 | assertEquals("Coverage: Classes 9/28 (76%). Methods 122/116 (49%). Lines 513/361 (41%). Branches 224/66 (23%). Instructions 2548/1613 (39%).", 75 | r.getBuildHealth().getDescription()); 76 | } 77 | 78 | @Test 79 | public void testLoadMultipleReports() throws Exception { 80 | JacocoBuildAction r = JacocoBuildAction.load(null,null, 81 | new JacocoHealthReportThresholds(30, 90, 25, 80, 15, 60, 15, 60, 20, 70, 0, 0), 82 | getClass().getResourceAsStream("jacoco.xml"), 83 | getClass().getResourceAsStream("jacoco2.xml")); 84 | assertEquals(76, r.clazz.getPercentage()); 85 | assertEquals(41, r.line.getPercentage()); 86 | assertCoverage(r.clazz, 9, 28); 87 | assertCoverage(r.method, 122, 116); 88 | assertCoverage(r.line, 513, 361); 89 | assertCoverage(r.branch, 224, 66); 90 | assertCoverage(r.instruction, 2548, 1613); 91 | assertCoverage(r.complexity, 246, 137); 92 | assertEquals("Coverage: Classes 9/28 (76%). Methods 122/116 (49%). Lines 513/361 (41%). Branches 224/66 (23%). Instructions 2548/1613" + 93 | " (39%).", 94 | r.getBuildHealth().getDescription()); 95 | }*/ 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/JacocoHealthReportDeltaThresholdsTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class JacocoHealthReportDeltaThresholdsTest { 9 | 10 | private JacocoHealthReportDeltaThresholds jacocoHealthReportDeltaThresholds; 11 | 12 | @Before 13 | public void setUp() { 14 | this.jacocoHealthReportDeltaThresholds = new JacocoHealthReportDeltaThresholds("10.0555503", "-1", "5.0647928", "190.90", "2.0222", "0"); 15 | } 16 | 17 | // Test if negative coverage thresholds are changed to zero percentage 18 | @Test 19 | public void changeNegativeThToZeroTest(){ 20 | assertEquals("Negative TH changed to zero", 0f, jacocoHealthReportDeltaThresholds.getDeltaBranch(), 0.00001); 21 | } 22 | 23 | // Test if coverage thresholds greater than 100 are changed to 100 percentage 24 | @Test 25 | public void changeTooBigToHundredTest(){ 26 | assertEquals("TH greater than 100 changed to 100", 100f, jacocoHealthReportDeltaThresholds.getDeltaLine(), 0.00001); 27 | } 28 | 29 | // Test if coverage thresholds greater than X.XXXXXX5 are half round up 30 | @Test 31 | public void halfRoundUpTest(){ 32 | assertEquals("Delta threshold with scale greater than six is round half up when greater than X.XXXXXX5", 5.064793f, jacocoHealthReportDeltaThresholds.getDeltaComplexity(), 0.00001); 33 | } 34 | 35 | // Test if coverage thresholds lesser than X.XXXXXX5 are half round down 36 | @Test 37 | public void halfRoundDownTest(){ 38 | assertEquals("Delta threshold with scale greater than six is round half down when lesser than X.XXXXXX5", 10.055550f, jacocoHealthReportDeltaThresholds.getDeltaInstruction(), 0.00001); 39 | } 40 | 41 | // Test if coverage thresholds with scale lesser than six are scaled to six digits after decimal 42 | @Test 43 | public void scaleToSixTest(){ 44 | assertEquals("Delta threshold with scale lesser than six is scaled to six", 2.022200f, jacocoHealthReportDeltaThresholds.getDeltaMethod(), 0.00001); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/RunBuilder.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import hudson.EnvVars; 4 | import hudson.model.Action; 5 | import hudson.model.Result; 6 | import hudson.model.Run; 7 | import hudson.model.TaskListener; 8 | 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.nio.file.Files; 12 | import java.util.concurrent.atomic.AtomicReference; 13 | import java.util.logging.Logger; 14 | 15 | import org.easymock.IAnswer; 16 | 17 | import static org.easymock.EasyMock.anyObject; 18 | import static org.easymock.EasyMock.expect; 19 | import static org.easymock.EasyMock.expectLastCall; 20 | import static org.easymock.EasyMock.getCurrentArguments; 21 | import static org.easymock.EasyMock.mock; 22 | import static org.easymock.EasyMock.niceMock; 23 | import static org.easymock.EasyMock.replay; 24 | import static org.junit.Assert.assertNotNull; 25 | import static org.junit.Assert.assertTrue; 26 | 27 | public class RunBuilder { 28 | private TaskListener taskListener; 29 | 30 | Run build() throws IOException, InterruptedException { 31 | final TaskListener usedTaskListener = taskListener == null ? niceMock(TaskListener.class) : taskListener; 32 | 33 | final Run run = mock(Run.class); 34 | expect(run.getEnvironment(usedTaskListener)).andReturn(new EnvVars()).anyTimes(); 35 | expect(run.getResult()).andReturn(Result.SUCCESS).anyTimes(); 36 | expect(run.getParent()).andReturn(null).anyTimes(); 37 | 38 | // create a test build directory 39 | File rootDir = Files.createTempDirectory("BuildTest.test").toFile(); 40 | assertNotNull(rootDir); 41 | 42 | expect(run.getRootDir()).andReturn(rootDir).anyTimes(); 43 | 44 | Action action = anyObject(); 45 | run.addAction(action); 46 | final AtomicReference buildAction = new AtomicReference<>(); 47 | expectLastCall().andAnswer((IAnswer) () -> { 48 | buildAction.set((JacocoBuildAction) getCurrentArguments()[0]); 49 | buildAction.get().onAttached(run); 50 | return null; 51 | }); 52 | 53 | replay(usedTaskListener, run); 54 | Logger.getLogger(RunBuilder.class.getName()).info("Created build dir: " + rootDir.getAbsolutePath()); 55 | return run; 56 | 57 | } 58 | 59 | public RunBuilder taskListener(TaskListener taskListener) { 60 | this.taskListener = taskListener; 61 | return this; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/WorkspaceBuilder.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco; 2 | 3 | import hudson.FilePath; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.logging.Logger; 11 | 12 | import static org.junit.Assert.assertNotNull; 13 | import static org.junit.Assert.assertTrue; 14 | 15 | public class WorkspaceBuilder { 16 | private List files = new ArrayList<>(); 17 | 18 | FilePath build() throws IOException { 19 | // create a test workspace of Jenkins job 20 | File wksp = Files.createTempDirectory("workspace.test").toFile(); 21 | assertNotNull(wksp); 22 | wksp.deleteOnExit(); 23 | 24 | final FilePath workspace = new FilePath(wksp); 25 | for (String file : files) { 26 | File f = new File(workspace.child(file).getRemote()); 27 | if (!f.getParentFile().exists()) { 28 | assertTrue("Failed creating: " + f.getParentFile(), f.getParentFile().mkdirs()); 29 | } 30 | assertTrue(f.createNewFile()); 31 | f.deleteOnExit(); 32 | } 33 | Logger.getLogger(WorkspaceBuilder.class.getName()).info("Created workspace: " + wksp.getAbsolutePath()); 34 | return workspace; 35 | } 36 | 37 | public WorkspaceBuilder file(String relativeFile) { 38 | this.files.add(relativeFile); 39 | return this; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/e2e/E2ETest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.e2e; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.hamcrest.Description; 7 | import org.hamcrest.TypeSafeDiagnosingMatcher; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.jvnet.hudson.test.RealJenkinsRule; 11 | 12 | import hudson.Functions; 13 | import hudson.model.Descriptor; 14 | import hudson.model.FreeStyleBuild; 15 | import hudson.model.FreeStyleProject; 16 | import hudson.plugins.jacoco.JacocoBuildAction; 17 | import hudson.plugins.jacoco.JacocoPublisher; 18 | import hudson.plugins.jacoco.model.Coverage; 19 | import hudson.tasks.BatchFile; 20 | import hudson.tasks.Builder; 21 | import hudson.tasks.Publisher; 22 | import hudson.tasks.Shell; 23 | import hudson.util.DescribableList; 24 | 25 | import static org.hamcrest.CoreMatchers.*; 26 | import static org.hamcrest.MatcherAssert.assertThat; 27 | 28 | import static hudson.plugins.jacoco.e2e.E2ETest.CoverageMatcher.withCoverage; 29 | 30 | public class E2ETest { 31 | 32 | @Rule 33 | public RealJenkinsRule rjr = new RealJenkinsRule(); 34 | 35 | @Test 36 | public void simpleTest() throws Throwable { 37 | rjr.then(r -> { 38 | FreeStyleProject project = r.createFreeStyleProject(); 39 | project.getBuildersList().addAll(createJacocoProjectBuilders()); 40 | project.getPublishersList().add(new JacocoPublisher()); 41 | 42 | FreeStyleBuild build = r.buildAndAssertSuccess(project); 43 | 44 | assertThat("plugin collected data", build.getLog(), containsString("Collecting JaCoCo coverage data")); 45 | 46 | JacocoBuildAction action = build.getAction(JacocoBuildAction.class); 47 | assertThat("Build has the Jacoco Action", action, notNullValue()); 48 | 49 | assertThat("incorrect branch coverage reported", action.getBranchCoverage(), withCoverage(0, 617, 617)); 50 | assertThat("incorrect class coverage reported", action.getClassCoverage(), withCoverage(7, 59, 66)); 51 | assertThat("incorrect complexity coverage reported", action.getComplexityScore(), withCoverage(19, 833, 852)); 52 | // different compilers can generate different instructions (e.g. java8 vs java 11. 53 | // so just skip this for now as it seems brittle 54 | // assertThat("incorrect instruction coverage reported", action.getInstructionCoverage(), withCoverage(229, 9013, 9242)); /* java 8* / 55 | // assertThat("incorrect instruction coverage reported", action.getInstructionCoverage(), withCoverage(229, 9010 , 9239)); /* java 11 */ 56 | assertThat("incorrect line coverage reported", action.getLineCoverage(), withCoverage(53, 1860, 1913)); 57 | } 58 | ); 59 | } 60 | 61 | private static List createJacocoProjectBuilders() { 62 | String[] commands = { "git clone --branch jacoco-3.2.0 https://github.com/jenkinsci/jacoco-plugin.git .", 63 | "mvn -P enable-jacoco -B -Dtest=ClassReportTest test" }; 64 | List builders = new ArrayList<>(); 65 | if (Functions.isWindows()) { 66 | for (String command : commands) { 67 | builders.add(new BatchFile(command)); 68 | } 69 | } else { 70 | for (String command : commands) { 71 | builders.add(new Shell(command)); 72 | } 73 | } 74 | return builders; 75 | } 76 | 77 | public static class CoverageMatcher extends TypeSafeDiagnosingMatcher { 78 | 79 | private final int covered; 80 | private final int missed; 81 | private final int total; 82 | 83 | private CoverageMatcher(int covered, int missed, int total) { 84 | this.covered = covered; 85 | this.missed = missed; 86 | this.total = total; 87 | } 88 | @Override 89 | public void describeTo(Description description) { 90 | description.appendText(" with covered="+ covered); 91 | description.appendText(" and missed="+ missed); 92 | description.appendText(" and total="+ total); 93 | 94 | } 95 | 96 | @Override 97 | protected boolean matchesSafely(Coverage coverage, Description mismatchDescription) { 98 | mismatchDescription.appendText("Coverage with covered="+ coverage.getCovered()); 99 | mismatchDescription.appendText(" and missed="+ coverage.getMissed()); 100 | mismatchDescription.appendText(" and total="+ coverage.getTotal()); 101 | 102 | return coverage.getCovered() == covered && 103 | coverage.getMissed() == missed && 104 | coverage.getTotal() == total; 105 | } 106 | 107 | public static CoverageMatcher withCoverage(int covered, int missed, int total) { 108 | return new CoverageMatcher(covered, missed, total); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/model/CoverageGraphLayoutTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.model; 2 | 3 | import hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageType; 4 | import org.junit.After; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | import java.util.Locale; 9 | 10 | import static hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageType.BRANCH; 11 | import static hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageType.CLAZZ; 12 | import static hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageType.COMPLEXITY; 13 | import static hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageType.INSTRUCTION; 14 | import static hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageType.LINE; 15 | import static hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageType.METHOD; 16 | import static hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageValue.COVERED; 17 | import static hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageValue.MISSED; 18 | import static hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageValue.PERCENTAGE; 19 | import static hudson.plugins.jacoco.model.CoverageGraphLayout.CoverageValue.values; 20 | import static java.util.Locale.ENGLISH; 21 | import static java.util.Locale.GERMAN; 22 | import static org.junit.Assert.assertEquals; 23 | 24 | public class CoverageGraphLayoutTest { 25 | 26 | private Locale localeBackup; 27 | 28 | @Before 29 | public void setUp() { 30 | localeBackup = Locale.getDefault(); 31 | } 32 | 33 | @After 34 | public void tearDown() { 35 | Locale.setDefault(localeBackup); 36 | } 37 | 38 | @Test 39 | public void type() { 40 | Locale.setDefault(ENGLISH); 41 | 42 | assertEquals("New Coverage Types", 6, CoverageType.values().length); 43 | assertEquals("instructions", INSTRUCTION.getMessage()); 44 | assertEquals("line", LINE.getMessage()); 45 | assertEquals("branch", BRANCH.getMessage()); 46 | assertEquals("method", METHOD.getMessage()); 47 | assertEquals("class", CLAZZ.getMessage()); 48 | assertEquals("complexity", COMPLEXITY.getMessage()); 49 | 50 | Locale.setDefault(GERMAN); 51 | assertEquals("Anweisungen", INSTRUCTION.getMessage()); 52 | assertEquals("Zeilen", LINE.getMessage()); 53 | assertEquals("Branch", BRANCH.getMessage()); 54 | assertEquals("Methoden", METHOD.getMessage()); 55 | assertEquals("Klassen", CLAZZ.getMessage()); 56 | 57 | // JDK 8 has a problem with encoding here, JDK 11 works, so we 58 | // need to check for both until we do not use JDK 8 any more 59 | assertEquals("Had: " + COMPLEXITY.getMessage(), 60 | "Komplexität", COMPLEXITY.getMessage()); 61 | } 62 | 63 | @Test 64 | public void value() { 65 | Locale.setDefault(ENGLISH); 66 | assertEquals("New Coverage Value", 3, values().length); 67 | assertEquals("line covered", COVERED.getMessage(LINE)); 68 | assertEquals("line missed", MISSED.getMessage(LINE)); 69 | assertEquals("line", PERCENTAGE.getMessage(LINE)); 70 | 71 | Locale.setDefault(GERMAN); 72 | assertEquals("Zeilen abgedeckt", COVERED.getMessage(LINE)); 73 | assertEquals("Zeilen nicht abgedeckt", MISSED.getMessage(LINE)); 74 | assertEquals("Zeilen", PERCENTAGE.getMessage(LINE)); 75 | } 76 | } -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/model/CoverageObjectTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.model; 2 | 3 | import hudson.plugins.jacoco.AbstractJacocoTestBase; 4 | import org.junit.Test; 5 | 6 | /** 7 | * @author Manuel Carrasco 8 | */ 9 | public class CoverageObjectTest extends AbstractJacocoTestBase { 10 | @Test 11 | public void testConstruct() { 12 | // no test-content for now... 13 | } 14 | 15 | /*@Test 16 | public void testPrintRatioTable() throws Exception { 17 | 18 | Coverage r = null; 19 | StringBuilder b = new StringBuilder(); 20 | 21 | r = new Coverage(0,100); 22 | b = new StringBuilder(); 23 | CoverageObject.printRatioTable(r, b); 24 | 25 | assertEquals("
100.0%
M:0 C: 100
", b.toString()); 26 | } 27 | 28 | @Test 29 | public void testPrintRatioTable2() throws Exception { 30 | Coverage r = null; 31 | StringBuilder b = new StringBuilder(); 32 | r = new Coverage(51,200); 33 | b = new StringBuilder(); 34 | 35 | CoverageObject.printRatioTable(r, b); 36 | assertEquals("
79.7%
M:51 C: 200
", b.toString()); 37 | } 38 | 39 | 40 | @Test 41 | public void testPrintColumnt() throws Exception { 42 | 43 | Coverage r = null; 44 | StringBuilder b = new StringBuilder(); 45 | CoverageObject.printRatioCell(true, null, b); 46 | assertEquals("", b.toString()); 47 | 48 | r = new Coverage(0,100); 49 | b = new StringBuilder(); 50 | CoverageObject.printRatioCell(true, r, b); 51 | assertTrue(b.toString().contains("'nowrap red'")); 52 | 53 | r = new Coverage(0,100); 54 | b = new StringBuilder(); 55 | CoverageObject.printRatioCell(false, r, b); 56 | assertTrue(b.toString().contains("'nowrap'")); 57 | 58 | r = new Coverage(51,200); 59 | b = new StringBuilder(); 60 | CoverageObject.printRatioCell(false, r, b); 61 | System.out.println(b.toString()); 62 | 63 | assertEquals("\n" + 64 | "
79.7%
M:51 C: 200
\n", b.toString()); 65 | 66 | }*/ 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/model/TestCoverageObject.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.model; 2 | 3 | import hudson.model.AbstractBuild; 4 | import hudson.model.FreeStyleBuild; 5 | import org.easymock.EasyMock; 6 | import org.easymock.IAnswer; 7 | import org.easymock.IMocksControl; 8 | 9 | /** 10 | * @author Martin Heinzerling 11 | */ 12 | public class TestCoverageObject extends CoverageObject 13 | { 14 | private TestCoverageObject previous = null; 15 | private AbstractBuild build = null; 16 | private int buildNumber = 1; 17 | private static IMocksControl mocksControl; 18 | 19 | public static void setEasyMock(IMocksControl mocksControl) 20 | { 21 | TestCoverageObject.mocksControl = mocksControl; 22 | } 23 | 24 | public TestCoverageObject() 25 | { 26 | super(); 27 | build = mocksControl.createMock("build", FreeStyleBuild.class); 28 | EasyMock.expect(build.getDisplayName()).andAnswer(new IAnswer() 29 | { 30 | public String answer() throws Throwable 31 | { 32 | return "#" + buildNumber; 33 | } 34 | }).anyTimes(); 35 | } 36 | 37 | @Override 38 | public AbstractBuild getBuild() 39 | { 40 | return build; 41 | } 42 | 43 | @Override 44 | public TestCoverageObject getPreviousResult() 45 | { 46 | return previous; 47 | } 48 | 49 | public TestCoverageObject clazz(int missed, int covered) 50 | { 51 | clazz = new Coverage(missed, covered); 52 | return this; 53 | } 54 | 55 | public TestCoverageObject method(int missed, int covered) 56 | { 57 | method = new Coverage(missed, covered); 58 | return this; 59 | } 60 | 61 | public TestCoverageObject line(int missed, int covered) 62 | { 63 | line = new Coverage(missed, covered); 64 | return this; 65 | } 66 | 67 | public TestCoverageObject complexity(int missed, int covered) 68 | { 69 | complexity = new Coverage(missed, covered); 70 | return this; 71 | } 72 | 73 | public TestCoverageObject instruction(int missed, int covered) 74 | { 75 | instruction = new Coverage(missed, covered); 76 | return this; 77 | } 78 | 79 | public TestCoverageObject branch(int missed, int covered) 80 | { 81 | branch = new Coverage(missed, covered); 82 | return this; 83 | } 84 | 85 | public TestCoverageObject previous(TestCoverageObject previous) 86 | { 87 | this.previous = previous; 88 | int i = 1; 89 | TestCoverageObject t = this; 90 | while (t != null) 91 | { 92 | t.buildNumber = i; 93 | i++; 94 | t = t.previous; 95 | } 96 | return this; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/portlet/chart/JacocoBuilderTrendChartTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.portlet.chart; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.junit.Assert.assertNotNull; 7 | 8 | public class JacocoBuilderTrendChartTest { 9 | @Test 10 | public void construct() throws Exception { 11 | JacocoBuilderTrendChart chart = new JacocoBuilderTrendChart("chart", "200", "500", "3"); 12 | assertEquals(3, chart.getDaysNumber()); 13 | assertEquals(200, chart.getWidth()); 14 | assertEquals(500, chart.getHeight()); 15 | 16 | // causes an NPE because Stapler.getCurrentRequest() returns null: assertNotNull(chart.getSummaryGraph()); 17 | } 18 | 19 | @Test 20 | public void descriptor() throws Exception { 21 | JacocoBuilderTrendChart.DescriptorImpl descriptor = new JacocoBuilderTrendChart.DescriptorImpl(); 22 | assertNotNull(descriptor.getDisplayName()); 23 | } 24 | } -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/portlet/utils/UtilsComparisonTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.portlet.utils; 2 | 3 | import hudson.model.Result; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class UtilsComparisonTest { 8 | 9 | // Test if logical AND operation on Result data type works as expected 10 | @Test 11 | public void logicalAndOfResultsTest(){ 12 | Result result_1 = Result.SUCCESS; 13 | Result result_2 = Result.UNSTABLE; 14 | Result result_3 = Result.FAILURE; 15 | Assert.assertEquals("Success AND Success = Success", "SUCCESS", Utils.applyLogicalAnd(result_1, result_1).toString()); 16 | Assert.assertEquals("Unstable AND Unstable = Unstable", "UNSTABLE", Utils.applyLogicalAnd(result_2, result_2).toString()); 17 | Assert.assertEquals("Unstable AND Success = Unstable", "UNSTABLE", Utils.applyLogicalAnd(result_2, result_1).toString()); 18 | Assert.assertEquals("Success AND Unstable = Unstable", "UNSTABLE", Utils.applyLogicalAnd(result_1, result_2).toString()); 19 | Assert.assertEquals("Failure AND Success = Failure", "FAILURE", Utils.applyLogicalAnd(result_3, result_1).toString()); 20 | Assert.assertEquals("Success AND Failure = Failure", "FAILURE", Utils.applyLogicalAnd(result_1, result_3).toString()); 21 | Assert.assertEquals("Failure AND Unstable = Failure", "FAILURE", Utils.applyLogicalAnd(result_3, result_2).toString()); 22 | Assert.assertEquals("Unstable AND Failure = Failure", "FAILURE", Utils.applyLogicalAnd(result_2, result_3).toString()); 23 | Assert.assertEquals("Failure AND Failure = Failure", "FAILURE", Utils.applyLogicalAnd(result_3, result_3).toString()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/portlet/utils/UtilsHudsonTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.portlet.utils; 2 | 3 | import java.math.RoundingMode; 4 | import java.util.ArrayList; 5 | import java.util.Calendar; 6 | import java.util.List; 7 | 8 | import org.jvnet.hudson.test.HudsonTestCase; 9 | 10 | import hudson.model.FreeStyleProject; 11 | import hudson.model.Job; 12 | 13 | /** 14 | * Test {@link hudson.plugins.jacoco.portlet.utils.Utils} 15 | * through HudsonTestCase extension. 16 | * 17 | * @author Mauro Durante Junior <Mauro.Durantejunior@sonyericsson.com> 18 | */ 19 | public class UtilsHudsonTest extends HudsonTestCase { 20 | 21 | /** 22 | * Tests {@link hudson.plugins.jacoco.portlet.utils.Utils#getLastDate(java.util.List) }. 23 | * @throws Exception on any exception occurrence. 24 | */ 25 | public void testGetLastDate() throws Exception { 26 | 27 | FreeStyleProject prj = createFreeStyleProject("prj1"); 28 | prj.scheduleBuild2(0).get(); 29 | FreeStyleProject prj2 = createFreeStyleProject("prj2"); 30 | prj2.scheduleBuild2(0).get(); 31 | 32 | List> jobs = new ArrayList<>(); 33 | jobs.add(prj); 34 | jobs.add(prj2); 35 | 36 | Calendar lastDate = Utils.getLastDate(jobs); 37 | assertNotNull(lastDate); 38 | } 39 | 40 | /** 41 | * Tests {@link hudson.plugins.jacoco.portlet.utils.Utils#roundFloat(int scale, RoundingMode roundingMode, float value) }. 42 | */ 43 | public void testRoundFloat() { 44 | int scale = 1; 45 | RoundingMode roundingMode = RoundingMode.HALF_EVEN; 46 | final float value = 9.987f; 47 | final float roundedAs = 10f; 48 | 49 | assertEquals(roundedAs, Utils.roundFloat(scale, roundingMode, value)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/portlet/utils/UtilsParameterizedTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.portlet.utils; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collection; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.junit.runners.Parameterized; 8 | import org.junit.runners.Parameterized.Parameters; 9 | import static junit.framework.Assert.assertEquals; 10 | 11 | /** 12 | * Test {@link hudson.plugins.jacoco.portlet.utils.Utils} 13 | * through HudsonTestCase extension. 14 | * 15 | * @author Mauro Durante Junior <Mauro.Durantejunior@sonyericsson.com> 16 | * @author Eduardo Palazzo <Eduardo.Palazzo@sonyericsson.com> 17 | */ 18 | @RunWith(value = Parameterized.class) 19 | public class UtilsParameterizedTest { 20 | 21 | /** 22 | * The value input into the system. 23 | */ 24 | private String inputValue; 25 | 26 | /** 27 | * The expected returned value. 28 | */ 29 | private int expected; 30 | 31 | /** 32 | * The object containing the input and output parameters. 33 | * @return Collection<Object[]> a Collection containing pairs of 34 | * input values and the respective expected value 35 | * returned by the method under test. 36 | */ 37 | @Parameters 38 | public static Collection data() { 39 | final int expectedValue = 10; 40 | final int aValidValue = 1; 41 | Object[][] data = new Object[][] { 42 | {null, expectedValue}, 43 | {"", expectedValue}, 44 | {"0", expectedValue}, 45 | {"a", expectedValue}, 46 | {"-1", expectedValue}, 47 | {"1", aValidValue}, }; 48 | return Arrays.asList(data); 49 | } 50 | 51 | /** 52 | * Constructor to be used in this parameterized test. 53 | * @param inputValue the value input into the system 54 | * @param expected the expected returned value 55 | */ 56 | public UtilsParameterizedTest(String inputValue, int expected) { 57 | this.inputValue = inputValue; 58 | this.expected = expected; 59 | } 60 | 61 | /** 62 | * This method tests validateChartAttributes() behavior. 63 | * Tests {@link hudson.plugins.jacoco.portlet.utils.Utils#validateChartAttributes(java.lang.String, int) }. 64 | */ 65 | @Test 66 | public void testValidateCharAttributes() { 67 | assertEquals(expected, Utils.validateChartAttributes(inputValue, expected)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/report/AbstractReportTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import static org.junit.Assert.*; 4 | import hudson.model.TaskListener; 5 | import hudson.plugins.jacoco.ExecutionFileLoader; 6 | import hudson.plugins.jacoco.JacocoBuildAction; 7 | 8 | import hudson.util.StreamTaskListener; 9 | import org.junit.Test; 10 | 11 | 12 | public class AbstractReportTest { 13 | 14 | @Test 15 | public void test() throws Exception { 16 | AbstractReport report = new AbstractReport() { 17 | // abstract class but not abstract method to override 18 | }; 19 | assertNotNull(report); 20 | 21 | report.setParent(new ClassReport()); 22 | report.getParent().setParent(new PackageReport()); 23 | 24 | 25 | TaskListener taskListener = StreamTaskListener.fromStdout(); 26 | 27 | JacocoBuildAction action = new JacocoBuildAction(null, null, taskListener, null, null); 28 | report.getParent().getParent().setParent(new CoverageReport(action, new ExecutionFileLoader())); 29 | assertNull(report.getBuild()); 30 | 31 | assertNull(report.getName()); 32 | assertNull(report.getDisplayName()); 33 | report.setName("testname"); 34 | assertEquals("testname", report.getName()); 35 | assertEquals("testname", report.getDisplayName()); 36 | 37 | report.setName("myname/&:<>2%;"); 38 | assertEquals("myname/____2__", report.getName()); 39 | assertEquals("myname/____2__", report.getDisplayName()); 40 | 41 | // TODO: cause NPEs, did not find out how to test this without a full jenkins-test 42 | //assertNull(report.getPreviousResult()); 43 | //CoverageElement cv = new CoverageElement(); 44 | //report.addCoverage(cv); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/report/AggregatedReportTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | 8 | public class AggregatedReportTest { 9 | 10 | @Test 11 | public void testSetFailed() throws Exception { 12 | AggregatedReport report = new AggregatedReport() { 13 | }; 14 | 15 | assertEquals(0, report.getChildren().size()); 16 | assertFalse(report.hasChildren()); 17 | 18 | MethodReport child = new MethodReport(); 19 | child.setName("testmethod"); 20 | report.add(child); 21 | assertEquals(1, report.getChildren().size()); 22 | assertTrue(report.hasChildren()); 23 | assertFalse(report.hasChildrenClassCoverage()); 24 | assertFalse(report.hasChildrenLineCoverage()); 25 | 26 | report.setParent(new PackageReport()); 27 | assertNotNull(report.getParent()); 28 | 29 | assertNull(report.getDynamic("test", null, null)); 30 | assertNotNull(report.getDynamic("testmethod", null, null)); 31 | 32 | report.setFailed(); 33 | 34 | child.getLineCoverage().accumulate(0, 3); 35 | assertTrue(report.hasChildrenLineCoverage()); 36 | 37 | child.getClassCoverage().accumulate(0, 3); 38 | assertFalse("For method children it's always false", report.hasChildrenClassCoverage()); 39 | 40 | report.setName("myname/&:<>2%;"); 41 | assertEquals("myname/____2__", report.getName()); 42 | assertEquals("myname/____2__", report.getDisplayName()); 43 | } 44 | 45 | @Test 46 | public void testClassCoverage() { 47 | AggregatedReport packageReport = 48 | new AggregatedReport() { 49 | }; 50 | 51 | ClassReport classChild = new ClassReport(); 52 | classChild.setName("testclass"); 53 | packageReport.add(classChild); 54 | 55 | assertFalse(packageReport.hasChildrenClassCoverage()); 56 | assertFalse(packageReport.hasChildrenLineCoverage()); 57 | 58 | classChild.getClassCoverage().accumulate(0, 3); 59 | 60 | assertTrue(packageReport.hasChildrenClassCoverage()); 61 | assertFalse(packageReport.hasChildrenLineCoverage()); 62 | 63 | classChild = new ClassReport(); 64 | classChild.setName("testclass/pkg"); 65 | packageReport.add(classChild); 66 | assertEquals("testclass.pkg", classChild.getName()); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/report/ClassReportTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.io.File; 6 | import java.io.StringWriter; 7 | 8 | import org.junit.Test; 9 | 10 | 11 | public class ClassReportTest { 12 | 13 | @Test 14 | public void testName() { 15 | ClassReport report = new ClassReport(); 16 | report.setName("testname"); 17 | assertEquals("testname", report.getName()); 18 | report.setName("test/name/1"); 19 | assertEquals("test.name.1", report.getName()); 20 | 21 | report.setName("myname/&:<>2%;"); 22 | assertEquals("myname.____2__", report.getName()); 23 | assertEquals("myname.____2__", report.getDisplayName()); 24 | } 25 | 26 | @Test 27 | public void testChildren() { 28 | ClassReport report = new ClassReport(); 29 | 30 | assertEquals(0, report.getChildren().size()); 31 | MethodReport child = new MethodReport(); 32 | child.setName("testname"); 33 | report.add(child); 34 | assertEquals(1, report.getChildren().size()); 35 | } 36 | 37 | @Test 38 | public void testSourceFile() { 39 | ClassReport report = new ClassReport(); 40 | report.setSrcFileInfo(null, "some/path"); 41 | assertEquals(new File("some/path"), report.getSourceFilePath()); 42 | } 43 | 44 | @Test 45 | public void testPrint() { 46 | ClassReport report = new ClassReport(); 47 | report.setSrcFileInfo(null, "some/path"); 48 | 49 | StringWriter writer = new StringWriter(); 50 | report.printHighlightedSrcFile(writer); 51 | 52 | String string = writer.toString(); 53 | assertEquals("ERROR: Error while reading the sourcefile!", string); 54 | } 55 | 56 | @Test 57 | public void testToString() { 58 | ClassReport report = new ClassReport(); 59 | assertNotNull(report.toString()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/report/CoverageReportTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import static org.junit.Assert.*; 4 | import hudson.plugins.jacoco.ExecutionFileLoader; 5 | import hudson.plugins.jacoco.JacocoBuildAction; 6 | import hudson.plugins.jacoco.JacocoHealthReportThresholds; 7 | 8 | import hudson.util.StreamTaskListener; 9 | import org.junit.Test; 10 | 11 | 12 | public class CoverageReportTest { 13 | @Test 14 | public void testGetBuild() { 15 | CoverageReport report = new CoverageReport(action, new ExecutionFileLoader()); 16 | assertNull(report.getBuild()); 17 | } 18 | 19 | @Test 20 | public void testName() { 21 | CoverageReport report = new CoverageReport(action, new ExecutionFileLoader()); 22 | assertEquals("Jacoco", report.getName()); 23 | 24 | report.setName("myname/&:<>2%;"); 25 | assertEquals("myname/____2__", report.getName()); 26 | assertEquals("myname/____2__", report.getDisplayName()); 27 | } 28 | 29 | @Test 30 | public void testDoJaCoCoExec() { 31 | CoverageReport report = new CoverageReport(action, new ExecutionFileLoader()); 32 | assertNotNull(report); 33 | // TODO: how to simulate JaCoCoBuildAction without full Jenkins test-framework? 34 | // report.doJacocoExec(); 35 | } 36 | 37 | @Test 38 | public void testThresholds() { 39 | CoverageReport report = new CoverageReport(action, new ExecutionFileLoader()); 40 | report.setThresholds(new JacocoHealthReportThresholds()); 41 | } 42 | 43 | private JacocoBuildAction action = new JacocoBuildAction(null, null, StreamTaskListener.fromStdout(), null, null); 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/report/MethodReportTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.io.StringWriter; 6 | 7 | import org.junit.Test; 8 | 9 | 10 | public class MethodReportTest { 11 | @Test 12 | public void testMissingFile() { 13 | MethodReport report = new MethodReport(); 14 | assertFalse(report.hasClassCoverage()); 15 | 16 | report.setSrcFileInfo(null); 17 | 18 | ClassReport p = new ClassReport(); 19 | p.setSrcFileInfo(null, "some/path"); 20 | report.setParent(p); 21 | 22 | StringWriter writer = new StringWriter(); 23 | report.printHighlightedSrcFile(writer); 24 | String string = writer.toString(); 25 | assertEquals("ERROR: Error while reading the sourcefile!", string); 26 | 27 | report.setName("myname/&:<>2%;"); 28 | assertEquals("myname/____2__", report.getName()); 29 | assertEquals("myname/____2__", report.getDisplayName()); 30 | } 31 | 32 | @Test 33 | public void testPrint() { 34 | MethodReport report = new MethodReport(); 35 | assertNotNull(report.printFourCoverageColumns()); 36 | } 37 | 38 | @Test 39 | public void testChildren() { 40 | MethodReport report = new MethodReport(); 41 | report.setName("pkg"); 42 | 43 | assertEquals(0, report.getChildren().size()); 44 | SourceFileReport child = new SourceFileReport(); 45 | child.setName("testname"); 46 | report.add(child); 47 | assertEquals("testname", child.getName()); 48 | assertEquals(1, report.getChildren().size()); 49 | assertEquals("testname", report.getChildren().values().iterator().next().getName()); 50 | } 51 | 52 | @Test 53 | public void testChildrenRemovePkgName() { 54 | MethodReport report = new MethodReport(); 55 | report.setName("pkg"); 56 | 57 | assertEquals(0, report.getChildren().size()); 58 | SourceFileReport child = new SourceFileReport(); 59 | child.setName("pkg.testname"); 60 | report.add(child); 61 | assertEquals("testname", child.getName()); 62 | assertEquals(1, report.getChildren().size()); 63 | assertEquals("testname", report.getChildren().values().iterator().next().getName()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/report/PackageReportTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | 8 | public class PackageReportTest { 9 | 10 | @Test 11 | public void testName() { 12 | PackageReport report = new PackageReport(); 13 | 14 | report.setName(""); 15 | assertEquals("(default)", report.getName()); 16 | 17 | report.setName("testname"); 18 | assertEquals("testname", report.getName()); 19 | 20 | report.setName("test/name/1"); 21 | assertEquals("test.name.1", report.getName()); 22 | 23 | report.setName("myname/&:<>2%;"); 24 | assertEquals("myname.____2__", report.getName()); 25 | assertEquals("myname.____2__", report.getDisplayName()); 26 | } 27 | 28 | @Test 29 | public void testChildren() { 30 | PackageReport report = new PackageReport(); 31 | report.setName("pkg"); 32 | 33 | assertEquals(0, report.getChildren().size()); 34 | ClassReport child = new ClassReport(); 35 | child.setName("testname"); 36 | report.add(child); 37 | assertEquals("testname", child.getName()); 38 | assertEquals(1, report.getChildren().size()); 39 | assertEquals("testname", report.getChildren().values().iterator().next().getName()); 40 | } 41 | 42 | @Test 43 | public void testChildrenRemovePkgName() { 44 | PackageReport report = new PackageReport(); 45 | report.setName("pkg"); 46 | 47 | assertEquals(0, report.getChildren().size()); 48 | ClassReport child = new ClassReport(); 49 | child.setName("pkg.testname"); 50 | report.add(child); 51 | assertEquals("testname", child.getName()); 52 | assertEquals(1, report.getChildren().size()); 53 | assertEquals("testname", report.getChildren().values().iterator().next().getName()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/report/SourceAnnotatorTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.io.File; 6 | import java.io.PrintWriter; 7 | 8 | import org.apache.commons.io.output.ByteArrayOutputStream; 9 | import org.jacoco.core.analysis.ISourceNode; 10 | import org.jacoco.core.internal.analysis.CounterImpl; 11 | import org.jacoco.core.internal.analysis.SourceFileCoverageImpl; 12 | import org.jacoco.core.internal.analysis.SourceNodeImpl; 13 | import org.junit.Test; 14 | 15 | 16 | public class SourceAnnotatorTest { 17 | 18 | @Test 19 | public void testSourceAnnotatorSimple() throws Exception { 20 | File file = new File("src/test/java/hudson/plugins/jacoco/report/SourceAnnotatorTest.java"); 21 | assertTrue(file.exists()); 22 | SourceAnnotator annotator = new SourceAnnotator(file); 23 | 24 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 25 | try (PrintWriter writer = new PrintWriter(out)) { 26 | ISourceNode cov = new SourceFileCoverageImpl("testclass", "com.example.test"); 27 | annotator.printHighlightedSrcFile(cov, writer); 28 | } 29 | String string = new String(out.toByteArray()); 30 | assertTrue(string.contains("package hudson.plugins.jacoco.report")); 31 | assertTrue(string.contains("public void testSourceAnnotator()")); 32 | assertTrue(string.contains("")); 33 | } 34 | 35 | @Test 36 | public void testSourceAnnotator() throws Exception { 37 | File file = new File("src/test/java/hudson/plugins/jacoco/report/SourceAnnotatorTest.java"); 38 | assertTrue(file.exists()); 39 | SourceAnnotator annotator = new SourceAnnotator(file); 40 | 41 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 42 | try (PrintWriter writer = new PrintWriter(out)) { 43 | SourceNodeImpl cov = new SourceFileCoverageImpl("testclass", "com.example.test"); 44 | 45 | // set some coverage 46 | cov.increment(CounterImpl.getInstance(0, 1), CounterImpl.getInstance(1, 2), 21); 47 | cov.increment(CounterImpl.getInstance(0, 1), CounterImpl.getInstance(0, 4), 22); 48 | cov.increment(CounterImpl.getInstance(1, 0), CounterImpl.getInstance(3, 0), 23); 49 | 50 | annotator.printHighlightedSrcFile(cov, writer); 51 | } 52 | String string = new String(out.toByteArray()); 53 | assertTrue(string.contains("package hudson.plugins.jacoco.report")); 54 | assertTrue(string.contains("public void testSourceAnnotator()")); 55 | assertTrue(string, string.contains("")); 56 | 57 | // coverage data is also contained 58 | assertTrue(string, string.contains("21:•")); 59 | assertTrue(string, string.contains("22:•")); 60 | assertTrue(string, string.contains("23:•")); 61 | } 62 | 63 | @Test 64 | public void testMissingFile() throws Exception { 65 | File file = new File("notexisting"); 66 | assertFalse(file.exists()); 67 | SourceAnnotator annotator = new SourceAnnotator(file); 68 | 69 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 70 | try (PrintWriter writer = new PrintWriter(out)) { 71 | ISourceNode cov = new SourceFileCoverageImpl("testclass", "com.example.test"); 72 | annotator.printHighlightedSrcFile(cov, writer); 73 | } 74 | String string = new String(out.toByteArray()); 75 | assertEquals("ERROR: Error while reading the sourcefile!", string); 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacoco/report/SourceFileReportTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacoco.report; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | 8 | 9 | public class SourceFileReportTest { 10 | @Test 11 | public void test() { 12 | SourceFileReport report = new SourceFileReport(); 13 | report.setName("myname"); 14 | assertEquals("myname", report.getName()); 15 | report.setName("myname/2"); 16 | assertEquals("myname.2", report.getName()); 17 | report.setName("myname/&:<>2%;"); 18 | assertEquals("myname.____2__", report.getName()); 19 | assertEquals("myname.____2__", report.getDisplayName()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacococoveragecolumn/BranchCoverageColumnTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacococoveragecolumn; 2 | 3 | import hudson.model.Descriptor.FormException; 4 | import hudson.model.Job; 5 | import hudson.model.Run; 6 | import hudson.plugins.jacoco.JacocoBuildAction; 7 | import hudson.plugins.jacoco.model.Coverage; 8 | import hudson.plugins.jacoco.model.CoverageElement; 9 | import hudson.plugins.jacoco.model.CoverageElement.Type; 10 | import hudson.search.QuickSilver; 11 | import hudson.util.StreamTaskListener; 12 | import net.sf.json.JSONObject; 13 | import org.easymock.EasyMock; 14 | import org.junit.Before; 15 | import org.junit.Test; 16 | import org.kohsuke.stapler.export.Exported; 17 | 18 | import javax.servlet.ServletContext; 19 | import java.io.IOException; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | import java.util.SortedMap; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertNotNull; 26 | import org.kohsuke.stapler.StaplerRequest; 27 | 28 | public class BranchCoverageColumnTest { 29 | 30 | private BranchCoverageColumn sut; 31 | 32 | @Before 33 | public void setUp() { 34 | sut = new BranchCoverageColumn(); 35 | } 36 | 37 | @Test 38 | public void testGetPercentWithBuildAndAction() { 39 | ServletContext context = EasyMock.createNiceMock(ServletContext.class); 40 | 41 | EasyMock.replay(context); 42 | 43 | final Job mockJob = new MyJob("externaljob") { 44 | @SuppressWarnings("deprecation") // avoid TransientActionFactory 45 | @Override 46 | @Exported 47 | @QuickSilver 48 | public MyRun getLastSuccessfulBuild() { 49 | try { 50 | MyRun newBuild = newBuild(); 51 | Map ratios = new HashMap<>(); 52 | ratios.put(Type.BRANCH, new Coverage(100, 200)); 53 | newBuild.addAction(new JacocoBuildAction(ratios, null, StreamTaskListener.fromStdout(), null, null)); 54 | assertEquals(1, newBuild.getActions().size()); 55 | return newBuild; 56 | } catch (IOException e) { 57 | throw new IllegalStateException(e); 58 | } 59 | } 60 | 61 | @Override 62 | public int assignBuildNumber() throws IOException { 63 | return nextBuildNumber++; 64 | } 65 | }; 66 | assertEquals("66.67", sut.getPercent(mockJob)); 67 | 68 | EasyMock.verify(context); 69 | } 70 | 71 | @Test 72 | public void testDescriptor() throws FormException { 73 | assertNotNull(sut.getDescriptor()); 74 | assertNotNull(sut.getDescriptor().newInstance((StaplerRequest) null, JSONObject.fromObject("{\"key\":\"value\"}"))); 75 | assertNotNull(sut.getDescriptor().getDisplayName()); 76 | } 77 | 78 | private class MyJob extends Job { 79 | 80 | public MyJob(String name) { 81 | super(null, name); 82 | } 83 | 84 | @Override 85 | public boolean isBuildable() { 86 | return false; 87 | } 88 | 89 | @Override 90 | protected SortedMap _getRuns() { 91 | return null; 92 | } 93 | 94 | @Override 95 | protected void removeRun(MyRun run) { 96 | } 97 | 98 | protected synchronized MyRun newBuild() throws IOException { 99 | return new MyRun(this); 100 | } 101 | } 102 | 103 | private class MyRun extends Run { 104 | 105 | public MyRun(MyJob job) throws IOException { 106 | super(job); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacococoveragecolumn/CoverageRangeTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacococoveragecolumn; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.awt.Color; 6 | 7 | import org.junit.Test; 8 | 9 | public class CoverageRangeTest { 10 | 11 | @Test 12 | public void testAbyssmal() { 13 | assertEquals(CoverageRange.ABYSSMAL, CoverageRange.valueOf(-1d)); 14 | } 15 | 16 | @Test 17 | public void testFillColorOf87() throws Exception { 18 | final Color color = CoverageRange.fillColorOf(87d); 19 | assertEquals(177, color.getRed()); 20 | assertEquals(255, color.getGreen()); 21 | assertEquals(63, color.getBlue()); 22 | 23 | } 24 | 25 | @Test 26 | public void test() { 27 | expect(CoverageRange.ABYSSMAL, -20.0); 28 | expect(CoverageRange.ABYSSMAL, 0.0); 29 | expect(CoverageRange.ABYSSMAL, 10.3); 30 | expect(CoverageRange.TRAGIC, 25.0); 31 | expect(CoverageRange.TRAGIC, 32.0); 32 | expect(CoverageRange.POOR, 50.0); 33 | expect(CoverageRange.POOR, 68.2); 34 | expect(CoverageRange.FAIR, 75.0); 35 | expect(CoverageRange.FAIR, 83.0); 36 | expect(CoverageRange.SUFFICIENT, 85.0); 37 | expect(CoverageRange.SUFFICIENT, 91.0); 38 | expect(CoverageRange.GOOD, 92.0); 39 | expect(CoverageRange.GOOD, 96.999); 40 | expect(CoverageRange.EXCELLENT, 97.0); 41 | expect(CoverageRange.EXCELLENT, 97.1); 42 | expect(CoverageRange.PERFECT, 100.0); 43 | expect(CoverageRange.PERFECT, 230.0); 44 | } 45 | 46 | private void expect(CoverageRange result, double value) { 47 | assertEquals(result, CoverageRange.valueOf(value)); 48 | assertNotNull(CoverageRange.fillColorOf(value)); 49 | assertNotNull(result.getLineColor()); 50 | assertNotNull(result.getFillHexString()); 51 | assertNotNull(result.getLineHexString()); 52 | assertNotNull(CoverageRange.colorAsHexString(result.getLineColor())); 53 | assertTrue("Had " + value + " and floor " + result.getFloor(), 54 | value < 0 || // special handling for negative values, should not be passed in anyway 55 | value >= result.getFloor()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/jacococoveragecolumn/JaCoCoColumnTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.jacococoveragecolumn; 2 | 3 | import hudson.model.Descriptor.FormException; 4 | import hudson.model.Job; 5 | import hudson.model.Run; 6 | import hudson.plugins.jacoco.JacocoBuildAction; 7 | import hudson.plugins.jacoco.model.Coverage; 8 | import hudson.plugins.jacoco.model.CoverageElement.Type; 9 | import hudson.search.QuickSilver; 10 | import hudson.util.StreamTaskListener; 11 | import net.sf.json.JSONObject; 12 | 13 | import org.easymock.EasyMock; 14 | import org.junit.Before; 15 | import org.junit.Test; 16 | import org.kohsuke.stapler.export.Exported; 17 | 18 | import javax.servlet.ServletContext; 19 | import java.io.IOException; 20 | import java.math.BigDecimal; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | import java.util.SortedMap; 24 | 25 | import static org.junit.Assert.*; 26 | import org.kohsuke.stapler.StaplerRequest; 27 | 28 | public class JaCoCoColumnTest { 29 | private JaCoCoColumn jaCoCoColumn; 30 | 31 | @Before 32 | public void setUp() { 33 | jaCoCoColumn = new JaCoCoColumn(); 34 | } 35 | 36 | @Test 37 | public void testGetPercentWithBuildAndAction() { 38 | ServletContext context = EasyMock.createNiceMock(ServletContext.class); 39 | 40 | EasyMock.replay(context); 41 | 42 | final Job mockJob = new MyJob("externaljob") { 43 | @Override 44 | @Exported 45 | @QuickSilver 46 | @SuppressWarnings("deprecation") // avoid TransientActionFactory 47 | public MyRun getLastSuccessfulBuild() { 48 | try { 49 | MyRun newBuild = newBuild(); 50 | Map ratios = new HashMap<>(); 51 | ratios.put(Type.LINE, new Coverage(200, 100)); 52 | newBuild.addAction(new JacocoBuildAction(ratios, null, StreamTaskListener.fromStdout(), null, null)); 53 | assertEquals(1, newBuild.getActions().size()); 54 | return newBuild; 55 | } catch (IOException e) { 56 | throw new IllegalStateException(e); 57 | } 58 | } 59 | 60 | @Override 61 | public int assignBuildNumber() throws IOException { 62 | return nextBuildNumber++; 63 | } 64 | }; 65 | assertTrue(jaCoCoColumn.hasCoverage(mockJob)); 66 | assertEquals("33.33", jaCoCoColumn.getPercent(mockJob)); 67 | assertEquals(new BigDecimal("33.33"), jaCoCoColumn.getCoverage(mockJob)); 68 | 69 | EasyMock.verify(context); 70 | } 71 | 72 | @Test 73 | public void testDescriptor() throws FormException { 74 | assertNotNull(jaCoCoColumn.getDescriptor()); 75 | assertNotNull( 76 | jaCoCoColumn.getDescriptor().newInstance((StaplerRequest) null, JSONObject.fromObject("{\"key\":\"value\"}"))); 77 | assertNotNull(jaCoCoColumn.getDescriptor().getDisplayName()); 78 | } 79 | 80 | private class MyJob extends Job { 81 | 82 | public MyJob(String name) { 83 | super(null, name); 84 | } 85 | 86 | @Override 87 | public boolean isBuildable() { 88 | return false; 89 | } 90 | 91 | @Override 92 | protected SortedMap _getRuns() { 93 | return null; 94 | } 95 | 96 | @Override 97 | protected void removeRun(MyRun run) { 98 | } 99 | 100 | protected synchronized MyRun newBuild() throws IOException { 101 | return new MyRun(this); 102 | } 103 | } 104 | 105 | private class MyRun extends Run { 106 | 107 | public MyRun(MyJob job) throws IOException { 108 | super(job); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/test/resources/Font Monkey License.txt: -------------------------------------------------------------------------------- 1 | This font is copyright 2008 by P.D. Magnus. Like all the Fontmonkey fonts, it is free for for all commercial or non-commercial use. To be clear: They do not cost anything. 2 | 3 | If you do use them for something, though, I would love to here about it. I would appreciate a sample of the thing for which you used the font, a photo of it, or even just an e-mail telling me about it. 4 | 5 | You can contact me via the website or by e-mail at pmagnus@fecundity.com 6 | 7 | You are also encouraged to acknowledge fontmonkey or link to me, although neither is strictly speaking required. 8 | 9 | The font files may be freely distributed provided this license, attribution to me, and the fontmonkey URL are included. 10 | 11 | VERSION HISTORY 12 | 13 | 26apr2008 first release -------------------------------------------------------------------------------- /src/test/resources/baseStroke.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/baseStroke.png -------------------------------------------------------------------------------- /src/test/resources/baseStroke_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/baseStroke_2.png -------------------------------------------------------------------------------- /src/test/resources/baseStroke_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/baseStroke_3.png -------------------------------------------------------------------------------- /src/test/resources/belligerent.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/belligerent.ttf -------------------------------------------------------------------------------- /src/test/resources/crop100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/crop100.png -------------------------------------------------------------------------------- /src/test/resources/crop100_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/crop100_2.png -------------------------------------------------------------------------------- /src/test/resources/crop100_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/crop100_3.png -------------------------------------------------------------------------------- /src/test/resources/crop5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/crop5.png -------------------------------------------------------------------------------- /src/test/resources/crop5_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/crop5_2.png -------------------------------------------------------------------------------- /src/test/resources/crop5_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/crop5_3.png -------------------------------------------------------------------------------- /src/test/resources/multiple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/multiple.png -------------------------------------------------------------------------------- /src/test/resources/multiple_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/multiple_2.png -------------------------------------------------------------------------------- /src/test/resources/multiple_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/multiple_3.png -------------------------------------------------------------------------------- /src/test/resources/simple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/simple.png -------------------------------------------------------------------------------- /src/test/resources/simple_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/simple_2.png -------------------------------------------------------------------------------- /src/test/resources/simple_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/simple_3.png -------------------------------------------------------------------------------- /src/test/resources/singleBuild.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/singleBuild.png -------------------------------------------------------------------------------- /src/test/resources/singleBuild_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/singleBuild_2.png -------------------------------------------------------------------------------- /src/test/resources/singleBuild_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/singleBuild_3.png -------------------------------------------------------------------------------- /src/test/resources/skipzero.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/skipzero.png -------------------------------------------------------------------------------- /src/test/resources/skipzero_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/skipzero_2.png -------------------------------------------------------------------------------- /src/test/resources/skipzero_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/jacoco-plugin/0ba2c8d411a4b9badfd62d2fcdcdc70e8dc5216d/src/test/resources/skipzero_3.png --------------------------------------------------------------------------------