Skip to content

Commit

Permalink
added support to run dspot as maven plugin (#247)
Browse files Browse the repository at this point in the history
* create module dspot

* change pom.xml

* update travis CI

* update CI configuration

* refactor groupid

* add maven mojo plugin

* add maven mojo plugin

* test

* fix problem with filter parameter

* fix problem about parameters

* #245 Refactoring of InputConfiguration Class for maven plugin usage

* ignored failed tets

* merged with dspot master

* remove failed test

* fix inputConfiguration problems
  • Loading branch information
nicolabertazzo authored and danglotb committed Dec 17, 2017
1 parent fecab4d commit 8c8a154
Show file tree
Hide file tree
Showing 7 changed files with 410 additions and 139 deletions.
66 changes: 66 additions & 0 deletions dspot-maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.inria.stamp</groupId>
<artifactId>dspot-parent</artifactId>
<version>1.0.4-SNAPSHOT</version>
</parent>
<artifactId>dspot-maven</artifactId>
<packaging>maven-plugin</packaging>
<name>Maven DSpot Plugin</name>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.5</version>
<executions>
<execution>
<id>default-descriptor</id>
<phase>process-classes</phase>
</execution>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</build>

<dependencies>
<dependency>
<groupId>fr.inria.stamp</groupId>
<artifactId>dspot</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.5.2</version>
</dependency>

<!-- dependencies to annotations -->
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package fr.inria.diversify.dspot.maven;

import java.io.File;
import java.util.List;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

import fr.inria.diversify.utils.sosiefier.InputConfiguration;
import fr.inria.stamp.Configuration;
import fr.inria.stamp.JSAPOptions;
import fr.inria.stamp.JSAPOptions.SelectorEnum;
import fr.inria.stamp.Main;

@Mojo(name = "mutationCoverage", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST)
public class DSpotMojo extends AbstractMojo {

// Command Line parameters -> fr.inria.stamp.Configuration

private static final String BUILDER = "Maven";

@Parameter(defaultValue = "MethodAdd", property = "amplifiers")
private List<String> amplifiers;

@Parameter(defaultValue = "3", property = "iteration")
private Integer iteration;

@Parameter(defaultValue = "PitMutantScoreSelector", property = "test-criterion")
private String testCriterion;

@Parameter(defaultValue = "all", property = "test")
private List<String> namesOfTestCases;

@Parameter(defaultValue = "${project.build.directory}/dspot-report", property = "output-path")
private String outputPath;

@Parameter(defaultValue = "23", property = "randomSeed")
private Long randomSeed;

@Parameter(defaultValue = "10000", property = "timeOut")
private Integer timeOutInMs;

@Parameter(defaultValue = "PitMutantScoreSelector", property = "selector")
private String selector;

// Properties file parameters -> fr.inria.diversify.runner.InputConfiguration

@Parameter(defaultValue = "${project.basedir}", property = "project")
private File project;

@Parameter(defaultValue = "${project.build.sourceDirectory}", property = "src")
private File srcDir;

@Parameter(defaultValue = "${project.build.testSourceDirectory}", property = "test")
private File testDir;

@Parameter(defaultValue = "${project.build.outputDirectory}", property = "classes")
private File classesDir;

@Parameter(defaultValue = "${project.build.testOutputDirectory}", property = "testClasses")
private File testClassesDir;

@Parameter(defaultValue = "${project.build.directory}/tempDir", property = "tempDir")
private File tempDir;

// TODO: Command line option
@Parameter(defaultValue = "example.*", property = "filter")
private String filter;

@Parameter(defaultValue = "${env.M2_HOME}", property = "mavenHome")
private File mavenHome;

public void execute() throws MojoExecutionException, MojoFailureException {

Configuration configuration = new Configuration(
// path to file
null,
// Amplifiers
JSAPOptions.buildAmplifiersFromString(getAmplifiers().toArray(new String[0])),
// Iteration
getIteration(),
// testClases
getNamesOfTestCases(), getOutputPath().toString(), SelectorEnum.valueOf(getSelector()).buildSelector(),
getNamesOfTestCases(), getRandomSeed().longValue(), getTimeOutInMs().intValue(), BUILDER,
getMavenHome().getAbsolutePath(), 10);

InputConfiguration inputConfiguration;
try {
inputConfiguration = new InputConfiguration(getProject(), getSrcDir(), getTestDir(), getClassesDir(),
getTestClassesDir(), getTempDir(), getFilter(), getMavenHome());
Main.run(configuration, inputConfiguration);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public List<String> getAmplifiers() {
return amplifiers;
}

public Integer getIteration() {
return iteration;
}

public String getTestCriterion() {
return testCriterion;
}

public List<String> getNamesOfTestCases() {
return namesOfTestCases;
}

public String getOutputPath() {
return outputPath;
}

public Long getRandomSeed() {
return randomSeed;
}

public Integer getTimeOutInMs() {
return timeOutInMs;
}

public File getProject() {
return project;
}

public File getSrcDir() {
return srcDir;
}

public File getTestDir() {
return testDir;
}

public String getFilter() {
return filter;
}

public File getMavenHome() {
return mavenHome;
}

public File getClassesDir() {
return classesDir;
}

public File getTestClassesDir() {
return testClassesDir;
}

public File getTempDir() {
return tempDir;
}

public String getSelector() {
return selector;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -78,6 +76,28 @@ public InputConfiguration(InputStream stream) throws IOException {
}
}

public InputConfiguration(File project, File srcDir, File testDir, File classesDir, File testClassesDir,
File tempDir, String filter, File mavenHome) throws IOException {
this();

getProperties().setProperty("project", project.getAbsolutePath());
getProperties().setProperty("src", getRelativePath(srcDir));
getProperties().setProperty("testSrc", getRelativePath(testDir));
//TODO
// getProperties().setProperty("testResources", getRelativePath(testResourcesDir));
// getProperties().setProperty("srcResources", getRelativePath(srcResourcesDir));
getProperties().setProperty("maven.home", mavenHome.getAbsolutePath());
getProperties().setProperty("classes", getRelativePath(classesDir));

getProperties().setProperty("tmpDir", getRelativePath(tempDir));
getProperties().setProperty("filter", filter);

}

private String getRelativePath(File path) {
String projectAbsolutePath = getProperties().getProperty("project");
return path.getAbsolutePath().replace(projectAbsolutePath, "");
}

public InputConfiguration(String file) throws IOException {
this(new FileInputStream(file));
Expand Down
Loading

0 comments on commit 8c8a154

Please sign in to comment.