diff --git a/builder/build.gradle b/builder/build.gradle index a48ca0a39..8dd6d6409 100644 --- a/builder/build.gradle +++ b/builder/build.gradle @@ -6,7 +6,8 @@ repositories { dependencies { compile "org.gradle:gradle-tooling-api:+" - compile 'org.slf4j:slf4j-api:1.7.7' + compile "org.slf4j:slf4j-api:1.7.7" + compile 'org.eclipse.jgit:org.eclipse.jgit:4.0.1.201506240215-r' testCompile 'junit:junit:4.12' } diff --git a/builder/src/test/java/GradleBuildTest.java b/builder/src/test/java/GradleBuildTest.java index 48e0c5f68..acf1affac 100644 --- a/builder/src/test/java/GradleBuildTest.java +++ b/builder/src/test/java/GradleBuildTest.java @@ -8,19 +8,65 @@ import org.gradle.tooling.GradleConnector; import org.gradle.tooling.ProjectConnection; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.treewalk.filter.TreeFilter; + import java.io.File; import java.io.FileFilter; import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; @RunWith(Parameterized.class) -public class GradleBuildTest { - +public class GradleBuildTest { @Parameters - public static File[] data() { - return new File("..").listFiles(new FileFilter() { - public boolean accept(File f) { return f.isDirectory() && Arrays.asList(f.list()).containsAll(Arrays.asList("build.gradle", "app")); } - }); + public static Collection data() { + LinkedHashSet projects = new LinkedHashSet(); + try { + Repository repository = new FileRepositoryBuilder() + .readEnvironment() // scan environment GIT_* variables + .findGitDir() // scan up the file system tree + .build(); + RevCommit head = new Git(repository) + .log().call() + .iterator().next(); + TreeWalk treeWalk = new TreeWalk(repository); + treeWalk.addTree(head.getTree()); + for (RevCommit p : head.getParents()) { + treeWalk.addTree(p.getTree()); + } + treeWalk.setRecursive(false); + treeWalk.setFilter(TreeFilter.ANY_DIFF); + while (treeWalk.next()) { + File f = new File("../" + treeWalk.getPathString()); + if (isProject(f)) { + System.err.println("project changed: " + f.getName()); + projects.add(f); + } + } + } catch (java.io.IOException e) { + System.err.println("error opening git repository: " + e); + } catch (GitAPIException e) { + System.err.println("error reading git repository log: " + e); + } + + for (File p : new File("..").listFiles(new FileFilter() { + public boolean accept(File f) { return isProject(f); } + })) { + projects.add(p); + } + return projects; } + + private static boolean isProject(File f) { + return f.isDirectory() && Arrays.asList(f.list()).containsAll(Arrays.asList("build.gradle", "app")); + } + private File gradleProject; public GradleBuildTest(File gradleProject) { this.gradleProject = gradleProject; @@ -32,14 +78,18 @@ public void test() { connector.forProjectDirectory(gradleProject); ProjectConnection connection = connector.connect(); try { - // Configure the build BuildLauncher launcher = connection.newBuild(); - launcher.forTasks("build"); launcher.setStandardOutput(System.out); - launcher.setStandardError(System.err); + launcher.setStandardError(System.err); + + launcher.forTasks("clean"); + launcher.run(); - // Run the build + launcher.forTasks("app:lint"); launcher.run(); + + launcher.forTasks("build"); + launcher.run(); } finally { // Clean up connection.close();