Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Made PoC of kotlin pom * added DSL example of curly branches ad mapping * Implemented first base version of kom * Made groupId and version inheritable form parent * Added relativePath support as well as fully qualified parent definition with braces * Made first e2e integration of a regular project kom * Dependencies: - Add dependency scopes: runtime, system - Add GAV definition of artifact - Rename params for better name hints in intellij idea - Decouple Dependency convertation from KomConverter NOTE: assertk for better test reading * Add dependency type * Add full support of maven dependency details * Adds build section, plugins+executions NOTE: - changed scope "this" to its section - added DslMarker to define scope and reduce methods cal invariants * Plugin configuration free style Free style definition: - String with braces is a name of section/element and section scope. - String with square brackets is a plural name of sections per value. - String withing plus assign value is element name and value - String withing "sameAs" value is element name and value - String withing leaded by plus is single/empty element NOTE: - plugin gav - plugin inheritance disabling * Plugin dependencies * Dependency details infix functions * Multi-module project * Dependency management * Plugin management * First level Build fields * Project details and propertries writer * project dependencies writer * project build details writer * Writes dependency details * Writes plugins * Writes plugin configuration * Writes multi-project modules * Renames property assigning method * Profiles: Adds profiles with activation and build sections NOTE: makes parent optional * Adds profile dependencies * Adds profiles dependencyManagement * Add README.md * Move samples of kom into polyglot-maven-examples
- Loading branch information
Showing
41 changed files
with
2,507 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Polyglot Kotlin | ||
Here is the code: | ||
```kotlin | ||
project { | ||
name = "Polyglot :: Kotlin" | ||
parent { | ||
groupId = "io.takari.polyglot" | ||
artifactId = "polyglot" | ||
version = "0.2.2-SNAPSHOT" | ||
} | ||
artifactId = "regular-project" | ||
packaging = jar | ||
|
||
val junitVersion = 4.12 | ||
|
||
properties { | ||
"kotlin.version" assign "1.1.61" | ||
} | ||
|
||
dependencies { | ||
compile("org.jetbrains.kotlin:kotlin-stdlib:" + it["kotlin.version"]) | ||
compile(it.groupId + ":polyglot-common:" + it.version) | ||
.exclusions("org.slf4j:jul-logger") | ||
|
||
test( | ||
"junit:junit:$junitVersion" exclusions "org.hamcrest:hamcrest-core", | ||
"org.jetbrains.kotlin:kotlin-test-junit:${it["kotlin.version"]}" | ||
) | ||
provided(groupId = "org.apache.maven.plugin-tools", artifactId = "maven-plugin-annotations", version = "3.4") | ||
} | ||
} | ||
``` | ||
|
||
## IDE support | ||
Targeting IntelliJ IDEA only. | ||
|
||
|
||
## Not supported yet | ||
* reports | ||
* licenses | ||
* scm | ||
* distributionManagement | ||
* contributors | ||
* repositories | ||
* organization | ||
* developers | ||
* mailingLists | ||
* prerequisites | ||
* issueManagement | ||
* ciManagement | ||
* reporting | ||
* arbitrary kotlin code execution on maven phase. Not sure if maven users would like to have such feature. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>polyglot</artifactId> | ||
<groupId>io.takari.polyglot</groupId> | ||
<version>0.3.2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>polyglot-kotlin</artifactId> | ||
<packaging>takari-jar</packaging> | ||
|
||
<name>Polyglot :: Kotlin</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<kotlin.version>1.2.21</kotlin.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.takari.polyglot</groupId> | ||
<artifactId>polyglot-common</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-script-runtime</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-script-util</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-compiler</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-compiler-client-embeddable</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-reflect</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-test-junit</artifactId> | ||
<version>${kotlin.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.willowtreeapps.assertk</groupId> | ||
<artifactId>assertk</artifactId> | ||
<version>0.9</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<sourceDirectory>src/main/kotlin</sourceDirectory> | ||
<testSourceDirectory>src/test/kotlin</testSourceDirectory> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</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> | ||
</project> |
18 changes: 18 additions & 0 deletions
18
polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinMapping.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import org.codehaus.plexus.component.annotations.Component | ||
import org.codehaus.plexus.component.annotations.Requirement | ||
import org.codehaus.plexus.logging.Logger | ||
import org.sonatype.maven.polyglot.mapping.Mapping | ||
import org.sonatype.maven.polyglot.mapping.MappingSupport | ||
|
||
@Component(role = Mapping::class, hint = "kotlin") | ||
class KotlinMapping: MappingSupport("kotlin") { | ||
|
||
@Requirement protected var log: Logger? = null | ||
|
||
init { | ||
setPomNames("pom.kts") | ||
setAcceptLocationExtensions(".kts") | ||
setAcceptOptionKeys("kts:4.0.0") | ||
priority = 1f | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import org.apache.maven.model.Model | ||
import org.apache.maven.model.io.ModelReader | ||
import org.codehaus.plexus.PlexusContainer | ||
import org.codehaus.plexus.component.annotations.Component | ||
import org.codehaus.plexus.component.annotations.Requirement | ||
import org.codehaus.plexus.logging.Logger | ||
import org.sonatype.maven.polyglot.io.ModelReaderSupport | ||
import java.io.Reader | ||
|
||
@Component(role = ModelReader::class, hint = "kotlin") | ||
class KotlinModelReader : ModelReaderSupport() { | ||
@Requirement | ||
private val container: PlexusContainer? = null | ||
|
||
@Requirement | ||
protected var log: Logger? = null | ||
|
||
private val scriptEngine = KomScriptEngineFactory().getScriptEngine() | ||
|
||
override fun read(komReader: Reader, options: MutableMap<String, *>): Model { | ||
val project = scriptEngine.eval(komReader) | ||
return KomConverter.toModel(project as Project) | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.sonatype.maven.polyglot.kotlin | ||
|
||
import org.apache.maven.model.Model | ||
import org.apache.maven.model.io.ModelWriter | ||
import org.apache.maven.shared.utils.xml.Xpp3Dom | ||
import org.codehaus.plexus.component.annotations.Component | ||
import org.sonatype.maven.polyglot.io.ModelWriterSupport | ||
import org.sonatype.maven.polyglot.kotlin.writer.* | ||
import org.sonatype.maven.polyglot.kotlin.writer.KomDependencyWriter.compile | ||
import org.sonatype.maven.polyglot.kotlin.writer.KomDependencyWriter.import | ||
import org.sonatype.maven.polyglot.kotlin.writer.KomDependencyWriter.provided | ||
import org.sonatype.maven.polyglot.kotlin.writer.KomDependencyWriter.runtime | ||
import org.sonatype.maven.polyglot.kotlin.writer.KomDependencyWriter.system | ||
import org.sonatype.maven.polyglot.kotlin.writer.KomDependencyWriter.test | ||
import java.io.Writer | ||
|
||
@Component(role = ModelWriter::class, hint = "kotlin") | ||
class KotlinModelWriter : ModelWriterSupport() { | ||
|
||
override fun write(output: Writer, options: MutableMap<String, Any>, model: Model) { | ||
with(output) { | ||
with(model) { | ||
appendln("project {") | ||
appendlnIf(name, { tab("name" assign it) }) | ||
appendln(tab + if (parent == null) "groupId" assign groupId else "parent" assign parent.gav()) | ||
appendln(tab("artifactId" assign artifactId)) | ||
appendln(tab("packaging = $packaging")) | ||
if (properties.isNotEmpty()) | ||
append(tab("properties {")) | ||
.appendln(properties.lineByLine { name, value -> tab(name assign value, 2) }) | ||
.appendln(tab("}")) | ||
if (modules.isNotEmpty()) | ||
appendln(tab("modules [")) | ||
.appendln(modules.quotedln(2)) | ||
.appendln(tab("]")) | ||
if (dependencies.isNotEmpty()) | ||
appendln(tab("dependencies {")) | ||
.append(import(dependencies)) | ||
.append(compile(dependencies)) | ||
.append(test(dependencies)) | ||
.append(provided(dependencies)) | ||
.append(runtime(dependencies)) | ||
.append(system(dependencies)) | ||
.appendln(tab("}")) | ||
if (build != null) { | ||
with(build) { | ||
appendln(tab("build {")) | ||
.appendlnIf(sourceDirectory, { tab("sourceDirectory" assign it, 2) }) | ||
.appendlnIf(testSourceDirectory, { tab("testSourceDirectory" assign it, 2) }) | ||
.appendlnIf(finalName, { tab("finalName" assign it, 2) }) | ||
.appendlnIf(scriptSourceDirectory, { tab("scriptSourceDirectory" assign it, 2) }) | ||
.appendlnIf(outputDirectory, { tab("outputDirectory" assign it, 2) }) | ||
.appendlnIf(testOutputDirectory, { tab("testOutputDirectory" assign it, 2) }) | ||
.appendlnIf(directory, { tab("directory" assign it, 2) }) | ||
.appendlnIf(filters, { tab("filters[${filters.quoted()}]", 2) }) | ||
if (plugins.isNotEmpty()) { | ||
appendln(tab("plugins {", 2)) | ||
plugins.forEach { | ||
appendln(tab("plugin(${it.id.quoted()}) {", 3)) | ||
if (it.executions.isNotEmpty()) { | ||
appendln(tab("executions {", 4)) | ||
it.executions.forEach { | ||
appendln(tab("execution(id = ${it.id.quoted()}, phase = ${it.phase.quoted()}, goals = arrayOf(${it.goals.quoted()}))", 5)) | ||
} | ||
appendln(tab("}", 4)) | ||
} | ||
if (it.dependencies.isNotEmpty()) | ||
appendln(tab("dependencies {", 4)) | ||
.append(compile(it.dependencies, 5)) | ||
.append(runtime(it.dependencies, 5)) | ||
.append(system(it.dependencies, 5)) | ||
.appendln(tab("}", 4)) | ||
if (it.configuration != null) | ||
appendln(tab("configuration {", 4)) | ||
.append((it.configuration as Xpp3Dom).children.toKonfig()) | ||
.appendln(tab("}", 4)) | ||
appendln(tab("}", 3)) | ||
} | ||
appendln(tab("}", 2)) | ||
} | ||
appendln(tab("}")) | ||
} | ||
} | ||
append("}") | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.