Add ktlint plugin to maven
This commit is contained in:
parent
d84770970d
commit
aa585358be
46
pom.xml
46
pom.xml
@ -150,6 +150,52 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>ktlint</id>
|
||||
<phase>verify</phase>
|
||||
<configuration>
|
||||
<target name="ktlint">
|
||||
<java taskname="ktlint" dir="${basedir}" fork="true" failonerror="true"
|
||||
classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath">
|
||||
<arg value="src/**/*.kt"/>
|
||||
</java>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>ktlint-format</id>
|
||||
<configuration>
|
||||
<target name="ktlint">
|
||||
<java taskname="ktlint" dir="${basedir}" fork="true" failonerror="true"
|
||||
classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath">
|
||||
<arg value="-F"/>
|
||||
<arg value="src/**/*.kt"/>
|
||||
</java>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.pinterest</groupId>
|
||||
<artifactId>ktlint</artifactId>
|
||||
<version>0.39.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@ -8,7 +8,6 @@ import org.koin.dsl.onClose
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import starter.ProjectZip
|
||||
import starter.config.Config
|
||||
import starter.views.Views
|
||||
|
||||
val mainModule = module {
|
||||
|
||||
@ -14,24 +14,32 @@ import starter.utils.PebbleFunction
|
||||
class DepAsXmlPebbleFunction : PebbleFunction {
|
||||
override val name = "depAsXml"
|
||||
override fun getArgumentNames() = listOf("dependency")
|
||||
override fun execute(args: Map<String, Any>, self: PebbleTemplate, context: EvaluationContext, lineNumber: Int): Any {
|
||||
|
||||
override fun execute(
|
||||
args: Map<String, Any>,
|
||||
self: PebbleTemplate,
|
||||
context: EvaluationContext,
|
||||
lineNumber: Int,
|
||||
): Any {
|
||||
val dep = args["dependency"] as Dependency
|
||||
|
||||
fun tagName(name: String) = """<span class="text-red-700">$name</span>"""
|
||||
|
||||
fun startTag(name: String): String {
|
||||
@Language("html") @Suppress("UnnecessaryVariable")
|
||||
val result = """<span class="text-gray-700"><</span><span class="text-red-700">$name</span><span class="text-gray-700">></span>"""
|
||||
val result = """<span class="text-gray-700"><</span>""" +
|
||||
"""${tagName(name)}<span class="text-gray-700">></span>"""
|
||||
return result
|
||||
}
|
||||
|
||||
fun endTag(name: String): String {
|
||||
@Language("html") @Suppress("UnnecessaryVariable")
|
||||
val result = """<span class="text-gray-700"></</span><span class="text-red-700">$name</span><span class="text-gray-700">></span>"""
|
||||
val result = """<span class="text-gray-700"></</span>""" +
|
||||
"""${tagName(name)}<span class="text-gray-700">></span>"""
|
||||
return result
|
||||
}
|
||||
|
||||
fun tag(name: String, content: String): String {
|
||||
return """${startTag(name)}$content${endTag(name)}"""
|
||||
}
|
||||
fun tag(name: String, content: String) = """${startTag(name)}$content${endTag(name)}"""
|
||||
|
||||
val result = """
|
||||
|${startTag("dependency")}
|
||||
|
||||
@ -20,6 +20,7 @@ val routesModule = module {
|
||||
routes(
|
||||
static(ResourceLoader.Classpath("/assets")),
|
||||
getAll<RouteSupplier>().toRouter()
|
||||
))
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,8 +15,8 @@ import starter.extensions.ok
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
class ZipRouteSupplier(
|
||||
private val conf: StarterConfig,
|
||||
private val projectZip: ProjectZip,
|
||||
private val conf: StarterConfig,
|
||||
private val projectZip: ProjectZip,
|
||||
) : RouteSupplier {
|
||||
|
||||
override fun get() = "/" bind Method.POST to { req ->
|
||||
|
||||
@ -2,7 +2,6 @@ package starter.templates
|
||||
|
||||
import com.mitchellbosecke.pebble.PebbleEngine
|
||||
import starter.Project
|
||||
import starter.utils.prettyPrintXml
|
||||
import starter.utils.render
|
||||
|
||||
class JunitTemplate(private val engine: PebbleEngine) : Template {
|
||||
|
||||
@ -6,7 +6,7 @@ import starter.utils.render
|
||||
|
||||
class MainTemplate(private val engine: PebbleEngine) : Template {
|
||||
override fun path(project: Project) =
|
||||
"src/main/kotlin/" + project.basePackage.replace('.', '/') + "/" + project.name.toLowerCase().capitalize() + ".kt"
|
||||
"src/main/kotlin/" + project.name.toLowerCase().capitalize() + ".kt"
|
||||
|
||||
override fun render(project: Project) =
|
||||
engine.render("starter/main/index", mapOf("basePackage" to project.basePackage))
|
||||
|
||||
@ -2,7 +2,6 @@ package starter.templates
|
||||
|
||||
import com.mitchellbosecke.pebble.PebbleEngine
|
||||
import starter.Project
|
||||
import starter.Version
|
||||
import starter.utils.prettyPrintXml
|
||||
import starter.utils.render
|
||||
|
||||
|
||||
@ -64,16 +64,20 @@ class PebbleEngineBuilder {
|
||||
PebbleEngine.Builder()
|
||||
.loader(builder.loader)
|
||||
.cacheActive(builder.cache != CacheType.None)
|
||||
.templateCache(when (builder.cache) {
|
||||
CacheType.None -> NoOpTemplateCache()
|
||||
CacheType.Caffeine -> CaffeineTemplateCache()
|
||||
CacheType.ConcurrentMap -> ConcurrentMapTemplateCache()
|
||||
})
|
||||
.tagCache(when (builder.cache) {
|
||||
CacheType.None -> NoOpTagCache()
|
||||
CacheType.Caffeine -> CaffeineTagCache()
|
||||
CacheType.ConcurrentMap -> ConcurrentMapTagCache()
|
||||
})
|
||||
.templateCache(
|
||||
when (builder.cache) {
|
||||
CacheType.None -> NoOpTemplateCache()
|
||||
CacheType.Caffeine -> CaffeineTemplateCache()
|
||||
CacheType.ConcurrentMap -> ConcurrentMapTemplateCache()
|
||||
}
|
||||
)
|
||||
.tagCache(
|
||||
when (builder.cache) {
|
||||
CacheType.None -> NoOpTagCache()
|
||||
CacheType.Caffeine -> CaffeineTagCache()
|
||||
CacheType.ConcurrentMap -> ConcurrentMapTagCache()
|
||||
}
|
||||
)
|
||||
.extension(object : AbstractExtension() {
|
||||
override fun getFunctions(): Map<String, Function>? =
|
||||
builder.functions.associateBy { it.name }.ifEmpty { null }
|
||||
|
||||
@ -72,7 +72,6 @@ internal class PomTemplateTest {
|
||||
.associate { it.nodeName to it.firstChild.nodeValue }
|
||||
|
||||
Triple(map["groupId"]!!, map["artifactId"]!!, map["version"] ?: "")
|
||||
|
||||
}.filterNot { it.second == "kotlin-stdlib-jdk8" }
|
||||
|
||||
println(deps.joinToString("\n"))
|
||||
@ -116,6 +115,5 @@ internal class PomTemplateTest {
|
||||
val kotlinxPluginDep = "$kotlinMavenPlugin/dependencies/dependency/artifactId"
|
||||
assertThat(xml.extract(kotlinxPluginDep))
|
||||
.isEqualTo("kotlin-maven-serialization")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user