Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
simonAllier committed Mar 27, 2014
1 parent 231df59 commit d19a935
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 44 deletions.
1 change: 1 addition & 0 deletions grid5000.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
sleep 20
cd /root/diversify-statements
git pull
mvn clean package
Expand Down
1 change: 0 additions & 1 deletion runFromGit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ for i in `seq 1 $1`
do
for j in `seq 1 $cpu`
do
sleep 2
java -Xmx2000m -Dhttp.proxyHost=proxy.rennes.grid5000.fr -Dhttp.proxyPort=3128 -jar target/Diversify-statements-1.0-SNAPSHOT-jar-with-dependencies.jar $(cat propertiesFile) > out_$i_$j &
done
wait
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/fr/inria/diversify/DiversifyMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,14 @@ protected void computeDiversifyStat(String transDir, String fileName) throws Exc
TransformationParser tf = new TransformationParser(true);
// TransformationOldParser tf = new TransformationOldParser(true);
Collection<Transformation> transformations = tf.parseDir(transDir);
long fail = transformations.stream().filter(t -> t.getStatus() == -1).count();
long sosie = transformations.stream().filter(t -> t.getStatus() == 0).count();
TransformationsWriter write = new TransformationsWriter(transformations, fileName);


FailureMatrix matrix = new FailureMatrix(transformations,DiversifyProperties.getProperty("allTestFile"));
matrix.printMatrix(fileName+"_matrix.csv");

// Log.info("nb stmt transformable {}",test());
Log.debug("all transformation type : {}", getAllTransformationType(transformations));
write.writeAllTransformation(null);
Expand All @@ -252,8 +258,7 @@ protected void computeDiversifyStat(String transDir, String fileName) throws Exc
for(String type : getAllTransformationType(transformations))
write.writeGoodTransformation(type);

FailureMatrix matrix = new FailureMatrix(transformations,DiversifyProperties.getProperty("allTestFile"));
matrix.printMatrix(fileName+"_matrix.csv");


