Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
232698d
Adds ignoreMissingReports flag
vasilejureschi Jan 26, 2023
38c0620
Switched from digester3 Apache to Jackson parser
vasilejureschi Jan 27, 2023
3b30f46
Adds backward compatibility
vasilejureschi Jan 27, 2023
9a9e7e1
Adds handling of numberOfTestsRun property
vasilejureschi Jan 27, 2023
f3487d8
Adds tests and cleans code
vasilejureschi Jul 16, 2023
e20269e
Update dependencies
unchiujar Jul 16, 2023
9377864
Merge remote-tracking branch 'jenkins/master'
unchiujar Jul 16, 2023
145d4b3
Updates all tests to use Junit5
unchiujar Jul 17, 2023
f137cd6
Add configuration option for ignoring missing reports
unchiujar Jul 17, 2023
2251667
Fixes bad checks for missing reports
unchiujar Jul 17, 2023
6538758
aider: Added unit tests for `FileProcessor.java`.
unchiujar Oct 14, 2023
f4ed2d0
Refactored test methods to have package-private access.
unchiujar Oct 14, 2023
c322163
aider: Change test methods in `FileProcessorTest.java` to throw a gen…
unchiujar Oct 14, 2023
79e22a8
Add MockitoExtension to FileProcessorTest and remove unused imports a…
unchiujar Oct 14, 2023
493f648
aider: Set up the `source` mock to return itself when `getParent()` i…
unchiujar Oct 14, 2023
8e0f961
Merge branch 'master' into JENKINS-68990
unchiujar Oct 15, 2023
d87a7c3
Ignores aider files
unchiujar Aug 19, 2024
4d97bc2
Merge remote-tracking branch 'jenkins/master'
unchiujar Aug 19, 2024
8f59fbe
Merge branch 'master' into JENKINS-68990
unchiujar Aug 19, 2024
b32bcb8
Reformat to match the original code indent
unchiujar Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ work
.vscode/

.DS_Store
.aider*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Configure report path, e.g. `target/pit-reports/**/mutations.xml` for a Maven bu
## Jenkins Pipeline
You can use the following step in pipeline to use this plugin in pipeline:

`pitmutation killRatioMustImprove: false, minimumKillRatio: 50.0, mutationStatsFile: '**/target/pit-reports/**/mutations.xml'`
`pitmutation ignoreMissingReports: false, killRatioMustImprove: false, minimumKillRatio: 50.0, mutationStatsFile: '**/target/pit-reports/**/mutations.xml'`

The plugin needs the XML and HTML output from PIT. Also make sure
that a clean target is executed before building, otherwise PIT will
Expand Down
61 changes: 41 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
</parent>

<artifactId>pitmutation</artifactId>
<version>1.0-19-SNAPSHOT</version>
<version>2.0.2</version>
<name>Jenkins PIT Mutation Plugin</name>
<packaging>hpi</packaging>
<url>http://wiki.jenkins-ci.org/display/JENKINS/pitmutation</url>

<scm>
<connection>scm:git:ssh://git@github.com/jenkinsci/pitmutation-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/jenkinsci/pitmutation-plugin.git</developerConnection>
<connection>scm:git:git://git@github.com/jenkinsci/pitmutation-plugin.git</connection>
<developerConnection>scm:git:git://git@github.com/jenkinsci/pitmutation-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/pitmutation-plugin</url>
<tag>HEAD</tag>
</scm>
Expand All @@ -37,6 +37,12 @@
<name>Benjamin Sproule</name>
<email>benjamin@benjaminsproule.com</email>
</developer>
<developer>
<id>vasilej</id>
<name>Vasile Jureschi</name>
<email>vasile.jureschi@gmail.com</email>
</developer>

</developers>

<repositories>
Expand All @@ -54,18 +60,26 @@
</pluginRepositories>

<dependencies>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.1</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.14.1</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-digester3</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>symbol-annotation</artifactId>
Expand All @@ -85,16 +99,16 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down Expand Up @@ -129,8 +143,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -141,7 +155,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>8</source>
<source>17</source>
</configuration>
</plugin>
<plugin>
Expand All @@ -164,6 +178,13 @@
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.16.1</version>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<configuration>
<targetClasses>
<param>org.jenkinsci.plugins.pitmutation.*</param>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.jenkinsci.plugins.pitmutation;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Publisher;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.StaplerRequest;

