Skip to content

Commit 6f62795

Browse files
author
Andreas Dann
committed
add sootdiff source code
1 parent 521bedd commit 6f62795

29 files changed

+2940
-0
lines changed

pom.xml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>de.upb</groupId>
8+
<artifactId>sootdiff</artifactId>
9+
<version>1.0</version>
10+
11+
<properties>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
15+
</properties>
16+
17+
18+
<build>
19+
<plugins>
20+
21+
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<version>${maven-compiler-plugin.version}</version>
26+
<configuration>
27+
<source>${maven.compiler.source}</source>
28+
<target>${maven.compiler.target}</target>
29+
</configuration>
30+
31+
</plugin>
32+
33+
<plugin>
34+
<artifactId>maven-assembly-plugin</artifactId>
35+
<configuration>
36+
<archive>
37+
<manifest>
38+
<mainClass>de.upb.soot.diff.Main</mainClass>
39+
</manifest>
40+
</archive>
41+
<descriptorRefs>
42+
<descriptorRef>jar-with-dependencies</descriptorRef>
43+
</descriptorRefs>
44+
</configuration>
45+
</plugin>
46+
47+
</plugins>
48+
</build>
49+
50+
51+
<dependencies>
52+
<dependency>
53+
<groupId>ca.mcgill.sable</groupId>
54+
<artifactId>soot</artifactId>
55+
<version>3.2.0-SNAPSHOT</version>
56+
</dependency>
57+
58+
59+
<dependency>
60+
<groupId>commons-cli</groupId>
61+
<artifactId>commons-cli</artifactId>
62+
<version>1.4</version>
63+
</dependency>
64+
65+
66+
<dependency>
67+
<groupId>org.apache.commons</groupId>
68+
<artifactId>commons-lang3</artifactId>
69+
<version>3.8.1</version>
70+
</dependency>
71+
72+
<dependency>
73+
<groupId>io.github.java-diff-utils</groupId>
74+
<artifactId>java-diff-utils</artifactId>
75+
<version>4.0</version>
76+
</dependency>
77+
<dependency>
78+
<groupId>junit</groupId>
79+
<artifactId>junit</artifactId>
80+
<version>4.12</version>
81+
<scope>test</scope>
82+
</dependency>
83+
84+
</dependencies>
85+
<repositories>
86+
<repository>
87+
<id>soot-snapshot</id>
88+
<name>soot snapshots</name>
89+
<url>https://soot-build.cs.uni-paderborn.de/nexus/repository/swt-upb/</url>
90+
</repository>
91+
</repositories>
92+
93+
</project>
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package de.upb.soot.diff;
2+
3+
import org.apache.commons.lang3.builder.DiffBuilder;
4+
import org.apache.commons.lang3.builder.DiffResult;
5+
import org.apache.commons.lang3.builder.Diffable;
6+
import org.apache.commons.lang3.builder.ToStringStyle;
7+
import soot.SootClass;
8+
import soot.SootField;
9+
import soot.SootMethod;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
import java.util.stream.Collectors;
14+
15+
16+
//FIXME: remove the old version
17+
/** @author Andreas Dann created on 06.12.18 */
18+
public class DiffSootClass implements Diffable<DiffSootClass> {
19+
20+
public SootClass sootClass;
21+
22+
public DiffSootClass(SootClass sootClass) {
23+
this.sootClass = sootClass;
24+
}
25+
26+
27+
//instead of this it may make sense to subclass the diffbuilder....
28+
29+
public DiffResult diff(DiffSootClass rhs) {
30+
DiffBuilder diffBuilder = new DiffBuilder(this, rhs, ToStringStyle.JSON_STYLE);
31+
diffBuilder =
32+
diffBuilder.append("name", sootClass.getJavaStyleName(), rhs.sootClass.getJavaStyleName());
33+
34+
diffBuilder =
35+
diffBuilder.append("modifier", sootClass.getModifiers(), rhs.sootClass.getModifiers());
36+
37+
// check the implemented interfaces
38+
39+
List<String> lhsInterFaces =
40+
sootClass
41+
.getInterfaces()
42+
.stream()
43+
.map(intf -> intf.getJavaStyleName())
44+
.collect(Collectors.toList());
45+
46+
List<String> rhsInterfaces =
47+
rhs.sootClass
48+
.getInterfaces()
49+
.stream()
50+
.map(intf -> intf.getJavaStyleName())
51+
.collect(Collectors.toList());
52+
53+
diffBuilder = diffBuilder.append("interfaces", lhsInterFaces, rhsInterfaces);
54+
55+
// check the super classes
56+
57+
String lhsSuperClasses = sootClass.getSuperclass().getJavaStyleName();
58+
59+
String rhsSuperClasses = rhs.sootClass.getSuperclass().getJavaStyleName();
60+
61+
diffBuilder = diffBuilder.append("superclass", lhsSuperClasses, rhsSuperClasses);
62+
63+
// check the fields
64+
65+
List<SootField> rhsFieldsToVisit = new ArrayList<>(rhs.sootClass.getFields());
66+
67+
// append the diff results of the methods ...
68+
for (SootField lhsField : this.sootClass.getFields()) {
69+
try {
70+
SootField rhsField = rhs.sootClass.getField(lhsField.getSubSignature());
71+
diffBuilder =
72+
diffBuilder.append(
73+
lhsField.getName(), lhsField.getSignature(), rhsField.getSignature());
74+
75+
// remove from the methods to visit
76+
rhsFieldsToVisit.remove(rhsField);
77+
78+
} catch (RuntimeException ex) {
79+
// no corresponding righthand method found
80+
// dummy method to compute diff
81+
diffBuilder = diffBuilder.append(lhsField.getName(), lhsField.getSignature(), null);
82+
}
83+
}
84+
85+
// get the diff for fields that are in the right class but not in the lhs
86+
for (SootField rhsField : rhsFieldsToVisit) {
87+
// no lhsMethod exists
88+
// create dummy lhsMethod
89+
// SootField lhsField = new SootField(null, null, 0);
90+
diffBuilder = diffBuilder.append(rhsField.getName(), null, rhsField.getSignature());
91+
}
92+
93+
// check the methods
94+
List<SootMethod> rhsMethodsToVisit = new ArrayList<>(rhs.sootClass.getMethods());
95+
96+
// append the diff results of the methods ...
97+
for (SootMethod lhsMethod : this.sootClass.getMethods()) {
98+
try {
99+
SootMethod rhsMethod = rhs.sootClass.getMethod(lhsMethod.getSubSignature());
100+
DiffResult diff = new DiffSootMethod(lhsMethod).diff(new DiffSootMethod(rhsMethod));
101+
diffBuilder = diffBuilder.append(lhsMethod.getName(), diff);
102+
103+
// remove from the methods to visit
104+
rhsMethodsToVisit.remove(rhsMethod);
105+
106+
} catch (RuntimeException ex) {
107+
// no corresponding righthand method found
108+
// dummy method to compute diff
109+
diffBuilder = diffBuilder.append(lhsMethod.getName(), new DiffSootMethod(lhsMethod), null);
110+
}
111+
}
112+
113+
// get the diff for methods that are in the right class but not in the lhs
114+
for (SootMethod rhsMethod : rhsMethodsToVisit) {
115+
// no lhsMethod exists
116+
// create dummy lhsMethod
117+
SootMethod lhsMethod = null;
118+
// DiffResult diff = new DiffSootMethod(lhsMethod).diff(new DiffSootMethod(rhsMethod));
119+
diffBuilder = diffBuilder.append(rhsMethod.getName(), null, new DiffSootMethod(rhsMethod));
120+
}
121+
122+
return diffBuilder.build();
123+
}
124+
}

0 commit comments

Comments
 (0)