in exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java [144:562]
public void execute() throws MojoExecutionException, MojoFailureException {
if (!doRunTCK) {
System.out.println("Skipping RunTCK goal!");
return;
}
Properties props = null;
boolean alreadyran = false;
String runonce = "false";
List<String> propsString = new ArrayList<>();
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);
// 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_DIR_NAME
+ File.separator
+ pmfProperties);
propsString.add(
"-DPMF2Properties="
+ buildDirectory
+ File.separator
+ CLASSES_DIR_NAME
+ 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);
try {
copyLog4j2ConfigurationFile();
} catch (IOException ex) {
Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null, ex);
}
// Copy JDO config files to classes dir
try {
fromFile = new File(confDirectory + File.separator + impl + "-jdoconfig.xml");
toFile =
new File(
buildDirectory
+ File.separator
+ CLASSES_DIR_NAME
+ 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_DIR_NAME
+ 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<>(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);
}
// Reset logfile content (may not be empty if previous run crashed)
resetFileContent(implLogFile);
resetFileContent(TCK_LOG_FILE);
int failureCount = 0;
for (String db : dbs) {
System.setProperty("jdo.tck.database", db);
alreadyran = false;
for (String idtype : idtypes) {
List<String> idPropsString = new ArrayList<>();
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<>();
cpList.addAll(urlList);
try {
URL url1 = enhancedDir.toURI().toURL();
URL url2 =
new File(buildDirectory + File.separator + CLASSES_DIR_NAME + 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());
}
for (String dependency : this.dependencyClasspath.split(File.pathSeparator)) {
cpList.add(new File(dependency).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<>();
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"));
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
StringBuilder propsFileData = new StringBuilder();
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_DIR_NAME + 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<>();
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");
failureCount++;
}
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);
}
// Move log to per-test location
String idname = "dsid";
if (idtype.trim().equals("applicationidentity")) {
idname = "app";
}
String configName = cfg;
if (cfg.indexOf('.') > 0) {
configName = configName.substring(0, cfg.indexOf('.'));
}
String testLogFilename = thisLogDir + idname + "-" + configName + "-" + impl + ".txt";
try {
File logFile = new File(implLogFile);
FileUtils.copyFile(logFile, new File(testLogFilename));
resetFileContent(implLogFile);
} catch (Exception e) {
System.out.println(">> Error copying implementation log file: " + e.getMessage());
}
String tckLogFilename = thisLogDir + idname + "-" + configName + "-" + TCK_LOG_FILE;
try {
File logFile = new File(TCK_LOG_FILE);
FileUtils.copyFile(logFile, new File(tckLogFilename));
resetFileContent(TCK_LOG_FILE);
} catch (Exception e) {
System.out.println(">> Error copying tck log file: " + e.getMessage());
}
if (runonce.equals("true")) {
alreadyran = true;
}
if (TCK_PARAM_ON_FAILURE_FAIL_FAST.equals(onFailure) && failureCount > 0) {
break;
}
}
if (TCK_PARAM_ON_FAILURE_FAIL_FAST.equals(onFailure) && failureCount > 0) {
break;
}
}
if (TCK_PARAM_ON_FAILURE_FAIL_FAST.equals(onFailure) && failureCount > 0) {
break;
}
}
// Remove log file
try {
FileUtils.forceDeleteOnExit(new File(implLogFile));
} catch (Exception e) {
System.out.println(">> Error deleting log file: " + e.getMessage());
}
try {
FileUtils.forceDeleteOnExit(new File(TCK_LOG_FILE));
} catch (Exception e) {
System.out.println(">> Error deleting log file: " + e.getMessage());
}
// Output results
command = new ArrayList<>();
command.add("java");
command.add("-cp");
command.add(cpString);
command.add("org.apache.jdo.tck.util.ResultSummary");
command.add(thisLogDir);
result = (new Utilities()).invokeTest(command, new File(buildDirectory));
// Create system configuration description file
command.set(3, "org.apache.jdo.tck.util.SystemCfgSummary");
command.set(4, cfgDirName);
command.add("system_config.txt");
result = (new Utilities()).invokeTest(command, new File(buildDirectory));
// Copy metadata from enhanced to configuration logs directory
for (String idtype : idtypes) {
String fromDirName =
buildDirectory
+ File.separator
+ "enhanced"
+ File.separator
+ impl
+ File.separator
+ idtype
+ File.separator;
String[] metadataExtensions = {"jdo", "jdoquery", "orm", "xml", "properties"};
String fromFileName = null;
String pkgName = null;
int startIdx = -1;
// iterator over list of abs name of metadata files in src
Iterator<File> fi = FileUtils.iterateFiles(new File(fromDirName), metadataExtensions, true);
while (fi.hasNext()) {
try {
fromFile = fi.next();
fromFileName = fromFile.toString();
if ((startIdx = fromFileName.indexOf(idtype + File.separator)) > -1) {
// fully specified name of file (idtype + package + filename)
pkgName = fromFileName.substring(startIdx);
toFile = new File(cfgDirName + File.separator + pkgName);
FileUtils.copyFile(fromFile, toFile);
}
} catch (IOException ex) {
throw new MojoExecutionException(
"Failed to copy files from "
+ fromFileName
+ " to "
+ toFile.toString()
+ ": "
+ ex.getLocalizedMessage());
}
}
}
if (TCK_PARAM_ON_FAILURE_FAIL_FAST.equals(onFailure) && failureCount > 0) {
throw new MojoExecutionException("Aborted TCK test run after 1 failure.");
}
if (TCK_PARAM_ON_FAILURE_FAIL_EVENTUALLY.equals(onFailure) && failureCount > 0) {
throw new MojoExecutionException("There were " + failureCount + " TCK test failures.");
}
}