Move Gradle Integration test classes to separate module for better re-use
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<root>
|
||||||
|
<item name='com.google.common.io.Files java.io.File createTempDir()'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
</root>
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.version>3.0.4</maven.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-project</artifactId>
|
||||||
|
<version>0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>kotlin-gradle-plugin-test</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.11</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>16.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.basedir}/src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<annotationPaths>
|
||||||
|
<annotationPath>${basedir}/annotations</annotationPath>
|
||||||
|
</annotationPaths>
|
||||||
|
</configuration>
|
||||||
|
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals> <goal>compile</goal> </goals>
|
||||||
|
</execution>
|
||||||
|
|
||||||
|
<execution>
|
||||||
|
<id>test-compile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals> <goal>test-compile</goal> </goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>jetbrains-utils</id>
|
||||||
|
<url>http://repository.jetbrains.com/utils</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
</project>
|
||||||
+119
@@ -0,0 +1,119 @@
|
|||||||
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
|
import com.google.common.io.Files
|
||||||
|
import java.io.File
|
||||||
|
import java.util.Scanner
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.After
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.fail
|
||||||
|
|
||||||
|
open class BaseGradleIT {
|
||||||
|
|
||||||
|
var workingDir: File = File(".")
|
||||||
|
|
||||||
|
Before fun setUp() {
|
||||||
|
workingDir = Files.createTempDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
After fun tearDown() {
|
||||||
|
deleteRecursively(workingDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Project(val projectName: String, val wrapperVersion: String = "1.4")
|
||||||
|
|
||||||
|
class CompiledProject(val project: Project, val output: String, val resultCode: Int)
|
||||||
|
|
||||||
|
fun Project.build(vararg tasks: String, check: CompiledProject.() -> Unit) {
|
||||||
|
copyRecursively(File("src/test/resources/testProject/$projectName"), workingDir)
|
||||||
|
val projectDir = File(workingDir, projectName)
|
||||||
|
copyDirRecursively(File("src/test/resources/GradleWrapper-$wrapperVersion"), projectDir)
|
||||||
|
val cmd = createCommand(tasks)
|
||||||
|
val process = createProcess(cmd, projectDir)
|
||||||
|
|
||||||
|
val (output, resultCode) = readOutput(process)
|
||||||
|
CompiledProject(this, output, resultCode).check()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CompiledProject.assertSuccessful(): CompiledProject {
|
||||||
|
assertEquals(resultCode, 0)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CompiledProject.assertContains(vararg expected: String): CompiledProject {
|
||||||
|
for (str in expected) {
|
||||||
|
assertTrue(output.contains(str), "Should contain '$str', actual output: $output")
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CompiledProject.assertReportExists(pathToReport: String = ""): CompiledProject {
|
||||||
|
assertTrue(File(File(workingDir, project.projectName), pathToReport).exists(), "The report [$pathToReport] does not exist.")
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createCommand(params: Array<String>): List<String> {
|
||||||
|
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").getAbsolutePath()
|
||||||
|
val tailParameters = params + listOf(pathToKotlinPlugin, "--no-daemon", "--debug")
|
||||||
|
|
||||||
|
return if (isWindows())
|
||||||
|
listOf("cmd", "/C", "gradlew.bat") + tailParameters
|
||||||
|
else
|
||||||
|
listOf("/bin/bash", "./gradlew") + tailParameters
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isWindows(): Boolean {
|
||||||
|
return System.getProperty("os.name")!!.contains("Windows")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createProcess(cmd: List<String>, projectDir: File): Process {
|
||||||
|
val builder = ProcessBuilder(cmd)
|
||||||
|
builder.directory(projectDir)
|
||||||
|
builder.redirectErrorStream(true)
|
||||||
|
return builder.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readOutput(process: Process): Pair<String, Int> {
|
||||||
|
val s = Scanner(process.getInputStream()!!)
|
||||||
|
val text = StringBuilder()
|
||||||
|
while (s.hasNextLine()) {
|
||||||
|
text append s.nextLine()
|
||||||
|
text append "\n"
|
||||||
|
}
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
val result = process.waitFor()
|
||||||
|
return text.toString() to result
|
||||||
|
}
|
||||||
|
|
||||||
|
fun copyRecursively(source: File, target: File) {
|
||||||
|
assertTrue(target.isDirectory())
|
||||||
|
val targetFile = File(target, source.getName())
|
||||||
|
if (source.isDirectory()) {
|
||||||
|
targetFile.mkdir()
|
||||||
|
source.listFiles()?.forEach { copyRecursively(it, targetFile) }
|
||||||
|
} else {
|
||||||
|
Files.copy(source, targetFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun copyDirRecursively(source: File, target: File) {
|
||||||
|
assertTrue(source.isDirectory())
|
||||||
|
assertTrue(target.isDirectory())
|
||||||
|
source.listFiles()?.forEach { copyRecursively(it, target) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteRecursively(f: File): Unit {
|
||||||
|
if (f.isDirectory()) {
|
||||||
|
f.listFiles()?.forEach { deleteRecursively(it) }
|
||||||
|
val fileList = f.listFiles()
|
||||||
|
if (fileList != null) {
|
||||||
|
assertTrue(fileList.isEmpty())
|
||||||
|
} else {
|
||||||
|
fail("Error listing directory content")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user