Skip to content

Commit

Permalink
use try catch clause for more accurate relative path check.
Browse files Browse the repository at this point in the history
  • Loading branch information
neetopia committed Oct 11, 2022
1 parent e9d7c81 commit a68d2a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Expand Up @@ -231,10 +231,11 @@ class IncrementalContext(
// Ugly, but better than copying the private logics out of stdlib.
// TODO: get rid of `relativeTo` if possible.
private fun String.toRelativeFile(): File =
if (this.startsWith(buildDir.path))
try {
File(this).relativeTo(buildDir)
else
} catch (e: Exception) {
File(this).relativeTo(baseDir)
}

private val KSFile.relativeFile
get() = filePath.toRelativeFile()
Expand Down
Expand Up @@ -65,6 +65,28 @@ class PlaygroundIT {
project.restore("workload/build.gradle.kts")
}

@Test
fun testArbitraryBuildDir() {
Assume.assumeTrue(System.getProperty("os.name").startsWith("Windows", ignoreCase = true))
val gradleRunner = GradleRunner.create().withProjectDir(project.root)

File(project.root, "workload/build.gradle.kts")
.appendText("project.buildDir = File(\"D:/build/\")")
val result = gradleRunner.withArguments("build").build()

Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":workload:build")?.outcome)

val artifact = File("D:/build/libs/workload-1.0-SNAPSHOT.jar")
Assert.assertTrue(artifact.exists())

JarFile(artifact).use { jarFile ->
Assert.assertTrue(jarFile.getEntry("TestProcessor.log").size > 0)
Assert.assertTrue(jarFile.getEntry("hello/HELLO.class").size > 0)
Assert.assertTrue(jarFile.getEntry("g/G.class").size > 0)
Assert.assertTrue(jarFile.getEntry("com/example/AClassBuilder.class").size > 0)
}
}

@Test
fun testAllowSourcesFromOtherPlugins() {
fun checkGBuilder() {
Expand Down

0 comments on commit a68d2a7

Please sign in to comment.