-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kotlinfmt used as well (w/ defaults) that seems closest to existing f…
…ormat
- Loading branch information
Showing
76 changed files
with
4,150 additions
and
3,972 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinMapping.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
73 changes: 36 additions & 37 deletions
73
polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, *>): 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<String, *>): 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<String, *>): 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<String, *>): 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<String, *>): 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<String, *>): Model { | ||
val temp = File.createTempFile("pom", ".kts") | ||
temp.deleteOnExit() | ||
temp.outputStream().use { input.copyTo(it) } | ||
val model = read(temp, options) | ||
temp.delete() | ||
return model | ||
} | ||
} |
53 changes: 30 additions & 23 deletions
53
polyglot-kotlin/src/main/kotlin/org/sonatype/maven/polyglot/kotlin/KotlinModelWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MavenProject> | ||
@Inject private lateinit var projectProvider: Provider<MavenProject> | ||
|
||
override fun write(output: Writer, options: Map<String, Any>, model: Model) { | ||
output.write(with(StringWriter(1024)) { | ||
val config = HashMap<String, Any>(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<String, Any>, model: Model) { | ||
output.write( | ||
with(StringWriter(1024)) { | ||
val config = HashMap<String, Any>(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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.