Skip to content
This repository was archived by the owner on Sep 14, 2022. It is now read-only.

Commit

Permalink
Ready to benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
steindani committed Oct 18, 2014
1 parent 1174863 commit b7ec3c4
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml

target/
#target/
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,11 @@
<version>3.4.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>

</dependencies>
</project>
13 changes: 13 additions & 0 deletions queries/csmr-a.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?sw
WHERE
{
?sw rdf:type <http://www.emftext.org/java/statements#//Switch> .

OPTIONAL {
?sw <http://www.emftext.org/java/statements#//Switch/cases> ?sc .
?sc rdf:type <http://www.emftext.org/java/statements#//DefaultSwitchCase>
}
FILTER (!BOUND(?sc))
}
15 changes: 15 additions & 0 deletions queries/csmr-b.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT ?cb
WHERE
{
?cb <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.emftext.org/java/statements#//CatchBlock> .
?cb <http://www.emftext.org/java/statements#//CatchBlock/parameter>
?cbParam .

?io <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.emftext.org/java/expressions#//InstanceOfExpression> .
?io <http://www.emftext.org/java/expressions#//InstanceOfExpression/child>
?ioChild .
?ioChild <http://www.emftext.org/java/references#//ElementReference/target>
?cbParam
}
34 changes: 34 additions & 0 deletions queries/csmr-c.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
PREFIX java: <https://www.java.com/>
PREFIX xannotations: <http://www.emftext.org/java/annotations#/>
PREFIX xarrays: <http://www.emftext.org/java/arrays#/>
PREFIX xclassifiers: <http://www.emftext.org/java/classifiers#/>
PREFIX xcommons: <http://www.emftext.org/java/commons#/>
PREFIX xcontainers: <http://www.emftext.org/java/containers#/>
PREFIX xexpressions: <http://www.emftext.org/java/expressions#/>
PREFIX xgenerics: <http://www.emftext.org/java/generics#/>
PREFIX ximports: <http://www.emftext.org/java/imports#/>
PREFIX xinstantiations: <http://www.emftext.org/java/instantiations#/>
PREFIX xliterals: <http://www.emftext.org/java/literals#/>
PREFIX xmembers: <http://www.emftext.org/java/members#/>
PREFIX xmodifiers: <http://www.emftext.org/java/modifiers#/>
PREFIX xoperators: <http://www.emftext.org/java/operators#/>
PREFIX xparameters: <http://www.emftext.org/java/parameters#/>
PREFIX xreferences: <http://www.emftext.org/java/references#/>
PREFIX xstatements: <http://www.emftext.org/java/statements#/>
PREFIX xtypes: <http://www.emftext.org/java/types#/>
PREFIX xvariables: <http://www.emftext.org/java/variables#/>

PREFIX base: <http://www.semanticweb.org/ontologies/2011/1/TrainRequirementOntology.owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?addEx
WHERE
{
?addEx rdf:type <http://www.emftext.org/java/expressions#//AdditiveExpression> .
?addEx <http://www.emftext.org/java/expressions#//AdditiveExpression/children> ?strRef .
?strRef <http://www.emftext.org/java/references#//StringReference/value> ""^^<http://www.w3.org/2001/XMLSchema#string> .
?addEx <http://www.emftext.org/java/expressions#//AdditiveExpression/additiveOperators> ?addOp .
?addOp rdf:type <http://www.emftext.org/java/operators#//Addition> .
}
22 changes: 22 additions & 0 deletions queries/csmr-d.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX java: <http://www.emftext.org/java/>
PREFIX commons: <http://www.emftext.org/commons/>

