Skip to content

Commit a6966f1

Browse files
Support uberjar and war tasks generation for CUBA 7.2 #191
1 parent 7124b98 commit a6966f1

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

src/main/kotlin/com/haulmont/cuba/cli/cubaplugin/deploy/uberjar/UberJarCommand.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.haulmont.cuba.cli.*
2121
import com.haulmont.cuba.cli.commands.GeneratorCommand
2222
import com.haulmont.cuba.cli.cubaplugin.deploy.ContextXmlParams
2323
import com.haulmont.cuba.cli.cubaplugin.di.cubaKodein
24+
import com.haulmont.cuba.cli.cubaplugin.model.DataSourceProvider
2425
import com.haulmont.cuba.cli.generation.TemplateProcessor
2526
import com.haulmont.cuba.cli.prompting.Answers
2627
import com.haulmont.cuba.cli.prompting.QuestionsList
@@ -63,7 +64,9 @@ class UberJarCommand : GeneratorCommand<UberJarModel>() {
6364
askIf("specifyLogback")
6465
}
6566

66-
confirmation("generateCustomJetty", "Generate custom Jetty environment file?")
67+
if(projectModel.database.dataSourceProvider == DataSourceProvider.JNDI) {
68+
confirmation("generateCustomJetty", "Generate custom Jetty environment file?")
69+
}
6770

6871
ContextXmlParams.run {
6972
askContextXmlParams(projectModel, questionName = "customJettyContextParams", askCondition = "generateCustomJetty")

src/main/kotlin/com/haulmont/cuba/cli/cubaplugin/deploy/uberjar/UberJarModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class UberJarModel(answers: Answers, projectModel: ProjectModel) {
2525
val generateLogback: Boolean by answers
2626
val customLogback: String? by answers.withDefault { null }
2727

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

src/main/kotlin/com/haulmont/cuba/cli/cubaplugin/deploy/war/WarCommand.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.haulmont.cuba.cli.*
2121
import com.haulmont.cuba.cli.commands.GeneratorCommand
2222
import com.haulmont.cuba.cli.cubaplugin.deploy.ContextXmlParams
2323
import com.haulmont.cuba.cli.cubaplugin.di.cubaKodein
24+
import com.haulmont.cuba.cli.cubaplugin.model.DataSourceProvider
2425
import com.haulmont.cuba.cli.generation.TemplateProcessor
2526
import com.haulmont.cuba.cli.prompting.Answers
2627
import com.haulmont.cuba.cli.prompting.QuestionsList
@@ -60,8 +61,10 @@ class WarCommand : GeneratorCommand<WarModel>() {
6061

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

63-
confirmation("generateContextXml", "Generate custom context.xml?") {
64-
askIf("includeTomcatContextXml")
64+
if(projectModel.database.dataSourceProvider == DataSourceProvider.JNDI) {
65+
confirmation("generateContextXml", "Generate custom context.xml?") {
66+
askIf("includeTomcatContextXml")
67+
}
6568
}
6669

6770
ContextXmlParams.run {

src/main/kotlin/com/haulmont/cuba/cli/cubaplugin/model/ProjectModel.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ private fun parseJndiDatabase(projectStructure: ProjectStructure): Database? {
133133
.resolve("context.xml")
134134

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

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

213-
fun getConnectionUrl(dbType: String, prefix: String, host: String, connectionParams: String?, dbName: String) : String {
214-
when(dbType) {
214+
fun getConnectionUrl(dbType: String, prefix: String, host: String, connectionParams: String?, dbName: String): String {
215+
return when (dbType) {
215216
"hsql" -> prefix + host + "/" + dbName + (connectionParams?.let { ";$it" } ?: "")
216-
"postgres", "mssql", "oracle", "mysql" -> prefix + host + "/" + dbName + (connectionParams?.let { "?$it" } ?: "")
217+
"postgres", "mssql", "oracle", "mysql" -> prefix + host + "/" + dbName + (connectionParams?.let { "?$it" }
218+
?: "")
219+
else -> throw ProjectScanException("Unable to construct jdbc url")
217220
}
218-
throw ProjectScanException("Unable to construct jdbc url")
219221
}
220222

221223
private fun Sequence<MatchResult>.getGroupValue(groupIndex: Int): String? =

src/main/kotlin/com/haulmont/cuba/cli/generation/XmlUtils.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ private fun createDocumentBuilder(): DocumentBuilder {
6161
}
6262

6363
fun save(document: Document, path: Path) = DOMSerializer(numIndentSpaces = 4).run {
64-
serialize(document, Files.newOutputStream(path))
64+
Files.newOutputStream(path).use { outputStream ->
65+
serialize(document, outputStream)
66+
}
6567
}
6668

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

0 commit comments

Comments
 (0)