Skip to content

Commit

Permalink
Bug #10969
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mmoqui committed Sep 23, 2019
1 parent 90de1fb commit 8716856
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
Expand Up @@ -175,7 +175,7 @@ class SilverpeasSetupPlugin implements Plugin<Project> {
build.outputs.upToDateWhen {
boolean ok = extension.installation.distDir.get().exists() &&
Files.exists(Paths.get(extension.installation.distDir.get().path, 'WEB-INF', 'web.xml'))
if (!extension.installation.developmentMode) {
if (!extension.installation.developmentMode.get()) {
ok = ok && Files.exists(
Paths.get(project.buildDir.path, SilverpeasConstructionTask.SILVERPEAS_WAR))
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/groovy/org/silverpeas/setup/TaskEventLogging.groovy
Expand Up @@ -68,15 +68,16 @@ class TaskEventLogging extends BuildAdapter implements TaskExecutionListener {
buildStarted = true
SilverpeasSetupExtension silverSetup =
(SilverpeasSetupExtension) task.project.extensions.getByName(SilverpeasSetupPlugin.EXTENSION)
String javaHome = System.getenv('JAVA_HOME')
FileLogger.getLogger(DEFAULT_LOG_NAMESPACE).formatInfo('%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n',
"SILVERPEAS SETUP: ${task.project.version}",
"SILVERPEAS HOME: ${silverSetup.silverpeasHome.path}",
"JBOSS HOME: ${silverSetup.jbossHome.path}",
"JCR HOME: ${silverSetup.settings.JCR_HOME.asPath().toString()}",
"JAVA HOME: ${System.getenv('JAVA_HOME')}",
"JAVA HOME: ${javaHome != null ? javaHome : 'not set'}",
"DATABASE: ${silverSetup.settings.DB_SERVERTYPE.toLowerCase()}",
"OPERATING SYSTEM: ${System.getProperty('os.name')}",
"PRODUCTION MODE: ${!silverSetup.installation.developmentMode}")
"PRODUCTION MODE: ${!silverSetup.installation.developmentMode.get()}")
}
FileLogger log = FileLogger.getLogger(task.name)
String taskTitle = unformat(task.name)
Expand Down
14 changes: 8 additions & 6 deletions src/main/groovy/org/silverpeas/setup/api/JBossServer.groovy
Expand Up @@ -81,13 +81,14 @@ class JBossServer {
}

private void assertCommandSucceeds(command) throws AssertionError, InvalidObjectException {
String message = command.in.text
if (command.exitValue() != 0 || message.contains('"outcome" => "failed"')) {
String error = command.err.text
if (!error) {
throw new InvalidObjectException(message)
String result = command.in.text
if (command.exitValue() != 0 || result.contains('"outcome" => "failed"')) {
boolean rollBacked = result.contains('"rolled-back" => true')
String msg = "Execution Output: \n${result}"
if (!rollBacked) {
throw new InvalidObjectException(msg)
}
throw new AssertionError(error)
throw new AssertionError(msg)
}
}

Expand Down Expand Up @@ -503,6 +504,7 @@ class JBossServer {
logger.warn "Invalid resource. ${e.message}"
} catch (AssertionError | Exception e) {
logger.info "${commandsFile.name} processing: [FAILURE]"
logger.error e.message
throw e
}
}
Expand Down
Expand Up @@ -146,6 +146,7 @@ class JBossConfigurationTask extends SilverpeasSetupTask {
(driver.name.startsWith('ojdbc') && settings.DB_SERVERTYPE == 'ORACLE')) {
settings.DB_DRIVER_NAME = driver.name
try {
server.remove(settings.DB_DRIVER_NAME)
server.add(Paths.get(driversDir.path, settings.DB_DRIVER_NAME).toString())
server.deploy(settings.DB_DRIVER_NAME)
} catch (Exception ex) {
Expand Down
Expand Up @@ -25,6 +25,8 @@ package org.silverpeas.setup.configuration

import org.gradle.api.tasks.StopExecutionException

import java.util.regex.Matcher

/**
* A replacement of any variable declarations by their value obtained from a map of key-values.
* The environment variables and the system properties aren't taken in charge; they won't be then
Expand All @@ -35,7 +37,7 @@ import org.gradle.api.tasks.StopExecutionException
*/
class VariableReplacement {

private static final def VARIABLE_PATTERN = /\$\{(\w+)\}/
private static final def VARIABLE_PATTERN = /\$\{(\w+)(:(\w+))?\}/

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

/**
* Parses any variable declaration in the specified expression and replace them by their value
* from the specified variables. If a variable, present in
* the parameter value, isn't among the given variables, then an exception is thrown.
* from the specified variables. A default value can be defined in a variable declaration in the
* case the variable isn't found in the variables passed in the arguments of the method. A default
* value can be specified in a variable declaration by declaring it just after the variable name,
* separated with the ':' character. For example: <code>${TOTO:32}</code> declares the variable
* TOTO with 32 as default value and <code>${TOTO}</code> defines the variable TOTO without any
* default value. If a variable in the expression isn't declared among the given variables and
* doesn't define a default value then an exception is thrown.
* @param expression the expression to parse.
* @param variables a map of key-value whose the key is a variable identifier and the value the
* variable value.
* @return the specified expression with any variable declaration replaced by their value.
*/
static final String parseExpression(String expression, Map variables) {
def matching = expression =~ VARIABLE_PATTERN
matching.each { token ->
String parsedExpression = expression
Matcher matching = expression =~ VARIABLE_PATTERN
matching.each { List<String> token ->
String varName = token[1]
String varValue = variables.containsKey(varName) ? variables[varName] : token[3]
try {
if (!token[1].startsWith('env') && !token[1].startsWith('sys')) {
if (variables.containsKey(token[1])) {
expression = expression.replace(token[0], variables[token[1]])
if (!varName.startsWith('env') && !varName.startsWith('sys')) {
if (varValue != null) {
parsedExpression = expression.replace(token[0], varValue)
} else {
println "Error: no such variable ${token[1]}"
throw new StopExecutionException("Error: no such variable ${token[1]}")
println "Error: no such variable ${varName}"
throw new StopExecutionException("Error: no such variable ${varName}")
}
}
} catch (Exception e) {
println "Error: cannot replace token ${token[0]} by value of ${token[1]}: ${variables[token[1]]}"
println "Error: cannot replace token ${token[0]} by value of ${varName} that is ${varValue}"
throw e
}
}
return expression
return parsedExpression
}

}

0 comments on commit 8716856

Please sign in to comment.