Fixes after review
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<root>
|
||||||
|
<item name='com.google.common.base.Joiner com.google.common.base.Joiner on(java.lang.String)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
</root>
|
||||||
+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>
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<root>
|
||||||
|
<item name='org.apache.commons.io.FilenameUtils java.lang.String getExtension(java.lang.String)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
</root>
|
||||||
@@ -4,4 +4,10 @@
|
|||||||
<val name="value" val=""fun apply(p0 : T) : Unit""/>
|
<val name="value" val=""fun apply(p0 : T) : Unit""/>
|
||||||
</annotation>
|
</annotation>
|
||||||
</item>
|
</item>
|
||||||
|
<item name='org.gradle.api.Project org.gradle.api.plugins.PluginContainer getPlugins()'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item name='org.gradle.api.Project org.gradle.api.plugins.Convention getConvention()'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
</root>
|
</root>
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<root>
|
||||||
|
<item name='org.gradle.api.file.FileCollection org.gradle.api.file.FileCollection filter(org.gradle.api.specs.Spec<? super java.io.File>)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
</root>
|
||||||
+1
-3
@@ -5,8 +5,6 @@
|
|||||||
</annotation>
|
</annotation>
|
||||||
</item>
|
</item>
|
||||||
<item name='org.gradle.api.internal.AbstractTask org.gradle.api.logging.Logger getLogger()'>
|
<item name='org.gradle.api.internal.AbstractTask org.gradle.api.logging.Logger getLogger()'>
|
||||||
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
<val name="value" val=""fun getLogger() : Logger?""/>
|
|
||||||
</annotation>
|
|
||||||
</item>
|
</item>
|
||||||
</root>
|
</root>
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<root>
|
||||||
|
<item name='org.gradle.api.internal.project.ProjectInternal org.gradle.api.internal.tasks.TaskContainerInternal getTasks()'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
</root>
|
||||||
+9
@@ -10,4 +10,13 @@
|
|||||||
<val name="value" val=""fun getExtensionsAsDynamicObject() : DynamicObject""/>
|
<val name="value" val=""fun getExtensionsAsDynamicObject() : DynamicObject""/>
|
||||||
</annotation>
|
</annotation>
|
||||||
</item>
|
</item>
|
||||||
|
<item name='org.gradle.api.plugins.PluginContainer org.gradle.api.Plugin apply(java.lang.String)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item name='org.gradle.api.plugins.PluginContainer T apply(java.lang.Class<T>)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item name='org.gradle.api.plugins.Convention T getPlugin(java.lang.Class<T>)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
</root>
|
</root>
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<root>
|
||||||
|
<item name='org.gradle.api.tasks.compile.AbstractCompile org.gradle.api.file.FileCollection getClasspath()'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
</root>
|
||||||
@@ -21,16 +21,27 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>gradle-api</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>1.4</version>
|
<version>4.11</version>
|
||||||
<scope>provided</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>12.0</version>
|
<version>12.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.directory.studio</groupId>
|
||||||
|
<artifactId>org.apache.commons.io</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>gradle-api</artifactId>
|
||||||
|
<version>1.4</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-compiler</artifactId>
|
<artifactId>kotlin-compiler</artifactId>
|
||||||
@@ -43,15 +54,9 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-runtime</artifactId>
|
<artifactId>kotlin-stdlib</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.testng</groupId>
|
|
||||||
<artifactId>testng</artifactId>
|
|
||||||
<version>6.8</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
@@ -94,6 +99,7 @@
|
|||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<!-- Invoker plugin maintains local maven repository in local-repo for gradle integration tests -->
|
||||||
<artifactId>maven-invoker-plugin</artifactId>
|
<artifactId>maven-invoker-plugin</artifactId>
|
||||||
<version>1.8</version>
|
<version>1.8</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
@@ -125,4 +131,11 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>jetbrains-utils</id>
|
||||||
|
<url>http://repository.jetbrains.com/utils</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
</project>
|
</project>
|
||||||
+6
-11
@@ -6,31 +6,26 @@ import org.gradle.api.internal.file.FileResolver
|
|||||||
import org.gradle.api.internal.file.DefaultSourceDirectorySet
|
import org.gradle.api.internal.file.DefaultSourceDirectorySet
|
||||||
import org.gradle.util.ConfigureUtil
|
import org.gradle.util.ConfigureUtil
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Nikita.Skvortsov
|
|
||||||
* Date: 2/21/13, 5:51 PM
|
|
||||||
*/
|
|
||||||
|
|
||||||
trait KotlinSourceSet {
|
trait KotlinSourceSet {
|
||||||
|
|
||||||
open fun getKotlin() : SourceDirectorySet
|
fun getKotlin(): SourceDirectorySet
|
||||||
open fun kotlin(configureClosure : Closure<Any?>?) : KotlinSourceSet
|
fun kotlin(configureClosure: Closure<Any?>?): KotlinSourceSet
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open class KotlinSourceSetImpl(displayName : String?, resolver : FileResolver?) : KotlinSourceSet {
|
open class KotlinSourceSetImpl(displayName: String?, resolver: FileResolver?): KotlinSourceSet {
|
||||||
|
|
||||||
private val kotlin : DefaultSourceDirectorySet = DefaultSourceDirectorySet(displayName + " Kotlin source", resolver);
|
private val kotlin: DefaultSourceDirectorySet = DefaultSourceDirectorySet(displayName + " Kotlin source", resolver);
|
||||||
{
|
{
|
||||||
kotlin.getFilter()?.include("**/*.java", "**/*.kt")
|
kotlin.getFilter()?.include("**/*.java", "**/*.kt")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getKotlin() : SourceDirectorySet {
|
override fun getKotlin(): SourceDirectorySet {
|
||||||
return kotlin
|
return kotlin
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun kotlin(configureClosure : Closure<Any?>?) : KotlinSourceSet {
|
override fun kotlin(configureClosure: Closure<Any?>?): KotlinSourceSet {
|
||||||
ConfigureUtil.configure(configureClosure, getKotlin())
|
ConfigureUtil.configure(configureClosure, getKotlin())
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-27
@@ -25,33 +25,28 @@ import org.gradle.api.Action
|
|||||||
import org.gradle.api.tasks.compile.AbstractCompile
|
import org.gradle.api.tasks.compile.AbstractCompile
|
||||||
import java.util.Arrays
|
import java.util.Arrays
|
||||||
|
|
||||||
|
open class KotlinPlugin: Plugin<Project> {
|
||||||
/**
|
|
||||||
* Created by Nikita.Skvortsov
|
|
||||||
* Date: 2/21/13, 5:55 PM
|
|
||||||
*/
|
|
||||||
|
|
||||||
open class KotlinPlugin : Plugin<Project> {
|
|
||||||
|
|
||||||
public override fun apply(project: Project) {
|
public override fun apply(project: Project) {
|
||||||
val javaBasePlugin = project.getPlugins()?.apply(javaClass<JavaBasePlugin>())!!
|
val javaBasePlugin = project.getPlugins().apply(javaClass<JavaBasePlugin>())
|
||||||
val javaPluginConvention = project.getConvention()?.getPlugin(javaClass<JavaPluginConvention>())!!
|
val javaPluginConvention = project.getConvention().getPlugin(javaClass<JavaPluginConvention>())
|
||||||
|
|
||||||
project.getPlugins()?.apply(javaClass<JavaPlugin>())
|
project.getPlugins().apply(javaClass<JavaPlugin>())
|
||||||
|
|
||||||
configureSourceSetDefaults(project as ProjectInternal, javaBasePlugin, javaPluginConvention)
|
configureSourceSetDefaults(project as ProjectInternal, javaBasePlugin, javaPluginConvention)
|
||||||
configureKDoc(project, javaPluginConvention)
|
configureKDoc(project, javaPluginConvention)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun configureSourceSetDefaults( project: ProjectInternal,
|
private fun configureSourceSetDefaults(project: ProjectInternal,
|
||||||
javaBasePlugin: JavaBasePlugin,
|
javaBasePlugin: JavaBasePlugin,
|
||||||
javaPluginConvention: JavaPluginConvention) {
|
javaPluginConvention: JavaPluginConvention) {
|
||||||
javaPluginConvention.getSourceSets()?.all(object : Action<SourceSet> {
|
javaPluginConvention.getSourceSets()?.all(object : Action<SourceSet> {
|
||||||
override fun execute(sourceSet : SourceSet?) {
|
override fun execute(sourceSet: SourceSet?) {
|
||||||
if (sourceSet is HasConvention) {
|
if (sourceSet is HasConvention) {
|
||||||
val sourceSetName = sourceSet.getName()
|
val sourceSetName = sourceSet.getName()
|
||||||
val kotlinSourceSet = KotlinSourceSetImpl(sourceSetName, project.getFileResolver())
|
val kotlinSourceSet = KotlinSourceSetImpl(sourceSetName, project.getFileResolver())
|
||||||
|
|
||||||
val kotlinDirSet = kotlinSourceSet.getKotlin()
|
val kotlinDirSet = kotlinSourceSet.getKotlin()
|
||||||
kotlinDirSet.srcDir(project.file("src/${sourceSetName}/kotlin"))
|
kotlinDirSet.srcDir(project.file("src/${sourceSetName}/kotlin"))
|
||||||
|
|
||||||
@@ -59,22 +54,22 @@ open class KotlinPlugin : Plugin<Project> {
|
|||||||
sourceSet.getAllSource()?.source(kotlinDirSet)
|
sourceSet.getAllSource()?.source(kotlinDirSet)
|
||||||
sourceSet.getConvention().getPlugins().put("kotlin", kotlinSourceSet)
|
sourceSet.getConvention().getPlugins().put("kotlin", kotlinSourceSet)
|
||||||
|
|
||||||
sourceSet.getResources()?.getFilter()?.exclude(KSpec({ (elem: FileTreeElement) ->
|
sourceSet.getResources()?.getFilter()?.exclude(KSpec({ elem ->
|
||||||
kotlinDirSet.contains(elem.getFile())
|
kotlinDirSet.contains(elem.getFile())
|
||||||
}))
|
}))
|
||||||
|
|
||||||
val kotlinTaskName = sourceSet.getCompileTaskName("kotlin")
|
val kotlinTaskName = sourceSet.getCompileTaskName("kotlin")
|
||||||
val kotlinTask : KotlinCompile = project.getTasks()?.add(kotlinTaskName , javaClass<KotlinCompile>())!!
|
val kotlinTask: KotlinCompile = project.getTasks().add(kotlinTaskName, javaClass<KotlinCompile>())!!
|
||||||
|
|
||||||
javaBasePlugin.configureForSourceSet(sourceSet, kotlinTask)
|
javaBasePlugin.configureForSourceSet(sourceSet, kotlinTask)
|
||||||
|
|
||||||
kotlinTask setDescription "Compiles the $sourceSet.kotlin."
|
kotlinTask.setDescription("Compiles the $sourceSet.kotlin.")
|
||||||
kotlinTask source kotlinDirSet
|
kotlinTask.source(kotlinDirSet)
|
||||||
|
|
||||||
val javaTask = project.getTasks()?.findByName(sourceSet.getCompileJavaTaskName()) as AbstractCompile?
|
val javaTask = project.getTasks().findByName(sourceSet.getCompileJavaTaskName()) as AbstractCompile?
|
||||||
javaTask?.dependsOn(kotlinTaskName)
|
javaTask?.dependsOn(kotlinTaskName)
|
||||||
|
|
||||||
val sourceSetCompileConfigurationName = if (sourceSetName.equals("main")) {
|
val sourceSetCompileConfigurationName = if (sourceSetName == SourceSet.MAIN_SOURCE_SET_NAME) {
|
||||||
"compile"
|
"compile"
|
||||||
} else {
|
} else {
|
||||||
"${sourceSetName}Compile"
|
"${sourceSetName}Compile"
|
||||||
@@ -83,21 +78,21 @@ open class KotlinPlugin : Plugin<Project> {
|
|||||||
project.getDependencies()?.add(sourceSetCompileConfigurationName, project.files(kotlinTask.getDestinationDir()))
|
project.getDependencies()?.add(sourceSetCompileConfigurationName, project.files(kotlinTask.getDestinationDir()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureKDoc(project: Project, javaPluginConvention: JavaPluginConvention) {
|
private fun configureKDoc(project: Project, javaPluginConvention: JavaPluginConvention) {
|
||||||
val mainSourceSet : HasConvention = javaPluginConvention.getSourceSets()?.getByName(SourceSet.MAIN_SOURCE_SET_NAME)!! as HasConvention
|
val mainSourceSet = javaPluginConvention.getSourceSets()?.getByName(SourceSet.MAIN_SOURCE_SET_NAME)!! as HasConvention
|
||||||
|
|
||||||
val kdoc : KDoc = project.getTasks()?.add(KDOC_TASK_NAME, javaClass<KDoc>())!!
|
val kdoc = project.getTasks()?.add(KDOC_TASK_NAME, javaClass<KDoc>())!!
|
||||||
kdoc.setDescription("Generates KDoc API documentation for the main source code.")
|
kdoc.setDescription("Generates KDoc API documentation for the main source code.")
|
||||||
kdoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP)
|
kdoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP)
|
||||||
kdoc.setSource(mainSourceSet.getConvention().getExtensionsAsDynamicObject().getProperty("kotlin"))
|
kdoc.setSource(mainSourceSet.getConvention().getExtensionsAsDynamicObject().getProperty("kotlin"))
|
||||||
|
|
||||||
project.getTasks()?.withType(javaClass<KDoc>(), object : Action<KDoc> {
|
project.getTasks()?.withType(javaClass<KDoc>(), object : Action<KDoc> {
|
||||||
override fun execute(param : KDoc?) {
|
override fun execute(param: KDoc?) {
|
||||||
param?.getConventionMapping()?.map("destinationDir", object : Callable<Any> {
|
param?.getConventionMapping()?.map("destinationDir", object : Callable<Any> {
|
||||||
override fun call() : Any {
|
override fun call(): Any {
|
||||||
return File(javaPluginConvention.getDocsDir(), "kdoc");
|
return File(javaPluginConvention.getDocsDir(), "kdoc");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -105,11 +100,11 @@ open class KotlinPlugin : Plugin<Project> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public val KDOC_TASK_NAME : String = "kdoc"
|
public val KDOC_TASK_NAME: String = "kdoc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open class KSpec<T : Any?>(val predicate : (T) -> Boolean) : Spec<T> {
|
open class KSpec<T: Any?>(val predicate: (T) -> Boolean): Spec<T> {
|
||||||
public override fun isSatisfiedBy(p0: T?): Boolean {
|
public override fun isSatisfiedBy(p0: T?): Boolean {
|
||||||
return p0 != null && predicate(p0)
|
return p0 != null && predicate(p0)
|
||||||
}
|
}
|
||||||
|
|||||||
+85
-66
@@ -21,20 +21,21 @@ import java.net.URL
|
|||||||
import com.google.common.io.Files
|
import com.google.common.io.Files
|
||||||
import org.gradle.api.file.SourceDirectorySet
|
import org.gradle.api.file.SourceDirectorySet
|
||||||
import com.google.common.base.Joiner
|
import com.google.common.base.Joiner
|
||||||
|
import java.util.ArrayList
|
||||||
|
import org.apache.commons.io.FilenameUtils
|
||||||
|
import org.jetbrains.jet.cli.common.messages.MessageCollector
|
||||||
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity
|
||||||
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation
|
||||||
|
import org.gradle.api.logging.Logger
|
||||||
|
|
||||||
/**
|
public open class KotlinCompile(): AbstractCompile() {
|
||||||
* Created by Nikita.Skvortsov
|
|
||||||
* Date: 2/22/13, 2:56 PM
|
|
||||||
*/
|
|
||||||
|
|
||||||
open class KotlinCompile() : AbstractCompile() {
|
|
||||||
|
|
||||||
val srcDirsRoots = HashSet<File>()
|
val srcDirsRoots = HashSet<File>()
|
||||||
val compiler = K2JVMCompiler()
|
val compiler = K2JVMCompiler()
|
||||||
val logger = getLogger()
|
val logger = getLogger()
|
||||||
|
|
||||||
// override setSource to track source directory sets
|
// override setSource to track source directory sets
|
||||||
override fun setSource(source : Any?) {
|
override fun setSource(source: Any?) {
|
||||||
srcDirsRoots.clear()
|
srcDirsRoots.clear()
|
||||||
if (source is SourceDirectorySet) {
|
if (source is SourceDirectorySet) {
|
||||||
srcDirsRoots.addAll(source.getSrcDirs())
|
srcDirsRoots.addAll(source.getSrcDirs())
|
||||||
@@ -43,7 +44,7 @@ open class KotlinCompile() : AbstractCompile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// override source to track source directory sets
|
// override source to track source directory sets
|
||||||
override fun source(vararg sources : Any?) : SourceTask? {
|
override fun source(vararg sources: Any?): SourceTask? {
|
||||||
for (source in sources) {
|
for (source in sources) {
|
||||||
if (source is SourceDirectorySet) {
|
if (source is SourceDirectorySet) {
|
||||||
srcDirsRoots.addAll(source.getSrcDirs())
|
srcDirsRoots.addAll(source.getSrcDirs())
|
||||||
@@ -52,142 +53,144 @@ open class KotlinCompile() : AbstractCompile() {
|
|||||||
return super.source(sources)
|
return super.source(sources)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findSrcDirRoot(file : File) : String {
|
fun findSrcDirRoot(file: File): File? {
|
||||||
val absPath = file.getAbsolutePath()
|
val absPath = file.getAbsolutePath()
|
||||||
for (root in srcDirsRoots) {
|
for (root in srcDirsRoots) {
|
||||||
val rootAbsPath = root.getAbsolutePath()
|
val rootAbsPath = root.getAbsolutePath()
|
||||||
if (absPath.contains(rootAbsPath)) {
|
if (FilenameUtils.directoryContains(rootAbsPath, absPath)) {
|
||||||
return rootAbsPath
|
return root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun compile() {
|
override fun compile() {
|
||||||
|
|
||||||
val args = K2JVMCompilerArguments();
|
val args = K2JVMCompilerArguments()
|
||||||
val javaSrcRoots = HashSet<String>()
|
|
||||||
|
|
||||||
val sources : MutableList<String> = LinkedList<String>()
|
val javaSrcRoots = HashSet<File>()
|
||||||
|
val sources = ArrayList<File>()
|
||||||
|
|
||||||
// collect source directory roots for all java files to allow cross compilation
|
// collect source directory roots for all java files to allow cross compilation
|
||||||
getSource().mapTo(sources, { (f : File) : String ->
|
for (file in getSource()) {
|
||||||
if (f.getName().endsWith(".java")) {
|
if (FilenameUtils.getExtension(file.getName()).equalsIgnoreCase("java")) {
|
||||||
val javaRoot = findSrcDirRoot(f)
|
val javaRoot = findSrcDirRoot(file)
|
||||||
if (javaRoot.length() > 0) {
|
if (javaRoot != null) {
|
||||||
javaSrcRoots.add(javaRoot)
|
javaSrcRoots.add(javaRoot)
|
||||||
}
|
}
|
||||||
""
|
|
||||||
} else {
|
} else {
|
||||||
f.getAbsolutePath()
|
sources.add(file)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
args.setSourceDirs(sources.filter { it.length() > 0 })
|
|
||||||
|
|
||||||
val joiner = Joiner.on(File.pathSeparator)!!
|
|
||||||
val gradleClasspath = getClasspath()?.filter(KSpec<File?>({ it != null && it.isAbsolute() }))?.getAsPath()
|
|
||||||
val javaSrcClasspath = joiner.join(javaSrcRoots)
|
|
||||||
val effectiveClassPath = joiner.join(javaSrcClasspath, gradleClasspath)
|
|
||||||
|
|
||||||
if (effectiveClassPath != null && effectiveClassPath.length() > 0) {
|
|
||||||
args.setClasspath(effectiveClassPath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
args.outputDir = (getDestinationDir()?.getPath())
|
if (sources.empty) {
|
||||||
|
getLogger().warn("No Kotlin files found, skipping Kotlin compiler task")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
args.setSourceDirs(sources.map { it.getAbsolutePath() })
|
||||||
|
|
||||||
|
// todo: WTF absolute == gradle class path?
|
||||||
|
val gradleClasspath = getClasspath().filter(KSpec { it != null && it.isAbsolute() })
|
||||||
|
val effectiveClassPath = (javaSrcRoots + gradleClasspath).makeString(File.pathSeparator)
|
||||||
|
|
||||||
|
args.setClasspath(effectiveClassPath)
|
||||||
|
|
||||||
|
val embeddedAnnotations = getAnnotations()
|
||||||
|
|
||||||
|
args.outputDir = getDestinationDir()?.getPath()
|
||||||
args.noJdkAnnotations = true
|
args.noJdkAnnotations = true
|
||||||
args.annotations = getAnnotations()
|
args.annotations = embeddedAnnotations.getPath()
|
||||||
args.noStdlib = true
|
args.noStdlib = true
|
||||||
|
|
||||||
val exitCode = compiler.exec(System.err, args)
|
val messageCollector = GradleMessageCollector(getLogger())
|
||||||
|
val exitCode = compiler.exec(messageCollector, args)
|
||||||
|
|
||||||
|
if (embeddedAnnotations.getParentFile()?.delete() != true) {
|
||||||
|
throw GradleException("Can't delete extracted annotations " + embeddedAnnotations)
|
||||||
|
}
|
||||||
|
|
||||||
when (exitCode) {
|
when (exitCode) {
|
||||||
ExitCode.COMPILATION_ERROR -> throw GradleException("Compilation error. See log for more details")
|
ExitCode.COMPILATION_ERROR -> throw GradleException("Compilation error. See log for more details")
|
||||||
ExitCode.INTERNAL_ERROR -> throw GradleException("Internal compiler error. See log for more details")
|
ExitCode.INTERNAL_ERROR -> throw GradleException("Internal compiler error. See log for more details")
|
||||||
else -> ""
|
else -> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAnnotations() : String? {
|
fun getAnnotations(): File {
|
||||||
val jdkAnnotations : String = "kotlin-jdk-annotations.jar"
|
val jdkAnnotations: String = "kotlin-jdk-annotations.jar"
|
||||||
val jdkAnnotationsResource : URL? = Resources.getResource(jdkAnnotations)
|
val jdkAnnotationsResource = Resources.getResource(jdkAnnotations) ?:
|
||||||
if (jdkAnnotationsResource == null) {
|
throw GradleException(jdkAnnotations + " not found in Kotlin gradle plugin classpath")
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo fix leak of deleteOnExit handlers
|
val jdkAnnotationsTempDir = Files.createTempDir()
|
||||||
val jdkAnnotationsTempDir : File? = Files.createTempDir()
|
val jdkAnnotationsFile = File(jdkAnnotationsTempDir, jdkAnnotations)
|
||||||
jdkAnnotationsTempDir?.deleteOnExit()
|
|
||||||
val jdkAnnotationsFile : File = File(jdkAnnotationsTempDir, jdkAnnotations)
|
|
||||||
|
|
||||||
Files.copy(Resources.newInputStreamSupplier(jdkAnnotationsResource), jdkAnnotationsFile)
|
Files.copy(Resources.newInputStreamSupplier(jdkAnnotationsResource), jdkAnnotationsFile)
|
||||||
return jdkAnnotationsFile.getPath()
|
return jdkAnnotationsFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public open class KDoc(): SourceTask() {
|
||||||
|
|
||||||
open class KDoc() : SourceTask() {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the directory to use to output the API docs
|
* Returns the directory to use to output the API docs
|
||||||
*/
|
*/
|
||||||
public var destinationDir : String = ""
|
public var destinationDir: String = ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the documentation set
|
* Returns the name of the documentation set
|
||||||
*/
|
*/
|
||||||
public var title : String = ""
|
public var title: String = ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the version name of the documentation set
|
* Returns the version name of the documentation set
|
||||||
*/
|
*/
|
||||||
public var version : String = ""
|
public var version: String = ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a map of the package prefix to the HTML URL for the root of the apidoc using javadoc/kdoc style
|
* Returns a map of the package prefix to the HTML URL for the root of the apidoc using javadoc/kdoc style
|
||||||
* directory layouts so that this API doc report can link to external packages
|
* directory layouts so that this API doc report can link to external packages
|
||||||
*/
|
*/
|
||||||
public var packagePrefixToUrls : Map<String, String> = HashMap()
|
public var packagePrefixToUrls: Map<String, String> = HashMap()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Set of the package name prefixes to ignore from the KDoc report
|
* Returns a Set of the package name prefixes to ignore from the KDoc report
|
||||||
*/
|
*/
|
||||||
public var ignorePackages : Set<String> = HashSet()
|
public var ignorePackages: Set<String> = HashSet()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if a warning should be generated if there are no comments
|
* Returns true if a warning should be generated if there are no comments
|
||||||
* on documented function or property
|
* on documented function or property
|
||||||
*/
|
*/
|
||||||
public var warnNoComments : Boolean = true
|
public var warnNoComments: Boolean = true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the HTTP URL of the root directory of source code that we should link to
|
* Returns the HTTP URL of the root directory of source code that we should link to
|
||||||
*/
|
*/
|
||||||
public var sourceRootHref : String = ""
|
public var sourceRootHref: String = ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The root project directory used to deduce relative file names when linking to source code
|
* The root project directory used to deduce relative file names when linking to source code
|
||||||
*/
|
*/
|
||||||
public var projectRootDir : String = ""
|
public var projectRootDir: String = ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map of package name to html or markdown files used to describe the package. If none is
|
* A map of package name to html or markdown files used to describe the package. If none is
|
||||||
* speciied we will look for a package.html or package.md file in the source tree
|
* specified we will look for a package.html or package.md file in the source tree
|
||||||
*/
|
*/
|
||||||
public var packageDescriptionFiles : Map<String,String> = HashMap()
|
public var packageDescriptionFiles: Map<String, String> = HashMap()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map of package name to summary text used in the package overviews
|
* A map of package name to summary text used in the package overviews
|
||||||
*/
|
*/
|
||||||
public var packageSummaryText : Map<String,String> = HashMap()
|
public var packageSummaryText: Map<String, String> = HashMap()
|
||||||
|
|
||||||
|
|
||||||
TaskAction fun generateDocs() {
|
TaskAction fun generateDocs() {
|
||||||
val args : KDocArguments = KDocArguments()
|
val args = KDocArguments()
|
||||||
val cfg : KDocConfig = args.docConfig
|
val cfg = args.docConfig
|
||||||
|
|
||||||
cfg.docOutputDir = destinationDir
|
cfg.docOutputDir = destinationDir
|
||||||
cfg.title = title
|
cfg.title = title
|
||||||
@@ -200,16 +203,32 @@ open class KDoc() : SourceTask() {
|
|||||||
cfg.packageDescriptionFiles.putAll(packageDescriptionFiles)
|
cfg.packageDescriptionFiles.putAll(packageDescriptionFiles)
|
||||||
cfg.packageSummaryText.putAll(packageSummaryText)
|
cfg.packageSummaryText.putAll(packageSummaryText)
|
||||||
|
|
||||||
val compiler : KDocCompiler = KDocCompiler()
|
val compiler = KDocCompiler()
|
||||||
|
|
||||||
val exitCode = compiler.exec(System.err, args);
|
val messageCollector = GradleMessageCollector(getLogger())
|
||||||
|
val exitCode = compiler.exec(messageCollector, args);
|
||||||
|
|
||||||
when (exitCode) {
|
when (exitCode) {
|
||||||
ExitCode.COMPILATION_ERROR -> throw GradleException("Failed to generate kdoc. See log for more details")
|
ExitCode.COMPILATION_ERROR -> throw GradleException("Failed to generate kdoc. See log for more details")
|
||||||
ExitCode.INTERNAL_ERROR -> throw GradleException("Internal generation error. See log for more details")
|
ExitCode.INTERNAL_ERROR -> throw GradleException("Internal generation error. See log for more details")
|
||||||
else -> ""
|
else -> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GradleMessageCollector(val logger : Logger): MessageCollector {
|
||||||
|
public override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
|
||||||
|
val path = location.getPath()
|
||||||
|
val position = if (path != null) (path + ": (" + location.getLine() + ", " + location.getColumn() + ") ") else ""
|
||||||
|
|
||||||
|
val text = position + message
|
||||||
|
|
||||||
|
when (severity) {
|
||||||
|
in CompilerMessageSeverity.VERBOSE -> logger.debug(text)
|
||||||
|
in CompilerMessageSeverity.ERRORS -> logger.error(text)
|
||||||
|
CompilerMessageSeverity.INFO -> logger.info(text)
|
||||||
|
else -> logger.warn(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+21
-25
@@ -5,29 +5,25 @@ import com.intellij.openapi.util.SystemInfo
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.Arrays
|
import java.util.Arrays
|
||||||
import java.util.Scanner
|
import java.util.Scanner
|
||||||
import org.testng.Assert.*
|
import org.junit.Before
|
||||||
import org.testng.annotations.AfterMethod
|
import org.junit.After
|
||||||
import org.testng.annotations.BeforeMethod
|
import org.junit.Test
|
||||||
import org.testng.annotations.Test
|
import kotlin.test.assertTrue
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.fail
|
||||||
|
|
||||||
/**
|
class BasicKotlinGradleIntegrationTest {
|
||||||
* Created by Nikita.Skvortsov
|
|
||||||
* Date: 2/27/13, 5:02 PM
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
var workingDir: File = File(".")
|
||||||
|
|
||||||
class BasicKotlinGradleIT {
|
Before fun setUp() {
|
||||||
|
workingDir = Files.createTempDir()
|
||||||
var workingDir : File = File(".")
|
|
||||||
|
|
||||||
BeforeMethod fun setUp() {
|
|
||||||
workingDir = Files.createTempDir()!!
|
|
||||||
workingDir.mkdirs()
|
workingDir.mkdirs()
|
||||||
copyRecursively(File("src/test/resources/testProject/alfa"), workingDir)
|
copyRecursively(File("src/test/resources/testProject/alfa"), workingDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AfterMethod fun tearDown() {
|
After fun tearDown() {
|
||||||
deleteRecursively(workingDir)
|
deleteRecursively(workingDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,19 +31,19 @@ class BasicKotlinGradleIT {
|
|||||||
val projectDir = File(workingDir, "alfa")
|
val projectDir = File(workingDir, "alfa")
|
||||||
|
|
||||||
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("target/local-repo").getAbsolutePath()
|
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("target/local-repo").getAbsolutePath()
|
||||||
val cmd = if (SystemInfo.isWindows)
|
val cmd = if (SystemInfo.isWindows)
|
||||||
Arrays.asList("cmd", "/C", "gradlew.bat", "clean", "compileDeployKotlin", "build", pathToKotlinPlugin, "--no-daemon")
|
listOf("cmd", "/C", "gradlew.bat", "clean", "compileDeployKotlin", "build", pathToKotlinPlugin, "--no-daemon", "--debug")
|
||||||
else
|
else
|
||||||
Arrays.asList("./gradlew", "clean", "compileDeployKotlin", "build", pathToKotlinPlugin, "--no-daemon")
|
listOf("/bin/sh", "./gradlew", "clean", "compileDeployKotlin", "build", pathToKotlinPlugin, "--no-daemon", "--debug")
|
||||||
|
|
||||||
val builder : ProcessBuilder = ProcessBuilder(cmd)
|
val builder = ProcessBuilder(cmd)
|
||||||
builder.directory(projectDir)
|
builder.directory(projectDir)
|
||||||
|
|
||||||
builder.redirectErrorStream(true)
|
builder.redirectErrorStream(true)
|
||||||
val process : Process = builder.start()
|
val process = builder.start()
|
||||||
|
|
||||||
val s : Scanner = Scanner(process.getInputStream()!!)
|
val s = Scanner(process.getInputStream()!!)
|
||||||
val text : StringBuilder = StringBuilder()
|
val text = StringBuilder()
|
||||||
while (s.hasNextLine()) {
|
while (s.hasNextLine()) {
|
||||||
text append s.nextLine()
|
text append s.nextLine()
|
||||||
text append "\n"
|
text append "\n"
|
||||||
@@ -74,7 +70,7 @@ class BasicKotlinGradleIT {
|
|||||||
val array = source.listFiles()
|
val array = source.listFiles()
|
||||||
if (array != null) {
|
if (array != null) {
|
||||||
for (child in array) {
|
for (child in array) {
|
||||||
copyRecursively(child,targetFile)
|
copyRecursively(child, targetFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -83,7 +79,7 @@ class BasicKotlinGradleIT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun deleteRecursively(f : File): Unit {
|
fun deleteRecursively(f: File): Unit {
|
||||||
if (f.isDirectory()) {
|
if (f.isDirectory()) {
|
||||||
val children = f.listFiles()
|
val children = f.listFiles()
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
Reference in New Issue
Block a user