try {
if (outFile == null)
outFile = inFile;
if (!MyTestRoundtrip.runTest(mappedClass, null, inFile, outFile)) {
throw new MojoExecutionException("Class did not round-trip document on document-compare");
}
} catch (Exception e) {
Throwable cause = (e.getCause() != null) ? e.getCause() : e;
throw new MojoExecutionException(cause.getLocalizedMessage(), cause);
} finally {
Thread.currentThread().setContextClassLoader(parent); // Restore
}
}
else
{ // Run the DocumentComparator
if (outFile == null)
{
getLog().info("For JiBX document compare you must supply two documents or a class and a document");
return;
}
try {
File fileIn = new File(inFile);
File fileOut = new File(outFile);
// compare with output document to be matched
InputStreamReader brdr = new FileReader(fileIn);
InputStreamReader frdr = new FileReader(fileOut);
DocumentComparator comp = new DocumentComparator(System.err);
if (comp.compare(frdr, brdr))
getLog().info("JiBX document compare successful");
else
throw new MojoExecutionException("Documents are not equal on document-compare");
} catch (XmlPullParserException e) {
Throwable cause = (e.getCause() != null) ? e.getCause() : e;
throw new MojoExecutionException(cause.getLocalizedMessage(), cause);
} catch (FileNotFoundException e) {
Throwable cause = (e.getCause() != null) ? e.getCause() : e;
throw new MojoExecutionException(cause.getLocalizedMessage(), cause);
}
}
}