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>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.8.1</version>
|
||||||
</plugin>
|
</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>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import org.koin.dsl.onClose
|
|||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import starter.ProjectZip
|
import starter.ProjectZip
|
||||||
import starter.config.Config
|
|
||||||
import starter.views.Views
|
import starter.views.Views
|
||||||
|
|
||||||
val mainModule = module {
|
val mainModule = module {
|
||||||
|
|||||||
@ -14,24 +14,32 @@ import starter.utils.PebbleFunction
|
|||||||
class DepAsXmlPebbleFunction : PebbleFunction {
|
class DepAsXmlPebbleFunction : PebbleFunction {
|
||||||
override val name = "depAsXml"
|
override val name = "depAsXml"
|
||||||
override fun getArgumentNames() = listOf("dependency")
|
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
|
val dep = args["dependency"] as Dependency
|
||||||
|
|
||||||
|
fun tagName(name: String) = """<span class="text-red-700">$name</span>"""
|
||||||
|
|
||||||
fun startTag(name: String): String {
|
fun startTag(name: String): String {
|
||||||
@Language("html") @Suppress("UnnecessaryVariable")
|
@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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun endTag(name: String): String {
|
fun endTag(name: String): String {
|
||||||
@Language("html") @Suppress("UnnecessaryVariable")
|
@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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun tag(name: String, content: String): String {
|
fun tag(name: String, content: String) = """${startTag(name)}$content${endTag(name)}"""
|
||||||
return """${startTag(name)}$content${endTag(name)}"""
|
|
||||||
}
|
|
||||||
|
|
||||||
val result = """
|
val result = """
|
||||||
|${startTag("dependency")}
|
|${startTag("dependency")}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ val routesModule = module {
|
|||||||
routes(
|
routes(
|
||||||
static(ResourceLoader.Classpath("/assets")),
|
static(ResourceLoader.Classpath("/assets")),
|
||||||
getAll<RouteSupplier>().toRouter()
|
getAll<RouteSupplier>().toRouter()
|
||||||
))
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,8 +15,8 @@ import starter.extensions.ok
|
|||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
|
|
||||||
class ZipRouteSupplier(
|
class ZipRouteSupplier(
|
||||||
private val conf: StarterConfig,
|
private val conf: StarterConfig,
|
||||||
private val projectZip: ProjectZip,
|
private val projectZip: ProjectZip,
|
||||||
) : RouteSupplier {
|
) : RouteSupplier {
|
||||||
|
|
||||||
override fun get() = "/" bind Method.POST to { req ->
|
override fun get() = "/" bind Method.POST to { req ->
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package starter.templates
|
|||||||
|
|
||||||
import com.mitchellbosecke.pebble.PebbleEngine
|
import com.mitchellbosecke.pebble.PebbleEngine
|
||||||
import starter.Project
|
import starter.Project
|
||||||
import starter.utils.prettyPrintXml
|
|
||||||
import starter.utils.render
|
import starter.utils.render
|
||||||
|
|
||||||
class JunitTemplate(private val engine: PebbleEngine) : Template {
|
class JunitTemplate(private val engine: PebbleEngine) : Template {
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import starter.utils.render
|
|||||||
|
|
||||||
class MainTemplate(private val engine: PebbleEngine) : Template {
|
class MainTemplate(private val engine: PebbleEngine) : Template {
|
||||||
override fun path(project: Project) =
|
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) =
|
override fun render(project: Project) =
|
||||||
engine.render("starter/main/index", mapOf("basePackage" to project.basePackage))
|
engine.render("starter/main/index", mapOf("basePackage" to project.basePackage))
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package starter.templates
|
|||||||
|
|
||||||
import com.mitchellbosecke.pebble.PebbleEngine
|
import com.mitchellbosecke.pebble.PebbleEngine
|
||||||
import starter.Project
|
import starter.Project
|
||||||
import starter.Version
|
|
||||||
import starter.utils.prettyPrintXml
|
import starter.utils.prettyPrintXml
|
||||||
import starter.utils.render
|
import starter.utils.render
|
||||||
|
|
||||||
|
|||||||
@ -64,16 +64,20 @@ class PebbleEngineBuilder {
|
|||||||
PebbleEngine.Builder()
|
PebbleEngine.Builder()
|
||||||
.loader(builder.loader)
|
.loader(builder.loader)
|
||||||
.cacheActive(builder.cache != CacheType.None)
|
.cacheActive(builder.cache != CacheType.None)
|
||||||
.templateCache(when (builder.cache) {
|
.templateCache(
|
||||||
CacheType.None -> NoOpTemplateCache()
|
when (builder.cache) {
|
||||||
CacheType.Caffeine -> CaffeineTemplateCache()
|
CacheType.None -> NoOpTemplateCache()
|
||||||
CacheType.ConcurrentMap -> ConcurrentMapTemplateCache()
|
CacheType.Caffeine -> CaffeineTemplateCache()
|
||||||
})
|
CacheType.ConcurrentMap -> ConcurrentMapTemplateCache()
|
||||||
.tagCache(when (builder.cache) {
|
}
|
||||||
CacheType.None -> NoOpTagCache()
|
)
|
||||||
CacheType.Caffeine -> CaffeineTagCache()
|
.tagCache(
|
||||||
CacheType.ConcurrentMap -> ConcurrentMapTagCache()
|
when (builder.cache) {
|
||||||
})
|
CacheType.None -> NoOpTagCache()
|
||||||
|
CacheType.Caffeine -> CaffeineTagCache()
|
||||||
|
CacheType.ConcurrentMap -> ConcurrentMapTagCache()
|
||||||
|
}
|
||||||
|
)
|
||||||
.extension(object : AbstractExtension() {
|
.extension(object : AbstractExtension() {
|
||||||
override fun getFunctions(): Map<String, Function>? =
|
override fun getFunctions(): Map<String, Function>? =
|
||||||
builder.functions.associateBy { it.name }.ifEmpty { null }
|
builder.functions.associateBy { it.name }.ifEmpty { null }
|
||||||
|
|||||||
@ -72,7 +72,6 @@ internal class PomTemplateTest {
|
|||||||
.associate { it.nodeName to it.firstChild.nodeValue }
|
.associate { it.nodeName to it.firstChild.nodeValue }
|
||||||
|
|
||||||
Triple(map["groupId"]!!, map["artifactId"]!!, map["version"] ?: "")
|
Triple(map["groupId"]!!, map["artifactId"]!!, map["version"] ?: "")
|
||||||
|
|
||||||
}.filterNot { it.second == "kotlin-stdlib-jdk8" }
|
}.filterNot { it.second == "kotlin-stdlib-jdk8" }
|
||||||
|
|
||||||
println(deps.joinToString("\n"))
|
println(deps.joinToString("\n"))
|
||||||
@ -116,6 +115,5 @@ internal class PomTemplateTest {
|
|||||||
val kotlinxPluginDep = "$kotlinMavenPlugin/dependencies/dependency/artifactId"
|
val kotlinxPluginDep = "$kotlinMavenPlugin/dependencies/dependency/artifactId"
|
||||||
assertThat(xml.extract(kotlinxPluginDep))
|
assertThat(xml.extract(kotlinxPluginDep))
|
||||||
.isEqualTo("kotlin-maven-serialization")
|
.isEqualTo("kotlin-maven-serialization")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user