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 2f027db commit 5eaa832
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
</natures>
<filteredResources>
<filter>
<id>1625891463658</id>
<id>1700381069244</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
Expand Down
7 changes: 4 additions & 3 deletions src/java/boa/functions/BoaAstIntrinsics.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright 2017, Hridesh Rajan, Robert Dyer,
* Copyright 2023, Hridesh Rajan, Robert Dyer,
* Iowa State University of Science and Technology
* and Bowling Green State University
* Bowling Green State University
* and University of Nebraska Board of Regents
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -63,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
47 changes: 46 additions & 1 deletion src/java/boa/functions/BoaIntrinsics.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021, Hridesh Rajan, Robert Dyer,
* Copyright 2014-2023, Hridesh Rajan, Robert Dyer,
* Iowa State University of Science and Technology
* and University of Nebraska Board of Regents
*
Expand All @@ -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,6 +49,43 @@
* @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) {
if (forksData == null)
loadForksData();
return p.getForked() || forksData.contains(Integer.parseInt(p.getId()));
}

private final static String[] fixingRegex = {
"\\bfix(s|es|ing|ed)?\\b",
"\\b(error|bug|issue)(s)?\\b",
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 5eaa832

Please sign in to comment.