reporterConfigs = Lists.newArrayList();
-
- private String m_testNames = "";
-
- public void setParallel(String parallel) {
- m_parallelMode = parallel;
- }
-
- public void setThreadCount(String threadCount) {
- m_threadCount = threadCount;
- }
-
- public void setDataProviderThreadCount(String dataproviderthreadCount) {
- m_dataproviderthreadCount = dataproviderthreadCount;
- }
-
- public void setUseDefaultListeners(String f) {
- m_useDefaultListeners = f;
- }
-
- // Ant task settings
- public void setHaltonfailure(boolean value) {
- m_haltOnFailure = value;
- }
-
- public void setOnHaltTarget(String targetName) {
- m_onHaltTarget = targetName;
- }
-
- public void setFailureProperty(String propertyName) {
- m_failurePropertyName = propertyName;
- }
-
- public void setHaltonskipped(boolean value) {
- m_haltOnSkipped = value;
- }
-
- public void setSkippedProperty(String propertyName) {
- m_skippedPropertyName = propertyName;
- }
-
- public void setHaltonFSP(boolean value) {
- m_haltOnFSP = value;
- }
-
- public void setFSPProperty(String propertyName) {
- m_fspPropertyName = propertyName;
- }
-
- public void setDelegateCommandSystemProperties(boolean value) {
- m_delegateCommandSystemProperties = value;
- }
-
- /**
- * @param verbose the flag to log the command line. When verbose is set to true the command line
- * parameters are stored in a temporary file stored in the user's default temporary file
- * directory. The file created is prefixed with "testng".
- */
- public void setDumpCommand(boolean verbose) {
- m_dump = verbose;
- }
-
- /**
- * Sets the flag to write on System.out
the Ant Environment properties.
- *
- * @param verbose true
for printing
- */
- public void setDumpEnv(boolean verbose) {
- m_dumpEnv = verbose;
- }
-
- /**
- * Sets te flag to write on System.out
the system properties.
- *
- * @param verbose true
for dumping the info
- */
- public void setDumpSys(boolean verbose) {
- m_dumpSys = verbose;
- }
-
- public void setEnableAssert(boolean flag) {
- m_assertEnabled = flag;
- }
-
- /**
- * The directory to invoke the VM in.
- *
- * @param workingDir the directory to invoke the JVM from.
- */
- public void setWorkingDir(File workingDir) {
- m_workingDir = workingDir;
- }
-
- /**
- * Sets a particular JVM to be used. Default is 'java' and is solved by Runtime.exec()
- *
.
- *
- * @param jvm the new jvm
- */
- public void setJvm(String jvm) {
- getJavaCommand().setVm(jvm);
- }
-
- /**
- * Set the timeout value (in milliseconds).
- *
- * If the tests are running for more than this value, the tests will be canceled.
- *
- * @param value the maximum time (in milliseconds) allowed before declaring the test as
- * 'timed-out'
- */
- public void setTimeout(Integer value) {
- m_timeout = value;
- }
-
- public Commandline.Argument createJvmarg() {
- return getJavaCommand().createVmArgument();
- }
-
- public void addSysproperty(Environment.Variable sysp) {
- getJavaCommand().addSysproperty(sysp);
- }
-
- /**
- * Adds an environment variable; used when forking.
- *
- * @param var The variable
- */
- public void addEnv(Environment.Variable var) {
- m_environment.addVariable(var);
- }
-
- /**
- * Adds path to classpath used for tests.
- *
- * @return reference to the classpath in the embedded java command line
- */
- public Path createClasspath() {
- return getJavaCommand().createClasspath(getProject()).createPath();
- }
-
- /**
- * Adds a path to the bootclasspath.
- *
- * @return reference to the bootclasspath in the embedded java command line
- */
- public Path createBootclasspath() {
- return getJavaCommand().createBootclasspath(getProject()).createPath();
- }
-
- /**
- * Set the classpath to be used when running the Java class
- *
- * @param s an Ant Path object containing the classpath.
- */
- public void setClasspath(Path s) {
- createClasspath().append(s);
- }
-
- /**
- * Classpath to use, by reference.
- *
- * @param r a reference to an existing classpath
- */
- public void setClasspathRef(Reference r) {
- createClasspath().setRefid(r);
- }
-
- public void addXmlfileset(FileSet fs) {
- m_xmlFilesets.add(fs);
- }
-
- public void setXmlfilesetRef(Reference ref) {
- m_xmlFilesets.add(createResourceCollection(ref));
- }
-
- public void addClassfileset(FileSet fs) {
- m_classFilesets.add(appendClassSelector(fs));
- }
-
- public void setClassfilesetRef(Reference ref) {
- m_classFilesets.add(createResourceCollection(ref));
- }
-
- public void setTestNames(String testNames) {
- m_testNames = testNames;
- }
-
- public void setIgnoreMissedTestNames(boolean ignoreMissedTestNames) {
- m_ignoreMissedTestNames = ignoreMissedTestNames;
- }
-
- /**
- * Sets the suite runner class to invoke
- *
- * @param s the name of the suite runner class
- */
- public void setSuiteRunnerClass(String s) {
- m_mainClass = s;
- }
-
- /**
- * Sets the suite name
- *
- * @param s the name of the suite
- */
- public void setSuiteName(String s) {
- m_suiteName = s;
- }
-
- /**
- * Sets the test name
- *
- * @param s the name of the test
- */
- public void setTestName(String s) {
- m_testName = s;
- }
-
- // TestNG settings
- public void setJUnit(boolean value) {
- mode = value ? Mode.junit : Mode.testng;
- }
-
- // TestNG settings
- public void setMode(Mode mode) {
- this.mode = mode;
- }
-
- public void setForkJvm(boolean forkJvm) {
- this.forkJvm = forkJvm;
- }
-
- /**
- * Sets the test output directory
- *
- * @param dir the name of directory
- */
- public void setOutputDir(File dir) {
- m_outputDir = dir;
- }
-
- /**
- * Sets the test jar
- *
- * @param s the name of test jar
- */
- public void setTestJar(File s) {
- m_testjar = s;
- }
-
- public void setGroups(String groups) {
- m_includedGroups = groups;
- }
-
- public void setExcludedGroups(String groups) {
- m_excludedGroups = groups;
- }
-
- private Integer m_verbose = null;
-
- private Integer m_suiteThreadPoolSize;
-
- private String m_xmlPathInJar;
-
- public void setVerbose(Integer verbose) {
- m_verbose = verbose;
- }
-
- public void setReporter(String listener) {
- m_listeners.add(listener);
- }
-
- public void setObjectFactory(String className) {
- m_objectFactory = className;
- }
-
- public void setTestRunnerFactory(String testRunnerFactory) {
- m_testRunnerFactory = testRunnerFactory;
- }
-
- public void setSuiteThreadPoolSize(Integer n) {
- m_suiteThreadPoolSize = n;
- }
-
- public void setListeners(String listeners) {
- StringTokenizer st = new StringTokenizer(listeners, " ,");
- while (st.hasMoreTokens()) {
- m_listeners.add(st.nextToken());
- }
- }
-
- public void setMethodSelectors(String methodSelectors) {
- StringTokenizer st = new StringTokenizer(methodSelectors, " ,");
- while (st.hasMoreTokens()) {
- m_methodselectors.add(st.nextToken());
- }
- }
-
- public void setConfigFailurePolicy(String failurePolicy) {
- m_configFailurePolicy = failurePolicy;
- }
-
- public void setRandomizeSuites(Boolean randomizeSuites) {
- m_randomizeSuites = randomizeSuites;
- }
-
- public void setMethods(String methods) {
- m_methods = methods;
- }
-
- /**
- * Launches TestNG in a new JVM.
- *
- *
{@inheritDoc}
- */
- @Override
- public void execute() throws BuildException {
- validateOptions();
-
- CommandlineJava cmd = getJavaCommand();
- cmd.setClassname(m_mainClass);
- if (m_assertEnabled) {
- cmd.createVmArgument().setValue("-ea");
- }
- if (m_delegateCommandSystemProperties) {
- delegateCommandSystemProperties();
- }
- List argv = createArguments();
-
- if (!forkJvm) {
- TestNG tng = TestNG.privateMain(argv.toArray(new String[0]), null);
- actOnResult(tng.getStatus(), false);
- return;
- }
-
- String fileName = "";
- FileWriter fw = null;
- BufferedWriter bw = null;
- try {
- File f = File.createTempFile("testng", "");
- fileName = f.getAbsolutePath();
-
- // If the user asked to see the command, preserve the file
- if (!m_dump) {
- f.deleteOnExit();
- }
- fw = new FileWriter(f);
- bw = new BufferedWriter(fw);
- for (String arg : argv) {
- bw.write(arg);
- bw.newLine();
- }
- bw.flush();
- } catch (IOException e) {
- LOGGER.error(e.getMessage(), e);
- } finally {
- try {
- if (bw != null) {
- bw.close();
- }
- if (fw != null) {
- fw.close();
- }
- } catch (IOException e) {
- LOGGER.error(e.getMessage(), e);
- }
- }
-
- printDebugInfo(fileName);
-
- createClasspath().setLocation(findJar());
-
- cmd.createArgument().setValue("@" + fileName);
-
- ExecuteWatchdog watchdog = createWatchdog();
- boolean wasKilled = false;
- int exitValue = executeAsForked(cmd, watchdog);
- if (null != watchdog) {
- wasKilled = watchdog.killedProcess();
- }
-
- actOnResult(exitValue, wasKilled);
- }
-
- protected List createArguments() {
- List argv = Lists.newArrayList();
- addBooleanIfTrue(
- argv, CommandLineArgs.SKIP_FAILED_INVOCATION_COUNTS, m_skipFailedInvocationCounts);
- addIntegerIfNotNull(argv, CommandLineArgs.LOG, m_verbose);
- addDefaultListeners(argv);
- addOutputDir(argv);
- addFileIfFile(argv, CommandLineArgs.TEST_JAR, m_testjar);
- addStringIfNotBlank(argv, CommandLineArgs.GROUPS, m_includedGroups);
- addStringIfNotBlank(argv, CommandLineArgs.EXCLUDED_GROUPS, m_excludedGroups);
- addFilesOfRCollection(argv, CommandLineArgs.TEST_CLASS, m_classFilesets);
- addListOfStringIfNotEmpty(argv, CommandLineArgs.LISTENER, m_listeners);
- addListOfStringIfNotEmpty(argv, CommandLineArgs.METHOD_SELECTORS, m_methodselectors);
- addStringIfNotNull(argv, CommandLineArgs.OBJECT_FACTORY, m_objectFactory);
- addStringIfNotNull(argv, CommandLineArgs.TEST_RUNNER_FACTORY, m_testRunnerFactory);
- addStringIfNotNull(argv, CommandLineArgs.PARALLEL, m_parallelMode);
- addStringIfNotNull(argv, CommandLineArgs.CONFIG_FAILURE_POLICY, m_configFailurePolicy);
- addBooleanIfTrue(argv, CommandLineArgs.RANDOMIZE_SUITES, m_randomizeSuites);
- addStringIfNotNull(argv, CommandLineArgs.THREAD_COUNT, m_threadCount);
- addStringIfNotNull(argv, CommandLineArgs.DATA_PROVIDER_THREAD_COUNT, m_dataproviderthreadCount);
- addStringIfNotBlank(argv, CommandLineArgs.SUITE_NAME, m_suiteName);
- addStringIfNotBlank(argv, CommandLineArgs.TEST_NAME, m_testName);
- addStringIfNotBlank(argv, CommandLineArgs.TEST_NAMES, m_testNames);
- addBooleanIfTrue(argv, CommandLineArgs.IGNORE_MISSED_TEST_NAMES, m_ignoreMissedTestNames);
- addStringIfNotBlank(argv, CommandLineArgs.METHODS, m_methods);
- addReporterConfigs(argv);
- addIntegerIfNotNull(argv, CommandLineArgs.SUITE_THREAD_POOL_SIZE, m_suiteThreadPoolSize);
- addStringIfNotNull(argv, CommandLineArgs.XML_PATH_IN_JAR, m_xmlPathInJar);
- addXmlFiles(argv);
- return argv;
- }
-
- private void addDefaultListeners(List argv) {
- if (m_useDefaultListeners != null) {
- String useDefaultListeners = "false";
- if ("yes".equalsIgnoreCase(m_useDefaultListeners)
- || "true".equalsIgnoreCase(m_useDefaultListeners)) {
- useDefaultListeners = "true";
- }
- argv.add(CommandLineArgs.USE_DEFAULT_LISTENERS);
- argv.add(useDefaultListeners);
- }
- }
-
- private void addOutputDir(List argv) {
- if (null != m_outputDir) {
- if (!m_outputDir.exists()) {
- m_outputDir.mkdirs();
- }
- if (m_outputDir.isDirectory()) {
- argv.add(CommandLineArgs.OUTPUT_DIRECTORY);
- argv.add(m_outputDir.getAbsolutePath());
- } else {
- throw new BuildException("Output directory is not a directory: " + m_outputDir);
- }
- }
- }
-
- private void addReporterConfigs(List argv) {
- for (AntReporterConfig reporterConfig : reporterConfigs) {
- argv.add(CommandLineArgs.REPORTER);
- argv.add(reporterConfig.serialize());
- }
- }
-
- private void addFilesOfRCollection(
- List argv, String name, List resources) {
- addArgumentsIfNotEmpty(argv, name, getFiles(resources), ",");
- }
-
- private void addListOfStringIfNotEmpty(List argv, String name, List arguments) {
- addArgumentsIfNotEmpty(argv, name, arguments, ";");
- }
-
- private void addArgumentsIfNotEmpty(
- List argv, String name, List arguments, String separator) {
- if (arguments != null && !arguments.isEmpty()) {
- argv.add(name);
- String value = Utils.join(arguments, separator);
- argv.add(value);
- }
- }
-
- private void addFileIfFile(List argv, String name, File file) {
- if ((null != file) && file.isFile()) {
- argv.add(name);
- argv.add(file.getAbsolutePath());
- }
- }
-
- private void addBooleanIfTrue(List argv, String name, Boolean value) {
- if (TRUE.equals(value)) {
- argv.add(name);
- }
- }
-
- private void addIntegerIfNotNull(List argv, String name, Integer value) {
- if (value != null) {
- argv.add(name);
- argv.add(value.toString());
- }
- }
-
- private void addStringIfNotNull(List argv, String name, String value) {
- if (value != null) {
- argv.add(name);
- argv.add(value);
- }
- }
-
- private void addStringIfNotBlank(List argv, String name, String value) {
- if (isStringNotBlank(value)) {
- argv.add(name);
- argv.add(value);
- }
- }
-
- private void addXmlFiles(List argv) {
- argv.addAll(getSuiteFileNames());
- }
-
- /** @return the list of the XML file names. This method can be overridden by subclasses. */
- protected List getSuiteFileNames() {
- return Lists.newArrayList(getFiles(m_xmlFilesets));
- }
-
- private void delegateCommandSystemProperties() {
- // Iterate over command-line args and pass them through as sysproperty
- // exclude any built-in properties that start with "ant."
- for (Object propKey : getProject().getUserProperties().keySet()) {
- String propName = (String) propKey;
- String propVal = getProject().getUserProperty(propName);
- if (propName.startsWith("ant.")) {
- log("Excluding ant property: " + propName + ": " + propVal, Project.MSG_DEBUG);
- } else {
- log("Including user property: " + propName + ": " + propVal, Project.MSG_DEBUG);
- Environment.Variable var = new Environment.Variable();
- var.setKey(propName);
- var.setValue(propVal);
- addSysproperty(var);
- }
- }
- }
-
- private void printDebugInfo(String fileName) {
- if (m_dumpSys) {
- debug("* SYSTEM PROPERTIES *");
- Properties props = System.getProperties();
- Enumeration en = props.propertyNames();
- while (en.hasMoreElements()) {
- String key = (String) en.nextElement();
- debug(key + ": " + props.getProperty(key));
- }
- debug("");
- }
- if (m_dumpEnv) {
- String[] vars = m_environment.getVariables();
- if (null != vars && vars.length > 0) {
- debug("* ENVIRONMENT *");
- for (String v : vars) {
- debug(v);
- }
- debug("");
- }
- }
- if (m_dump) {
- dumpCommand(fileName);
- }
- }
-
- private void debug(String message) {
- log("[TestNGAntTask] " + message, Project.MSG_DEBUG);
- }
-
- protected void actOnResult(int exitValue, boolean wasKilled) {
- if (exitValue == -1) {
- executeHaltTarget(exitValue);
- throw new BuildException("an error occurred when running TestNG tests");
- }
-
- if ((exitValue & ExitCode.HAS_NO_TEST) == ExitCode.HAS_NO_TEST) {
- if (m_haltOnFailure) {
- executeHaltTarget(exitValue);
- throw new BuildException("No tests were run");
- } else {
- if (null != m_failurePropertyName) {
- getProject().setNewProperty(m_failurePropertyName, "true");
- }
-
- log("TestNG haven't found any tests to be run", Project.MSG_DEBUG);
- }
- }
-
- boolean failed = (ExitCode.hasFailure(exitValue)) || wasKilled;
- if (failed) {
- final String msg = wasKilled ? "The tests timed out and were killed." : "The tests failed.";
- if (m_haltOnFailure) {
- executeHaltTarget(exitValue);
- throw new BuildException(msg);
- } else {
- if (null != m_failurePropertyName) {
- getProject().setNewProperty(m_failurePropertyName, "true");
- }
-
- log(msg, Project.MSG_INFO);
- }
- }
-
- if (ExitCode.hasSkipped(exitValue)) {
- if (m_haltOnSkipped) {
- executeHaltTarget(exitValue);
- throw new BuildException("There are TestNG SKIPPED tests");
- } else {
- if (null != m_skippedPropertyName) {
- getProject().setNewProperty(m_skippedPropertyName, "true");
- }
-
- log("There are TestNG SKIPPED tests", Project.MSG_DEBUG);
- }
- }
-
- if (ExitCode.hasFailureWithinSuccessPercentage(exitValue)) {
- if (m_haltOnFSP) {
- executeHaltTarget(exitValue);
- throw new BuildException("There are TestNG FAILED WITHIN SUCCESS PERCENTAGE tests");
- } else {
- if (null != m_fspPropertyName) {
- getProject().setNewProperty(m_fspPropertyName, "true");
- }
-
- log("There are TestNG FAILED WITHIN SUCCESS PERCENTAGE tests", Project.MSG_DEBUG);
- }
- }
- }
-
- /** Executes the target, if any, that user designates executing before failing the test */
- private void executeHaltTarget(int exitValue) {
- if (m_onHaltTarget != null) {
- if (m_outputDir != null) {
- getProject().setProperty("testng.outputdir", m_outputDir.getAbsolutePath());
- }
- getProject().setProperty("testng.returncode", String.valueOf(exitValue));
- Target t = getProject().getTargets().get(m_onHaltTarget);
- if (t != null) {
- t.execute();
- }
- }
- }
-
- /**
- * Executes the command line as a new process.
- *
- * @param cmd the command to execute
- * @param watchdog - A {@link ExecuteWatchdog} object.
- * @return the exit status of the subprocess or INVALID.
- */
- protected int executeAsForked(CommandlineJava cmd, ExecuteWatchdog watchdog) {
- Execute execute =
- new Execute(
- new TestNGLogSH(
- this, Project.MSG_INFO, Project.MSG_WARN, (m_verbose == null || m_verbose < 5)),
- watchdog);
- execute.setCommandline(cmd.getCommandline());
- execute.setAntRun(getProject());
- if (m_workingDir != null) {
- if (m_workingDir.exists() && m_workingDir.isDirectory()) {
- execute.setWorkingDirectory(m_workingDir);
- } else {
- log("Ignoring invalid working directory : " + m_workingDir, Project.MSG_WARN);
- }
- }
-
- String[] environment = m_environment.getVariables();
- if (null != environment) {
- for (String envEntry : environment) {
- log("Setting environment variable: " + envEntry, Project.MSG_VERBOSE);
- }
- }
-
- execute.setEnvironment(environment);
-
- log(cmd.describeCommand(), Project.MSG_VERBOSE);
- int retVal;
- try {
- retVal = execute.execute();
- } catch (IOException e) {
- throw new BuildException("Process fork failed.", e, getLocation());
- }
-
- return retVal;
- }
-
- /** @return the created (or create) the CommandlineJava
. */
- protected CommandlineJava getJavaCommand() {
- if (null == m_javaCommand) {
- m_javaCommand = new CommandlineJava();
- }
-
- return m_javaCommand;
- }
-
- /**
- * @return null
if there is no timeout value, otherwise the watchdog instance.
- * @throws BuildException under unspecified circumstances
- * @since Ant 1.2
- */
- protected ExecuteWatchdog createWatchdog() /*throws BuildException*/ {
- if (m_timeout == null) {
- return null;
- }
-
- return new ExecuteWatchdog(m_timeout.longValue());
- }
-
- protected void validateOptions() throws BuildException {
- int suiteCount = getSuiteFileNames().size();
- if (suiteCount == 0
- && m_classFilesets.size() == 0
- && Utils.isStringEmpty(m_methods)
- && ((null == m_testjar) || !m_testjar.isFile())) {
- throw new BuildException("No suites, classes, methods or jar file was specified.");
- }
-
- if ((null != m_includedGroups) && (m_classFilesets.size() == 0 && suiteCount == 0)) {
- throw new BuildException("No class filesets or xml file sets specified while using groups");
- }
-
- if (m_onHaltTarget != null) {
- if (!getProject().getTargets().containsKey(m_onHaltTarget)) {
- throw new BuildException("Target " + m_onHaltTarget + " not found in this project");
- }
- }
- }
-
- private ResourceCollection createResourceCollection(Reference ref) {
- Object o = ref.getReferencedObject();
- if (!(o instanceof ResourceCollection)) {
- throw new BuildException("Only File based ResourceCollections are supported.");
- }
- ResourceCollection rc = (ResourceCollection) o;
- if (!rc.isFilesystemOnly()) {
- throw new BuildException("Only ResourceCollections from local file system are supported.");
- }
- return rc;
- }
-
- private FileSet appendClassSelector(FileSet fs) {
- FilenameSelector selector = new FilenameSelector();
- selector.setName("**/*.class");
- selector.setProject(getProject());
- fs.appendSelector(selector);
-
- return fs;
- }
-
- private File findJar() {
- Class thisClass = getClass();
- String resource = thisClass.getName().replace('.', '/') + ".class";
- URL url = thisClass.getClassLoader().getResource(resource);
-
- if (null != url) {
- String u = url.toString();
- if (u.startsWith("jar:file:")) {
- int pling = u.indexOf("!");
- String jarName = u.substring(4, pling);
-
- return new File(fromURI(jarName));
- } else if (u.startsWith("file:")) {
- int tail = u.indexOf(resource);
- String dirName = u.substring(0, tail);
-
- return new File(fromURI(dirName));
- }
- }
-
- return null;
- }
-
- private String fromURI(String uri) {
- URL url = null;
- try {
- url = new URL(uri);
- } catch (MalformedURLException murle) {
- // Gobble exceptions and do nothing.
- }
- if ((null == url) || !("file".equals(url.getProtocol()))) {
- throw new IllegalArgumentException("Can only handle valid file: URIs");
- }
-
- StringBuilder buf = new StringBuilder(url.getHost());
- if (buf.length() > 0) {
- buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
- }
-
- String file = url.getFile();
- int queryPos = file.indexOf('?');
- buf.append((queryPos < 0) ? file : file.substring(0, queryPos));
-
- uri = buf.toString().replace('/', File.separatorChar);
-
- if ((File.pathSeparatorChar == ';')
- && uri.startsWith("\\")
- && (uri.length() > 2)
- && Character.isLetter(uri.charAt(1))
- && (uri.lastIndexOf(':') > -1)) {
- uri = uri.substring(1);
- }
-
- StringBuilder sb = new StringBuilder();
- CharacterIterator iter = new StringCharacterIterator(uri);
- for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
- if (c == '%') {
- char c1 = iter.next();
- if (c1 != CharacterIterator.DONE) {
- int i1 = Character.digit(c1, 16);
- char c2 = iter.next();
- if (c2 != CharacterIterator.DONE) {
- int i2 = Character.digit(c2, 16);
- sb.append((char) ((i1 << 4) + i2));
- }
- }
- } else {
- sb.append(c);
- }
- }
-
- return sb.toString();
- }
-
- /**
- * Returns the list of files corresponding to the resource collection
- *
- * @param resources - A list of {@link ResourceCollection}
- * @return the list of files corresponding to the resource collection
- * @throws BuildException
- */
- private List getFiles(List resources) throws BuildException {
- List files = Lists.newArrayList();
- for (ResourceCollection rc : resources) {
- for (Resource o : rc) {
- if (o instanceof FileResource) {
- FileResource fr = ((FileResource) o);
- if (fr.isDirectory()) {
- throw new BuildException("Directory based FileResources are not supported.");
- }
- if (!fr.isExists()) {
- log("'" + fr.toLongString() + "' does not exist", Project.MSG_VERBOSE);
- }
- files.add(fr.getFile().getAbsolutePath());
- } else {
- log("Unsupported Resource type: " + o.toString(), Project.MSG_VERBOSE);
- }
- }
- }
- return files;
- }
-
- private void dumpCommand(String fileName) {
- log("TESTNG PASSED @" + fileName + " WHICH CONTAINS:", Project.MSG_INFO);
- readAndPrintFile(fileName);
- }
-
- private void readAndPrintFile(String fileName) {
- try {
- Files.readAllLines(Paths.get(fileName)).forEach(line -> log(" " + line, Project.MSG_INFO));
- } catch (IOException ex) {
- LOGGER.error(ex.getMessage(), ex);
- }
- }
-
- public void addConfiguredReporter(AntReporterConfig reporterConfig) {
- reporterConfigs.add(reporterConfig);
- }
-
- public void setSkipFailedInvocationCounts(boolean skip) {
- m_skipFailedInvocationCounts = skip;
- }
-
- public void setXmlPathInJar(String path) {
- m_xmlPathInJar = path;
- }
- /**
- * Add the referenced property set as system properties for the TestNG JVM.
- *
- * @param sysPropertySet A PropertySet of system properties.
- */
- public void addConfiguredPropertySet(PropertySet sysPropertySet) {
- Properties properties = sysPropertySet.getProperties();
- log(
- properties.keySet().size() + " properties found in nested propertyset",
- Project.MSG_VERBOSE);
- for (Object propKeyObj : properties.keySet()) {
- String propKey = (String) propKeyObj;
- Environment.Variable sysProp = new Environment.Variable();
- sysProp.setKey(propKey);
- if (properties.get(propKey) instanceof String) {
- String propVal = (String) properties.get(propKey);
- sysProp.setValue(propVal);
- getJavaCommand().addSysproperty(sysProp);
- log("Added system property " + propKey + " with value " + propVal, Project.MSG_VERBOSE);
- } else {
- log("Ignoring non-String property " + propKey, Project.MSG_WARN);
- }
- }
- }
-
- @Override
- protected void handleOutput(String output) {
- if (output.startsWith(VerboseReporter.LISTENER_PREFIX)) {
- // send everything from VerboseReporter to verbose level unless log level is > 4
- log(output, m_verbose < 5 ? Project.MSG_VERBOSE : Project.MSG_INFO);
- } else {
- super.handleOutput(output);
- }
- }
-
- private static class TestNGLogOS extends LogOutputStream {
-
- private Task task;
- private boolean verbose;
-
- public TestNGLogOS(Task task, int level, boolean verbose) {
- super(task, level);
- this.task = task;
- this.verbose = verbose;
- }
-
- @Override
- protected void processLine(String line, int level) {
- if (line.startsWith(VerboseReporter.LISTENER_PREFIX)) {
- task.log(line, verbose ? Project.MSG_VERBOSE : Project.MSG_INFO);
- } else {
- super.processLine(line, level);
- }
- }
- }
-
- protected static class TestNGLogSH extends PumpStreamHandler {
-
- public TestNGLogSH(Task task, int outlevel, int errlevel, boolean verbose) {
- super(new TestNGLogOS(task, outlevel, verbose), new LogOutputStream(task, errlevel));
- }
- }
-}
diff --git a/testng-ant/src/test/java/test/ant/AntTest.java b/testng-ant/src/test/java/test/ant/AntTest.java
deleted file mode 100644
index d096be9956..0000000000
--- a/testng-ant/src/test/java/test/ant/AntTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package test.ant;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.regex.Pattern;
-import org.apache.tools.ant.BuildFileRule;
-import org.testng.annotations.Test;
-
-public class AntTest {
-
- private final BuildFileRule rule = new BuildFileRule();
-
- @Test
- public void testSimple() {
- rule.configureProject("src/test/resources/ant/build-simple.xml");
- rule.executeTarget("testng");
- String expectedText = "Total tests run: 1, Passes: 1, Failures: 0, Skips: 0";
- assertThat(rule.getLog()).containsPattern(Pattern.compile(expectedText));
- }
-
- @Test
- public void testReporter() {
- MyReporter.expectedFilter = "*insert*";
- MyReporter.expectedFiltering = true;
-
- rule.configureProject("src/test/resources/ant/build-reporter-config.xml");
- rule.executeTarget("testng");
- }
-}
diff --git a/testng-ant/src/test/java/test/ant/MyReporter.java b/testng-ant/src/test/java/test/ant/MyReporter.java
deleted file mode 100644
index 5d858a1477..0000000000
--- a/testng-ant/src/test/java/test/ant/MyReporter.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package test.ant;
-
-import org.testng.IReporter;
-
-public class MyReporter implements IReporter {
-
- public static String expectedFilter;
- public static boolean expectedFiltering;
-
- public void setMethodFilter(String filter) {
- if (!filter.equals(expectedFilter)) {
- throw new IllegalArgumentException("Expect filter: " + expectedFilter);
- }
- }
-
- public void setEnableFiltering(boolean enableFiltering) {
- if (enableFiltering != expectedFiltering) {
- throw new IllegalArgumentException("Expect filtering: " + expectedFiltering);
- }
- }
-}
diff --git a/testng-ant/src/test/java/test/ant/SimpleSample.java b/testng-ant/src/test/java/test/ant/SimpleSample.java
deleted file mode 100644
index 0802c59e42..0000000000
--- a/testng-ant/src/test/java/test/ant/SimpleSample.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package test.ant;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class SimpleSample {
-
- @Test
- public void test() {
- Assert.assertTrue(true);
- }
-}
diff --git a/testng-ant/src/test/resources/ant/build-reporter-config.xml b/testng-ant/src/test/resources/ant/build-reporter-config.xml
deleted file mode 100644
index e69c9815a1..0000000000
--- a/testng-ant/src/test/resources/ant/build-reporter-config.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/testng-ant/src/test/resources/ant/build-simple.xml b/testng-ant/src/test/resources/ant/build-simple.xml
deleted file mode 100644
index 83c9d08c49..0000000000
--- a/testng-ant/src/test/resources/ant/build-simple.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/testng-ant/testng-ant-build.gradle.kts b/testng-ant/testng-ant-build.gradle.kts
deleted file mode 100644
index 505d314233..0000000000
--- a/testng-ant/testng-ant-build.gradle.kts
+++ /dev/null
@@ -1,11 +0,0 @@
-plugins {
- id("testng.java-library")
-}
-
-dependencies {
- api("org.apache.ant:ant:1.10.12")
-
- implementation(projects.testngCore)
- testImplementation(projects.testngAsserts)
- testImplementation("org.apache.ant:ant-testutil:1.10.12")
-}
diff --git a/testng-bom/testng-bom-build.gradle.kts b/testng-bom/testng-bom-build.gradle.kts
index 14309a85cc..208269cdea 100644
--- a/testng-bom/testng-bom-build.gradle.kts
+++ b/testng-bom/testng-bom-build.gradle.kts
@@ -6,7 +6,6 @@ plugins {
// Add a convenience pom.xml that sets all the versions
dependencies {
constraints {
- api(projects.testngAnt)
api(projects.testngApi)
api(projects.testngAsserts)
api(projects.testngCollections)
diff --git a/testng-core/src/main/java/org/testng/internal/ant/AntReporterConfig.java b/testng-core/src/main/java/org/testng/internal/ant/AntReporterConfig.java
deleted file mode 100644
index 1a6e79e319..0000000000
--- a/testng-core/src/main/java/org/testng/internal/ant/AntReporterConfig.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.testng.internal.ant;
-
-import java.util.List;
-import java.util.stream.Collectors;
-import org.testng.collections.Lists;
-
-/**
- * Used with the <reporter> sub-element of the Ant task
- *
- * NOTE: this class needs to be public. It's used by TestNG Ant task
- */
-public class AntReporterConfig {
-
- /** The class name of the reporter listener */
- protected String className;
-
- /** The properties of the reporter listener */
- private final List properties = Lists.newArrayList();
-
- public void addProperty(Property property) {
- properties.add(property);
- }
-
- public void setClassName(String className) {
- this.className = className;
- }
-
- public String serialize() {
- List properties =
- this.properties.stream()
- .map(
- property ->
- new org.testng.internal.ReporterConfig.Property(property.name, property.value))
- .collect(Collectors.toList());
- return (new org.testng.internal.ReporterConfig(className, properties)).serialize();
- }
-
- public static class Property {
- private String name;
- private String value;
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
- }
-}
diff --git a/testng-core/src/test/java/test/ant/AntSystemPropertySet.java b/testng-core/src/test/java/test/ant/AntSystemPropertySet.java
deleted file mode 100644
index b6e00629e0..0000000000
--- a/testng-core/src/test/java/test/ant/AntSystemPropertySet.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package test.ant;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-
-import org.testng.annotations.Test;
-
-/**
- * Test whether nested propertysets are passed passed from the ant task. Executed by the
- * "run:antprop" target in test/build.xml.
- *
- * @author Todd Wells
- */
-public class AntSystemPropertySet {
-
- @Test
- public void outputTestProperties() {
- assertNotNull(System.getProperty("syspropset1"), "syspropset1 not found");
- assertEquals(System.getProperty("syspropset1"), "value 1", "Wrong value for syspropset1");
-
- assertNotNull(System.getProperty("syspropset2"), "syspropset2 not found");
- assertEquals(System.getProperty("syspropset2"), "value 2", "Wrong value for syspropset2");
-
- assertNotNull(System.getProperty("sysprop1"), "sysprop1 not found");
- assertEquals(System.getProperty("sysprop1"), "value 3", "Wrong value for sysprop1");
- }
-}
diff --git a/testng-core/src/test/java/test/ant/DontOverrideSuiteNameTest.java b/testng-core/src/test/java/test/ant/DontOverrideSuiteNameTest.java
deleted file mode 100644
index 4420db8fd7..0000000000
--- a/testng-core/src/test/java/test/ant/DontOverrideSuiteNameTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package test.ant;
-
-import org.testng.annotations.Test;
-
-@Test
-public class DontOverrideSuiteNameTest {
- private boolean m_run = false;
-
- @Test(groups = {"nopackage"})
- public void test() {
- m_run = true;
- }
-}
diff --git a/testng-core/src/test/java/test/ant/MultipleThreadTest.java b/testng-core/src/test/java/test/ant/MultipleThreadTest.java
deleted file mode 100644
index 190d629153..0000000000
--- a/testng-core/src/test/java/test/ant/MultipleThreadTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package test.ant;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-/**
- * Tests that more than one thread is used for running tests
- *
- * @author micheb10 2 Oct 2006
- */
-public class MultipleThreadTest {
- public static Set _threads;
-
- @BeforeClass
- public void prepareHashSet() {
- _threads = Collections.synchronizedSet(new HashSet<>());
- }
-
- @Test
- public void recordThread00() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread01() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread02() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread03() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread04() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread05() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread06() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread07() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread08() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread09() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread10() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread11() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread12() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread13() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread14() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread15() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread16() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread17() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread18() {
- _threads.add(Thread.currentThread());
- }
-
- @Test
- public void recordThread19() {
- _threads.add(Thread.currentThread());
- }
-
- @AfterClass
- public void confirmMultipleThreads() {
- Assert.assertTrue(
- _threads.size() > 1,
- "More than one thread should have been used for running the tests - "
- + _threads.size()
- + " was used");
- }
-}
diff --git a/testng-core/src/test/java/test/ant/NoPackageTest.java b/testng-core/src/test/java/test/ant/NoPackageTest.java
deleted file mode 100644
index d6ecb45373..0000000000
--- a/testng-core/src/test/java/test/ant/NoPackageTest.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package test.ant;
-
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.Test;
-
-/** @author Filippo Diotalevi */
-public class NoPackageTest {
- private boolean m_run = false;
-
- @Test(groups = {"nopackage"})
- public void test() {
- m_run = true;
- }
-
- @AfterMethod(groups = {"nopackage"})
- public void after() {
- assert m_run : "test method was not run";
- }
-}
diff --git a/testng-core/src/test/java/test/ant/TestCommandLineArgs.java b/testng-core/src/test/java/test/ant/TestCommandLineArgs.java
deleted file mode 100644
index 4b4c28fc9c..0000000000
--- a/testng-core/src/test/java/test/ant/TestCommandLineArgs.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package test.ant;
-
-import static org.testng.AssertJUnit.assertEquals;
-
-import java.io.File;
-import org.testng.annotations.Test;
-
-public class TestCommandLineArgs {
-
- @Test
- public void testUnixPathResolution() {
- String path = "/wee/wom/flibble.txt";
-
- String[] segments = path.split("[/\\\\]", -1);
-
- assertEquals(4, segments.length);
- assertEquals("wee", segments[1]);
- }
-
- @Test
- public void testDOSPathResolution() {
- String path = "c:\\\\com\\pants\\wibble.txt";
-
- String[] segments = path.split("[/\\\\]", -1);
-
- assertEquals(5, segments.length);
- assertEquals("com", segments[2]); // because c: is actually \\ which will be split twice
- }
-
- @Test
- public void testPathResolution() {
- File file = new File("../CHANGES.txt");
-
- assert file.exists();
-
- String path = file.getAbsolutePath();
-
- assert path.split("[/\\\\]", -1).length > 1;
- }
-}
diff --git a/testng-core/src/test/resources/testng.xml b/testng-core/src/test/resources/testng.xml
index 8b27e69553..57ad2c64ac 100644
--- a/testng-core/src/test/resources/testng.xml
+++ b/testng-core/src/test/resources/testng.xml
@@ -678,13 +678,6 @@
-
-
-
-
-
-
-
diff --git a/testng-core/src/test/resources/testng.yaml b/testng-core/src/test/resources/testng.yaml
index cbf371e098..60f9fedc2a 100644
--- a/testng-core/src/test/resources/testng.yaml
+++ b/testng-core/src/test/resources/testng.yaml
@@ -312,10 +312,6 @@ tests:
- test.JUnitTest1
- test.CommandLineTest
- - name: Ant-ClassFileResolution
- classes:
- - test.ant.TestCommandLineArgs
-
- name: Class Run
classes:
- test.regression.groupsordering.A
diff --git a/testng/testng-build.gradle.kts b/testng/testng-build.gradle.kts
index c9b00e5594..d796b34dc8 100644
--- a/testng/testng-build.gradle.kts
+++ b/testng/testng-build.gradle.kts
@@ -14,9 +14,6 @@ java {
it.owner.let { id -> id is ProjectComponentIdentifier && id.build.isCurrentBuild }
}
- create("ant") {
- api(projects.testngAnt)
- }
create("guice") {
api(platform("com.google.inject:guice-bom:5.1.0"))
api("com.google.inject:guice")
@@ -57,7 +54,6 @@ tasks.mergedJar {
bsh.*;version="[2.0.0,3.0.0)";resolution:=optional,
com.beust.jcommander.*;version="[1.7.0,3.0.0)";resolution:=optional,
com.google.inject.*;version="[1.2,1.3)";resolution:=optional,
- org.apache.tools.ant.*;version="[1.7.0, 2.0.0)";resolution:=optional,
org.yaml.*;version="[1.6,2.0)";resolution:=optional,
*;resolution:=optional
""".trimIndent().replace("\n", ""),
@@ -68,7 +64,6 @@ tasks.mergedJar {
org.testng.collections
org.testng.internal
org.testng.internal.annotations
- org.testng.internal.ant
org.testng.internal.collections
org.testng.internal.invokers
org.testng.internal.invokers.objects