Visu v = new Visu(fileName+"_visu/visu");
v.writeJSON(transformations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public Class<?> getCodeFragmentType() {
}

public CtSimpleType<?> getSourceClass() {
return codeFragment.getParent(CtSimpleType.class);
return getCompilationUnit().getMainType();
}

public int getStartLine() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ protected List<String> buildMatrix() {
StringBuilder sb = new StringBuilder();
List<String> failures = transformation.getFailures();
for(String test: allTest) {
if(failures.contains(test))
if(failures.contains(test)){
sb.append(";1");
}
else
sb.append(";0");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,26 @@ public void apply(String srcDir) throws Exception {
removeSourceCode();
}

public void applyWithParent(String srcDir) throws Exception { throw new Exception("not implemented");};
public void restore(String srcDir) throws Exception {
if(parent != null) {
parent.removeSourceCode();
parent.printJavaFile(srcDir);
}
removeSourceCode();
printJavaFile(srcDir);
}

public void applyWithParent(String srcDir) throws Exception {
addSourceCode();
printJavaFile(srcDir);

if(parent != null) {
parent.addSourceCode();
parent.printJavaFile(srcDir);
parent.removeSourceCode();
}
removeSourceCode();
}

protected boolean equalParent(Transformation otherParent) {
if(parent != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ protected JSONObject getObject(JSONArray array, int index) {

protected Transformation parseTransformation(JSONObject jsonObject) {
try {

String type = jsonObject.getString("type");
Transformation trans = null;

Expand All @@ -154,6 +155,7 @@ protected Transformation parseTransformation(JSONObject jsonObject) {

return trans;
}catch (Exception e) {
countError++;
// Log.warn("error during the parsing of "+jsonObject,e);
return null;
}
Expand Down Expand Up @@ -279,6 +281,7 @@ protected Transformation parseStmt(JSONObject jsonObject) throws Exception {
trans = parseASTDelete(jsonObject);

trans.setName(jsonObject.getString("name"));
String p = jsonObject.getJSONObject("transplantationPoint").getString("position");
trans.setTransplantationPoint(findCodeFragment(jsonObject.getJSONObject("transplantationPoint")));
return trans;
}
Expand Down Expand Up @@ -415,15 +418,34 @@ protected ASTTransformation parseASTReplace(JSONObject jsonObject) throws Except

protected CodeFragment findCodeFragment(JSONObject jsonObject) throws Exception {
CodeFragment cf = null;
String position = jsonObject.getString("position");
for (CodeFragment codeFragment : DiversifyEnvironment.getCodeFragments()) {
try {
if (codeFragment.positionString().equals(jsonObject.get("position")) ){

if (codeFragment.positionString().equals(position) ){
cf = codeFragment;
break;
}
} catch (Exception e) {}
}
if (cf == null) {
int count = 0;
for (CodeFragment codeFragment : DiversifyEnvironment.getCodeFragments()) {
try {
position = position.split(":")[0];
if(codeFragment.positionString().startsWith(position)) {
count++;
String sourceCode = jsonObject.getString("sourceCode");
String cfSourceCode = codeFragment.equalString();
if(sourceCode.equals(cfSourceCode)) {
cf = codeFragment;
break;
}
}
} catch (Exception e) {}
}
}
if(cf == null) {
throw new Exception();
}
return cf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,6 @@ public abstract class ASTTransformation extends AbstractTransformation {

public ASTTransformation() {}

public void applyWithParent(String srcDir) throws Exception {
addSourceCode();
printJavaFile(srcDir);

if(parent != null) {
parent.addSourceCode();
parent.printJavaFile(srcDir);
parent.removeSourceCode();
}
removeSourceCode();
}

public void restore(String srcDir) throws Exception {
if(parent != null) {
parent.removeSourceCode();
parent.printJavaFile(srcDir);
}
removeSourceCode();
printJavaFile(srcDir);
}

public void printJavaFile(String directory) throws IOException {
CtSimpleType<?> type = getOriginalClass(transplantationPoint);
Factory factory = type.getFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ public void addSourceCode() {
compileUnit.addSourceCodeFragment(new SourceCodeFragment(sp.getSourceEnd()+1, "**/"+mutant.toString(), 0));
}

public void restore(String srcDir) throws Exception {
removeSourceCode();
printJavaFile(srcDir);
}

public void printJavaFile(String directory) throws IOException {
CtSimpleType<?> type = operator.getPosition().getCompilationUnit().getMainType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ public void addSourceCode() throws Exception {
compileUnit.addSourceCodeFragment(new SourceCodeFragment(sp.getSourceEnd()+1, "**/"+newLiteral, 0));
}

public void restore(String srcDir) throws Exception {
removeSourceCode();
printJavaFile(srcDir);
}

public void printJavaFile(String directory) throws IOException {
CtSimpleType<?> type = inlineConstant.getPosition().getCompilationUnit().getMainType();
Factory factory = type.getFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ public void addSourceCode() throws Exception {
compileUnit.addSourceCodeFragment(new SourceCodeFragment(sp.getSourceEnd()+1, "**/"+newLiteral, 0));
}

public void restore(String srcDir) throws Exception {
removeSourceCode();
printJavaFile(srcDir);
}

public void printJavaFile(String directory) throws IOException {
CtSimpleType<?> type = ret.getPosition().getCompilationUnit().getMainType();
Factory factory = type.getFactory();
Expand Down
4 changes: 2 additions & 2 deletions utils/dagger/gridAll.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ classes=core/target/classes

nbRun=100
timeOut=-1
result=all/cdagger/trans
result=all/dagger/trans
gitRepository=repo
transformation.size=1
transformation.type=all
jacoco=utils/dagger/jacoco.exec
#jacoco=utils/dagger/jacoco.exec
javaVersion=6

0 comments on commit d19a935

Please sign in to comment.