From c2cce431a3cb41044b160f28940e8b6f23ced5a2 Mon Sep 17 00:00:00 2001 From: danglotb Date: Tue, 28 May 2019 17:17:19 +0200 Subject: [PATCH 01/19] feat: add setup methods to set all the values that come from the command line --- .../main/java/eu/stamp_project/DSpotMojo.java | 63 +++++++++---------- .../utils/options/JSAPOptions.java | 33 ++++------ .../utils/program/InputConfiguration.java | 36 +++++++++++ 3 files changed, 76 insertions(+), 56 deletions(-) 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 8468c67fa..5d29a3086 100644 --- a/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java +++ b/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java @@ -252,28 +252,22 @@ public void execute() { .collect(Collectors.toList()); } try { - InputConfiguration.initialize(properties) - .setAmplifiers(AmplifierEnum.buildAmplifiersFromString(new ArrayList<>(this.amplifiers))) - .setNbIteration(this.iteration) - .setTestClasses(this.test) - .setBudgetizer(BudgetizerEnum.valueOf(this.budgetizer)) - .setTestCases(this.cases) - .setSeed(this.randomSeed) - .setTimeOutInMs(this.timeOut) - .setBuilderName(this.automaticBuilder) - .setMaxTestAmplified(this.maxTestAmplified) - .setClean(this.clean) - .setMinimize(this.noMinimize) - .setVerbose(this.verbose) - .setUseWorkingDirectory(this.workingDirectory) - .setWithComment(this.withComment) - .setDescartesMode(this.descartes) - .setGenerateAmplifiedTestClass(this.generateNewTestClass) - .setKeepOriginalTestMethods(this.keepOriginalTestMethods) - .setUseMavenToExecuteTest(this.useMavenToExeTest) - .setTargetOneTestClass(this.targetOneTestClass) - .setAllowPathInAssertion(this.allowPathInAssertions); + InputConfiguration.initialize(properties); + + InputConfiguration.setUp( + this.amplifiers, this.budgetizer, + SelectorEnum.valueOf(this.testCriterion).buildSelector(), this.test, + this.cases, this.iteration, + this.randomSeed, this.timeOut, + this.maxTestAmplified, this.clean, + this.verbose, this.workingDirectory, + this.withComment, this.generateNewTestClass, + this.keepOriginalTestMethods, false, + this.descartes, this.useMavenToExeTest, + this.targetOneTestClass, this.allowPathInAssertions + ); + InputConfiguration.get().setOutputDirectory( ConstantsProperties.OUTPUT_DIRECTORY.get(properties).isEmpty() ? this.outputPath : ConstantsProperties.OUTPUT_DIRECTORY.get(properties)); @@ -321,26 +315,25 @@ public void execute() { @NotNull Properties initializeProperties() { Properties properties = new Properties(); + properties.setProperty(ConstantsProperties.PROJECT_ROOT_PATH.getName(), project.getBasedir().getAbsolutePath()); + final Build build = project.getBuild(); + properties.setProperty(ConstantsProperties.SRC_CODE.getName(), build.getSourceDirectory()); + properties.setProperty(ConstantsProperties.TEST_SRC_CODE.getName(), build.getTestSourceDirectory()); + properties.setProperty(ConstantsProperties.SRC_CLASSES.getName(), build.getOutputDirectory()); + properties.setProperty(ConstantsProperties.TEST_CLASSES.getName(), build.getTestOutputDirectory()); + // TODO checks that we can use an empty module for multi module project + // TODO the guess here is that the user will launch the plugin from the root of the targeted module + // TODO and thus, we do not need to compute the relative path from its parents + // TODO however, it may lacks some dependencies and the user should run a resolve dependency goal + // TODO before using the dspot plugin + // TODO we must maybe need to use a correct lifecycle + properties.setProperty(ConstantsProperties.MODULE.getName(), ""); if (this.pathToProperties != null && !this.pathToProperties.isEmpty()) { try { properties.load(new FileInputStream(this.pathToProperties)); } catch (IOException e) { e.printStackTrace(); } - } else { - properties.setProperty(ConstantsProperties.PROJECT_ROOT_PATH.getName(), project.getBasedir().getAbsolutePath()); - final Build build = project.getBuild(); - properties.setProperty(ConstantsProperties.SRC_CODE.getName(), build.getSourceDirectory()); - properties.setProperty(ConstantsProperties.TEST_SRC_CODE.getName(), build.getTestSourceDirectory()); - properties.setProperty(ConstantsProperties.SRC_CLASSES.getName(), build.getOutputDirectory()); - properties.setProperty(ConstantsProperties.TEST_CLASSES.getName(), build.getTestOutputDirectory()); - // TODO checks that we can use an empty module for multi module project - // TODO the guess here is that the user will launch the plugin from the root of the targeted module - // TODO and thus, we do not need to compute the relative path from its parents - // TODO however, it may lacks some dependencies and the user should run a resolve dependency goal - // TODO before using the dspot plugin - // TODO we must maybe need to use a correct lifecycle - properties.setProperty(ConstantsProperties.MODULE.getName(), ""); } return properties; } diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java index f777ca02b..411bb454f 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java @@ -123,27 +123,18 @@ public static boolean parse(String[] args) { // we check now the binaries folders after the compilation Checker.checkBinariesFolders(properties); - InputConfiguration.get() - .setAmplifiers(AmplifierEnum.buildAmplifiersFromString(amplifiers)) - .setNbIteration(jsapConfig.getInt("iteration")) - .setTestClasses(testClasses) - .setSelector(testCriterion) - .setTestCases(testCases) - .setSeed(jsapConfig.getLong("seed")) - .setTimeOutInMs(jsapConfig.getInt("timeOut")) - .setMaxTestAmplified(jsapConfig.getInt("maxTestAmplified")) - .setBudgetizer(BudgetizerEnum.valueOf(budgetizer)) - .setClean(jsapConfig.getBoolean("clean")) - .setMinimize(!jsapConfig.getBoolean("no-minimize")) - .setVerbose(jsapConfig.getBoolean("verbose")) - .setUseWorkingDirectory(jsapConfig.getBoolean("working-directory")) - .setWithComment(jsapConfig.getBoolean("comment")) - .setGenerateAmplifiedTestClass(jsapConfig.getBoolean("generate-new-test-class")) - .setKeepOriginalTestMethods(jsapConfig.getBoolean("keep-original-test-methods")) - .setDescartesMode(jsapConfig.getBoolean("descartes") && !jsapConfig.getBoolean("gregor")) - .setUseMavenToExecuteTest(jsapConfig.getBoolean("use-maven-to-exe-test")) - .setTargetOneTestClass(jsapConfig.getBoolean("targetOneTestClass")) - .setAllowPathInAssertion(jsapConfig.getBoolean("allow-path-in-assertions")); + InputConfiguration.setUp( + amplifiers, budgetizer, + testCriterion, testClasses, + testCases, jsapConfig.getInt("iteration"), + jsapConfig.getLong("seed"), jsapConfig.getInt("timeOut"), + jsapConfig.getInt("maxTestAmplified"), jsapConfig.getBoolean("clean"), + jsapConfig.getBoolean("verbose"), jsapConfig.getBoolean("working-directory"), + jsapConfig.getBoolean("comment"), jsapConfig.getBoolean("generate-new-test-class"), + jsapConfig.getBoolean("keep-original-test-methods"), jsapConfig.getBoolean("gregor"), + jsapConfig.getBoolean("descartes"), jsapConfig.getBoolean("use-maven-to-exe-test"), + jsapConfig.getBoolean("targetOneTestClass"), jsapConfig.getBoolean("allow-path-in-assertions") + ); return false; } diff --git a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java index b0df768ae..d55d830a3 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java +++ b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java @@ -7,6 +7,7 @@ import eu.stamp_project.dspot.selector.PitMutantScoreSelector; import eu.stamp_project.dspot.selector.TestSelector; import eu.stamp_project.utils.DSpotCache; +import eu.stamp_project.utils.options.AmplifierEnum; import eu.stamp_project.utils.options.BudgetizerEnum; import eu.stamp_project.testrunner.EntryPoint; import eu.stamp_project.utils.AmplificationHelper; @@ -305,6 +306,41 @@ private InputConfiguration(String pathToProjectRoot, // then it will take the command line value (default: false) } + /** + + */ + public static void setUp(List amplifiers, String budgetizer, + TestSelector testCriterion, List testClasses, + List testCases, int iteration, + long seed, int timeOut, + int maxTestAmplified, boolean clean, + boolean verbose, boolean workingDirectory, + boolean comment, boolean generateNewTestClass, + boolean keepOriginalTestMethods, boolean gregor, + boolean descartes, boolean useMavenToExecuteTest, + boolean targetOneTestClass, boolean allowPathInAssertion) { + InputConfiguration.get() + .setAmplifiers(AmplifierEnum.buildAmplifiersFromString(amplifiers)) + .setNbIteration(iteration) + .setTestClasses(testClasses) + .setSelector(testCriterion) + .setTestCases(testCases) + .setSeed(seed) + .setTimeOutInMs(timeOut) + .setMaxTestAmplified(maxTestAmplified) + .setBudgetizer(BudgetizerEnum.valueOf(budgetizer)) + .setClean(clean) + .setVerbose(verbose) + .setUseWorkingDirectory(workingDirectory) + .setWithComment(comment) + .setGenerateAmplifiedTestClass(generateNewTestClass) + .setKeepOriginalTestMethods(keepOriginalTestMethods) + .setDescartesMode(descartes && !gregor) + .setUseMavenToExecuteTest(useMavenToExecuteTest) + .setTargetOneTestClass(targetOneTestClass) + .setAllowPathInAssertion(allowPathInAssertion); + } + /* Paths project properties */ From bc7d07f90811307834869fd5764234ced82e1e3f Mon Sep 17 00:00:00 2001 From: danglotb Date: Tue, 28 May 2019 17:26:47 +0200 Subject: [PATCH 02/19] refactor: no more use of camel case in options --- .../main/java/eu/stamp_project/DSpotMojo.java | 118 ++++++++++-------- .../utils/options/JSAPOptions.java | 30 ++--- 2 files changed, 84 insertions(+), 64 deletions(-) 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 5d29a3086..b67df2260 100644 --- a/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java +++ b/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java @@ -30,42 +30,56 @@ public class DSpotMojo extends AbstractMojo { /** - * [optional] specify the path to the configuration file (format Java properties) of the target project (e.g. ./foo.properties). + * [mandatory] specify the path to the configuration file (format Java properties) of the target project (e.g. ./foo.properties). */ - @Parameter(property = "path-to-properties", defaultValue = "") + @Parameter(property = "path-to-properties") private String pathToProperties; /** - * [optional] specify the list of amplifiers to use. Default with all available amplifiers. - * - StringLiteralAmplifier - * - NumberLiteralAmplifier - * - CharLiteralAmplifier - * - BooleanLiteralAmplifier - * - AllLiteralAmplifiers - * - MethodAdd - * - MethodRemove - * - TestDataMutator (deprecated) - * - MethodGeneratorAmplifier - * - ReturnValueAmplifier - * - ReplacementAmplifier - * - NullifierAmplifier - * - None + * [optional] specify the list of amplifiers to use. By default, DSpot does not use any amplifiers (None) and applies only assertion amplification. + * Possible values are: + * - MethodAdd + * - MethodRemove + * - TestDataMutator + * - MethodGeneratorAmplifier + * - ReturnValueAmplifier + * - StringLiteralAmplifier + * - NumberLiteralAmplifier + * - BooleanLiteralAmplifier + * - CharLiteralAmplifier + * - AllLiteralAmplifiers + * - NullifierAmplifier + * - None */ @Parameter(defaultValue = "None", property = "amplifiers") private List amplifiers; /** - * [optional] specify the number of amplification iterations. A larger number may help to improve the test criterion (e.g. a larger number of iterations may help to kill more mutants). This has an impact on the execution time: the more iterations, the longer DSpot runs. + * [optional] specify the number of amplification iterations. A larger number may help to improve the test criterion (e.g. a larger number of iterations may help to kill more mutants). This has an impact on the execution time: the more iterations, the longer DSpot runs. */ @Parameter(defaultValue = "3", property = "iteration") private Integer iteration; /** - * [optional] specify the test adequacy criterion to be maximized with amplification + * [optional] specify the test adequacy criterion to be maximized with amplification. + * Possible values are: + * - PitMutantScoreSelector + * - JacocoCoverageSelector + * - TakeAllSelector + * - ChangeDetectorSelector */ @Parameter(defaultValue = "PitMutantScoreSelector", property = "test-criterion") private String testCriterion; + /** + * [optional] specify the Pit output format. + * Possible values are: + * - XML + * - CSV + */ + @Parameter(defaultValue = "XML", property = "pit-output-format") + private String pitOutputFormat; + /** * [optional] specify a Bugdetizer. * Possible values are: @@ -77,118 +91,124 @@ public class DSpotMojo extends AbstractMojo { private String budgetizer; /** - * [optional] specify the maximum number of amplified tests that dspot keeps (before generating assertion) + * [optional] specify the maximum number of amplified tests that dspot keeps (before generating assertion) */ @Parameter(defaultValue = "200", property = "max-test-amplified") private Integer maxTestAmplified; /** - * [optional] fully qualified names of test classes to be amplified. If the value is all, DSpot will amplify the whole test suite. You can also use regex to describe a set of test classes. By default, DSpot selects all the tests (value all). + * [optional] fully qualified names of test classes to be amplified. If the value is all, DSpot will amplify the whole test suite. You can also use regex to describe a set of test classes. By default, DSpot selects all the tests (value all). */ @Parameter(defaultValue = "all", property = "test") private List test; /** - * specify the test cases to amplify + * specify the test cases to amplify */ - @Parameter(property = "cases") - private List cases; + @Parameter(property = "test-cases") + private List testCases; /** - * [optional] specify the output folder + * [optional] specify the output folder */ @Parameter(defaultValue = "target/dspot/output", property = "output-path") private String outputPath; /** - * [optional] if enabled, DSpot will remove the out directory if exists, else it will append the results to the exist files. (default: off) + * [optional] if enabled, DSpot will remove the out directory if exists, else it will append the results to the exist files. */ @Parameter(defaultValue = "false", property = "clean") private Boolean clean; /** - * [optional, expert mode] specify the path to the .csv of the original result of Pit Test. If you use this option the selector will be forced to PitMutantScoreSelector + * [optional, expert mode] specify the path to the .xml or .csv of the original result of Pit Test. If you use this option the selector will be forced to PitMutantScoreSelector */ @Parameter(property = "path-pit-result") private String pathPitResult; /** - * [optional, expert] enable this option will make DSpot computing the mutation score of only one test class (the first pass through --test command line option) + * [optional, expert] enable this option will make DSpot computing the mutation score of only one test class (the first pass through --test command line option) */ - @Parameter(defaultValue = "false", property = "targetOneTestClass") + @Parameter(defaultValue = "false", property = "target-one-test-class") private Boolean targetOneTestClass; /** - * Enable the descartes engine for Pit Mutant Score Selector. + * Enable the descartes engine for Pit Mutant Score Selector. */ @Parameter(defaultValue = "true", property = "descartes") private Boolean descartes; /** - * [optional] specify the automatic builder to build the project + * Enable the gregor engine for Pit Mutant Score Selector. */ - @Parameter(defaultValue = "MavenBuilder", property = "automatic-builder") + @Parameter(defaultValue = "false", property = "gregor") + private Boolean gregor; + + /** + * [optional] specify the automatic builder to build the project + */ + @Parameter(defaultValue = "", property = "automatic-builder") private String automaticBuilder; /** - * specify the path to the maven home + * specify the path to the maven home */ @Parameter(property = "maven-home") private String mavenHome; /** - * specify a seed for the random object (used for all randomized operation) + * specify a seed for the random object (used for all randomized operation) */ - @Parameter(defaultValue = "23", property = "randomSeed") + @Parameter(defaultValue = "23", property = "random-seed") private Long randomSeed; /** - * specify the timeout value of the degenerated tests in millisecond + * specify the timeout value of the degenerated tests in millisecond */ - @Parameter(defaultValue = "10000", property = "timeOut") + @Parameter(defaultValue = "10000", property = "time-out") private Integer timeOut; /** - * Enable verbose mode of DSpot. + * Enable verbose mode of DSpot. */ @Parameter(defaultValue = "false", property = "verbose") private Boolean verbose; /** - * Enable comment on amplified test: details steps of the Amplification. + * Enable comment on amplified test: details steps of the Amplification. */ @Parameter(defaultValue = "false", property = "with-comment") private Boolean withComment; /** - * Disable the minimization of amplified tests. + * Disable the minimization of amplified tests. */ @Parameter(defaultValue = "false", property = "no-minimize") private Boolean noMinimize; /** - * Enable this option to change working directory with the root of the project. + * Enable this option to change working directory with the root of the project. */ @Parameter(defaultValue = "false", property = "working-directory") private Boolean workingDirectory; /** - * Enable the creation of a new test class. + * Enable the creation of a new test class. */ @Parameter(defaultValue = "false", property = "generate-new-test-class") private Boolean generateNewTestClass; /** - * If enabled, DSpot keeps original test methods of the amplified test class. + * If enabled, DSpot keeps original test methods of the amplified test class. */ @Parameter(defaultValue = "false", property = "keep-original-test-methods") private Boolean keepOriginalTestMethods; /** - * If enabled, DSpot will use maven to execute the tests. + * If enabled, DSpot will use maven to execute the tests. */ @Parameter(defaultValue = "false", property = "use-maven-to-exe-test") - private Boolean useMavenToExeTest = false; + private Boolean useMavenToExeTest; /** * If enabled, DSpot will generate assertions for values that seems like to be paths. @@ -197,13 +217,13 @@ public class DSpotMojo extends AbstractMojo { private Boolean allowPathInAssertions; /** - * run the example of DSpot and leave + * run the example of DSpot and leave */ @Parameter(defaultValue = "false", property = "example") private Boolean example; /** - * show this help + * show this help */ @Parameter(defaultValue = "false", property = "help") private Boolean help; @@ -258,7 +278,7 @@ public void execute() { InputConfiguration.setUp( this.amplifiers, this.budgetizer, SelectorEnum.valueOf(this.testCriterion).buildSelector(), this.test, - this.cases, this.iteration, + this.testCases, this.iteration, this.randomSeed, this.timeOut, this.maxTestAmplified, this.clean, this.verbose, this.workingDirectory, @@ -267,7 +287,7 @@ public void execute() { this.descartes, this.useMavenToExeTest, this.targetOneTestClass, this.allowPathInAssertions ); - + InputConfiguration.get().setOutputDirectory( ConstantsProperties.OUTPUT_DIRECTORY.get(properties).isEmpty() ? this.outputPath : ConstantsProperties.OUTPUT_DIRECTORY.get(properties)); @@ -362,7 +382,7 @@ void setTestClassesNames(List test) { } void setTestMethods(List cases) { - this.cases = cases; + this.testCases = cases; } void setVerbose(Boolean verbose) { diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java index 411bb454f..154aa1a39 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java @@ -127,13 +127,13 @@ public static boolean parse(String[] args) { amplifiers, budgetizer, testCriterion, testClasses, testCases, jsapConfig.getInt("iteration"), - jsapConfig.getLong("seed"), jsapConfig.getInt("timeOut"), - jsapConfig.getInt("maxTestAmplified"), jsapConfig.getBoolean("clean"), + jsapConfig.getLong("random-seed"), jsapConfig.getInt("time-out"), + jsapConfig.getInt("max-test-amplified"), jsapConfig.getBoolean("clean"), jsapConfig.getBoolean("verbose"), jsapConfig.getBoolean("working-directory"), jsapConfig.getBoolean("comment"), jsapConfig.getBoolean("generate-new-test-class"), jsapConfig.getBoolean("keep-original-test-methods"), jsapConfig.getBoolean("gregor"), jsapConfig.getBoolean("descartes"), jsapConfig.getBoolean("use-maven-to-exe-test"), - jsapConfig.getBoolean("targetOneTestClass"), jsapConfig.getBoolean("allow-path-in-assertions") + jsapConfig.getBoolean("target-one-test-class"), jsapConfig.getBoolean("allow-path-in-assertions") ); return false; } @@ -241,42 +241,42 @@ private static JSAP initJSAP() { mutantScore.setUsageName("./path/to/mutations.csv"); mutantScore.setHelp("[optional, expert mode] specify the path to the .xml or .csv of the original result of Pit Test. If you use this option the selector will be forced to PitMutantScoreSelector"); - Switch targetOneTestClass = new Switch("targetOneTestClass"); - targetOneTestClass.setLongFlag("targetOneTestClass"); + Switch targetOneTestClass = new Switch("target-one-test-class"); + targetOneTestClass.setLongFlag("target-one-test-class"); targetOneTestClass.setHelp("[optional, expert] enable this option will make DSpot computing the mutation score of only one test class (the first pass through --test command line option)"); targetOneTestClass.setDefault("false"); - FlaggedOption testCases = new FlaggedOption("testCases"); + FlaggedOption testCases = new FlaggedOption("test-cases"); testCases.setList(true); testCases.setAllowMultipleDeclarations(false); - testCases.setLongFlag("cases"); + testCases.setLongFlag("test-cases"); testCases.setShortFlag('c'); testCases.setStringParser(JSAP.STRING_PARSER); testCases.setHelp("specify the test cases to amplify"); - FlaggedOption seed = new FlaggedOption("seed"); + FlaggedOption seed = new FlaggedOption("random-seed"); seed.setStringParser(JSAP.LONG_PARSER); - seed.setLongFlag("randomSeed"); + seed.setLongFlag("random-seed"); seed.setUsageName("long integer"); seed.setHelp("specify a seed for the random object (used for all randomized operation)"); seed.setDefault("23"); - FlaggedOption timeOut = new FlaggedOption("timeOut"); + FlaggedOption timeOut = new FlaggedOption("time-out"); timeOut.setStringParser(JSAP.INTEGER_PARSER); - timeOut.setLongFlag("timeOut"); + timeOut.setLongFlag("time-out"); timeOut.setUsageName("long integer"); timeOut.setHelp("specify the timeout value of the degenerated tests in millisecond"); timeOut.setDefault("10000"); - FlaggedOption automaticBuilder = new FlaggedOption("builder"); + FlaggedOption automaticBuilder = new FlaggedOption("automatic-builder"); automaticBuilder.setStringParser(JSAP.STRING_PARSER); automaticBuilder.setLongFlag("automatic-builder"); automaticBuilder.setUsageName("MavenBuilder | GradleBuilder"); automaticBuilder.setHelp("[optional] specify the automatic builder to build the project"); automaticBuilder.setDefault(""); - FlaggedOption mavenHome = new FlaggedOption("mavenHome"); + FlaggedOption mavenHome = new FlaggedOption("maven-home"); mavenHome.setStringParser(JSAP.STRING_PARSER); mavenHome.setLongFlag("maven-home"); mavenHome.setUsageName("path to maven home"); @@ -287,7 +287,7 @@ private static JSAP initJSAP() { verbose.setDefault("false"); verbose.setHelp("Enable verbose mode of DSpot."); - FlaggedOption maxTestAmplified = new FlaggedOption("maxTestAmplified"); + FlaggedOption maxTestAmplified = new FlaggedOption("max-test-amplified"); maxTestAmplified.setStringParser(JSAP.INTEGER_PARSER); maxTestAmplified.setLongFlag("max-test-amplified"); maxTestAmplified.setUsageName("integer"); @@ -301,7 +301,7 @@ private static JSAP initJSAP() { budgetizer.setHelp("[optional] specify a Bugdetizer." + JSAPOptions.helpForEnums(BudgetizerEnum.class)); budgetizer.setDefault("RandomBudgetizer"); - Switch withComment = new Switch("comment"); + Switch withComment = new Switch("with-comment"); withComment.setLongFlag("with-comment"); withComment.setDefault("false"); withComment.setHelp("Enable comment on amplified test: details steps of the Amplification."); From e05ea091ddd8bb18c7954cb37673f8a51f8ceb8d Mon Sep 17 00:00:00 2001 From: danglotb Date: Tue, 28 May 2019 22:33:40 +0200 Subject: [PATCH 03/19] refactor: all the configuration in done now in one place --- .../main/java/eu/stamp_project/DSpotMojo.java | 65 +++--- .../utils/options/Configuration.java | 201 ++++++++++++++++++ .../utils/options/JSAPOptions.java | 127 +++++------ .../utils/options/check/Checker.java | 34 ++- .../utils/program/InputConfiguration.java | 19 +- 5 files changed, 311 insertions(+), 135 deletions(-) create mode 100644 dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java 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 b67df2260..f22205b3c 100644 --- a/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java +++ b/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java @@ -1,12 +1,8 @@ package eu.stamp_project; -import eu.stamp_project.dspot.selector.PitMutantScoreSelector; import eu.stamp_project.utils.AmplificationHelper; import eu.stamp_project.utils.DSpotUtils; -import eu.stamp_project.utils.options.AmplifierEnum; -import eu.stamp_project.utils.options.BudgetizerEnum; -import eu.stamp_project.utils.options.JSAPOptions; -import eu.stamp_project.utils.options.SelectorEnum; +import eu.stamp_project.utils.options.*; import eu.stamp_project.utils.program.ConstantsProperties; import eu.stamp_project.utils.program.InputConfiguration; import org.apache.commons.io.FilenameUtils; @@ -20,7 +16,6 @@ import org.jetbrains.annotations.NotNull; import java.io.*; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Properties; @@ -266,6 +261,7 @@ public void execute() { return; } } + if (this.amplifiers.size() == 1 && this.amplifiers.get(0).contains(AmplificationHelper.PATH_SEPARATOR)) { this.amplifiers = Arrays.stream(this.amplifiers.get(0).split(AmplificationHelper.PATH_SEPARATOR)) @@ -273,39 +269,34 @@ public void execute() { } try { - InputConfiguration.initialize(properties); - - InputConfiguration.setUp( - this.amplifiers, this.budgetizer, - SelectorEnum.valueOf(this.testCriterion).buildSelector(), this.test, - this.testCases, this.iteration, - this.randomSeed, this.timeOut, - this.maxTestAmplified, this.clean, - this.verbose, this.workingDirectory, - this.withComment, this.generateNewTestClass, - this.keepOriginalTestMethods, false, - this.descartes, this.useMavenToExeTest, - this.targetOneTestClass, this.allowPathInAssertions + Configuration.configure( + properties, + this.amplifiers, + this.testCriterion, + this.budgetizer, + this.pitOutputFormat, + this.pathPitResult, + this.AUTOMATIC_BUILDER_NAME, + this.outputPath, + this.iteration, + this.randomSeed, + this.timeOut, + this.maxTestAmplified, + this.clean, + this.verbose, + this.workingDirectory, + this.withComment, + this.generateNewTestClass, + this.keepOriginalTestMethods, + this.gregor, + this.descartes, + this.useMavenToExeTest, + this.targetOneTestClass, + this.allowPathInAssertions, + this.test, + this.testCases ); - InputConfiguration.get().setOutputDirectory( - ConstantsProperties.OUTPUT_DIRECTORY.get(properties).isEmpty() ? - this.outputPath : ConstantsProperties.OUTPUT_DIRECTORY.get(properties)); - - if (this.pathPitResult != null && !this.pathPitResult.isEmpty()) { - InputConfiguration.get().setSelector(new PitMutantScoreSelector(this.pathPitResult, - this.pathPitResult.endsWith(".xml") ? - PitMutantScoreSelector.OutputFormat.XML : PitMutantScoreSelector.OutputFormat.CSV, - PitMutantScoreSelector.OutputFormat.XML) - ); - } else { - InputConfiguration.get().setSelector(SelectorEnum.valueOf(this.testCriterion).buildSelector()); - } - - if (!this.pathToSecondVersion.isEmpty()) { - InputConfiguration.get().setAbsolutePathToSecondVersionProjectRoot(this.pathToSecondVersion); - } - if (!this.pathToTestListCsv.isEmpty()) { // clear both list of test classes and test cases InputConfiguration.get().getTestCases().clear(); diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java b/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java new file mode 100644 index 000000000..908b0a16b --- /dev/null +++ b/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java @@ -0,0 +1,201 @@ +package eu.stamp_project.utils.options; + +import eu.stamp_project.dspot.selector.PitMutantScoreSelector; +import eu.stamp_project.dspot.selector.TestSelector; +import eu.stamp_project.utils.options.check.Checker; +import eu.stamp_project.utils.program.InputConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; +import java.util.Properties; + +/** + * Created by Benjamin DANGLOT + * benjamin.danglot@inria.fr + * on 28/05/19 + */ +public class Configuration { + + private static final Logger LOGGER = LoggerFactory.getLogger(Configuration.class); + + public static void configure(final String pathToPropertiesFile, + final List amplifiers, + final String selector, + final String budgetizer, + final String pitOutputFormat, + final String pathPitResult, + final String builder, + final String output, + final int iteration, + final long randomSeed, + final int timeOut, + final int maxTestAmplified, + final boolean clean, + final boolean verbose, + final boolean workingDirectory, + final boolean comment, + final boolean generateNewTestClass, + final boolean keepOriginalTestMethods, + final boolean gregor, + final boolean descartes, + final boolean useMavenToExecuteTest, + final boolean targetOneTestClass, + final boolean allowPathInAssertion, + final List testClasses, + final List testCases) { + + Checker.checkPathToPropertiesValue(pathToPropertiesFile); + final Properties properties = loadProperties(pathToPropertiesFile); + configure( + properties, + amplifiers, + selector, + budgetizer, + pitOutputFormat, + pathPitResult, + builder, + output, + iteration, + randomSeed, + timeOut, + maxTestAmplified, + clean, + verbose, + workingDirectory, + comment, + generateNewTestClass, + keepOriginalTestMethods, + gregor, + descartes, + useMavenToExecuteTest, + targetOneTestClass, + allowPathInAssertion, + testClasses, + testCases + ); + } + + public static void configure(Properties properties, + final List amplifiers, + final String selector, + final String budgetizer, + final String pitOutputFormat, + final String pathPitResult, + final String builder, + final String output, + final int iteration, + final long randomSeed, + final int timeOut, + final int maxTestAmplified, + final boolean clean, + final boolean verbose, + final boolean workingDirectory, + final boolean comment, + final boolean generateNewTestClass, + final boolean keepOriginalTestMethods, + final boolean gregor, + final boolean descartes, + final boolean useMavenToExecuteTest, + final boolean targetOneTestClass, + final boolean allowPathInAssertion, + final List testClasses, + final List testCases) { + // pit output format + PitMutantScoreSelector.OutputFormat consecutiveFormat; + if (pitOutputFormat.toLowerCase().equals("xml")) { + consecutiveFormat = PitMutantScoreSelector.OutputFormat.XML; + } else if (pitOutputFormat.toLowerCase().equals("csv")) { + consecutiveFormat = PitMutantScoreSelector.OutputFormat.CSV; + } else { + LOGGER.warn("You specified an invalid format. Forcing the Pit output format to XML."); + consecutiveFormat = PitMutantScoreSelector.OutputFormat.XML; + } + + // expert test selector mode + TestSelector testCriterion; + if (pathPitResult != null) { + if (!"PitMutantScoreSelector".equals(selector)) { + LOGGER.warn("You specified a path to a mutations file but you did not specify the right test-criterion"); + LOGGER.warn("Forcing the Selector to PitMutantScoreSelector"); + } + PitMutantScoreSelector.OutputFormat originalFormat; + if (pathPitResult.toLowerCase().endsWith(".xml")) { + originalFormat = PitMutantScoreSelector.OutputFormat.XML; + } else if (pathPitResult.toLowerCase().endsWith(".csv")) { + originalFormat = PitMutantScoreSelector.OutputFormat.CSV; + } else { + LOGGER.warn("You specified the wrong Pit format. Skipping expert mode."); + originalFormat = PitMutantScoreSelector.OutputFormat.XML; + } + testCriterion = new PitMutantScoreSelector(pathPitResult, originalFormat, consecutiveFormat); + + // default test selector mode + } else { + if (!(pitOutputFormat == null)) { + if (!"PitMutantScoreSelector".equals(selector)) { + LOGGER.warn("You specified an output format but you did not specify the right test-criterion"); + LOGGER.warn("Forcing the Selector to PitMutantScoreSelector"); + } + testCriterion = new PitMutantScoreSelector(consecutiveFormat); + } else { + testCriterion = SelectorEnum.valueOf(selector).buildSelector(); + } + } + + Checker.preChecking( + amplifiers, + selector, + budgetizer, + properties + ); + + InputConfiguration.initialize(properties, builder); + if (InputConfiguration.get().getOutputDirectory().isEmpty()) { + + InputConfiguration.get().setOutputDirectory(output); + } + + Checker.postChecking(properties); + + InputConfiguration.setUp( + amplifiers, + budgetizer, + testCriterion, + testClasses, + testCases, + iteration, + randomSeed, + timeOut, + maxTestAmplified, + clean, + verbose, + workingDirectory, + comment, + generateNewTestClass, + keepOriginalTestMethods, + gregor, + descartes, + useMavenToExecuteTest, + targetOneTestClass, + allowPathInAssertion + ); + } + + public static Properties loadProperties(String pathToPropertiesFile) { + try { + Properties properties = new Properties(); + if (pathToPropertiesFile == null || "".equals(pathToPropertiesFile)) { + LOGGER.warn("You did not specify any path for the properties file. Using only default values."); + } else { + properties.load(new FileInputStream(pathToPropertiesFile)); + } + return properties; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java index 154aa1a39..f9bdf048b 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java @@ -12,6 +12,7 @@ import eu.stamp_project.utils.options.check.Checker; import eu.stamp_project.utils.program.InputConfiguration; import eu.stamp_project.utils.AmplificationHelper; +import jdk.internal.org.objectweb.asm.util.CheckClassAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,60 +51,30 @@ public static boolean parse(String[] args) { return true; } - // checking path to properties - Checker.checkPathToPropertiesValue(jsapConfig); - - // checking enum values + // getting first all the values of the command line. + final String pathToPropertiesFile = jsapConfig.getString("path-to-properties"); final List amplifiers = new ArrayList<>(Arrays.asList(jsapConfig.getStringArray("amplifiers"))); final String selector = jsapConfig.getString("test-criterion"); final String budgetizer = jsapConfig.getString("budgetizer"); - Checker.checkEnum(AmplifierEnum.class, amplifiers, "amplifiers"); - Checker.checkEnum(SelectorEnum.class, selector, "test-criterion"); - Checker.checkEnum(BudgetizerEnum.class, budgetizer, "budgetizer"); - - // pit output format - PitMutantScoreSelector.OutputFormat consecutiveFormat; - if (jsapConfig.getString("pit-output-format").toLowerCase().equals("xml")) { - consecutiveFormat = PitMutantScoreSelector.OutputFormat.XML; - } else if (jsapConfig.getString("pit-output-format").toLowerCase().equals("csv")) { - consecutiveFormat = PitMutantScoreSelector.OutputFormat.CSV; - } else { - LOGGER.warn("You specified an invalid format. Forcing the Pit output format to XML."); - consecutiveFormat = PitMutantScoreSelector.OutputFormat.XML; - } - - // expert test selector mode - TestSelector testCriterion; - if (jsapConfig.getString("mutant") != null) { - if (!"PitMutantScoreSelector".equals(jsapConfig.getString("test-criterion"))) { - LOGGER.warn("You specified a path to a mutations file but you did not specify the right test-criterion"); - LOGGER.warn("Forcing the Selector to PitMutantScoreSelector"); - } - String pathToOriginalResultOfPit = jsapConfig.getString("mutant"); - PitMutantScoreSelector.OutputFormat originalFormat; - if (pathToOriginalResultOfPit.toLowerCase().endsWith(".xml")) { - originalFormat = PitMutantScoreSelector.OutputFormat.XML; - } else if (pathToOriginalResultOfPit.toLowerCase().endsWith(".csv")) { - originalFormat = PitMutantScoreSelector.OutputFormat.CSV; - } else { - LOGGER.warn("You specified the wrong Pit format. Skipping expert mode."); - originalFormat = PitMutantScoreSelector.OutputFormat.XML; - } - testCriterion = new PitMutantScoreSelector(jsapConfig.getString("mutant"), originalFormat, consecutiveFormat); - - // default test selector mode - } else { - if (!(jsapConfig.getString("output-format") == null)) { - if (!"PitMutantScoreSelector".equals(jsapConfig.getString("test-criterion"))) { - LOGGER.warn("You specified an output format but you did not specify the right test-criterion"); - LOGGER.warn("Forcing the Selector to PitMutantScoreSelector"); - } - testCriterion = new PitMutantScoreSelector(consecutiveFormat); - } else { - testCriterion = SelectorEnum.valueOf(jsapConfig.getString("test-criterion")).buildSelector(); - } - } - + final String pitOutputFormat = jsapConfig.getString("pit-output-format"); + final String pathPitResult = jsapConfig.getString("path-pit-result"); + final String builder = jsapConfig.getString("builder"); + final String output = jsapConfig.getString("output"); + final int iteration = jsapConfig.getInt("iteration"); + final long randomSeed = jsapConfig.getLong("random-seed"); + final int timeOut = jsapConfig.getInt("time-out"); + final int maxTestAmplified = jsapConfig.getInt("max-test-amplified"); + final boolean clean = jsapConfig.getBoolean("clean"); + final boolean verbose = jsapConfig.getBoolean("verbose"); + final boolean workingDirectory = jsapConfig.getBoolean("working-directory"); + final boolean comment = jsapConfig.getBoolean("comment"); + final boolean generateNewTestClass = jsapConfig.getBoolean("generate-new-test-class"); + final boolean keepOriginalTestMethods = jsapConfig.getBoolean("keep-original-test-methods"); + final boolean gregor = jsapConfig.getBoolean("gregor"); + final boolean descartes = jsapConfig.getBoolean("descartes"); + final boolean useMavenToExecuteTest = jsapConfig.getBoolean("use-maven-to-exe-test"); + final boolean targetOneTestClass = jsapConfig.getBoolean("target-one-test-class"); + final boolean allowPathInAssertion = jsapConfig.getBoolean("allow-path-in-assertions"); // these values need to be checked when the factory is available // We check them in DSpot class since we have the codes that allow to check them easily // and thus, the Factory will be created. @@ -111,30 +82,34 @@ public static boolean parse(String[] args) { final List testClasses = Arrays.asList(jsapConfig.getStringArray("test")); final List testCases = Arrays.asList(jsapConfig.getStringArray("testCases")); - // we check the properties before initializing the InputConfiguration. - final Properties properties = InputConfiguration.loadProperties(jsapConfig.getString("path-to-properties")); - Checker.checkProperties(properties); - - InputConfiguration.initialize(properties, jsapConfig.getString("builder")); - if (InputConfiguration.get().getOutputDirectory().isEmpty()) { - InputConfiguration.get().setOutputDirectory(jsapConfig.getString("output")); - } - - // we check now the binaries folders after the compilation - Checker.checkBinariesFolders(properties); - - InputConfiguration.setUp( - amplifiers, budgetizer, - testCriterion, testClasses, - testCases, jsapConfig.getInt("iteration"), - jsapConfig.getLong("random-seed"), jsapConfig.getInt("time-out"), - jsapConfig.getInt("max-test-amplified"), jsapConfig.getBoolean("clean"), - jsapConfig.getBoolean("verbose"), jsapConfig.getBoolean("working-directory"), - jsapConfig.getBoolean("comment"), jsapConfig.getBoolean("generate-new-test-class"), - jsapConfig.getBoolean("keep-original-test-methods"), jsapConfig.getBoolean("gregor"), - jsapConfig.getBoolean("descartes"), jsapConfig.getBoolean("use-maven-to-exe-test"), - jsapConfig.getBoolean("target-one-test-class"), jsapConfig.getBoolean("allow-path-in-assertions") + Configuration.configure( + pathToPropertiesFile, + amplifiers, + selector, + budgetizer, + pitOutputFormat, + pathPitResult, + builder, + output, + iteration, + randomSeed, + timeOut, + maxTestAmplified, + clean, + verbose, + workingDirectory, + comment, + generateNewTestClass, + keepOriginalTestMethods, + gregor, + descartes, + useMavenToExecuteTest, + targetOneTestClass, + allowPathInAssertion, + testClasses, + testCases ); + return false; } @@ -220,7 +195,7 @@ private static JSAP initJSAP() { specificTestClass.setUsageName("my.package.MyClassTest | all"); specificTestClass.setHelp("[optional] fully qualified names of test classes to be amplified. If the value is all, DSpot will amplify the whole test suite. You can also use regex to describe a set of test classes. By default, DSpot selects all the tests (value all)."); - FlaggedOption output = new FlaggedOption("output"); + FlaggedOption output = new FlaggedOption("output-path"); output.setStringParser(JSAP.STRING_PARSER); output.setAllowMultipleDeclarations(false); output.setShortFlag('o'); @@ -233,7 +208,7 @@ private static JSAP initJSAP() { cleanOutput.setDefault("false"); cleanOutput.setHelp("[optional] if enabled, DSpot will remove the out directory if exists, else it will append the results to the exist files."); - FlaggedOption mutantScore = new FlaggedOption("mutant"); + FlaggedOption mutantScore = new FlaggedOption("path-pit-result"); mutantScore.setStringParser(JSAP.STRING_PARSER); mutantScore.setAllowMultipleDeclarations(false); mutantScore.setShortFlag('m'); diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/check/Checker.java b/dspot/src/main/java/eu/stamp_project/utils/options/check/Checker.java index 439f913ce..4db96ade2 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/check/Checker.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/check/Checker.java @@ -1,9 +1,11 @@ package eu.stamp_project.utils.options.check; -import com.martiansoftware.jsap.JSAPResult; import eu.stamp_project.Main; import eu.stamp_project.utils.AmplificationHelper; import eu.stamp_project.utils.DSpotUtils; +import eu.stamp_project.utils.options.AmplifierEnum; +import eu.stamp_project.utils.options.BudgetizerEnum; +import eu.stamp_project.utils.options.SelectorEnum; import eu.stamp_project.utils.program.ConstantsProperties; import eu.stamp_project.utils.report.error.Error; import eu.stamp_project.utils.report.error.ErrorEnum; @@ -29,6 +31,26 @@ public class Checker { private static final Logger LOGGER = LoggerFactory.getLogger(Checker.class); + /* + Checking algo + */ + + public static void preChecking(List amplifiers, + String selector, + String budgetizer, + Properties properties) { + Checker.checkEnum(AmplifierEnum.class, amplifiers, "amplifiers"); + Checker.checkEnum(SelectorEnum.class, selector, "test-criterion"); + Checker.checkEnum(BudgetizerEnum.class, budgetizer, "budgetizer"); + Checker.checkProperties(properties); + } + + public static void postChecking(Properties properties) { + // we check now the binaries folders after the compilation + Checker.checkBinariesFolders(properties); + } + + /* PROPERTIES CHECK */ @@ -103,7 +125,7 @@ public static void checkProperties(Properties properties) { } // TODO check JVM args and System args checkJVMArgs(ConstantsProperties.JVM_ARGS.get(properties)); // no checks since it is a soft checks - Checker.checkProperties(ConstantsProperties.SYSTEM_PROPERTIES.get(properties)); + checkSystemProperties(ConstantsProperties.SYSTEM_PROPERTIES.get(properties)); } // TODO must be enhanced. @@ -112,7 +134,7 @@ public static void checkProperties(Properties properties) { I'll restrict the check to jvmArgs=-Xmx2048m,-Xms1024m,-Dis.admin.user=admin,-Dis.admin.passwd=$2pRSid#, i.e increase the memory and gives some property By soft checks, I mean that DSpot won't throw errors (like others checks) but will display a warning. - Same for checkProperties + Same for checkSystemProperties */ public static boolean checkJVMArgs(String jvmArgs) { final String[] jvmArgsArrays = jvmArgs.split(","); @@ -134,7 +156,7 @@ public static boolean checkJVMArgs(String jvmArgs) { return isOkayGlobal; } - public static boolean checkProperties(String systemProperties) { + public static boolean checkSystemProperties(String systemProperties) { return true; } @@ -163,9 +185,9 @@ private static void checkRelativePathPropertyValue(final String propertyValue, /* PROPERTIES PATH FILE CHECK */ - public static void checkPathToPropertiesValue(JSAPResult jsapConfig) { + public static void checkPathToPropertiesValue(String pathToPropertiesFile) { Checker.checkPathnameNotNullAndFileExist( - jsapConfig.getString("path-to-properties"), + pathToPropertiesFile, ErrorEnum.ERROR_PATH_TO_PROPERTIES, "You did not provide the path to your properties file, which is mandatory.", "The provided path to the properties file is incorrect, the properties file does not exist." diff --git a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java index d55d830a3..a47e550e9 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java +++ b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java @@ -12,6 +12,7 @@ import eu.stamp_project.testrunner.EntryPoint; import eu.stamp_project.utils.AmplificationHelper; import eu.stamp_project.utils.DSpotUtils; +import eu.stamp_project.utils.options.Configuration; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,20 +46,6 @@ public class InputConfiguration { private static final Logger LOGGER = LoggerFactory.getLogger(InputConfiguration.class); - public static Properties loadProperties(String pathToPropertiesFile) { - try { - Properties properties = new Properties(); - if (pathToPropertiesFile == null || "".equals(pathToPropertiesFile)) { - LOGGER.warn("You did not specify any path for the properties file. Using only default values."); - } else { - properties.load(new FileInputStream(pathToPropertiesFile)); - } - return properties; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - public static InputConfiguration get() { return InputConfiguration.instance; } @@ -74,7 +61,7 @@ public static InputConfiguration get() { * @return the new instance of the InputConfiguration */ public static InputConfiguration initialize(String pathToPropertiesFile) { - InputConfiguration.initialize(loadProperties(pathToPropertiesFile)); + InputConfiguration.initialize(Configuration.loadProperties(pathToPropertiesFile)); InputConfiguration.instance.configPath = pathToPropertiesFile; return InputConfiguration.instance; } @@ -91,7 +78,7 @@ public static InputConfiguration initialize(String pathToPropertiesFile) { * @return the new instance of the InputConfiguration */ public static InputConfiguration initialize(String pathToPropertiesFile, String builderName) { - InputConfiguration.initialize(loadProperties(pathToPropertiesFile), builderName); + InputConfiguration.initialize(Configuration.loadProperties(pathToPropertiesFile), builderName); InputConfiguration.instance.configPath = pathToPropertiesFile; return InputConfiguration.instance; } From 2eb6ba5436586be35dd90d83ded216b8619595ec Mon Sep 17 00:00:00 2001 From: danglotb Date: Tue, 28 May 2019 22:39:27 +0200 Subject: [PATCH 04/19] refactor: the example is now done as a normal configuration to avoid redundant code --- .../main/java/eu/stamp_project/DSpotMojo.java | 3 --- .../src/main/java/eu/stamp_project/Main.java | 22 ++----------------- .../utils/options/Configuration.java | 18 +++++++++++++++ .../utils/options/JSAPOptions.java | 8 +++---- 4 files changed, 23 insertions(+), 28 deletions(-) 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 f22205b3c..d385cbb6b 100644 --- a/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java +++ b/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java @@ -317,9 +317,6 @@ public void execute() { } catch (Exception e) { throw new RuntimeException(e); } - // global report handling - Main.GLOBAL_REPORT.output(); - Main.GLOBAL_REPORT.reset(); } // visible for testing... diff --git a/dspot/src/main/java/eu/stamp_project/Main.java b/dspot/src/main/java/eu/stamp_project/Main.java index e3faeb0d9..38f8a7d51 100644 --- a/dspot/src/main/java/eu/stamp_project/Main.java +++ b/dspot/src/main/java/eu/stamp_project/Main.java @@ -37,12 +37,8 @@ public static void main(String[] args) { } catch (Exception ignored) { } - final boolean shouldRunExample = JSAPOptions.parse(args); - if (shouldRunExample) { - Main.runExample(); - } else { - run(); - } + JSAPOptions.parse(args); + run(); // global report handling Main.GLOBAL_REPORT.output(); Main.GLOBAL_REPORT.reset(); @@ -83,18 +79,4 @@ public static void createOutputDirectories() { } } - static void runExample() { - try { - InputConfiguration.get().initialize("src/test/resources/test-projects/test-projects.properties"); - DSpot dSpot = new DSpot(1, - Collections.singletonList(new TestDataMutator()), - new JacocoCoverageSelector(), - BudgetizerEnum.RandomBudgetizer - ); - dSpot.amplifyTestClassesTestMethods(Collections.singletonList("example.TestSuiteExample"), Collections.emptyList()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } \ No newline at end of file diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java b/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java index 908b0a16b..1c118b628 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java @@ -1,5 +1,7 @@ package eu.stamp_project.utils.options; +import eu.stamp_project.dspot.amplifier.TestDataMutator; +import eu.stamp_project.dspot.selector.JacocoCoverageSelector; import eu.stamp_project.dspot.selector.PitMutantScoreSelector; import eu.stamp_project.dspot.selector.TestSelector; import eu.stamp_project.utils.options.check.Checker; @@ -9,6 +11,7 @@ import java.io.FileInputStream; import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Properties; @@ -21,6 +24,21 @@ public class Configuration { private static final Logger LOGGER = LoggerFactory.getLogger(Configuration.class); + static void configureExample() { + try { + + InputConfiguration.get().initialize("src/test/resources/test-projects/test-projects.properties"); + InputConfiguration.get().setNbIteration(1); + InputConfiguration.get().setAmplifiers(Collections.singletonList(new TestDataMutator())); + InputConfiguration.get().setSelector(new JacocoCoverageSelector()); + InputConfiguration.get().setBudgetizer(BudgetizerEnum.RandomBudgetizer); + InputConfiguration.get().setTestClasses(Collections.singletonList("example.TestSuiteExample")); + InputConfiguration.get().setTestClasses(Collections.emptyList()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + public static void configure(final String pathToPropertiesFile, final List amplifiers, final String selector, diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java index f9bdf048b..ff2585138 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java @@ -36,10 +36,9 @@ public class JSAPOptions { * parse the command line argument * * @param args command line arguments. Refer to the README on the github page or use --help command line option to display all the accepted arguments. - * @return true if --example is pass through the command line. It will run DSpot with a small example to make a demonstration of the usage of DSpot. * Otherwise, it returns false and DSpot will run normally, using the properties and the command line options. */ - public static boolean parse(String[] args) { + public static void parse(String[] args) { JSAPResult jsapConfig = options.parse(args); if (!jsapConfig.success() || jsapConfig.getBoolean("help")) { System.err.println(); @@ -48,7 +47,8 @@ public static boolean parse(String[] args) { } showUsage(); } else if (jsapConfig.getBoolean("example")) { - return true; + Configuration.configureExample(); + return; } // getting first all the values of the command line. @@ -109,8 +109,6 @@ public static boolean parse(String[] args) { testClasses, testCases ); - - return false; } private static String helpForEnums(Class enumClass) { From 99465e989e515b732b1ad7ca989605bbe14d93b4 Mon Sep 17 00:00:00 2001 From: danglotb Date: Tue, 28 May 2019 23:04:34 +0200 Subject: [PATCH 05/19] style: remove unused imports --- .../main/java/eu/stamp_project/utils/options/JSAPOptions.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java index ff2585138..ae3707426 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java @@ -8,11 +8,8 @@ import com.martiansoftware.jsap.Parameter; import com.martiansoftware.jsap.Switch; import eu.stamp_project.dspot.selector.PitMutantScoreSelector; -import eu.stamp_project.dspot.selector.TestSelector; import eu.stamp_project.utils.options.check.Checker; -import eu.stamp_project.utils.program.InputConfiguration; import eu.stamp_project.utils.AmplificationHelper; -import jdk.internal.org.objectweb.asm.util.CheckClassAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From a1931897c1e24c9f086999f844d1c5f9262b6aca Mon Sep 17 00:00:00 2001 From: danglotb Date: Tue, 28 May 2019 23:05:39 +0200 Subject: [PATCH 06/19] fix: update API in dspot-prettifier --- .../java/eu/stamp_project/prettifier/options/JSAPOptions.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dspot-prettifier/src/main/java/eu/stamp_project/prettifier/options/JSAPOptions.java b/dspot-prettifier/src/main/java/eu/stamp_project/prettifier/options/JSAPOptions.java index 76f6f8e7c..f93d7baae 100644 --- a/dspot-prettifier/src/main/java/eu/stamp_project/prettifier/options/JSAPOptions.java +++ b/dspot-prettifier/src/main/java/eu/stamp_project/prettifier/options/JSAPOptions.java @@ -22,7 +22,7 @@ public class JSAPOptions extends eu.stamp_project.utils.options.JSAPOptions { * @param args command line arguments. Refer to the README on the github page or use --help command line option to display all the accepted arguments. * @return always true */ - public static boolean parse(String[] args) { + public static void parse(String[] args) { SplittedCommandLineOptions splittedOptions = new SplittedCommandLineOptions(args); System.out.println(splittedOptions); eu.stamp_project.utils.options.JSAPOptions.parse(splittedOptions.getDSpotOptions()); @@ -44,8 +44,6 @@ public static boolean parse(String[] args) { .setRelativePathToModelForCode2Vec(jsapConfig.getString("path-to-code2vec-model")); System.out.println(InputConfiguration.get()); - - return true; } public static void showUsage() { From d77b46e155bd27a8ef179bf9f3de0f27b9ee2185 Mon Sep 17 00:00:00 2001 From: danglotb Date: Wed, 29 May 2019 16:05:38 +0200 Subject: [PATCH 07/19] test: update command line option --- dspot/src/test/java/eu/stamp_project/MainTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dspot/src/test/java/eu/stamp_project/MainTest.java b/dspot/src/test/java/eu/stamp_project/MainTest.java index 4c83aa8a2..a9357d9ca 100644 --- a/dspot/src/test/java/eu/stamp_project/MainTest.java +++ b/dspot/src/test/java/eu/stamp_project/MainTest.java @@ -1,7 +1,7 @@ package eu.stamp_project; -import eu.stamp_project.utils.program.InputConfiguration; import eu.stamp_project.utils.AmplificationHelper; +import eu.stamp_project.utils.program.InputConfiguration; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; @@ -83,7 +83,7 @@ public void testMainWithMixedListOfTestClassesAndTestMethods() throws Exception "--path-to-properties", "src/test/resources/sample/sample.properties", "--test-criterion", "TakeAllSelector", "--test", "fr.inria.sample.TestClassWithoutAssert:fr.inria.sample.TestClassWithAssert", - "--cases", "test1:test:anOldTest", + "--test-cases", "test1:test:anOldTest", "--no-minimize" }); // an amplification happened, w/e it is From 9436bf82b4596c2fcd7f9d02fd92734cb0033859 Mon Sep 17 00:00:00 2001 From: danglotb Date: Wed, 29 May 2019 16:05:58 +0200 Subject: [PATCH 08/19] fix: check not null --- .../java/eu/stamp_project/utils/program/InputConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java index a47e550e9..9c444afdf 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java +++ b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java @@ -147,7 +147,7 @@ public static InputConfiguration initialize(Properties properties, String builde InputConfiguration.instance = new InputConfiguration(properties); InputConfiguration.instance.configPath = ""; final String builderNameProperties = ConstantsProperties.AUTOMATIC_BUILDER_NAME.get(properties); - if (builderName.isEmpty() && builderNameProperties.isEmpty()) { + if (builderName == null || (builderName.isEmpty() && builderNameProperties.isEmpty())) { LOGGER.warn("No builder has been specified."); LOGGER.warn("Using Maven as a default builder."); LOGGER.warn("You can use the command-line option --automatic-builder"); From 8f1da92957015770ee59844edaeeadd390832318 Mon Sep 17 00:00:00 2001 From: danglotb Date: Wed, 29 May 2019 16:06:19 +0200 Subject: [PATCH 09/19] fix: the key of with comment option --- .../main/java/eu/stamp_project/utils/options/JSAPOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java index ae3707426..3d898f104 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java @@ -64,7 +64,7 @@ public static void parse(String[] args) { final boolean clean = jsapConfig.getBoolean("clean"); final boolean verbose = jsapConfig.getBoolean("verbose"); final boolean workingDirectory = jsapConfig.getBoolean("working-directory"); - final boolean comment = jsapConfig.getBoolean("comment"); + final boolean comment = jsapConfig.getBoolean("with-comment"); final boolean generateNewTestClass = jsapConfig.getBoolean("generate-new-test-class"); final boolean keepOriginalTestMethods = jsapConfig.getBoolean("keep-original-test-methods"); final boolean gregor = jsapConfig.getBoolean("gregor"); From 562e81b1bb2998f777f5f5a70261b6369463ed91 Mon Sep 17 00:00:00 2001 From: danglotb Date: Wed, 29 May 2019 16:06:40 +0200 Subject: [PATCH 10/19] fix: do not always use the pit mutant score selector --- .../stamp_project/utils/options/Configuration.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java b/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java index 1c118b628..790866b07 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java @@ -149,18 +149,8 @@ public static void configure(Properties properties, originalFormat = PitMutantScoreSelector.OutputFormat.XML; } testCriterion = new PitMutantScoreSelector(pathPitResult, originalFormat, consecutiveFormat); - - // default test selector mode } else { - if (!(pitOutputFormat == null)) { - if (!"PitMutantScoreSelector".equals(selector)) { - LOGGER.warn("You specified an output format but you did not specify the right test-criterion"); - LOGGER.warn("Forcing the Selector to PitMutantScoreSelector"); - } - testCriterion = new PitMutantScoreSelector(consecutiveFormat); - } else { - testCriterion = SelectorEnum.valueOf(selector).buildSelector(); - } + testCriterion = SelectorEnum.valueOf(selector).buildSelector(); } Checker.preChecking( From ba305603eec28e34b375152f67578e0d36189520 Mon Sep 17 00:00:00 2001 From: danglotb Date: Thu, 30 May 2019 17:37:01 +0200 Subject: [PATCH 11/19] test: update test with new command line option name --- .../utils/options/JSAPOptions.java | 2 +- .../test/java/eu/stamp_project/MainTest.java | 40 ++++++++++++------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java index 3d898f104..bea7beec7 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/JSAPOptions.java @@ -77,7 +77,7 @@ public static void parse(String[] args) { // and thus, the Factory will be created. // Anyway, the verification in DSpot is not yet too late nor deep in the amplification's process. final List testClasses = Arrays.asList(jsapConfig.getStringArray("test")); - final List testCases = Arrays.asList(jsapConfig.getStringArray("testCases")); + final List testCases = Arrays.asList(jsapConfig.getStringArray("test-cases")); Configuration.configure( pathToPropertiesFile, diff --git a/dspot/src/test/java/eu/stamp_project/MainTest.java b/dspot/src/test/java/eu/stamp_project/MainTest.java index a9357d9ca..441dbfa46 100644 --- a/dspot/src/test/java/eu/stamp_project/MainTest.java +++ b/dspot/src/test/java/eu/stamp_project/MainTest.java @@ -200,7 +200,7 @@ public void testOnParametrizedTestClass() throws Exception { "--test", "example.ParametrizedTestSuiteExample", "--budgetizer", "TextualDistanceBudgetizer", "--no-minimize", - "--cases", "test2" + "--test-cases", "test2" }); final CtClass amplifiedTestClass = InputConfiguration.get().getFactory().Class().get("example.ParametrizedTestSuiteExample"); assertNotNull(amplifiedTestClass); @@ -266,11 +266,23 @@ public void testExample() throws Exception { " }"; private static final String expectedReportExample = - "Initial instruction coverage: 30 / 34" + AmplificationHelper.LINE_SEPARATOR + - "88" + AmplificationHelper.DECIMAL_SEPARATOR + "24%" + AmplificationHelper.LINE_SEPARATOR + - "Amplification results with 5 amplified tests." + AmplificationHelper.LINE_SEPARATOR + - "Amplified instruction coverage: 34 / 34" + AmplificationHelper.LINE_SEPARATOR + - "100" + AmplificationHelper.DECIMAL_SEPARATOR + "00%" + AmplificationHelper.LINE_SEPARATOR; + "Initial instruction coverage: 30 / 34\n" + + "88.24%\n" + + "Amplification results with 57 amplified tests.\n" + + "Amplified instruction coverage: 34 / 34\n" + + "100.00%\n" + + "\n" + + "Initial instruction coverage: 30 / 34\n" + + "88.24%\n" + + "Amplification results with 5 amplified tests.\n" + + "Amplified instruction coverage: 34 / 34\n" + + "100.00%\n" + + "\n" + + "Initial instruction coverage: 30 / 34\n" + + "88.24%\n" + + "Amplification results with 0 amplified tests.\n" + + "Amplified instruction coverage: 30 / 34\n" + + "88.24%\n"; @Test public void testOverrideExistingResults() throws Exception { @@ -289,9 +301,9 @@ public void testOverrideExistingResults() throws Exception { "--test-criterion", "JacocoCoverageSelector", "--amplifiers", "MethodAdd" + AmplificationHelper.PATH_SEPARATOR + "TestDataMutator" + AmplificationHelper.PATH_SEPARATOR + "MethodGeneratorAmplifier" + AmplificationHelper.PATH_SEPARATOR + "ReturnValueAmplifier", "--iteration", "1", - "--randomSeed", "72", + "--random-seed", "72", "--test", "example.TestSuiteExample", - "--cases", "test2", + "--test-cases", "test2", "--output-path", "target/trash", "--max-test-amplified", "200", "--keep-original-test-methods" @@ -309,9 +321,9 @@ public void testOverrideExistingResults() throws Exception { "--test-criterion", "JacocoCoverageSelector", "--amplifiers", "MethodAdd" + AmplificationHelper.PATH_SEPARATOR + "TestDataMutator", "--iteration", "1", - "--randomSeed", "72", + "--random-seed", "72", "--test", "example.TestSuiteExample", - "--cases", "test2", + "--test-cases", "test2", "--output-path", "target/trash", "--max-test-amplified", "200", "--keep-original-test-methods", @@ -333,9 +345,9 @@ public void testOverrideExistingResults() throws Exception { "--test-criterion", "JacocoCoverageSelector", "--amplifiers", "MethodGeneratorAmplifier" + AmplificationHelper.PATH_SEPARATOR + "ReturnValueAmplifier", "--iteration", "1", - "--randomSeed", "72", + "--random-seed", "72", "--test", "example.TestSuiteExample", - "--cases", "test2", + "--test-cases", "test2", "--output-path", "target/trash", "--max-test-amplified", "200", "--keep-original-test-methods" @@ -353,9 +365,9 @@ public void testOverrideExistingResults() throws Exception { "--test-criterion", "JacocoCoverageSelector", "--amplifiers", "MethodGeneratorAmplifier" + AmplificationHelper.PATH_SEPARATOR + "ReturnValueAmplifier", "--iteration", "1", - "--randomSeed", "72", + "--random-seed", "72", "--test", "example.TestSuiteExample", - "--cases", "test2", + "--test-cases", "test2", "--output-path", "target/trash", "--max-test-amplified", "200", "--keep-original-test-methods", From 10716b235a517a0b6cb61e3bd576f87d732b04ae Mon Sep 17 00:00:00 2001 From: danglotb Date: Thu, 30 May 2019 17:37:21 +0200 Subject: [PATCH 12/19] fix: use initialize --- .../java/eu/stamp_project/utils/options/Configuration.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java b/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java index 790866b07..00e48c459 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java @@ -26,8 +26,7 @@ public class Configuration { static void configureExample() { try { - - InputConfiguration.get().initialize("src/test/resources/test-projects/test-projects.properties"); + InputConfiguration.initialize("src/test/resources/test-projects/test-projects.properties"); InputConfiguration.get().setNbIteration(1); InputConfiguration.get().setAmplifiers(Collections.singletonList(new TestDataMutator())); InputConfiguration.get().setSelector(new JacocoCoverageSelector()); From dadc1dd36b7621535384c4db4bf3a5a46792c4af Mon Sep 17 00:00:00 2001 From: danglotb Date: Thu, 30 May 2019 17:57:06 +0200 Subject: [PATCH 13/19] fix: check the input of test criterion before creating test criterion --- .../stamp_project/utils/options/Configuration.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java b/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java index 00e48c459..27ac278c6 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/Configuration.java @@ -131,6 +131,13 @@ public static void configure(Properties properties, consecutiveFormat = PitMutantScoreSelector.OutputFormat.XML; } + Checker.preChecking( + amplifiers, + selector, + budgetizer, + properties + ); + // expert test selector mode TestSelector testCriterion; if (pathPitResult != null) { @@ -152,13 +159,6 @@ public static void configure(Properties properties, testCriterion = SelectorEnum.valueOf(selector).buildSelector(); } - Checker.preChecking( - amplifiers, - selector, - budgetizer, - properties - ); - InputConfiguration.initialize(properties, builder); if (InputConfiguration.get().getOutputDirectory().isEmpty()) { From d2d6b698e6f23f70d071944972364bfb8bc0f544 Mon Sep 17 00:00:00 2001 From: danglotb Date: Thu, 30 May 2019 18:21:16 +0200 Subject: [PATCH 14/19] style: remove unused imports --- dspot/src/main/java/eu/stamp_project/Main.java | 4 ---- .../eu/stamp_project/utils/program/InputConfiguration.java | 2 -- 2 files changed, 6 deletions(-) diff --git a/dspot/src/main/java/eu/stamp_project/Main.java b/dspot/src/main/java/eu/stamp_project/Main.java index 38f8a7d51..d6fa130fb 100644 --- a/dspot/src/main/java/eu/stamp_project/Main.java +++ b/dspot/src/main/java/eu/stamp_project/Main.java @@ -1,9 +1,6 @@ package eu.stamp_project; import eu.stamp_project.dspot.DSpot; -import eu.stamp_project.dspot.amplifier.TestDataMutator; -import eu.stamp_project.dspot.selector.JacocoCoverageSelector; -import eu.stamp_project.utils.options.BudgetizerEnum; import eu.stamp_project.utils.options.JSAPOptions; import eu.stamp_project.utils.program.InputConfiguration; import eu.stamp_project.utils.RandomHelper; @@ -18,7 +15,6 @@ import java.io.File; import java.io.IOException; -import java.util.Collections; import java.util.List; /** diff --git a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java index 9c444afdf..fec54d892 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java +++ b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java @@ -20,8 +20,6 @@ import spoon.reflect.factory.Factory; import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; From b4d4b05245ac9949f8d185e1aa4527f8b6963020 Mon Sep 17 00:00:00 2001 From: danglotb Date: Thu, 30 May 2019 20:31:08 +0200 Subject: [PATCH 15/19] feat: let now the user to specify an absolute path for others paths --- .../src/main/java/eu/stamp_project/Main.java | 6 ++-- .../utils/options/check/Checker.java | 29 +++++++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/dspot/src/main/java/eu/stamp_project/Main.java b/dspot/src/main/java/eu/stamp_project/Main.java index d6fa130fb..f491f7cf2 100644 --- a/dspot/src/main/java/eu/stamp_project/Main.java +++ b/dspot/src/main/java/eu/stamp_project/Main.java @@ -35,9 +35,6 @@ public static void main(String[] args) { } JSAPOptions.parse(args); run(); - // global report handling - Main.GLOBAL_REPORT.output(); - Main.GLOBAL_REPORT.reset(); } public static void run() { @@ -59,6 +56,9 @@ public static void run() { LOGGER.info("Amplification {}.", amplifiedTestClasses.isEmpty() ? "failed" : "succeed"); final long elapsedTime = System.currentTimeMillis() - startTime; LOGGER.info("Elapsed time {} ms", elapsedTime); + // global report handling + Main.GLOBAL_REPORT.output(); + Main.GLOBAL_REPORT.reset(); } public static void createOutputDirectories() { diff --git a/dspot/src/main/java/eu/stamp_project/utils/options/check/Checker.java b/dspot/src/main/java/eu/stamp_project/utils/options/check/Checker.java index 4db96ade2..898221c4a 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/options/check/Checker.java +++ b/dspot/src/main/java/eu/stamp_project/utils/options/check/Checker.java @@ -62,13 +62,13 @@ public static void checkBinariesFolders(Properties properties) { currentPath += targetModulePropertyValue != null ? targetModulePropertyValue : ""; // binary folders: classes and test-classes - Checker.checkRelativePathPropertyValue( + Checker.checkPathPropertyValue( properties.getProperty(ConstantsProperties.SRC_CLASSES.getName()), ErrorEnum.ERROR_PATH_TO_SRC_CLASSES_PROPERTY, ConstantsProperties.SRC_CLASSES.getNaturalLanguageDesignation(), currentPath ); - Checker.checkRelativePathPropertyValue( + Checker.checkPathPropertyValue( properties.getProperty(ConstantsProperties.TEST_CLASSES.getName()), ErrorEnum.ERROR_PATH_TO_TEST_CLASSES_PROPERTY, ConstantsProperties.TEST_CLASSES.getNaturalLanguageDesignation(), @@ -87,7 +87,7 @@ public static void checkProperties(Properties properties) { ); // target module final String targetModulePropertyValue = DSpotUtils.shouldAddSeparator.apply(properties.getProperty(ConstantsProperties.MODULE.getName())); - Checker.checkRelativePathPropertyValue( + Checker.checkPathPropertyValue( targetModulePropertyValue, ErrorEnum.ERROR_PATH_TO_TARGET_MODULE_PROPERTY, ConstantsProperties.MODULE.getNaturalLanguageDesignation(), @@ -96,13 +96,13 @@ public static void checkProperties(Properties properties) { currentPath += targetModulePropertyValue != null ? targetModulePropertyValue : ""; // source folders: src and testSrc - Checker.checkRelativePathPropertyValue( + Checker.checkPathPropertyValue( properties.getProperty(ConstantsProperties.SRC_CODE.getName()), ErrorEnum.ERROR_PATH_TO_SRC_PROPERTY, ConstantsProperties.SRC_CODE.getNaturalLanguageDesignation(), currentPath ); - Checker.checkRelativePathPropertyValue( + Checker.checkPathPropertyValue( properties.getProperty(ConstantsProperties.TEST_SRC_CODE.getName()), ErrorEnum.ERROR_PATH_TO_TEST_SRC_PROPERTY, ConstantsProperties.TEST_SRC_CODE.getNaturalLanguageDesignation(), @@ -110,7 +110,7 @@ public static void checkProperties(Properties properties) { ); // path to maven home - Checker.checkRelativePathPropertyValue( + Checker.checkPathPropertyValue( properties.getProperty(ConstantsProperties.MAVEN_HOME.getName()), ErrorEnum.ERROR_PATH_TO_MAVEN_HOME, ConstantsProperties.MAVEN_HOME.getNaturalLanguageDesignation(), @@ -170,6 +170,23 @@ public static void checkIsACorrectVersion(final String proposedVersion) { } } + private static void checkPathPropertyValue(final String propertyValue, + final ErrorEnum errorEnumInCaseOfError, + final String naturalLanguageDesignation, + final String rootPathProject) { + if (propertyValue != null) { + final String additionalMessage = "The provided path to the " + naturalLanguageDesignation + " of your project is incorrect, the folder does not exist." + + AmplificationHelper.LINE_SEPARATOR + " This path should be either relative to the path pointed by " + + ConstantsProperties.PROJECT_ROOT_PATH.getName() + " property " + + AmplificationHelper.LINE_SEPARATOR + "or an absolute path"; + if (new File(propertyValue).isAbsolute()) { + Checker.checkFileExists(propertyValue, errorEnumInCaseOfError, additionalMessage); + } else { + Checker.checkFileExists(rootPathProject + "/" + propertyValue, errorEnumInCaseOfError, additionalMessage); + } + } + } + private static void checkRelativePathPropertyValue(final String propertyValue, final ErrorEnum errorEnumInCaseOfError, final String naturalLanguageDesignation, From 4a316af9276212aac90424e9781b5a89a60aebbc Mon Sep 17 00:00:00 2001 From: danglotb Date: Wed, 5 Jun 2019 09:43:19 +0200 Subject: [PATCH 16/19] refactor: factorize the check and substring --- .../utils/program/InputConfiguration.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java index fec54d892..1493b531c 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java +++ b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java @@ -363,6 +363,17 @@ public InputConfiguration setTargetModule(String targetModule) { return this; } + private String removeProjectRootIfAbsoluteAndAddSeparator(String path) { + System.out.println(path); + System.out.println(this.absolutePathToProjectRoot); + if (new File(path).isAbsolute()) { + System.out.println(path.substring(this.absolutePathToProjectRoot.length())); + return DSpotUtils.shouldAddSeparator.apply(path.substring(this.absolutePathToProjectRoot.length())); + } else { + return DSpotUtils.shouldAddSeparator.apply(path); + } + } + private String pathToSourceCode; public String getPathToSourceCode() { @@ -374,10 +385,7 @@ public String getAbsolutePathToSourceCode() { } public InputConfiguration setPathToSourceCode(String pathToSourceCode) { - if (new File(pathToSourceCode).isAbsolute()) { - pathToSourceCode = pathToSourceCode.substring(this.absolutePathToProjectRoot.length()); - } - this.pathToSourceCode = DSpotUtils.shouldAddSeparator.apply(pathToSourceCode); + this.pathToSourceCode =removeProjectRootIfAbsoluteAndAddSeparator(pathToSourceCode); return this; } @@ -388,10 +396,7 @@ public String getPathToTestSourceCode() { } public InputConfiguration setPathToTestSourceCode(String pathToTestSourceCode) { - if (new File(pathToTestSourceCode).isAbsolute()) { - pathToTestSourceCode = pathToTestSourceCode.substring(this.absolutePathToProjectRoot.length()); - } - this.pathToTestSourceCode = DSpotUtils.shouldAddSeparator.apply(pathToTestSourceCode); + this.pathToTestSourceCode = removeProjectRootIfAbsoluteAndAddSeparator(pathToTestSourceCode); return this; } @@ -410,10 +415,7 @@ public String getPathToClasses() { } public InputConfiguration setPathToClasses(String pathToClasses) { - if (new File(pathToClasses).isAbsolute()) { - pathToClasses = pathToClasses.substring(this.absolutePathToProjectRoot.length()); - } - this.pathToClasses = DSpotUtils.shouldAddSeparator.apply(pathToClasses); + this.pathToClasses = removeProjectRootIfAbsoluteAndAddSeparator(pathToClasses); return this; } @@ -432,10 +434,7 @@ public String getAbsolutePathToTestClasses() { } public InputConfiguration setPathToTestClasses(String pathToTestClasses) { - if (new File(pathToTestClasses).isAbsolute()) { - pathToTestClasses = pathToTestClasses.substring(this.absolutePathToProjectRoot.length()); - } - this.pathToTestClasses = DSpotUtils.shouldAddSeparator.apply(pathToTestClasses); + this.pathToTestClasses = removeProjectRootIfAbsoluteAndAddSeparator(pathToTestClasses); return this; } From b5e5baef4ffb2d8d89a8f70d99e6269085e7a2ab Mon Sep 17 00:00:00 2001 From: danglotb Date: Wed, 5 Jun 2019 09:43:55 +0200 Subject: [PATCH 17/19] fix: substring now paths to have relative path instead of absolute paths --- .../src/main/java/eu/stamp_project/DSpotMojo.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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 d385cbb6b..143018d80 100644 --- a/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java +++ b/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java @@ -323,12 +323,17 @@ public void execute() { @NotNull Properties initializeProperties() { Properties properties = new Properties(); - properties.setProperty(ConstantsProperties.PROJECT_ROOT_PATH.getName(), project.getBasedir().getAbsolutePath()); + final String absolutePathProjectRoot = project.getBasedir().getAbsolutePath(); + properties.setProperty(ConstantsProperties.PROJECT_ROOT_PATH.getName(), absolutePathProjectRoot); final Build build = project.getBuild(); - properties.setProperty(ConstantsProperties.SRC_CODE.getName(), build.getSourceDirectory()); - properties.setProperty(ConstantsProperties.TEST_SRC_CODE.getName(), build.getTestSourceDirectory()); - properties.setProperty(ConstantsProperties.SRC_CLASSES.getName(), build.getOutputDirectory()); - properties.setProperty(ConstantsProperties.TEST_CLASSES.getName(), build.getTestOutputDirectory()); + properties.setProperty(ConstantsProperties.SRC_CODE.getName(), + build.getSourceDirectory().substring(absolutePathProjectRoot.length())); + properties.setProperty(ConstantsProperties.TEST_SRC_CODE.getName(), + build.getTestSourceDirectory().substring(absolutePathProjectRoot.length())); + properties.setProperty(ConstantsProperties.SRC_CLASSES.getName(), + build.getOutputDirectory().substring(absolutePathProjectRoot.length())); + properties.setProperty(ConstantsProperties.TEST_CLASSES.getName(), + build.getTestOutputDirectory().substring(absolutePathProjectRoot.length())); // TODO checks that we can use an empty module for multi module project // TODO the guess here is that the user will launch the plugin from the root of the targeted module // TODO and thus, we do not need to compute the relative path from its parents From df0f55b41d437a75f6ffa8ab3f5b8a1b4538977c Mon Sep 17 00:00:00 2001 From: danglotb Date: Wed, 5 Jun 2019 11:30:07 +0200 Subject: [PATCH 18/19] refactor: factorize the code to manage relative paths and make it visible --- .../eu/stamp_project/utils/DSpotUtils.java | 11 +++++++++++ .../utils/program/InputConfiguration.java | 19 ++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dspot/src/main/java/eu/stamp_project/utils/DSpotUtils.java b/dspot/src/main/java/eu/stamp_project/utils/DSpotUtils.java index ffc561a7d..c9543d096 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/DSpotUtils.java +++ b/dspot/src/main/java/eu/stamp_project/utils/DSpotUtils.java @@ -201,6 +201,17 @@ public static void copyPackageFromResources() { }); } + public static String removeProjectRootIfAbsoluteAndAddSeparator(final String prefix, String path) { + if (new File(path).isAbsolute()) { + path = path.substring(prefix.length()); + return DSpotUtils.shouldAddSeparator.apply( + path.startsWith("/") ? path.substring(1) : path + ); + } else { + return DSpotUtils.shouldAddSeparator.apply(path); + } + } + public static final Function shouldAddSeparator = string -> string != null ? string + (string.endsWith(File.separator) ? "" : File.separator) : null; diff --git a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java index 1493b531c..bc9e9c098 100644 --- a/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java +++ b/dspot/src/main/java/eu/stamp_project/utils/program/InputConfiguration.java @@ -363,17 +363,6 @@ public InputConfiguration setTargetModule(String targetModule) { return this; } - private String removeProjectRootIfAbsoluteAndAddSeparator(String path) { - System.out.println(path); - System.out.println(this.absolutePathToProjectRoot); - if (new File(path).isAbsolute()) { - System.out.println(path.substring(this.absolutePathToProjectRoot.length())); - return DSpotUtils.shouldAddSeparator.apply(path.substring(this.absolutePathToProjectRoot.length())); - } else { - return DSpotUtils.shouldAddSeparator.apply(path); - } - } - private String pathToSourceCode; public String getPathToSourceCode() { @@ -385,7 +374,7 @@ public String getAbsolutePathToSourceCode() { } public InputConfiguration setPathToSourceCode(String pathToSourceCode) { - this.pathToSourceCode =removeProjectRootIfAbsoluteAndAddSeparator(pathToSourceCode); + this.pathToSourceCode = DSpotUtils.removeProjectRootIfAbsoluteAndAddSeparator(this.absolutePathToProjectRoot, pathToSourceCode); return this; } @@ -396,7 +385,7 @@ public String getPathToTestSourceCode() { } public InputConfiguration setPathToTestSourceCode(String pathToTestSourceCode) { - this.pathToTestSourceCode = removeProjectRootIfAbsoluteAndAddSeparator(pathToTestSourceCode); + this.pathToTestSourceCode = DSpotUtils.removeProjectRootIfAbsoluteAndAddSeparator(this.absolutePathToProjectRoot, pathToTestSourceCode); return this; } @@ -415,7 +404,7 @@ public String getPathToClasses() { } public InputConfiguration setPathToClasses(String pathToClasses) { - this.pathToClasses = removeProjectRootIfAbsoluteAndAddSeparator(pathToClasses); + this.pathToClasses = DSpotUtils.removeProjectRootIfAbsoluteAndAddSeparator(this.absolutePathToProjectRoot, pathToClasses); return this; } @@ -434,7 +423,7 @@ public String getAbsolutePathToTestClasses() { } public InputConfiguration setPathToTestClasses(String pathToTestClasses) { - this.pathToTestClasses = removeProjectRootIfAbsoluteAndAddSeparator(pathToTestClasses); + this.pathToTestClasses = DSpotUtils.removeProjectRootIfAbsoluteAndAddSeparator(this.absolutePathToProjectRoot, pathToTestClasses); return this; } From d7bd5851015de21a38fc49ca223aeab1989c8a2c Mon Sep 17 00:00:00 2001 From: danglotb Date: Wed, 5 Jun 2019 11:30:29 +0200 Subject: [PATCH 19/19] fix: change absolute paths by relative paths --- .../main/java/eu/stamp_project/DSpotMojo.java | 122 +++++++++--------- .../MultiModuleDSpotMojoTest.java | 8 +- 2 files changed, 67 insertions(+), 63 deletions(-) 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 143018d80..32e6b8744 100644 --- a/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java +++ b/dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java @@ -25,200 +25,200 @@ public class DSpotMojo extends AbstractMojo { /** - * [mandatory] specify the path to the configuration file (format Java properties) of the target project (e.g. ./foo.properties). + * [mandatory] specify the path to the configuration file (format Java properties) of the target project (e.g. ./foo.properties). */ @Parameter(property = "path-to-properties") private String pathToProperties; /** - * [optional] specify the list of amplifiers to use. By default, DSpot does not use any amplifiers (None) and applies only assertion amplification. - * Possible values are: - * - MethodAdd - * - MethodRemove - * - TestDataMutator - * - MethodGeneratorAmplifier - * - ReturnValueAmplifier - * - StringLiteralAmplifier - * - NumberLiteralAmplifier - * - BooleanLiteralAmplifier - * - CharLiteralAmplifier - * - AllLiteralAmplifiers - * - NullifierAmplifier - * - None + * [optional] specify the list of amplifiers to use. By default, DSpot does not use any amplifiers (None) and applies only assertion amplification. + * Possible values are: + * - MethodAdd + * - MethodRemove + * - TestDataMutator + * - MethodGeneratorAmplifier + * - ReturnValueAmplifier + * - StringLiteralAmplifier + * - NumberLiteralAmplifier + * - BooleanLiteralAmplifier + * - CharLiteralAmplifier + * - AllLiteralAmplifiers + * - NullifierAmplifier + * - None */ @Parameter(defaultValue = "None", property = "amplifiers") private List amplifiers; /** - * [optional] specify the number of amplification iterations. A larger number may help to improve the test criterion (e.g. a larger number of iterations may help to kill more mutants). This has an impact on the execution time: the more iterations, the longer DSpot runs. + * [optional] specify the number of amplification iterations. A larger number may help to improve the test criterion (e.g. a larger number of iterations may help to kill more mutants). This has an impact on the execution time: the more iterations, the longer DSpot runs. */ @Parameter(defaultValue = "3", property = "iteration") private Integer iteration; /** - * [optional] specify the test adequacy criterion to be maximized with amplification. - * Possible values are: - * - PitMutantScoreSelector - * - JacocoCoverageSelector - * - TakeAllSelector - * - ChangeDetectorSelector + * [optional] specify the test adequacy criterion to be maximized with amplification. + * Possible values are: + * - PitMutantScoreSelector + * - JacocoCoverageSelector + * - TakeAllSelector + * - ChangeDetectorSelector */ @Parameter(defaultValue = "PitMutantScoreSelector", property = "test-criterion") private String testCriterion; /** - * [optional] specify the Pit output format. - * Possible values are: - * - XML - * - CSV + * [optional] specify the Pit output format. + * Possible values are: + * - XML + * - CSV */ @Parameter(defaultValue = "XML", property = "pit-output-format") private String pitOutputFormat; /** - * [optional] specify a Bugdetizer. - * Possible values are: - * - RandomBudgetizer - * - TextualDistanceBudgetizer - * - SimpleBudgetizer + * [optional] specify a Bugdetizer. + * Possible values are: + * - RandomBudgetizer + * - TextualDistanceBudgetizer + * - SimpleBudgetizer */ @Parameter(defaultValue = "RandomBudgetizer", property = "budgetizer") private String budgetizer; /** - * [optional] specify the maximum number of amplified tests that dspot keeps (before generating assertion) + * [optional] specify the maximum number of amplified tests that dspot keeps (before generating assertion) */ @Parameter(defaultValue = "200", property = "max-test-amplified") private Integer maxTestAmplified; /** - * [optional] fully qualified names of test classes to be amplified. If the value is all, DSpot will amplify the whole test suite. You can also use regex to describe a set of test classes. By default, DSpot selects all the tests (value all). + * [optional] fully qualified names of test classes to be amplified. If the value is all, DSpot will amplify the whole test suite. You can also use regex to describe a set of test classes. By default, DSpot selects all the tests (value all). */ @Parameter(defaultValue = "all", property = "test") private List test; /** - * specify the test cases to amplify + * specify the test cases to amplify */ @Parameter(property = "test-cases") private List testCases; /** - * [optional] specify the output folder + * [optional] specify the output folder */ @Parameter(defaultValue = "target/dspot/output", property = "output-path") private String outputPath; /** - * [optional] if enabled, DSpot will remove the out directory if exists, else it will append the results to the exist files. + * [optional] if enabled, DSpot will remove the out directory if exists, else it will append the results to the exist files. */ @Parameter(defaultValue = "false", property = "clean") private Boolean clean; /** - * [optional, expert mode] specify the path to the .xml or .csv of the original result of Pit Test. If you use this option the selector will be forced to PitMutantScoreSelector + * [optional, expert mode] specify the path to the .xml or .csv of the original result of Pit Test. If you use this option the selector will be forced to PitMutantScoreSelector */ @Parameter(property = "path-pit-result") private String pathPitResult; /** - * [optional, expert] enable this option will make DSpot computing the mutation score of only one test class (the first pass through --test command line option) + * [optional, expert] enable this option will make DSpot computing the mutation score of only one test class (the first pass through --test command line option) */ @Parameter(defaultValue = "false", property = "target-one-test-class") private Boolean targetOneTestClass; /** - * Enable the descartes engine for Pit Mutant Score Selector. + * Enable the descartes engine for Pit Mutant Score Selector. */ @Parameter(defaultValue = "true", property = "descartes") private Boolean descartes; /** - * Enable the gregor engine for Pit Mutant Score Selector. + * Enable the gregor engine for Pit Mutant Score Selector. */ @Parameter(defaultValue = "false", property = "gregor") private Boolean gregor; /** - * [optional] specify the automatic builder to build the project + * [optional] specify the automatic builder to build the project */ @Parameter(defaultValue = "", property = "automatic-builder") private String automaticBuilder; /** - * specify the path to the maven home + * specify the path to the maven home */ @Parameter(property = "maven-home") private String mavenHome; /** - * specify a seed for the random object (used for all randomized operation) + * specify a seed for the random object (used for all randomized operation) */ @Parameter(defaultValue = "23", property = "random-seed") private Long randomSeed; /** - * specify the timeout value of the degenerated tests in millisecond + * specify the timeout value of the degenerated tests in millisecond */ @Parameter(defaultValue = "10000", property = "time-out") private Integer timeOut; /** - * Enable verbose mode of DSpot. + * Enable verbose mode of DSpot. */ @Parameter(defaultValue = "false", property = "verbose") private Boolean verbose; /** - * Enable comment on amplified test: details steps of the Amplification. + * Enable comment on amplified test: details steps of the Amplification. */ @Parameter(defaultValue = "false", property = "with-comment") private Boolean withComment; /** - * Disable the minimization of amplified tests. + * Disable the minimization of amplified tests. */ @Parameter(defaultValue = "false", property = "no-minimize") private Boolean noMinimize; /** - * Enable this option to change working directory with the root of the project. + * Enable this option to change working directory with the root of the project. */ @Parameter(defaultValue = "false", property = "working-directory") private Boolean workingDirectory; /** - * Enable the creation of a new test class. + * Enable the creation of a new test class. */ @Parameter(defaultValue = "false", property = "generate-new-test-class") private Boolean generateNewTestClass; /** - * If enabled, DSpot keeps original test methods of the amplified test class. + * If enabled, DSpot keeps original test methods of the amplified test class. */ @Parameter(defaultValue = "false", property = "keep-original-test-methods") private Boolean keepOriginalTestMethods; /** - * If enabled, DSpot will use maven to execute the tests. + * If enabled, DSpot will use maven to execute the tests. */ @Parameter(defaultValue = "false", property = "use-maven-to-exe-test") private Boolean useMavenToExeTest; /** - * If enabled, DSpot will generate assertions for values that seems like to be paths. + * If enabled, DSpot will generate assertions for values that seems like to be paths. */ @Parameter(defaultValue = "false", property = "allow-path-in-assertions") private Boolean allowPathInAssertions; /** - * run the example of DSpot and leave + * run the example of DSpot and leave */ @Parameter(defaultValue = "false", property = "example") private Boolean example; /** - * show this help + * show this help */ @Parameter(defaultValue = "false", property = "help") private Boolean help; @@ -271,7 +271,7 @@ public void execute() { Configuration.configure( properties, - this.amplifiers, + this.amplifiers, this.testCriterion, this.budgetizer, this.pitOutputFormat, @@ -327,13 +327,17 @@ Properties initializeProperties() { properties.setProperty(ConstantsProperties.PROJECT_ROOT_PATH.getName(), absolutePathProjectRoot); final Build build = project.getBuild(); properties.setProperty(ConstantsProperties.SRC_CODE.getName(), - build.getSourceDirectory().substring(absolutePathProjectRoot.length())); + DSpotUtils.removeProjectRootIfAbsoluteAndAddSeparator(absolutePathProjectRoot, build.getSourceDirectory()) + ); properties.setProperty(ConstantsProperties.TEST_SRC_CODE.getName(), - build.getTestSourceDirectory().substring(absolutePathProjectRoot.length())); + DSpotUtils.removeProjectRootIfAbsoluteAndAddSeparator(absolutePathProjectRoot, build.getTestSourceDirectory()) + ); properties.setProperty(ConstantsProperties.SRC_CLASSES.getName(), - build.getOutputDirectory().substring(absolutePathProjectRoot.length())); + DSpotUtils.removeProjectRootIfAbsoluteAndAddSeparator(absolutePathProjectRoot, build.getOutputDirectory()) + ); properties.setProperty(ConstantsProperties.TEST_CLASSES.getName(), - build.getTestOutputDirectory().substring(absolutePathProjectRoot.length())); + DSpotUtils.removeProjectRootIfAbsoluteAndAddSeparator(absolutePathProjectRoot, build.getTestOutputDirectory()) + ); // TODO checks that we can use an empty module for multi module project // TODO the guess here is that the user will launch the plugin from the root of the targeted module // TODO and thus, we do not need to compute the relative path from its parents diff --git a/dspot-maven/src/test/java/eu/stamp_project/MultiModuleDSpotMojoTest.java b/dspot-maven/src/test/java/eu/stamp_project/MultiModuleDSpotMojoTest.java index 546b6027c..083d43509 100644 --- a/dspot-maven/src/test/java/eu/stamp_project/MultiModuleDSpotMojoTest.java +++ b/dspot-maven/src/test/java/eu/stamp_project/MultiModuleDSpotMojoTest.java @@ -35,13 +35,13 @@ public void testOnMultiModuleParent() throws Exception { assertNotNull(properties.get(ConstantsProperties.PROJECT_ROOT_PATH.getName())); assertEquals(testPom.getAbsolutePath(), properties.get(ConstantsProperties.PROJECT_ROOT_PATH.getName())); assertNotNull(properties.get(ConstantsProperties.SRC_CODE.getName())); - assertEquals(testPom.getAbsolutePath() + "/src/main/java", properties.get(ConstantsProperties.SRC_CODE.getName())); + assertEquals("src/main/java/", properties.get(ConstantsProperties.SRC_CODE.getName())); assertNotNull(properties.get(ConstantsProperties.TEST_SRC_CODE.getName())); - assertEquals(testPom.getAbsolutePath() + "/src/test/java", properties.get(ConstantsProperties.TEST_SRC_CODE.getName())); + assertEquals("src/test/java/", properties.get(ConstantsProperties.TEST_SRC_CODE.getName())); assertNotNull(properties.get(ConstantsProperties.SRC_CLASSES.getName())); - assertEquals(testPom.getAbsolutePath() + "/target/classes", properties.get(ConstantsProperties.SRC_CLASSES.getName())); + assertEquals("target/classes/", properties.get(ConstantsProperties.SRC_CLASSES.getName())); assertNotNull(properties.get(ConstantsProperties.TEST_CLASSES.getName())); - assertEquals(testPom.getAbsolutePath() + "/target/test-classes", properties.get(ConstantsProperties.TEST_CLASSES.getName())); + assertEquals("target/test-classes/", properties.get(ConstantsProperties.TEST_CLASSES.getName())); assertNotNull(properties.get(ConstantsProperties.MODULE.getName())); assertEquals("", properties.get(ConstantsProperties.MODULE.getName())); }