Skip to content

Commit

Permalink
add isfork() function
Browse files Browse the repository at this point in the history
  • Loading branch information
psybers committed Nov 19, 2023
1 parent fad8beb commit a1ad663
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
6 changes: 5 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

<target name="-translate-protobuf" depends="-check-protobuf" unless="protobuf.uptodate">
<echo level="error" message="Translating Protocol Buffer files to Java" />
<apply executable="protoc" parallel="true">
<apply executable="protoc" parallel="true">
<arg value="--proto_path=${src.proto}" />
<arg value="--java_out=src/compiled-proto" />
<srcfile />
Expand All @@ -95,6 +95,7 @@

<target name="compile-protobuf" depends="-init,-translate-protobuf,-check-deps" description="Compiles the generated protobuf code.">
<javac includeantruntime="true" srcdir="src/compiled-proto" destdir="build/classes" debug="${debug.enabled}" debuglevel="${debug.level}">
<compilerarg value="-proc:none" />
<classpath refid="project.class.path" />
</javac>
</target>
Expand Down Expand Up @@ -136,6 +137,7 @@

<target name="compile-parser" depends="-parser,-check-deps" description="Compile the parser.">
<javac includeantruntime="true" srcdir="${src.parser.paths}" destdir="build/classes" debug="${debug.enabled}" debuglevel="${debug.level}">
<compilerarg value="-proc:none" />
<compilerarg value="-Xlint:unchecked"/>
<compilerarg value="-Xlint:deprecation"/>
<classpath refid="project.class.path" />
Expand All @@ -151,6 +153,7 @@
<!-- main compilation targets -->
<target name="compile" depends="compile-protobuf,compile-parser,-check-deps" description="Compile the compiler.">
<javac includeantruntime="true" srcdir="${src.paths}" destdir="build/classes" debug="${debug.enabled}" debuglevel="${debug.level}">
<compilerarg value="-proc:none" />
<compilerarg value="-Xlint:unchecked"/>
<compilerarg value="-Xlint:deprecation"/>
<classpath refid="project.class.path" />
Expand Down Expand Up @@ -450,6 +453,7 @@

<target name="-compile-tests" depends="compile,-check-deps">
<javac includeantruntime="true" srcdir="src/test" destdir="build/tests" debug="${debug.enabled}" debuglevel="${debug.level}">
<compilerarg value="-proc:none" />
<compilerarg value="-Xlint:unchecked"/>
<compilerarg value="-Xlint:deprecation"/>
<classpath refid="project.class.path" />
Expand Down
4 changes: 2 additions & 2 deletions src/java/boa/functions/BoaAstIntrinsics.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-20222, Hridesh Rajan, Robert Dyer,
* Copyright 2017-2023, Hridesh Rajan, Robert Dyer,
* Iowa State University of Science and Technology
* Bowling Green State University
* and University of Nebraska Board of Regents
Expand Down Expand Up @@ -64,7 +64,7 @@
*/
public class BoaAstIntrinsics {
@SuppressWarnings("rawtypes")
static Context context;
public static Context context;
private static MapFile.Reader map;
private static MapFile.Reader commentsMap;
private static MapFile.Reader issuesMap;
Expand Down
45 changes: 41 additions & 4 deletions src/java/boa/functions/BoaIntrinsics.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package boa.functions;

import java.io.BufferedInputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -29,6 +31,12 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import boa.datagen.DefaultProperties;
import boa.types.Code.CodeRepository;
import boa.types.Code.Revision;
import boa.types.Diff.ChangedFile;
Expand All @@ -41,12 +49,41 @@
* @author rdyer
*/
public class BoaIntrinsics {
private static Set<Integer> forksData;

private static void loadForksData() {
try {
final Configuration conf = BoaAstIntrinsics.context.getConfiguration();
final FileSystem fs;
final Path p;
if (DefaultProperties.localDataPath != null) {
p = new Path(DefaultProperties.localDataPath, "forks.bin");
fs = FileSystem.getLocal(conf);
} else {
p = new Path(
BoaAstIntrinsics.context.getConfiguration().get("fs.default.name", "hdfs://boa-njt/"),
new Path(conf.get("boa.forks.file", conf.get("boa.ast.dir", conf.get("boa.input.dir", "")) + "/forks.bin"))
);
fs = FileSystem.get(conf);
}

try (final FSDataInputStream data = fs.open(p);
final BufferedInputStream bis = new BufferedInputStream(data);
final ObjectInputStream ois = new ObjectInputStream(bis)) {
forksData = (Set<Integer>)ois.readObject();
}
} catch (final Exception e) {
System.err.println("Error reading forks.bin: " + e.getMessage());
e.printStackTrace();
forksData = new HashSet<Integer>();
}
}

@FunctionSpec(name = "isfork", returnType = "bool", formalParameters = { "Project" })
public static boolean isfork(final Project p) {
final String[] knownForks = { };
final Set<String> forks = new HashSet<>();
Collections.addAll(forks, knownForks);
return p.getForked() || forks.contains(p.getId());
if (forksData == null)
loadForksData();
return p.getForked() || forksData.contains(Integer.parseInt(p.getId()));
}

private final static String[] fixingRegex = {
Expand Down
7 changes: 6 additions & 1 deletion src/java/boa/runtime/BoaRunner.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021, Anthony Urso, Hridesh Rajan, Robert Dyer,
* Copyright 2014-2023, Anthony Urso, Hridesh Rajan, Robert Dyer,
* Iowa State University of Science and Technology
* and University of Nebraska Board of Regents
*
Expand Down Expand Up @@ -120,6 +120,11 @@ public Job job(final Path[] ins, final Path out) throws IOException {
.hasArg()
.withArgName("INPUT")
.create("c"));
options.addOption(org.apache.commons.cli.OptionBuilder.withLongOpt("forks")
.withDescription("which INPUT to use for forks data")
.hasArg()
.withArgName("INPUT")
.create("f"));
options.addOption(org.apache.commons.cli.OptionBuilder.withLongOpt("splitsize")
.withDescription("split size in BYTES")
.hasArg()
Expand Down
2 changes: 2 additions & 0 deletions templates/BoaJavaHadoop.stg
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class <name> extends boa.runtime.BoaRunner {
configuration.set("boa.ast.dir", line.getOptionValue("ast"));
if (line.hasOption("comments"))
configuration.set("boa.comments.dir", line.getOptionValue("comments"));
if (line.hasOption("forks"))
configuration.set("boa.forks.file", line.getOptionValue("forks"));

if (line.hasOption("splitsize"))
configuration.setInt("mapred.max.split.size", Integer.parseInt(line.getOptionValue("splitsize")));
Expand Down

0 comments on commit a1ad663

Please sign in to comment.