/**
* The type Descriptor.
*/
@Extension
@Symbol("pitmutation")
public class DescriptorImpl extends BuildStepDescriptor<Publisher> {

/**
* Instantiates a new Descriptor.
*/
public DescriptorImpl() {
super(PitPublisher.class);
}

@Override
public String getDisplayName() {
return Messages.PitPublisher_DisplayName();
}

@Override
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
return true;
}

/**
* {@inheritDoc}
*/
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
req.bindParameters(this, "pitmutation");
save();
return super.configure(req, formData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.jenkinsci.plugins.pitmutation;

import hudson.FilePath;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static java.util.Optional.ofNullable;

public class FileProcessor {

public static final String SINGLE_MODULE_REPORT_FOLDER = "mutation-report-all";
public static final String MULTI_MODULE_REPORT_FORMAT = "mutation-report-%s";

public void copySingleModuleReport(FilePath source, FilePath buildTarget) throws IOException, InterruptedException {
copyMutationReports(source, buildTarget, SINGLE_MODULE_REPORT_FOLDER);
}

public void copyMultiModuleReport(FilePath source, FilePath buildTarget, String module) throws IOException,
InterruptedException {
copyMutationReports(source, buildTarget, String.format(MULTI_MODULE_REPORT_FORMAT, module));
}

private void copyMutationReports(FilePath source, FilePath buildTarget, String mutationFilePath) throws IOException,
InterruptedException {
var targetPath = new FilePath(buildTarget, mutationFilePath);
var parent = ofNullable(source.getParent()).orElseThrow(() -> new IOException("Mutation file not found"));
parent.copyRecursiveTo(targetPath);
}

public Map<FilePath, String> getNames(FilePath[] reports, String base) {
Map<FilePath, String> names = new HashMap<>();
for (int i = 0; i < reports.length; i++) {
FilePath report = reports[i];

final String moduleName;
if (StringUtils.isBlank(base)) {
moduleName = String.valueOf(i == 0 ? null : i);
} else {
String[] partsFromRemoteWithoutBase = report.getRemote().replace(base, "").split("[/\\\\]");
if (partsFromRemoteWithoutBase.length > 1) {
moduleName = partsFromRemoteWithoutBase[1];
} else {
moduleName = String.valueOf(i == 0 ? null : i);
}
}

names.put(report, moduleName);
}
return names;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jenkinsci.plugins.pitmutation;

import hudson.model.Result;
import org.jenkinsci.plugins.pitmutation.targets.MutationStats;

import static hudson.model.Result.SUCCESS;
import static hudson.model.Result.UNSTABLE;

class MustImproveCondition implements Condition {
@Override
public Result decideResult(final PitBuildAction action) {
PitBuildAction previousAction = action.getPreviousAction();
if (previousAction != null) {
MutationStats previousStats = previousAction.getReport().getMutationStats();
return action.getReport().getMutationStats().getKillPercent() >= previousStats.getKillPercent() ?
SUCCESS :
UNSTABLE;
} else {
return SUCCESS;
}
}
}
30 changes: 26 additions & 4 deletions src/main/java/org/jenkinsci/plugins/pitmutation/Mutation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
* `
*
* @author edward
*/
@Data
Expand All @@ -12,19 +17,36 @@ public class Mutation {
private String sourceFile;
private String mutatedClass;
private String mutatedMethod;
private int numberOfTestsRun;
private int lineNumber;
private String mutator;
private int index;
/**
* @deprecated from 1 .9 the mutation library generates a list of indexes <a href="https://issues.jenkins.io/browse/JENKINS-68990">JENKINS-68990</a>
*/
@Deprecated(forRemoval = true, since = "1.9")
private Integer index;
private List<Integer> indexes = new ArrayList<>();
private String killingTest;
private String methodDescription;
private String description;
/**
* @deprecated from 1 .9 the mutation library generates a list of blocks <a href="https://issues.jenkins.io/browse/JENKINS-68990">JENKINS-68990</a>
*/
@Deprecated(forRemoval = true, since = "1.9")
private String block;
private List<String> blocks = new ArrayList<>();

public Mutation() {
}

public String getMutatorClass() {
int lastDot = mutator.lastIndexOf('.');
String className = mutator.substring(lastDot + 1);
return className.endsWith("Mutator")
? className.substring(0, className.length() - 7)
: className;
return className.endsWith("Mutator") ? className.substring(0, className.length() - 7) : className;
}

protected boolean canEqual(final Object other) {
return other instanceof Mutation;
}

}
Loading