Skip to content

Commit

Permalink
In-repo test on src_dir, also fix
Browse files Browse the repository at this point in the history
  • Loading branch information
peterebden committed Jan 9, 2017
1 parent 0895f3a commit 9bb64f0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
14 changes: 14 additions & 0 deletions test/java_rules/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Test for java_library rules using src_dir
java_library(
name = 'src_dir_lib',
src_dir = 'src',
)

java_test(
name = 'src_dir_test',
srcs = ['test/build/please/java/test/SrcDirTest.java'],
deps = [
':src_dir_lib',
'//third_party/java:junit',
],
)
7 changes: 7 additions & 0 deletions test/java_rules/src/build/please/java/test/SrcDirLib.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package build.please.java.test;

public class SrcDirLib {
public static int WhatDoYouGetWhenYouMultiply(int a, int b) {
return a == 6 && b == 9 ? 42 : a * b;
}
}
11 changes: 11 additions & 0 deletions test/java_rules/test/build/please/java/test/SrcDirTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package build.please.java.test;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class SrcDirTest {
@Test
public void TestTheAnswer() {
assertEquals(42, SrcDirLib.WhatDoYouGetWhenYouMultiply(6, 9));
}
}
8 changes: 5 additions & 3 deletions tools/javac_worker/src/build/please/compile/JavaCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import javax.tools.ToolProvider;

import build.please.worker.WorkerProto.BuildRequest;
import build.please.worker.WorkerProto.BuildResponse;;
import build.please.worker.WorkerProto.BuildResponse;

public class JavaCompiler {
/**
Expand Down Expand Up @@ -69,7 +69,7 @@ private void readStdin(byte[] b) throws IOException {
/**
* build handles building a single build rule.
*/
public BuildResponse build(BuildRequest request) {
public BuildResponse build(BuildRequest request) throws IOException {
try {
return reallyBuild(request);
} catch (Exception ex) {
Expand Down Expand Up @@ -101,7 +101,7 @@ private BuildResponse reallyBuild(BuildRequest request) throws IOException {
for (String src : request.getSrcsList()) {
srcs.add(src.startsWith("/") ? src : request.getTempDir() + "/" + src);
}
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromStrings(srcs);
Iterable<? extends JavaFileObject> compilationUnits;
ArrayList<String> opts = new ArrayList<String>();
opts.addAll(Arrays.asList(
"-d", tmpDir,
Expand All @@ -114,6 +114,8 @@ private BuildResponse reallyBuild(BuildRequest request) throws IOException {
FileFinder finder = new FileFinder(".java");
Files.walkFileTree(new File(request.getTempDir() + "/" + request.getSrcs(0)).toPath(), finder);
compilationUnits = fileManager.getJavaFileObjectsFromStrings(finder.getFiles());
} else {
compilationUnits = fileManager.getJavaFileObjectsFromStrings(srcs);
}
// Find any .jar files and add them to the classpath
FileFinder finder = new FileFinder(".jar");
Expand Down

0 comments on commit 9bb64f0

Please sign in to comment.