Skip to content

Commit 074737d

Browse files
committed
Bug #10969
Fix the development mode checking. Fix the command status parsing with CLI scripts (in JBossServer) Add a way to specify a default value in variable placeholders in an expression. For example, a variable without default value can be used as before in an expression: ${MY_VARIABLE}. Beside that, a default value can be indicated as such: ${MY_VARIABLE:true} the semi-colon is used as the separator between the variable name and its default value. When the variable placeholder is encountered within an expression and it has no values set (for example in the config.properties), then the default value is used to replace the variable placehodler.
1 parent 90de1fb commit 074737d

File tree

6 files changed

+36
-22
lines changed

6 files changed

+36
-22
lines changed

src/main/groovy/org/silverpeas/setup/SilverpeasSetupPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class SilverpeasSetupPlugin implements Plugin<Project> {
175175
build.outputs.upToDateWhen {
176176
boolean ok = extension.installation.distDir.get().exists() &&
177177
Files.exists(Paths.get(extension.installation.distDir.get().path, 'WEB-INF', 'web.xml'))
178-
if (!extension.installation.developmentMode) {
178+
if (!extension.installation.developmentMode.get()) {
179179
ok = ok && Files.exists(
180180
Paths.get(project.buildDir.path, SilverpeasConstructionTask.SILVERPEAS_WAR))
181181
}

src/main/groovy/org/silverpeas/setup/TaskEventLogging.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ class TaskEventLogging extends BuildAdapter implements TaskExecutionListener {
6868
buildStarted = true
6969
SilverpeasSetupExtension silverSetup =
7070
(SilverpeasSetupExtension) task.project.extensions.getByName(SilverpeasSetupPlugin.EXTENSION)
71+
String javaHome = System.getenv('JAVA_HOME')
7172
FileLogger.getLogger(DEFAULT_LOG_NAMESPACE).formatInfo('%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n',
7273
"SILVERPEAS SETUP: ${task.project.version}",
7374
"SILVERPEAS HOME: ${silverSetup.silverpeasHome.path}",
7475
"JBOSS HOME: ${silverSetup.jbossHome.path}",
7576
"JCR HOME: ${silverSetup.settings.JCR_HOME.asPath().toString()}",
76-
"JAVA HOME: ${System.getenv('JAVA_HOME')}",
77+
"JAVA HOME: ${javaHome != null ? javaHome : 'not set'}",
7778
"DATABASE: ${silverSetup.settings.DB_SERVERTYPE.toLowerCase()}",
7879
"OPERATING SYSTEM: ${System.getProperty('os.name')}",
79-
"PRODUCTION MODE: ${!silverSetup.installation.developmentMode}")
80+
"PRODUCTION MODE: ${!silverSetup.installation.developmentMode.get()}")
8081
}
8182
FileLogger log = FileLogger.getLogger(task.name)
8283
String taskTitle = unformat(task.name)

src/main/groovy/org/silverpeas/setup/api/JBossServer.groovy

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ class JBossServer {
8181
}
8282

8383
private void assertCommandSucceeds(command) throws AssertionError, InvalidObjectException {
84-
String message = command.in.text
85-
if (command.exitValue() != 0 || message.contains('"outcome" => "failed"')) {
86-
String error = command.err.text
87-
if (!error) {
88-
throw new InvalidObjectException(message)
84+
String result = command.in.text
85+
if (command.exitValue() != 0 || result.contains('"outcome" => "failed"')) {
86+
boolean rollBacked = result.contains('"rolled-back" => true')
87+
String msg = "Execution Output: \n${result}"
88+
if (!rollBacked) {
89+
throw new InvalidObjectException(msg)
8990
}
90-
throw new AssertionError(error)
91+
throw new AssertionError(msg)
9192
}
9293
}
9394

@@ -503,6 +504,7 @@ class JBossServer {
503504
logger.warn "Invalid resource. ${e.message}"
504505
} catch (AssertionError | Exception e) {
505506
logger.info "${commandsFile.name} processing: [FAILURE]"
507+
logger.error e.message
506508
throw e
507509
}
508510
}

src/main/groovy/org/silverpeas/setup/configuration/ConfigurationScriptBuilder.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ConfigurationScriptBuilder {
7575
switch(type.toLowerCase()) {
7676
case 'cli':
7777
if (cliScript) {
78-
cliScript.toFile() << new File(scriptPath).text
78+
cliScript.toFile() << new File(scriptPath).text + '\n'
7979
script = cliScript
8080
} else {
8181
script = new JBossCliScript(scriptPath)

src/main/groovy/org/silverpeas/setup/configuration/JBossConfigurationTask.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class JBossConfigurationTask extends SilverpeasSetupTask {
146146
(driver.name.startsWith('ojdbc') && settings.DB_SERVERTYPE == 'ORACLE')) {
147147
settings.DB_DRIVER_NAME = driver.name
148148
try {
149+
server.remove(settings.DB_DRIVER_NAME)
149150
server.add(Paths.get(driversDir.path, settings.DB_DRIVER_NAME).toString())
150151
server.deploy(settings.DB_DRIVER_NAME)
151152
} catch (Exception ex) {

src/main/groovy/org/silverpeas/setup/configuration/VariableReplacement.groovy

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ package org.silverpeas.setup.configuration
2525

2626
import org.gradle.api.tasks.StopExecutionException
2727

28+
import java.util.regex.Matcher
29+
2830
/**
2931
* A replacement of any variable declarations by their value obtained from a map of key-values.
3032
* The environment variables and the system properties aren't taken in charge; they won't be then
@@ -35,7 +37,7 @@ import org.gradle.api.tasks.StopExecutionException
3537
*/
3638
class VariableReplacement {
3739

38-
private static final def VARIABLE_PATTERN = /\$\{(\w+)\}/
40+
private static final def VARIABLE_PATTERN = /\$\{(\w+)(:([^}]+))?\}/
3941

4042
/**
4143
* Parses the values of the specified parameters and for each of them, replace any variable
@@ -57,31 +59,39 @@ class VariableReplacement {
5759

5860
/**
5961
* Parses any variable declaration in the specified expression and replace them by their value
60-
* from the specified variables. If a variable, present in
61-
* the parameter value, isn't among the given variables, then an exception is thrown.
62+
* from the specified variables. A default value can be defined in a variable declaration in the
63+
* case the variable isn't found in the variables passed in the arguments of the method. A default
64+
* value can be specified in a variable declaration by declaring it just after the variable name,
65+
* separated with the ':' character. For example: <code>${TOTO:32}</code> declares the variable
66+
* TOTO with 32 as default value and <code>${TOTO}</code> defines the variable TOTO without any
67+
* default value. If a variable in the expression isn't declared among the given variables and
68+
* doesn't define a default value then an exception is thrown.
6269
* @param expression the expression to parse.
6370
* @param variables a map of key-value whose the key is a variable identifier and the value the
6471
* variable value.
6572
* @return the specified expression with any variable declaration replaced by their value.
6673
*/
6774
static final String parseExpression(String expression, Map variables) {
68-
def matching = expression =~ VARIABLE_PATTERN
69-
matching.each { token ->
75+
String parsedExpression = expression
76+
Matcher matching = expression =~ VARIABLE_PATTERN
77+
matching.each { List<String> token ->
78+
String varName = token[1]
79+
String varValue = variables.containsKey(varName) ? variables[varName] : token[3]
7080
try {
71-
if (!token[1].startsWith('env') && !token[1].startsWith('sys')) {
72-
if (variables.containsKey(token[1])) {
73-
expression = expression.replace(token[0], variables[token[1]])
81+
if (!varName.startsWith('env') && !varName.startsWith('sys')) {
82+
if (varValue != null) {
83+
parsedExpression = expression.replace(token[0], varValue)
7484
} else {
75-
println "Error: no such variable ${token[1]}"
76-
throw new StopExecutionException("Error: no such variable ${token[1]}")
85+
println "Error: no such variable ${varName}"
86+
throw new StopExecutionException("Error: no such variable ${varName}")
7787
}
7888
}
7989
} catch (Exception e) {
80-
println "Error: cannot replace token ${token[0]} by value of ${token[1]}: ${variables[token[1]]}"
90+
println "Error: cannot replace token ${token[0]} by value of ${varName} that is ${varValue}"
8191
throw e
8292
}
8393
}
84-
return expression
94+
return parsedExpression
8595
}
8696

8797
}

0 commit comments

Comments
 (0)