Skip to content

Commit

Permalink
Convert .cli config for tests to Groovy script
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Dec 7, 2017
1 parent c4eee90 commit 7b9266e
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 183 deletions.
96 changes: 44 additions & 52 deletions server/etc/scripts/runJbossCli.groovy
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import java.nio.file.Files
import java.nio.file.attribute.PosixFilePermission

import static java.nio.file.attribute.PosixFilePermission.*


/*
* Copyright 2017, Red Hat, Inc. and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
Expand All @@ -24,57 +18,55 @@ import static java.nio.file.attribute.PosixFilePermission.*
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

/**
* @author Patrick Huang
* <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
* @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*/
String appServerHome = project.properties.get('appserver.home')

if (appServerHome == null) {
throw new Exception('Missing appserver properties. Please invoke mvn with -Dappserver=jbosseap6 or -Dappserver=wildfly8')
String getPropertyValue(String name) {
def value = session.userProperties.get(name)
if (value) return value //property was defined from command line e.g.: -DpropertyName=value
return project.properties.get(name)
}

File baseDir = new File(project.basedir as String)

// basedir will be either functional-test module or services/zanata-war module
File commonCLIScript = new File(baseDir.getParentFile(), "etc/scripts/zanata-config-test-common.cli")
File arqTestCLIScript = new File(baseDir.getParentFile(), "etc/scripts/zanata-config-arq-test.cli")

File serverHome = new File(appServerHome)

String ext = isWindows() ? 'bat' : 'sh'

File jbossCLI = new File(serverHome, "bin/jboss-cli.$ext")

// need to set file to executable
Set<PosixFilePermission> permissions = [GROUP_READ, GROUP_EXECUTE, OTHERS_EXECUTE, OTHERS_READ, OWNER_EXECUTE, OWNER_READ, OWNER_WRITE]
Files.setPosixFilePermissions(jbossCLI.toPath(), permissions)

runJBossCLI(jbossCLI, commonCLIScript)
if (project.artifactId != 'functional-test') {
// we are running arquillian test. need to run extra script
runJBossCLI(jbossCLI, arqTestCLIScript)
}

static void runJBossCLI(File jbossCLI, File cliScript) {
String cmd = "$jbossCLI.absolutePath --file=$cliScript.absolutePath"

println "about to execute $cmd"

def sout = new StringBuilder(), serr = new StringBuilder()
def proc = cmd.execute()
proc.consumeProcessOutput(sout, serr)
// give it 30 seconds
proc.waitForOrKill(30000)
println "jboss cli execution:stdout> $sout"
if (!serr.toString().isEmpty()) {
println "jboss cli execution:stderr> $serr"
}
def exitValue = proc.exitValue()
assert exitValue == 0 : "jboss cli execution returned non-zero code:$exitValue"
String appServerHome = getPropertyValue('appserver.home')
if (appServerHome == null) {
throw new Exception('Missing appserver properties. Please invoke mvn with -Dappserver=jbosseap6/wildfly8 or -Dappserver.home=jboss_home_dir')
}


static boolean isWindows() {
System.properties.getProperty('os.name').toLowerCase().contains('windows')
// NB: project is a MavenProject
// http://maven.apache.org/ref/3-LATEST/maven-core/apidocs/org/apache/maven/project/MavenProject.html

def groovyAll = project.artifactMap.get('org.codehaus.groovy:groovy-all')
if (!groovyAll) throw new Exception("Please add groovy-all as a dependency")

String scriptName = 'zanataConfigTest.groovy'
String zanataConfigScript = new File("${project.basedir}/../etc/scripts/$scriptName").canonicalPath

def args = [
'java',
'-Djava.util.logging.manager=org.jboss.logmanager.LogManager',
'-jar', "$appServerHome/jboss-modules.jar",
'-modulepath', "$appServerHome/modules",
'-dependencies', 'org.jboss.as.cli,org.apache.commons.cli,org.jboss.logmanager',
'-classpath', groovyAll.file,
'groovy.ui.GroovyMain',
zanataConfigScript
// ,'-v'
]

boolean runningArquillian = project.artifactId != 'functional-test'
if (runningArquillian) args.add('--datasource')

println "Executing $scriptName"
//println args

// 'as String[]' coerces any GStrings and Files to Strings
def processBuilder = new ProcessBuilder(args as String[])
processBuilder.environment().put('JBOSS_HOME', appServerHome)
def resultCode = processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT).redirectError(ProcessBuilder.Redirect.INHERIT).start().waitFor()
if (resultCode) {
throw new Exception("$scriptName failed with exit code $resultCode")
} else {
println "$scriptName completed successfully"
}
17 changes: 0 additions & 17 deletions server/etc/scripts/zanata-config-arq-test.cli

This file was deleted.

113 changes: 0 additions & 113 deletions server/etc/scripts/zanata-config-test-common.cli

This file was deleted.

Loading

0 comments on commit 7b9266e

Please sign in to comment.