SELECT ?methodCall
WHERE
{
?ref rdf:type <java:references#//Reference> .
?ref <java:references#//Reference/next> ?methodCall .
?ref <java:references#//ElementReference/target> ?var .
?var rdf:type <java:variables#//Variable> .

?eqLayout rdf:type <commons:layout#//ReferenceLayoutInformation> .
?eqLayout <commons:layout#//LayoutInformation/visibleTokenText>
"equals"^^<http://www.w3.org/2001/XMLSchema#string> .
?eqLayout <commons:layout#//ReferenceLayoutInformation/object> ?eqEnumID .

?methodCall rdf:type <java:references#//MethodCall> .
?methodCall <java:references#//ElementReference/target> ?eqEnumID .
?methodCall <java:references#//Argumentable/arguments> ?arg .
?arg rdf:type <java:references#//StringReference> .
}
137 changes: 97 additions & 40 deletions src/main/java/hu/bme/mit/codemodel/jamoppdiscoverer/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.UnknownHostException;
import java.util.*;
import java.util.Arrays;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class CommandParser {

Expand All @@ -24,7 +28,8 @@ public class CommandParser {
protected String newFilesListPath = null;
protected String modifiedFilesListPath = null;
protected String deletedFilesListPath = null;
// protected String gitOutputPath = null;
protected static final int NTHREDS = 2;
// protected String gitOutputPath = null;

// -----------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -57,6 +62,77 @@ public void processArguments(String[] args) {

public void execute() {

long dgStart = System.currentTimeMillis();
processChanges();
System.out.println("[DepGraph] " + (System.currentTimeMillis() - dgStart));


long agsStart = System.currentTimeMillis();
processFiles();
System.out.println("[ASG] " + (System.currentTimeMillis() - agsStart));
}

protected void processFiles() {
// ----------------------------------------------------------------------------------------------------- PROCESS

try {
DependencyManager dm = DependencyManager.getInstance();

// MultiMap of packages, and the files inside them
HashMultimap<String, String> packageAndFiles = HashMultimap.create();

for (String path : ChangeProcessor.getFilesToProcess()) {
String relativePath = RelativePath.of(path);

Dependency dependency = dm.find(relativePath);
if (dependency != null) {
String packageName = dependency.getPackageName();

if (!"".equals(packageName)) {
packageAndFiles.get(packageName).add(relativePath);
}
} else {
packageAndFiles.get("").add(relativePath);
}
}

// processing packages separately
Set<String> packages = packageAndFiles.keys().elementSet();

// for (String p : packages) {
// FileDiscoverer packageDiscoverer = new FileDiscoverer(p);
//
// for (String file : packageAndFiles.get(p)) {
// packageDiscoverer.execute(new File(file));
// }
// }



ExecutorService executor = Executors.newFixedThreadPool(NTHREDS);

for (String p : packages) {

ParserProcess process = new ParserProcess(p, packageAndFiles.get(p));
executor.execute(process);

}

// This will make the executor accept no new threads
// and finish all existing threads in the queue
executor.shutdown();
// Wait until all threads are finish
executor.awaitTermination(9999999, TimeUnit.DAYS);


} catch (UnknownHostException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

protected void processChanges() {
// --------------------------------------------------------------------------------------------------------- NEW

if (newFilesListPath != null) {
Expand Down Expand Up @@ -99,53 +175,34 @@ public void execute() {
File f = new File("toprocess/");
FileIterator.iterate(f, new InitializationIterator());
}
}

// ----------------------------------------------------------------------------------------------------- PROCESS

try {
DependencyManager dm = DependencyManager.getInstance();
protected void printHelp() {
HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(120);

// MultiMap of packages, and the files inside them
HashMultimap<String, String> packageAndFiles = HashMultimap.create();
formatter.printHelp("java -jar JaMoPPDiscoverer.jar [options]", "options:", options, "", false);
System.out.println();
}

for (String path : ChangeProcessor.getFilesToProcess()) {
String relativePath = RelativePath.of(path);
protected class ParserProcess implements Runnable {

Dependency dependency = dm.find(relativePath);
if (dependency != null) {
String packageName = dependency.getPackageName();
protected String packageName = null;
protected Set<String> files = null;

if (!"".equals(packageName)) {
packageAndFiles.get(packageName).add(relativePath);
}
} else {
packageAndFiles.get("").add(relativePath);
}
}

// processing packages separately
Set<String> packages = packageAndFiles.keys().elementSet();
public ParserProcess(String packageName, Set<String> files) {
this.packageName = packageName;
this.files = files;
}

for (String p : packages) {
FileDiscoverer packageDiscoverer = new FileDiscoverer(p);
@Override
public void run() {
FileDiscoverer packageDiscoverer = new FileDiscoverer(packageName);

for (String file : packageAndFiles.get(p)) {
packageDiscoverer.execute(new File(file));
}
for (String file : files) {
packageDiscoverer.execute(new File(file));
}


} catch (UnknownHostException e) {
e.printStackTrace();
}

}

protected void printHelp() {
HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(120);

formatter.printHelp("java -jar JaMoPPDiscoverer.jar [options]", "options:", options, "", false);
System.out.println();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import hu.bme.mit.codemodel.jamoppdiscoverer.utils.RelativePath;
import hu.bme.mit.codemodel.jamoppdiscoverer.whitepages.DependencyManager;
import hu.bme.mit.codemodel.jamoppdiscoverer.whitepages.pojo.Dependency;
import org.apache.commons.lang.StringEscapeUtils;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
Expand All @@ -27,10 +28,12 @@
import java.io.*;
import java.net.UnknownHostException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FileDiscoverer implements FileIterator.Function {

protected static final int DEBUG_LEVEL = 0;
protected static final int DEBUG_LEVEL = -9001;
protected static DependencyManager dependencyManager = null;
private final JavaClasspath cp;
protected String rootPath = new File("").getAbsolutePath() + "/";
Expand All @@ -42,6 +45,10 @@ public class FileDiscoverer implements FileIterator.Function {
protected Set<Resource> basePackageResources = new HashSet<>();
protected Long packageSize = 0L;
protected Long packageCount = 0L;
protected static Pattern literalPattern = Pattern.compile("^(.*?)(\\^\\^.*)$");

// protected static ResourceSet cprs = new ResourceSetImpl();
// protected static JavaClasspath scp = JavaClasspath.get(cprs);

public FileDiscoverer(String packageName) {

Expand Down Expand Up @@ -69,12 +76,25 @@ public FileDiscoverer(String packageName) {

// init ResourceSet
resourceSet.getLoadOptions().put(JavaClasspath.OPTION_USE_LOCAL_CLASSPATH, Boolean.TRUE);
// resourceSet.getLoadOptions().put(JavaClasspath.OPTION_REGISTER_STD_LIB, Boolean.TRUE);

// TODO make this configurable
resourceSet.getLoadOptions().put(IJavaOptions.DISABLE_LAYOUT_INFORMATION_RECORDING, Boolean.TRUE);

cp = JavaClasspath.get(resourceSet);
cp.registerStdLib();
cp.registerSourceOrClassFileFolder(URI.createFileURI(rootPath + INPUT_DIRECTORY));
// scp.registerStdLib();
//
// Map<String, List<String>> packageClassifierMap = scp.getPackageClassifierMap();
// for(String p : packageClassifierMap.keySet()) {
// cp.getPackageClassifierMap().put(p, new ArrayList<String>(packageClassifierMap.get(p)));
// }
//
// resourceSet.getURIConverter().getURIMap().putAll(cprs.getURIConverter().getURIMap());

// javaClasspath.registerStdLib();
// resourceSet.getjavaClasspath.getDefaultImports();
// cp.registerStdLib();
// cp.registerSourceOrClassFileFolder(URI.createFileURI(rootPath + INPUT_DIRECTORY));


loadPackageResources();
Expand Down Expand Up @@ -422,7 +442,17 @@ protected String exportTTL(Resource target) {
// if (DEBUG_LEVEL > 0) System.out.println("\t" + _attribute.getName() + ":\t" + attributeValue + "\t" + attributeType);

String attributeString = ResourceFactory.createTypedLiteral(attribute).toString();
w.println("<" + objectURI + "> <" + attributeURI + "> '''" + attributeString.replace("^^", "'''^^<") + "> .");
String toSaveString = "";

Matcher matcher = literalPattern.matcher(attributeString);

if (matcher.matches()) {
toSaveString = "'''" + StringEscapeUtils.escapeJava(matcher.group(1)) + "'''" + matcher.group(2).replace("^^", "^^<") + ">";
} else {
toSaveString = "'''" + attributeString.replace("^^", "'''^^<") + ">";
}

w.println("<" + objectURI + "> <" + attributeURI + "> " + toSaveString + " .");
}

// --------------------------------------------------------------------------------------- REFERENCE
Expand Down
7 changes: 7 additions & 0 deletions target/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*

!.gitignore

!import-check.sh
!transform.sh
!transform-import-check.sh
Loading

0 comments on commit b7ec3c4

Please sign in to comment.