Skip to content

Commit

Permalink
Switch to composite build
Browse files Browse the repository at this point in the history
and validate oldest supported gradle and android gradle plugins in test.
  • Loading branch information
evant committed Oct 15, 2016
1 parent 97b7fce commit 166c5ee
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ retrolambda, giving you lambda goodness on java 6 or 7. It relies on the
wonderful [retrolambda](https://github.com/orfjackal/retrolambda) by Esko
Luontola.

Note: The minimum android gradle plugin is `1.5.0`.
Note: The minimum android gradle plugin is `1.5.0` and the minimum gradle plugin is `2.5`.

Usage
----
Expand Down
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
allprojects {
group = 'me.tatarka'
version = '3.3.0'
ext.androidPluginVersion = '2.2.1'
group = project.property('group')
version = project.property('version')
ext.androidPluginVersion = project.property('androidPluginVersion')
}

task test {
dependsOn gradle.includedBuild('gradle-retrolambda').task(':test')
}
9 changes: 8 additions & 1 deletion gradle-retrolambda/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'idea'

Properties props = new Properties()
props.load(new FileInputStream("$projectDir/../gradle.properties"))
group = props['group']
version = props['version']
ext.androidPluginVersion = props['androidPluginVersion']

sourceCompatibility = '1.6'


repositories {
jcenter()
mavenCentral()
Expand Down Expand Up @@ -158,7 +165,7 @@ if (project.hasProperty('sonatype.username') && project.hasProperty('sonatype.pa
}
}

def grgit = Grgit.open(project.rootProject.projectDir)
def grgit = Grgit.open("$projectDir/..")

task checkRelease << {
def readmeVersion = file("$project.rootProject.projectDir/README.md").readLines().find { it.contains('me.tatarka:gradle-retrolambda:') }?.trim()
Expand Down
1 change: 1 addition & 0 deletions gradle-retrolambda/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'gradle-retrolambda'
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class RetrolambdaPluginAndroid implements Plugin<Project> {

transform.putJavaCompileTask(variant.dirName, javaCompileTask)

def extractAnnotations = project.tasks.findByName("extract${variant.name.capitalize()}Annotations")
def extractAnnotations = project.tasks.findByName("extract${RetrolambdaUtil.capitalize(variant.name)}Annotations")
if (extractAnnotations) {
extractAnnotations.deleteAllActions()
project.logger.warn("$extractAnnotations.name is incompatible with java 8 sources and has been disabled.")
Expand All @@ -108,7 +108,7 @@ public class RetrolambdaPluginAndroid implements Plugin<Project> {
ensureCompileOnJava8(retrolambda, javaCompileTask)
}

Test runTask = (Test) project.tasks.findByName("test${variant.capitalize()}UnitTest")
Test runTask = (Test) project.tasks.findByName("test${RetrolambdaUtil.capitalize(variant)}UnitTest")
if (runTask) {
runTask.doFirst {
def retrolambda = project.extensions.getByType(RetrolambdaExtension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class RetrolambdaPluginGroovy implements Plugin<Project> {
project.afterEvaluate {
project.sourceSets.all { SourceSet set ->
if (project.retrolambda.isIncluded(set.name)) {
def name = set.name.capitalize()
def name = RetrolambdaUtil.capitalize(set.name)
def taskName = "compileRetrolambdaGroovy$name"
def oldOutputDir = set.output.classesDir
def newOutputDir = project.file("$project.buildDir/retrolambda/$set.name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class RetrolambdaPluginJava implements Plugin<Project> {

javaPlugin.sourceSets.all { SourceSet set ->
if (retrolambda.isIncluded(set.name)) {
def name = set.name.capitalize()
def name = RetrolambdaUtil.capitalize(set.name)
def taskName = "compileRetrolambda$name"
def oldOutputDir = set.output.classesDir
def newOutputDir = project.file("$project.buildDir/retrolambda/$set.name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.gradle.api.ProjectConfigurationException
import org.gradle.api.file.FileCollection
import org.gradle.api.logging.LogLevel
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.internal.reflect.DirectInstantiator

import static com.android.build.api.transform.Status.*
import static me.tatarka.RetrolambdaPlugin.javaVersionToBytecode
Expand Down Expand Up @@ -40,17 +41,18 @@ class RetrolambdaTransform extends Transform {
void transform(Context context, Collection<TransformInput> inputs, Collection<TransformInput> referencedInputs, TransformOutputProvider outputProvider, boolean isIncremental) throws IOException, TransformException, InterruptedException {
context.logging.captureStandardOutput(LogLevel.INFO)

inputs.each { TransformInput input ->
for (TransformInput input : inputs) {
def outputDir = outputProvider.getContentLocation("retrolambda", outputTypes, scopes, Format.DIRECTORY)

// Instead of looping, it might be better to figure out a way to pass multiple input
// dirs into retrolambda. Luckily, the common case is only one.
input.directoryInputs.each { DirectoryInput directoryInput ->
for (DirectoryInput directoryInput : input.directoryInputs) {
File inputFile = directoryInput.file
FileCollection changed
if (isIncremental) {
changed = project.files()
directoryInput.changedFiles.each { File file, Status status ->
for (Map.Entry<File, Status> entry : directoryInput.changedFiles) {
File file = entry.key; Status status = entry.value
if (status == ADDED || status == CHANGED) {
changed += project.files(file);
}
Expand Down Expand Up @@ -110,7 +112,9 @@ class RetrolambdaTransform extends Transform {
}

def classpathFiles = javaCompileTask.classpath
referencedInputs.each { TransformInput input -> classpathFiles += project.files(input.directoryInputs*.file) }
for (TransformInput input : referencedInputs) {
classpathFiles += project.files(input.directoryInputs*.file)
}

// bootClasspath isn't set until the last possible moment because it's expensive to look
// up the android sdk path.
Expand All @@ -133,7 +137,7 @@ class RetrolambdaTransform extends Transform {

@Override
Set<QualifiedContent.ContentType> getInputTypes() {
return Collections.singleton(QualifiedContent.DefaultContentType.CLASSES)
return Collections.<QualifiedContent.ContentType>singleton(QualifiedContent.DefaultContentType.CLASSES)
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.tatarka;

class RetrolambdaUtil {
static String capitalize(CharSequence self) {
return self.length() == 0 ? "" : "" + Character.toUpperCase(self.charAt(0)) + self.subSequence(1, self.length());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,42 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.runners.Parameterized;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Collection;

import static me.tatarka.TestHelpers.writeBuildFile;
import static me.tatarka.TestHelpers.getPluginClasspath;
import static me.tatarka.TestHelpers.newestSupportedAndroidPluginVersion;
import static me.tatarka.TestHelpers.oldestSupportedAndroidPluginVersion;
import static me.tatarka.TestHelpers.writeFile;
import static org.assertj.core.api.Assertions.assertThat;

@RunWith(JUnit4.class)
@RunWith(Parameterized.class)
public class AndroidAppPluginTest {
static final String androidVersion = "1.5.0";

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
oldestSupportedAndroidPluginVersion(),
newestSupportedAndroidPluginVersion()
});
}

@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final String androidVersion;
private final String gradleVersion;
private File rootDir;
private File buildFile;

public AndroidAppPluginTest(String androidVersion, String gradleVersion) {
this.androidVersion = androidVersion;
this.gradleVersion = gradleVersion;
}

@Before
public void setup() throws Exception {
rootDir = testProjectDir.getRoot();
Expand All @@ -35,16 +52,18 @@ public void setup() throws Exception {

@Test
public void assembleDebug() throws Exception {
writeBuildFile(buildFile,
writeFile(buildFile,
//language="Groovy"
"buildscript {\n" +
" System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'\n" +
" \n" +
" repositories {\n" +
" jcenter()\n" +
" }\n" +
" \n" +
" dependencies {\n" +
" classpath files($pluginClasspath)\n" +
" classpath 'com.android.tools.build:gradle:" + androidVersion +"'\n" +
" classpath files(" + getPluginClasspath() + ")\n" +
" classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" +
" }\n" +
"}\n" +
"\n" +
Expand Down Expand Up @@ -88,6 +107,7 @@ public void assembleDebug() throws Exception {

StringWriter errorOutput = new StringWriter();
BuildResult result = GradleRunner.create()
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.getRoot())
.withArguments("assembleDebug", "--stacktrace")
.forwardStdError(errorOutput)
Expand All @@ -104,16 +124,16 @@ public void assembleDebug() throws Exception {

@Test
public void assembleDebugIncremental() throws Exception {
writeBuildFile(buildFile,
writeFile(buildFile,
//language="Groovy"
"buildscript {\n" +
" repositories {\n" +
" jcenter()\n" +
" }\n" +
" \n" +
" dependencies {\n" +
" classpath files($pluginClasspath)\n" +
" classpath 'com.android.tools.build:gradle:" + androidVersion +"'\n" +
" classpath files(" + getPluginClasspath() + ")\n" +
" classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" +
" }\n" +
"}\n" +
"\n" +
Expand Down Expand Up @@ -157,6 +177,7 @@ public void assembleDebugIncremental() throws Exception {

StringWriter errorOutput = new StringWriter();
BuildResult result = GradleRunner.create()
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.getRoot())
.withArguments("assembleDebug", "--stacktrace")
.forwardStdError(errorOutput)
Expand All @@ -177,6 +198,7 @@ public void assembleDebugIncremental() throws Exception {

errorOutput = new StringWriter();
result = GradleRunner.create()
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.getRoot())
.withArguments("assembleDebug", "--stacktrace")
.forwardStdError(errorOutput)
Expand All @@ -193,16 +215,16 @@ public void assembleDebugIncremental() throws Exception {

@Test
public void unitTest() throws Exception {
writeBuildFile(buildFile,
writeFile(buildFile,
//language="Groovy"
"buildscript {\n" +
" repositories {\n" +
" jcenter()\n" +
" }\n" +
" \n" +
" dependencies {\n" +
" classpath files($pluginClasspath)\n" +
" classpath 'com.android.tools.build:gradle:" + androidVersion +"'\n" +
" classpath files(" + getPluginClasspath() + ")\n" +
" classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" +
" }\n" +
"}\n" +
"\n" +
Expand Down Expand Up @@ -265,26 +287,27 @@ public void unitTest() throws Exception {

StringWriter errorOutput = new StringWriter();
BuildResult result = GradleRunner.create()
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.getRoot())
.withArguments("test", "--stacktrace")
.forwardStdError(errorOutput)
.build();

assertThat(errorOutput.toString()).isNullOrEmpty();
}

@Test
public void withKotlin() throws Exception {
writeBuildFile(buildFile,
writeFile(buildFile,
//language="Groovy"
"buildscript {\n" +
" repositories {\n" +
" jcenter()\n" +
" }\n" +
" \n" +
" dependencies {\n" +
" classpath files($pluginClasspath)\n" +
" classpath 'com.android.tools.build:gradle:" + androidVersion +"'\n" +
" classpath files(" + getPluginClasspath() + ")\n" +
" classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" +
" classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.4'" +
" }\n" +
"}\n" +
Expand Down Expand Up @@ -320,7 +343,7 @@ public void withKotlin() throws Exception {

File javaFile1 = new File(rootDir, "src/main/java/test/MainActivity.java");
File javaFile2 = new File(rootDir, "src/main/java/test/JavaFile.java");

File kotlinFile = new File(rootDir, "src/main/kotlin/test/KotlinFile.kt");

writeFile(javaFile1, "package test;" +
Expand All @@ -334,14 +357,14 @@ public void withKotlin() throws Exception {
" new KotlinFile().doThis();" +
" }\n" +
"}");

writeFile(javaFile2, "package test;" +
"public class JavaFile {\n" +
" public void doThat() {\n" +
" System.out.println(\"That\");" +
" }" +
"}");

writeFile(kotlinFile, "package test\n" +
"import kotlin.io.println\n" +
"class KotlinFile {\n" +
Expand All @@ -353,6 +376,7 @@ public void withKotlin() throws Exception {

StringWriter errorOutput = new StringWriter();
BuildResult result = GradleRunner.create()
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.getRoot())
.withArguments("assembleDebug", "--stacktrace")
.forwardStdError(errorOutput)
Expand Down
Loading

0 comments on commit 166c5ee

Please sign in to comment.