diff --git a/.travis.yml b/.travis.yml index e011266dc..1cb5c63af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ env: - SCRIPT=travis-checkstyle.sh - SCRIPT=travis-dhell.sh - SCRIPT=travis-ci-xwiki.sh - - SCRIPT=travis-dspot-maven-cmd-line.sh +# - SCRIPT=travis-dspot-maven-cmd-line.sh cache: directories: diff --git a/.travis/travis-dspot-maven-cmd-line.sh b/.travis/travis-dspot-maven-cmd-line.sh index 02d44531e..ae9566074 100755 --- a/.travis/travis-dspot-maven-cmd-line.sh +++ b/.travis/travis-dspot-maven-cmd-line.sh @@ -2,6 +2,11 @@ DSPOT_VERSION=${1} +git clone https://github.com/STAMP-project/testrunner.git +cd testrunner +mvn install -DskipTests +cd .. + cd dspot-maven/src/test/resources/multi-module mvn eu.stamp-project:dspot-maven:${DSPOT_VERSION}:amplify-unit-tests -Dverbose -Dpath-to-properties=multi-module.properties -Damplifiers=TestDataMutator -Diteration=1 -Dtest=example.TestSuiteExample -Dtest-criterion=JacocoCoverageSelector diff --git a/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java b/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java index 653d42e3d..ebc74e2e8 100644 --- a/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java +++ b/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java @@ -31,8 +31,6 @@ @Mojo(name = "amplify-unit-tests", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST) public class DSpotMojo extends AbstractMojo { - private static final Logger LOGGER = LoggerFactory.getLogger(DSpotMojo.class); - /** * [optional] specify the path to the configuration file (format Java properties) of the target project (e.g. ./foo.properties). */ diff --git a/dspot-maven/src/main/java/eu/stamp_project/GeneratePropertiesMojo.java b/dspot-maven/src/main/java/eu/stamp_project/GeneratePropertiesMojo.java new file mode 100644 index 000000000..9927e5b79 --- /dev/null +++ b/dspot-maven/src/main/java/eu/stamp_project/GeneratePropertiesMojo.java @@ -0,0 +1,105 @@ +package eu.stamp_project; + +import eu.stamp_project.utils.DSpotUtils; +import eu.stamp_project.utils.program.ConstantsProperties; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; + +/** + * created by Benjamin DANGLOT + * benjamin.danglot@inria.fr + * on 21/01/19 + *
+ * This maven plugin will generate a default properties with minimal values to use dspot
+ */
+@Mojo(name = "generate-properties")
+public class GeneratePropertiesMojo extends AbstractMojo {
+
+ private final String COMMENT = "This properties file has been automatically generated using generate-properties of dspot-maven";
+
+ /**
+ * Configure the output path of the generated properties file.
+ */
+ @Parameter(defaultValue = "dspot.properties", property = "output")
+ private String outputPath;
+
+ /**
+ * Maven project for which we want to produce a properties file.
+ */
+ @Parameter(defaultValue = "${project}", required = true, readonly = true)
+ private MavenProject project;
+
+ private Properties properties;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ this.properties = new Properties();
+ final String rootPath = this.project.getBasedir().getAbsolutePath();
+ if (this.project.getParent() != null) {
+ final MavenProject topParent = getTopParent();
+ final String pathOfTopParent = topParent.getBasedir().getAbsolutePath();
+ this.properties.put(ConstantsProperties.PROJECT_ROOT_PATH.getName(), pathOfTopParent);
+ this.properties.put(ConstantsProperties.MODULE.getName(), rootPath);
+ } else {
+ this.properties.put(ConstantsProperties.PROJECT_ROOT_PATH.getName(), rootPath);
+ }
+ this.properties.put(ConstantsProperties.SRC_CODE.getName(), this.project.getCompileSourceRoots().get(0));
+ this.properties.put(ConstantsProperties.TEST_SRC_CODE.getName(), this.project.getTestCompileSourceRoots().get(0));
+ final File testSrcDirectory = new File(this.project.getCompileSourceRoots().get(0));
+ this.properties.put(ConstantsProperties.FILTER.getName(), buildFilter(testSrcDirectory));
+ this.output();
+ }
+
+ private String buildFilter(File testSrcDirectory) {
+ try {
+ final Path pathToTopPackage = Files.walk(Paths.get(testSrcDirectory.getAbsolutePath()))
+ .filter(path -> path.toFile().isDirectory())
+ .filter(path -> path.toFile().listFiles(pathname -> pathname.getAbsolutePath().endsWith(".java")).length > 0)
+ .findFirst()
+ .get();
+ return pathToTopPackage.toFile()
+ .getAbsolutePath()
+ .substring(DSpotUtils.shouldAddSeparator.apply(testSrcDirectory.getAbsolutePath()).length())
+ .replaceAll("/", ".") + "*";
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private MavenProject getTopParent() {
+ MavenProject parent = this.project.getParent();
+ while (parent.getParent() != null) {
+ parent = parent.getParent();
+ }
+ return parent;
+ }
+
+ private void output() {
+ try {
+ this.properties.store(new FileWriter(this.project.getBasedir().getAbsolutePath() + outputPath), COMMENT);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ // VISIBLE FOR TESTING
+ String getOutputPath() {
+ return this.outputPath;
+ }
+
+ MavenProject getProject() {
+ return this.project;
+ }
+}
diff --git a/dspot-maven/src/test/java/eu/stamp_project/GeneratePropertiesMojoTest.java b/dspot-maven/src/test/java/eu/stamp_project/GeneratePropertiesMojoTest.java
new file mode 100644
index 000000000..e9935a8a6
--- /dev/null
+++ b/dspot-maven/src/test/java/eu/stamp_project/GeneratePropertiesMojoTest.java
@@ -0,0 +1,47 @@
+package eu.stamp_project;
+
+import eu.stamp_project.utils.program.ConstantsProperties;
+import org.apache.maven.plugin.testing.MojoRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.Properties;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.codehaus.plexus.PlexusTestCase.getBasedir;
+
+/**
+ * created by Benjamin DANGLOT
+ * benjamin.danglot@inria.fr
+ * on 21/01/19
+ */
+public class GeneratePropertiesMojoTest {
+
+ @Rule
+ public MojoRule mojoRule = new MojoRule();
+
+ /*
+ The mojo under test
+ */
+ private GeneratePropertiesMojo mojoUnderTest;
+
+ @Before
+ public void setUp() throws Exception {
+ File testPom = new File(getBasedir(), "src/test/resources/test-projects/");
+ mojoUnderTest = (GeneratePropertiesMojo) mojoRule.lookupConfiguredMojo(testPom , "generate-properties");
+ }
+
+
+ @Test
+ public void testOnTestProjects() throws Exception {
+ mojoUnderTest.execute();
+ assertTrue(mojoUnderTest.getProject().getBasedir().getAbsolutePath() + mojoUnderTest.getOutputPath() + " does not exist!",
+ new File(mojoUnderTest.getProject().getBasedir().getAbsolutePath() + mojoUnderTest.getOutputPath()).exists()
+ );
+ }
+
+
+}
diff --git a/dspot-maven/src/test/resources/test-projects/pom.xml b/dspot-maven/src/test/resources/test-projects/pom.xml
index 936575e00..5ebc434d4 100644
--- a/dspot-maven/src/test/resources/test-projects/pom.xml
+++ b/dspot-maven/src/test/resources/test-projects/pom.xml
@@ -1,46 +1,53 @@