Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support the latest version of gradle #278

Merged
merged 1 commit into from
Apr 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RetrolambdaExec {
if (!retrolambda.onJava8) {
def java = "${retrolambda.tryGetJdk()}/bin/java"
if (!checkIfExecutableExists(java)) {
throw new ProjectConfigurationException("Cannot find executable: $java", null)
throw new ProjectConfigurationException("Cannot find executable: $java", (Throwable) null)
}
exec.executable java
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class RetrolambdaExtension {
String tryGetJdk() {
String jdk = getJdk()
if (jdk == null) {
throw new ProjectConfigurationException("When running gradle with java 5, 6 or 7, you must set the path to jdk8, either with property retrolambda.jdk or environment variable JAVA8_HOME", null)
throw new ProjectConfigurationException("When running gradle with java 5, 6 or 7, you must set the path to jdk8, either with property retrolambda.jdk or environment variable JAVA8_HOME", (Throwable) null)
}
return jdk
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.gradle.api.plugins.JavaPlugin

@CompileStatic
public class RetrolambdaPlugin implements Plugin<Project> {
protected static String retrolambdaCompile = "net.orfjackal.retrolambda:retrolambda:2.5.1"
protected static String retrolambdaCompile = "net.orfjackal.retrolambda:retrolambda:2.5.6"

@Override
void apply(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class RetrolambdaPluginAndroid implements Plugin<Project> {
// Set JDK 8 for the compiler task
def javac = "${retrolambda.tryGetJdk()}/bin/javac"
if (!checkIfExecutableExists(javac)) {
throw new ProjectConfigurationException("Cannot find executable: $javac", null)
throw new ProjectConfigurationException("Cannot find executable: $javac", (Throwable) null)
}
javaCompile.options.fork = true
javaCompile.options.forkOptions.executable = javac
Expand All @@ -154,7 +154,7 @@ class RetrolambdaPluginAndroid implements Plugin<Project> {
if (!retrolambda.onJava8) {
def java = "${retrolambda.tryGetJdk()}/bin/java"
if (!checkIfExecutableExists(java)) {
throw new ProjectConfigurationException("Cannot find executable: $java", null)
throw new ProjectConfigurationException("Cannot find executable: $java", (Throwable) null)
}
test.executable java
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class RetrolambdaPluginGroovy implements Plugin<Project> {
if (project.retrolambda.isIncluded(set.name)) {
def name = RetrolambdaUtil.capitalize(set.name)
def taskName = "compileRetrolambdaGroovy$name"
def oldOutputDir = set.output.classesDir
def oldOutputDir = RetrolambdaUtil.groovyOutputDir(set)
def newOutputDir = project.file("$project.buildDir/retrolambda/$set.name")

/* No compileJavaTaskName present, so re-use any modifications applied to compileJava and remap to Groovy */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class RetrolambdaPluginJava implements Plugin<Project> {
if (retrolambda.isIncluded(set.name)) {
def name = RetrolambdaUtil.capitalize(set.name)
def taskName = "compileRetrolambda$name"
def oldOutputDir = set.output.classesDir
def oldOutputDir = RetrolambdaUtil.javaOutputDir(set)
def newOutputDir = project.file("$project.buildDir/retrolambda/$set.name")

def compileJavaTask = project.tasks.getByName(set.compileJavaTaskName) as JavaCompile
Expand Down Expand Up @@ -82,7 +82,7 @@ public class RetrolambdaPluginJava implements Plugin<Project> {
if (oldJdkPath != null) {
def oldJava = "$oldJdkPath/bin/java"
if (!checkIfExecutableExists(oldJava)) {
throw new ProjectConfigurationException("Cannot find executable: $oldJava", null)
throw new ProjectConfigurationException("Cannot find executable: $oldJava", (Throwable) null)
}
task.executable oldJava
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class RetrolambdaTask extends DefaultTask {
def retrolambda = project.extensions.getByType(RetrolambdaExtension)

List<InputFileDetails> changes = []
inputs.outOfDate { changes += it }
inputs.outOfDate { changes.add(it) }

// Ensure output is cleared if build is not incremental.
if (inputs.incremental && !changes.isEmpty() && !retrolambda.incremental) {
outputDir.eachFile { it.delete() }
} else {
changes.each { InputFileDetails change ->
for (InputFileDetails change : changes) {
if (change.modified) deleteRelated(toOutput(change.file))
}
}
Expand Down Expand Up @@ -90,11 +90,11 @@ class RetrolambdaTask extends DefaultTask {
}
}

def File toOutput(File file) {
File toOutput(File file) {
return outputDir.toPath().resolve(inputDir.toPath().relativize(file.toPath())).toFile()
}

def deleteRelated(File file) {
void deleteRelated(File file) {
def className = file.name.replaceFirst(/\.class$/, '')
// Delete any generated Lambda classes
project.logger.debug("Deleting related for " + className + " in " + file.parentFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class RetrolambdaTransform extends Transform {
BaseVariant variant = getVariant(context, outputDir)

if (variant == null) {
throw new ProjectConfigurationException('Missing variant for output dir: ' + outputDir, null)
throw new ProjectConfigurationException('Missing variant for output dir: ' + outputDir, (Throwable) null)
}

FileCollection classpathFiles = variant.javaCompile.classpath
Expand All @@ -132,7 +132,7 @@ class RetrolambdaTransform extends Transform {
} else {
// If this is null it means the javaCompile task didn't need to run, however, we still
// need to run but can't without the bootClasspath. Just fail and ask the user to rebuild.
throw new ProjectConfigurationException("Unable to obtain the bootClasspath. This may happen if your javaCompile tasks didn't run but retrolambda did. You must rebuild your project or otherwise force javaCompile to run.", null)
throw new ProjectConfigurationException("Unable to obtain the bootClasspath. This may happen if your javaCompile tasks didn't run but retrolambda did. You must rebuild your project or otherwise force javaCompile to run.", (Throwable) null)
}

return classpathFiles
Expand Down Expand Up @@ -161,7 +161,7 @@ class RetrolambdaTransform extends Transform {
// This will no longer be needed when the transform api supports per-variant transforms
String[] parts = outputDir.toURI().path.split('/intermediates/transforms/retrolambda/|/folders/[0-9]+')
if (parts.length < 2) {
throw new ProjectConfigurationException('Could not extract variant from output dir: ' + outputDir, null)
throw new ProjectConfigurationException('Could not extract variant from output dir: ' + outputDir, (Throwable) null)
}
String variantPath = parts[1]
for (BaseVariant variant : variants) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
package me.tatarka

import groovy.transform.TypeChecked
import groovy.transform.TypeCheckingMode
import org.gradle.api.tasks.SourceSet

class RetrolambdaUtil {
static String capitalize(CharSequence self) {
return self.length() == 0 ? "" : "" + Character.toUpperCase(self.charAt(0)) + self.subSequence(1, self.length())
}

@TypeChecked(TypeCheckingMode.SKIP)
static File javaOutputDir(SourceSet set) {
try {
return set.java.outputDir
} catch (Exception e) {
return set.output.classesDir
}
}

@TypeChecked(TypeCheckingMode.SKIP)
static File groovyOutputDir(SourceSet set) {
try {
return set.groovy.outputDir
} catch (Exception e) {
return set.output.classesDir
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
import java.util.Arrays;
import java.util.Collection;

import static me.tatarka.TestHelpers.findFile;
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 me.tatarka.TestHelpers.*;
import static org.assertj.core.api.Assertions.assertThat;

@RunWith(Parameterized.class)
Expand All @@ -38,19 +34,22 @@ public static Collection<Object[]> data() {
private final String androidVersion;
private final String gradleVersion;
private final String buildToolsVersion;
private final String kotlinVersion;
private File rootDir;
private File buildFile;

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

@Before
public void setup() throws Exception {
rootDir = testProjectDir.getRoot();
buildFile = testProjectDir.newFile("build.gradle");
copyLocalPropertiesIfExists(rootDir);
}

@Test
Expand All @@ -75,6 +74,7 @@ public void assembleDebug() throws Exception {
"apply plugin: 'me.tatarka.retrolambda'\n" +
"\n" +
"repositories {\n" +
" maven { url 'https://maven.google.com' }\n" +
" mavenCentral()\n" +
"}\n" +
"\n" +
Expand All @@ -92,7 +92,7 @@ public void assembleDebug() throws Exception {

writeFile(manifestFile,
//language="XML"
"<manifest package=\"test\" " +
"<manifest package=\"test.test\" " +
"xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <application/>\n" +
"</manifest>");
Expand Down Expand Up @@ -147,6 +147,7 @@ public void assembleDebugIncremental() throws Exception {
"apply plugin: 'me.tatarka.retrolambda'\n" +
"\n" +
"repositories {\n" +
" maven { url 'https://maven.google.com' }\n" +
" mavenCentral()\n" +
"}\n" +
"\n" +
Expand All @@ -164,7 +165,7 @@ public void assembleDebugIncremental() throws Exception {

writeFile(manifestFile,
//language="XML"
"<manifest package=\"test\" " +
"<manifest package=\"test.test\" " +
"xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <application/>\n" +
"</manifest>");
Expand Down Expand Up @@ -240,6 +241,7 @@ public void assembleDebugIncrementalShouldntLeak() throws Exception {
"apply plugin: 'me.tatarka.retrolambda'\n" +
"\n" +
"repositories {\n" +
" maven { url 'https://maven.google.com' }\n" +
" mavenCentral()\n" +
"}\n" +
"\n" +
Expand All @@ -257,7 +259,7 @@ public void assembleDebugIncrementalShouldntLeak() throws Exception {

writeFile(manifestFile,
//language="XML"
"<manifest package=\"test\" " +
"<manifest package=\"test.test\" " +
"xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <application/>\n" +
"</manifest>");
Expand Down Expand Up @@ -293,13 +295,15 @@ public void assembleDebugIncrementalShouldntLeak() throws Exception {
assertThat(lambdaClassFile).exists();

// delete the java file
javaFile.delete();
if (!javaFile.delete()) {
throw new Exception("Failed to delete file: " + javaFile);
}

errorOutput = new StringWriter();
result = GradleRunner.create()
.withGradleVersion(gradleVersion)
.withProjectDir(rootDir)
.withArguments("assembleDebug", "--stacktrace", "-Pandroid.enableAapt2=false")
.withArguments("assembleDebug", "--stacktrace", "-Pandroid.enableAapt2=false", "--debug")
.forwardStdError(errorOutput)
.build();

Expand Down Expand Up @@ -329,6 +333,7 @@ public void unitTest() throws Exception {
"apply plugin: 'me.tatarka.retrolambda'\n" +
"\n" +
"repositories {\n" +
" maven { url 'https://maven.google.com' }\n" +
" mavenCentral()\n" +
"}\n" +
"\n" +
Expand All @@ -350,7 +355,7 @@ public void unitTest() throws Exception {

writeFile(manifestFile,
//language="XML"
"<manifest package=\"test\" " +
"<manifest package=\"test.test\" " +
"xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <application/>\n" +
"</manifest>");
Expand Down Expand Up @@ -414,6 +419,7 @@ public void androidTest() throws Exception {
"apply plugin: 'me.tatarka.retrolambda'\n" +
"\n" +
"repositories {\n" +
" maven { url 'https://maven.google.com' }\n" +
" mavenCentral()\n" +
"}\n" +
"\n" +
Expand Down Expand Up @@ -494,7 +500,7 @@ public void withKotlin() throws Exception {
" dependencies {\n" +
" classpath files(" + getPluginClasspath() + ")\n" +
" classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" +
" classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0'" +
" classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:" + kotlinVersion + "'" +
" }\n" +
"}\n" +
"\n" +
Expand All @@ -503,6 +509,7 @@ public void withKotlin() throws Exception {
"apply plugin: 'kotlin-android'\n" +
"\n" +
"repositories {\n" +
" maven { url 'https://maven.google.com' }\n" +
" mavenCentral()\n" +
"}\n" +
"\n" +
Expand All @@ -523,7 +530,7 @@ public void withKotlin() throws Exception {

writeFile(manifestFile,
//language="XML"
"<manifest package=\"test\" " +
"<manifest package=\"test.test\" " +
"xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <application/>\n" +
"</manifest>");
Expand Down
Loading