Introduce tooling model for Kotlin gradle projects

A KotlinProject model for Gradle projects including Kotlin (JVM, JS or
common) plugins is introduced. Its model builder KotlinModelBuilder
produces an implementation of these models and can be queried through
the Gradle Tooling API when needed. Model builder is registered in the
corresponding Kotlin Gradle plugins.

Model definition should be published as a separate artifact in public
repositories so it can be consumed when needed.
This commit is contained in:
Lucas Smaira
2018-06-04 16:33:02 +01:00
committed by Sergey Igushkin
parent 4b03db771a
commit 9def6f020f
24 changed files with 900 additions and 16 deletions
@@ -0,0 +1,21 @@
apply plugin: 'kotlin'
configureJvmProject(project)
configurePublishing(project)
repositories {
mavenLocal()
}
dependencies {
compile "org.jetbrains:annotations:13.0"
}
artifacts {
archives sourcesJar
archives javadocJar
}
jar {
manifestAttributes(manifest, project)
}
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.model;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.List;
/**
* Represents the compiler arguments for a given Kotlin source set.
* @see SourceSet
*/
public interface CompilerArguments {
/**
* Return current arguments for the given source set.
*
* @return current arguments for the given source set.
*/
@NotNull
List<String> getCurrentArguments();
/**
* Return default arguments for the given source set.
*
* @return default arguments for the given source set.
*/
@NotNull
List<String> getDefaultArguments();
/**
* Return the classpath the given source set is compiled against.
*
* @return the classpath the given source set is compiled against.
*/
@NotNull
List<File> getCompileClasspath();
}
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.model;
import org.jetbrains.annotations.Nullable;
/**
* Wraps all experimental features information for a given Kotlin project.
* @see KotlinProject
*/
public interface ExperimentalFeatures {
/**
* Return coroutines string.
*
* @return coroutines.
*/
@Nullable
String getCoroutines();
}
@@ -0,0 +1,88 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.model;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
/**
* Entry point for the model of Kotlin Projects.
* Plugins 'kotlin', 'kotlin-platform-jvm', 'kotlin2js', 'kotlin-platform-js' and 'kotlin-platform-common' can produce this model.
*/
public interface KotlinProject {
/**
* Possible Kotlin project types.
*/
enum ProjectType {
/** Indicator of platform plugin id 'kotlin-platform-jvm' or 'kotlin'. */
PLATFORM_JVM,
/** Indicator of platform plugin id 'kotlin-platform-js' or 'kotlin2js'. */
PLATFORM_JS,
/** Indicator of platform plugin id 'kotlin-platform-common'. */
PLATFORM_COMMON
}
/**
* Return a number representing the version of this API.
* Always increasing if changed.
*
* @return the version of this model.
*/
long getModelVersion();
/**
* Returns the module (Gradle project) name.
*
* @return the module name.
*/
@NotNull
String getName();
/**
* Return the Kotlin version.
*
* @return the Kotlin version.
*/
@NotNull
String getKotlinVersion();
/**
* Return the type of the platform plugin applied.
*
* @return the type of the platform plugin applied. Possible values are defined in the enum.
*/
@NotNull
ProjectType getProjectType();
/**
* Return all source sets used by Kotlin.
*
* @return all source sets.
*/
@NotNull
Collection<SourceSet> getSourceSets();
/**
* Return all modules (Gradle projects) registered as 'expectedBy' dependency.
*
* @return expectedBy dependencies.
*/
@NotNull
Collection<String> getExpectedByDependencies();
/**
* Return an object containing a descriptor of the experimental features.
*
* @return experimental features.
*/
@NotNull
ExperimentalFeatures getExperimentalFeatures();
}
@@ -0,0 +1,90 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.model;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.Collection;
/**
* Represents a source set for a given Kotlin Gradle project.
* @see KotlinProject
*/
public interface SourceSet {
/**
* Possible source set types.
*/
enum SourceSetType {
PRODUCTION,
TEST
}
/**
* Return the source set name.
*
* @return the source set name.
*/
@NotNull
String getName();
/**
* Return the type of the source set.
*
* @return the type of the source set.
*/
@NotNull
SourceSetType getType();
/**
* Return the names of all friend source sets.
*
* @return friend source sets.
*/
@NotNull
Collection<String> getFriendSourceSets();
/**
* Return all Kotlin sources directories.
*
* @return all Kotlin sources directories.
*/
@NotNull
Collection<File> getSourceDirectories();
/**
* Return all Kotlin resources directories.
*
* @return all Kotlin resources directories.
*/
@NotNull
Collection<File> getResourcesDirectories();
/**
* Return the classes output directory.
*
* @return the classes output directory.
*/
@NotNull
File getClassesOutputDirectory();
/**
* Return the resources output directory.
*
* @return the resources output directory.
*/
@NotNull
File getResourcesOutputDirectory();
/**
* Return an object containing all compiler arguments for this source set.
*
* @return compiler arguments for this source set.
*/
@NotNull
CompilerArguments getCompilerArguments();
}