org.apache.fop.tools.anttasks.RunTest Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* $Id: RunTest.java 1780541 2017-01-27 11:27:04Z ssteiner $ */
package org.apache.fop.tools.anttasks;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
/**
* Testing ant task.
* This task is used to test FOP as a build target.
* This uses the TestConverter (with weak code dependency)
* to run the tests and check the results.
*/
public class RunTest extends Task {
private String basedir;
private String testsuite = "";
private String referenceJar = "";
private String refVersion = "";
/**
* Sets the test suite name.
* @param str name of the test suite
*/
public void setTestSuite(String str) {
testsuite = str;
}
/**
* Sets the base directory.
* @param str base directory
*/
public void setBasedir(String str) {
basedir = str;
}
/**
* Sets the reference directory.
* @param str reference directory
*/
public void setReference(String str) {
referenceJar = str;
}
/**
* Sets the reference version.
* @param str reference version
*/
public void setRefVersion(String str) {
refVersion = str;
}
/**
* This creates the reference output, if required, then tests
* the current build.
* {@inheritDoc}
*/
public void execute() throws BuildException {
runReference();
testNewBuild();
}
/**
* Test the current build.
* This uses the current jar file (in build/fop.jar) to run the
* tests with.
* The output is then compared with the reference output.
*/
protected void testNewBuild() {
try {
ClassLoader loader = new URLClassLoader(
createUrls("build/fop.jar"));
Map diff = runConverter(loader, "areatree",
"reference/output/");
if (diff != null && !diff.isEmpty()) {
System.out.println("====================================");
System.out.println("The following files differ:");
boolean broke = false;
for (Map.Entry