diff --git a/polyglot-kotlin/pom.xml b/polyglot-kotlin/pom.xml index 58dff604..ab4887a5 100644 --- a/polyglot-kotlin/pom.xml +++ b/polyglot-kotlin/pom.xml @@ -163,6 +163,15 @@ + + com.diffplug.spotless + spotless-maven-plugin + + + + + + src/main/kotlin src/test/kotlin diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinMapping.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinMapping.kt index 6aa4ef98..dd4d0bff 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinMapping.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinMapping.kt @@ -1,17 +1,17 @@ package org.sonatype.maven.polyglot.kotlin -import org.sonatype.maven.polyglot.mapping.MappingSupport import javax.inject.Named import javax.inject.Singleton +import org.sonatype.maven.polyglot.mapping.MappingSupport @Singleton -@Named( "kotlin" ) +@Named("kotlin") class KotlinMapping : MappingSupport("kotlin") { - init { - setPomNames("pom.kts") - setAcceptLocationExtensions(".kts") - setAcceptOptionKeys("kotlin:4.0.0", "kts:4.0.0") - priority = 1f - } + init { + setPomNames("pom.kts") + setAcceptLocationExtensions(".kts") + setAcceptOptionKeys("kotlin:4.0.0", "kts:4.0.0") + priority = 1f + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelReader.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelReader.kt index d99c6e3d..2c909b78 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelReader.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelReader.kt @@ -1,53 +1,52 @@ package org.sonatype.maven.polyglot.kotlin -import org.apache.maven.model.Model -import org.apache.maven.model.building.ModelProcessor -import org.apache.maven.model.io.ModelReader -import org.sonatype.maven.polyglot.execute.ExecuteManager -import org.sonatype.maven.polyglot.kotlin.dsl.Project -import org.sonatype.maven.polyglot.kotlin.engine.ScriptHost import java.io.File import java.io.InputStream import java.io.Reader import javax.inject.Inject import javax.inject.Named import javax.inject.Singleton +import org.apache.maven.model.Model +import org.apache.maven.model.building.ModelProcessor +import org.apache.maven.model.io.ModelReader +import org.sonatype.maven.polyglot.execute.ExecuteManager +import org.sonatype.maven.polyglot.kotlin.dsl.Project +import org.sonatype.maven.polyglot.kotlin.engine.ScriptHost @Singleton -@Named( "kotlin" ) +@Named("kotlin") class KotlinModelReader : ModelReader { - @Inject - private lateinit var executeManager: ExecuteManager + @Inject private lateinit var executeManager: ExecuteManager - override fun read(input: File, options: Map): Model { - val source = options[ModelProcessor.SOURCE].toString() - val sourceFile = File(source) - val basedir = sourceFile.parentFile.canonicalFile - val model = Project(input) - ScriptHost.eval(input, basedir, model) - val tasks = ArrayList(model.tasks) - executeManager.register(model, tasks) - executeManager.install(model, options) - model.tasks.clear() // Must be cleared or Maven goes into an infinitely repeatable introspection - return model - } + override fun read(input: File, options: Map): Model { + val source = options[ModelProcessor.SOURCE].toString() + val sourceFile = File(source) + val basedir = sourceFile.parentFile.canonicalFile + val model = Project(input) + ScriptHost.eval(input, basedir, model) + val tasks = ArrayList(model.tasks) + executeManager.register(model, tasks) + executeManager.install(model, options) + model.tasks.clear() // Must be cleared or Maven goes into an infinitely repeatable introspection + return model + } - override fun read(input: Reader, options: MutableMap): Model { - val temp = File.createTempFile("pom", ".kts") - temp.deleteOnExit() - temp.writer().use { input.copyTo(it) } - val model = read(temp, options) - temp.delete() - return model - } + override fun read(input: Reader, options: MutableMap): Model { + val temp = File.createTempFile("pom", ".kts") + temp.deleteOnExit() + temp.writer().use { input.copyTo(it) } + val model = read(temp, options) + temp.delete() + return model + } - override fun read(input: InputStream, options: MutableMap): Model { - val temp = File.createTempFile("pom", ".kts") - temp.deleteOnExit() - temp.outputStream().use { input.copyTo(it) } - val model = read(temp, options) - temp.delete() - return model - } + override fun read(input: InputStream, options: MutableMap): Model { + val temp = File.createTempFile("pom", ".kts") + temp.deleteOnExit() + temp.outputStream().use { input.copyTo(it) } + val model = read(temp, options) + temp.delete() + return model + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelWriter.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelWriter.kt index dd5f54af..038232fc 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelWriter.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelWriter.kt @@ -1,39 +1,46 @@ package org.sonatype.maven.polyglot.kotlin -import org.apache.maven.model.Model -import org.apache.maven.project.MavenProject -import org.slf4j.LoggerFactory -import org.sonatype.maven.polyglot.io.ModelWriterSupport -import org.sonatype.maven.polyglot.kotlin.serialization.ModelScriptWriter import java.io.StringWriter import java.io.Writer import javax.inject.Inject import javax.inject.Named import javax.inject.Provider import javax.inject.Singleton +import org.apache.maven.model.Model +import org.apache.maven.project.MavenProject +import org.slf4j.LoggerFactory +import org.sonatype.maven.polyglot.io.ModelWriterSupport +import org.sonatype.maven.polyglot.kotlin.serialization.ModelScriptWriter @Singleton -@Named( "kotlin" ) +@Named("kotlin") class KotlinModelWriter : ModelWriterSupport() { - private var log = LoggerFactory.getLogger( KotlinModelWriter::class.java ) + private var log = LoggerFactory.getLogger(KotlinModelWriter::class.java) - @Inject - private lateinit var projectProvider: Provider + @Inject private lateinit var projectProvider: Provider - override fun write(output: Writer, options: Map, model: Model) { - output.write(with(StringWriter(1024)) { - val config = HashMap(options) - config.putIfAbsent("xml.dsl.enabled", projectProvider.get()?.properties?.getProperty("polyglot-kotlin.xml-dsl-enabled", "true") ?: "true") - config.putIfAbsent("flavor", projectProvider.get()?.properties?.getProperty("polyglot-kotlin.flavor", "mixed") ?: "mixed") - ModelScriptWriter(this, config).write(model) - val kotlinScript = toString() - if (log.isDebugEnabled) { - log.debug(({ "POM model converted from XML: \n$kotlinScript\n" })()) - } - kotlinScript + override fun write(output: Writer, options: Map, model: Model) { + output.write( + with(StringWriter(1024)) { + val config = HashMap(options) + config.putIfAbsent( + "xml.dsl.enabled", + projectProvider + .get() + ?.properties + ?.getProperty("polyglot-kotlin.xml-dsl-enabled", "true") ?: "true") + config.putIfAbsent( + "flavor", + projectProvider.get()?.properties?.getProperty("polyglot-kotlin.flavor", "mixed") + ?: "mixed") + ModelScriptWriter(this, config).write(model) + val kotlinScript = toString() + if (log.isDebugEnabled) { + log.debug(({ "POM model converted from XML: \n$kotlinScript\n" })()) + } + kotlinScript }) - output.flush() - } - + output.flush() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Activation.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Activation.kt index da6d363c..b31a55e1 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Activation.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Activation.kt @@ -3,44 +3,40 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Activation : org.apache.maven.model.Activation(), Cloneable { - @PomDsl - fun os(name: String? = null, block: ActivationOS.(ActivationOS) -> Unit) { - val os = ActivationOS().apply { - this.name = name - } - block(os, os) - this.os = os - } + @PomDsl + fun os(name: String? = null, block: ActivationOS.(ActivationOS) -> Unit) { + val os = ActivationOS().apply { this.name = name } + block(os, os) + this.os = os + } - @PomDsl - fun property(name: String? = null, block: ActivationProperty.(ActivationProperty) -> Unit) { - val property = ActivationProperty().apply { - this.name = name - } - block(property, property) - this.property = property - } + @PomDsl + fun property(name: String? = null, block: ActivationProperty.(ActivationProperty) -> Unit) { + val property = ActivationProperty().apply { this.name = name } + block(property, property) + this.property = property + } - @PomDsl - fun file(block: ActivationFile.(ActivationFile) -> Unit) { - val file = ActivationFile() - block(file, file) - this.file = file - } + @PomDsl + fun file(block: ActivationFile.(ActivationFile) -> Unit) { + val file = ActivationFile() + block(file, file) + this.file = file + } - @PomDsl - fun jdk(jdk: String): Activation { - this.jdk = jdk - return this - } + @PomDsl + fun jdk(jdk: String): Activation { + this.jdk = jdk + return this + } - @PomDsl - fun activeByDefault(activeByDefault: Boolean = true): Activation { - this.isActiveByDefault = activeByDefault - return this - } + @PomDsl + fun activeByDefault(activeByDefault: Boolean = true): Activation { + this.isActiveByDefault = activeByDefault + return this + } - override fun clone(): org.apache.maven.model.Activation { - return super.clone() - } + override fun clone(): org.apache.maven.model.Activation { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationFile.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationFile.kt index cc6ddab2..ed20bcf1 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationFile.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationFile.kt @@ -3,19 +3,19 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ActivationFile : org.apache.maven.model.ActivationFile(), Cloneable { - @PomDsl - fun missing(missing: String): ActivationFile { - this.missing = missing - return this - } + @PomDsl + fun missing(missing: String): ActivationFile { + this.missing = missing + return this + } - @PomDsl - fun exists(exists: String): ActivationFile { - this.exists = exists - return this - } + @PomDsl + fun exists(exists: String): ActivationFile { + this.exists = exists + return this + } - override fun clone(): org.apache.maven.model.ActivationFile { - return super.clone() - } + override fun clone(): org.apache.maven.model.ActivationFile { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationOS.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationOS.kt index 467d9fea..fe9e3d4b 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationOS.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationOS.kt @@ -3,31 +3,31 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ActivationOS : org.apache.maven.model.ActivationOS(), Cloneable { - @PomDsl - fun name(name: String): ActivationOS { - this.name = name - return this - } + @PomDsl + fun name(name: String): ActivationOS { + this.name = name + return this + } - @PomDsl - fun family(family: String): ActivationOS { - this.family = family - return this - } + @PomDsl + fun family(family: String): ActivationOS { + this.family = family + return this + } - @PomDsl - fun arch(arch: String): ActivationOS { - this.arch = arch - return this - } + @PomDsl + fun arch(arch: String): ActivationOS { + this.arch = arch + return this + } - @PomDsl - fun version(version: String): ActivationOS { - this.version = version - return this - } + @PomDsl + fun version(version: String): ActivationOS { + this.version = version + return this + } - override fun clone(): org.apache.maven.model.ActivationOS { - return super.clone() - } + override fun clone(): org.apache.maven.model.ActivationOS { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationProperty.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationProperty.kt index eadc2987..38fcec1c 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationProperty.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ActivationProperty.kt @@ -3,19 +3,19 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ActivationProperty : org.apache.maven.model.ActivationProperty(), Cloneable { - @PomDsl - fun name(name: String): ActivationProperty { - this.name = name - return this - } + @PomDsl + fun name(name: String): ActivationProperty { + this.name = name + return this + } - @PomDsl - fun value(value: String): ActivationProperty { - this.value = value - return this - } + @PomDsl + fun value(value: String): ActivationProperty { + this.value = value + return this + } - override fun clone(): org.apache.maven.model.ActivationProperty { - return super.clone() - } + override fun clone(): org.apache.maven.model.ActivationProperty { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Build.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Build.kt index fb5da6ce..7be9d4d2 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Build.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Build.kt @@ -3,109 +3,110 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl open class Build : org.apache.maven.model.Build(), Cloneable { - @PomDsl - fun sourceDirectory(sourceDirectory: String): Build { - this.sourceDirectory = sourceDirectory - return this - } - - @PomDsl - fun scriptSourceDirectory(scriptSourceDirectory: String): Build { - this.scriptSourceDirectory = scriptSourceDirectory - return this - } - - @PomDsl - fun testSourceDirectory(testSourceDirectory: String): Build { - this.testSourceDirectory = testSourceDirectory - return this - } - - @PomDsl - fun outputDirectory(outputDirectory: String): Build { - this.outputDirectory = outputDirectory - return this - } - - @PomDsl - fun testOutputDirectory(testOutputDirectory: String): Build { - this.testOutputDirectory = testOutputDirectory - return this - } - - @PomDsl - fun defaultGoal(defaultGoal: String): Build { - this.defaultGoal = defaultGoal - return this - } - - @PomDsl - fun directory(directory: String): Build { - this.directory = directory - return this - } - - @PomDsl - fun finalName(finalName: String): Build { - this.finalName = finalName - return this - } - - @PomDsl - fun resources(block: ResourceList.(ResourceList) -> Unit) { - val resources = ResourceList() - block(resources, resources) - this.resources = resources - } - - @PomDsl - fun testResources(block: TestResourceList.(TestResourceList) -> Unit) { - val testResources = TestResourceList() - block(testResources, testResources) - this.testResources = testResources - } - - @PomDsl - fun extensions(block: ExtensionList.(ExtensionList) -> Unit) { - val extensions = ExtensionList() - block(extensions, extensions) - this.extensions = extensions - } - - @PomDsl - fun pluginManagement(block: PluginManagement.(PluginManagement) -> Unit) { - val pluginManagement = PluginManagement() - block.invoke(pluginManagement, pluginManagement) - this.pluginManagement = pluginManagement - } - - @PomDsl - fun plugins(block: PluginList.(PluginList) -> Unit) { - val plugins = PluginList() - block.invoke(plugins, plugins) - this.plugins = plugins - } - - @PomDsl - fun extensions(vararg gav: String): Build { - this.extensions = gav.map { value -> - val (groupId, artifactId, version) = splitCoordinates(value) - Extension().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version - } + @PomDsl + fun sourceDirectory(sourceDirectory: String): Build { + this.sourceDirectory = sourceDirectory + return this + } + + @PomDsl + fun scriptSourceDirectory(scriptSourceDirectory: String): Build { + this.scriptSourceDirectory = scriptSourceDirectory + return this + } + + @PomDsl + fun testSourceDirectory(testSourceDirectory: String): Build { + this.testSourceDirectory = testSourceDirectory + return this + } + + @PomDsl + fun outputDirectory(outputDirectory: String): Build { + this.outputDirectory = outputDirectory + return this + } + + @PomDsl + fun testOutputDirectory(testOutputDirectory: String): Build { + this.testOutputDirectory = testOutputDirectory + return this + } + + @PomDsl + fun defaultGoal(defaultGoal: String): Build { + this.defaultGoal = defaultGoal + return this + } + + @PomDsl + fun directory(directory: String): Build { + this.directory = directory + return this + } + + @PomDsl + fun finalName(finalName: String): Build { + this.finalName = finalName + return this + } + + @PomDsl + fun resources(block: ResourceList.(ResourceList) -> Unit) { + val resources = ResourceList() + block(resources, resources) + this.resources = resources + } + + @PomDsl + fun testResources(block: TestResourceList.(TestResourceList) -> Unit) { + val testResources = TestResourceList() + block(testResources, testResources) + this.testResources = testResources + } + + @PomDsl + fun extensions(block: ExtensionList.(ExtensionList) -> Unit) { + val extensions = ExtensionList() + block(extensions, extensions) + this.extensions = extensions + } + + @PomDsl + fun pluginManagement(block: PluginManagement.(PluginManagement) -> Unit) { + val pluginManagement = PluginManagement() + block.invoke(pluginManagement, pluginManagement) + this.pluginManagement = pluginManagement + } + + @PomDsl + fun plugins(block: PluginList.(PluginList) -> Unit) { + val plugins = PluginList() + block.invoke(plugins, plugins) + this.plugins = plugins + } + + @PomDsl + fun extensions(vararg gav: String): Build { + this.extensions = + gav.map { value -> + val (groupId, artifactId, version) = splitCoordinates(value) + Extension().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version + } } - return this - } - - @PomDsl - fun filters(vararg filters: String): Build { - this.filters = filters.asList() - return this - } - - override fun clone(): org.apache.maven.model.Build { - return super.clone() - } + return this + } + + @PomDsl + fun filters(vararg filters: String): Build { + this.filters = filters.asList() + return this + } + + override fun clone(): org.apache.maven.model.Build { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/CiManagement.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/CiManagement.kt index d343bc76..145c69f3 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/CiManagement.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/CiManagement.kt @@ -3,29 +3,27 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class CiManagement : org.apache.maven.model.CiManagement(), Cloneable { - @PomDsl - fun system(system: String): CiManagement { - this.system = system - return this - } + @PomDsl + fun system(system: String): CiManagement { + this.system = system + return this + } - @PomDsl - fun url(url: String): CiManagement { - this.url = url - return this - } + @PomDsl + fun url(url: String): CiManagement { + this.url = url + return this + } - /** - * Provides a callback for defining a list of notifiers. - */ - @PomDsl - fun notifiers(block: NotifierList.(NotifierList) -> Unit) { - val notifiers = NotifierList() - block.invoke(notifiers, notifiers) - this.notifiers = notifiers - } + /** Provides a callback for defining a list of notifiers. */ + @PomDsl + fun notifiers(block: NotifierList.(NotifierList) -> Unit) { + val notifiers = NotifierList() + block.invoke(notifiers, notifiers) + this.notifiers = notifiers + } - override fun clone(): org.apache.maven.model.CiManagement { - return super.clone() - } + override fun clone(): org.apache.maven.model.CiManagement { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Contributor.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Contributor.kt index 8d3e5473..a6797bff 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Contributor.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Contributor.kt @@ -3,61 +3,57 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Contributor : org.apache.maven.model.Contributor(), Cloneable { - @PomDsl - fun name(name: String): Contributor { - this.name = name - return this - } - - @PomDsl - fun email(email: String): Contributor { - this.email = email - return this - } - - @PomDsl - fun url(url: String): Contributor { - this.url = url - return this - } - - @PomDsl - fun organization(organization: String): Contributor { - this.organization = organization - return this - } - - @PomDsl - fun organizationUrl(organizationUrl: String): Contributor { - this.organizationUrl = organizationUrl - return this - } - - @PomDsl - fun roles(vararg roles: String): Contributor { - this.roles = roles.asList() - return this - } - - @PomDsl - fun timezone(timezone: String): Contributor { - this.timezone = timezone - return this - } - - /** - * Provides a callback for defining additional contributor properties. - */ - @PomDsl - fun properties(block: Properties.(Properties) -> Unit) { - val properties = Properties() - block.invoke(properties, properties) - this.properties = propertiesFactory().apply { - putAll(properties.entries()) - } - } - - override fun clone(): org.apache.maven.model.Contributor { - return super.clone() - } + @PomDsl + fun name(name: String): Contributor { + this.name = name + return this + } + + @PomDsl + fun email(email: String): Contributor { + this.email = email + return this + } + + @PomDsl + fun url(url: String): Contributor { + this.url = url + return this + } + + @PomDsl + fun organization(organization: String): Contributor { + this.organization = organization + return this + } + + @PomDsl + fun organizationUrl(organizationUrl: String): Contributor { + this.organizationUrl = organizationUrl + return this + } + + @PomDsl + fun roles(vararg roles: String): Contributor { + this.roles = roles.asList() + return this + } + + @PomDsl + fun timezone(timezone: String): Contributor { + this.timezone = timezone + return this + } + + /** Provides a callback for defining additional contributor properties. */ + @PomDsl + fun properties(block: Properties.(Properties) -> Unit) { + val properties = Properties() + block.invoke(properties, properties) + this.properties = propertiesFactory().apply { putAll(properties.entries()) } + } + + override fun clone(): org.apache.maven.model.Contributor { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ContributorList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ContributorList.kt index d7ce0e2c..bbe9c2a4 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ContributorList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ContributorList.kt @@ -3,39 +3,40 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ContributorList : ArrayList(), Cloneable { - private val nameAndEmailRegex: Regex = Regex("""([^<]+?)\s*<\s*(([^>@]+)@[^>]+)\s*>""") - private val emailRegex: Regex = Regex("""([^@]+)@.+""") + private val nameAndEmailRegex: Regex = Regex("""([^<]+?)\s*<\s*(([^>@]+)@[^>]+)\s*>""") + private val emailRegex: Regex = Regex("""([^@]+)@.+""") - /** - * Provides a callback for defining a new contributor entry. If formatted as `name `, the name will be - * extracted from the first part of the string, and the email from the second. - * - * @param name the name of the contributor - */ - @PomDsl - fun contributor(name: String? = null, block: (Contributor.(Contributor) -> Unit)? = null) { - val contributor = Contributor().apply { - if (name != null) { - val nameAndEmailMatch = this@ContributorList.nameAndEmailRegex.matchEntire(name) - if (nameAndEmailMatch != null) { - this.name = nameAndEmailMatch.groupValues[1] - this.email = nameAndEmailMatch.groupValues[2] - } else { - val emailMatch = this@ContributorList.emailRegex.matchEntire(name) - if (emailMatch != null) { - this.name = emailMatch.groupValues[1] - this.email = emailMatch.groupValues[0] - } else { - this.name = name - } - } + /** + * Provides a callback for defining a new contributor entry. If formatted as `name `, the + * name will be extracted from the first part of the string, and the email from the second. + * + * @param name the name of the contributor + */ + @PomDsl + fun contributor(name: String? = null, block: (Contributor.(Contributor) -> Unit)? = null) { + val contributor = + Contributor().apply { + if (name != null) { + val nameAndEmailMatch = this@ContributorList.nameAndEmailRegex.matchEntire(name) + if (nameAndEmailMatch != null) { + this.name = nameAndEmailMatch.groupValues[1] + this.email = nameAndEmailMatch.groupValues[2] + } else { + val emailMatch = this@ContributorList.emailRegex.matchEntire(name) + if (emailMatch != null) { + this.name = emailMatch.groupValues[1] + this.email = emailMatch.groupValues[0] + } else { + this.name = name + } } + } } - block?.invoke(contributor, contributor) - add(contributor) - } + block?.invoke(contributor, contributor) + add(contributor) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DSLSupport.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DSLSupport.kt index d2181277..e1272801 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DSLSupport.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DSLSupport.kt @@ -9,39 +9,40 @@ private val coordinatesDelimiter = Regex(":") /** * Splits the supplied artifact identifier into its constituent parts. * - * @param coordinates an artifact identifier in the form `groupId:artifactId[:version][:type][:classifier]` + * @param coordinates an artifact identifier in the form + * `groupId:artifactId[:version][:type][:classifier]` * @param size the size of the array to be returned */ fun splitCoordinates(coordinates: String?, size: Int = 5): Array { - val list = Array(size) { null } - coordinates?.split(coordinatesDelimiter, size)?.forEachIndexed { i, str -> - list[i] = if (str.isBlank()) null else str.trim() - } - return list + val list = Array(size) { null } + coordinates?.split(coordinatesDelimiter, size)?.forEachIndexed { i, str -> + list[i] = if (str.isBlank()) null else str.trim() + } + return list } fun MutableCollection.addAll(vararg t: T) { - t.forEach { add(it) } + t.forEach { add(it) } } fun MutableCollection.addFirstNonNull(vararg t: T?) { - val first = t.firstOrNull { it != null } - if (first != null) add(first) + val first = t.firstOrNull { it != null } + if (first != null) add(first) } fun MutableCollection.addAllNonNull(vararg t: T?) { - t.forEach { if (it != null) add(it) } + t.forEach { if (it != null) add(it) } } @Suppress("UNCHECKED_CAST") fun cast(o: Any): T { - return o as T + return o as T } fun escape(text: String): String { - return escapeJava(text).replace("\$", "\\\$") + return escapeJava(text).replace("\$", "\\\$") } fun escapeRaw(text: String): String { - return text.replace("""$""", """${'$'}{'$'}""") + return text.replace("""$""", """${'$'}{'$'}""") } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Dependency.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Dependency.kt index 447e6210..a8783e03 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Dependency.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Dependency.kt @@ -3,81 +3,81 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Dependency : org.apache.maven.model.Dependency(), Cloneable { - @PomDsl - fun groupId(groupId: String): Dependency { - this.groupId = groupId - return this - } + @PomDsl + fun groupId(groupId: String): Dependency { + this.groupId = groupId + return this + } - @PomDsl - fun artifactId(artifactId: String): Dependency { - this.artifactId = artifactId - return this - } + @PomDsl + fun artifactId(artifactId: String): Dependency { + this.artifactId = artifactId + return this + } - @PomDsl - fun version(version: String): Dependency { - this.version = version - return this - } + @PomDsl + fun version(version: String): Dependency { + this.version = version + return this + } - @PomDsl - fun type(type: String): Dependency { - this.type = type - return this - } + @PomDsl + fun type(type: String): Dependency { + this.type = type + return this + } - @PomDsl - fun classifier(classifier: String): Dependency { - this.classifier = classifier - return this - } + @PomDsl + fun classifier(classifier: String): Dependency { + this.classifier = classifier + return this + } - @PomDsl - fun scope(scope: String): Dependency { - this.scope = scope - return this - } + @PomDsl + fun scope(scope: String): Dependency { + this.scope = scope + return this + } - @PomDsl - fun systemPath(systemPath: String): Dependency { - this.systemPath = systemPath - return this - } + @PomDsl + fun systemPath(systemPath: String): Dependency { + this.systemPath = systemPath + return this + } - @PomDsl - fun optional(optional: Boolean = true): Dependency { - this.isOptional = optional - return this - } + @PomDsl + fun optional(optional: Boolean = true): Dependency { + this.isOptional = optional + return this + } - /** - * Provides a callback for defining dependency exclusions. - */ - @PomDsl - fun exclusions(block: ExclusionList.(ExclusionList) -> Unit): Dependency { - val exclusionList = ExclusionList() - block(exclusionList, exclusionList) - this.exclusions = exclusionList - return this - } + /** Provides a callback for defining dependency exclusions. */ + @PomDsl + fun exclusions(block: ExclusionList.(ExclusionList) -> Unit): Dependency { + val exclusionList = ExclusionList() + block(exclusionList, exclusionList) + this.exclusions = exclusionList + return this + } - /** - * Excludes the artifacts having the specified `groupId:artifactId`. The wildcard `*` character can be used to - * exclude matching artifacts. - */ - @PomDsl - fun exclusions(vararg ga: String): Dependency { - this.exclusions = ga.map { splitCoordinates(it) }.map { (groupId, artifactId) -> - Exclusion().apply { + /** + * Excludes the artifacts having the specified `groupId:artifactId`. The wildcard `*` character + * can be used to exclude matching artifacts. + */ + @PomDsl + fun exclusions(vararg ga: String): Dependency { + this.exclusions = + ga.map { splitCoordinates(it) } + .map { (groupId, artifactId) -> + Exclusion().apply { this.groupId = groupId this.artifactId = artifactId + } } - } - return this - } + return this + } - override fun clone(): org.apache.maven.model.Dependency { - return super.clone() - } + override fun clone(): org.apache.maven.model.Dependency { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DependencyList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DependencyList.kt index 71e7c889..df2716ce 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DependencyList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DependencyList.kt @@ -3,163 +3,177 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl open class DependencyList : ArrayList(), Cloneable { - /** - * Adds a dependency identified by the supplied coordinates. - * - * @param gavtc an artifact identifier in the form `groupId:artifactId[:version][:type][:classifier]` - * @param block a callback for performing additional initialization - */ - @PomDsl - fun dependency(gavtc: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - val (groupId, artifactId, version, type, classifier) = splitCoordinates(gavtc) - return Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version - if (type != null) this.type = type - this.classifier = classifier - this@DependencyList.add(this) - block?.invoke(this, this) - } + /** + * Adds a dependency identified by the supplied coordinates. + * + * @param gavtc an artifact identifier in the form + * `groupId:artifactId[:version][:type][:classifier]` + * @param block a callback for performing additional initialization + */ + @PomDsl + fun dependency( + gavtc: String? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + val (groupId, artifactId, version, type, classifier) = splitCoordinates(gavtc) + return Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version + if (type != null) this.type = type + this.classifier = classifier + this@DependencyList.add(this) + block?.invoke(this, this) } + } - /** - * Adds a "compile" scope dependency identified by the supplied coordinates. - * - * @param gavtc an artifact identifier in the form `groupId:artifactId[:version][:type][:classifier]` - * @param block a callback for performing additional initialization - */ - @PomDsl - fun compile(gavtc: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency(gavtc, block).apply { - this.scope = "compile" - } - } + /** + * Adds a "compile" scope dependency identified by the supplied coordinates. + * + * @param gavtc an artifact identifier in the form + * `groupId:artifactId[:version][:type][:classifier]` + * @param block a callback for performing additional initialization + */ + @PomDsl + fun compile(gavtc: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { + return dependency(gavtc, block).apply { this.scope = "compile" } + } - /** - * Adds a "test" scope dependency identified by the supplied coordinates. - * - * @param gavtc an artifact identifier in the form `groupId:artifactId[:version][:type][:classifier]` - * @param block a callback for performing additional initialization - */ - @PomDsl - fun test(gavtc: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency(gavtc, block).apply { - this.scope = "test" - } - } + /** + * Adds a "test" scope dependency identified by the supplied coordinates. + * + * @param gavtc an artifact identifier in the form + * `groupId:artifactId[:version][:type][:classifier]` + * @param block a callback for performing additional initialization + */ + @PomDsl + fun test(gavtc: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { + return dependency(gavtc, block).apply { this.scope = "test" } + } - /** - * Adds a "provided" scope dependency identified by the supplied coordinates. - * - * @param gavtc an artifact identifier in the form `groupId:artifactId[:version][:type][:classifier]` - * @param block a callback for performing additional initialization - */ - @PomDsl - fun provided(gavtc: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency(gavtc, block).apply { - this.scope = "provided" - } - } + /** + * Adds a "provided" scope dependency identified by the supplied coordinates. + * + * @param gavtc an artifact identifier in the form + * `groupId:artifactId[:version][:type][:classifier]` + * @param block a callback for performing additional initialization + */ + @PomDsl + fun provided( + gavtc: String? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return dependency(gavtc, block).apply { this.scope = "provided" } + } - /** - * Adds a "runtime" scope dependency identified by the supplied coordinates. - * - * @param gavtc an artifact identifier in the form `groupId:artifactId[:version][:type][:classifier]` - * @param block a callback for performing additional initialization - */ - @PomDsl - fun runtime(gavtc: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency(gavtc, block).apply { - this.scope = "runtime" - } - } + /** + * Adds a "runtime" scope dependency identified by the supplied coordinates. + * + * @param gavtc an artifact identifier in the form + * `groupId:artifactId[:version][:type][:classifier]` + * @param block a callback for performing additional initialization + */ + @PomDsl + fun runtime(gavtc: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { + return dependency(gavtc, block).apply { this.scope = "runtime" } + } - /** - * Adds a "system" scope dependency identified by the supplied coordinates. - * - * @param gavtc an artifact identifier in the form `groupId:artifactId[:version][:type][:classifier]` - * @param systemPath the location of the system dependency, relative to `${basedir}` - * @param block a callback for performing additional initialization - */ - @PomDsl - fun system(gavtc: String? = null, systemPath: String, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency(gavtc, block).apply { - this.scope = "system" - this.systemPath = systemPath - } + /** + * Adds a "system" scope dependency identified by the supplied coordinates. + * + * @param gavtc an artifact identifier in the form + * `groupId:artifactId[:version][:type][:classifier]` + * @param systemPath the location of the system dependency, relative to `${basedir}` + * @param block a callback for performing additional initialization + */ + @PomDsl + fun system( + gavtc: String? = null, + systemPath: String, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return dependency(gavtc, block).apply { + this.scope = "system" + this.systemPath = systemPath } + } - /** - * Adds an optional (non-transitive) dependency identified by the supplied coordinates. - * - * @param gavtc an artifact identifier in the form `groupId:artifactId[:version][:type][:classifier]` - * @param block a callback for performing additional initialization - */ - @PomDsl - fun optional(gavtc: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency(gavtc, block).apply { - this.isOptional = true - } - } + /** + * Adds an optional (non-transitive) dependency identified by the supplied coordinates. + * + * @param gavtc an artifact identifier in the form + * `groupId:artifactId[:version][:type][:classifier]` + * @param block a callback for performing additional initialization + */ + @PomDsl + fun optional( + gavtc: String? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return dependency(gavtc, block).apply { this.isOptional = true } + } - /** - * Adds a dependency identified by the supplied coordinate parameters. - * - * @param groupId the dependency groupId - * @param artifactId the dependency artifactId - * @param version the dependency version - * @param type the dependency packaging type - * @param classifier the dependency classifier - * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) - * @param scope the dependency scope ("compile", "runtime", "test", "provided", "system") - * @param systemPath the dependency system path when the scope is "system" - * @param block a callback for performing additional initialization - */ - @PomDsl - fun dependency(groupId: String, - artifactId: String, - version: String? = null, - type: String = "jar", - classifier: String? = null, - optional: Boolean? = null, - scope: String? = null, - systemPath: String? = null, - block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version - this.type = type - this.classifier = classifier - if (optional != null) this.isOptional = optional - this.scope = scope - this.systemPath = systemPath - this@DependencyList.add(this) - block?.invoke(this, this) - } + /** + * Adds a dependency identified by the supplied coordinate parameters. + * + * @param groupId the dependency groupId + * @param artifactId the dependency artifactId + * @param version the dependency version + * @param type the dependency packaging type + * @param classifier the dependency classifier + * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) + * @param scope the dependency scope ("compile", "runtime", "test", "provided", "system") + * @param systemPath the dependency system path when the scope is "system" + * @param block a callback for performing additional initialization + */ + @PomDsl + fun dependency( + groupId: String, + artifactId: String, + version: String? = null, + type: String = "jar", + classifier: String? = null, + optional: Boolean? = null, + scope: String? = null, + systemPath: String? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version + this.type = type + this.classifier = classifier + if (optional != null) this.isOptional = optional + this.scope = scope + this.systemPath = systemPath + this@DependencyList.add(this) + block?.invoke(this, this) } + } - /** - * Adds a "compile" scope dependency identified by the supplied coordinate parameters. - * - * @param groupId the dependency groupId - * @param artifactId the dependency artifactId - * @param version the dependency version - * @param type the dependency packaging type - * @param classifier the dependency classifier - * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) - * @param block a callback for performing additional initialization - */ - @PomDsl - fun compile(groupId: String, - artifactId: String, - version: String? = null, - type: String = "jar", - classifier: String? = null, - optional: Boolean? = null, - block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency( + /** + * Adds a "compile" scope dependency identified by the supplied coordinate parameters. + * + * @param groupId the dependency groupId + * @param artifactId the dependency artifactId + * @param version the dependency version + * @param type the dependency packaging type + * @param classifier the dependency classifier + * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) + * @param block a callback for performing additional initialization + */ + @PomDsl + fun compile( + groupId: String, + artifactId: String, + version: String? = null, + type: String = "jar", + classifier: String? = null, + optional: Boolean? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return dependency( groupId = groupId, artifactId = artifactId, version = version, @@ -168,31 +182,31 @@ open class DependencyList : ArrayList(), Clon optional = optional, scope = "compile", block = block) - .apply { - scope = "compile" - } - } + .apply { scope = "compile" } + } - /** - * Adds a "test" scope dependency identified by the supplied coordinate parameters. - * - * @param groupId the dependency groupId - * @param artifactId the dependency artifactId - * @param version the dependency version - * @param type the dependency packaging type - * @param classifier the dependency classifier - * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) - * @param block a callback for performing additional initialization - */ - @PomDsl - fun test(groupId: String, - artifactId: String, - version: String? = null, - type: String = "jar", - classifier: String? = null, - optional: Boolean? = null, - block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency( + /** + * Adds a "test" scope dependency identified by the supplied coordinate parameters. + * + * @param groupId the dependency groupId + * @param artifactId the dependency artifactId + * @param version the dependency version + * @param type the dependency packaging type + * @param classifier the dependency classifier + * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) + * @param block a callback for performing additional initialization + */ + @PomDsl + fun test( + groupId: String, + artifactId: String, + version: String? = null, + type: String = "jar", + classifier: String? = null, + optional: Boolean? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return dependency( groupId = groupId, artifactId = artifactId, version = version, @@ -201,31 +215,31 @@ open class DependencyList : ArrayList(), Clon optional = optional, scope = "test", block = block) - .apply { - scope = "test" - } - } + .apply { scope = "test" } + } - /** - * Adds a "provided" scope dependency identified by the supplied coordinate parameters. - * - * @param groupId the dependency groupId - * @param artifactId the dependency artifactId - * @param version the dependency version - * @param type the dependency packaging type - * @param classifier the dependency classifier - * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) - * @param block a callback for performing additional initialization - */ - @PomDsl - fun provided(groupId: String, - artifactId: String, - version: String? = null, - type: String = "jar", - classifier: String? = null, - optional: Boolean? = null, - block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency( + /** + * Adds a "provided" scope dependency identified by the supplied coordinate parameters. + * + * @param groupId the dependency groupId + * @param artifactId the dependency artifactId + * @param version the dependency version + * @param type the dependency packaging type + * @param classifier the dependency classifier + * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) + * @param block a callback for performing additional initialization + */ + @PomDsl + fun provided( + groupId: String, + artifactId: String, + version: String? = null, + type: String = "jar", + classifier: String? = null, + optional: Boolean? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return dependency( groupId = groupId, artifactId = artifactId, version = version, @@ -234,31 +248,31 @@ open class DependencyList : ArrayList(), Clon optional = optional, scope = "provided", block = block) - .apply { - this.scope = "provided" - } - } + .apply { this.scope = "provided" } + } - /** - * Adds a "runtime" scope dependency identified by the supplied coordinate parameters. - * - * @param groupId the dependency groupId - * @param artifactId the dependency artifactId - * @param version the dependency version - * @param type the dependency packaging type - * @param classifier the dependency classifier - * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) - * @param block a callback for performing additional initialization - */ - @PomDsl - fun runtime(groupId: String, - artifactId: String, - version: String? = null, - type: String = "jar", - classifier: String? = null, - optional: Boolean? = null, - block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency( + /** + * Adds a "runtime" scope dependency identified by the supplied coordinate parameters. + * + * @param groupId the dependency groupId + * @param artifactId the dependency artifactId + * @param version the dependency version + * @param type the dependency packaging type + * @param classifier the dependency classifier + * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) + * @param block a callback for performing additional initialization + */ + @PomDsl + fun runtime( + groupId: String, + artifactId: String, + version: String? = null, + type: String = "jar", + classifier: String? = null, + optional: Boolean? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return dependency( groupId = groupId, artifactId = artifactId, version = version, @@ -267,33 +281,33 @@ open class DependencyList : ArrayList(), Clon optional = optional, scope = "runtime", block = block) - .apply { - this.scope = "runtime" - } - } + .apply { this.scope = "runtime" } + } - /** - * Adds a "system" scope dependency identified by the supplied coordinate parameters. - * - * @param groupId the dependency groupId - * @param artifactId the dependency artifactId - * @param version the dependency version - * @param type the dependency packaging type - * @param classifier the dependency classifier - * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) - * @param systemPath the location of the system dependency relative to `${basedir}` - * @param block a callback for performing additional initialization - */ - @PomDsl - fun system(groupId: String, - artifactId: String, - version: String? = null, - type: String = "jar", - classifier: String? = null, - optional: Boolean? = null, - systemPath: String, - block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency( + /** + * Adds a "system" scope dependency identified by the supplied coordinate parameters. + * + * @param groupId the dependency groupId + * @param artifactId the dependency artifactId + * @param version the dependency version + * @param type the dependency packaging type + * @param classifier the dependency classifier + * @param optional a boolean flag indicating whether the dependency is optional (non-transitive) + * @param systemPath the location of the system dependency relative to `${basedir}` + * @param block a callback for performing additional initialization + */ + @PomDsl + fun system( + groupId: String, + artifactId: String, + version: String? = null, + type: String = "jar", + classifier: String? = null, + optional: Boolean? = null, + systemPath: String, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return dependency( groupId = groupId, artifactId = artifactId, version = version, @@ -303,42 +317,44 @@ open class DependencyList : ArrayList(), Clon scope = "system", systemPath = systemPath, block = block) - .apply { - this.scope = "system" - this.systemPath = systemPath - } - } + .apply { + this.scope = "system" + this.systemPath = systemPath + } + } - /** - * Adds an optional dependency identified by the supplied coordinate parameters. - * - * @param groupId the dependency groupId - * @param artifactId the dependency artifactId - * @param version the dependency version - * @param type the dependency packaging type - * @param classifier the dependency classifier - * @param block a callback for performing additional initialization - */ - @PomDsl - fun optional(groupId: String, - artifactId: String, - version: String? = null, - type: String = "jar", - classifier: String? = null, - scope: String? = null, - block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency( - groupId = groupId, - artifactId = artifactId, - version = version, - scope = scope, - type = type, - classifier = classifier, - optional = true, - block = block) - } + /** + * Adds an optional dependency identified by the supplied coordinate parameters. + * + * @param groupId the dependency groupId + * @param artifactId the dependency artifactId + * @param version the dependency version + * @param type the dependency packaging type + * @param classifier the dependency classifier + * @param block a callback for performing additional initialization + */ + @PomDsl + fun optional( + groupId: String, + artifactId: String, + version: String? = null, + type: String = "jar", + classifier: String? = null, + scope: String? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return dependency( + groupId = groupId, + artifactId = artifactId, + version = version, + scope = scope, + type = type, + classifier = classifier, + optional = true, + block = block) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DependencyManagement.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DependencyManagement.kt index aa7a95ed..fd6fd60e 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DependencyManagement.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DependencyManagement.kt @@ -3,14 +3,14 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class DependencyManagement : org.apache.maven.model.DependencyManagement(), Cloneable { - @PomDsl - fun dependencies(block: ManagedDependencyList.(ManagedDependencyList) -> Unit) { - val dependencies = ManagedDependencyList() - block.invoke(dependencies, dependencies) - this.dependencies = dependencies - } + @PomDsl + fun dependencies(block: ManagedDependencyList.(ManagedDependencyList) -> Unit) { + val dependencies = ManagedDependencyList() + block.invoke(dependencies, dependencies) + this.dependencies = dependencies + } - override fun clone(): org.apache.maven.model.DependencyManagement { - return super.clone() - } + override fun clone(): org.apache.maven.model.DependencyManagement { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DeploymentRepository.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DeploymentRepository.kt index 80611158..baa64d12 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DeploymentRepository.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DeploymentRepository.kt @@ -3,36 +3,36 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class DeploymentRepository : org.apache.maven.model.DeploymentRepository(), Cloneable { - @PomDsl - fun uniqueVersion(uniqueVersion: Boolean = true) { - this.isUniqueVersion = uniqueVersion - } + @PomDsl + fun uniqueVersion(uniqueVersion: Boolean = true) { + this.isUniqueVersion = uniqueVersion + } - @PomDsl - fun id(id: String): DeploymentRepository { - this.id = id - return this - } + @PomDsl + fun id(id: String): DeploymentRepository { + this.id = id + return this + } - @PomDsl - fun name(name: String): DeploymentRepository { - this.name = name - return this - } + @PomDsl + fun name(name: String): DeploymentRepository { + this.name = name + return this + } - @PomDsl - fun url(url: String): DeploymentRepository { - this.url = url - return this - } + @PomDsl + fun url(url: String): DeploymentRepository { + this.url = url + return this + } - @PomDsl - fun layout(layout: String): DeploymentRepository { - this.layout = layout - return this - } + @PomDsl + fun layout(layout: String): DeploymentRepository { + this.layout = layout + return this + } - override fun clone(): org.apache.maven.model.DeploymentRepository { - return super.clone() - } + override fun clone(): org.apache.maven.model.DeploymentRepository { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Developer.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Developer.kt index fe6dfcf2..dc77a64c 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Developer.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Developer.kt @@ -3,67 +3,63 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Developer : org.apache.maven.model.Developer(), Cloneable { - @PomDsl - fun id(id: String): Developer { - this.id = id - return this - } + @PomDsl + fun id(id: String): Developer { + this.id = id + return this + } - @PomDsl - fun name(name: String): Developer { - this.name = name - return this - } + @PomDsl + fun name(name: String): Developer { + this.name = name + return this + } - @PomDsl - fun email(email: String): Developer { - this.email = email - return this - } + @PomDsl + fun email(email: String): Developer { + this.email = email + return this + } - @PomDsl - fun url(url: String): Developer { - this.url = url - return this - } + @PomDsl + fun url(url: String): Developer { + this.url = url + return this + } - @PomDsl - fun organization(organization: String): Developer { - this.organization = organization - return this - } + @PomDsl + fun organization(organization: String): Developer { + this.organization = organization + return this + } - @PomDsl - fun organizationUrl(organizationUrl: String): Developer { - this.organizationUrl = organizationUrl - return this - } + @PomDsl + fun organizationUrl(organizationUrl: String): Developer { + this.organizationUrl = organizationUrl + return this + } - @PomDsl - fun roles(vararg roles: String): Developer { - this.roles = roles.asList() - return this - } + @PomDsl + fun roles(vararg roles: String): Developer { + this.roles = roles.asList() + return this + } - @PomDsl - fun timezone(timezone: String): Developer { - this.timezone = timezone - return this - } + @PomDsl + fun timezone(timezone: String): Developer { + this.timezone = timezone + return this + } - /** - * Provides a callback for defining additional developer properties. - */ - @PomDsl - fun properties(block: Properties.(Properties) -> Unit) { - val properties = Properties() - block.invoke(properties, properties) - this.properties = propertiesFactory().apply { - putAll(properties.entries()) - } - } + /** Provides a callback for defining additional developer properties. */ + @PomDsl + fun properties(block: Properties.(Properties) -> Unit) { + val properties = Properties() + block.invoke(properties, properties) + this.properties = propertiesFactory().apply { putAll(properties.entries()) } + } - override fun clone(): org.apache.maven.model.Developer { - return super.clone() - } + override fun clone(): org.apache.maven.model.Developer { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DeveloperList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DeveloperList.kt index ad3eca18..171ad846 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DeveloperList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DeveloperList.kt @@ -3,43 +3,44 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class DeveloperList : ArrayList(), Cloneable { - private val nameAndEmailRegex: Regex = Regex("""([^<]+?)\s*<\s*(([^>@]+)@[^>]+)\s*>""") - private val emailRegex: Regex = Regex("""([^@]+)@.+""") + private val nameAndEmailRegex: Regex = Regex("""([^<]+?)\s*<\s*(([^>@]+)@[^>]+)\s*>""") + private val emailRegex: Regex = Regex("""([^@]+)@.+""") - /** - * Provides a callback for defining a new developer entry. If formatted as `name `, the name will be - * extracted from the first part of the string, and the email from the second. The ID will be extracted from the - * email. - * - * @param nameOrId the name or id of the developer entry - */ - @PomDsl - fun developer(nameOrId: String? = null, block: (Developer.(Developer) -> Unit)? = null) { - val developer = Developer().apply { - if (nameOrId != null) { - val nameAndEmailMatch = this@DeveloperList.nameAndEmailRegex.matchEntire(nameOrId) - if (nameAndEmailMatch != null) { - this.id = nameAndEmailMatch.groupValues[3] - this.name = nameAndEmailMatch.groupValues[1] - this.email = nameAndEmailMatch.groupValues[2] - } else { - val emailMatch = this@DeveloperList.emailRegex.matchEntire(nameOrId) - if (emailMatch != null) { - this.id = emailMatch.groupValues[1] - this.name = emailMatch.groupValues[1] - this.email = emailMatch.groupValues[0] - } else { - this.id = nameOrId - this.name = nameOrId - } - } + /** + * Provides a callback for defining a new developer entry. If formatted as `name `, the + * name will be extracted from the first part of the string, and the email from the second. The ID + * will be extracted from the email. + * + * @param nameOrId the name or id of the developer entry + */ + @PomDsl + fun developer(nameOrId: String? = null, block: (Developer.(Developer) -> Unit)? = null) { + val developer = + Developer().apply { + if (nameOrId != null) { + val nameAndEmailMatch = this@DeveloperList.nameAndEmailRegex.matchEntire(nameOrId) + if (nameAndEmailMatch != null) { + this.id = nameAndEmailMatch.groupValues[3] + this.name = nameAndEmailMatch.groupValues[1] + this.email = nameAndEmailMatch.groupValues[2] + } else { + val emailMatch = this@DeveloperList.emailRegex.matchEntire(nameOrId) + if (emailMatch != null) { + this.id = emailMatch.groupValues[1] + this.name = emailMatch.groupValues[1] + this.email = emailMatch.groupValues[0] + } else { + this.id = nameOrId + this.name = nameOrId + } } + } } - block?.invoke(developer, developer) - add(developer) - } + block?.invoke(developer, developer) + add(developer) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DistributionManagement.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DistributionManagement.kt index 4d2b232a..89793406 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DistributionManagement.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DistributionManagement.kt @@ -3,59 +3,69 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class DistributionManagement : org.apache.maven.model.DistributionManagement(), Cloneable { - @PomDsl - fun downloadUrl(downloadUrl: String) { - this.downloadUrl = downloadUrl - } - - @PomDsl - fun status(status: String) { - this.status = status - } - - @PomDsl - fun repository(nameOrId: String? = null, block: DeploymentRepository.(DeploymentRepository) -> Unit) { - val repository = DeploymentRepository().apply { - this.id = nameOrId - this.name = nameOrId + @PomDsl + fun downloadUrl(downloadUrl: String) { + this.downloadUrl = downloadUrl + } + + @PomDsl + fun status(status: String) { + this.status = status + } + + @PomDsl + fun repository( + nameOrId: String? = null, + block: DeploymentRepository.(DeploymentRepository) -> Unit + ) { + val repository = + DeploymentRepository().apply { + this.id = nameOrId + this.name = nameOrId } - block.invoke(repository, repository) - this.repository = repository - } - - @PomDsl - fun snapshotRepository(nameOrId: String? = null, block: DeploymentRepository.(DeploymentRepository) -> Unit) { - val snapshotRepository = DeploymentRepository().apply { - this.id = nameOrId - this.name = nameOrId + block.invoke(repository, repository) + this.repository = repository + } + + @PomDsl + fun snapshotRepository( + nameOrId: String? = null, + block: DeploymentRepository.(DeploymentRepository) -> Unit + ) { + val snapshotRepository = + DeploymentRepository().apply { + this.id = nameOrId + this.name = nameOrId } - block.invoke(snapshotRepository, snapshotRepository) - this.snapshotRepository = snapshotRepository - } - - @PomDsl - fun site(nameOrId: String? = null, block: Site.(Site) -> Unit) { - val site = Site().apply { - this.id = nameOrId - this.name = nameOrId + block.invoke(snapshotRepository, snapshotRepository) + this.snapshotRepository = snapshotRepository + } + + @PomDsl + fun site(nameOrId: String? = null, block: Site.(Site) -> Unit) { + val site = + Site().apply { + this.id = nameOrId + this.name = nameOrId } - block.invoke(site, site) - this.site = site - } - - @PomDsl - fun relocation(gav: String? = null, block: Relocation.(Relocation) -> Unit) { - val (groupId, artifactId, version) = splitCoordinates(gav, 3) - val relocation = Relocation().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + block.invoke(site, site) + this.site = site + } + + @PomDsl + fun relocation(gav: String? = null, block: Relocation.(Relocation) -> Unit) { + val (groupId, artifactId, version) = splitCoordinates(gav, 3) + val relocation = + Relocation().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - block.invoke(relocation, relocation) - this.relocation = relocation - } + block.invoke(relocation, relocation) + this.relocation = relocation + } - override fun clone(): org.apache.maven.model.DistributionManagement { - return super.clone() - } + override fun clone(): org.apache.maven.model.DistributionManagement { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Exclusion.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Exclusion.kt index d1cbaa71..a7b7524c 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Exclusion.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Exclusion.kt @@ -3,19 +3,19 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Exclusion : org.apache.maven.model.Exclusion(), Cloneable { - @PomDsl - fun groupId(groupId: String): Exclusion { - this.groupId = groupId - return this - } + @PomDsl + fun groupId(groupId: String): Exclusion { + this.groupId = groupId + return this + } - @PomDsl - fun artifactId(artifactId: String): Exclusion { - this.artifactId = artifactId - return this - } + @PomDsl + fun artifactId(artifactId: String): Exclusion { + this.artifactId = artifactId + return this + } - override fun clone(): org.apache.maven.model.Exclusion { - return super.clone() - } + override fun clone(): org.apache.maven.model.Exclusion { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ExclusionList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ExclusionList.kt index fa0d5b1a..9b8ac973 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ExclusionList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ExclusionList.kt @@ -3,17 +3,15 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ExclusionList : ArrayList(), Cloneable { - /** - * Provides a callback for defining a new dependency exclusion. - */ - @PomDsl - fun exclusion(block: Exclusion.(Exclusion) -> Unit) { - val exclusion = Exclusion() - block(exclusion, exclusion) - add(exclusion) - } + /** Provides a callback for defining a new dependency exclusion. */ + @PomDsl + fun exclusion(block: Exclusion.(Exclusion) -> Unit) { + val exclusion = Exclusion() + block(exclusion, exclusion) + add(exclusion) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Extension.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Extension.kt index c7f8d9e7..7f611dbf 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Extension.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Extension.kt @@ -1,27 +1,27 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl -class Extension : org.apache.maven.model.Extension(), Cloneable { +class Extension : org.apache.maven.model.Extension(), Cloneable { - @PomDsl - fun groupId(groupId: String): Extension { - this.groupId = groupId - return this - } + @PomDsl + fun groupId(groupId: String): Extension { + this.groupId = groupId + return this + } - @PomDsl - fun artifactId(artifactId: String): Extension { - this.artifactId = artifactId - return this - } + @PomDsl + fun artifactId(artifactId: String): Extension { + this.artifactId = artifactId + return this + } - @PomDsl - fun version(version: String): Extension { - this.version = version - return this - } + @PomDsl + fun version(version: String): Extension { + this.version = version + return this + } - override fun clone(): org.apache.maven.model.Extension { - return super.clone() - } + override fun clone(): org.apache.maven.model.Extension { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ExtensionList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ExtensionList.kt index b0eb1ff6..e3ed3a92 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ExtensionList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ExtensionList.kt @@ -3,22 +3,20 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ExtensionList : ArrayList(), Cloneable { - /** - * Provides a callback for defining a new build extension. - */ - @PomDsl - fun extension(gav: String? = null, block: (Extension.(Extension) -> Unit)? = null): Extension { - val (groupId, artifactId, version) = splitCoordinates(gav, 3) - return Extension().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version - this@ExtensionList.add(this) - block?.invoke(this, this) - } + /** Provides a callback for defining a new build extension. */ + @PomDsl + fun extension(gav: String? = null, block: (Extension.(Extension) -> Unit)? = null): Extension { + val (groupId, artifactId, version) = splitCoordinates(gav, 3) + return Extension().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version + this@ExtensionList.add(this) + block?.invoke(this, this) } + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/IssueManagement.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/IssueManagement.kt index d9f81d9d..971309df 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/IssueManagement.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/IssueManagement.kt @@ -3,19 +3,19 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class IssueManagement : org.apache.maven.model.IssueManagement(), Cloneable { - @PomDsl - fun system(system: String): IssueManagement { - this.system = system - return this - } + @PomDsl + fun system(system: String): IssueManagement { + this.system = system + return this + } - @PomDsl - fun url(url: String): IssueManagement { - this.url = url - return this - } + @PomDsl + fun url(url: String): IssueManagement { + this.url = url + return this + } - override fun clone(): org.apache.maven.model.IssueManagement { - return super.clone() - } + override fun clone(): org.apache.maven.model.IssueManagement { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/License.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/License.kt index 0aa29f0e..af49ba48 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/License.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/License.kt @@ -3,31 +3,31 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class License : org.apache.maven.model.License(), Cloneable { - @PomDsl - fun name(name: String): License { - this.name = name - return this - } + @PomDsl + fun name(name: String): License { + this.name = name + return this + } - @PomDsl - fun url(url: String): License { - this.url = url - return this - } + @PomDsl + fun url(url: String): License { + this.url = url + return this + } - @PomDsl - fun distribution(distribution: String): License { - this.distribution = distribution - return this - } + @PomDsl + fun distribution(distribution: String): License { + this.distribution = distribution + return this + } - @PomDsl - fun comments(comments: String): License { - this.comments = comments - return this - } + @PomDsl + fun comments(comments: String): License { + this.comments = comments + return this + } - override fun clone(): org.apache.maven.model.License { - return super.clone() - } + override fun clone(): org.apache.maven.model.License { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/LicenseList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/LicenseList.kt index fab627a7..191d0e0d 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/LicenseList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/LicenseList.kt @@ -3,16 +3,14 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class LicenseList : ArrayList(), Cloneable { - @PomDsl - fun license(name: String? = null, block: License.(License) -> Unit) { - val license = License().apply { - this.name = name - } - block.invoke(license, license) - add(license) - } + @PomDsl + fun license(name: String? = null, block: License.(License) -> Unit) { + val license = License().apply { this.name = name } + block.invoke(license, license) + add(license) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/MailingList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/MailingList.kt index f0d54ab6..022baaa8 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/MailingList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/MailingList.kt @@ -3,43 +3,43 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class MailingList : org.apache.maven.model.MailingList(), Cloneable { - @PomDsl - fun name(name: String): MailingList { - this.name = name - return this - } - - @PomDsl - fun subscribe(subscribe: String): MailingList { - this.subscribe = subscribe - return this - } - - @PomDsl - fun unsubscribe(unsubscribe: String): MailingList { - this.unsubscribe = unsubscribe - return this - } - - @PomDsl - fun post(post: String): MailingList { - this.post = post - return this - } - - @PomDsl - fun archive(name: String): MailingList { - this.archive = name - return this - } - - @PomDsl - fun otherArchives(vararg otherArchives: String): MailingList { - this.otherArchives = otherArchives.asList() - return this - } - - override fun clone(): org.apache.maven.model.MailingList { - return super.clone() - } + @PomDsl + fun name(name: String): MailingList { + this.name = name + return this + } + + @PomDsl + fun subscribe(subscribe: String): MailingList { + this.subscribe = subscribe + return this + } + + @PomDsl + fun unsubscribe(unsubscribe: String): MailingList { + this.unsubscribe = unsubscribe + return this + } + + @PomDsl + fun post(post: String): MailingList { + this.post = post + return this + } + + @PomDsl + fun archive(name: String): MailingList { + this.archive = name + return this + } + + @PomDsl + fun otherArchives(vararg otherArchives: String): MailingList { + this.otherArchives = otherArchives.asList() + return this + } + + override fun clone(): org.apache.maven.model.MailingList { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/MailingListList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/MailingListList.kt index 2cd74207..cfbbd710 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/MailingListList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/MailingListList.kt @@ -3,19 +3,15 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class MailingListList : ArrayList(), Cloneable { - /** - * Provides a callback for defining a new mailing list. - */ - @PomDsl - fun mailingList(name: String? = null, block: MailingList.(MailingList) -> Unit) { - val mailingList = MailingList().apply { - this.name = name - } - block(mailingList, mailingList) - add(mailingList) - } + /** Provides a callback for defining a new mailing list. */ + @PomDsl + fun mailingList(name: String? = null, block: MailingList.(MailingList) -> Unit) { + val mailingList = MailingList().apply { this.name = name } + block(mailingList, mailingList) + add(mailingList) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ManagedDependencyList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ManagedDependencyList.kt index 8b95f17c..aef00d74 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ManagedDependencyList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ManagedDependencyList.kt @@ -3,32 +3,35 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ManagedDependencyList : DependencyList(), Cloneable { - @PomDsl - fun import(gav: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency(gav, block).apply { - scope = "import" - type = "pom" - } + @PomDsl + fun import(gav: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { + return dependency(gav, block).apply { + scope = "import" + type = "pom" } + } - @PomDsl - fun import(groupId: String, - artifactId: String, - version: String? = null, - classifier: String? = null, - block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return dependency( + @PomDsl + fun import( + groupId: String, + artifactId: String, + version: String? = null, + classifier: String? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return dependency( groupId = groupId, artifactId = artifactId, version = version, classifier = classifier, - block = block).apply { - this.scope = "import" - this.type = "pom" + block = block) + .apply { + this.scope = "import" + this.type = "pom" } - } + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Notifier.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Notifier.kt index 9f5fcc3c..c3c5a5c4 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Notifier.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Notifier.kt @@ -3,52 +3,50 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Notifier : org.apache.maven.model.Notifier(), Cloneable { - @PomDsl - fun type(type: String): Notifier { - this.type = type - return this - } - - @PomDsl - fun address(address: String): Notifier { - this.address = address - return this - } - - @PomDsl - fun sendOnError(sendOnError: Boolean = true): Notifier { - this.isSendOnError = sendOnError - return this - } - - @PomDsl - fun sendOnFailure(sendOnFailure: Boolean = true): Notifier { - this.isSendOnFailure = sendOnFailure - return this - } - - @PomDsl - fun sendOnSuccess(sendOnSuccess: Boolean = true): Notifier { - this.isSendOnSuccess = sendOnSuccess - return this - } - - @PomDsl - fun sendOnWarning(sendOnWarning: Boolean = true): Notifier { - this.isSendOnWarning = sendOnWarning - return this - } - - @PomDsl - fun configuration(block: Properties.(Properties) -> Unit) { - val properties = Properties() - block.invoke(properties, properties) - this.configuration = propertiesFactory().apply { - putAll(properties.entries()) - } - } - - override fun clone(): org.apache.maven.model.Notifier { - return super.clone() - } + @PomDsl + fun type(type: String): Notifier { + this.type = type + return this + } + + @PomDsl + fun address(address: String): Notifier { + this.address = address + return this + } + + @PomDsl + fun sendOnError(sendOnError: Boolean = true): Notifier { + this.isSendOnError = sendOnError + return this + } + + @PomDsl + fun sendOnFailure(sendOnFailure: Boolean = true): Notifier { + this.isSendOnFailure = sendOnFailure + return this + } + + @PomDsl + fun sendOnSuccess(sendOnSuccess: Boolean = true): Notifier { + this.isSendOnSuccess = sendOnSuccess + return this + } + + @PomDsl + fun sendOnWarning(sendOnWarning: Boolean = true): Notifier { + this.isSendOnWarning = sendOnWarning + return this + } + + @PomDsl + fun configuration(block: Properties.(Properties) -> Unit) { + val properties = Properties() + block.invoke(properties, properties) + this.configuration = propertiesFactory().apply { putAll(properties.entries()) } + } + + override fun clone(): org.apache.maven.model.Notifier { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/NotifierList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/NotifierList.kt index cfedb898..aa1518b0 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/NotifierList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/NotifierList.kt @@ -3,17 +3,15 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class NotifierList : ArrayList(), Cloneable { - /** - * Provides a callback for defining a new notifier entry. - */ - @PomDsl - fun notifier(block: Notifier.(Notifier) -> Unit) { - val notifier = Notifier() - block(notifier, notifier) - add(notifier) - } + /** Provides a callback for defining a new notifier entry. */ + @PomDsl + fun notifier(block: Notifier.(Notifier) -> Unit) { + val notifier = Notifier() + block(notifier, notifier) + add(notifier) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Organization.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Organization.kt index 58b82b1d..9641f395 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Organization.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Organization.kt @@ -3,19 +3,19 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Organization : org.apache.maven.model.Organization(), Cloneable { - @PomDsl - fun name(name: String): Organization { - this.name = name - return this - } + @PomDsl + fun name(name: String): Organization { + this.name = name + return this + } - @PomDsl - fun url(url: String): Organization { - this.url = url - return this - } + @PomDsl + fun url(url: String): Organization { + this.url = url + return this + } - override fun clone(): org.apache.maven.model.Organization { - return super.clone() - } + override fun clone(): org.apache.maven.model.Organization { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Parent.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Parent.kt index b62fa071..482f1d23 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Parent.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Parent.kt @@ -3,35 +3,35 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Parent : org.apache.maven.model.Parent(), Cloneable { - init { - relativePath = "../pom.kts" - } + init { + relativePath = "../pom.kts" + } - @PomDsl - fun groupId(groupId: String): Parent { - this.groupId = groupId - return this - } + @PomDsl + fun groupId(groupId: String): Parent { + this.groupId = groupId + return this + } - @PomDsl - fun artifactId(artifactId: String): Parent { - this.artifactId = artifactId - return this - } + @PomDsl + fun artifactId(artifactId: String): Parent { + this.artifactId = artifactId + return this + } - @PomDsl - fun version(version: String): Parent { - this.version = version - return this - } + @PomDsl + fun version(version: String): Parent { + this.version = version + return this + } - @PomDsl - infix fun relativePath(relativePath: String): Parent { - this.relativePath = relativePath - return this - } + @PomDsl + infix fun relativePath(relativePath: String): Parent { + this.relativePath = relativePath + return this + } - override fun clone(): org.apache.maven.model.Parent { - return super.clone() - } + override fun clone(): org.apache.maven.model.Parent { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Plugin.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Plugin.kt index 76a0ae2b..36473334 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Plugin.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Plugin.kt @@ -6,139 +6,150 @@ import org.codehaus.plexus.util.xml.Xpp3DomBuilder @PomDsl class Plugin : org.apache.maven.model.Plugin(), Cloneable { - //-- Initialization ----------------------------------------------------------------------------------------------// + // -- Initialization + // ----------------------------------------------------------------------------------------------// - private val _executions: PluginExecutionList - get() { - return executions as PluginExecutionList - } - - private val _dependencies: DependencyList - get() { - return dependencies as DependencyList - } - - init { - this.executions = PluginExecutionList() - this.dependencies = DependencyList() - } - - @PomDsl - fun groupId(groupId: String): Plugin { - this.groupId = groupId - return this - } - - @PomDsl - fun artifactId(artifactId: String): Plugin { - this.artifactId = artifactId - return this + private val _executions: PluginExecutionList + get() { + return executions as PluginExecutionList } - @PomDsl - fun version(version: String): Plugin { - this.version = version - return this - } - - @PomDsl - fun extensions(extensions: Boolean = true): Plugin { - this.extensions = extensions.toString() - return this - } - - @PomDsl - fun inherited(inherited: Boolean = true): Plugin { - this.isInherited = inherited - return this - } - - //-- Block Functions ---------------------------------------------------------------------------------------------// - - @PomDsl - fun executions(block: PluginExecutionList.(PluginExecutionList) -> Unit) { - block.invoke(_executions, _executions) + private val _dependencies: DependencyList + get() { + return dependencies as DependencyList } - @PomDsl - fun dependencies(block: DependencyList.(DependencyList) -> Unit) { - block(_dependencies, _dependencies) - } - - //-- Plugin Dependency Helpers -----------------------------------------------------------------------------------// - - @PomDsl - fun dependency(gavtc: String? = null, block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return _dependencies.dependency(gavtc, block) - } - - @PomDsl - fun dependency(groupId: String, - artifactId: String, - version: String? = null, - type: String = "jar", - classifier: String? = null, - optional: Boolean? = null, - scope: String? = null, - systemPath: String? = null, - block: (Dependency.(Dependency) -> Unit)? = null): Dependency { - return _dependencies.dependency(groupId, artifactId, version, type, classifier, optional, scope, systemPath, block) - } - - //-- Plugin Execution Helpers ------------------------------------------------------------------------------------// - - @PomDsl - fun execution(id: String? = "default", - phase: String? = null, - goals: List? = null, - priority: Int = 0, - inherited: Boolean? = null, - configuration: Xpp3Dom? = null, - block: (PluginExecution.(PluginExecution) -> Unit)? = null): PluginExecution { - return _executions.execution(id, phase, goals, priority, inherited, configuration, block) - } - - //-- Configuration Helpers ---------------------------------------------------------------------------------------// - - /** - * Sets the plugin configuration. - * - * @param source the configuration source as a [String] of XML - */ - @PomDsl - fun configuration(source: String): Xpp3Dom { - this.configuration = source - return this.configuration as Xpp3Dom - } - - @PomDsl - fun configuration(block: XmlNode.(XmlNode) -> Unit) { - val configuration = XmlNode("configuration") - block(configuration, configuration) - this.configuration = configuration.xpp3Dom - } - - /** - * Sets the configuration. - */ - override fun setConfiguration(source: Any?) { - val name = "configuration" - val xpp3Dom = - when (source) { - null -> null - is Xpp3Dom -> source - else -> Xpp3DomBuilder.build(source.toString().reader()) - } - if (xpp3Dom != null && xpp3Dom.name != name) { - val configuration = Xpp3Dom(name) - configuration.addChild(xpp3Dom) - super.setConfiguration(configuration) - } else { - super.setConfiguration(xpp3Dom) + init { + this.executions = PluginExecutionList() + this.dependencies = DependencyList() + } + + @PomDsl + fun groupId(groupId: String): Plugin { + this.groupId = groupId + return this + } + + @PomDsl + fun artifactId(artifactId: String): Plugin { + this.artifactId = artifactId + return this + } + + @PomDsl + fun version(version: String): Plugin { + this.version = version + return this + } + + @PomDsl + fun extensions(extensions: Boolean = true): Plugin { + this.extensions = extensions.toString() + return this + } + + @PomDsl + fun inherited(inherited: Boolean = true): Plugin { + this.isInherited = inherited + return this + } + + // -- Block Functions + // ---------------------------------------------------------------------------------------------// + + @PomDsl + fun executions(block: PluginExecutionList.(PluginExecutionList) -> Unit) { + block.invoke(_executions, _executions) + } + + @PomDsl + fun dependencies(block: DependencyList.(DependencyList) -> Unit) { + block(_dependencies, _dependencies) + } + + // -- Plugin Dependency Helpers + // -----------------------------------------------------------------------------------// + + @PomDsl + fun dependency( + gavtc: String? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return _dependencies.dependency(gavtc, block) + } + + @PomDsl + fun dependency( + groupId: String, + artifactId: String, + version: String? = null, + type: String = "jar", + classifier: String? = null, + optional: Boolean? = null, + scope: String? = null, + systemPath: String? = null, + block: (Dependency.(Dependency) -> Unit)? = null + ): Dependency { + return _dependencies.dependency( + groupId, artifactId, version, type, classifier, optional, scope, systemPath, block) + } + + // -- Plugin Execution Helpers + // ------------------------------------------------------------------------------------// + + @PomDsl + fun execution( + id: String? = "default", + phase: String? = null, + goals: List? = null, + priority: Int = 0, + inherited: Boolean? = null, + configuration: Xpp3Dom? = null, + block: (PluginExecution.(PluginExecution) -> Unit)? = null + ): PluginExecution { + return _executions.execution(id, phase, goals, priority, inherited, configuration, block) + } + + // -- Configuration Helpers + // ---------------------------------------------------------------------------------------// + + /** + * Sets the plugin configuration. + * + * @param source the configuration source as a [String] of XML + */ + @PomDsl + fun configuration(source: String): Xpp3Dom { + this.configuration = source + return this.configuration as Xpp3Dom + } + + @PomDsl + fun configuration(block: XmlNode.(XmlNode) -> Unit) { + val configuration = XmlNode("configuration") + block(configuration, configuration) + this.configuration = configuration.xpp3Dom + } + + /** Sets the configuration. */ + override fun setConfiguration(source: Any?) { + val name = "configuration" + val xpp3Dom = + when (source) { + null -> null + is Xpp3Dom -> source + else -> Xpp3DomBuilder.build(source.toString().reader()) } + if (xpp3Dom != null && xpp3Dom.name != name) { + val configuration = Xpp3Dom(name) + configuration.addChild(xpp3Dom) + super.setConfiguration(configuration) + } else { + super.setConfiguration(xpp3Dom) } + } - override fun clone(): org.apache.maven.model.Plugin { - return super.clone() - } + override fun clone(): org.apache.maven.model.Plugin { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginExecution.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginExecution.kt index 4ef1cbb3..f640ed20 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginExecution.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginExecution.kt @@ -6,71 +6,70 @@ import org.codehaus.plexus.util.xml.Xpp3DomBuilder @PomDsl class PluginExecution : org.apache.maven.model.PluginExecution(), Cloneable { - @PomDsl - fun id(id: String): PluginExecution { - this.id = id - return this - } + @PomDsl + fun id(id: String): PluginExecution { + this.id = id + return this + } - @PomDsl - fun phase(phase: String): PluginExecution { - this.phase = phase - return this - } + @PomDsl + fun phase(phase: String): PluginExecution { + this.phase = phase + return this + } - @PomDsl - fun goals(vararg goals: String): PluginExecution { - this.goals = goals.asList() - return this - } + @PomDsl + fun goals(vararg goals: String): PluginExecution { + this.goals = goals.asList() + return this + } - @PomDsl - fun inherited(inherited: Boolean = true): PluginExecution { - this.isInherited = inherited - return this - } + @PomDsl + fun inherited(inherited: Boolean = true): PluginExecution { + this.isInherited = inherited + return this + } - //-- Configuration Helpers ---------------------------------------------------------------------------------------// + // -- Configuration Helpers + // ---------------------------------------------------------------------------------------// - /** - * Sets the plugin configuration. - * - * @param source the configuration source as a [String] of XML - */ - @PomDsl - fun configuration(source: String): Xpp3Dom { - this.configuration = source - return this.configuration as Xpp3Dom - } + /** + * Sets the plugin configuration. + * + * @param source the configuration source as a [String] of XML + */ + @PomDsl + fun configuration(source: String): Xpp3Dom { + this.configuration = source + return this.configuration as Xpp3Dom + } - @PomDsl - fun configuration(block: XmlNode.(XmlNode) -> Unit) { - val configuration = XmlNode("configuration") - block(configuration, configuration) - this.configuration = configuration.xpp3Dom - } + @PomDsl + fun configuration(block: XmlNode.(XmlNode) -> Unit) { + val configuration = XmlNode("configuration") + block(configuration, configuration) + this.configuration = configuration.xpp3Dom + } - /** - * Sets the configuration. - */ - override fun setConfiguration(source: Any?) { - val name = "configuration" - val xpp3Dom = - when (source) { - null -> null - is Xpp3Dom -> source - else -> Xpp3DomBuilder.build(source.toString().reader()) - } - if (xpp3Dom != null && xpp3Dom.name != name) { - val configuration = Xpp3Dom(name) - configuration.addChild(xpp3Dom) - super.setConfiguration(configuration) - } else { - super.setConfiguration(xpp3Dom) + /** Sets the configuration. */ + override fun setConfiguration(source: Any?) { + val name = "configuration" + val xpp3Dom = + when (source) { + null -> null + is Xpp3Dom -> source + else -> Xpp3DomBuilder.build(source.toString().reader()) } + if (xpp3Dom != null && xpp3Dom.name != name) { + val configuration = Xpp3Dom(name) + configuration.addChild(xpp3Dom) + super.setConfiguration(configuration) + } else { + super.setConfiguration(xpp3Dom) } + } - override fun clone(): org.apache.maven.model.PluginExecution { - return super.clone() - } + override fun clone(): org.apache.maven.model.PluginExecution { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginExecutionList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginExecutionList.kt index db7447d1..49e63676 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginExecutionList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginExecutionList.kt @@ -5,30 +5,30 @@ import org.codehaus.plexus.util.xml.Xpp3Dom @PomDsl class PluginExecutionList : ArrayList(), Cloneable { - /** - * Defines a new plugin execution. - */ - @PomDsl - fun execution(id: String? = "default", - phase: String? = null, - goals: List? = null, - priority: Int = 0, - inherited: Boolean? = null, - configuration: Xpp3Dom? = null, - block: (PluginExecution.(PluginExecution) -> Unit)? = null): PluginExecution { - return PluginExecution().apply { - this.id = id - this.phase = phase - this.priority = priority - if (inherited != null) this.isInherited = inherited - this.goals = goals - this.configuration = configuration - this@PluginExecutionList.add(this) - block?.invoke(this, this) - } + /** Defines a new plugin execution. */ + @PomDsl + fun execution( + id: String? = "default", + phase: String? = null, + goals: List? = null, + priority: Int = 0, + inherited: Boolean? = null, + configuration: Xpp3Dom? = null, + block: (PluginExecution.(PluginExecution) -> Unit)? = null + ): PluginExecution { + return PluginExecution().apply { + this.id = id + this.phase = phase + this.priority = priority + if (inherited != null) this.isInherited = inherited + this.goals = goals + this.configuration = configuration + this@PluginExecutionList.add(this) + block?.invoke(this, this) } + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginList.kt index 3d9674e8..66f80982 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginList.kt @@ -3,22 +3,20 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class PluginList : ArrayList(), Cloneable { - /** - * Provides a callback for defining a new build plugin. - */ - @PomDsl - fun plugin(gav: String? = null, block: (Plugin.(Plugin) -> Unit)? = null): Plugin { - val (groupId, artifactId, version) = splitCoordinates(gav, 3) - return Plugin().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version - this@PluginList.add(this) - block?.invoke(this, this) - } + /** Provides a callback for defining a new build plugin. */ + @PomDsl + fun plugin(gav: String? = null, block: (Plugin.(Plugin) -> Unit)? = null): Plugin { + val (groupId, artifactId, version) = splitCoordinates(gav, 3) + return Plugin().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version + this@PluginList.add(this) + block?.invoke(this, this) } + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginManagement.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginManagement.kt index 82d00ae1..c431211a 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginManagement.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginManagement.kt @@ -3,14 +3,14 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class PluginManagement : org.apache.maven.model.PluginManagement(), Cloneable { - @PomDsl - fun plugins(block: PluginList.(PluginList) -> Unit) { - val plugins = PluginList() - block.invoke(plugins, plugins) - this.plugins = plugins - } + @PomDsl + fun plugins(block: PluginList.(PluginList) -> Unit) { + val plugins = PluginList() + block.invoke(plugins, plugins) + this.plugins = plugins + } - override fun clone(): org.apache.maven.model.PluginManagement { - return super.clone() - } + override fun clone(): org.apache.maven.model.PluginManagement { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginRepositoryList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginRepositoryList.kt index 4a5634ab..eaf2618a 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginRepositoryList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PluginRepositoryList.kt @@ -3,17 +3,18 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class PluginRepositoryList : ArrayList(), Cloneable { - @PomDsl - fun pluginRepository(nameOrId: String? = null, block: Repository.(Repository) -> Unit) { - val repository = Repository().apply { - this.id = nameOrId - this.name = nameOrId + @PomDsl + fun pluginRepository(nameOrId: String? = null, block: Repository.(Repository) -> Unit) { + val repository = + Repository().apply { + this.id = nameOrId + this.name = nameOrId } - block.invoke(repository, repository) - add(repository) - } + block.invoke(repository, repository) + add(repository) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PomDsl.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PomDsl.kt index 1414c3fb..563c3b1c 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PomDsl.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/PomDsl.kt @@ -1,5 +1,3 @@ package org.sonatype.maven.polyglot.kotlin.dsl -@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -@DslMarker -annotation class PomDsl +@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) @DslMarker annotation class PomDsl diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Prerequisites.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Prerequisites.kt index 29e05eff..b23f36ba 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Prerequisites.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Prerequisites.kt @@ -3,12 +3,12 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Prerequisites : org.apache.maven.model.Prerequisites(), Cloneable { - @PomDsl - fun maven(mavenVersion: String) { - this.maven = mavenVersion - } + @PomDsl + fun maven(mavenVersion: String) { + this.maven = mavenVersion + } - override fun clone(): org.apache.maven.model.Prerequisites { - return super.clone() - } + override fun clone(): org.apache.maven.model.Prerequisites { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Profile.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Profile.kt index 14ddfd04..2cb21edf 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Profile.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Profile.kt @@ -6,123 +6,120 @@ import org.codehaus.plexus.util.xml.Xpp3DomBuilder @PomDsl class Profile : org.apache.maven.model.Profile(), Cloneable { - @PomDsl - fun id(id: String): Profile { - this.id = id - return this - } - - @PomDsl - fun activation(block: Activation.(Activation) -> Unit) { - val activation = Activation() - block(activation, activation) - this.activation = activation - } - - @PomDsl - fun build(block: Build.(Build) -> Unit) { - val build = Build() - block(build, build) - this.build = build - } - - @PomDsl - fun dependencies(block: DependencyList.(DependencyList) -> Unit) { - val dependencies = DependencyList() - block(dependencies, dependencies) - this.dependencies = dependencies - } - - @PomDsl - fun dependencyManagement(block: DependencyManagement.(DependencyManagement) -> Unit) { - val dependencyManagement = DependencyManagement() - block(dependencyManagement, dependencyManagement) - this.dependencyManagement = dependencyManagement - } - - @PomDsl - fun distributionManagement(block: DistributionManagement.(DistributionManagement) -> Unit) { - val distributionManagement = DistributionManagement() - block.invoke(distributionManagement, distributionManagement) - this.distributionManagement = distributionManagement - } - - @PomDsl - fun modules(vararg modules: String) { - this.modules = modules.asList() - } - - @PomDsl - fun pluginRepositories(block: PluginRepositoryList.(PluginRepositoryList) -> Unit) { - val pluginRepositories = PluginRepositoryList() - block.invoke(pluginRepositories, pluginRepositories) - this.pluginRepositories = pluginRepositories - } - - @PomDsl - fun properties(block: Properties.(Properties) -> Unit) { - val properties = Properties() - block.invoke(properties, properties) - this.properties = propertiesFactory().apply { - putAll(properties.entries()) - } - } - - @PomDsl - fun repositories(block: RepositoryList.(RepositoryList) -> Unit) { - val repositories = RepositoryList() - block.invoke(repositories, repositories) - this.repositories = repositories - } - - @PomDsl - fun reporting(block: Reporting.(Reporting) -> Unit) { - val reporting = Reporting() - block(reporting, reporting) - this.reporting = reporting - } - - //-- Configuration Helpers ---------------------------------------------------------------------------------------// - - /** - * Sets the reports content. - * - * @param source the reports source as a [String] of XML - */ - @PomDsl - fun reports(source: String): Xpp3Dom { - this.reports = source - return this.reports as Xpp3Dom - } - - @PomDsl - fun reports(block: XmlNode.(XmlNode) -> Unit) { - val reports = XmlNode("reports") - block(reports, reports) - this.reports = reports.xpp3Dom - } - - /** - * Sets the reports. - */ - override fun setReports(source: Any?) { - val name = "reports" - val xpp3Dom = - when (source) { - null -> null - is Xpp3Dom -> source - else -> Xpp3DomBuilder.build(source.toString().reader()) - } - if (xpp3Dom != null && xpp3Dom.name != name) { - val configuration = Xpp3Dom(name) - configuration.addChild(xpp3Dom) - super.setReports(configuration) - } else { - super.setReports(xpp3Dom) + @PomDsl + fun id(id: String): Profile { + this.id = id + return this + } + + @PomDsl + fun activation(block: Activation.(Activation) -> Unit) { + val activation = Activation() + block(activation, activation) + this.activation = activation + } + + @PomDsl + fun build(block: Build.(Build) -> Unit) { + val build = Build() + block(build, build) + this.build = build + } + + @PomDsl + fun dependencies(block: DependencyList.(DependencyList) -> Unit) { + val dependencies = DependencyList() + block(dependencies, dependencies) + this.dependencies = dependencies + } + + @PomDsl + fun dependencyManagement(block: DependencyManagement.(DependencyManagement) -> Unit) { + val dependencyManagement = DependencyManagement() + block(dependencyManagement, dependencyManagement) + this.dependencyManagement = dependencyManagement + } + + @PomDsl + fun distributionManagement(block: DistributionManagement.(DistributionManagement) -> Unit) { + val distributionManagement = DistributionManagement() + block.invoke(distributionManagement, distributionManagement) + this.distributionManagement = distributionManagement + } + + @PomDsl + fun modules(vararg modules: String) { + this.modules = modules.asList() + } + + @PomDsl + fun pluginRepositories(block: PluginRepositoryList.(PluginRepositoryList) -> Unit) { + val pluginRepositories = PluginRepositoryList() + block.invoke(pluginRepositories, pluginRepositories) + this.pluginRepositories = pluginRepositories + } + + @PomDsl + fun properties(block: Properties.(Properties) -> Unit) { + val properties = Properties() + block.invoke(properties, properties) + this.properties = propertiesFactory().apply { putAll(properties.entries()) } + } + + @PomDsl + fun repositories(block: RepositoryList.(RepositoryList) -> Unit) { + val repositories = RepositoryList() + block.invoke(repositories, repositories) + this.repositories = repositories + } + + @PomDsl + fun reporting(block: Reporting.(Reporting) -> Unit) { + val reporting = Reporting() + block(reporting, reporting) + this.reporting = reporting + } + + // -- Configuration Helpers + // ---------------------------------------------------------------------------------------// + + /** + * Sets the reports content. + * + * @param source the reports source as a [String] of XML + */ + @PomDsl + fun reports(source: String): Xpp3Dom { + this.reports = source + return this.reports as Xpp3Dom + } + + @PomDsl + fun reports(block: XmlNode.(XmlNode) -> Unit) { + val reports = XmlNode("reports") + block(reports, reports) + this.reports = reports.xpp3Dom + } + + /** Sets the reports. */ + override fun setReports(source: Any?) { + val name = "reports" + val xpp3Dom = + when (source) { + null -> null + is Xpp3Dom -> source + else -> Xpp3DomBuilder.build(source.toString().reader()) } + if (xpp3Dom != null && xpp3Dom.name != name) { + val configuration = Xpp3Dom(name) + configuration.addChild(xpp3Dom) + super.setReports(configuration) + } else { + super.setReports(xpp3Dom) } + } - override fun clone(): org.apache.maven.model.Profile { - return super.clone() - } + override fun clone(): org.apache.maven.model.Profile { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ProfileList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ProfileList.kt index a27f0c35..3483f32a 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ProfileList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ProfileList.kt @@ -3,19 +3,15 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ProfileList : ArrayList(), Cloneable { - /** - * Provides a callback for defining a new dependency exclusion. - */ - @PomDsl - fun profile(id: String? = null, block: Profile.(Profile) -> Unit) { - val profile = Profile().apply { - this.id = id - } - block.invoke(profile, profile) - add(profile) - } + /** Provides a callback for defining a new dependency exclusion. */ + @PomDsl + fun profile(id: String? = null, block: Profile.(Profile) -> Unit) { + val profile = Profile().apply { this.id = id } + block.invoke(profile, profile) + add(profile) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Project.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Project.kt index a68c975a..56162867 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Project.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Project.kt @@ -1,400 +1,431 @@ package org.sonatype.maven.polyglot.kotlin.dsl +import java.io.File import org.codehaus.plexus.util.xml.Xpp3Dom import org.codehaus.plexus.util.xml.Xpp3DomBuilder import org.sonatype.maven.polyglot.execute.ExecuteTask -import java.io.File @PomDsl class Project(pom: File) : org.apache.maven.model.Model(), Cloneable { - init { - this.pomFile = pom - this.modelVersion = "4.0.0" - this.modelEncoding = "UTF-8" - } - - val tasks: MutableList - get() { - val bld = build - if (bld != null && bld is ProjectBuild) { - return bld.tasks - } - return mutableListOf() - } - - //-- Project Model Version ---------------------------------------------------------------------------------------// - - @PomDsl - fun modelVersion(modelVersion: String) { - this.modelVersion = modelVersion - } - - //-- Project Directory -------------------------------------------------------------------------------------------// - - @PomDsl - override fun getProjectDirectory(): File? { - return super.getProjectDirectory() - } - - //-- Project ID --------------------------------------------------------------------------------------------------// - - /** - * @param gavp a string in the form groupId:artifactId:version[:packaging] - */ - @PomDsl - fun id(gavp: String) { - val (groupId, artifactId, version, packaging) = splitCoordinates(gavp, 4) - this.id(groupId, artifactId, version, packaging) - } - - @PomDsl - fun id(groupId: String? = null, - artifactId: String? = null, - version: String? = null, - packaging: String? = null) { - this.groupId = groupId - this.artifactId = artifactId - this.version = version - if (packaging != null) this.packaging = packaging - } - - fun setId(gavp: String) { - id(gavp) - } - - //-- Parent POM --------------------------------------------------------------------------------------------------// - - @PomDsl - fun parent(block: Parent.(Parent) -> Unit) { - val parent = Parent() - block.invoke(parent, parent) - this.parent = parent - } - - @PomDsl - fun parent(gav: String, - relativePath: String? = null): Parent { - val (groupId, artifactId, version) = splitCoordinates(gav, 3) - return Parent().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version - if (relativePath !== null) this.relativePath = relativePath - this@Project.parent = this - } - } - - @PomDsl - fun parent(groupId: String, - artifactId: String, - version: String, - relativePath: String? = null): Parent { - return Parent().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version - if (relativePath !== null) this.relativePath = relativePath - this@Project.parent = this - } - } - - //-- Project Artifact ID -----------------------------------------------------------------------------------------// - - @PomDsl - fun artifactId(artifactId: String) { - this.artifactId = artifactId - } - - //-- Project Group ID --------------------------------------------------------------------------------------------// - - @PomDsl - fun groupId(groupId: String) { - this.groupId = groupId - } - - //-- Project Version ---------------------------------------------------------------------------------------------// - - @PomDsl - fun version(version: String) { - this.version = version - } - - //-- Project Packaging -------------------------------------------------------------------------------------------// - - @PomDsl - fun packaging(packaging: String) { - this.packaging = packaging - } - - //-- Project Name ------------------------------------------------------------------------------------------------// - - @PomDsl - fun name(name: String) { - this.name = name - } - - //-- Project Description -----------------------------------------------------------------------------------------// - - @PomDsl - fun description(description: String) { - this.description = description - } - - //-- Project URL -------------------------------------------------------------------------------------------------// - - @PomDsl - fun url(url: String) { - this.url = url - } - - //-- Project Inception Year --------------------------------------------------------------------------------------// - - @PomDsl - fun inceptionYear(inceptionYear: String) { - this.inceptionYear = inceptionYear - } - - @PomDsl - fun inceptionYear(inceptionYear: Int) { - this.inceptionYear = inceptionYear.toString() - } - - //-- Organization ------------------------------------------------------------------------------------------------// - - @PomDsl - fun organization(block: Organization.(Organization) -> Unit) { - val organization = Organization() - block.invoke(organization, organization) - this.organization = organization - } - - @PomDsl - fun organization(name: String?, url: String?): Organization { - return Organization().apply { - this.name = name - this.url = url - this@Project.organization = this - } - } - - //-- Licenses ----------------------------------------------------------------------------------------------------// - - @PomDsl - fun licenses(block: LicenseList.(LicenseList) -> Unit) { - val licenses = LicenseList() - block.invoke(licenses, licenses) - this.licenses = licenses - } - - @PomDsl - fun license(name: String, - url: String, - distribution: String = "repo", - comments: String? = null): License { - return License().apply { - this.name = name - this.url = url - this.distribution = distribution - this.comments = comments - this@Project.addLicense(this) + init { + this.pomFile = pom + this.modelVersion = "4.0.0" + this.modelEncoding = "UTF-8" + } + + val tasks: MutableList + get() { + val bld = build + if (bld != null && bld is ProjectBuild) { + return bld.tasks + } + return mutableListOf() + } + + // -- Project Model Version + // ---------------------------------------------------------------------------------------// + + @PomDsl + fun modelVersion(modelVersion: String) { + this.modelVersion = modelVersion + } + + // -- Project Directory + // -------------------------------------------------------------------------------------------// + + @PomDsl + override fun getProjectDirectory(): File? { + return super.getProjectDirectory() + } + + // -- Project ID + // --------------------------------------------------------------------------------------------------// + + /** @param gavp a string in the form groupId:artifactId:version[:packaging] */ + @PomDsl + fun id(gavp: String) { + val (groupId, artifactId, version, packaging) = splitCoordinates(gavp, 4) + this.id(groupId, artifactId, version, packaging) + } + + @PomDsl + fun id( + groupId: String? = null, + artifactId: String? = null, + version: String? = null, + packaging: String? = null + ) { + this.groupId = groupId + this.artifactId = artifactId + this.version = version + if (packaging != null) this.packaging = packaging + } + + fun setId(gavp: String) { + id(gavp) + } + + // -- Parent POM + // --------------------------------------------------------------------------------------------------// + + @PomDsl + fun parent(block: Parent.(Parent) -> Unit) { + val parent = Parent() + block.invoke(parent, parent) + this.parent = parent + } + + @PomDsl + fun parent(gav: String, relativePath: String? = null): Parent { + val (groupId, artifactId, version) = splitCoordinates(gav, 3) + return Parent().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version + if (relativePath !== null) this.relativePath = relativePath + this@Project.parent = this + } + } + + @PomDsl + fun parent( + groupId: String, + artifactId: String, + version: String, + relativePath: String? = null + ): Parent { + return Parent().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version + if (relativePath !== null) this.relativePath = relativePath + this@Project.parent = this + } + } + + // -- Project Artifact ID + // -----------------------------------------------------------------------------------------// + + @PomDsl + fun artifactId(artifactId: String) { + this.artifactId = artifactId + } + + // -- Project Group ID + // --------------------------------------------------------------------------------------------// + + @PomDsl + fun groupId(groupId: String) { + this.groupId = groupId + } + + // -- Project Version + // ---------------------------------------------------------------------------------------------// + + @PomDsl + fun version(version: String) { + this.version = version + } + + // -- Project Packaging + // -------------------------------------------------------------------------------------------// + + @PomDsl + fun packaging(packaging: String) { + this.packaging = packaging + } + + // -- Project Name + // ------------------------------------------------------------------------------------------------// + + @PomDsl + fun name(name: String) { + this.name = name + } + + // -- Project Description + // -----------------------------------------------------------------------------------------// + + @PomDsl + fun description(description: String) { + this.description = description + } + + // -- Project URL + // -------------------------------------------------------------------------------------------------// + + @PomDsl + fun url(url: String) { + this.url = url + } + + // -- Project Inception Year + // --------------------------------------------------------------------------------------// + + @PomDsl + fun inceptionYear(inceptionYear: String) { + this.inceptionYear = inceptionYear + } + + @PomDsl + fun inceptionYear(inceptionYear: Int) { + this.inceptionYear = inceptionYear.toString() + } + + // -- Organization + // ------------------------------------------------------------------------------------------------// + + @PomDsl + fun organization(block: Organization.(Organization) -> Unit) { + val organization = Organization() + block.invoke(organization, organization) + this.organization = organization + } + + @PomDsl + fun organization(name: String?, url: String?): Organization { + return Organization().apply { + this.name = name + this.url = url + this@Project.organization = this + } + } + + // -- Licenses + // ----------------------------------------------------------------------------------------------------// + + @PomDsl + fun licenses(block: LicenseList.(LicenseList) -> Unit) { + val licenses = LicenseList() + block.invoke(licenses, licenses) + this.licenses = licenses + } + + @PomDsl + fun license( + name: String, + url: String, + distribution: String = "repo", + comments: String? = null + ): License { + return License().apply { + this.name = name + this.url = url + this.distribution = distribution + this.comments = comments + this@Project.addLicense(this) + } + } + + // -- Developers + // --------------------------------------------------------------------------------------------------// + + @PomDsl + fun developers(block: DeveloperList.(DeveloperList) -> Unit) { + val developers = DeveloperList() + block.invoke(developers, developers) + this.developers = developers + } + + // -- Contributors + // ------------------------------------------------------------------------------------------------// + + @PomDsl + fun contributors(block: ContributorList.(ContributorList) -> Unit) { + val contributors = ContributorList() + block.invoke(contributors, contributors) + this.contributors = contributors + } + + // -- Mailing Lists + // -----------------------------------------------------------------------------------------------// + + @PomDsl + fun mailingLists(block: MailingListList.(MailingListList) -> Unit) { + val mailingLists = MailingListList() + block.invoke(mailingLists, mailingLists) + this.mailingLists = mailingLists + } + + // -- Prerequisites + // -----------------------------------------------------------------------------------------------// + + @PomDsl + fun prerequisites(block: Prerequisites.(Prerequisites) -> Unit) { + val prerequisites = Prerequisites() + block.invoke(prerequisites, prerequisites) + this.prerequisites = prerequisites + } + + // -- Modules + // -----------------------------------------------------------------------------------------------------// + + @PomDsl + fun modules(vararg modules: String) { + this.modules = modules.asList() + } + + // -- SCM + // ---------------------------------------------------------------------------------------------------------// + + @PomDsl + fun scm(block: Scm.(Scm) -> Unit) { + val scm = Scm() + block.invoke(scm, scm) + this.scm = scm + } + + // -- Issue Management + // --------------------------------------------------------------------------------------------// + + @PomDsl + fun issueManagement(block: IssueManagement.(IssueManagement) -> Unit) { + val issueManagement = IssueManagement() + block.invoke(issueManagement, issueManagement) + this.issueManagement = issueManagement + } + + // -- CI Management + // -----------------------------------------------------------------------------------------------// + + @PomDsl + fun ciManagement(block: CiManagement.(CiManagement) -> Unit) { + val ciManagement = CiManagement() + block.invoke(ciManagement, ciManagement) + this.ciManagement = ciManagement + } + + // -- Distribution Management + // -------------------------------------------------------------------------------------// + + @PomDsl + fun distributionManagement(block: DistributionManagement.(DistributionManagement) -> Unit) { + val distributionManagement = DistributionManagement() + block.invoke(distributionManagement, distributionManagement) + this.distributionManagement = distributionManagement + } + + // -- Properties + // --------------------------------------------------------------------------------------------------// + + @PomDsl + fun properties(block: Properties.(Properties) -> Unit) { + val properties = Properties() + block.invoke(properties, properties) + this.properties = propertiesFactory().apply { putAll(properties.entries()) } + } + + // -- Dependency Management + // ---------------------------------------------------------------------------------------// + + @PomDsl + fun dependencyManagement(block: DependencyManagement.(DependencyManagement) -> Unit) { + val dependencyManagement = DependencyManagement() + block(dependencyManagement, dependencyManagement) + this.dependencyManagement = dependencyManagement + } + + // -- Dependencies + // ------------------------------------------------------------------------------------------------// + + @PomDsl + fun dependencies(block: DependencyList.(DependencyList) -> Unit) { + val dependencies = DependencyList() + block(dependencies, dependencies) + this.dependencies = dependencies + } + + // -- Repositories + // ------------------------------------------------------------------------------------------------// + + @PomDsl + fun repositories(block: RepositoryList.(RepositoryList) -> Unit) { + val repositories = RepositoryList() + block.invoke(repositories, repositories) + this.repositories = repositories + } + + // -- Plugin Repositories + // -----------------------------------------------------------------------------------------// + + @PomDsl + fun pluginRepositories(block: PluginRepositoryList.(PluginRepositoryList) -> Unit) { + val pluginRepositories = PluginRepositoryList() + block.invoke(pluginRepositories, pluginRepositories) + this.pluginRepositories = pluginRepositories + } + + // -- Build + // -------------------------------------------------------------------------------------------------------// + + @PomDsl + fun build(block: ProjectBuild.(ProjectBuild) -> Unit) { + val build = ProjectBuild() + block(build, build) + setBuild(build) + } + + // -- Reports + // -----------------------------------------------------------------------------------------------------// + + /** + * Sets the reports content. + * + * @param source the reports source as a [String] of XML + */ + @PomDsl + fun reports(source: String): Xpp3Dom { + this.reports = source + return this.reports as Xpp3Dom + } + + @PomDsl + fun reports(block: XmlNode.(XmlNode) -> Unit) { + val reports = XmlNode("reports") + block(reports, reports) + this.reports = reports.xpp3Dom + } + + /** Sets the reports. */ + override fun setReports(source: Any?) { + val name = "reports" + val xpp3Dom = + when (source) { + null -> null + is Xpp3Dom -> source + else -> Xpp3DomBuilder.build(source.toString().reader()) } - } - - //-- Developers --------------------------------------------------------------------------------------------------// - - @PomDsl - fun developers(block: DeveloperList.(DeveloperList) -> Unit) { - val developers = DeveloperList() - block.invoke(developers, developers) - this.developers = developers - } - - //-- Contributors ------------------------------------------------------------------------------------------------// - - @PomDsl - fun contributors(block: ContributorList.(ContributorList) -> Unit) { - val contributors = ContributorList() - block.invoke(contributors, contributors) - this.contributors = contributors - } - - //-- Mailing Lists -----------------------------------------------------------------------------------------------// - - @PomDsl - fun mailingLists(block: MailingListList.(MailingListList) -> Unit) { - val mailingLists = MailingListList() - block.invoke(mailingLists, mailingLists) - this.mailingLists = mailingLists - } - - //-- Prerequisites -----------------------------------------------------------------------------------------------// - - @PomDsl - fun prerequisites(block: Prerequisites.(Prerequisites) -> Unit) { - val prerequisites = Prerequisites() - block.invoke(prerequisites, prerequisites) - this.prerequisites = prerequisites - } - - //-- Modules -----------------------------------------------------------------------------------------------------// - - @PomDsl - fun modules(vararg modules: String) { - this.modules = modules.asList() - } - - //-- SCM ---------------------------------------------------------------------------------------------------------// - - @PomDsl - fun scm(block: Scm.(Scm) -> Unit) { - val scm = Scm() - block.invoke(scm, scm) - this.scm = scm - } - - //-- Issue Management --------------------------------------------------------------------------------------------// - - @PomDsl - fun issueManagement(block: IssueManagement.(IssueManagement) -> Unit) { - val issueManagement = IssueManagement() - block.invoke(issueManagement, issueManagement) - this.issueManagement = issueManagement - } - - //-- CI Management -----------------------------------------------------------------------------------------------// - - @PomDsl - fun ciManagement(block: CiManagement.(CiManagement) -> Unit) { - val ciManagement = CiManagement() - block.invoke(ciManagement, ciManagement) - this.ciManagement = ciManagement - } - - //-- Distribution Management -------------------------------------------------------------------------------------// - - @PomDsl - fun distributionManagement(block: DistributionManagement.(DistributionManagement) -> Unit) { - val distributionManagement = DistributionManagement() - block.invoke(distributionManagement, distributionManagement) - this.distributionManagement = distributionManagement - } - - //-- Properties --------------------------------------------------------------------------------------------------// - - @PomDsl - fun properties(block: Properties.(Properties) -> Unit) { - val properties = Properties() - block.invoke(properties, properties) - this.properties = propertiesFactory().apply { - putAll(properties.entries()) - } - } - - //-- Dependency Management ---------------------------------------------------------------------------------------// - - @PomDsl - fun dependencyManagement(block: DependencyManagement.(DependencyManagement) -> Unit) { - val dependencyManagement = DependencyManagement() - block(dependencyManagement, dependencyManagement) - this.dependencyManagement = dependencyManagement - } - - //-- Dependencies ------------------------------------------------------------------------------------------------// - - @PomDsl - fun dependencies(block: DependencyList.(DependencyList) -> Unit) { - val dependencies = DependencyList() - block(dependencies, dependencies) - this.dependencies = dependencies - } - - //-- Repositories ------------------------------------------------------------------------------------------------// - - @PomDsl - fun repositories(block: RepositoryList.(RepositoryList) -> Unit) { - val repositories = RepositoryList() - block.invoke(repositories, repositories) - this.repositories = repositories - } - - //-- Plugin Repositories -----------------------------------------------------------------------------------------// - - @PomDsl - fun pluginRepositories(block: PluginRepositoryList.(PluginRepositoryList) -> Unit) { - val pluginRepositories = PluginRepositoryList() - block.invoke(pluginRepositories, pluginRepositories) - this.pluginRepositories = pluginRepositories - } - - //-- Build -------------------------------------------------------------------------------------------------------// - - @PomDsl - fun build(block: ProjectBuild.(ProjectBuild) -> Unit) { - val build = ProjectBuild() - block(build, build) - setBuild(build) - } - - //-- Reports -----------------------------------------------------------------------------------------------------// - - /** - * Sets the reports content. - * - * @param source the reports source as a [String] of XML - */ - @PomDsl - fun reports(source: String): Xpp3Dom { - this.reports = source - return this.reports as Xpp3Dom - } - - @PomDsl - fun reports(block: XmlNode.(XmlNode) -> Unit) { - val reports = XmlNode("reports") - block(reports, reports) - this.reports = reports.xpp3Dom - } - - /** - * Sets the reports. - */ - override fun setReports(source: Any?) { - val name = "reports" - val xpp3Dom = - when (source) { - null -> null - is Xpp3Dom -> source - else -> Xpp3DomBuilder.build(source.toString().reader()) - } - if (xpp3Dom != null && xpp3Dom.name != name) { - val configuration = Xpp3Dom(name) - configuration.addChild(xpp3Dom) - super.setReports(configuration) - } else { - super.setReports(xpp3Dom) - } - } - - //-- Reporting ---------------------------------------------------------------------------------------------------// - - @PomDsl - fun reporting(block: Reporting.(Reporting) -> Unit) { - val reporting = Reporting() - block(reporting, reporting) - this.reporting = reporting - } - - //-- Profiles ----------------------------------------------------------------------------------------------------// - - @PomDsl - fun profiles(block: ProfileList.(ProfileList) -> Unit) { - val profiles = ProfileList() - block(profiles, profiles) - this.profiles = profiles - } - - override fun clone(): org.apache.maven.model.Model { - return super.clone() - } + if (xpp3Dom != null && xpp3Dom.name != name) { + val configuration = Xpp3Dom(name) + configuration.addChild(xpp3Dom) + super.setReports(configuration) + } else { + super.setReports(xpp3Dom) + } + } + + // -- Reporting + // ---------------------------------------------------------------------------------------------------// + + @PomDsl + fun reporting(block: Reporting.(Reporting) -> Unit) { + val reporting = Reporting() + block(reporting, reporting) + this.reporting = reporting + } + + // -- Profiles + // ----------------------------------------------------------------------------------------------------// + + @PomDsl + fun profiles(block: ProfileList.(ProfileList) -> Unit) { + val profiles = ProfileList() + block(profiles, profiles) + this.profiles = profiles + } + + override fun clone(): org.apache.maven.model.Model { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ProjectBuild.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ProjectBuild.kt index c18dc658..34ce9e6f 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ProjectBuild.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ProjectBuild.kt @@ -1,34 +1,42 @@ package org.sonatype.maven.polyglot.kotlin.dsl +import java.io.File import org.sonatype.maven.polyglot.execute.ExecuteContext import org.sonatype.maven.polyglot.execute.ExecuteTask import org.sonatype.maven.polyglot.kotlin.engine.ScriptHost import org.sonatype.maven.polyglot.kotlin.execute.KotlinExecuteTask -import java.io.File @PomDsl class ProjectBuild : Build() { - val tasks: MutableList = mutableListOf() + val tasks: MutableList = mutableListOf() - @PomDsl - fun execute(id: String, phase: String, profile: String? = null, block: ExecuteContext.() -> Unit) { - tasks.add(KotlinExecuteTask(block).apply { - this.id = id - this.phase = phase - this.profileId = profile + @PomDsl + fun execute( + id: String, + phase: String, + profile: String? = null, + block: ExecuteContext.() -> Unit + ) { + tasks.add( + KotlinExecuteTask(block).apply { + this.id = id + this.phase = phase + this.profileId = profile }) - } + } - @PomDsl - fun execute(id: String, phase: String, profile: String? = null, script: String) { - tasks.add(KotlinExecuteTask { - val file = File("$basedir/$script") - ScriptHost.eval(file, this) - }.apply { - this.id = id - this.phase = phase - this.profileId = profile - }) - } + @PomDsl + fun execute(id: String, phase: String, profile: String? = null, script: String) { + tasks.add( + KotlinExecuteTask { + val file = File("$basedir/$script") + ScriptHost.eval(file, this) + } + .apply { + this.id = id + this.phase = phase + this.profileId = profile + }) + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Properties.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Properties.kt index f93562e3..d7d62227 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Properties.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Properties.kt @@ -5,50 +5,50 @@ import java.util.* @PomDsl open class Properties { - private val properties: MutableMap = LinkedHashMap() - private val groups: MutableList = ArrayList() + private val properties: MutableMap = LinkedHashMap() + private val groups: MutableList = ArrayList() - internal fun entries(): Map { - return this@Properties.properties - } + internal fun entries(): Map { + return this@Properties.properties + } - @Suppress("unused") - internal fun groups(): List { - return this@Properties.groups - } + @Suppress("unused") + internal fun groups(): List { + return this@Properties.groups + } - @PomDsl - fun group(comment: String? = null, block: Properties.Group.(Properties.Group) -> Unit) { - val group = Group(comment) - block(group, group) - groups.add(group) - } + @PomDsl + fun group(comment: String? = null, block: Properties.Group.(Properties.Group) -> Unit) { + val group = Group(comment) + block(group, group) + groups.add(group) + } - infix fun String.to(value: Any) = addEntry(this, value) + infix fun String.to(value: Any) = addEntry(this, value) - private fun addEntry(key: String, value: Any) { - properties[key] = value.toString() - } + private fun addEntry(key: String, value: Any) { + properties[key] = value.toString() + } - @PomDsl - inner class Group(@Suppress("unused") val comment: String? = null) { + @PomDsl + inner class Group(@Suppress("unused") val comment: String? = null) { - private val keys: MutableSet = LinkedHashSet() + private val keys: MutableSet = LinkedHashSet() - @Suppress("unused") - fun entries(): Map { - return this@Properties.properties.filterKeys { keys.contains(it) } - } + @Suppress("unused") + fun entries(): Map { + return this@Properties.properties.filterKeys { keys.contains(it) } + } - infix fun String.to(value: String) = addEntry(this, value) + infix fun String.to(value: String) = addEntry(this, value) - infix fun String.to(value: Number) = addEntry(this, value) + infix fun String.to(value: Number) = addEntry(this, value) - infix fun String.to(value: Boolean) = addEntry(this, value) + infix fun String.to(value: Boolean) = addEntry(this, value) - private fun addEntry(key: String, value: Any) { - keys.add(key) - this@Properties.addEntry(key, value) - } + private fun addEntry(key: String, value: Any) { + keys.add(key) + this@Properties.addEntry(key, value) } + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Relocation.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Relocation.kt index 00684692..742a6bde 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Relocation.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Relocation.kt @@ -3,31 +3,31 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Relocation : org.apache.maven.model.Relocation(), Cloneable { - @PomDsl - fun groupId(groupId: String): Relocation { - this.groupId = groupId - return this - } + @PomDsl + fun groupId(groupId: String): Relocation { + this.groupId = groupId + return this + } - @PomDsl - fun artifactId(artifactId: String): Relocation { - this.artifactId = artifactId - return this - } + @PomDsl + fun artifactId(artifactId: String): Relocation { + this.artifactId = artifactId + return this + } - @PomDsl - fun version(version: String): Relocation { - this.version = version - return this - } + @PomDsl + fun version(version: String): Relocation { + this.version = version + return this + } - @PomDsl - fun message(message: String): Relocation { - this.message = message - return this - } + @PomDsl + fun message(message: String): Relocation { + this.message = message + return this + } - override fun clone(): org.apache.maven.model.Relocation { - return super.clone() - } + override fun clone(): org.apache.maven.model.Relocation { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportPlugin.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportPlugin.kt index 77e63f8b..4ac74aa5 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportPlugin.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportPlugin.kt @@ -6,81 +6,78 @@ import org.codehaus.plexus.util.xml.Xpp3DomBuilder @PomDsl class ReportPlugin : org.apache.maven.model.ReportPlugin(), Cloneable { - @PomDsl - fun groupId(groupId: String): ReportPlugin { - this.groupId = groupId - return this - } + @PomDsl + fun groupId(groupId: String): ReportPlugin { + this.groupId = groupId + return this + } - @PomDsl - fun artifactId(artifactId: String): ReportPlugin { - this.artifactId = artifactId - return this - } + @PomDsl + fun artifactId(artifactId: String): ReportPlugin { + this.artifactId = artifactId + return this + } - @PomDsl - fun version(version: String): ReportPlugin { - this.version = version - return this - } + @PomDsl + fun version(version: String): ReportPlugin { + this.version = version + return this + } - @PomDsl - fun inherited(inherited: Boolean = true): ReportPlugin { - this.isInherited = inherited - return this - } + @PomDsl + fun inherited(inherited: Boolean = true): ReportPlugin { + this.isInherited = inherited + return this + } - /** - * Provides a callback for defining a list of report sets. - */ - @PomDsl - fun reportSets(block: ReportSetList.(ReportSetList) -> Unit) { - val reportSets = ReportSetList() - block(reportSets, reportSets) - this.reportSets = reportSets - } + /** Provides a callback for defining a list of report sets. */ + @PomDsl + fun reportSets(block: ReportSetList.(ReportSetList) -> Unit) { + val reportSets = ReportSetList() + block(reportSets, reportSets) + this.reportSets = reportSets + } - //-- Configuration Helpers ---------------------------------------------------------------------------------------// + // -- Configuration Helpers + // ---------------------------------------------------------------------------------------// - /** - * Sets the plugin configuration. - * - * @param source the configuration source as a [String] of XML - */ - @PomDsl - fun configuration(source: String): Xpp3Dom { - this.configuration = source - return this.configuration as Xpp3Dom - } + /** + * Sets the plugin configuration. + * + * @param source the configuration source as a [String] of XML + */ + @PomDsl + fun configuration(source: String): Xpp3Dom { + this.configuration = source + return this.configuration as Xpp3Dom + } - @PomDsl - fun configuration(block: XmlNode.(XmlNode) -> Unit) { - val configuration = XmlNode("configuration") - block(configuration, configuration) - this.configuration = configuration.xpp3Dom - } + @PomDsl + fun configuration(block: XmlNode.(XmlNode) -> Unit) { + val configuration = XmlNode("configuration") + block(configuration, configuration) + this.configuration = configuration.xpp3Dom + } - /** - * Sets the configuration. - */ - override fun setConfiguration(source: Any?) { - val name = "configuration" - val xpp3Dom = - when (source) { - null -> null - is Xpp3Dom -> source - else -> Xpp3DomBuilder.build(source.toString().reader()) - } - if (xpp3Dom != null && xpp3Dom.name != name) { - val configuration = Xpp3Dom(name) - configuration.addChild(xpp3Dom) - super.setConfiguration(configuration) - } else { - super.setConfiguration(xpp3Dom) + /** Sets the configuration. */ + override fun setConfiguration(source: Any?) { + val name = "configuration" + val xpp3Dom = + when (source) { + null -> null + is Xpp3Dom -> source + else -> Xpp3DomBuilder.build(source.toString().reader()) } + if (xpp3Dom != null && xpp3Dom.name != name) { + val configuration = Xpp3Dom(name) + configuration.addChild(xpp3Dom) + super.setConfiguration(configuration) + } else { + super.setConfiguration(xpp3Dom) } + } - override fun clone(): org.apache.maven.model.ReportPlugin { - return super.clone() - } + override fun clone(): org.apache.maven.model.ReportPlugin { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportPluginList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportPluginList.kt index 9631c6c9..4ad0d124 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportPluginList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportPluginList.kt @@ -3,22 +3,23 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ReportPluginList : ArrayList(), Cloneable { - /** - * Provides a callback for defining a new report plugin. - */ - @PomDsl - fun plugin(gav: String? = null, block: (ReportPlugin.(ReportPlugin) -> Unit)? = null): ReportPlugin { - val (groupId, artifactId, version) = splitCoordinates(gav, 3) - return ReportPlugin().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version - this@ReportPluginList.add(this) - block?.invoke(this, this) - } + /** Provides a callback for defining a new report plugin. */ + @PomDsl + fun plugin( + gav: String? = null, + block: (ReportPlugin.(ReportPlugin) -> Unit)? = null + ): ReportPlugin { + val (groupId, artifactId, version) = splitCoordinates(gav, 3) + return ReportPlugin().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version + this@ReportPluginList.add(this) + block?.invoke(this, this) } + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportSet.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportSet.kt index 944e096b..e68f4917 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportSet.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportSet.kt @@ -6,65 +6,64 @@ import org.codehaus.plexus.util.xml.Xpp3DomBuilder @PomDsl class ReportSet : org.apache.maven.model.ReportSet(), Cloneable { - @PomDsl - fun id(id: String): ReportSet { - this.id = id - return this - } + @PomDsl + fun id(id: String): ReportSet { + this.id = id + return this + } - @PomDsl - fun reports(vararg reports: String): ReportSet { - this.reports = reports.asList() - return this - } + @PomDsl + fun reports(vararg reports: String): ReportSet { + this.reports = reports.asList() + return this + } - @PomDsl - fun inherited(inherited: Boolean = true): ReportSet { - this.isInherited = inherited - return this - } + @PomDsl + fun inherited(inherited: Boolean = true): ReportSet { + this.isInherited = inherited + return this + } - //-- Configuration Helpers ---------------------------------------------------------------------------------------// + // -- Configuration Helpers + // ---------------------------------------------------------------------------------------// - /** - * Sets the plugin configuration. - * - * @param source the configuration source as a [String] of XML - */ - @PomDsl - fun configuration(source: String): Xpp3Dom { - this.configuration = source - return this.configuration as Xpp3Dom - } + /** + * Sets the plugin configuration. + * + * @param source the configuration source as a [String] of XML + */ + @PomDsl + fun configuration(source: String): Xpp3Dom { + this.configuration = source + return this.configuration as Xpp3Dom + } - @PomDsl - fun configuration(block: XmlNode.(XmlNode) -> Unit) { - val configuration = XmlNode("configuration") - block(configuration, configuration) - this.configuration = configuration.xpp3Dom - } + @PomDsl + fun configuration(block: XmlNode.(XmlNode) -> Unit) { + val configuration = XmlNode("configuration") + block(configuration, configuration) + this.configuration = configuration.xpp3Dom + } - /** - * Sets the configuration. - */ - override fun setConfiguration(source: Any?) { - val name = "configuration" - val xpp3Dom = - when (source) { - null -> null - is Xpp3Dom -> source - else -> Xpp3DomBuilder.build(source.toString().reader()) - } - if (xpp3Dom != null && xpp3Dom.name != name) { - val configuration = Xpp3Dom(name) - configuration.addChild(xpp3Dom) - super.setConfiguration(configuration) - } else { - super.setConfiguration(xpp3Dom) + /** Sets the configuration. */ + override fun setConfiguration(source: Any?) { + val name = "configuration" + val xpp3Dom = + when (source) { + null -> null + is Xpp3Dom -> source + else -> Xpp3DomBuilder.build(source.toString().reader()) } + if (xpp3Dom != null && xpp3Dom.name != name) { + val configuration = Xpp3Dom(name) + configuration.addChild(xpp3Dom) + super.setConfiguration(configuration) + } else { + super.setConfiguration(xpp3Dom) } + } - override fun clone(): org.apache.maven.model.ReportSet { - return super.clone() - } + override fun clone(): org.apache.maven.model.ReportSet { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportSetList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportSetList.kt index 188711b1..1716bacc 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportSetList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ReportSetList.kt @@ -3,19 +3,15 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ReportSetList : ArrayList(), Cloneable { - /** - * Provides a callback for defining a new report set. - */ - @PomDsl - fun reportSet(id: String? = null, block: ReportSet.(ReportSet) -> Unit) { - val reportSet = ReportSet().apply { - this.id = id - } - block(reportSet, reportSet) - add(reportSet) - } + /** Provides a callback for defining a new report set. */ + @PomDsl + fun reportSet(id: String? = null, block: ReportSet.(ReportSet) -> Unit) { + val reportSet = ReportSet().apply { this.id = id } + block(reportSet, reportSet) + add(reportSet) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Reporting.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Reporting.kt index 0205b85e..bf820b30 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Reporting.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Reporting.kt @@ -3,26 +3,26 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Reporting : org.apache.maven.model.Reporting(), Cloneable { - @PomDsl - fun excludeDefaults(excludeDefaults: Boolean = true): Reporting { - this.isExcludeDefaults = excludeDefaults - return this - } + @PomDsl + fun excludeDefaults(excludeDefaults: Boolean = true): Reporting { + this.isExcludeDefaults = excludeDefaults + return this + } - @PomDsl - fun outputDirectory(outputDirectory: String): Reporting { - this.outputDirectory = outputDirectory - return this - } + @PomDsl + fun outputDirectory(outputDirectory: String): Reporting { + this.outputDirectory = outputDirectory + return this + } - @PomDsl - fun plugins(block: ReportPluginList.(ReportPluginList) -> Unit) { - val plugins = ReportPluginList() - block.invoke(plugins, plugins) - this.plugins = plugins - } + @PomDsl + fun plugins(block: ReportPluginList.(ReportPluginList) -> Unit) { + val plugins = ReportPluginList() + block.invoke(plugins, plugins) + this.plugins = plugins + } - override fun clone(): org.apache.maven.model.Reporting { - return super.clone() - } + override fun clone(): org.apache.maven.model.Reporting { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Repository.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Repository.kt index fef2285a..4aaf2571 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Repository.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Repository.kt @@ -3,45 +3,45 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Repository : org.apache.maven.model.Repository(), Cloneable { - @PomDsl - fun id(id: String): Repository { - this.id = id - return this - } - - @PomDsl - fun name(name: String): Repository { - this.name = name - return this - } - - @PomDsl - fun url(url: String): Repository { - this.url = url - return this - } - - @PomDsl - fun layout(layout: String): Repository { - this.layout = layout - return this - } - - @PomDsl - fun releases(block: RepositoryPolicy.(RepositoryPolicy) -> Unit) { - val releases = RepositoryPolicy() - block.invoke(releases, releases) - this.releases = releases - } - - @PomDsl - fun snapshots(block: RepositoryPolicy.(RepositoryPolicy) -> Unit) { - val snapshots = RepositoryPolicy() - block.invoke(snapshots, snapshots) - this.snapshots = snapshots - } - - override fun clone(): org.apache.maven.model.Repository { - return super.clone() - } + @PomDsl + fun id(id: String): Repository { + this.id = id + return this + } + + @PomDsl + fun name(name: String): Repository { + this.name = name + return this + } + + @PomDsl + fun url(url: String): Repository { + this.url = url + return this + } + + @PomDsl + fun layout(layout: String): Repository { + this.layout = layout + return this + } + + @PomDsl + fun releases(block: RepositoryPolicy.(RepositoryPolicy) -> Unit) { + val releases = RepositoryPolicy() + block.invoke(releases, releases) + this.releases = releases + } + + @PomDsl + fun snapshots(block: RepositoryPolicy.(RepositoryPolicy) -> Unit) { + val snapshots = RepositoryPolicy() + block.invoke(snapshots, snapshots) + this.snapshots = snapshots + } + + override fun clone(): org.apache.maven.model.Repository { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/RepositoryList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/RepositoryList.kt index 90300060..9b3c1928 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/RepositoryList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/RepositoryList.kt @@ -3,17 +3,18 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class RepositoryList : ArrayList(), Cloneable { - @PomDsl - fun repository(nameOrId: String? = null, block: Repository.(Repository) -> Unit) { - val repository = Repository().apply { - this.id = nameOrId - this.name = nameOrId + @PomDsl + fun repository(nameOrId: String? = null, block: Repository.(Repository) -> Unit) { + val repository = + Repository().apply { + this.id = nameOrId + this.name = nameOrId } - block.invoke(repository, repository) - add(repository) - } + block.invoke(repository, repository) + add(repository) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/RepositoryPolicy.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/RepositoryPolicy.kt index f6fca7d4..2a249401 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/RepositoryPolicy.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/RepositoryPolicy.kt @@ -3,25 +3,25 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class RepositoryPolicy : org.apache.maven.model.RepositoryPolicy(), Cloneable { - @PomDsl - fun enabled(enabled: Boolean = true): RepositoryPolicy { - this.isEnabled = enabled - return this - } + @PomDsl + fun enabled(enabled: Boolean = true): RepositoryPolicy { + this.isEnabled = enabled + return this + } - @PomDsl - fun updatePolicy(updatePolicy: String): RepositoryPolicy { - this.updatePolicy = updatePolicy - return this - } + @PomDsl + fun updatePolicy(updatePolicy: String): RepositoryPolicy { + this.updatePolicy = updatePolicy + return this + } - @PomDsl - fun checksumPolicy(checksumPolicy: String): RepositoryPolicy { - this.checksumPolicy = checksumPolicy - return this - } + @PomDsl + fun checksumPolicy(checksumPolicy: String): RepositoryPolicy { + this.checksumPolicy = checksumPolicy + return this + } - override fun clone(): org.apache.maven.model.RepositoryPolicy { - return super.clone() - } + override fun clone(): org.apache.maven.model.RepositoryPolicy { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Resource.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Resource.kt index a17510f9..dc8ea28c 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Resource.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Resource.kt @@ -3,37 +3,37 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Resource : org.apache.maven.model.Resource(), Cloneable { - @PomDsl - fun targetPath(targetPath: String): Resource { - this.targetPath = targetPath - return this - } + @PomDsl + fun targetPath(targetPath: String): Resource { + this.targetPath = targetPath + return this + } - @PomDsl - fun filtering(filtering: Boolean = true): Resource { - this.isFiltering = filtering - return this - } + @PomDsl + fun filtering(filtering: Boolean = true): Resource { + this.isFiltering = filtering + return this + } - @PomDsl - fun directory(directory: String): Resource { - this.directory = directory - return this - } + @PomDsl + fun directory(directory: String): Resource { + this.directory = directory + return this + } - @PomDsl - fun includes(vararg includes: String): Resource { - this.includes = includes.asList() - return this - } + @PomDsl + fun includes(vararg includes: String): Resource { + this.includes = includes.asList() + return this + } - @PomDsl - fun excludes(vararg excludes: String): Resource { - this.excludes = excludes.asList() - return this - } + @PomDsl + fun excludes(vararg excludes: String): Resource { + this.excludes = excludes.asList() + return this + } - override fun clone(): org.apache.maven.model.Resource { - return super.clone() - } + override fun clone(): org.apache.maven.model.Resource { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ResourceList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ResourceList.kt index 486b6427..7ef8fd7b 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ResourceList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/ResourceList.kt @@ -3,14 +3,14 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class ResourceList : ArrayList(), Cloneable { - @PomDsl - fun resource(block: Resource.(Resource) -> Unit) { - val resource = Resource() - block.invoke(resource, resource) - add(resource) - } + @PomDsl + fun resource(block: Resource.(Resource) -> Unit) { + val resource = Resource() + block.invoke(resource, resource) + add(resource) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Scm.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Scm.kt index dcf97f2e..71d73b0b 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Scm.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Scm.kt @@ -3,27 +3,27 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Scm : org.apache.maven.model.Scm(), Cloneable { - @PomDsl - fun url(url: String) { - this.url = url - } + @PomDsl + fun url(url: String) { + this.url = url + } - @PomDsl - fun connection(connection: String) { - this.connection = connection - } + @PomDsl + fun connection(connection: String) { + this.connection = connection + } - @PomDsl - fun developerConnection(developerConnection: String) { - this.developerConnection = developerConnection - } + @PomDsl + fun developerConnection(developerConnection: String) { + this.developerConnection = developerConnection + } - @PomDsl - fun tag(tag: String) { - this.tag = tag - } + @PomDsl + fun tag(tag: String) { + this.tag = tag + } - override fun clone(): org.apache.maven.model.Scm { - return super.clone() - } + override fun clone(): org.apache.maven.model.Scm { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Site.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Site.kt index f8a96e4a..0f1a85c6 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Site.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/Site.kt @@ -3,25 +3,25 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class Site : org.apache.maven.model.Site(), Cloneable { - @PomDsl - fun id(id: String): Site { - this.id = id - return this - } + @PomDsl + fun id(id: String): Site { + this.id = id + return this + } - @PomDsl - fun name(name: String): Site { - this.name = name - return this - } + @PomDsl + fun name(name: String): Site { + this.name = name + return this + } - @PomDsl - fun url(url: String): Site { - this.url = url - return this - } + @PomDsl + fun url(url: String): Site { + this.url = url + return this + } - override fun clone(): org.apache.maven.model.Site { - return super.clone() - } + override fun clone(): org.apache.maven.model.Site { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/TestResourceList.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/TestResourceList.kt index 35db6b62..8a44d535 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/TestResourceList.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/TestResourceList.kt @@ -3,14 +3,14 @@ package org.sonatype.maven.polyglot.kotlin.dsl @PomDsl class TestResourceList : ArrayList(), Cloneable { - @PomDsl - fun testResource(block: Resource.(Resource) -> Unit) { - val resource = Resource() - block.invoke(resource, resource) - add(resource) - } + @PomDsl + fun testResource(block: Resource.(Resource) -> Unit) { + val resource = Resource() + block.invoke(resource, resource) + add(resource) + } - override fun clone(): Any { - return super.clone() - } + override fun clone(): Any { + return super.clone() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/XmlNode.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/XmlNode.kt index 6c51e40e..7fc15995 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/XmlNode.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/XmlNode.kt @@ -5,43 +5,43 @@ import org.codehaus.plexus.util.xml.Xpp3Dom @PomDsl open class XmlNode(val name: String, val parent: XmlNode? = null) { - var xpp3Dom: Xpp3Dom = Xpp3Dom(name) + var xpp3Dom: Xpp3Dom = Xpp3Dom(name) - init { - if (parent != null) { - parent.xpp3Dom.addChild(xpp3Dom) - } - } - - infix fun String.to(value: Any) { - val node = XmlNode(this, this@XmlNode) - node.xpp3Dom.value = value.toString() - } - - infix fun String.to(value: Int) { - val node = XmlNode(this, this@XmlNode) - node.xpp3Dom.value = value.toString() - } - - infix fun String.to(value: Long) { - val node = XmlNode(this, this@XmlNode) - node.xpp3Dom.value = value.toString() - } - - infix fun String.to(value: Double) { - val node = XmlNode(this, this@XmlNode) - node.xpp3Dom.value = value.toString() - } - - infix fun String.to(value: Boolean) { - val node = XmlNode(this, this@XmlNode) - node.xpp3Dom.value = value.toString() - } - - @PomDsl - operator fun String.invoke(block: XmlNode.(XmlNode) -> Unit): XmlNode { - val node = XmlNode(this, this@XmlNode) - block.invoke(node, node) - return node + init { + if (parent != null) { + parent.xpp3Dom.addChild(xpp3Dom) } + } + + infix fun String.to(value: Any) { + val node = XmlNode(this, this@XmlNode) + node.xpp3Dom.value = value.toString() + } + + infix fun String.to(value: Int) { + val node = XmlNode(this, this@XmlNode) + node.xpp3Dom.value = value.toString() + } + + infix fun String.to(value: Long) { + val node = XmlNode(this, this@XmlNode) + node.xpp3Dom.value = value.toString() + } + + infix fun String.to(value: Double) { + val node = XmlNode(this, this@XmlNode) + node.xpp3Dom.value = value.toString() + } + + infix fun String.to(value: Boolean) { + val node = XmlNode(this, this@XmlNode) + node.xpp3Dom.value = value.toString() + } + + @PomDsl + operator fun String.invoke(block: XmlNode.(XmlNode) -> Unit): XmlNode { + val node = XmlNode(this, this@XmlNode) + block.invoke(node, node) + return node + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/PomKtsScript.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/PomKtsScript.kt index 04636508..cbec6c3d 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/PomKtsScript.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/PomKtsScript.kt @@ -1,45 +1,38 @@ package org.sonatype.maven.polyglot.kotlin.engine -import org.sonatype.maven.polyglot.execute.ExecuteContext -import org.sonatype.maven.polyglot.kotlin.dsl.PomDsl -import org.sonatype.maven.polyglot.kotlin.dsl.Project import java.io.File import kotlin.script.experimental.annotations.KotlinScript import kotlin.script.templates.ScriptTemplateDefinition +import org.sonatype.maven.polyglot.execute.ExecuteContext +import org.sonatype.maven.polyglot.kotlin.dsl.PomDsl +import org.sonatype.maven.polyglot.kotlin.dsl.Project @KotlinScript( - displayName = "Maven kotlin POM script", - fileExtension = "pom.kts", - compilationConfiguration = ScriptDefinition::class -) + displayName = "Maven kotlin POM script", + fileExtension = "pom.kts", + compilationConfiguration = ScriptDefinition::class) @ScriptTemplateDefinition(scriptFilePattern = "pom\\.kts") abstract class PomKtsScript(val script: File, val basedir: File, val model: Project) { - /** - * Configures a Maven project model. - */ - @PomDsl - fun project(nameOrId: String? = null, block: Project.() -> Unit): Project { - if (nameOrId != null) { - model.name = nameOrId - model.id = nameOrId - } - return model.apply(block) + /** Configures a Maven project model. */ + @PomDsl + fun project(nameOrId: String? = null, block: Project.() -> Unit): Project { + if (nameOrId != null) { + model.name = nameOrId + model.id = nameOrId } + return model.apply(block) + } - /** - * Invokes the script at the supplied location - */ - @Suppress("unused") - fun eval(script: File) { - ScriptHost.eval(script, basedir, model) - } + /** Invokes the script at the supplied location */ + @Suppress("unused") + fun eval(script: File) { + ScriptHost.eval(script, basedir, model) + } - /** - * Invokes the script at the supplied location - */ - @Suppress("unused") - fun ExecuteContext.eval(taskScript: File) { - ScriptHost.eval(taskScript, this) - } + /** Invokes the script at the supplied location */ + @Suppress("unused") + fun ExecuteContext.eval(taskScript: File) { + ScriptHost.eval(taskScript, this) + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/ScriptDefinition.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/ScriptDefinition.kt index 30bb942b..d503a559 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/ScriptDefinition.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/ScriptDefinition.kt @@ -1,5 +1,11 @@ package org.sonatype.maven.polyglot.kotlin.engine +import kotlin.script.experimental.api.ScriptAcceptedLocation +import kotlin.script.experimental.api.ScriptCompilationConfiguration +import kotlin.script.experimental.api.acceptedLocations +import kotlin.script.experimental.api.ide +import kotlin.script.experimental.jvm.dependenciesFromClassContext +import kotlin.script.experimental.jvm.jvm import org.apache.maven.artifact.Artifact import org.apache.maven.model.Model import org.apache.maven.plugin.logging.Log @@ -7,27 +13,24 @@ import org.apache.maven.project.MavenProject import org.apache.maven.settings.Settings import org.codehaus.plexus.util.xml.Xpp3DomBuilder import org.sonatype.maven.polyglot.execute.ExecuteContext -import kotlin.script.experimental.api.ScriptAcceptedLocation -import kotlin.script.experimental.api.ScriptCompilationConfiguration -import kotlin.script.experimental.api.acceptedLocations -import kotlin.script.experimental.api.ide -import kotlin.script.experimental.jvm.dependenciesFromClassContext -import kotlin.script.experimental.jvm.jvm -object ScriptDefinition : ScriptCompilationConfiguration( - { - jvm { - dependenciesFromClassContext(PomKtsScript::class, "polyglot-kotlin") // needed for DSL - dependenciesFromClassContext(ExecuteContext::class, "polyglot-common") // needed for executing tasks - dependenciesFromClassContext(Model::class, "maven-model") // needed for maven model - dependenciesFromClassContext(MavenProject::class, "maven-core") // needed for maven project/session - dependenciesFromClassContext(Artifact::class, "maven-artifact") // needed for maven artifacts - dependenciesFromClassContext(Settings::class, "maven-settings") // needed for accessing settings - dependenciesFromClassContext(Xpp3DomBuilder::class, "plexus-utils") // needed for Xpp3DomBuilder - dependenciesFromClassContext(Log::class, "maven-plugin-api") // Needed for writing to the Maven build log - } - ide { - acceptedLocations(ScriptAcceptedLocation.Everywhere) - } - } -) +object ScriptDefinition : + ScriptCompilationConfiguration({ + jvm { + dependenciesFromClassContext(PomKtsScript::class, "polyglot-kotlin") // needed for DSL + dependenciesFromClassContext( + ExecuteContext::class, "polyglot-common") // needed for executing tasks + dependenciesFromClassContext(Model::class, "maven-model") // needed for maven model + dependenciesFromClassContext( + MavenProject::class, "maven-core") // needed for maven project/session + dependenciesFromClassContext( + Artifact::class, "maven-artifact") // needed for maven artifacts + dependenciesFromClassContext( + Settings::class, "maven-settings") // needed for accessing settings + dependenciesFromClassContext( + Xpp3DomBuilder::class, "plexus-utils") // needed for Xpp3DomBuilder + dependenciesFromClassContext( + Log::class, "maven-plugin-api") // Needed for writing to the Maven build log + } + ide { acceptedLocations(ScriptAcceptedLocation.Everywhere) } + }) diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/ScriptHost.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/ScriptHost.kt index 4ac5a7b4..c0d18851 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/ScriptHost.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/ScriptHost.kt @@ -1,8 +1,5 @@ package org.sonatype.maven.polyglot.kotlin.engine -import org.apache.maven.MavenExecutionException -import org.sonatype.maven.polyglot.execute.ExecuteContext -import org.sonatype.maven.polyglot.kotlin.dsl.Project import java.io.File import kotlin.script.experimental.api.ResultWithDiagnostics import kotlin.script.experimental.api.ScriptCompilationConfiguration @@ -14,47 +11,50 @@ import kotlin.script.experimental.jvm.baseClassLoader import kotlin.script.experimental.jvm.jvm import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate +import org.apache.maven.MavenExecutionException +import org.sonatype.maven.polyglot.execute.ExecuteContext +import org.sonatype.maven.polyglot.kotlin.dsl.Project object ScriptHost { - private val host = BasicJvmScriptingHost() - private val pomCompilationConfig = createJvmCompilationConfigurationFromTemplate() - private val taskCompilationConfig = createJvmCompilationConfigurationFromTemplate() + private val host = BasicJvmScriptingHost() + private val pomCompilationConfig = createJvmCompilationConfigurationFromTemplate() + private val taskCompilationConfig = createJvmCompilationConfigurationFromTemplate() - fun eval(script: File, basedir: File, model: Project) { - eval(script, pomCompilationConfig) { - constructorArgs(script, basedir, model) - jvm { - baseClassLoader(PomKtsScript::class.java.classLoader) - } - } + fun eval(script: File, basedir: File, model: Project) { + eval(script, pomCompilationConfig) { + constructorArgs(script, basedir, model) + jvm { baseClassLoader(PomKtsScript::class.java.classLoader) } } + } - fun eval(script: File, executeContext: ExecuteContext) { - eval(script, taskCompilationConfig) { - constructorArgs(script, executeContext) - jvm { - baseClassLoader(TaskKtsScript::class.java.classLoader) - } - } + fun eval(script: File, executeContext: ExecuteContext) { + eval(script, taskCompilationConfig) { + constructorArgs(script, executeContext) + jvm { baseClassLoader(TaskKtsScript::class.java.classLoader) } } + } - private fun eval(script: File, - compilationConfig: ScriptCompilationConfiguration, - evaluationConfigBuilder: ScriptEvaluationConfiguration.Builder.() -> Unit) { - val sourceCode = script.readText().toScriptSource() - val evaluationConfig = ScriptEvaluationConfiguration(evaluationConfigBuilder) - val result = host.eval(sourceCode, compilationConfig, evaluationConfig) - result.reports.filter { it.exception != null }.forEach { - System.err.println(it) - it.exception?.printStackTrace() - } - if (result is ResultWithDiagnostics.Failure) { - throw MavenExecutionException( - "Failed to evaluate script\n" + - result.reports - .filterNot { it.severity == ScriptDiagnostic.Severity.DEBUG } - .joinToString("\n"), script - ) + private fun eval( + script: File, + compilationConfig: ScriptCompilationConfiguration, + evaluationConfigBuilder: ScriptEvaluationConfiguration.Builder.() -> Unit + ) { + val sourceCode = script.readText().toScriptSource() + val evaluationConfig = ScriptEvaluationConfiguration(evaluationConfigBuilder) + val result = host.eval(sourceCode, compilationConfig, evaluationConfig) + result.reports + .filter { it.exception != null } + .forEach { + System.err.println(it) + it.exception?.printStackTrace() } + if (result is ResultWithDiagnostics.Failure) { + throw MavenExecutionException( + "Failed to evaluate script\n" + + result.reports + .filterNot { it.severity == ScriptDiagnostic.Severity.DEBUG } + .joinToString("\n"), + script) } + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/TaskKtsScript.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/TaskKtsScript.kt index c28315e5..14149497 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/TaskKtsScript.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/engine/TaskKtsScript.kt @@ -1,14 +1,14 @@ package org.sonatype.maven.polyglot.kotlin.engine -import org.sonatype.maven.polyglot.execute.ExecuteContext import java.io.File import kotlin.script.experimental.annotations.KotlinScript import kotlin.script.templates.ScriptTemplateDefinition +import org.sonatype.maven.polyglot.execute.ExecuteContext @KotlinScript( displayName = "External kotlin task script", fileExtension = "task.kts", - compilationConfiguration = ScriptDefinition::class -) + compilationConfiguration = ScriptDefinition::class) @ScriptTemplateDefinition(scriptFilePattern = ".*\\.task\\.kts") -abstract class TaskKtsScript(val script: File, private val delegate: ExecuteContext) : ExecuteContext by delegate +abstract class TaskKtsScript(val script: File, private val delegate: ExecuteContext) : + ExecuteContext by delegate diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/execute/KotlinExecuteTask.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/execute/KotlinExecuteTask.kt index 1c649b4f..864a77f4 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/execute/KotlinExecuteTask.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/execute/KotlinExecuteTask.kt @@ -5,7 +5,7 @@ import org.sonatype.maven.polyglot.execute.ExecuteTaskSupport class KotlinExecuteTask(private val script: ExecuteContext.() -> Unit) : ExecuteTaskSupport() { - override fun execute(context: ExecuteContext) { - context.script() - } + override fun execute(context: ExecuteContext) { + context.script() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/serialization/KotlinScriptWriter.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/serialization/KotlinScriptWriter.kt index 532dde06..ab8dd163 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/serialization/KotlinScriptWriter.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/serialization/KotlinScriptWriter.kt @@ -1,307 +1,318 @@ package org.sonatype.maven.polyglot.kotlin.serialization -import org.sonatype.maven.polyglot.kotlin.dsl.escape -import org.sonatype.maven.polyglot.kotlin.dsl.escapeRaw import java.io.Writer import java.util.* import kotlin.collections.ArrayList +import org.sonatype.maven.polyglot.kotlin.dsl.escape +import org.sonatype.maven.polyglot.kotlin.dsl.escapeRaw internal open class KotlinScriptWriter(writer: Writer) { - private enum class SerializerState { - BLOCK, FUNCTION, FIELD, RAW_STRING - } - - private val state: Deque = LinkedList() - private val indentation = " " - protected var indentLevel = 0 - private var lineStart = true - private val argumentWrapThreshold = 50 - private val out = OUT(writer) - private val expressionText = Regex("""[$][{][^}]+[}]""") - private val booleanLiteral = Regex("true|false") - - class OUT(private val out: Writer) : Writer() { - - private var position: Long = 0 - - override fun write(cbuf: CharArray, off: Int, len: Int) { - out.write(cbuf, off, len) - position += len - } - - override fun flush() { - out.flush() - } - - override fun close() { - out.close() - } - } - - protected fun write(str: String): KotlinScriptWriter { - if (lineStart) { - for (i in 1..indentLevel) { - out.write(indentation) - } - lineStart = false - } - out.write(str) - return this + private enum class SerializerState { + BLOCK, + FUNCTION, + FIELD, + RAW_STRING + } + + private val state: Deque = LinkedList() + private val indentation = " " + protected var indentLevel = 0 + private var lineStart = true + private val argumentWrapThreshold = 50 + private val out = OUT(writer) + private val expressionText = Regex("""[$][{][^}]+[}]""") + private val booleanLiteral = Regex("true|false") + + class OUT(private val out: Writer) : Writer() { + + private var position: Long = 0 + + override fun write(cbuf: CharArray, off: Int, len: Int) { + out.write(cbuf, off, len) + position += len } - private fun writeString(value: String): KotlinScriptWriter { - val escapedValue = escape(value) - when { - expressionText.find(value) != null -> { - write("\"${escapedValue}\"") - } - value != escapedValue -> { - val escapedRawValue = escapeRaw(value) - tripleQuotedString(escapedRawValue) - } - else -> write("\"${value}\"") - } - return this + override fun flush() { + out.flush() } - protected fun writePair(pair: Pair): KotlinScriptWriter { - writeString(pair.first) - write(" to ") - val value = pair.second - when { - value == null -> write("null") - value.toLongOrNull().toString() == value -> write(value) - value.toDoubleOrNull().toString() == value -> write(value) - value.matches(booleanLiteral) -> write(value) - else -> writeString(value) - } - return this + override fun close() { + out.close() } - - protected fun endLine(): KotlinScriptWriter { - out.write("\n") - lineStart = true - return this + } + + protected fun write(str: String): KotlinScriptWriter { + if (lineStart) { + for (i in 1..indentLevel) { + out.write(indentation) + } + lineStart = false } - - protected fun blockComment(comment: String): KotlinScriptWriter { - write("/*").endLine() - comment.prependIndent(" * ").lines().forEach { write(it).endLine() } - write(" */").endLine() - return this + out.write(str) + return this + } + + private fun writeString(value: String): KotlinScriptWriter { + val escapedValue = escape(value) + when { + expressionText.find(value) != null -> { + write("\"${escapedValue}\"") + } + value != escapedValue -> { + val escapedRawValue = escapeRaw(value) + tripleQuotedString(escapedRawValue) + } + else -> write("\"${value}\"") } - - protected fun lineComment(comment: String): KotlinScriptWriter { - comment.prependIndent("// ").lines().forEach { write(it).endLine() } - return this + return this + } + + protected fun writePair(pair: Pair): KotlinScriptWriter { + writeString(pair.first) + write(" to ") + val value = pair.second + when { + value == null -> write("null") + value.toLongOrNull().toString() == value -> write(value) + value.toDoubleOrNull().toString() == value -> write(value) + value.matches(booleanLiteral) -> write(value) + else -> writeString(value) } - - protected fun block(name: String, - modelObject: T?, - args: (T.(MutableList) -> Unit)? = null, - contents: (T.() -> Unit)? = null) { - block(name, modelObject, "it", args, contents) + return this + } + + protected fun endLine(): KotlinScriptWriter { + out.write("\n") + lineStart = true + return this + } + + protected fun blockComment(comment: String): KotlinScriptWriter { + write("/*").endLine() + comment.prependIndent(" * ").lines().forEach { write(it).endLine() } + write(" */").endLine() + return this + } + + protected fun lineComment(comment: String): KotlinScriptWriter { + comment.prependIndent("// ").lines().forEach { write(it).endLine() } + return this + } + + protected fun block( + name: String, + modelObject: T?, + args: (T.(MutableList) -> Unit)? = null, + contents: (T.() -> Unit)? = null + ) { + block(name, modelObject, "it", args, contents) + } + + protected fun block( + name: String, + modelObject: T?, + paramName: String, + args: (T.(MutableList) -> Unit)? = null, + contents: (T.() -> Unit)? = null + ) { + if (modelObject == null) { + return + } else if (modelObject is Collection<*> && modelObject.isEmpty()) { + return + } else if (modelObject is Map<*, *> && modelObject.isEmpty()) { + return + } else if (indentLevel == 1) { + // Add an extra space before project-level blocks + endLine() } - - protected fun block(name: String, - modelObject: T?, - paramName: String, - args: (T.(MutableList) -> Unit)? = null, - contents: (T.() -> Unit)? = null) { - if (modelObject == null) { - return - } else if (modelObject is Collection<*> && modelObject.isEmpty()) { - return - } else if (modelObject is Map<*, *> && modelObject.isEmpty()) { - return - } else if (indentLevel == 1) { - // Add an extra space before project-level blocks - endLine() + if (args != null) { + val params: MutableList = ArrayList() + args(modelObject, params) + if (params.isEmpty()) { + if (contents != null) { + startBlock(name, paramName) } - if (args != null) { - val params: MutableList = ArrayList() - args(modelObject, params) - if (params.isEmpty()) { - if (contents != null) { - startBlock(name, paramName) - } - } else { - function(name) { - if (params.size == 1 || params.joinToString().length < argumentWrapThreshold) { - @Suppress("UNCHECKED_CAST") - when (params[0]) { - is Pair<*, *> -> namedArguments(params as List>) - is String -> arguments(params as List) - else -> throw IllegalArgumentException("The argument type \"${params[0]::class}\" is unsupported. Must be Pair or String") - } - } else { - @Suppress("UNCHECKED_CAST") - when (params[0]) { - is Pair<*, *> -> namedMultiLineArguments(params as List>) - is String -> multiLineArguments(params as List) - else -> throw IllegalArgumentException("The argument type \"${params[0]::class}\" is unsupported. Must be Pair or String") - } - } - } - if (contents != null) { - write(" ") - startBlock(null, paramName) - } + } else { + function(name) { + if (params.size == 1 || params.joinToString().length < argumentWrapThreshold) { + @Suppress("UNCHECKED_CAST") + when (params[0]) { + is Pair<*, *> -> namedArguments(params as List>) + is String -> arguments(params as List) + else -> + throw IllegalArgumentException( + "The argument type \"${params[0]::class}\" is unsupported. Must be Pair or String") + } + } else { + @Suppress("UNCHECKED_CAST") + when (params[0]) { + is Pair<*, *> -> namedMultiLineArguments(params as List>) + is String -> multiLineArguments(params as List) + else -> + throw IllegalArgumentException( + "The argument type \"${params[0]::class}\" is unsupported. Must be Pair or String") } - } else if (contents != null) { - startBlock(name, paramName) + } } if (contents != null) { - contents(modelObject) - endBlock() - } - endLine() - } - - protected fun singleQuotedString(text: String?) { - if (text == null) { - write("null") - } else { - write("\"").write(escape(text)).write("\"") - } - } - - private fun tripleQuotedString(text: String?) { - if (text == null) { - write("null") - } else { - write("\"\"\"") - state.push(SerializerState.RAW_STRING) - incrementIndent() - text.lines().forEach { write(it) } - decrementIndent() - state.pop() - write("\"\"\"") + write(" ") + startBlock(null, paramName) } + } + } else if (contents != null) { + startBlock(name, paramName) } - - private fun incrementIndent(): KotlinScriptWriter { - indentLevel++ - return this - } - - private fun decrementIndent(): KotlinScriptWriter { - indentLevel-- - return this - } - - private fun startBlock(name: String? = null, paramName: String? = "it"): KotlinScriptWriter { - write(if (name == null) "{" else "${name} {") - if (paramName != "it") { - write(" ${paramName} ->") - } - state.push(SerializerState.BLOCK) - indentLevel++ - endLine() - return this - } - - private fun endBlock(): KotlinScriptWriter { - indentLevel-- - write("}") - state.pop() - return this + if (contents != null) { + contents(modelObject) + endBlock() } - - private fun startFunction(name: String): KotlinScriptWriter { - write("${name}(") - state.push(SerializerState.FUNCTION) - return this - } - - private fun endFunction(): KotlinScriptWriter { - write(")") - state.pop() - return this - } - - private fun startField(name: String) { - write("${name} = ") - state.push(SerializerState.FIELD) + endLine() + } + + protected fun singleQuotedString(text: String?) { + if (text == null) { + write("null") + } else { + write("\"").write(escape(text)).write("\"") } - - private fun endField() { - state.pop() - } - - private fun startMultiLineString() { - write("\"\"\"") - state.push(SerializerState.RAW_STRING) - incrementIndent() - endLine() + } + + private fun tripleQuotedString(text: String?) { + if (text == null) { + write("null") + } else { + write("\"\"\"") + state.push(SerializerState.RAW_STRING) + incrementIndent() + text.lines().forEach { write(it) } + decrementIndent() + state.pop() + write("\"\"\"") } - - private fun endMultiLineString() { - write("\"\"\"") - state.pop() - decrementIndent() + } + + private fun incrementIndent(): KotlinScriptWriter { + indentLevel++ + return this + } + + private fun decrementIndent(): KotlinScriptWriter { + indentLevel-- + return this + } + + private fun startBlock(name: String? = null, paramName: String? = "it"): KotlinScriptWriter { + write(if (name == null) "{" else "${name} {") + if (paramName != "it") { + write(" ${paramName} ->") } - - protected fun arguments(values: List) { - values.forEachIndexed { index, value -> - if (index > 0) write(", ") - singleQuotedString(value) - } + state.push(SerializerState.BLOCK) + indentLevel++ + endLine() + return this + } + + private fun endBlock(): KotlinScriptWriter { + indentLevel-- + write("}") + state.pop() + return this + } + + private fun startFunction(name: String): KotlinScriptWriter { + write("${name}(") + state.push(SerializerState.FUNCTION) + return this + } + + private fun endFunction(): KotlinScriptWriter { + write(")") + state.pop() + return this + } + + private fun startField(name: String) { + write("${name} = ") + state.push(SerializerState.FIELD) + } + + private fun endField() { + state.pop() + } + + private fun startMultiLineString() { + write("\"\"\"") + state.push(SerializerState.RAW_STRING) + incrementIndent() + endLine() + } + + private fun endMultiLineString() { + write("\"\"\"") + state.pop() + decrementIndent() + } + + protected fun arguments(values: List) { + values.forEachIndexed { index, value -> + if (index > 0) write(", ") + singleQuotedString(value) } + } - private fun namedArguments(pairs: List>) { - pairs.forEachIndexed { index, pair -> - if (index > 0) write(", ") - write("${pair.first} = ") - singleQuotedString(pair.second) - } + private fun namedArguments(pairs: List>) { + pairs.forEachIndexed { index, pair -> + if (index > 0) write(", ") + write("${pair.first} = ") + singleQuotedString(pair.second) } - - private fun multiLineArguments(values: List) { - incrementIndent() + } + + private fun multiLineArguments(values: List) { + incrementIndent() + endLine() + values.forEachIndexed { index, value -> + if (index > 0) { + write(",") endLine() - values.forEachIndexed { index, value -> - if (index > 0) { - write(",") - endLine() - } - singleQuotedString(value) - } - endLine() - decrementIndent() + } + singleQuotedString(value) } - - private fun namedMultiLineArguments(pairs: List>) { - incrementIndent() + endLine() + decrementIndent() + } + + private fun namedMultiLineArguments(pairs: List>) { + incrementIndent() + endLine() + pairs.forEachIndexed { index, pair -> + if (index > 0) { + write(",") endLine() - pairs.forEachIndexed { index, pair -> - if (index > 0) { - write(",") - endLine() - } - write("${pair.first} = ") - singleQuotedString(pair.second) - } - endLine() - decrementIndent() - } - - protected fun field(fieldName: String, contents: () -> Unit) { - startField(fieldName) - contents() - endField() - } - - protected fun function(functionName: String, contents: () -> Unit) { - startFunction(functionName) - contents() - endFunction() - } - - protected fun multiLineString(contents: () -> Unit) { - startMultiLineString() - contents() - endMultiLineString() + } + write("${pair.first} = ") + singleQuotedString(pair.second) } + endLine() + decrementIndent() + } + + protected fun field(fieldName: String, contents: () -> Unit) { + startField(fieldName) + contents() + endField() + } + + protected fun function(functionName: String, contents: () -> Unit) { + startFunction(functionName) + contents() + endFunction() + } + + protected fun multiLineString(contents: () -> Unit) { + startMultiLineString() + contents() + endMultiLineString() + } } diff --git a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/serialization/ModelScriptWriter.kt b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/serialization/ModelScriptWriter.kt index 63d9d7dc..e5891b8d 100644 --- a/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/serialization/ModelScriptWriter.kt +++ b/polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/serialization/ModelScriptWriter.kt @@ -1,5 +1,9 @@ package org.sonatype.maven.polyglot.kotlin.serialization +import java.io.Writer +import java.time.LocalDate +import java.time.LocalTime +import java.util.* import org.apache.maven.execution.MavenSession import org.apache.maven.model.* import org.apache.maven.plugin.logging.Log @@ -10,17 +14,14 @@ import org.sonatype.maven.polyglot.kotlin.dsl.addAll import org.sonatype.maven.polyglot.kotlin.dsl.addAllNonNull import org.sonatype.maven.polyglot.kotlin.dsl.addFirstNonNull import org.sonatype.maven.polyglot.kotlin.dsl.cast -import java.io.Writer -import java.time.LocalDate -import java.time.LocalTime -import java.util.* /** - * A `ModelScriptWriter` converts a Maven project model into a Kotlin script capable of producing an identical model. - * Instances of this class may be configured with one of two flavors of the Kotlin Model DSL. The most basic flavor, - * "block", consists of simply writing callbacks on each model element and using property setters to initialize its - * fields. All complex model elements can be configured using this "block" flavor of the DSL. The "block" flavor, - * however, does little on its own to reduce the code verbosity of the original XML. + * A `ModelScriptWriter` converts a Maven project model into a Kotlin script capable of producing an + * identical model. Instances of this class may be configured with one of two flavors of the Kotlin + * Model DSL. The most basic flavor, "block", consists of simply writing callbacks on each model + * element and using property setters to initialize its fields. All complex model elements can be + * configured using this "block" flavor of the DSL. The "block" flavor, however, does little on its + * own to reduce the code verbosity of the original XML. * * ``` * project { @@ -77,8 +78,8 @@ import java.util.* * } * ``` * - * The "mixed" flavor leverages optional parameters on block functions as well as additional extension functions and in - * order to minimize the verbosity of specific model elements. + * The "mixed" flavor leverages optional parameters on block functions as well as additional + * extension functions and in order to minimize the verbosity of specific model elements. * * ``` * project("Sample Application") { @@ -106,775 +107,789 @@ import java.util.* * } * } * ``` - * Fields that require values of type [Xpp3Dom] can receive their values as strings or by using the XML builder DSL - * shown in the sample plugin configuration above. + * + * Fields that require values of type [Xpp3Dom] can receive their values as strings or by using the + * XML builder DSL shown in the sample plugin configuration above. */ -internal class ModelScriptWriter( - writer: Writer, - private val options: Map -) : KotlinScriptWriter(writer) { - - private val fileComment: String = (options["file.comment"] as String?) - ?: "Generated from pom.kts on ${LocalDate.now()} at ${LocalTime.now()}" - - // By default, Xpp3Dom values are scripted as a function that accepts a raw (triple-quoted) string. - // When using the XML builder DSL, we script the Xpp3Dom as hierarchy of gets on tag names using an operator - private val useXmlBuilder: Boolean = option("xml.dsl.enabled", false) { it == "true" } - - // The default flavor is to use consistent block semantics all the way down the model. - // When the flavor is "mixed", we'll write the script using additional extensions that - // have been designed to minimize verbosity. - private val flavor: String = option("flavor", "block") { +internal class ModelScriptWriter(writer: Writer, private val options: Map) : + KotlinScriptWriter(writer) { + + private val fileComment: String = + (options["file.comment"] as String?) + ?: "Generated from pom.kts on ${LocalDate.now()} at ${LocalTime.now()}" + + // By default, Xpp3Dom values are scripted as a function that accepts a raw (triple-quoted) + // string. + // When using the XML builder DSL, we script the Xpp3Dom as hierarchy of gets on tag names using + // an operator + private val useXmlBuilder: Boolean = option("xml.dsl.enabled", false) { it == "true" } + + // The default flavor is to use consistent block semantics all the way down the model. + // When the flavor is "mixed", we'll write the script using additional extensions that + // have been designed to minimize verbosity. + private val flavor: String = + option("flavor", "block") { when (it) { - "mixed" -> "mixed" - else -> "block" + "mixed" -> "mixed" + else -> "block" } - } - - private val mixedFlavor: Boolean = flavor == "mixed" - - private val blockFlavor: Boolean = flavor == "block" - - // For convenience in referencing methods inside certain lambdas - private val out: ModelScriptWriter = this - - //-- Public API --------------------------------------------------------------------------------------------------// - - fun write(model: Model) { - - blockComment(fileComment) - - val gavp = with(model) { - "${groupId ?: ""}:${artifactId ?: ""}:${version ?: ""}:${packaging ?: "jar"}" - } - block("project", model, { if (mixedFlavor) it.addFirstNonNull(name, gavp) }) { - - set("modelVersion", modelVersion) { modelVersion != "4.0.0" } - set("modelEncoding", modelEncoding) { modelEncoding != "UTF-8" } - - writeParent(parent) - - if (blockFlavor || name != null) { - endLine() - if (mixedFlavor) { - set("id", gavp) - } else { - set("groupId", groupId) - set("artifactId", artifactId) - set("version", version) - set("packaging", packaging) { packaging != "jar" } - } - } - - if (mixedFlavor && name != null) { - if (listOfNotNull(description, url, inceptionYear).isNotEmpty()) { - endLine() - } - } else { - if (listOfNotNull(name, description, url, inceptionYear).isNotEmpty()) { - endLine() - } - } - - set("name", name) { blockFlavor } - set("description", description) - set("url", url) - set("inceptionYear", inceptionYear) - - writeOrganization(organization) - - block("licenses", licenses) { forEach(out::writeLicense) } - block("developers", developers) { forEach(out::writeDeveloper) } - block("contributors", contributors) { forEach(out::writeContributor) } - block("mailingLists", mailingLists) { forEach(out::writeMailingList) } + } - writePrerequisites(prerequisites) + private val mixedFlavor: Boolean = flavor == "mixed" - block("modules", modules, { it.addAll(modules) }) + private val blockFlavor: Boolean = flavor == "block" - writeScm(scm) - writeIssueManagement(issueManagement) - writeCiManagement(ciManagement) - writeDistributionManagement(distributionManagement) - writeProperties(properties) - writeDependencyManagement(dependencyManagement) + // For convenience in referencing methods inside certain lambdas + private val out: ModelScriptWriter = this - block("dependencies", dependencies) { forEach(out::writeDependency) } - block("repositories", repositories) { forEach(out::writeRepository) } - block("pluginRepositories", pluginRepositories) { forEach(::writePluginRepository) } + // -- Public API + // --------------------------------------------------------------------------------------------------// - writeBuild(build) + fun write(model: Model) { - set("reports", reports as Xpp3Dom?) + blockComment(fileComment) - writeReporting(reporting) - - block("profiles", profiles) { forEach(out::writeProfile) } + val gavp = + with(model) { + "${groupId ?: ""}:${artifactId ?: ""}:${version ?: ""}:${packaging ?: "jar"}" } - } + block("project", model, { if (mixedFlavor) it.addFirstNonNull(name, gavp) }) { + set("modelVersion", modelVersion) { modelVersion != "4.0.0" } + set("modelEncoding", modelEncoding) { modelEncoding != "UTF-8" } - //-- Protected API -----------------------------------------------------------------------------------------------// + writeParent(parent) - private fun writeActivation(activation: Activation?) { - block("activation", activation) { - set("isActiveByDefault", "activeByDefault", isActiveByDefault) { isActiveByDefault } - set("jdk", jdk) - writeActivationOS(os) - writeActivationProperty(property) - writeActivationFile(file) - } - } - - private fun writeActivationFile(activationFile: ActivationFile?) { - block("file", activationFile) { - set("missing", missing) - set("exists", exists) - } - } - - private fun writeActivationOS(activationOS: ActivationOS?) { - block("os", activationOS, { if (mixedFlavor) it.add(name) }) { - set("name", name) { blockFlavor } - set("family", family) - set("arch", arch) - set("version", version) - } - } - - private fun writeActivationProperty(activationProperty: ActivationProperty?) { - block("property", activationProperty, { if (mixedFlavor) it.add(name) }) { - set("name", name) { blockFlavor } - set("value", value) - } - } - - private fun writeBuild(build: Build?) { - block("build", build) { - set("finalName", finalName) - set("defaultGoal", defaultGoal) - set("sourceDirectory", sourceDirectory) - set("testSourceDirectory", testSourceDirectory) - set("scriptSourceDirectory", scriptSourceDirectory) - set("directory", directory) - set("outputDirectory", outputDirectory) - set("testOutputDirectory", testOutputDirectory) - set("filters", filters) - block("resources", resources) { forEach(out::writeResource) } - block("testResources", testResources) { forEach(out::writeTestResource) } - block("extensions", extensions) { forEach(out::writeExtension) } - writePluginManagement(pluginManagement) - block("plugins", plugins) { forEach(out::writePlugin) } + if (blockFlavor || name != null) { + endLine() + if (mixedFlavor) { + set("id", gavp) + } else { + set("groupId", groupId) + set("artifactId", artifactId) + set("version", version) + set("packaging", packaging) { packaging != "jar" } } - } + } - private fun writeBuildBase(buildBase: BuildBase?) { - block("build", buildBase) { - set("defaultGoal", defaultGoal) - set("resources", cast>(resources)) - set("testResources", cast>(testResources)) - set("directory", directory) - set("finalName", finalName) - set("filters", filters) - writePluginManagement(pluginManagement) - block("plugins", plugins) { forEach(out::writePlugin) } + if (mixedFlavor && name != null) { + if (listOfNotNull(description, url, inceptionYear).isNotEmpty()) { + endLine() } - } - - private fun writeCiManagement(ciManagement: CiManagement?) { - block("ciManagement", ciManagement) { - set("system", system) - set("url", url) - block("notifiers", notifiers) { forEach(out::writeNotifier) } + } else { + if (listOfNotNull(name, description, url, inceptionYear).isNotEmpty()) { + endLine() } - } + } + + set("name", name) { blockFlavor } + set("description", description) + set("url", url) + set("inceptionYear", inceptionYear) - private fun writeContributor(contributor: Contributor) { - block("contributor", contributor, { if (mixedFlavor) it.add(name) }) { - set("name", name) { blockFlavor } - set("email", email) - set("url", url) - set("organization", organization) - set("organizationUrl", organizationUrl) - set("roles", roles) - set("timezone", timezone) - writeProperties(properties) - } - } + writeOrganization(organization) + + block("licenses", licenses) { forEach(out::writeLicense) } + block("developers", developers) { forEach(out::writeDeveloper) } + block("contributors", contributors) { forEach(out::writeContributor) } + block("mailingLists", mailingLists) { forEach(out::writeMailingList) } + + writePrerequisites(prerequisites) - private fun writeDependency(dependency: Dependency) { - val gav = with(dependency) { - if (version == null) { - "${groupId ?: ""}:${artifactId ?: ""}" - } else { - "${groupId ?: ""}:${artifactId ?: ""}:${version}" - } - } + block("modules", modules, { it.addAll(modules) }) + + writeScm(scm) + writeIssueManagement(issueManagement) + writeCiManagement(ciManagement) + writeDistributionManagement(distributionManagement) + writeProperties(properties) + writeDependencyManagement(dependencyManagement) + + block("dependencies", dependencies) { forEach(out::writeDependency) } + block("repositories", repositories) { forEach(out::writeRepository) } + block("pluginRepositories", pluginRepositories) { forEach(::writePluginRepository) } + + writeBuild(build) + + set("reports", reports as Xpp3Dom?) + + writeReporting(reporting) + + block("profiles", profiles) { forEach(out::writeProfile) } + } + } + + // -- Protected API + // -----------------------------------------------------------------------------------------------// + + private fun writeActivation(activation: Activation?) { + block("activation", activation) { + set("isActiveByDefault", "activeByDefault", isActiveByDefault) { isActiveByDefault } + set("jdk", jdk) + writeActivationOS(os) + writeActivationProperty(property) + writeActivationFile(file) + } + } + + private fun writeActivationFile(activationFile: ActivationFile?) { + block("file", activationFile) { + set("missing", missing) + set("exists", exists) + } + } + + private fun writeActivationOS(activationOS: ActivationOS?) { + block("os", activationOS, { if (mixedFlavor) it.add(name) }) { + set("name", name) { blockFlavor } + set("family", family) + set("arch", arch) + set("version", version) + } + } + + private fun writeActivationProperty(activationProperty: ActivationProperty?) { + block("property", activationProperty, { if (mixedFlavor) it.add(name) }) { + set("name", name) { blockFlavor } + set("value", value) + } + } + + private fun writeBuild(build: Build?) { + block("build", build) { + set("finalName", finalName) + set("defaultGoal", defaultGoal) + set("sourceDirectory", sourceDirectory) + set("testSourceDirectory", testSourceDirectory) + set("scriptSourceDirectory", scriptSourceDirectory) + set("directory", directory) + set("outputDirectory", outputDirectory) + set("testOutputDirectory", testOutputDirectory) + set("filters", filters) + block("resources", resources) { forEach(out::writeResource) } + block("testResources", testResources) { forEach(out::writeTestResource) } + block("extensions", extensions) { forEach(out::writeExtension) } + writePluginManagement(pluginManagement) + block("plugins", plugins) { forEach(out::writePlugin) } + } + } + + private fun writeBuildBase(buildBase: BuildBase?) { + block("build", buildBase) { + set("defaultGoal", defaultGoal) + set("resources", cast>(resources)) + set("testResources", cast>(testResources)) + set("directory", directory) + set("finalName", finalName) + set("filters", filters) + writePluginManagement(pluginManagement) + block("plugins", plugins) { forEach(out::writePlugin) } + } + } + + private fun writeCiManagement(ciManagement: CiManagement?) { + block("ciManagement", ciManagement) { + set("system", system) + set("url", url) + block("notifiers", notifiers) { forEach(out::writeNotifier) } + } + } + + private fun writeContributor(contributor: Contributor) { + block("contributor", contributor, { if (mixedFlavor) it.add(name) }) { + set("name", name) { blockFlavor } + set("email", email) + set("url", url) + set("organization", organization) + set("organizationUrl", organizationUrl) + set("roles", roles) + set("timezone", timezone) + writeProperties(properties) + } + } + + private fun writeDependency(dependency: Dependency) { + val gav = with(dependency) { - val fields = HashSet() - if (type != null && type != "jar") fields.add("type") - if (classifier != null) fields.add("classifier") - if (scope != null) fields.add("scope") - if (systemPath != null) fields.add("systemPath") - if (!exclusions.isNullOrEmpty()) fields.add("exclusions") - if (isOptional) fields.add("isOptional") - - if (mixedFlavor) { - if (fields.isEmpty()) { - block("dependency", dependency, { it.add(gav) }) - } else if (fields.contains("scope")) { - if (scope == "import" && type == "pom") { - if (fields.size == 2) { - block(scope, dependency, { it.add(gav) }) - } else { - block(scope, dependency, { it.add(gav) }) { - set("classifier", classifier) - writeExclusions(exclusions) - set("isOptional", "optional", isOptional) { isOptional } - } - } - } else if (scope == "system" && systemPath != null) { - if (fields.size == 2) { - block(scope, dependency, { it.addAll(gav, systemPath) }) - } else { - block(scope, dependency, { it.addAll(gav, systemPath) }) { - set("type", type) { type != "jar" } - set("classifier", classifier) - writeExclusions(exclusions) - set("isOptional", "optional", isOptional) { isOptional } - } - } - } else { - if (fields.size == 1) { - block(scope, dependency, { it.add(gav) }) - } else { - block(scope, dependency, { it.add(gav) }) { - set("type", type) { type != "jar" } - set("classifier", classifier) - writeExclusions(exclusions) - set("isOptional", "optional", isOptional) { isOptional } - } - } - } - } else if (fields.contains("isOptional")) { - if (fields.size == 1) { - block("optional", dependency, { it.add(gav) }) - } else { - block("optional", dependency, { it.add(gav) }) { - set("type", type) { type != "jar" } - set("classifier", classifier) - writeExclusions(exclusions) - } - } - } else { - block("dependency", dependency, { it.add(gav) }) { - set("type", type) { type != "jar" } - set("classifier", classifier) - writeExclusions(exclusions) - } - } + if (version == null) { + "${groupId ?: ""}:${artifactId ?: ""}" + } else { + "${groupId ?: ""}:${artifactId ?: ""}:${version}" + } + } + with(dependency) { + val fields = HashSet() + if (type != null && type != "jar") fields.add("type") + if (classifier != null) fields.add("classifier") + if (scope != null) fields.add("scope") + if (systemPath != null) fields.add("systemPath") + if (!exclusions.isNullOrEmpty()) fields.add("exclusions") + if (isOptional) fields.add("isOptional") + + if (mixedFlavor) { + if (fields.isEmpty()) { + block("dependency", dependency, { it.add(gav) }) + } else if (fields.contains("scope")) { + if (scope == "import" && type == "pom") { + if (fields.size == 2) { + block(scope, dependency, { it.add(gav) }) } else { - block("dependency", dependency, { if (mixedFlavor) it.add(gav) }) { - if (blockFlavor) { - set("groupId", groupId) - set("artifactId", artifactId) - set("version", version) - } - set("type", type) { type != "jar" } - set("classifier", classifier) - set("scope", scope) - set("systemPath", systemPath) - writeExclusions(exclusions) - set("isOptional", "optional", isOptional) { isOptional } - } + block(scope, dependency, { it.add(gav) }) { + set("classifier", classifier) + writeExclusions(exclusions) + set("isOptional", "optional", isOptional) { isOptional } + } } - } - } - - private fun writeDependencyManagement(dependencyManagement: DependencyManagement?) { - block("dependencyManagement", dependencyManagement) { - block("dependencies", dependencies) { - forEach(out::writeDependency) - } - } - } - - private fun writeDeploymentRepository(deploymentRepository: DeploymentRepository?, blockName: String) { - block(blockName, deploymentRepository, { if (mixedFlavor) it.addFirstNonNull(name, id) }) { - set("id", id) { blockFlavor || (name != null && name != id) } - set("name", name) { blockFlavor } - set("url", url) - set("layout", layout) { layout != "default" } - set("isUniqueVersion", "uniqueVersion", isUniqueVersion) { !isUniqueVersion } - } - } - - private fun writeDeveloper(developer: Developer) { - if (mixedFlavor && developer.email != null) { - val address = if (developer.name != null) { - "${developer.name} <${developer.email}>" + } else if (scope == "system" && systemPath != null) { + if (fields.size == 2) { + block(scope, dependency, { it.addAll(gav, systemPath) }) } else { - developer.email + block(scope, dependency, { it.addAll(gav, systemPath) }) { + set("type", type) { type != "jar" } + set("classifier", classifier) + writeExclusions(exclusions) + set("isOptional", "optional", isOptional) { isOptional } + } } - val id = if (developer.id != developer.email.split('@')[0]) developer.id else null - if (id != null || developer.url != null || developer.organization != null || developer.organizationUrl != null || !developer.roles.isNullOrEmpty() || developer.timezone != null || !developer.properties.isNullOrEmpty()) { - block("developer", developer, { it.add(address) }) { - set("id", id) { id != developer.email.split('@')[0] } - set("url", url) - set("organization", organization) - set("organizationUrl", organizationUrl) - set("roles", roles) - set("timezone", timezone) - writeProperties(properties) - } + } else { + if (fields.size == 1) { + block(scope, dependency, { it.add(gav) }) } else { - block("developer", developer, { it.add(address) }) + block(scope, dependency, { it.add(gav) }) { + set("type", type) { type != "jar" } + set("classifier", classifier) + writeExclusions(exclusions) + set("isOptional", "optional", isOptional) { isOptional } + } } - } else { - block("developer", developer, { if (mixedFlavor) it.addFirstNonNull(name, id) }) { - set("id", id) { blockFlavor || (name != null && name != id) } - set("name", name) { blockFlavor } - set("email", email) - set("url", url) - set("organization", organization) - set("organizationUrl", organizationUrl) - set("roles", roles) - set("timezone", timezone) - writeProperties(properties) + } + } else if (fields.contains("isOptional")) { + if (fields.size == 1) { + block("optional", dependency, { it.add(gav) }) + } else { + block("optional", dependency, { it.add(gav) }) { + set("type", type) { type != "jar" } + set("classifier", classifier) + writeExclusions(exclusions) } - } - } - - private fun writeDistributionManagement(distributionManagement: DistributionManagement?) { - block("distributionManagement", distributionManagement) { - writeDeploymentRepository(repository) - writeDeploymentSnapshotRepository(snapshotRepository) - writeSite(site) - set("downloadUrl", downloadUrl) - writeRelocation(relocation) - set("status", status) - } - } - - private fun writeExclusion(exclusion: Exclusion) { - block("exclusion", exclusion) { + } + } else { + block("dependency", dependency, { it.add(gav) }) { + set("type", type) { type != "jar" } + set("classifier", classifier) + writeExclusions(exclusions) + } + } + } else { + block("dependency", dependency, { if (mixedFlavor) it.add(gav) }) { + if (blockFlavor) { set("groupId", groupId) set("artifactId", artifactId) - } - } - - private fun writeExclusions(exclusions: List?) { - if (mixedFlavor) { - block("exclusions", exclusions, { args -> - args.addAll(map { - "${it.groupId ?: ""}:${it.artifactId ?: ""}" - }) - }) - } else { - block("exclusions", exclusions) { forEach(out::writeExclusion) } - } - } - - private fun writeExtension(extension: Extension) { - if (mixedFlavor) { - val gav = with(extension) { - if (version == null) { - "${groupId ?: ""}:${artifactId ?: ""}" - } else { - "${groupId ?: ""}:${artifactId ?: ""}:${version}" - } - } - block("extension", extension, { it.add(gav) }) - } else { - block("extension", extension) { - set("groupId", groupId) - set("artifactId", artifactId) - set("version", version) - } - } - } - - private fun writeIssueManagement(issueManagement: IssueManagement?) { - block("issueManagement", issueManagement) { - set("system", system) - set("url", url) - } - } - - private fun writeLicense(license: License) { - block("license", license, { if (mixedFlavor) it.add(name) }) { - set("name", name) { blockFlavor } - set("url", url) - set("distribution", distribution) - set("comments", comments) - } - } - - private fun writeMailingList(mailingList: MailingList) { - block("mailingList", mailingList, { if (mixedFlavor) it.add(name) }) { - set("name", name) { blockFlavor } - set("subscribe", subscribe) - set("unsubscribe", unsubscribe) - set("post", post) - set("archive", archive) - set("otherArchives", otherArchives) - } - } - - private fun writeNotifier(notifier: Notifier) { - block("notifier", notifier) { - set("type", type) { type != "mail" } - set("address", address) - set("isSendOnError", "sendOnError", isSendOnError) { !isSendOnError } - set("isSendOnFailure", "sendOnFailure", isSendOnFailure) { !isSendOnFailure } - set("isSendOnSuccess", "sendOnSuccess", isSendOnSuccess) { !isSendOnFailure } - set("isSendOnWarning", "sendOnWarning", isSendOnWarning) { !isSendOnFailure } - writeProperties(configuration, "configuration") - } - } - - private fun writeOrganization(organization: Organization?) { - if (mixedFlavor) { - block("organization", organization, { it.addAllNonNull(name, url) }) - } else { - block("organization", organization) { - set("name", name) - set("url", url) - } - } - } - - private fun writeParent(parent: Parent?) { - if (mixedFlavor) { - block("parent", parent, { it.addAll(groupId, artifactId, version, relativePath) }) - } else { - block("parent", parent) { - set("groupId", groupId) - set("artifactId", artifactId) - set("version", version) - set("relativePath", relativePath) { relativePath != "../pom.kts" } - } - } - } - - private fun writePlugin(plugin: Plugin) { - val gav = with(plugin) { - val groupId = if (groupId == null) "" else groupId + set("version", version) + } + set("type", type) { type != "jar" } + set("classifier", classifier) + set("scope", scope) + set("systemPath", systemPath) + writeExclusions(exclusions) + set("isOptional", "optional", isOptional) { isOptional } + } + } + } + } + + private fun writeDependencyManagement(dependencyManagement: DependencyManagement?) { + block("dependencyManagement", dependencyManagement) { + block("dependencies", dependencies) { forEach(out::writeDependency) } + } + } + + private fun writeDeploymentRepository( + deploymentRepository: DeploymentRepository?, + blockName: String + ) { + block(blockName, deploymentRepository, { if (mixedFlavor) it.addFirstNonNull(name, id) }) { + set("id", id) { blockFlavor || (name != null && name != id) } + set("name", name) { blockFlavor } + set("url", url) + set("layout", layout) { layout != "default" } + set("isUniqueVersion", "uniqueVersion", isUniqueVersion) { !isUniqueVersion } + } + } + + private fun writeDeveloper(developer: Developer) { + if (mixedFlavor && developer.email != null) { + val address = + if (developer.name != null) { + "${developer.name} <${developer.email}>" + } else { + developer.email + } + val id = if (developer.id != developer.email.split('@')[0]) developer.id else null + if (id != null || + developer.url != null || + developer.organization != null || + developer.organizationUrl != null || + !developer.roles.isNullOrEmpty() || + developer.timezone != null || + !developer.properties.isNullOrEmpty()) { + block("developer", developer, { it.add(address) }) { + set("id", id) { id != developer.email.split('@')[0] } + set("url", url) + set("organization", organization) + set("organizationUrl", organizationUrl) + set("roles", roles) + set("timezone", timezone) + writeProperties(properties) + } + } else { + block("developer", developer, { it.add(address) }) + } + } else { + block("developer", developer, { if (mixedFlavor) it.addFirstNonNull(name, id) }) { + set("id", id) { blockFlavor || (name != null && name != id) } + set("name", name) { blockFlavor } + set("email", email) + set("url", url) + set("organization", organization) + set("organizationUrl", organizationUrl) + set("roles", roles) + set("timezone", timezone) + writeProperties(properties) + } + } + } + + private fun writeDistributionManagement(distributionManagement: DistributionManagement?) { + block("distributionManagement", distributionManagement) { + writeDeploymentRepository(repository) + writeDeploymentSnapshotRepository(snapshotRepository) + writeSite(site) + set("downloadUrl", downloadUrl) + writeRelocation(relocation) + set("status", status) + } + } + + private fun writeExclusion(exclusion: Exclusion) { + block("exclusion", exclusion) { + set("groupId", groupId) + set("artifactId", artifactId) + } + } + + private fun writeExclusions(exclusions: List?) { + if (mixedFlavor) { + block( + "exclusions", + exclusions, + { args -> args.addAll(map { "${it.groupId ?: ""}:${it.artifactId ?: ""}" }) }) + } else { + block("exclusions", exclusions) { forEach(out::writeExclusion) } + } + } + + private fun writeExtension(extension: Extension) { + if (mixedFlavor) { + val gav = + with(extension) { if (version == null) { - "${groupId}:${artifactId ?: ""}" + "${groupId ?: ""}:${artifactId ?: ""}" } else { - "${groupId}:${artifactId ?: ""}:${version}" + "${groupId ?: ""}:${artifactId ?: ""}:${version}" } - } + } + block("extension", extension, { it.add(gav) }) + } else { + block("extension", extension) { + set("groupId", groupId) + set("artifactId", artifactId) + set("version", version) + } + } + } + + private fun writeIssueManagement(issueManagement: IssueManagement?) { + block("issueManagement", issueManagement) { + set("system", system) + set("url", url) + } + } + + private fun writeLicense(license: License) { + block("license", license, { if (mixedFlavor) it.add(name) }) { + set("name", name) { blockFlavor } + set("url", url) + set("distribution", distribution) + set("comments", comments) + } + } + + private fun writeMailingList(mailingList: MailingList) { + block("mailingList", mailingList, { if (mixedFlavor) it.add(name) }) { + set("name", name) { blockFlavor } + set("subscribe", subscribe) + set("unsubscribe", unsubscribe) + set("post", post) + set("archive", archive) + set("otherArchives", otherArchives) + } + } + + private fun writeNotifier(notifier: Notifier) { + block("notifier", notifier) { + set("type", type) { type != "mail" } + set("address", address) + set("isSendOnError", "sendOnError", isSendOnError) { !isSendOnError } + set("isSendOnFailure", "sendOnFailure", isSendOnFailure) { !isSendOnFailure } + set("isSendOnSuccess", "sendOnSuccess", isSendOnSuccess) { !isSendOnFailure } + set("isSendOnWarning", "sendOnWarning", isSendOnWarning) { !isSendOnFailure } + writeProperties(configuration, "configuration") + } + } + + private fun writeOrganization(organization: Organization?) { + if (mixedFlavor) { + block("organization", organization, { it.addAllNonNull(name, url) }) + } else { + block("organization", organization) { + set("name", name) + set("url", url) + } + } + } + + private fun writeParent(parent: Parent?) { + if (mixedFlavor) { + block("parent", parent, { it.addAll(groupId, artifactId, version, relativePath) }) + } else { + block("parent", parent) { + set("groupId", groupId) + set("artifactId", artifactId) + set("version", version) + set("relativePath", relativePath) { relativePath != "../pom.kts" } + } + } + } + + private fun writePlugin(plugin: Plugin) { + val gav = with(plugin) { - if (mixedFlavor && extensions.isNullOrEmpty() && executions.isNullOrEmpty() && - dependencies.isNullOrEmpty() && isInherited && configuration == null) { - block("plugin", plugin, { it.add(gav) }) - } else { - block("plugin", plugin, { if (mixedFlavor) it.add(gav) }) { - if (blockFlavor) { - set("groupId", groupId) - set("artifactId", artifactId) - set("version", version) - } - set("extensions", extensions) - block("executions", executions) { forEach(out::writePluginExecution) } - block("dependencies", dependencies) { forEach(out::writeDependency) } - set("isInherited", "inherited", isInherited) { !isInherited } - set("configuration", configuration as Xpp3Dom?) - } - } - } - } - - private fun writePluginExecution(pluginExecution: PluginExecution) { - block("execution", pluginExecution, { if (mixedFlavor && id != "default") it.add(id) }) { - set("id", id) { id != "default" && blockFlavor } - set("phase", phase) - set("goals", goals) - set("isInherited", "inherited", isInherited) { !isInherited } - set("configuration", configuration as Xpp3Dom?) - } - } - - private fun writePluginManagement(pluginManagement: PluginManagement?) { - block("pluginManagement", pluginManagement) { - block("plugins", plugins) { forEach(out::writePlugin) } - } - } - - private fun writePrerequisites(prerequisites: Prerequisites?) { - block("prerequisites", prerequisites) { - set("maven", maven) { maven != "2.0" } - } - } - - private fun writeProfile(profile: Profile) { - block("profile", profile, { if (mixedFlavor) it.add(id) }) { - set("id", id) { id != "default" && blockFlavor } - - writeActivation(activation) - - block("modules", modules, { it.addAll(modules) }) - - writeDistributionManagement(distributionManagement) - writeProperties(properties) - writeDependencyManagement(dependencyManagement) - - block("dependencies", dependencies) { forEach(out::writeDependency) } - block("repositories", repositories) { forEach(out::writeRepository) } - block("pluginRepositories", pluginRepositories) { forEach(out::writePluginRepository) } - - writeBuildBase(build) - - set("reports", reports as Xpp3Dom?) - - writeReporting(reporting) - } - } - - private fun writeProperties(properties: Properties?, blockName: String = "properties") { - @Suppress("UNCHECKED_CAST") - block(blockName, properties as Map) { - entries - .sortedBy { entry -> entry.key } - .forEach { entry -> - writePair(entry.key to entry.value) - endLine() - } - } - } - - private fun writeRelocation(relocation: Relocation?) { - block("relocation", relocation) { + val groupId = if (groupId == null) "" else groupId + if (version == null) { + "${groupId}:${artifactId ?: ""}" + } else { + "${groupId}:${artifactId ?: ""}:${version}" + } + } + with(plugin) { + if (mixedFlavor && + extensions.isNullOrEmpty() && + executions.isNullOrEmpty() && + dependencies.isNullOrEmpty() && + isInherited && + configuration == null) { + block("plugin", plugin, { it.add(gav) }) + } else { + block("plugin", plugin, { if (mixedFlavor) it.add(gav) }) { + if (blockFlavor) { set("groupId", groupId) set("artifactId", artifactId) set("version", version) - set("message", message) + } + set("extensions", extensions) + block("executions", executions) { forEach(out::writePluginExecution) } + block("dependencies", dependencies) { forEach(out::writeDependency) } + set("isInherited", "inherited", isInherited) { !isInherited } + set("configuration", configuration as Xpp3Dom?) } + } } + } - private fun writeReportPlugin(reportPlugin: ReportPlugin) { - val gav = with(reportPlugin) { - val groupId = if (groupId == null) "" else groupId - if (version == null) { - "${groupId}:${artifactId ?: ""}" - } else { - "${groupId}:${artifactId ?: ""}:${version}" - } - } - with(reportPlugin) { - if (mixedFlavor && reportSets.isNullOrEmpty() && isInherited && configuration == null) { - block("plugin", reportPlugin, { it.add(gav) }) - } else { - block("plugin", reportPlugin, { if (mixedFlavor) it.add(gav) }) { - if (blockFlavor) { - set("groupId", groupId) - set("artifactId", artifactId) - set("version", version) - } - block("reportSets", reportSets) { forEach(out::writeReportSet) } - set("isInherited", "inherited", isInherited) { !isInherited } - set("configuration", configuration as Xpp3Dom?) - } - } - } + private fun writePluginExecution(pluginExecution: PluginExecution) { + block("execution", pluginExecution, { if (mixedFlavor && id != "default") it.add(id) }) { + set("id", id) { id != "default" && blockFlavor } + set("phase", phase) + set("goals", goals) + set("isInherited", "inherited", isInherited) { !isInherited } + set("configuration", configuration as Xpp3Dom?) } + } - private fun writeReportSet(reportSet: ReportSet) { - block("reportSet", reportSet, { if (mixedFlavor) it.add(id) }) { - set("id", id) { id != "default" } - set("reports", reports) - set("isInherited", "inherited", isInherited) { !isInherited } - set("configuration", configuration as Xpp3Dom?) - } + private fun writePluginManagement(pluginManagement: PluginManagement?) { + block("pluginManagement", pluginManagement) { + block("plugins", plugins) { forEach(out::writePlugin) } } + } - private fun writeReporting(reporting: Reporting?) { - block("reporting", reporting) { - set("isExcludeDefaults", "excludeDefaults", isExcludeDefaults) { !isExcludeDefaults } - set("outputDirectory", outputDirectory) - block("plugins", plugins) { forEach(out::writeReportPlugin) } - } - } + private fun writePrerequisites(prerequisites: Prerequisites?) { + block("prerequisites", prerequisites) { set("maven", maven) { maven != "2.0" } } + } - private fun writeRepository(repository: Repository, blockName: String) { - block(blockName, repository, { if (mixedFlavor) it.addFirstNonNull(name, id) }) { - set("id", id) { blockFlavor || (name != null && name != id) } - set("name", name) { blockFlavor } - set("url", url) - set("layout", layout) { layout != "default" } - writeReleaseRepositoryPolicy(releases) - writeSnapshotRepositoryPolicy(snapshots) - } - } + private fun writeProfile(profile: Profile) { + block("profile", profile, { if (mixedFlavor) it.add(id) }) { + set("id", id) { id != "default" && blockFlavor } - private fun writeRepositoryPolicy(repositoryPolicy: RepositoryPolicy?, blockName: String) { - block(blockName, repositoryPolicy) { - set("isEnabled", "enabled", isEnabled) { !isEnabled } - set("updatePolicy", updatePolicy) - set("checksumPolicy", checksumPolicy) - } - } + writeActivation(activation) - private fun writeResource(resource: Resource, blockName: String) { - block(blockName, resource) { - set("targetPath", targetPath) - set("isFiltering", "filtering", isFiltering) { !isFiltering } - set("directory", directory) - set("includes", includes) - set("excludes", excludes) - } - } + block("modules", modules, { it.addAll(modules) }) - private fun writeScm(scm: Scm?) { - block("scm", scm) { - set("url", url) - set("connection", connection) - set("developerConnection", developerConnection) - set("tag", tag) { tag != "HEAD" } - } - } + writeDistributionManagement(distributionManagement) + writeProperties(properties) + writeDependencyManagement(dependencyManagement) - private fun writeSite(site: Site?) { - block("site", site, { if (mixedFlavor) it.addFirstNonNull(name, id) }) { - set("id", id) { blockFlavor || (name != null && name != id) } - set("name", name) { blockFlavor } - set("url", url) - } - } + block("dependencies", dependencies) { forEach(out::writeDependency) } + block("repositories", repositories) { forEach(out::writeRepository) } + block("pluginRepositories", pluginRepositories) { forEach(out::writePluginRepository) } - private fun set(fieldName: String, value: String?, test: (() -> Boolean) = { true }) { - if (value != null && test()) { - val content: () -> Unit = { singleQuotedString(value) } - if (mixedFlavor) { - function(fieldName, content) - } else { - field(fieldName, content) - } - endLine() - } + writeBuildBase(build) + + set("reports", reports as Xpp3Dom?) + + writeReporting(reporting) } + } - private fun set(fieldName: String, functionName: String, value: Boolean, test: (() -> Boolean) = { true }) { - if (test()) { - val content: () -> Unit = { write(value.toString()) } - if (mixedFlavor) { - function(functionName, content) - } else { - field(fieldName, content) - } + private fun writeProperties(properties: Properties?, blockName: String = "properties") { + @Suppress("UNCHECKED_CAST") + block(blockName, properties as Map) { + entries + .sortedBy { entry -> entry.key } + .forEach { entry -> + writePair(entry.key to entry.value) endLine() - } + } } + } - private fun set(fieldName: String, values: List?) { - if (!values.isNullOrEmpty()) { - if (mixedFlavor) { - function(fieldName) { - arguments(values) - } - } else { - field(fieldName) { - function("listOf") { - arguments(values) - } - } - } - endLine() - } + private fun writeRelocation(relocation: Relocation?) { + block("relocation", relocation) { + set("groupId", groupId) + set("artifactId", artifactId) + set("version", version) + set("message", message) } + } - private fun set(fieldName: String, xml: Xpp3Dom?) { - when { - xml == null -> return - useXmlBuilder -> { - block(xml.name, xml) { - children.forEach { writeXpp3Dom(it) } - } - } - else -> { - if (indentLevel == 1) { - endLine() - } - field(fieldName) { - multiLineString { - val str = xml.toString() - .replace(Regex("""(?s)\Q\E\s*"""), "") - .replace("$", "\${\"$\"}") - str.lines().forEach { - if (it.isNotEmpty()) { - write(it) - endLine() - } - } - } - } + private fun writeReportPlugin(reportPlugin: ReportPlugin) { + val gav = + with(reportPlugin) { + val groupId = if (groupId == null) "" else groupId + if (version == null) { + "${groupId}:${artifactId ?: ""}" + } else { + "${groupId}:${artifactId ?: ""}:${version}" + } + } + with(reportPlugin) { + if (mixedFlavor && reportSets.isNullOrEmpty() && isInherited && configuration == null) { + block("plugin", reportPlugin, { it.add(gav) }) + } else { + block("plugin", reportPlugin, { if (mixedFlavor) it.add(gav) }) { + if (blockFlavor) { + set("groupId", groupId) + set("artifactId", artifactId) + set("version", version) + } + block("reportSets", reportSets) { forEach(out::writeReportSet) } + set("isInherited", "inherited", isInherited) { !isInherited } + set("configuration", configuration as Xpp3Dom?) + } + } + } + } + + private fun writeReportSet(reportSet: ReportSet) { + block("reportSet", reportSet, { if (mixedFlavor) it.add(id) }) { + set("id", id) { id != "default" } + set("reports", reports) + set("isInherited", "inherited", isInherited) { !isInherited } + set("configuration", configuration as Xpp3Dom?) + } + } + + private fun writeReporting(reporting: Reporting?) { + block("reporting", reporting) { + set("isExcludeDefaults", "excludeDefaults", isExcludeDefaults) { !isExcludeDefaults } + set("outputDirectory", outputDirectory) + block("plugins", plugins) { forEach(out::writeReportPlugin) } + } + } + + private fun writeRepository(repository: Repository, blockName: String) { + block(blockName, repository, { if (mixedFlavor) it.addFirstNonNull(name, id) }) { + set("id", id) { blockFlavor || (name != null && name != id) } + set("name", name) { blockFlavor } + set("url", url) + set("layout", layout) { layout != "default" } + writeReleaseRepositoryPolicy(releases) + writeSnapshotRepositoryPolicy(snapshots) + } + } + + private fun writeRepositoryPolicy(repositoryPolicy: RepositoryPolicy?, blockName: String) { + block(blockName, repositoryPolicy) { + set("isEnabled", "enabled", isEnabled) { !isEnabled } + set("updatePolicy", updatePolicy) + set("checksumPolicy", checksumPolicy) + } + } + + private fun writeResource(resource: Resource, blockName: String) { + block(blockName, resource) { + set("targetPath", targetPath) + set("isFiltering", "filtering", isFiltering) { !isFiltering } + set("directory", directory) + set("includes", includes) + set("excludes", excludes) + } + } + + private fun writeScm(scm: Scm?) { + block("scm", scm) { + set("url", url) + set("connection", connection) + set("developerConnection", developerConnection) + set("tag", tag) { tag != "HEAD" } + } + } + + private fun writeSite(site: Site?) { + block("site", site, { if (mixedFlavor) it.addFirstNonNull(name, id) }) { + set("id", id) { blockFlavor || (name != null && name != id) } + set("name", name) { blockFlavor } + set("url", url) + } + } + + private fun set(fieldName: String, value: String?, test: (() -> Boolean) = { true }) { + if (value != null && test()) { + val content: () -> Unit = { singleQuotedString(value) } + if (mixedFlavor) { + function(fieldName, content) + } else { + field(fieldName, content) + } + endLine() + } + } + + private fun set( + fieldName: String, + functionName: String, + value: Boolean, + test: (() -> Boolean) = { true } + ) { + if (test()) { + val content: () -> Unit = { write(value.toString()) } + if (mixedFlavor) { + function(functionName, content) + } else { + field(fieldName, content) + } + endLine() + } + } + + private fun set(fieldName: String, values: List?) { + if (!values.isNullOrEmpty()) { + if (mixedFlavor) { + function(fieldName) { arguments(values) } + } else { + field(fieldName) { function("listOf") { arguments(values) } } + } + endLine() + } + } + + private fun set(fieldName: String, xml: Xpp3Dom?) { + when { + xml == null -> return + useXmlBuilder -> { + block(xml.name, xml) { children.forEach { writeXpp3Dom(it) } } + } + else -> { + if (indentLevel == 1) { + endLine() + } + field(fieldName) { + multiLineString { + val str = + xml.toString() + .replace(Regex("""(?s)\Q\E\s*"""), "") + .replace("$", "\${\"$\"}") + str.lines().forEach { + if (it.isNotEmpty()) { + write(it) endLine() + } } + } } + endLine() + } } + } - private fun writeXpp3Dom(xml: Xpp3Dom) { - if (xml.value == null) { - block("\"${xml.name}\"", xml) { - children.forEach { writeXpp3Dom(it) } - } - } else { - writePair(Pair(xml.name, xml.value)) - endLine() - } + private fun writeXpp3Dom(xml: Xpp3Dom) { + if (xml.value == null) { + block("\"${xml.name}\"", xml) { children.forEach { writeXpp3Dom(it) } } + } else { + writePair(Pair(xml.name, xml.value)) + endLine() } + } - private val executeContext: ExecuteContext = ExecuteContextStub() - - private class ExecuteContextStub : ExecuteContext { - override fun getProject(): MavenProject { - throw NotImplementedError("not implemented") - } - - override fun getSession(): MavenSession { - throw NotImplementedError("not implemented") - } + private val executeContext: ExecuteContext = ExecuteContextStub() - override fun getLog(): Log { - throw NotImplementedError("not implemented") - } + private class ExecuteContextStub : ExecuteContext { + override fun getProject(): MavenProject { + throw NotImplementedError("not implemented") } - private fun writeDeploymentRepository(deploymentRepository: DeploymentRepository?) { - writeDeploymentRepository(deploymentRepository, "repository") + override fun getSession(): MavenSession { + throw NotImplementedError("not implemented") } - private fun writeDeploymentSnapshotRepository(deploymentRepository: DeploymentRepository?) { - writeDeploymentRepository(deploymentRepository, "snapshotRepository") + override fun getLog(): Log { + throw NotImplementedError("not implemented") } + } - private fun writeRepository(repository: Repository) { - writeRepository(repository, "repository") - } + private fun writeDeploymentRepository(deploymentRepository: DeploymentRepository?) { + writeDeploymentRepository(deploymentRepository, "repository") + } - private fun writePluginRepository(repository: Repository) { - writeRepository(repository, "pluginRepository") - } + private fun writeDeploymentSnapshotRepository(deploymentRepository: DeploymentRepository?) { + writeDeploymentRepository(deploymentRepository, "snapshotRepository") + } - private fun writeReleaseRepositoryPolicy(repositoryPolicy: RepositoryPolicy?) { - writeRepositoryPolicy(repositoryPolicy, "releases") - } + private fun writeRepository(repository: Repository) { + writeRepository(repository, "repository") + } - private fun writeSnapshotRepositoryPolicy(repositoryPolicy: RepositoryPolicy?) { - writeRepositoryPolicy(repositoryPolicy, "snapshots") - } + private fun writePluginRepository(repository: Repository) { + writeRepository(repository, "pluginRepository") + } - private fun writeResource(resource: Resource) { - writeResource(resource, "resource") - } + private fun writeReleaseRepositoryPolicy(repositoryPolicy: RepositoryPolicy?) { + writeRepositoryPolicy(repositoryPolicy, "releases") + } - private fun writeTestResource(resource: Resource) { - writeResource(resource, "testResource") - } + private fun writeSnapshotRepositoryPolicy(repositoryPolicy: RepositoryPolicy?) { + writeRepositoryPolicy(repositoryPolicy, "snapshots") + } - private fun option(key: String, default: T, converter: (String) -> T): T { - val value = options[key] ?: return default - return converter(value.toString()) - } + private fun writeResource(resource: Resource) { + writeResource(resource, "resource") + } + + private fun writeTestResource(resource: Resource) { + writeResource(resource, "testResource") + } + + private fun option(key: String, default: T, converter: (String) -> T): T { + val value = options[key] ?: return default + return converter(value.toString()) + } } diff --git a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinMappingTest.kt b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinMappingTest.kt index c194b4fd..337f99f3 100644 --- a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinMappingTest.kt +++ b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinMappingTest.kt @@ -9,15 +9,16 @@ import org.sonatype.maven.polyglot.mapping.Mapping class KotlinMappingTest : PlexusTestCase() { - override fun customizeContainerConfiguration(configuration: ContainerConfiguration?) { - configuration?.autoWiring = true; - configuration?.classPathScanning = PlexusConstants.SCANNING_CACHE - } + override fun customizeContainerConfiguration(configuration: ContainerConfiguration?) { + configuration?.autoWiring = true + configuration?.classPathScanning = PlexusConstants.SCANNING_CACHE + } - @Test - fun testMapping() { - val mapping = lookup(Mapping::class.java, "kotlin") - val options = mapOf("org.apache.maven.model.building.source" to "/polyglot-maven/polyglot-kotlin/pom.kts") - Assert.assertTrue(mapping.accept(options)) - } + @Test + fun testMapping() { + val mapping = lookup(Mapping::class.java, "kotlin") + val options = + mapOf("org.apache.maven.model.building.source" to "/polyglot-maven/polyglot-kotlin/pom.kts") + Assert.assertTrue(mapping.accept(options)) + } } diff --git a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelReaderTests.kt b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelReaderTests.kt index 0104b974..94fbf681 100644 --- a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelReaderTests.kt +++ b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelReaderTests.kt @@ -5,20 +5,25 @@ import org.sonatype.maven.polyglot.kotlin.testing.AbstractModelTestCase class KotlinModelReaderTests(testName: String) : AbstractModelTestCase(testName) { - //@formatter:off + // @formatter:off - @Test fun `test#example`() = doTest() + @Test fun `test#example`() = doTest() - @Test fun `test#convert#kotlin-to-xml#variation-0`() = doTest() - @Test fun `test#convert#kotlin-to-xml#variation-1`() = doTest() - @Test fun `test#convert#kotlin-to-xml#variation-2`() = doTest() - @Test fun `test#convert#kotlin-to-xml#variation-3`() = doTest() - @Test fun `test#convert#kotlin-to-xml#variation-4`() = doTest() - @Test fun `test#convert#kotlin-to-xml#variation-5`() = doTest() + @Test fun `test#convert#kotlin-to-xml#variation-0`() = doTest() - // @formatter:on + @Test fun `test#convert#kotlin-to-xml#variation-1`() = doTest() - private fun doTest() { - assertEquals(pomXml, pomKts.kts2model().model2xml()) - } + @Test fun `test#convert#kotlin-to-xml#variation-2`() = doTest() + + @Test fun `test#convert#kotlin-to-xml#variation-3`() = doTest() + + @Test fun `test#convert#kotlin-to-xml#variation-4`() = doTest() + + @Test fun `test#convert#kotlin-to-xml#variation-5`() = doTest() + + // @formatter:on + + private fun doTest() { + assertEquals(pomXml, pomKts.kts2model().model2xml()) + } } diff --git a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelWriterTests.kt b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelWriterTests.kt index 42a7c476..17ce46f8 100644 --- a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelWriterTests.kt +++ b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelWriterTests.kt @@ -5,48 +5,44 @@ import org.junit.Test import org.sonatype.maven.polyglot.kotlin.testing.AbstractModelTestCase // TODO: fix this and re-enable tests -@Ignore( "about to inject MavenProject -> OutOfScopeEx" ) +@Ignore("about to inject MavenProject -> OutOfScopeEx") class KotlinModelWriterTests(testName: String) : AbstractModelTestCase(testName) { - @Test - fun `test#convert#xml-to-kotlin#variation-0`() { - doTest( - "file.comment" to "${this::class.simpleName}\n$testBasePath", - "xml.dsl.enabled" to false, - "flavor" to "block" - ) - } + @Test + fun `test#convert#xml-to-kotlin#variation-0`() { + doTest( + "file.comment" to "${this::class.simpleName}\n$testBasePath", + "xml.dsl.enabled" to false, + "flavor" to "block") + } - @Test - fun `test#convert#xml-to-kotlin#variation-1`() { - doTest( - "file.comment" to "${this::class.simpleName}\n$testBasePath", - "xml.dsl.enabled" to true, - "flavor" to "mixed" - ) - } + @Test + fun `test#convert#xml-to-kotlin#variation-1`() { + doTest( + "file.comment" to "${this::class.simpleName}\n$testBasePath", + "xml.dsl.enabled" to true, + "flavor" to "mixed") + } - @Test - fun `test#convert#xml-to-kotlin#variation-2`() { - doTest( - "file.comment" to "${this::class.simpleName}\n$testBasePath", - "xml.dsl.enabled" to false, - "flavor" to "block" - ) - } + @Test + fun `test#convert#xml-to-kotlin#variation-2`() { + doTest( + "file.comment" to "${this::class.simpleName}\n$testBasePath", + "xml.dsl.enabled" to false, + "flavor" to "block") + } - @Test - fun `test#convert#xml-to-kotlin#variation-3`() { - doTest( - "file.comment" to "${this::class.simpleName}\n$testBasePath", - "xml.dsl.enabled" to true, - "flavor" to "mixed" - ) - } + @Test + fun `test#convert#xml-to-kotlin#variation-3`() { + doTest( + "file.comment" to "${this::class.simpleName}\n$testBasePath", + "xml.dsl.enabled" to true, + "flavor" to "mixed") + } - private fun doTest(vararg options: Pair) { - val kts = pomXml.xml2model(*options).model2kts(*options) - assertEquals(pomKts, kts) - assertEquals(pomXml, kts.kts2model().model2xml()) - } + private fun doTest(vararg options: Pair) { + val kts = pomXml.xml2model(*options).model2kts(*options) + assertEquals(pomKts, kts) + assertEquals(pomXml, kts.kts2model().model2xml()) + } } diff --git a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/UnitTests.kt b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/UnitTests.kt index 5fc8e336..d346e7cd 100644 --- a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/UnitTests.kt +++ b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/UnitTests.kt @@ -1,162 +1,243 @@ package org.sonatype.maven.polyglot.kotlin -import org.assertj.core.api.Assertions.assertThat import org.junit.Test import org.sonatype.maven.polyglot.kotlin.testing.AbstractModelTestCase class UnitTests(testName: String) : AbstractModelTestCase(testName) { - //@formatter:off - - @Test fun `test#unit-tests#artifactId#variation-1`() = doTest() - @Test fun `test#unit-tests#artifactId#variation-2`() = doTest() - @Test fun `test#unit-tests#artifactId#variation-3`() = doTest() - @Test fun `test#unit-tests#artifactId#variation-4`() = doTest() - @Test fun `test#unit-tests#artifactId#variation-5`() = doTest() - @Test fun `test#unit-tests#artifactId#variation-6`() = doTest() - - @Test fun `test#unit-tests#build#variation-1`() = doTest() - @Test fun `test#unit-tests#build#variation-2`() = doTest() - @Test fun `test#unit-tests#build#variation-3`() = doTest() - @Test fun `test#unit-tests#build#variation-4`() = doTest() - @Test fun `test#unit-tests#build#variation-5`() = doTest() - @Test fun `test#unit-tests#build#variation-6`() = doTest() - - @Test fun `test#unit-tests#ciManagement#variation-1`() = doTest() - @Test fun `test#unit-tests#ciManagement#variation-2`() = doTest() - - @Test fun `test#unit-tests#contributors#variation-1`() = doTest() - @Test fun `test#unit-tests#contributors#variation-2`() = doTest() - - @Test fun `test#unit-tests#dependencies#variation-1`() = doTest() - @Test fun `test#unit-tests#dependencies#variation-2`() = doTest() - @Test fun `test#unit-tests#dependencies#variation-3`() = doTest() - @Test fun `test#unit-tests#dependencies#variation-4`() = doTest() - @Test fun `test#unit-tests#dependencies#variation-5`() = doTest() - @Test fun `test#unit-tests#dependencies#variation-6`() = doTest() - @Test fun `test#unit-tests#dependencies#variation-7`() = doTest() - @Test fun `test#unit-tests#dependencies#variation-8`() = doTest() - - @Test fun `test#unit-tests#dependencyManagement#variation-1`() = doTest() - @Test fun `test#unit-tests#dependencyManagement#variation-2`() = doTest() - @Test fun `test#unit-tests#dependencyManagement#variation-3`() = doTest() - - @Test fun `test#unit-tests#description#variation-1`() = doTest() - @Test fun `test#unit-tests#description#variation-2`() = doTest() - @Test fun `test#unit-tests#description#variation-3`() = doTest() - - @Test fun `test#unit-tests#developers#variation-1`() = doTest() - @Test fun `test#unit-tests#developers#variation-2`() = doTest() - - @Test fun `test#unit-tests#distributionManagement#variation-1`() = doTest() - @Test fun `test#unit-tests#distributionManagement#variation-2`() = doTest() - @Test fun `test#unit-tests#distributionManagement#variation-3`() = doTest() - @Test fun `test#unit-tests#distributionManagement#variation-4`() = doTest() - - @Test fun `test#unit-tests#execute#variation-1`() = doTest() - @Test fun `test#unit-tests#execute#variation-2`() = doTest() - - @Test fun `test#unit-tests#groupId#variation-1`() = doTest() - @Test fun `test#unit-tests#groupId#variation-2`() = doTest() - @Test fun `test#unit-tests#groupId#variation-3`() = doTest() - @Test fun `test#unit-tests#groupId#variation-4`() = doTest() - @Test fun `test#unit-tests#groupId#variation-5`() = doTest() - @Test fun `test#unit-tests#groupId#variation-6`() = doTest() - - @Test fun `test#unit-tests#id#variation-1`() = doTest() - @Test fun `test#unit-tests#id#variation-2`() = doTest() - @Test fun `test#unit-tests#id#variation-3`() = doTest() - @Test fun `test#unit-tests#id#variation-4`() = doTest() - - @Test fun `test#unit-tests#inceptionYear#variation-1`() = doTest() - @Test fun `test#unit-tests#inceptionYear#variation-2`() = doTest() - @Test fun `test#unit-tests#inceptionYear#variation-3`() = doTest() - - @Test fun `test#unit-tests#issueManagement#variation-1`() = doTest() - @Test fun `test#unit-tests#issueManagement#variation-2`() = doTest() - - @Test fun `test#unit-tests#licenses#variation-1`() = doTest() - @Test fun `test#unit-tests#licenses#variation-2`() = doTest() - @Test fun `test#unit-tests#licenses#variation-3`() = doTest() - - @Test fun `test#unit-tests#mailingLists#variation-1`() = doTest() - @Test fun `test#unit-tests#mailingLists#variation-2`() = doTest() - @Test fun `test#unit-tests#mailingLists#variation-3`() = doTest() - - @Test fun `test#unit-tests#modelVersion#variation-1`() = doTest() - @Test fun `test#unit-tests#modelVersion#variation-2`() = doTest() - - @Test fun `test#unit-tests#modules#variation-1`() = doTest() - @Test fun `test#unit-tests#modules#variation-2`() = doTest() - - @Test fun `test#unit-tests#name#variation-1`() = doTest() - @Test fun `test#unit-tests#name#variation-2`() = doTest() - @Test fun `test#unit-tests#name#variation-3`() = doTest() - - @Test fun `test#unit-tests#organization#variation-1`() = doTest() - @Test fun `test#unit-tests#organization#variation-2`() = doTest() - @Test fun `test#unit-tests#organization#variation-3`() = doTest() - - @Test fun `test#unit-tests#packaging#variation-1`() = doTest() - @Test fun `test#unit-tests#packaging#variation-2`() = doTest() - @Test fun `test#unit-tests#packaging#variation-3`() = doTest() - @Test fun `test#unit-tests#packaging#variation-4`() = doTest() - @Test fun `test#unit-tests#packaging#variation-5`() = doTest() - @Test fun `test#unit-tests#packaging#variation-6`() = doTest() - - @Test fun `test#unit-tests#parent#variation-1`() = doTest() - @Test fun `test#unit-tests#parent#variation-2`() = doTest() - @Test fun `test#unit-tests#parent#variation-3`() = doTest() - @Test fun `test#unit-tests#parent#variation-4`() = doTest() - @Test fun `test#unit-tests#parent#variation-5`() = doTest() - @Test fun `test#unit-tests#parent#variation-6`() = doTest() - - @Test fun `test#unit-tests#pluginRepositories#variation-1`() = doTest() - @Test fun `test#unit-tests#pluginRepositories#variation-2`() = doTest() - @Test fun `test#unit-tests#pluginRepositories#variation-3`() = doTest() - @Test fun `test#unit-tests#pluginRepositories#variation-4`() = doTest() - - @Test fun `test#unit-tests#prerequisites#variation-1`() = doTest() - @Test fun `test#unit-tests#prerequisites#variation-2`() = doTest() - - @Test fun `test#unit-tests#profiles#variation-1`() = doTest() - @Test fun `test#unit-tests#profiles#variation-2`() = doTest() - - @Test fun `test#unit-tests#properties#variation-1`() = doTest() - @Test fun `test#unit-tests#properties#variation-2`() = doTest() - - @Test fun `test#unit-tests#reporting#variation-1`() = doTest() - @Test fun `test#unit-tests#reporting#variation-2`() = doTest() - @Test fun `test#unit-tests#reporting#variation-3`() = doTest() - @Test fun `test#unit-tests#reporting#variation-4`() = doTest() - - @Test fun `test#unit-tests#reports#variation-1`() = doTest() - @Test fun `test#unit-tests#reports#variation-2`() = doTest() - @Test fun `test#unit-tests#reports#variation-3`() = doTest() - @Test fun `test#unit-tests#reports#variation-4`() = doTest() - @Test fun `test#unit-tests#reports#variation-5`() = doTest() - - @Test fun `test#unit-tests#repositories#variation-1`() = doTest() - @Test fun `test#unit-tests#repositories#variation-2`() = doTest() - @Test fun `test#unit-tests#repositories#variation-3`() = doTest() - @Test fun `test#unit-tests#repositories#variation-4`() = doTest() - - @Test fun `test#unit-tests#scm#variation-1`() = doTest() - @Test fun `test#unit-tests#scm#variation-2`() = doTest() - - @Test fun `test#unit-tests#url#variation-1`() = doTest() - @Test fun `test#unit-tests#url#variation-2`() = doTest() - - @Test fun `test#unit-tests#version#variation-1`() = doTest() - @Test fun `test#unit-tests#version#variation-2`() = doTest() - @Test fun `test#unit-tests#version#variation-3`() = doTest() - @Test fun `test#unit-tests#version#variation-4`() = doTest() - @Test fun `test#unit-tests#version#variation-5`() = doTest() - @Test fun `test#unit-tests#version#variation-6`() = doTest() - - // @formatter:on - - private fun doTest() { - assertEquals(pomXml, pomKts.kts2model().model2xml()) - } + // @formatter:off + + @Test fun `test#unit-tests#artifactId#variation-1`() = doTest() + + @Test fun `test#unit-tests#artifactId#variation-2`() = doTest() + + @Test fun `test#unit-tests#artifactId#variation-3`() = doTest() + + @Test fun `test#unit-tests#artifactId#variation-4`() = doTest() + + @Test fun `test#unit-tests#artifactId#variation-5`() = doTest() + + @Test fun `test#unit-tests#artifactId#variation-6`() = doTest() + + @Test fun `test#unit-tests#build#variation-1`() = doTest() + + @Test fun `test#unit-tests#build#variation-2`() = doTest() + + @Test fun `test#unit-tests#build#variation-3`() = doTest() + + @Test fun `test#unit-tests#build#variation-4`() = doTest() + + @Test fun `test#unit-tests#build#variation-5`() = doTest() + + @Test fun `test#unit-tests#build#variation-6`() = doTest() + + @Test fun `test#unit-tests#ciManagement#variation-1`() = doTest() + + @Test fun `test#unit-tests#ciManagement#variation-2`() = doTest() + + @Test fun `test#unit-tests#contributors#variation-1`() = doTest() + + @Test fun `test#unit-tests#contributors#variation-2`() = doTest() + + @Test fun `test#unit-tests#dependencies#variation-1`() = doTest() + + @Test fun `test#unit-tests#dependencies#variation-2`() = doTest() + + @Test fun `test#unit-tests#dependencies#variation-3`() = doTest() + + @Test fun `test#unit-tests#dependencies#variation-4`() = doTest() + + @Test fun `test#unit-tests#dependencies#variation-5`() = doTest() + + @Test fun `test#unit-tests#dependencies#variation-6`() = doTest() + + @Test fun `test#unit-tests#dependencies#variation-7`() = doTest() + + @Test fun `test#unit-tests#dependencies#variation-8`() = doTest() + + @Test fun `test#unit-tests#dependencyManagement#variation-1`() = doTest() + + @Test fun `test#unit-tests#dependencyManagement#variation-2`() = doTest() + + @Test fun `test#unit-tests#dependencyManagement#variation-3`() = doTest() + + @Test fun `test#unit-tests#description#variation-1`() = doTest() + + @Test fun `test#unit-tests#description#variation-2`() = doTest() + + @Test fun `test#unit-tests#description#variation-3`() = doTest() + + @Test fun `test#unit-tests#developers#variation-1`() = doTest() + + @Test fun `test#unit-tests#developers#variation-2`() = doTest() + + @Test fun `test#unit-tests#distributionManagement#variation-1`() = doTest() + + @Test fun `test#unit-tests#distributionManagement#variation-2`() = doTest() + + @Test fun `test#unit-tests#distributionManagement#variation-3`() = doTest() + + @Test fun `test#unit-tests#distributionManagement#variation-4`() = doTest() + + @Test fun `test#unit-tests#execute#variation-1`() = doTest() + + @Test fun `test#unit-tests#execute#variation-2`() = doTest() + + @Test fun `test#unit-tests#groupId#variation-1`() = doTest() + + @Test fun `test#unit-tests#groupId#variation-2`() = doTest() + + @Test fun `test#unit-tests#groupId#variation-3`() = doTest() + + @Test fun `test#unit-tests#groupId#variation-4`() = doTest() + + @Test fun `test#unit-tests#groupId#variation-5`() = doTest() + + @Test fun `test#unit-tests#groupId#variation-6`() = doTest() + + @Test fun `test#unit-tests#id#variation-1`() = doTest() + + @Test fun `test#unit-tests#id#variation-2`() = doTest() + + @Test fun `test#unit-tests#id#variation-3`() = doTest() + + @Test fun `test#unit-tests#id#variation-4`() = doTest() + + @Test fun `test#unit-tests#inceptionYear#variation-1`() = doTest() + + @Test fun `test#unit-tests#inceptionYear#variation-2`() = doTest() + + @Test fun `test#unit-tests#inceptionYear#variation-3`() = doTest() + + @Test fun `test#unit-tests#issueManagement#variation-1`() = doTest() + + @Test fun `test#unit-tests#issueManagement#variation-2`() = doTest() + + @Test fun `test#unit-tests#licenses#variation-1`() = doTest() + + @Test fun `test#unit-tests#licenses#variation-2`() = doTest() + + @Test fun `test#unit-tests#licenses#variation-3`() = doTest() + + @Test fun `test#unit-tests#mailingLists#variation-1`() = doTest() + + @Test fun `test#unit-tests#mailingLists#variation-2`() = doTest() + + @Test fun `test#unit-tests#mailingLists#variation-3`() = doTest() + + @Test fun `test#unit-tests#modelVersion#variation-1`() = doTest() + + @Test fun `test#unit-tests#modelVersion#variation-2`() = doTest() + + @Test fun `test#unit-tests#modules#variation-1`() = doTest() + + @Test fun `test#unit-tests#modules#variation-2`() = doTest() + + @Test fun `test#unit-tests#name#variation-1`() = doTest() + + @Test fun `test#unit-tests#name#variation-2`() = doTest() + + @Test fun `test#unit-tests#name#variation-3`() = doTest() + + @Test fun `test#unit-tests#organization#variation-1`() = doTest() + + @Test fun `test#unit-tests#organization#variation-2`() = doTest() + + @Test fun `test#unit-tests#organization#variation-3`() = doTest() + + @Test fun `test#unit-tests#packaging#variation-1`() = doTest() + + @Test fun `test#unit-tests#packaging#variation-2`() = doTest() + + @Test fun `test#unit-tests#packaging#variation-3`() = doTest() + + @Test fun `test#unit-tests#packaging#variation-4`() = doTest() + + @Test fun `test#unit-tests#packaging#variation-5`() = doTest() + + @Test fun `test#unit-tests#packaging#variation-6`() = doTest() + + @Test fun `test#unit-tests#parent#variation-1`() = doTest() + + @Test fun `test#unit-tests#parent#variation-2`() = doTest() + + @Test fun `test#unit-tests#parent#variation-3`() = doTest() + + @Test fun `test#unit-tests#parent#variation-4`() = doTest() + + @Test fun `test#unit-tests#parent#variation-5`() = doTest() + + @Test fun `test#unit-tests#parent#variation-6`() = doTest() + + @Test fun `test#unit-tests#pluginRepositories#variation-1`() = doTest() + + @Test fun `test#unit-tests#pluginRepositories#variation-2`() = doTest() + + @Test fun `test#unit-tests#pluginRepositories#variation-3`() = doTest() + + @Test fun `test#unit-tests#pluginRepositories#variation-4`() = doTest() + + @Test fun `test#unit-tests#prerequisites#variation-1`() = doTest() + + @Test fun `test#unit-tests#prerequisites#variation-2`() = doTest() + + @Test fun `test#unit-tests#profiles#variation-1`() = doTest() + + @Test fun `test#unit-tests#profiles#variation-2`() = doTest() + + @Test fun `test#unit-tests#properties#variation-1`() = doTest() + + @Test fun `test#unit-tests#properties#variation-2`() = doTest() + + @Test fun `test#unit-tests#reporting#variation-1`() = doTest() + + @Test fun `test#unit-tests#reporting#variation-2`() = doTest() + + @Test fun `test#unit-tests#reporting#variation-3`() = doTest() + + @Test fun `test#unit-tests#reporting#variation-4`() = doTest() + + @Test fun `test#unit-tests#reports#variation-1`() = doTest() + + @Test fun `test#unit-tests#reports#variation-2`() = doTest() + + @Test fun `test#unit-tests#reports#variation-3`() = doTest() + + @Test fun `test#unit-tests#reports#variation-4`() = doTest() + + @Test fun `test#unit-tests#reports#variation-5`() = doTest() + + @Test fun `test#unit-tests#repositories#variation-1`() = doTest() + + @Test fun `test#unit-tests#repositories#variation-2`() = doTest() + + @Test fun `test#unit-tests#repositories#variation-3`() = doTest() + + @Test fun `test#unit-tests#repositories#variation-4`() = doTest() + + @Test fun `test#unit-tests#scm#variation-1`() = doTest() + + @Test fun `test#unit-tests#scm#variation-2`() = doTest() + + @Test fun `test#unit-tests#url#variation-1`() = doTest() + + @Test fun `test#unit-tests#url#variation-2`() = doTest() + + @Test fun `test#unit-tests#version#variation-1`() = doTest() + + @Test fun `test#unit-tests#version#variation-2`() = doTest() + + @Test fun `test#unit-tests#version#variation-3`() = doTest() + + @Test fun `test#unit-tests#version#variation-4`() = doTest() + + @Test fun `test#unit-tests#version#variation-5`() = doTest() + + @Test fun `test#unit-tests#version#variation-6`() = doTest() + + // @formatter:on + + private fun doTest() { + assertEquals(pomXml, pomKts.kts2model().model2xml()) + } } diff --git a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DSLSupportTests.kt b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DSLSupportTests.kt index 4ee256cc..810b5fc6 100644 --- a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DSLSupportTests.kt +++ b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/dsl/DSLSupportTests.kt @@ -5,199 +5,216 @@ import org.junit.Test class DSLSupportTests { - @Test - fun `splitGavtc with gav (1 of 1)`() { - assertThat(splitCoordinates("com.example:sample-lib:1.0", 3)).containsExactly("com.example", "sample-lib", "1.0") - val (groupId, artifactId, version) = splitCoordinates("com.example:sample-lib:1.0", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + @Test + fun `splitGavtc with gav (1 of 1)`() { + assertThat(splitCoordinates("com.example:sample-lib:1.0", 3)) + .containsExactly("com.example", "sample-lib", "1.0") + val (groupId, artifactId, version) = splitCoordinates("com.example:sample-lib:1.0", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isEqualTo("com.example") - assertThat(dep.artifactId).isEqualTo("sample-lib") - assertThat(dep.version).isEqualTo("1.0") - } - - @Test - fun `splitGavtc with ga_ (1 of 2)`() { - assertThat(splitCoordinates("com.example:sample-lib:", 3)).containsExactly("com.example", "sample-lib", null) - val (groupId, artifactId, version) = splitCoordinates("com.example:sample-lib:", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isEqualTo("com.example") + assertThat(dep.artifactId).isEqualTo("sample-lib") + assertThat(dep.version).isEqualTo("1.0") + } + + @Test + fun `splitGavtc with ga_ (1 of 2)`() { + assertThat(splitCoordinates("com.example:sample-lib:", 3)) + .containsExactly("com.example", "sample-lib", null) + val (groupId, artifactId, version) = splitCoordinates("com.example:sample-lib:", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isEqualTo("com.example") - assertThat(dep.artifactId).isEqualTo("sample-lib") - assertThat(dep.version).isNull() - } - - @Test - fun `splitGavtc with ga_ (2 of 2)`() { - assertThat(splitCoordinates("com.example:sample-lib", 3)).containsExactly("com.example", "sample-lib", null) - val (groupId, artifactId, version) = splitCoordinates("com.example:sample-lib", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isEqualTo("com.example") + assertThat(dep.artifactId).isEqualTo("sample-lib") + assertThat(dep.version).isNull() + } + + @Test + fun `splitGavtc with ga_ (2 of 2)`() { + assertThat(splitCoordinates("com.example:sample-lib", 3)) + .containsExactly("com.example", "sample-lib", null) + val (groupId, artifactId, version) = splitCoordinates("com.example:sample-lib", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isEqualTo("com.example") - assertThat(dep.artifactId).isEqualTo("sample-lib") - assertThat(dep.version).isNull() - } - - @Test - fun `splitGavtc with g_v (1 of 1)`() { - assertThat(splitCoordinates("com.example::1.0", 3)).containsExactly("com.example", null, "1.0") - val (groupId, artifactId, version) = splitCoordinates("com.example::1.0", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isEqualTo("com.example") + assertThat(dep.artifactId).isEqualTo("sample-lib") + assertThat(dep.version).isNull() + } + + @Test + fun `splitGavtc with g_v (1 of 1)`() { + assertThat(splitCoordinates("com.example::1.0", 3)).containsExactly("com.example", null, "1.0") + val (groupId, artifactId, version) = splitCoordinates("com.example::1.0", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isEqualTo("com.example") - assertThat(dep.artifactId).isNull() - assertThat(dep.version).isEqualTo("1.0") - } - - @Test - fun `splitGavtc with g__ (1 of 3)`() { - assertThat(splitCoordinates("com.example::", 3)).containsExactly("com.example", null, null) - val (groupId, artifactId, version) = splitCoordinates("com.example::", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isEqualTo("com.example") + assertThat(dep.artifactId).isNull() + assertThat(dep.version).isEqualTo("1.0") + } + + @Test + fun `splitGavtc with g__ (1 of 3)`() { + assertThat(splitCoordinates("com.example::", 3)).containsExactly("com.example", null, null) + val (groupId, artifactId, version) = splitCoordinates("com.example::", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isEqualTo("com.example") - assertThat(dep.artifactId).isNull() - assertThat(dep.version).isNull() - } - - @Test - fun `splitGavtc with g__ (2 of 3)`() { - assertThat(splitCoordinates("com.example:", 3)).containsExactly("com.example", null, null) - val (groupId, artifactId, version) = splitCoordinates("com.example:", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isEqualTo("com.example") + assertThat(dep.artifactId).isNull() + assertThat(dep.version).isNull() + } + + @Test + fun `splitGavtc with g__ (2 of 3)`() { + assertThat(splitCoordinates("com.example:", 3)).containsExactly("com.example", null, null) + val (groupId, artifactId, version) = splitCoordinates("com.example:", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isEqualTo("com.example") - assertThat(dep.artifactId).isNull() - assertThat(dep.version).isNull() - } - - @Test - fun `splitGavtc with g__ (3 of 3)`() { - assertThat(splitCoordinates("com.example", 3)).containsExactly("com.example", null, null) - val (groupId, artifactId, version) = splitCoordinates("com.example", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isEqualTo("com.example") + assertThat(dep.artifactId).isNull() + assertThat(dep.version).isNull() + } + + @Test + fun `splitGavtc with g__ (3 of 3)`() { + assertThat(splitCoordinates("com.example", 3)).containsExactly("com.example", null, null) + val (groupId, artifactId, version) = splitCoordinates("com.example", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isEqualTo("com.example") - assertThat(dep.artifactId).isNull() - assertThat(dep.version).isNull() - } - - @Test - fun `splitGavtc with _av (1 of 1)`() { - assertThat(splitCoordinates(":sample-lib:1.0", 3)).containsExactly(null, "sample-lib", "1.0") - val (groupId, artifactId, version) = splitCoordinates(":sample-lib:1.0", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isEqualTo("com.example") + assertThat(dep.artifactId).isNull() + assertThat(dep.version).isNull() + } + + @Test + fun `splitGavtc with _av (1 of 1)`() { + assertThat(splitCoordinates(":sample-lib:1.0", 3)).containsExactly(null, "sample-lib", "1.0") + val (groupId, artifactId, version) = splitCoordinates(":sample-lib:1.0", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isNull() - assertThat(dep.artifactId).isEqualTo("sample-lib") - assertThat(dep.version).isEqualTo("1.0") - } - - @Test - fun `splitGavtc with _a_ (1 of 2)`() { - assertThat(splitCoordinates(":sample-lib:", 3)).containsExactly(null, "sample-lib", null) - val (groupId, artifactId, version) = splitCoordinates(":sample-lib", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isNull() + assertThat(dep.artifactId).isEqualTo("sample-lib") + assertThat(dep.version).isEqualTo("1.0") + } + + @Test + fun `splitGavtc with _a_ (1 of 2)`() { + assertThat(splitCoordinates(":sample-lib:", 3)).containsExactly(null, "sample-lib", null) + val (groupId, artifactId, version) = splitCoordinates(":sample-lib", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isNull() - assertThat(dep.artifactId).isEqualTo("sample-lib") - assertThat(dep.version).isNull() - } - - @Test - fun `splitGavtc with _a_ (2 of 2)`() { - assertThat(splitCoordinates(":sample-lib", 3)).containsExactly(null, "sample-lib", null) - val (groupId, artifactId, version) = splitCoordinates(":sample-lib", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isNull() + assertThat(dep.artifactId).isEqualTo("sample-lib") + assertThat(dep.version).isNull() + } + + @Test + fun `splitGavtc with _a_ (2 of 2)`() { + assertThat(splitCoordinates(":sample-lib", 3)).containsExactly(null, "sample-lib", null) + val (groupId, artifactId, version) = splitCoordinates(":sample-lib", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isNull() - assertThat(dep.artifactId).isEqualTo("sample-lib") - assertThat(dep.version).isNull() - } - - @Test - fun `splitGavtc with __v (1 of 1)`() { - assertThat(splitCoordinates("::1.0", 3)).containsExactly(null, null, "1.0") - val (groupId, artifactId, version) = splitCoordinates("::1.0", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isNull() + assertThat(dep.artifactId).isEqualTo("sample-lib") + assertThat(dep.version).isNull() + } + + @Test + fun `splitGavtc with __v (1 of 1)`() { + assertThat(splitCoordinates("::1.0", 3)).containsExactly(null, null, "1.0") + val (groupId, artifactId, version) = splitCoordinates("::1.0", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isNull() - assertThat(dep.artifactId).isNull() - assertThat(dep.version).isEqualTo("1.0") - } - - @Test - fun `splitGavtc with ___ (1 of 3)`() { - assertThat(splitCoordinates("::", 3)).containsExactly(null, null, null) - val (groupId, artifactId, version) = splitCoordinates("::", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isNull() + assertThat(dep.artifactId).isNull() + assertThat(dep.version).isEqualTo("1.0") + } + + @Test + fun `splitGavtc with ___ (1 of 3)`() { + assertThat(splitCoordinates("::", 3)).containsExactly(null, null, null) + val (groupId, artifactId, version) = splitCoordinates("::", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isNull() - assertThat(dep.artifactId).isNull() - assertThat(dep.version).isNull() - } - - @Test - fun `splitGavtc with ___ (2 of 3)`() { - assertThat(splitCoordinates(":", 3)).containsExactly(null, null, null) - val (groupId, artifactId, version) = splitCoordinates(":", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isNull() + assertThat(dep.artifactId).isNull() + assertThat(dep.version).isNull() + } + + @Test + fun `splitGavtc with ___ (2 of 3)`() { + assertThat(splitCoordinates(":", 3)).containsExactly(null, null, null) + val (groupId, artifactId, version) = splitCoordinates(":", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isNull() - assertThat(dep.artifactId).isNull() - assertThat(dep.version).isNull() - } - - @Test - fun `splitGavtc with ___ (3 of 3)`() { - assertThat(splitCoordinates("", 3)).containsExactly(null, null, null) - val (groupId, artifactId, version) = splitCoordinates("", 3) - val dep = Dependency().apply { - this.groupId = groupId - this.artifactId = artifactId - this.version = version + assertThat(dep.groupId).isNull() + assertThat(dep.artifactId).isNull() + assertThat(dep.version).isNull() + } + + @Test + fun `splitGavtc with ___ (3 of 3)`() { + assertThat(splitCoordinates("", 3)).containsExactly(null, null, null) + val (groupId, artifactId, version) = splitCoordinates("", 3) + val dep = + Dependency().apply { + this.groupId = groupId + this.artifactId = artifactId + this.version = version } - assertThat(dep.groupId).isNull() - assertThat(dep.artifactId).isNull() - assertThat(dep.version).isNull() - } -} \ No newline at end of file + assertThat(dep.groupId).isNull() + assertThat(dep.artifactId).isNull() + assertThat(dep.version).isNull() + } +} diff --git a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/testing/AbstractModelTestCase.kt b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/testing/AbstractModelTestCase.kt index d7b043b3..61c8d618 100644 --- a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/testing/AbstractModelTestCase.kt +++ b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/testing/AbstractModelTestCase.kt @@ -1,5 +1,6 @@ package org.sonatype.maven.polyglot.kotlin.testing +import java.io.File import org.apache.maven.model.Model import org.apache.maven.model.building.ModelProcessor import org.apache.maven.model.io.ModelReader @@ -10,57 +11,60 @@ import org.codehaus.plexus.PlexusConstants import org.codehaus.plexus.PlexusTestCase import org.junit.Assert import org.sonatype.maven.polyglot.kotlin.dsl.propertiesFactory -import java.io.File abstract class AbstractModelTestCase(testName: String) : PlexusTestCase() { - init { - name = testName - propertiesFactory = { org.sonatype.maven.polyglot.kotlin.util.Properties() } - } + init { + name = testName + propertiesFactory = { org.sonatype.maven.polyglot.kotlin.util.Properties() } + } - override fun customizeContainerConfiguration(configuration: ContainerConfiguration?) { - configuration?.autoWiring = true; - configuration?.classPathScanning = PlexusConstants.SCANNING_CACHE - } + override fun customizeContainerConfiguration(configuration: ContainerConfiguration?) { + configuration?.autoWiring = true + configuration?.classPathScanning = PlexusConstants.SCANNING_CACHE + } - protected val testBasePath: String = testName.removePrefix("test#").replace('#', '/') - private val testResources: File = File("target/test-classes") - private val testOutput: File = File("target/test-output") + protected val testBasePath: String = testName.removePrefix("test#").replace('#', '/') + private val testResources: File = File("target/test-classes") + private val testOutput: File = File("target/test-output") - private val kotlinModelWriter: ModelWriter = lookup(ModelWriter::class.java, "kotlin") + private val kotlinModelWriter: ModelWriter = lookup(ModelWriter::class.java, "kotlin") - private val kotlinModelReader: ModelReader = lookup(ModelReader::class.java, "kotlin") + private val kotlinModelReader: ModelReader = lookup(ModelReader::class.java, "kotlin") - private val xmlModelReader: ModelReader = lookup(ModelReader::class.java, "default") + private val xmlModelReader: ModelReader = lookup(ModelReader::class.java, "default") - private val xmlModelWriter: ModelWriter = lookup(ModelWriter::class.java, "default") + private val xmlModelWriter: ModelWriter = lookup(ModelWriter::class.java, "default") - protected val pomXml: File = testResources.resolve(testBasePath).resolve("pom.xml").also { assertThat(it).exists() } + protected val pomXml: File = + testResources.resolve(testBasePath).resolve("pom.xml").also { assertThat(it).exists() } - protected val pomKts: File = testResources.resolve(testBasePath).resolve("pom.kts").also { assertThat(it).exists() } + protected val pomKts: File = + testResources.resolve(testBasePath).resolve("pom.kts").also { assertThat(it).exists() } - protected fun File.xml2model(vararg options: Pair): Model = xmlModelReader.read(this, mapOf(*options) + mapOf(ModelProcessor.SOURCE to this)) + protected fun File.xml2model(vararg options: Pair): Model = + xmlModelReader.read(this, mapOf(*options) + mapOf(ModelProcessor.SOURCE to this)) - protected fun File.kts2model(vararg options: Pair): Model = kotlinModelReader.read(this, mapOf(*options) + mapOf(ModelProcessor.SOURCE to this)) + protected fun File.kts2model(vararg options: Pair): Model = + kotlinModelReader.read(this, mapOf(*options) + mapOf(ModelProcessor.SOURCE to this)) - protected fun Model.model2xml(vararg options: Pair): File { - val basedir = testOutput.resolve(testBasePath) - basedir.mkdirs() - val file = basedir.resolve("pom.xml") - xmlModelWriter.write(file, mapOf(*options), this) - return file - } + protected fun Model.model2xml(vararg options: Pair): File { + val basedir = testOutput.resolve(testBasePath) + basedir.mkdirs() + val file = basedir.resolve("pom.xml") + xmlModelWriter.write(file, mapOf(*options), this) + return file + } - protected fun Model.model2kts(vararg options: Pair): File { - val basedir = testOutput.resolve(testBasePath) - basedir.mkdirs() - val file = basedir.resolve("pom.kts") - kotlinModelWriter.write(file, mapOf(*options), this) - return file - } + protected fun Model.model2kts(vararg options: Pair): File { + val basedir = testOutput.resolve(testBasePath) + basedir.mkdirs() + val file = basedir.resolve("pom.kts") + kotlinModelWriter.write(file, mapOf(*options), this) + return file + } - protected fun assertEquals(expected: File, actual: File) { - Assert.assertEquals(expected.readText(), actual.readText()) - } + protected fun assertEquals(expected: File, actual: File) { + Assert.assertEquals(expected.readText(), actual.readText()) + } } diff --git a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/testing/extensions.kt b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/testing/extensions.kt index b72f3ef5..71c0d0f3 100644 --- a/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/testing/extensions.kt +++ b/polyglot-kotlin/src/test/kotlin/org/sonatype/maven/polyglot/kotlin/testing/extensions.kt @@ -1,119 +1,118 @@ package org.sonatype.maven.polyglot.kotlin.testing -import org.apache.maven.model.Model -import org.apache.maven.model.io.DefaultModelReader -import org.apache.maven.model.io.DefaultModelWriter -import org.apache.maven.model.io.xpp3.MavenXpp3Writer -import org.assertj.core.api.Assertions.assertThat import java.io.ByteArrayOutputStream import java.io.Reader import java.io.StringReader import java.io.StringWriter import java.lang.reflect.Field +import org.apache.maven.model.Model +import org.apache.maven.model.io.DefaultModelReader +import org.apache.maven.model.io.DefaultModelWriter +import org.apache.maven.model.io.xpp3.MavenXpp3Writer +import org.assertj.core.api.Assertions.assertThat -/** - * Returns a [Reader] to the classpath resource named by this string. - */ +/** Returns a [Reader] to the classpath resource named by this string. */ internal fun String.asResource(): Reader? { - println("Reading $this") - return Thread.currentThread().contextClassLoader.getResourceAsStream(this)?.reader() + println("Reading $this") + return Thread.currentThread().contextClassLoader.getResourceAsStream(this)?.reader() } internal fun println(model: Model) { - println(toString(model)) + println(toString(model)) } internal fun toString(model: Model): String { - val output = StringWriter() - val writer = MavenXpp3Writer() -// writer.setFileComment("\nGenerated from pom.kts on ${java.util.Date()}\n") - writer.write(output, model) - return output.toString() + val output = StringWriter() + val writer = MavenXpp3Writer() + // writer.setFileComment("\nGenerated from pom.kts on ${java.util.Date()}\n") + writer.write(output, model) + return output.toString() } internal fun toByteArray(model: Model): ByteArray? { - val output = ByteArrayOutputStream() - val writer = MavenXpp3Writer() -// writer.setFileComment("\nGenerated from pom.kts on ${java.util.Date()}\n") - writer.write(output, model) - return output.toByteArray() + val output = ByteArrayOutputStream() + val writer = MavenXpp3Writer() + // writer.setFileComment("\nGenerated from pom.kts on ${java.util.Date()}\n") + writer.write(output, model) + return output.toByteArray() } /** - * Asserts that no data is lost during serialization by doing a field by field comparison between the original model - * and the deserialized model. + * Asserts that no data is lost during serialization by doing a field by field comparison between + * the original model and the deserialized model. */ internal fun assertNoDataLossOnSerialization(project: Model) { - // Serialize the project model - val options = HashMap() - val output = StringWriter() - DefaultModelWriter().write(output, options, project) + // Serialize the project model + val options = HashMap() + val output = StringWriter() + DefaultModelWriter().write(output, options, project) - // Verify that the project model deserializes with all its original data - val input = StringReader(output.toString()) - val actual = DefaultModelReader().read(input, options) - compare("project", Model::class.java, project, actual) + // Verify that the project model deserializes with all its original data + val input = StringReader(output.toString()) + val actual = DefaultModelReader().read(input, options) + compare("project", Model::class.java, project, actual) } -//-- Private Implementation ------------------------------------------------------------------------------------------// +// -- Private Implementation +// ------------------------------------------------------------------------------------------// private const val comparingMessage = "Comparing %-50s: %s%n" private fun compare(name: String, type: Class<*>, o1: Any?, o2: Any?) { - System.out.printf(comparingMessage, name, type.name) - System.out.printf("\texpected: %s%n", o1?.toString()?.replace("\n", "\n ")) - System.out.printf("\tactual: %s%n", o2?.toString()?.replace("\n", "\n ")) - if (o1 !== o2) { - if (String::class.java.isAssignableFrom(type)) { - assertThat(o2).isEqualTo(o1).withFailMessage("'$name' values are not equal") - } else if (List::class.java.isAssignableFrom(type)) { - if (o1 is List<*> && o2 is List<*>) { - assertThat(o2.size).isEqualTo(o1.size).withFailMessage("'$name' values are not equal") - for (i in o1.indices) { - compare("$name[$i]", o1[i]!!::class.java, o1[i], o2[i]) - } - } - } else if (Map::class.java.isAssignableFrom(type)) { - if (o1 is Map<*, *> && o2 is Map<*, *>) { - assertThat(o2.size).isEqualTo(o1.size).withFailMessage("'$name' values are not equal") - val keys = setOf(*o1.keys.toTypedArray(), *o2.keys.toTypedArray()) - for (key in keys) { - compare("$name['$key']", o1[key]!!::class.java, o1[key], o2[key]) - } - } - } else if (o1 != null && o2 != null) { - if (o2 is Model) { - // Calling getters on lazily populated fields - o2.developers - o2.contributors - o2.mailingLists - o2.build?.resources - o2.build?.testResources - o2.build?.filters - o2.modules - } - doWithFields(type) { field -> compare("$name.${field.name}", field, o1, o2) } - } else { - assertThat(o2).isEqualTo(o1).withFailMessage("'$name' values are not equal") + System.out.printf(comparingMessage, name, type.name) + System.out.printf("\texpected: %s%n", o1?.toString()?.replace("\n", "\n ")) + System.out.printf("\tactual: %s%n", o2?.toString()?.replace("\n", "\n ")) + if (o1 !== o2) { + if (String::class.java.isAssignableFrom(type)) { + assertThat(o2).isEqualTo(o1).withFailMessage("'$name' values are not equal") + } else if (List::class.java.isAssignableFrom(type)) { + if (o1 is List<*> && o2 is List<*>) { + assertThat(o2.size).isEqualTo(o1.size).withFailMessage("'$name' values are not equal") + for (i in o1.indices) { + compare("$name[$i]", o1[i]!!::class.java, o1[i], o2[i]) } + } + } else if (Map::class.java.isAssignableFrom(type)) { + if (o1 is Map<*, *> && o2 is Map<*, *>) { + assertThat(o2.size).isEqualTo(o1.size).withFailMessage("'$name' values are not equal") + val keys = setOf(*o1.keys.toTypedArray(), *o2.keys.toTypedArray()) + for (key in keys) { + compare("$name['$key']", o1[key]!!::class.java, o1[key], o2[key]) + } + } + } else if (o1 != null && o2 != null) { + if (o2 is Model) { + // Calling getters on lazily populated fields + o2.developers + o2.contributors + o2.mailingLists + o2.build?.resources + o2.build?.testResources + o2.build?.filters + o2.modules + } + doWithFields(type) { field -> compare("$name.${field.name}", field, o1, o2) } + } else { + assertThat(o2).isEqualTo(o1).withFailMessage("'$name' values are not equal") } + } } private fun compare(name: String, field: Field, o1: T, o2: T) { - field.isAccessible = true - val expected = field.get(o1) - val actual = field.get(o2) - compare(name, field.type, expected, actual) + field.isAccessible = true + val expected = field.get(o1) + val actual = field.get(o2) + compare(name, field.type, expected, actual) } private fun doWithFields(clazz: Class<*>, fieldCallback: (Field) -> Unit) { - var targetClass: Class<*>? = clazz - do { - val tc = targetClass!! - val fields = tc.declaredFields - for (field in fields) { - fieldCallback.invoke(field) - } - targetClass = tc.superclass - } while (targetClass != null && targetClass != Any::class.java) + var targetClass: Class<*>? = clazz + do { + val tc = targetClass!! + val fields = tc.declaredFields + for (field in fields) { + fieldCallback.invoke(field) + } + targetClass = tc.superclass + } while (targetClass != null && targetClass != Any::class.java) }