Wizard: Add initial version of the new project wizard
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(kotlinStdlib())
|
||||
compileOnly(project(":kotlin-reflect-api"))
|
||||
|
||||
implementation(project(":libraries:tools:new-project-wizard"))
|
||||
compileOnly(intellijDep()) { includeJars("snakeyaml-1.24") }
|
||||
|
||||
testImplementation(projectTests(":compiler:tests-common"))
|
||||
testImplementation(project(":kotlin-test:kotlin-test-junit"))
|
||||
testImplementation(commonDep("junit:junit"))
|
||||
testImplementation(intellijDep())
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
|
||||
projectTest {
|
||||
dependsOn(":dist")
|
||||
workingDir = rootDir
|
||||
}
|
||||
|
||||
testsJar()
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard
|
||||
|
||||
import YamlParsingError
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
import org.yaml.snakeyaml.parser.ParserException
|
||||
import java.nio.file.Path
|
||||
|
||||
|
||||
class YamlSettingsParser(settings: List<PluginSetting<Any, *>>, private val parsingState: ParsingState) {
|
||||
private val settingByName = settings.associateBy { it.path }
|
||||
|
||||
fun parseYamlText(yaml: String): TaskResult<Map<SettingReference<*, *>, Any>> {
|
||||
val yamlObject = try {
|
||||
Success(Yaml().load<Any>(yaml) ?: emptyMap<String, Any>())
|
||||
} catch (e: ParserException) {
|
||||
Failure(YamlParsingError(e))
|
||||
} catch (e: Exception) {
|
||||
Failure(ExceptionErrorImpl(e))
|
||||
}
|
||||
return yamlObject.flatMap { map ->
|
||||
if (map is Map<*, *>) {
|
||||
val result = ComputeContext.runInComputeContextWithState(parsingState) {
|
||||
parseSettingValues(map, "")
|
||||
}
|
||||
result.map { (pluginSettings, newState) ->
|
||||
pluginSettings + newState.settingValues
|
||||
}
|
||||
} else Failure(
|
||||
BadSettingValueError("Settings file should be a map of settings")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun parseYamlFile(file: Path) = computeM {
|
||||
val (yaml) = safe { file.toFile().readText() }
|
||||
parseYamlText(yaml)
|
||||
}
|
||||
|
||||
private fun ParsingContext.parseSettingValues(
|
||||
data: Any,
|
||||
settingPath: String
|
||||
): TaskResult<Map<PluginSettingReference<*, *>, Any>> =
|
||||
if (settingPath in settingByName) compute {
|
||||
val setting = settingByName.getValue(settingPath)
|
||||
val (parsed) = setting.type.parse(this, data, settingPath)
|
||||
listOf(PluginSettingReference(setting) to parsed)
|
||||
} else {
|
||||
when (data) {
|
||||
is Map<*, *> -> {
|
||||
data.entries.mapCompute { (name, value) ->
|
||||
if (value == null) fail(BadSettingValueError("No value was found for a key `$settingPath`"))
|
||||
val prefix = if (settingPath.isEmpty()) "" else "$settingPath."
|
||||
val (children) = parseSettingValues(value, "$prefix$name")
|
||||
children.entries.map { (key, value) -> key to value }
|
||||
}.sequence().map { it.flatten() }
|
||||
}
|
||||
else -> Failure(
|
||||
BadSettingValueError("No value was found for a key `$settingPath`")
|
||||
)
|
||||
}
|
||||
}.map { it.toMap() }
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.YamlSettingsParser
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PluginSettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.AndroidServiceImpl
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.Service
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatesPlugin
|
||||
import java.nio.file.Paths
|
||||
|
||||
class YamlWizard(
|
||||
private val yaml: String,
|
||||
private val path: String,
|
||||
createPlugins: (Context) -> List<Plugin>
|
||||
) : Wizard(createPlugins, listOf(AndroidServiceImpl())) {
|
||||
override fun apply(
|
||||
services: List<Service>,
|
||||
phases: Set<GenerationPhase>,
|
||||
onTaskExecuting: (PipelineTask) -> Unit
|
||||
): TaskResult<Unit> = computeM {
|
||||
super.apply(services, setOf(GenerationPhase.PREPARE), onTaskExecuting)
|
||||
val parsingData = with(valuesReadingContext) {
|
||||
ParsingState(TemplatesPlugin::templates.propertyValue, emptyMap())
|
||||
}
|
||||
val yamlParser = YamlSettingsParser(pluginSettings, parsingData)
|
||||
val (settingsValuesFromYaml) = yamlParser.parseYamlText(yaml)
|
||||
val settingValues = defaultPluginSettingValues + settingsValuesFromYaml
|
||||
settingValues.forEach { (path, value) -> context.settingContext[path] = value }
|
||||
context.settingContext[StructurePlugin::projectPath.reference] = Paths.get(path)
|
||||
super.apply(services, phases, onTaskExecuting)
|
||||
}
|
||||
|
||||
private val defaultPluginSettingValues
|
||||
get() = pluginSettings.mapNotNull { setting ->
|
||||
val defaultValue = setting.defaultValue ?: return@mapNotNull null
|
||||
PluginSettingReference(setting) to defaultValue
|
||||
} .toMap()
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Error
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.asString
|
||||
import org.yaml.snakeyaml.parser.ParserException
|
||||
|
||||
data class YamlParsingError(val exception: ParserException) : Error() {
|
||||
override val message: String
|
||||
get() = exception.asString()
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'kotlin-android-extensions'
|
||||
}
|
||||
group = 'testGroupId'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
defaultConfig {
|
||||
applicationId 'testArtifactId'
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName '1.0'
|
||||
}
|
||||
buildTypes {
|
||||
'release' {
|
||||
isMinifyEnabled false
|
||||
}
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.core:core-ktx:1.1.0'
|
||||
implementation kotlin('stdlib-jdk7')
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation kotlin('stdlib-jdk8')
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("kotlin-android")
|
||||
id("kotlin-android-extensions")
|
||||
}
|
||||
group = "testGroupId"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
android {
|
||||
compileSdkVersion(29)
|
||||
defaultConfig {
|
||||
applicationId = "testArtifactId"
|
||||
minSdkVersion(24)
|
||||
targetSdkVersion(29)
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
}
|
||||
buildTypes {
|
||||
getByName("release") {
|
||||
isMinifyEnabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation("androidx.appcompat:appcompat:1.1.0")
|
||||
implementation("androidx.core:core-ktx:1.1.0")
|
||||
implementation(kotlin("stdlib-jdk7"))
|
||||
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
classpath kotlin('gradle-plugin', '1.3.61')
|
||||
}
|
||||
}
|
||||
group = 'testGroupId'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:3.2.1")
|
||||
classpath(kotlin("gradle-plugin", "1.3.61"))
|
||||
}
|
||||
}
|
||||
group = "testGroupId"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.GroovyDslPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.KotlinDslPlugin
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
kotlin:
|
||||
version: 1.3.61
|
||||
projectKind: Multiplatform
|
||||
modules:
|
||||
- type:
|
||||
name: android
|
||||
androidSdkPath: /home/ilya/Android/Sdk
|
||||
kind: singleplatform
|
||||
name: android
|
||||
sourcesets:
|
||||
- type: main
|
||||
- type: test
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.multiplatform' version '1.3.61'
|
||||
}
|
||||
group = 'testGroupId'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
js('nodeJs') {
|
||||
nodejs {
|
||||
|
||||
}
|
||||
}
|
||||
js('browser') {
|
||||
browser {
|
||||
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
nodeJsMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-js')
|
||||
}
|
||||
}
|
||||
nodeJsTest {
|
||||
|
||||
}
|
||||
browserMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-js')
|
||||
}
|
||||
}
|
||||
browserTest {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "1.3.61"
|
||||
}
|
||||
group = "testGroupId"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
js("nodeJs") {
|
||||
nodejs {
|
||||
|
||||
}
|
||||
}
|
||||
js("browser") {
|
||||
browser {
|
||||
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
val nodeJsMain by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-js"))
|
||||
}
|
||||
}
|
||||
val nodeJsTest by getting
|
||||
val browserMain by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-js"))
|
||||
}
|
||||
}
|
||||
val browserTest by getting
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.GroovyDslPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.KotlinDslPlugin
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
kotlin:
|
||||
version: 1.3.61
|
||||
projectKind: Multiplatform
|
||||
modules:
|
||||
- type: multiplatform
|
||||
kind: multiplatform
|
||||
name: a
|
||||
subModules:
|
||||
- type: jsNode
|
||||
kind: target
|
||||
name: nodeJs
|
||||
sourcesets:
|
||||
- type: main
|
||||
- type: test
|
||||
- type: jsBrowser
|
||||
kind: target
|
||||
name: browser
|
||||
sourcesets:
|
||||
- type: main
|
||||
- type: test
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.multiplatform' version '1.3.61'
|
||||
}
|
||||
group = 'testGroupId'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
jvm()
|
||||
sourceSets {
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-jdk8')
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "1.3.61"
|
||||
}
|
||||
group = "testGroupId"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
jvm()
|
||||
sourceSets {
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
}
|
||||
val jvmTest by getting
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.GroovyDslPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.KotlinDslPlugin
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
kotlin:
|
||||
version: 1.3.61
|
||||
projectKind: Multiplatform
|
||||
modules:
|
||||
- type: multiplatform
|
||||
kind: multiplatform
|
||||
name: a
|
||||
subModules:
|
||||
- type: jvmTarget
|
||||
kind: target
|
||||
name: jvm
|
||||
sourcesets:
|
||||
- type: main
|
||||
- type: test
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
|
||||
}
|
||||
group = 'testGroupId'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-jdk8')
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "1.3.61"
|
||||
}
|
||||
group = "testGroupId"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.MavenPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.GroovyDslPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.KotlinDslPlugin
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>nya</artifactId>
|
||||
<groupId>testGroupId</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>nya</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<kotlin.code.style>official</kotlin.code.style>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>1.3.61</version>
|
||||
<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>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>1.3.61</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
kotlin:
|
||||
version: 1.3.61
|
||||
projectKind: Singleplatform
|
||||
modules:
|
||||
- type: JVM Module
|
||||
name: nya
|
||||
kind: singleplatform
|
||||
sourcesets:
|
||||
- type: main
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.multiplatform' version '1.3.61'
|
||||
}
|
||||
group = 'testGroupId'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
def hostOs = System.getProperty("os.name")
|
||||
def isMingwX64 = hostOs.startsWith("Windows")
|
||||
org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests nativeTarget
|
||||
if (hostOs == "Mac OS X") nativeTarget = macosX64('myNative')
|
||||
else if (hostOs == "Linux") nativeTarget = linuxX64("myNative")
|
||||
else if (isMingwX64) return nativeTarget = mingwX64("myNative")
|
||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
||||
|
||||
nativeTarget.with {
|
||||
binaries {
|
||||
executable {
|
||||
entryPoint = 'MAIN CLASS'
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
myNativeMain {
|
||||
|
||||
}
|
||||
myNativeTest {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "1.3.61"
|
||||
}
|
||||
group = "testGroupId"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
val hostOs = System.getProperty("os.name")
|
||||
val isMingwX64 = hostOs.startsWith("Windows")
|
||||
val nativeTarget = when {
|
||||
hostOs == "Mac OS X" -> macosX64("myNative")
|
||||
hostOs == "Linux" -> linuxX64("myNative")
|
||||
isMingwX64 -> mingwX64("myNative")
|
||||
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
|
||||
}
|
||||
|
||||
nativeTarget.apply {
|
||||
binaries {
|
||||
executable {
|
||||
entryPoint = "MAIN CLASS"
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
val myNativeMain by getting
|
||||
val myNativeTest by getting
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.GroovyDslPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.KotlinDslPlugin
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
kotlin:
|
||||
version: 1.3.61
|
||||
projectKind: Multiplatform
|
||||
modules:
|
||||
- type: multiplatform
|
||||
kind: multiplatform
|
||||
name: a
|
||||
subModules:
|
||||
- type: nativeForCurrentSystem
|
||||
kind: target
|
||||
name: myNative
|
||||
sourcesets:
|
||||
- type: main
|
||||
- type: test
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.multiplatform' version '1.3.61'
|
||||
}
|
||||
group = 'testGroupId'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
jvm()
|
||||
js('a') {
|
||||
browser {
|
||||
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-jdk8')
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
|
||||
}
|
||||
aMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-js')
|
||||
}
|
||||
}
|
||||
aTest {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "1.3.61"
|
||||
}
|
||||
group = "testGroupId"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
jvm()
|
||||
js("a") {
|
||||
browser {
|
||||
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
}
|
||||
val jvmTest by getting
|
||||
val aMain by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-js"))
|
||||
}
|
||||
}
|
||||
val aTest by getting
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.GroovyDslPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.KotlinDslPlugin
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
kotlin:
|
||||
version: 1.3.61
|
||||
projectKind: Multiplatform
|
||||
modules:
|
||||
- type: multiplatform
|
||||
kind: multiplatform
|
||||
name: a
|
||||
subModules:
|
||||
- type: jvmTarget
|
||||
kind: target
|
||||
name: jvm
|
||||
sourcesets:
|
||||
- type: main
|
||||
- type: test
|
||||
- type: jsBrowser
|
||||
kind: target
|
||||
name: a
|
||||
sourcesets:
|
||||
- type: main
|
||||
- type: test
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.multiplatform' version '1.3.61'
|
||||
}
|
||||
group = 'testGroupId'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
linuxX64 {
|
||||
binaries {
|
||||
executable {
|
||||
entryPoint = 'MAIN CLASS'
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
linuxX64Main {
|
||||
|
||||
}
|
||||
linuxX64Test {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "1.3.61"
|
||||
}
|
||||
group = "testGroupId"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
linuxX64 {
|
||||
binaries {
|
||||
executable {
|
||||
entryPoint = "MAIN CLASS"
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
val linuxX64Main by getting
|
||||
val linuxX64Test by getting
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.GroovyDslPlugin
|
||||
org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.KotlinDslPlugin
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
kotlin:
|
||||
version: 1.3.61
|
||||
projectKind: Multiplatform
|
||||
modules:
|
||||
- type: multiplatform
|
||||
kind: multiplatform
|
||||
name: a
|
||||
subModules:
|
||||
- type: linuxX64Target
|
||||
kind: target
|
||||
name: linuxX64
|
||||
sourcesets:
|
||||
- type: main
|
||||
- type: test
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.tools.projectWizard.cli
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ExceptionError
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.div
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.onFailure
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.Services
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.MavenPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.GroovyDslPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.KotlinDslPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.YamlWizard
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
abstract class AbstractBuildFileGenerationTest : AbstractPluginBasedTest() {
|
||||
|
||||
fun doTest(directoryPath: String) {
|
||||
val directory = Paths.get(directoryPath)
|
||||
val testData = init(directory)
|
||||
if (KotlinDslPlugin::class in testData.pluginClasses) {
|
||||
doTest(directory, testData, BuildSystem.GRADLE_KOTLIN_DSL)
|
||||
}
|
||||
if (GroovyDslPlugin::class in testData.pluginClasses) {
|
||||
doTest(directory, testData, BuildSystem.GRADLE_GROOVY_DSL)
|
||||
}
|
||||
if (MavenPlugin::class in testData.pluginClasses) {
|
||||
doTest(directory, testData, BuildSystem.MAVEN)
|
||||
}
|
||||
}
|
||||
|
||||
private fun doTest(directory: Path, testData: WizardTestData, buildSystem: BuildSystem) {
|
||||
val yaml = directory.resolve("settings.yaml").toFile().readText() + "\n" +
|
||||
defaultStructure + "\n" +
|
||||
buildSystem.yaml
|
||||
val tempDir = Files.createTempDirectory(null)
|
||||
val wizard = YamlWizard(yaml, tempDir.toString(), testData.createPlugins)
|
||||
val result = wizard.apply(Services.osServices, GenerationPhase.ALL)
|
||||
result.onFailure { errors ->
|
||||
errors.forEach { error ->
|
||||
if (error is ExceptionError) {
|
||||
throw error.exception
|
||||
}
|
||||
}
|
||||
fail(errors.joinToString("\n"))
|
||||
}
|
||||
|
||||
val expectedDirectory = (directory / EXPECTED_DIRECTORY_NAME).takeIf { Files.exists(it) } ?: directory
|
||||
|
||||
compareFiles(
|
||||
expectedDirectory.allBuildFiles(buildSystem), expectedDirectory,
|
||||
tempDir.allBuildFiles(buildSystem), tempDir
|
||||
)
|
||||
}
|
||||
|
||||
private fun Path.allBuildFiles(buildSystem: BuildSystem) =
|
||||
listFiles { it.fileName.toString() == buildSystem.buildFileName }
|
||||
|
||||
private enum class BuildSystem(val buildFileName: String, val yaml: String) {
|
||||
GRADLE_KOTLIN_DSL(
|
||||
buildFileName = "build.gradle.kts",
|
||||
yaml = """buildSystem:
|
||||
type: GradleKotlinDsl
|
||||
gradle:
|
||||
createGradleWrapper: false
|
||||
version: 5.4.1""".trimIndent()
|
||||
),
|
||||
GRADLE_GROOVY_DSL(
|
||||
buildFileName = "build.gradle",
|
||||
yaml = """buildSystem:
|
||||
type: GradleGroovyDsl
|
||||
gradle:
|
||||
createGradleWrapper: false
|
||||
version: 5.4.1""".trimIndent()
|
||||
),
|
||||
MAVEN(
|
||||
buildFileName = "pom.xml",
|
||||
yaml = """buildSystem:
|
||||
type: Maven""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val EXPECTED_DIRECTORY_NAME = "expected"
|
||||
|
||||
private val defaultStructure =
|
||||
"""structure:
|
||||
name: generatedProject
|
||||
groupId: testGroupId
|
||||
artifactId: testArtifactId
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.tools.projectWizard.cli
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Context
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Plugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.PluginReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatesPlugin
|
||||
import java.nio.file.Path
|
||||
import kotlin.reflect.full.primaryConstructor
|
||||
|
||||
abstract class AbstractPluginBasedTest : UsefulTestCase() {
|
||||
open val defaultPlugins: List<PluginReference> = listOf(
|
||||
StructurePlugin::class,
|
||||
TemplatesPlugin::class
|
||||
)
|
||||
|
||||
protected fun init(directory: Path): WizardTestData {
|
||||
val pluginNames = directory.resolve("plugins.txt").toFile().readLines().mapNotNull { name ->
|
||||
name.trim().takeIf { it.isNotBlank() }
|
||||
}.distinct()
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val pluginClasses = defaultPlugins + pluginNames.map { pluginName ->
|
||||
Class.forName(pluginName).kotlin as PluginReference
|
||||
}
|
||||
|
||||
val createPlugins = { context: Context ->
|
||||
pluginClasses.map { pluginClass ->
|
||||
pluginClass.primaryConstructor!!.call(context)
|
||||
}
|
||||
}
|
||||
return WizardTestData(pluginClasses, createPlugins)
|
||||
}
|
||||
}
|
||||
|
||||
data class WizardTestData(
|
||||
val pluginClasses: List<PluginReference>,
|
||||
val createPlugins: (Context) -> List<Plugin>
|
||||
)
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.tools.projectWizard.cli;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("libraries/tools/new-project-wizard/new-project-wizard-cli/testData/buildFileGeneration")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class BuildFileGenerationTestGenerated extends AbstractBuildFileGenerationTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBuildFileGeneration() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("libraries/tools/new-project-wizard/new-project-wizard-cli/testData/buildFileGeneration"), Pattern.compile("^([^\\.]+)$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("android")
|
||||
public void testAndroid() throws Exception {
|
||||
runTest("libraries/tools/new-project-wizard/new-project-wizard-cli/testData/buildFileGeneration/android/");
|
||||
}
|
||||
|
||||
@TestMetadata("jsNodeAndBrowserTargets")
|
||||
public void testJsNodeAndBrowserTargets() throws Exception {
|
||||
runTest("libraries/tools/new-project-wizard/new-project-wizard-cli/testData/buildFileGeneration/jsNodeAndBrowserTargets/");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmTarget")
|
||||
public void testJvmTarget() throws Exception {
|
||||
runTest("libraries/tools/new-project-wizard/new-project-wizard-cli/testData/buildFileGeneration/jvmTarget/");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinJvm")
|
||||
public void testKotlinJvm() throws Exception {
|
||||
runTest("libraries/tools/new-project-wizard/new-project-wizard-cli/testData/buildFileGeneration/kotlinJvm/");
|
||||
}
|
||||
|
||||
@TestMetadata("nativeForCurrentSystem")
|
||||
public void testNativeForCurrentSystem() throws Exception {
|
||||
runTest("libraries/tools/new-project-wizard/new-project-wizard-cli/testData/buildFileGeneration/nativeForCurrentSystem/");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleMultiplatform")
|
||||
public void testSimpleMultiplatform() throws Exception {
|
||||
runTest("libraries/tools/new-project-wizard/new-project-wizard-cli/testData/buildFileGeneration/simpleMultiplatform/");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleNativeTarget")
|
||||
public void testSimpleNativeTarget() throws Exception {
|
||||
runTest("libraries/tools/new-project-wizard/new-project-wizard-cli/testData/buildFileGeneration/simpleNativeTarget/");
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.tools.projectWizard.cli
|
||||
|
||||
import org.hamcrest.core.Is
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.junit.Assert.assertThat
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.util.stream.Collectors
|
||||
|
||||
internal fun Path.readFile() = toFile().readText().trim()
|
||||
|
||||
internal fun Path.listFiles(filter: (Path) -> Boolean) =
|
||||
Files.walk(this).filter { path ->
|
||||
Files.isRegularFile(path) && filter(path)
|
||||
}.collect(Collectors.toList()).sorted()
|
||||
|
||||
internal fun compareFiles(
|
||||
expectedFiles: List<Path>, expectedDir: Path,
|
||||
actualFiles: List<Path>, actualDir: Path
|
||||
) {
|
||||
val expectedFilesSorted = expectedFiles.sorted()
|
||||
val actualFilesSorted = actualFiles.sorted()
|
||||
|
||||
assertThat(
|
||||
actualFilesSorted.map { actualDir.relativize(it) },
|
||||
Is.`is`(expectedFilesSorted.map { expectedDir.relativize(it) })
|
||||
)
|
||||
|
||||
for ((actualFile, expectedFile) in actualFilesSorted zip expectedFilesSorted) {
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile.toFile(), actualFile.readFile())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user