Skip to content

Commit

Permalink
Refactor: organize packages to reflect the algorithm (#933)
Browse files Browse the repository at this point in the history
* refactor Main, DSpot and Amplification

* remove global report in main

* refactor DSpot constructor

* remove amplification class

* add new configuration to prettifier

* combine amplify and run in DSpot

* make inputConfiguration private

* change name to DSpotState

* move verbose to DSpotState

* change remaining use of verbose

* clean code

* refactor DSpotState

* first organization

* basically done organization

* fix merge problems

* rename InputConfiguration to UserInput
  • Loading branch information
andrewbwogi authored and danglotb committed Dec 4, 2019
1 parent 21b7be5 commit ee804de
Show file tree
Hide file tree
Showing 201 changed files with 889 additions and 887 deletions.
8 changes: 4 additions & 4 deletions README-developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ First of all, you have to create an `InputConfiguration`. Only the path to your
```java
// 1. Instantiate `InputConfiguration` and `InputProgram`
String propertiesFilePath = <pathToYourPropertiesFile>;
InputConfiguration inputConfiguration = new InputConfiguration(propertiesFilePath);
InputConfiguration userInput = new InputConfiguration(propertiesFilePath);
```

Then you have to build the `InputProgram`, this is done by attaching the `InputProgram` to your `InputConfiguration`:

```java
InputProgram program = new InputProgram();
inputConfiguration.setInputProgram(program);
userInput.setInputProgram(program);
```
Then, you are ready to construct the `DSpot` object that will allow you to amplify your test.
There are a lot of constructor available, all of them allow you to custom your `DSpot` object, and so your amplification.
Expand All @@ -86,7 +86,7 @@ Following the shortest constructor with all default values of `DSpot`, and the l
// 2. Instantiate `DSpot` object
DSpot dspot = new DSpot(InputConfiguration);
DSpot dspot = new DSpot(
InputConfiguration inputConfiguration, // input configuration built at step 1
InputConfiguration userInput, // input configuration built at step 1
int numberOfIterations, // number of time that the main loop will be applied (-i | --iteration option of the CLI)
List<Amplifier> amplifiers, // list of the amplifiers to be used (-a | --amplifiers option of the CLI)
TestSelector testSelector // test selector criterion (-s | --test-selector option of the CLI)
Expand All @@ -105,4 +105,4 @@ dspot.amplifyAllTests(); // will amplify all test in the test suite.

## Contributing

DSpot is licensed under LGPLv3. Contributors and pull requests are welcome.
DSpot is licensed under LGPLv3. Contributors and pull requests are welcome.
2 changes: 1 addition & 1 deletion dspot-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<configuration>
<processors>
<processor>
eu.stamp_project.utils.DSpotMojoGenerator
eu.stamp_project.dspot.common.miscellaneous.DSpotMojoGenerator
</processor>
</processors>
<withImports>true</withImports>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import eu.stamp_project.automaticbuilder.AutomaticBuilder;
import eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder;
import eu.stamp_project.prettifier.code2vec.Code2VecExecutor;
import eu.stamp_project.prettifier.code2vec.Code2VecParser;
import eu.stamp_project.prettifier.code2vec.Code2VecWriter;
import eu.stamp_project.prettifier.context2name.Context2Name;
import eu.stamp_project.prettifier.minimization.GeneralMinimizer;
import eu.stamp_project.prettifier.minimization.Minimizer;
import eu.stamp_project.prettifier.minimization.PitMutantMinimizer;
import eu.stamp_project.prettifier.options.InputConfiguration;
import eu.stamp_project.prettifier.options.UserInput;
import eu.stamp_project.prettifier.output.PrettifiedTestMethods;
import eu.stamp_project.prettifier.output.report.ReportJSON;
import eu.stamp_project.test_framework.TestFramework;
import eu.stamp_project.utils.compilation.DSpotCompiler;
import eu.stamp_project.utils.configuration.DSpotState;
import eu.stamp_project.utils.configuration.InitializeDSpot;
import eu.stamp_project.utils.options.check.Checker;
import eu.stamp_project.utils.options.check.InputErrorException;
import eu.stamp_project.dspot.common.test_framework.TestFramework;
import eu.stamp_project.dspot.common.compilation.DSpotCompiler;
import eu.stamp_project.dspot.common.configuration.DSpotState;
import eu.stamp_project.dspot.common.configuration.InitializeDSpot;
import eu.stamp_project.dspot.common.configuration.check.Checker;
import eu.stamp_project.dspot.common.configuration.check.InputErrorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class Main {
public static ReportJSON report = new ReportJSON();

public static void main(String[] args) {
InputConfiguration inputConfiguration = new InputConfiguration();
UserInput inputConfiguration = new UserInput();
final CommandLine commandLine = new CommandLine(inputConfiguration);
commandLine.setUsageHelpWidth(120);
try {
Expand Down Expand Up @@ -80,7 +80,7 @@ public static void main(String[] args) {
run(inputConfiguration);
}

public static void run(InputConfiguration configuration) {
public static void run(UserInput configuration) {
final CtType<?> amplifiedTestClass = loadAmplifiedTestClass(configuration);
final List<CtMethod<?>> prettifiedAmplifiedTestMethods =
run(
Expand All @@ -91,7 +91,7 @@ public static void run(InputConfiguration configuration) {
output(amplifiedTestClass, prettifiedAmplifiedTestMethods, configuration);
}

public static CtType<?> loadAmplifiedTestClass(InputConfiguration configuration) {
public static CtType<?> loadAmplifiedTestClass(UserInput configuration) {
Launcher launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
launcher.addInputResource(configuration.getPathToAmplifiedTestClass());
Expand All @@ -100,7 +100,7 @@ public static CtType<?> loadAmplifiedTestClass(InputConfiguration configuration)
}

public static List<CtMethod<?>> run(CtType<?> amplifiedTestClass,
InputConfiguration configuration) {
UserInput configuration) {
InitializeDSpot initializeDSpot = new InitializeDSpot();
final AutomaticBuilder automaticBuilder = configuration.getBuilderEnum().getAutomaticBuilder(configuration);
final String dependencies = initializeDSpot.completeDependencies(configuration, automaticBuilder);
Expand All @@ -127,7 +127,7 @@ public static List<CtMethod<?>> run(CtType<?> amplifiedTestClass,

public static List<CtMethod<?>> applyMinimization(List<CtMethod<?>> amplifiedTestMethodsToBeMinimized,
CtType<?> amplifiedTestClass,
InputConfiguration configuration) {
UserInput configuration) {

Main.report.medianNbStatementBefore = Main.getMedian(amplifiedTestMethodsToBeMinimized.stream()
.map(ctMethod -> ctMethod.getElements(new TypeFilter<>(CtStatement.class)))
Expand Down Expand Up @@ -173,7 +173,7 @@ private static List<CtMethod<?>> applyGivenMinimizer(Minimizer minimizer, List<C
}

public static void applyCode2Vec(List<CtMethod<?>> amplifiedTestMethodsToBeRenamed,
InputConfiguration configuration) {
UserInput configuration) {
Code2VecWriter writer = new Code2VecWriter(configuration.getPathToRootOfCode2Vec());
Code2VecParser parser = new Code2VecParser();
Code2VecExecutor code2VecExecutor = null;
Expand Down Expand Up @@ -228,7 +228,7 @@ public static <T extends Number & Comparable<T>> Double getMedian(List<T> list)

public static void output(CtType<?> amplifiedTestClass,
List<CtMethod<?>> prettifiedAmplifiedTestMethods,
InputConfiguration configuration) {
UserInput configuration) {
new PrettifiedTestMethods(configuration.getOutputDirectory())
.output(amplifiedTestClass, prettifiedAmplifiedTestMethods);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eu.stamp_project.prettifier;

import eu.stamp_project.test_framework.TestFramework;
import eu.stamp_project.dspot.common.test_framework.TestFramework;
import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.declaration.CtMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eu.stamp_project.prettifier.code2vec;

import eu.stamp_project.prettifier.options.InputConfiguration;
import eu.stamp_project.utils.AmplificationHelper;
import eu.stamp_project.dspot.common.miscellaneous.AmplificationHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eu.stamp_project.prettifier.code2vec;

import eu.stamp_project.utils.AmplificationHelper;
import eu.stamp_project.dspot.common.miscellaneous.AmplificationHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package eu.stamp_project.prettifier.code2vec;

import eu.stamp_project.prettifier.Main;
import eu.stamp_project.prettifier.options.InputConfiguration;
import eu.stamp_project.utils.DSpotUtils;
import eu.stamp_project.dspot.common.miscellaneous.DSpotUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.reflect.declaration.CtMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import eu.stamp_project.prettifier.Main;
import eu.stamp_project.prettifier.output.report.ReportJSON;
import eu.stamp_project.test_framework.TestFramework;
import eu.stamp_project.utils.DSpotUtils;
import eu.stamp_project.dspot.common.test_framework.TestFramework;
import eu.stamp_project.dspot.common.miscellaneous.DSpotUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.reflect.code.*;
Expand All @@ -15,7 +15,7 @@
import java.util.*;
import java.util.stream.Collectors;

import static eu.stamp_project.test_framework.TestFramework.ASSERTIONS_FILTER;
import static eu.stamp_project.dspot.common.test_framework.TestFramework.ASSERTIONS_FILTER;

/**
* Created by Benjamin DANGLOT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package eu.stamp_project.prettifier.minimization;

import eu.stamp_project.automaticbuilder.AutomaticBuilder;
import eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder;
import eu.stamp_project.prettifier.Main;
import eu.stamp_project.prettifier.output.report.ReportJSON;
import eu.stamp_project.test_framework.TestFramework;
import eu.stamp_project.utils.AmplificationHelper;
import eu.stamp_project.utils.DSpotUtils;
import eu.stamp_project.utils.compilation.DSpotCompiler;
import eu.stamp_project.utils.pit.AbstractParser;
import eu.stamp_project.utils.pit.AbstractPitResult;
import eu.stamp_project.utils.pit.PitXMLResultParser;
import eu.stamp_project.utils.program.InputConfiguration;
import eu.stamp_project.dspot.common.test_framework.TestFramework;
import eu.stamp_project.dspot.common.miscellaneous.AmplificationHelper;
import eu.stamp_project.dspot.common.miscellaneous.DSpotUtils;
import eu.stamp_project.dspot.common.compilation.DSpotCompiler;
import eu.stamp_project.dspot.selector.pitmutantscoreselector.AbstractParser;
import eu.stamp_project.dspot.selector.pitmutantscoreselector.AbstractPitResult;
import eu.stamp_project.dspot.selector.pitmutantscoreselector.PitXMLResultParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.reflect.code.CtInvocation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package eu.stamp_project.prettifier.options;

import eu.stamp_project.utils.AmplificationHelper;
import eu.stamp_project.utils.DSpotUtils;
import eu.stamp_project.utils.options.check.InputErrorException;
import eu.stamp_project.dspot.common.miscellaneous.DSpotUtils;
import eu.stamp_project.dspot.common.configuration.check.InputErrorException;
import picocli.CommandLine;

/**
Expand All @@ -11,9 +10,9 @@
* on 11/02/19
*/
@CommandLine.Command(name = "eu.stamp_project.Main", mixinStandardHelpOptions = true)
public class InputConfiguration extends eu.stamp_project.utils.program.InputConfiguration {
public class UserInput extends eu.stamp_project.dspot.common.configuration.UserInput {

public InputConfiguration() {
public UserInput() {

}

Expand All @@ -28,7 +27,7 @@ public String getPathToAmplifiedTestClass() {
return this.pathToAmplifiedTestClass;
}

public InputConfiguration setPathToAmplifiedTestClass(String pathToAmplifiedTestClass) {
public UserInput setPathToAmplifiedTestClass(String pathToAmplifiedTestClass) {
if (!pathToAmplifiedTestClass.endsWith(".java")) {
// TODO must add this error to the global report
throw new InputErrorException();
Expand All @@ -51,7 +50,7 @@ public String getPathToRootOfCode2Vec() {
return pathToRootOfCode2Vec;
}

public InputConfiguration setPathToRootOfCode2Vec(String pathToRootOfCode2Vec) {
public UserInput setPathToRootOfCode2Vec(String pathToRootOfCode2Vec) {
this.pathToRootOfCode2Vec = DSpotUtils.shouldAddSeparator.apply(pathToRootOfCode2Vec);
return this;
}
Expand All @@ -67,7 +66,7 @@ public String getRelativePathToModelForCode2Vec() {
return relativePathToModelForCode2Vec;
}

public InputConfiguration setRelativePathToModelForCode2Vec(String relativePathToModelForCode2Vec) {
public UserInput setRelativePathToModelForCode2Vec(String relativePathToModelForCode2Vec) {
this.relativePathToModelForCode2Vec = relativePathToModelForCode2Vec;
return this;
}
Expand All @@ -78,7 +77,7 @@ public long getTimeToWaitForCode2vecInMillis() {
return this.timeToWaitForCode2vecInMillis;
}

public InputConfiguration setTimeToWaitForCode2vecInMillis(long timeToWaitForCode2vecInMillis) {
public UserInput setTimeToWaitForCode2vecInMillis(long timeToWaitForCode2vecInMillis) {
this.timeToWaitForCode2vecInMillis = timeToWaitForCode2vecInMillis;
return this;
}
Expand All @@ -91,7 +90,7 @@ public String getPathToRootOfContext2Name() {
return pathToRootOfContext2Name;
}

public InputConfiguration setPathToRootOfContext2Name(String pathToRootOfContext2Name) {
public UserInput setPathToRootOfContext2Name(String pathToRootOfContext2Name) {
this.pathToRootOfContext2Name = DSpotUtils.shouldAddSeparator.apply(pathToRootOfContext2Name);
return this;
}
Expand All @@ -102,7 +101,7 @@ public String getRelativePathToModelForContext2Name() {
return relativePathToModelForContext2Name;
}

public InputConfiguration setRelativePathToModelForContext2Name(String relativePathToModelForContext2Name) {
public UserInput setRelativePathToModelForContext2Name(String relativePathToModelForContext2Name) {
this.relativePathToModelForContext2Name = relativePathToModelForContext2Name;
return this;
}
Expand All @@ -113,7 +112,7 @@ public long getTimeToWaitForContext2nameInMillis() {
return this.timeToWaitForContext2nameInMillis;
}

public InputConfiguration setTimeToWaitForContext2nameInMillis(long timeToWaitForContext2nameInMillis) {
public UserInput setTimeToWaitForContext2nameInMillis(long timeToWaitForContext2nameInMillis) {
this.timeToWaitForContext2nameInMillis = timeToWaitForContext2nameInMillis;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package eu.stamp_project.prettifier.output;

import eu.stamp_project.test_framework.TestFramework;
import eu.stamp_project.utils.DSpotUtils;
import eu.stamp_project.utils.program.InputConfiguration;
import eu.stamp_project.dspot.common.test_framework.TestFramework;
import eu.stamp_project.dspot.common.miscellaneous.DSpotUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.reflect.declaration.CtMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package eu.stamp_project;

import eu.stamp_project.dspot.amplifier.value.ValueCreator;
import eu.stamp_project.utils.RandomHelper;
import eu.stamp_project.utils.configuration.DSpotState;
import eu.stamp_project.utils.options.AutomaticBuilderEnum;
import eu.stamp_project.utils.program.InputConfiguration;
import eu.stamp_project.dspot.amplifier.amplifiers.value.ValueCreator;
import eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper;
import eu.stamp_project.dspot.common.configuration.DSpotState;
import eu.stamp_project.dspot.common.configuration.UserInput;
import eu.stamp_project.dspot.common.configuration.options.AutomaticBuilderEnum;
import org.junit.Before;

/**
Expand All @@ -18,13 +18,13 @@ public String getPathToPropertiesFile() {
return "src/test/resources/sample/";
}

protected InputConfiguration configuration;
protected UserInput configuration;

@Before
public void setUp() throws Exception {
RandomHelper.setSeedRandom(72L);
ValueCreator.count = 0;
this.configuration = new InputConfiguration();
this.configuration = new UserInput();
this.configuration.setAbsolutePathToProjectRoot(this.getPathToPropertiesFile());
this.configuration.setVerbose(true);
this.configuration.setBuilderEnum(AutomaticBuilderEnum.Maven);
Expand Down
15 changes: 7 additions & 8 deletions dspot-prettifier/src/test/java/eu/stamp_project/Utils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package eu.stamp_project;

import eu.stamp_project.automaticbuilder.AutomaticBuilder;
import eu.stamp_project.test_framework.TestFramework;
import eu.stamp_project.utils.compilation.DSpotCompiler;
import eu.stamp_project.utils.configuration.DSpotState;
import eu.stamp_project.utils.configuration.InitializeDSpot;
import eu.stamp_project.utils.program.InputConfiguration;
import eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder;
import eu.stamp_project.dspot.common.configuration.UserInput;
import eu.stamp_project.dspot.common.test_framework.TestFramework;
import eu.stamp_project.dspot.common.compilation.DSpotCompiler;
import eu.stamp_project.dspot.common.configuration.InitializeDSpot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.reflect.code.CtLiteral;
Expand All @@ -29,9 +28,9 @@ public class Utils {

public static final Logger LOGGER = LoggerFactory.getLogger(Utils.class);

private static InputConfiguration configuration;
private static UserInput configuration;

public static void init(InputConfiguration configuration) {
public static void init(UserInput configuration) {
InitializeDSpot initializeDSpot = new InitializeDSpot();
final AutomaticBuilder automaticBuilder = configuration.getBuilderEnum().getAutomaticBuilder(configuration);
final String dependencies = initializeDSpot.completeDependencies(configuration, automaticBuilder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eu.stamp_project.prettifier;

import eu.stamp_project.test_framework.TestFramework;
import eu.stamp_project.dspot.common.test_framework.TestFramework;
import org.junit.Test;
import spoon.Launcher;
import spoon.reflect.declaration.CtMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package eu.stamp_project.prettifier.code2vec;

import eu.stamp_project.prettifier.options.InputConfiguration;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eu.stamp_project.prettifier.code2vec;

import eu.stamp_project.utils.AmplificationHelper;
import eu.stamp_project.dspot.common.miscellaneous.AmplificationHelper;
import org.junit.Test;

import static junit.framework.TestCase.assertEquals;
Expand Down
Loading

0 comments on commit ee804de

Please sign in to comment.