diff --git a/src/main/groovy/org/silverpeas/setup/SilverpeasSetupPlugin.groovy b/src/main/groovy/org/silverpeas/setup/SilverpeasSetupPlugin.groovy index 13316037..d92e815e 100644 --- a/src/main/groovy/org/silverpeas/setup/SilverpeasSetupPlugin.groovy +++ b/src/main/groovy/org/silverpeas/setup/SilverpeasSetupPlugin.groovy @@ -175,7 +175,7 @@ class SilverpeasSetupPlugin implements Plugin { 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)) } diff --git a/src/main/groovy/org/silverpeas/setup/TaskEventLogging.groovy b/src/main/groovy/org/silverpeas/setup/TaskEventLogging.groovy index 4bfd71e5..72892c00 100644 --- a/src/main/groovy/org/silverpeas/setup/TaskEventLogging.groovy +++ b/src/main/groovy/org/silverpeas/setup/TaskEventLogging.groovy @@ -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) diff --git a/src/main/groovy/org/silverpeas/setup/api/JBossServer.groovy b/src/main/groovy/org/silverpeas/setup/api/JBossServer.groovy index 8a988116..d0c9da33 100644 --- a/src/main/groovy/org/silverpeas/setup/api/JBossServer.groovy +++ b/src/main/groovy/org/silverpeas/setup/api/JBossServer.groovy @@ -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) } } @@ -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 } } diff --git a/src/main/groovy/org/silverpeas/setup/configuration/JBossConfigurationTask.groovy b/src/main/groovy/org/silverpeas/setup/configuration/JBossConfigurationTask.groovy index f769d529..66d6c6ab 100644 --- a/src/main/groovy/org/silverpeas/setup/configuration/JBossConfigurationTask.groovy +++ b/src/main/groovy/org/silverpeas/setup/configuration/JBossConfigurationTask.groovy @@ -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) { diff --git a/src/main/groovy/org/silverpeas/setup/configuration/VariableReplacement.groovy b/src/main/groovy/org/silverpeas/setup/configuration/VariableReplacement.groovy index b8bd1ddd..5d1f0609 100644 --- a/src/main/groovy/org/silverpeas/setup/configuration/VariableReplacement.groovy +++ b/src/main/groovy/org/silverpeas/setup/configuration/VariableReplacement.groovy @@ -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 @@ -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 @@ -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: ${TOTO:32} declares the variable + * TOTO with 32 as default value and ${TOTO} 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 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 } }