From a326b39794391b142b4cd7eefadfb1be0b675a5d Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Sun, 19 Nov 2023 02:03:35 -0600 Subject: [PATCH] add isfork() function --- .project | 4 +- src/java/boa/functions/BoaAstIntrinsics.java | 7 +-- src/java/boa/functions/BoaIntrinsics.java | 50 +++++++++++++++++++- src/java/boa/runtime/BoaRunner.java | 7 ++- templates/BoaJavaHadoop.stg | 2 + 5 files changed, 62 insertions(+), 8 deletions(-) diff --git a/.project b/.project index 5d1a63b9f..939331fcb 100644 --- a/.project +++ b/.project @@ -16,12 +16,12 @@ - 1625891463658 + 1700380680913 30 org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ diff --git a/src/java/boa/functions/BoaAstIntrinsics.java b/src/java/boa/functions/BoaAstIntrinsics.java index 9d4b4ea3b..f5cdfa64b 100644 --- a/src/java/boa/functions/BoaAstIntrinsics.java +++ b/src/java/boa/functions/BoaAstIntrinsics.java @@ -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. @@ -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; diff --git a/src/java/boa/functions/BoaIntrinsics.java b/src/java/boa/functions/BoaIntrinsics.java index 23c244856..2d89cb989 100644 --- a/src/java/boa/functions/BoaIntrinsics.java +++ b/src/java/boa/functions/BoaIntrinsics.java @@ -1,6 +1,7 @@ /* - * Copyright 2014, Hridesh Rajan, Robert Dyer, - * and Iowa State University of Science and Technology + * Copyright 2023, Hridesh Rajan, Robert Dyer, + * Iowa State University of Science and Technology + * 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. @@ -16,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; @@ -28,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; @@ -40,6 +49,43 @@ * @author rdyer */ public class BoaIntrinsics { + private static Set 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)ois.readObject(); + } + } catch (final Exception e) { + System.err.println("Error reading forks.bin: " + e.getMessage()); + e.printStackTrace(); + forksData = new HashSet(); + } + } + + @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", diff --git a/src/java/boa/runtime/BoaRunner.java b/src/java/boa/runtime/BoaRunner.java index 686b9da5f..bf1ae524d 100644 --- a/src/java/boa/runtime/BoaRunner.java +++ b/src/java/boa/runtime/BoaRunner.java @@ -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 * @@ -121,6 +121,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() diff --git a/templates/BoaJavaHadoop.stg b/templates/BoaJavaHadoop.stg index 20ef4ae6a..d69dda50f 100644 --- a/templates/BoaJavaHadoop.stg +++ b/templates/BoaJavaHadoop.stg @@ -56,6 +56,8 @@ public class 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")));