boolean alreadyran = false;
String runonce = "false";
List<String> propsString = new ArrayList<String>();
List<String> command;
String cpString = null;
InvocationResult result;
File fromFile = null;
File toFile = null;
if (impl.equals("iut")) {
pmfProperties="iut-pmf.properties";
}
if (cfgs == null) {
if (cfgList != null) {
cfgs = new ArrayList<String>();
PropertyUtils.string2List(cfgList, (List<String>)cfgs);
} else {
// Fallback to "src/conf/configurations.list"
setCfgListFromFile();
if (cfgList != null) {
cfgs = new ArrayList<String>();
PropertyUtils.string2List(cfgList, (List<String>)cfgs);
}
if (cfgList == null) {
throw new MojoExecutionException(
"Could not find configurations to run TCK. " +
"Set cfgList parameter on command line or cfgs in pom.xml");
}
}
}
PropertyUtils.string2Set(dblist, dbs);
PropertyUtils.string2Set(identitytypes, idtypes);
System.out.println("*>TCK to be run for implementation '" + impl +
"' on \n" +
" configurations: " + cfgs.toString() + "\n" +
" databases: " + dbs.toString() + "\n" +
" identitytypes: " + identitytypes.toString());
// Properties required for test execution
System.out.println("cleanupaftertest is " + cleanupaftertest);
propsString.add("-DResultPrinterClass=" + resultPrinterClass);
propsString.add("-Dverbose=" + verbose);
propsString.add("-Djdo.tck.cleanupaftertest=" + cleanupaftertest);
propsString.add("-DPMFProperties=" + buildDirectory + File.separator
+ "classes" + File.separator + pmfProperties);
propsString.add("-DPMF2Properties=" + buildDirectory + File.separator
+ "classes" + File.separator + pmfProperties);
String excludeFile = confDirectory + File.separator + exclude;
propsString.add("-Djdo.tck.exclude="
+ getTrimmedPropertyValue(PropertyUtils.getProperties(excludeFile), "jdo.tck.exclude"));
// Create configuration log directory
String timestamp = Utilities.now();
String thisLogDir = logsDirectory + File.separator + timestamp
+ File.separator;
String cfgDirName = thisLogDir + "configuration";
File cfgDir = new File(cfgDirName);
if (!(cfgDir.exists()) && !(cfgDir.mkdirs())) {
throw new MojoExecutionException("Failed to create directory "
+ cfgDirName);
}
propsString.add("-Djdo.tck.log.directory=" + thisLogDir);
// Copy JDO config files to classes dir
try {
fromFile = new File(confDirectory + File.separator + impl + "-jdoconfig.xml");
toFile = new File(buildDirectory + File.separator + "classes" +
File.separator + "META-INF" + File.separator + "jdoconfig.xml");
FileUtils.copyFile(fromFile, toFile);
fromFile = new File(confDirectory + File.separator + impl + "-persistence.xml");
toFile = new File(buildDirectory + File.separator + "classes" +
File.separator + "META-INF" + File.separator + "persistence.xml");
FileUtils.copyFile(fromFile, toFile);
} catch (IOException ex) {
Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null, ex);
}
// Get ClassLoader URLs to build classpath below
URL[] cpURLs = ((URLClassLoader) Thread.currentThread().getContextClassLoader()).getURLs();
ArrayList<URL> urlList = new ArrayList<URL>(Arrays.asList(cpURLs));
// Get contents of pmf properties file to build new file below
String pmfPropsReadFileName = confDirectory + File.separator + pmfProperties;
String defaultPropsContents = "";
try {
defaultPropsContents = Utilities.readFile(pmfPropsReadFileName);
} catch (IOException ex) {
Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null, ex);
}
for (String db : dbs) {
System.setProperty("jdo.tck.database", db);
alreadyran = false;
for (String idtype : idtypes) {
List<String> idPropsString = new ArrayList<String>();
idPropsString.addAll(propsString);
idPropsString.add("-Djdo.tck.identitytype=" + idtype);
String enhancedDirName = buildDirectory + File.separator + "enhanced"
+ File.separator + impl + File.separator + idtype + File.separator;
File enhancedDir = new File(enhancedDirName);
if (!(enhancedDir.exists())) {
throw new MojoExecutionException("Could not find enhanced directory "
+ enhancedDirName + ". Execute Enhance goal before RunTCK.");
}
// Set classpath string: add new entries to URLS from loader
ArrayList<URL> cpList = new ArrayList<URL>();
cpList.addAll(urlList);
try {
URL url1 = enhancedDir.toURI().toURL();
URL url2 = new File(buildDirectory + File.separator
+ "classes" + File.separator).toURI().toURL();
if (runtckVerbose) {
System.out.println("url2 is " + url2.toString());
}
cpList.add(url1);
cpList.add(url2);
String[] jars = {"jar"};
Iterator<File> fi = FileUtils.iterateFiles(
new File(extLibsDirectory), jars, true);
while (fi.hasNext()) {
cpList.add(fi.next().toURI().toURL());
}
if (impl.equals("iut")) {
fi = FileUtils.iterateFiles(
new File(iutLibsDirectory), jars, true);
while (fi.hasNext()) {
cpList.add(fi.next().toURI().toURL());
}
} else {
fi = FileUtils.iterateFiles(
new File(jdoriLibsDirectory), jars, true);
while (fi.hasNext()) {
cpList.add(fi.next().toURI().toURL());
}
}
} catch (MalformedURLException ex) {
ex.printStackTrace();
Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null, ex);
}
cpString = Utilities.urls2ClasspathString(cpList);
if (runtckVerbose) {
System.out.println("\nClasspath is " + cpString);
}
for (String cfg : cfgs) {
List<String> cfgPropsString = new ArrayList<String>();
cfgPropsString.addAll(idPropsString);
// Parse conf file and set properties String
props = PropertyUtils.getProperties(confDirectory
+ File.separator + cfg);
cfgPropsString.add("-Djdo.tck.testdata="
+ getTrimmedPropertyValue(props, "jdo.tck.testdata"));
cfgPropsString.add("-Djdo.tck.standarddata="
+ getTrimmedPropertyValue(props, "jdo.tck.standarddata"));
cfgPropsString.add("-Djdo.tck.mapping.companyfactory="
+ getTrimmedPropertyValue(props, "jdo.tck.mapping.companyfactory"));
// innerPropsString.append("-Djdo.tck.description=\"" +
// props.getProperty("jdo.tck.description") + "\"");
cfgPropsString.add("-Djdo.tck.requiredOptions="
+ getTrimmedPropertyValue(props, "jdo.tck.requiredOptions"));
cfgPropsString.add("-Djdo.tck.signaturefile="
+ signaturefile);
String mapping = getTrimmedPropertyValue(props, "jdo.tck.mapping");
if (mapping == null) {
throw new MojoExecutionException(
"Could not find mapping value in conf file: " + cfg);
}
String classes = getTrimmedPropertyValue(props, "jdo.tck.classes");
String excludeList = getTrimmedPropertyValue(
PropertyUtils.getProperties(excludeFile), "jdo.tck.exclude");
if (classes == null) {
throw new MojoExecutionException(
"Could not find classes value in conf file: " + cfg);
}
classes = Utilities.removeSubstrs(classes, excludeList);
if (classes.equals("")) {
System.out.println("Skipping configuration " + cfg +
": classes excluded");
continue;
}
List<String> classesList = Arrays.asList(classes.split(" "));
cfgPropsString.add("-Djdo.tck.schemaname=" + idtype + mapping);
cfgPropsString.add("-Djdo.tck.cfg=" + cfg);
runonce = getTrimmedPropertyValue(props, "runOnce");
runonce = (runonce == null) ? "false" : runonce;
// Add Mapping and schemaname to properties file
StringBuffer propsFileData = new StringBuffer();
propsFileData.append("\n### Properties below added by maven 2 goal RunTCK.jdori");
propsFileData.append("\njavax.jdo.mapping.Schema=" + idtype + mapping);
mapping = (mapping.equals("0")) ? "" : mapping;
propsFileData.append("\njavax.jdo.option.Mapping=standard" + mapping);
propsFileData.append("\n");
String pmfPropsWriteFileName = buildDirectory + File.separator
+ "classes" + File.separator + pmfProperties;
try {
BufferedWriter out = new BufferedWriter(new FileWriter(pmfPropsWriteFileName, false));
out.write(defaultPropsContents + propsFileData.toString());
out.close();
} catch (IOException ex) {
Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null, ex);
}
// build command line string
command = new ArrayList<String>();
command.add("java");
command.add("-cp");
command.add(cpString);
command.addAll(cfgPropsString);
command.add(dbproperties);
command.add(jvmproperties);
if (debugTCK) {
command.add(debugDirectives);
}
command.add(testRunnerClass);
command.addAll(classesList);
if (runonce.equals("true") && alreadyran) {
continue;
}
if (debugTCK) {
System.out.println("Using debug arguments: \n"
+ debugDirectives);
}
// invoke class runner
System.out.print("*> Running tests for " + cfg +
" with " + idtype +
" on '" + db + "'" +
" mapping=" + mapping + " ... ");
try {
result = (new Utilities()).invokeTest(command);
if (result.getExitValue() == 0) {
System.out.println("success");
} else {
System.out.println("FAIL");
}
if (runtckVerbose) {
System.out.println("\nCommand line is: \n" + command.toString());
System.out.println("Test exit value is " + result.getExitValue());
System.out.println("Test result output:\n" + result.getOutputString());
System.out.println("Test result error:\n" + result.getErrorString());
}
} catch (java.lang.RuntimeException re) {
System.out.println("Exception on command " + command);
}