Skip to content

Commit

Permalink
Support uberjar and war tasks generation for CUBA 7.2 #191
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-shustanov committed Oct 6, 2020
1 parent 7124b98 commit a6966f1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.haulmont.cuba.cli.*
import com.haulmont.cuba.cli.commands.GeneratorCommand
import com.haulmont.cuba.cli.cubaplugin.deploy.ContextXmlParams
import com.haulmont.cuba.cli.cubaplugin.di.cubaKodein
import com.haulmont.cuba.cli.cubaplugin.model.DataSourceProvider
import com.haulmont.cuba.cli.generation.TemplateProcessor
import com.haulmont.cuba.cli.prompting.Answers
import com.haulmont.cuba.cli.prompting.QuestionsList
Expand Down Expand Up @@ -63,7 +64,9 @@ class UberJarCommand : GeneratorCommand<UberJarModel>() {
askIf("specifyLogback")
}

confirmation("generateCustomJetty", "Generate custom Jetty environment file?")
if(projectModel.database.dataSourceProvider == DataSourceProvider.JNDI) {
confirmation("generateCustomJetty", "Generate custom Jetty environment file?")
}

ContextXmlParams.run {
askContextXmlParams(projectModel, questionName = "customJettyContextParams", askCondition = "generateCustomJetty")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class UberJarModel(answers: Answers, projectModel: ProjectModel) {
val generateLogback: Boolean by answers
val customLogback: String? by answers.withDefault { null }

val generateCustomJetty: Boolean by answers
val generateCustomJetty: Boolean by answers.withDefault { false }
val jettyContextParams = answers["customJettyContextParams"]?.let { ContextXmlParams(it as Answers, projectModel) }
val customJettyPath: String? by answers.withDefault { null }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.haulmont.cuba.cli.*
import com.haulmont.cuba.cli.commands.GeneratorCommand
import com.haulmont.cuba.cli.cubaplugin.deploy.ContextXmlParams
import com.haulmont.cuba.cli.cubaplugin.di.cubaKodein
import com.haulmont.cuba.cli.cubaplugin.model.DataSourceProvider
import com.haulmont.cuba.cli.generation.TemplateProcessor
import com.haulmont.cuba.cli.prompting.Answers
import com.haulmont.cuba.cli.prompting.QuestionsList
Expand Down Expand Up @@ -60,8 +61,10 @@ class WarCommand : GeneratorCommand<WarModel>() {

confirmation("includeTomcatContextXml", "Include Tomcat's context.xml?")

confirmation("generateContextXml", "Generate custom context.xml?") {
askIf("includeTomcatContextXml")
if(projectModel.database.dataSourceProvider == DataSourceProvider.JNDI) {
confirmation("generateContextXml", "Generate custom context.xml?") {
askIf("includeTomcatContextXml")
}
}

ContextXmlParams.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ private fun parseJndiDatabase(projectStructure: ProjectStructure): Database? {
.resolve("context.xml")

val contextXmlRoot = parse(contextXml).documentElement
val resourceElement = contextXmlRoot.xpath("//Resource[@name=\"jdbc/CubaDS\"]").firstOrNull() as? Element ?: return null
val resourceElement = contextXmlRoot.xpath("//Resource[@name=\"jdbc/CubaDS\"]").firstOrNull() as? Element
?: return null

return Database(
getDbTypeByDriver(resourceElement["driverClassName"]),
Expand Down Expand Up @@ -210,12 +211,13 @@ fun getPrefixUrl(driverClass: String): String = when {
else -> throw ProjectScanException("Unrecognized jdbc driver class $driverClass")
}

fun getConnectionUrl(dbType: String, prefix: String, host: String, connectionParams: String?, dbName: String) : String {
when(dbType) {
fun getConnectionUrl(dbType: String, prefix: String, host: String, connectionParams: String?, dbName: String): String {
return when (dbType) {
"hsql" -> prefix + host + "/" + dbName + (connectionParams?.let { ";$it" } ?: "")
"postgres", "mssql", "oracle", "mysql" -> prefix + host + "/" + dbName + (connectionParams?.let { "?$it" } ?: "")
"postgres", "mssql", "oracle", "mysql" -> prefix + host + "/" + dbName + (connectionParams?.let { "?$it" }
?: "")
else -> throw ProjectScanException("Unable to construct jdbc url")
}
throw ProjectScanException("Unable to construct jdbc url")
}

private fun Sequence<MatchResult>.getGroupValue(groupIndex: Int): String? =
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/com/haulmont/cuba/cli/generation/XmlUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ private fun createDocumentBuilder(): DocumentBuilder {
}

fun save(document: Document, path: Path) = DOMSerializer(numIndentSpaces = 4).run {
serialize(document, Files.newOutputStream(path))
Files.newOutputStream(path).use { outputStream ->
serialize(document, outputStream)
}
}

fun updateXml(path: Path, block: Element.() -> Unit) {
Expand Down

0 comments on commit a6966f1

Please sign in to comment.