-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change AGP and ddmlib to compileOnly instead of implementation (#96)
* Convert PluginTestHelper to Kotlin and move to test source set * Change AGP and ddmlib to compileOnly instead of implementation This is to avoid pulling a higher version when OkReplay plugin is applied. * Remove no longer used function
- Loading branch information
1 parent
da2789c
commit 1e6163f
Showing
8 changed files
with
110 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 0 additions & 91 deletions
91
okreplay-gradle-plugin/src/main/groovy/okreplay/PluginTestHelper.groovy
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
okreplay-gradle-plugin/src/test/kotlin/okreplay/PluginTestHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package okreplay | ||
|
||
import com.android.build.gradle.AppPlugin | ||
import com.android.build.gradle.BaseExtension | ||
import org.apache.commons.io.FileUtils | ||
import org.gradle.api.Project | ||
import org.gradle.api.internal.project.ProjectInternal | ||
import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading | ||
import java.io.File | ||
import java.util.Properties | ||
|
||
fun Project.setupDefaultAndroidProject() { | ||
prepareLocalProperties(projectDir) | ||
|
||
val manifest = File(projectDir, "src/main/AndroidManifest.xml") | ||
manifest.parentFile.mkdirs() | ||
manifest.writeText("<manifest package=\"com.example.okreplay\"/>") | ||
pluginManager.apply(AppPlugin::class.java) | ||
|
||
val androidExtension = extensions.getByType(BaseExtension::class.java) | ||
androidExtension.compileSdkVersion(28) | ||
} | ||
|
||
fun Project.applyOkReplay() { | ||
pluginManager.apply(OkReplayPlugin::class.java) | ||
} | ||
|
||
fun Project.evaluate() { | ||
(this as ProjectInternal).evaluate() | ||
} | ||
|
||
fun createTempTestDirectory(testProjectName: String): File { | ||
val dir = File(workingDir, "build/integrationTests/$testProjectName") | ||
FileUtils.deleteDirectory(dir) | ||
FileUtils.forceMkdir(dir) | ||
return dir | ||
} | ||
|
||
fun prepareProjectTestDir(destDir: File, testProjectName: String, testBuildScriptName: String) { | ||
val testProjectsRoot = "src/test/testProject" | ||
val projectTypeRoot = File("$testProjectsRoot/android") | ||
val projectUnderTest = File(workingDir, "$projectTypeRoot/$testProjectName") | ||
check(projectUnderTest.isDirectory) { "Couldn't find test project" } | ||
|
||
val requestedBuildScript = File( | ||
"$projectTypeRoot/buildScriptFixtures/$testBuildScriptName.gradle") | ||
val requestedSettingsFile = File( | ||
"$projectTypeRoot/buildScriptFixtures/settings.gradle") | ||
check(requestedBuildScript.isFile) { "Couldn't find the test build script" } | ||
|
||
prepareLocalProperties(destDir) | ||
projectUnderTest.copyRecursively(destDir) | ||
requestedSettingsFile.copyTo(File(destDir, "settings.gradle")) | ||
|
||
val buildScript = requestedBuildScript.readText() | ||
.replace("\$PLUGIN_CLASSPATH", getPluginClasspath()) | ||
File(destDir, "build.gradle").writeText(buildScript) | ||
} | ||
|
||
private fun prepareLocalProperties(destDir: File) { | ||
val localProperties = File(destDir, "local.properties") | ||
localProperties.writeText("sdk.dir=${androidHome()}") | ||
} | ||
|
||
private fun androidHome(): String { | ||
val envVar = System.getenv("ANDROID_HOME") | ||
if (envVar != null) { | ||
return envVar | ||
} | ||
val localPropFile = File(workingDir.parentFile, "local.properties") | ||
if (localPropFile.isFile) { | ||
val props = Properties() | ||
localPropFile.inputStream().use { props.load(it) } | ||
val sdkDir = props.getProperty("sdk.dir") | ||
if (sdkDir != null) { | ||
return sdkDir | ||
} | ||
} | ||
throw IllegalStateException("SDK location not found. Define location with sdk.dir in the " + | ||
"local.properties file or with an ANDROID_HOME environment variable.") | ||
} | ||
|
||
private fun getPluginClasspath(): String { | ||
return PluginUnderTestMetadataReading.readImplementationClasspath() | ||
.asSequence() | ||
.map { it.absolutePath.replace("\\", "\\\\") } // escape backslashes on Windows | ||
.joinToString(", ") { "'$it'" } | ||
} | ||
|
||
private val workingDir: File | ||
get() = File(System.getProperty("user.dir")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.