diff --git a/build.xml b/build.xml index dd3193b59..2a80fddfb 100644 --- a/build.xml +++ b/build.xml @@ -85,7 +85,7 @@ - + @@ -175,15 +175,18 @@ - + + + + @@ -198,6 +201,7 @@ + @@ -212,6 +216,7 @@ + @@ -226,13 +231,14 @@ + - + @@ -240,6 +246,7 @@ + @@ -253,6 +260,7 @@ + @@ -266,6 +274,7 @@ + @@ -279,6 +288,7 @@ + @@ -289,6 +299,7 @@ + @@ -299,6 +310,7 @@ + @@ -312,6 +324,7 @@ + @@ -322,6 +335,7 @@ + @@ -332,6 +346,7 @@ + @@ -346,6 +361,7 @@ + @@ -369,13 +385,8 @@ - - - - - - + @@ -390,6 +401,13 @@ + + + + + + + @@ -415,7 +433,7 @@ - + diff --git a/src/java/boa/datagen/util/ProtoMessageVisitor.java b/src/test/boa/test/datagen/ProtoMessageVisitor.java similarity index 98% rename from src/java/boa/datagen/util/ProtoMessageVisitor.java rename to src/test/boa/test/datagen/ProtoMessageVisitor.java index 1be0c409f..640e6ac1d 100644 --- a/src/java/boa/datagen/util/ProtoMessageVisitor.java +++ b/src/test/boa/test/datagen/ProtoMessageVisitor.java @@ -1,4 +1,4 @@ -package boa.datagen.util; +package boa.test.datagen; import java.util.Iterator; import java.util.List; diff --git a/src/test/boa/test/datagen/TestSequenceFile.java b/src/test/boa/test/datagen/TestSequenceFile.java index 980604863..eb7406dce 100644 --- a/src/test/boa/test/datagen/TestSequenceFile.java +++ b/src/test/boa/test/datagen/TestSequenceFile.java @@ -27,7 +27,6 @@ import boa.datagen.BoaGenerator; import boa.datagen.DefaultProperties; import boa.datagen.util.FileIO; -import boa.datagen.util.ProtoMessageVisitor; import boa.functions.BoaIntrinsics; import boa.test.datagen.java.Java8BaseTest; import boa.types.Ast.ASTRoot; diff --git a/src/test/boa/test/datagen/TestTypeFullyQualifiedName.java b/src/test/boa/test/datagen/TestTypeFullyQualifiedName.java index 6585cb01e..1a3f48389 100644 --- a/src/test/boa/test/datagen/TestTypeFullyQualifiedName.java +++ b/src/test/boa/test/datagen/TestTypeFullyQualifiedName.java @@ -14,7 +14,7 @@ import com.google.protobuf.CodedInputStream; import com.google.protobuf.Message; -import boa.datagen.util.ProtoMessageVisitor; + import boa.types.Ast.ASTRoot; import boa.types.Ast.Declaration; import boa.types.Ast.Expression; diff --git a/src/test/boa/test/datagen/ASTDumper.java b/src/test/boa/test/datagen/java/ASTDumper.java similarity index 99% rename from src/test/boa/test/datagen/ASTDumper.java rename to src/test/boa/test/datagen/java/ASTDumper.java index 8a49a5463..a7e2ef79c 100644 --- a/src/test/boa/test/datagen/ASTDumper.java +++ b/src/test/boa/test/datagen/java/ASTDumper.java @@ -13,7 +13,7 @@ // is preserved, and any changes are properly documented. // -package boa.test.datagen; +package boa.test.datagen.java; import java.util.ArrayList; import java.util.Iterator; diff --git a/src/test/boa/test/datagen/java/DumpJava.java b/src/test/boa/test/datagen/java/DumpJava.java index 573859ab8..f2d3c5788 100644 --- a/src/test/boa/test/datagen/java/DumpJava.java +++ b/src/test/boa/test/datagen/java/DumpJava.java @@ -1,5 +1,5 @@ /* - * Copyright 2017, Robert Dyer, + * Copyright 2017, Robert Dyer, * and Bowling Green State University * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/test/boa/test/datagen/IASTPrinter.java b/src/test/boa/test/datagen/java/IASTPrinter.java similarity index 98% rename from src/test/boa/test/datagen/IASTPrinter.java rename to src/test/boa/test/datagen/java/IASTPrinter.java index 6fe02d027..6104fcb88 100644 --- a/src/test/boa/test/datagen/IASTPrinter.java +++ b/src/test/boa/test/datagen/java/IASTPrinter.java @@ -13,7 +13,7 @@ // is preserved, and any changes are properly documented. // -package boa.test.datagen; +package boa.test.datagen.java; /** * SAX-style printer for outputting AST nodes. diff --git a/src/test/boa/test/datagen/ICommentsExtractor.java b/src/test/boa/test/datagen/java/ICommentsExtractor.java similarity index 97% rename from src/test/boa/test/datagen/ICommentsExtractor.java rename to src/test/boa/test/datagen/java/ICommentsExtractor.java index a688786b8..95f761133 100644 --- a/src/test/boa/test/datagen/ICommentsExtractor.java +++ b/src/test/boa/test/datagen/java/ICommentsExtractor.java @@ -13,7 +13,7 @@ // is preserved, and any changes are properly documented. // -package boa.test.datagen; +package boa.test.datagen.java; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.Comment; diff --git a/src/test/boa/test/datagen/Indenter.java b/src/test/boa/test/datagen/java/Indenter.java similarity index 97% rename from src/test/boa/test/datagen/Indenter.java rename to src/test/boa/test/datagen/java/Indenter.java index 85fd60b24..df7156eb6 100644 --- a/src/test/boa/test/datagen/Indenter.java +++ b/src/test/boa/test/datagen/java/Indenter.java @@ -13,7 +13,7 @@ // is preserved, and any changes are properly documented. // -package boa.test.datagen; +package boa.test.datagen.java; /** * Maintains an indentation string. diff --git a/src/test/boa/test/datagen/JSONStyleASTPrinter.java b/src/test/boa/test/datagen/java/JSONStyleASTPrinter.java similarity index 99% rename from src/test/boa/test/datagen/JSONStyleASTPrinter.java rename to src/test/boa/test/datagen/java/JSONStyleASTPrinter.java index c449b4b3f..46ba9f8e5 100644 --- a/src/test/boa/test/datagen/JSONStyleASTPrinter.java +++ b/src/test/boa/test/datagen/java/JSONStyleASTPrinter.java @@ -13,7 +13,7 @@ // is preserved, and any changes are properly documented. // -package boa.test.datagen; +package boa.test.datagen.java; import java.io.OutputStream; import java.io.PrintWriter; diff --git a/src/test/boa/test/datagen/java/Java7BaseTest.java b/src/test/boa/test/datagen/java/Java7BaseTest.java index a93437775..db87aad40 100644 --- a/src/test/boa/test/datagen/java/Java7BaseTest.java +++ b/src/test/boa/test/datagen/java/Java7BaseTest.java @@ -46,10 +46,8 @@ import boa.types.Diff.ChangedFile; import boa.datagen.util.FileIO; import boa.datagen.util.JavaVisitor; -import boa.datagen.util.ProtoMessageVisitor; import boa.test.compiler.BaseTest; -import boa.test.datagen.ASTDumper; -import boa.test.datagen.UglyMathCommentsExtractor; +import boa.test.datagen.ProtoMessageVisitor; /* * @author rdyer @@ -98,13 +96,13 @@ public void acceptAST(String sourceFilePath, CompilationUnit cu) { sb.append(JsonFormat.printToString(ast.build())); } }; - Map fileContents = new HashMap(); + final Map fileContents = new HashMap(); fileContents.put("", content); @SuppressWarnings("rawtypes") - Map options = JavaCore.getOptions(); + final Map options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_COMPLIANCE, javaVersion); options.put(JavaCore.COMPILER_SOURCE, javaVersion); - ASTParser parser = ASTParser.newParser(astLevel); + final ASTParser parser = ASTParser.newParser(astLevel); parser.setCompilerOptions(options); parser.setEnvironment(new String[0], new String[]{}, new String[]{}, true); parser.setResolveBindings(true); @@ -167,20 +165,20 @@ protected static Declaration getDeclaration(final SequenceFile.Reader ar, final if (cf.getAst() && astpos > -1) { try { ar.seek(astpos); - Writable astkey = new LongWritable(); - BytesWritable val = new BytesWritable(); + final Writable astkey = new LongWritable(); + final BytesWritable val = new BytesWritable(); ar.next(astkey, val); - byte[] bytes = val.getBytes(); - ASTRoot root = ASTRoot.parseFrom(CodedInputStream.newInstance(bytes, 0, val.getLength())); - ProtoMessageVisitor v = new ProtoMessageVisitor() { + final byte[] bytes = val.getBytes(); + final ASTRoot root = ASTRoot.parseFrom(CodedInputStream.newInstance(bytes, 0, val.getLength())); + final ProtoMessageVisitor v = new ProtoMessageVisitor() { private boolean found = false; @Override - public boolean preVisit(Message message) { + public boolean preVisit(final Message message) { if (found) return false; if (message instanceof Declaration) { - Declaration temp = (Declaration) message; + final Declaration temp = (Declaration) message; Declaration type = declarations.get(temp.getKey()); if (type == null) { type = Declaration.newBuilder(temp).build(); @@ -195,7 +193,7 @@ public boolean preVisit(Message message) { }; }; v.visit(root); - } catch (IOException e) {} + } catch (final IOException e) {} } return declarations.get(nodeId); } @@ -205,27 +203,27 @@ protected static Message getMessage(final SequenceFile.Reader ar, final ChangedF if (cf.getAst() && astpos > -1) { try { ar.seek(astpos); - Writable astkey = new LongWritable(); - BytesWritable val = new BytesWritable(); + final Writable astkey = new LongWritable(); + final BytesWritable val = new BytesWritable(); ar.next(astkey, val); - byte[] bytes = val.getBytes(); - ASTRoot root = ASTRoot.parseFrom(CodedInputStream.newInstance(bytes, 0, val.getLength())); + final byte[] bytes = val.getBytes(); + final ASTRoot root = ASTRoot.parseFrom(CodedInputStream.newInstance(bytes, 0, val.getLength())); return getMessage(root, nodeId); - } catch (IOException e) {} + } catch (final IOException e) {} } return null; } protected static Message getMessage(final Message root, final int nodeId) { final Message[] m = new Message[1]; - ProtoMessageVisitor v = new ProtoMessageVisitor() { + final ProtoMessageVisitor v = new ProtoMessageVisitor() { private boolean found = false; @Override - public boolean preVisit(Message message) { + public boolean preVisit(final Message message) { if (found) return false; - Object v = getFieldValue(message, "key"); + final Object v = getFieldValue(message, "key"); if (v != null && (Integer) v == nodeId) { m[0] = message; found = true; @@ -238,9 +236,9 @@ public boolean preVisit(Message message) { return m[0]; } - protected static Object getFieldValue(Message message, String name) { - for (Iterator> iter = message.getAllFields().entrySet().iterator(); iter.hasNext();) { - Map.Entry field = iter.next(); + protected static Object getFieldValue(final Message message, final String name) { + for (final Iterator> iter = message.getAllFields().entrySet().iterator(); iter.hasNext();) { + final Map.Entry field = iter.next(); if (field.getKey().getName().equals(name)) { return field.getValue(); } @@ -249,43 +247,43 @@ protected static Object getFieldValue(Message message, String name) { } protected static HashMap> collectDeclarations(final SequenceFile.Reader ar, List snapshot) throws IOException { - HashMap> fileNodeDeclaration = new HashMap>(); + final HashMap> fileNodeDeclaration = new HashMap>(); for (int fileIndex = 0; fileIndex < snapshot.size(); fileIndex++) { - ChangedFile cf = snapshot.get(fileIndex); + final ChangedFile cf = snapshot.get(fileIndex); long astpos = cf.getKey(); if (!cf.getAst()) continue; if (astpos > -1) { ar.seek(astpos); - Writable astkey = new LongWritable(); - BytesWritable val = new BytesWritable(); + final Writable astkey = new LongWritable(); + final BytesWritable val = new BytesWritable(); ar.next(astkey, val); - byte[] bytes = val.getBytes(); - ASTRoot root = ASTRoot.parseFrom(CodedInputStream.newInstance(bytes, 0, val.getLength())); - HashMap nodeDeclaration = collectDeclarations(root); + final byte[] bytes = val.getBytes(); + final ASTRoot root = ASTRoot.parseFrom(CodedInputStream.newInstance(bytes, 0, val.getLength())); + final HashMap nodeDeclaration = collectDeclarations(root); fileNodeDeclaration.put(fileIndex, nodeDeclaration); } } return fileNodeDeclaration; } - protected static HashMap collectDeclarations(Message message) { - HashMap nodeDeclaration = new HashMap(); + protected static HashMap collectDeclarations(final Message message) { + final HashMap nodeDeclaration = new HashMap(); if (message instanceof Declaration) { nodeDeclaration.put(((Declaration) message).getKey(), (Declaration) message); } - for (Iterator> iter = message.getAllFields().entrySet().iterator(); iter.hasNext();) { - Map.Entry field = iter.next(); + for (final Iterator> iter = message.getAllFields().entrySet().iterator(); iter.hasNext();) { + final Map.Entry field = iter.next(); nodeDeclaration.putAll(collectDeclarations(field.getKey(), field.getValue())); } return nodeDeclaration; } - protected static HashMap collectDeclarations(FieldDescriptor field, Object value) { - HashMap nodeDeclaration = new HashMap(); + protected static HashMap collectDeclarations(final FieldDescriptor field, final Object value) { + final HashMap nodeDeclaration = new HashMap(); if (field.isRepeated()) { // Repeated field. Print each element. - for (Iterator iter = ((List) value).iterator(); iter.hasNext();) + for (final Iterator iter = ((List) value).iterator(); iter.hasNext();) if (field.getType() == Type.MESSAGE) nodeDeclaration.putAll(collectDeclarations((Message) iter.next())); } diff --git a/src/test/boa/test/datagen/java/Java8BaseTest.java b/src/test/boa/test/datagen/java/Java8BaseTest.java index 1e28ca408..ef914c9c4 100644 --- a/src/test/boa/test/datagen/java/Java8BaseTest.java +++ b/src/test/boa/test/datagen/java/Java8BaseTest.java @@ -35,7 +35,7 @@ private static void setJava8() { public static void dumpJavaWrapped(final String content) { setJava8(); Java7BaseTest.dumpJavaWrapped(content); - } + } public static void dumpJava(final String content) { setJava8(); diff --git a/src/test/boa/test/datagen/java/JavaToBoa.java b/src/test/boa/test/datagen/java/JavaToBoa.java index 18282b234..3f77c0f4c 100644 --- a/src/test/boa/test/datagen/java/JavaToBoa.java +++ b/src/test/boa/test/datagen/java/JavaToBoa.java @@ -1,5 +1,5 @@ /* - * Copyright 2016, Hridesh Rajan, Robert Dyer, + * Copyright 2016, Hridesh Rajan, Robert Dyer, * Iowa State University of Science and Technology, * and Bowling Green State University * @@ -21,7 +21,7 @@ * @author rdyer */ public class JavaToBoa extends Java8BaseTest { - public static void main(String[] args) { + public static void main(final String[] args) { for (final String s : args) if (s.indexOf("class ") == -1) System.out.println(parseWrapped(s)); diff --git a/src/test/boa/test/datagen/java/TestJLSVersion.java b/src/test/boa/test/datagen/java/TestJLSVersion.java index be679d8b5..f2563f9fb 100644 --- a/src/test/boa/test/datagen/java/TestJLSVersion.java +++ b/src/test/boa/test/datagen/java/TestJLSVersion.java @@ -43,31 +43,30 @@ @RunWith(Parameterized.class) public class TestJLSVersion { - - @Parameters(name = "{index}: {0}") - public static List data() throws Exception { - List data = new ArrayList(); - CodeRepository cr = buildCodeRepository("boalang/test-datagen"); - String[][] commits = new String[][] { + @Parameters(name = "{index}: {0}") + public static List data() throws Exception { + final List data = new ArrayList(); + final CodeRepository cr = buildCodeRepository("boalang/test-datagen"); + final String[][] commits = new String[][] { {"15c9685cbd36edba1709637bb8f8c217c894bee6", "58"}, {"30e04b12074b7288b4d2cf166c5c7c98a243d1ee", "59"}, }; - - for (String[] commit : commits) { - ChangedFile[] snapshot = BoaIntrinsics.getSnapshotById(cr, commit[0], new String[]{"SOURCE_JAVA_"}); + + for (final String[] commit : commits) { + final ChangedFile[] snapshot = BoaIntrinsics.getSnapshotById(cr, commit[0], new String[]{"SOURCE_JAVA_"}); assertThat(snapshot.length, Matchers.is(Integer.parseInt(commit[1]))); - - for (ChangedFile cf : snapshot) - data.add(new Object[]{cf.getName(), cf}); + + for (final ChangedFile cf : snapshot) + data.add(new Object[]{cf.getName(), cf}); } - return data; - } - - private ChangedFile changedFile; - + return data; + } + + private ChangedFile changedFile; + private static Configuration conf = new Configuration(); private static FileSystem fileSystem = null; - + private static SequenceFile.Writer projectWriter; private static SequenceFile.Writer astWriter; private static SequenceFile.Writer commitWriter; @@ -75,30 +74,30 @@ public static List data() throws Exception { private static long astWriterLen = 1; private static long commitWriterLen = 1; private static long contentWriterLen = 1; - - public TestJLSVersion(String name, ChangedFile input) { + + public TestJLSVersion(final String name, final ChangedFile input) { DefaultProperties.DEBUG = true; this.changedFile = input; } - + @Test public void testJLSVersion() throws Exception { - String kind = changedFile.getKind().name(); - String version = kind.substring(kind.lastIndexOf('_') + 1); + final String kind = changedFile.getKind().name(); + final String version = kind.substring(kind.lastIndexOf('_') + 1); assertThat(changedFile.getName(), Matchers.containsString("/" + version + "/")); } - - private static CodeRepository buildCodeRepository(String repoName) throws Exception { + + private static CodeRepository buildCodeRepository(final String repoName) throws Exception { fileSystem = FileSystem.get(conf); - + System.out.println("Repo: " + repoName); - File gitDir = new File("dataset/repos/" + repoName); + final File gitDir = new File("dataset/repos/" + repoName); openWriters(gitDir.getAbsolutePath()); FileIO.DirectoryRemover filecheck = new FileIO.DirectoryRemover(gitDir.getAbsolutePath()); filecheck.run(); - String url = "https://github.com/" + repoName + ".git"; + final String url = "https://github.com/" + repoName + ".git"; RepositoryCloner.clone(new String[]{url, gitDir.getAbsolutePath()}); - GitConnector conn = new GitConnector(gitDir.getAbsolutePath(), repoName, astWriter, astWriterLen, commitWriter, commitWriterLen, contentWriter, contentWriterLen); + final GitConnector conn = new GitConnector(gitDir.getAbsolutePath(), repoName, astWriter, astWriterLen, commitWriter, commitWriterLen, contentWriter, contentWriterLen); final CodeRepository.Builder repoBuilder = CodeRepository.newBuilder(); repoBuilder.setKind(RepositoryKind.GIT); repoBuilder.setUrl(url); @@ -115,7 +114,7 @@ private static CodeRepository buildCodeRepository(String repoName) throws Except repoBuilder.addAllBranchNames(conn.getBranchNames()); repoBuilder.addAllTags(conn.getTagIndices()); repoBuilder.addAllTagNames(conn.getTagNames()); - + closeWriters(); List snapshot1 = new ArrayList(); @@ -124,59 +123,59 @@ private static CodeRepository buildCodeRepository(String repoName) throws Except List snapshot2 = conn.getSnapshot(Constants.HEAD); Set s1 = new HashSet(); Set s2 = new HashSet(snapshot2); - for (ChangedFile cf : snapshot1) + for (final ChangedFile cf : snapshot1) s1.add(cf.getName()); // System.out.println("Test head snapshot"); assertEquals(s2, s1); for (int i = conn.getRevisions().size()-1; i >= 0; i--) { - AbstractCommit commit = (AbstractCommit) conn.getRevisions().get(i); + final AbstractCommit commit = (AbstractCommit) conn.getRevisions().get(i); snapshot1 = new ArrayList(); conn.getSnapshot(i, snapshot1); snapshot2 = conn.getSnapshot(commit.getId()); s1 = new HashSet(); s2 = new HashSet(snapshot2); - for (ChangedFile cf : snapshot1) + for (final ChangedFile cf : snapshot1) s1.add(cf.getName()); // System.out.println("Test snapshot at " + commit.getId()); assertEquals(s2, s1); } - - CodeRepository cr = repoBuilder.build(); - + + final CodeRepository cr = repoBuilder.build(); + { - ChangedFile[] snapshot = BoaIntrinsics.getSnapshot(cr); - String[] fileNames = new String[snapshot.length]; + final ChangedFile[] snapshot = BoaIntrinsics.getSnapshot(cr); + final String[] fileNames = new String[snapshot.length]; for (int i = 0; i < snapshot.length; i++) fileNames[i] = snapshot[i].getName(); Arrays.sort(fileNames); - String[] expectedFileNames = conn.getSnapshot(Constants.HEAD).toArray(new String[0]); + final String[] expectedFileNames = conn.getSnapshot(Constants.HEAD).toArray(new String[0]); Arrays.sort(expectedFileNames); // System.out.println("Test head snapshot"); assertArrayEquals(expectedFileNames, fileNames); } - - for (Revision rev : cr.getRevisionsList()) { - ChangedFile[] snapshot = BoaIntrinsics.getSnapshotById(cr, rev.getId()); - String[] fileNames = new String[snapshot.length]; + + for (final Revision rev : cr.getRevisionsList()) { + final ChangedFile[] snapshot = BoaIntrinsics.getSnapshotById(cr, rev.getId()); + final String[] fileNames = new String[snapshot.length]; for (int i = 0; i < snapshot.length; i++) fileNames[i] = snapshot[i].getName(); Arrays.sort(fileNames); - String[] expectedFileNames = conn.getSnapshot(rev.getId()).toArray(new String[0]); + final String[] expectedFileNames = conn.getSnapshot(rev.getId()).toArray(new String[0]); Arrays.sort(expectedFileNames); // System.out.println("Test snapshot at " + rev.getId()); assertArrayEquals(expectedFileNames, fileNames); } - + new Thread(new FileIO.DirectoryRemover(gitDir.getAbsolutePath())).start(); conn.close(); - + return cr; } - public static void openWriters(String base) { - long time = System.currentTimeMillis(); - String suffix = time + ".seq"; + public static void openWriters(final String base) { + final long time = System.currentTimeMillis(); + final String suffix = time + ".seq"; while (true) { try { projectWriter = SequenceFile.createWriter(fileSystem, conf, new Path(base + "/project/" + suffix), @@ -188,11 +187,11 @@ public static void openWriters(String base) { contentWriter = SequenceFile.createWriter(fileSystem, conf, new Path(base + "/source/" + suffix), LongWritable.class, BytesWritable.class, CompressionType.BLOCK); break; - } catch (Throwable t) { + } catch (final Throwable t) { t.printStackTrace(); try { Thread.sleep(1000); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } } } @@ -207,23 +206,23 @@ public static void closeWriters() { contentWriter.close(); try { Thread.sleep(1000); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } break; - } catch (Throwable t) { + } catch (final Throwable t) { t.printStackTrace(); try { Thread.sleep(1000); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } } } } - public void print(Set s, List snapshot, Map commits) { - List l = new ArrayList(s); + public void print(final Set s, final List snapshot, final Map commits) { + final List l = new ArrayList(s); Collections.sort(l); - for (String f : l) + for (final String f : l) System.out.println(f + " " + commits.get(f).getId()); System.out.println("=========================================="); } diff --git a/src/test/boa/test/datagen/java/TestJLSVersionOfChangedFile.java b/src/test/boa/test/datagen/java/TestJLSVersionOfChangedFile.java index a5de2f5a6..26b3ebbe4 100644 --- a/src/test/boa/test/datagen/java/TestJLSVersionOfChangedFile.java +++ b/src/test/boa/test/datagen/java/TestJLSVersionOfChangedFile.java @@ -44,40 +44,39 @@ @RunWith(Parameterized.class) public class TestJLSVersionOfChangedFile { - @Parameters(name = "{index}: {0}") public static List data() throws Exception { - List data = new ArrayList(); - CodeRepository cr = buildCodeRepository("boalang/compiler"); - String[][] commits = new String[][] { + final List data = new ArrayList(); + final CodeRepository cr = buildCodeRepository("boalang/compiler"); + final String[][] commits = new String[][] { {"3a1e352cc63f94058ddb38341531d347f121c29a", "58"}, {"b82810e725dbf8c7fde6e7fdc034c5676d270313", "1"}, }; - - Map map = new HashMap(); + + final Map map = new HashMap(); for (int i = 0; i < commits.length; i++) { - String[] commit = commits[i]; + final String[] commit = commits[i]; map.put(commit[0], i); } - for (Revision rev : cr.getRevisionsList()) { - Integer index = map.get(rev.getId()); + for (final Revision rev : cr.getRevisionsList()) { + final Integer index = map.get(rev.getId()); if (index != null) { - String[] commit = commits[index]; - List snapshot = rev.getFilesList(); + final String[] commit = commits[index]; + final List snapshot = rev.getFilesList(); assertThat(snapshot.size(), Matchers.is(Integer.parseInt(commit[1]))); - - for (ChangedFile cf : snapshot) + + for (final ChangedFile cf : snapshot) data.add(new Object[]{cf.getName(), cf}); } } return data; } - + private ChangedFile changedFile; - + private static Configuration conf = new Configuration(); private static FileSystem fileSystem = null; - + private static SequenceFile.Writer projectWriter; private static SequenceFile.Writer astWriter; private static SequenceFile.Writer commitWriter; @@ -85,30 +84,30 @@ public static List data() throws Exception { private static long astWriterLen = 1; private static long commitWriterLen = 1; private static long contentWriterLen = 1; - - public TestJLSVersionOfChangedFile(String name, ChangedFile input) { + + public TestJLSVersionOfChangedFile(final String name, final ChangedFile input) { DefaultProperties.DEBUG = true; this.changedFile = input; } - + @Test public void testJLSVersion() throws Exception { - String kind = changedFile.getKind().name(); - String version = kind.substring(kind.lastIndexOf('_') + 1); + final String kind = changedFile.getKind().name(); + final String version = kind.substring(kind.lastIndexOf('_') + 1); assertThat(changedFile.getName(), Matchers.containsString("/" + version + "/")); } - - private static CodeRepository buildCodeRepository(String repoName) throws Exception { + + private static CodeRepository buildCodeRepository(final String repoName) throws Exception { fileSystem = FileSystem.get(conf); - + System.out.println("Repo: " + repoName); - File gitDir = new File("dataset/repos/" + repoName); + final File gitDir = new File("dataset/repos/" + repoName); openWriters(gitDir.getAbsolutePath()); FileIO.DirectoryRemover filecheck = new FileIO.DirectoryRemover(gitDir.getAbsolutePath()); filecheck.run(); - String url = "https://github.com/" + repoName + ".git"; + final String url = "https://github.com/" + repoName + ".git"; RepositoryCloner.clone(new String[]{url, gitDir.getAbsolutePath()}); - GitConnector conn = new GitConnector(gitDir.getAbsolutePath(), repoName, astWriter, astWriterLen, commitWriter, commitWriterLen, contentWriter, contentWriterLen); + final GitConnector conn = new GitConnector(gitDir.getAbsolutePath(), repoName, astWriter, astWriterLen, commitWriter, commitWriterLen, contentWriter, contentWriterLen); final CodeRepository.Builder repoBuilder = CodeRepository.newBuilder(); repoBuilder.setKind(RepositoryKind.GIT); repoBuilder.setUrl(url); @@ -125,7 +124,7 @@ private static CodeRepository buildCodeRepository(String repoName) throws Except repoBuilder.addAllBranchNames(conn.getBranchNames()); repoBuilder.addAllTags(conn.getTagIndices()); repoBuilder.addAllTagNames(conn.getTagNames()); - + closeWriters(); List snapshot1 = new ArrayList(); @@ -134,59 +133,59 @@ private static CodeRepository buildCodeRepository(String repoName) throws Except List snapshot2 = conn.getSnapshot(Constants.HEAD); Set s1 = new HashSet(); Set s2 = new HashSet(snapshot2); - for (ChangedFile cf : snapshot1) + for (final ChangedFile cf : snapshot1) s1.add(cf.getName()); // System.out.println("Test head snapshot"); assertEquals(s2, s1); for (int i = conn.getRevisions().size()-1; i >= 0; i--) { - AbstractCommit commit = (AbstractCommit) conn.getRevisions().get(i); + final AbstractCommit commit = (AbstractCommit) conn.getRevisions().get(i); snapshot1 = new ArrayList(); conn.getSnapshot(i, snapshot1); snapshot2 = conn.getSnapshot(commit.getId()); s1 = new HashSet(); s2 = new HashSet(snapshot2); - for (ChangedFile cf : snapshot1) + for (final ChangedFile cf : snapshot1) s1.add(cf.getName()); // System.out.println("Test snapshot at " + commit.getId()); assertEquals(s2, s1); } - - CodeRepository cr = repoBuilder.build(); - + + final CodeRepository cr = repoBuilder.build(); + { - ChangedFile[] snapshot = BoaIntrinsics.getSnapshot(cr); - String[] fileNames = new String[snapshot.length]; + final ChangedFile[] snapshot = BoaIntrinsics.getSnapshot(cr); + final String[] fileNames = new String[snapshot.length]; for (int i = 0; i < snapshot.length; i++) fileNames[i] = snapshot[i].getName(); Arrays.sort(fileNames); - String[] expectedFileNames = conn.getSnapshot(Constants.HEAD).toArray(new String[0]); + final String[] expectedFileNames = conn.getSnapshot(Constants.HEAD).toArray(new String[0]); Arrays.sort(expectedFileNames); // System.out.println("Test head snapshot"); assertArrayEquals(expectedFileNames, fileNames); } - - for (Revision rev : cr.getRevisionsList()) { - ChangedFile[] snapshot = BoaIntrinsics.getSnapshotById(cr, rev.getId()); - String[] fileNames = new String[snapshot.length]; + + for (final Revision rev : cr.getRevisionsList()) { + final ChangedFile[] snapshot = BoaIntrinsics.getSnapshotById(cr, rev.getId()); + final String[] fileNames = new String[snapshot.length]; for (int i = 0; i < snapshot.length; i++) fileNames[i] = snapshot[i].getName(); Arrays.sort(fileNames); - String[] expectedFileNames = conn.getSnapshot(rev.getId()).toArray(new String[0]); + final String[] expectedFileNames = conn.getSnapshot(rev.getId()).toArray(new String[0]); Arrays.sort(expectedFileNames); // System.out.println("Test snapshot at " + rev.getId()); assertArrayEquals(expectedFileNames, fileNames); } - + new Thread(new FileIO.DirectoryRemover(gitDir.getAbsolutePath())).start(); conn.close(); - + return cr; } - public static void openWriters(String base) { - long time = System.currentTimeMillis(); - String suffix = time + ".seq"; + public static void openWriters(final String base) { + final long time = System.currentTimeMillis(); + final String suffix = time + ".seq"; while (true) { try { projectWriter = SequenceFile.createWriter(fileSystem, conf, new Path(base + "/project/" + suffix), @@ -198,11 +197,11 @@ public static void openWriters(String base) { contentWriter = SequenceFile.createWriter(fileSystem, conf, new Path(base + "/source/" + suffix), LongWritable.class, BytesWritable.class, CompressionType.BLOCK); break; - } catch (Throwable t) { + } catch (final Throwable t) { t.printStackTrace(); try { Thread.sleep(1000); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } } } @@ -217,23 +216,23 @@ public static void closeWriters() { contentWriter.close(); try { Thread.sleep(1000); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } break; - } catch (Throwable t) { + } catch (final Throwable t) { t.printStackTrace(); try { Thread.sleep(1000); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } } } } - public void print(Set s, List snapshot, Map commits) { - List l = new ArrayList(s); + public void print(final Set s, final List snapshot, final Map commits) { + final List l = new ArrayList(s); Collections.sort(l); - for (String f : l) + for (final String f : l) System.out.println(f + " " + commits.get(f).getId()); System.out.println("=========================================="); } diff --git a/src/test/boa/test/datagen/UglyMathCommentsExtractor.java b/src/test/boa/test/datagen/java/UglyMathCommentsExtractor.java similarity index 99% rename from src/test/boa/test/datagen/UglyMathCommentsExtractor.java rename to src/test/boa/test/datagen/java/UglyMathCommentsExtractor.java index fccdfce3d..67717f5bf 100644 --- a/src/test/boa/test/datagen/UglyMathCommentsExtractor.java +++ b/src/test/boa/test/datagen/java/UglyMathCommentsExtractor.java @@ -13,7 +13,7 @@ // is preserved, and any changes are properly documented. // -package boa.test.datagen; +package boa.test.datagen.java; import java.io.Closeable; import java.io.IOException;