blob: 684638d2bb08ea6d5fb86b393fb5ad9d2b7f4461 [file] [log] [blame]
package org.eclipse.ant.tests.core.testplugin;
/**********************************************************************
Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
This file is made available under the terms of the Common Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/cpl-v10.html
**********************************************************************/
import org.eclipse.ant.core.AntRunner;
import org.eclipse.ant.tests.core.AbstractAntTest;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
/**
* Responsible for running test ant build files.
*/
public class AntFileRunner {
private static final String BASE_DIR_PREFIX = "-Dbasedir="; //$NON-NLS-1$
public void run(IFile buildFile, String[] targets, String[] args, String baseDir, boolean captureOutput) throws CoreException {
AntRunner runner = new AntRunner();
String[] runnerArgs = args;
if (baseDir.length() > 0) {
// Ant requires the working directory to be specified
// as one of the arguments, so it needs to be appended.
int length = 1;
if (args != null) {
length = args.length + 1;
}
runnerArgs = new String[length];
if (args != null) {
System.arraycopy(args, 0, runnerArgs, 0, args.length);
}
runnerArgs[length - 1] = BASE_DIR_PREFIX + baseDir;
}
runner.setArguments(runnerArgs);
if (buildFile != null) {
runner.setBuildFileLocation(buildFile.getLocation().toFile().toString());
}
if (targets != null && targets.length > 0) {
runner.setExecutionTargets(targets);
}
if (captureOutput) {
runner.addBuildLogger(AbstractAntTest.ANT_TEST_BUILD_LOGGER);
}
runner.run(null);
}
public void run(String[] args, String baseDir) throws Exception {
AntRunner runner = new AntRunner();
String[] runnerArgs = args;
if (baseDir.length() > 0) {
// Ant requires the working directory to be specified
// as one of the arguments, so it needs to be appended.
runnerArgs = new String[args.length + 1];
System.arraycopy(args, 0, runnerArgs, 0, args.length);
runnerArgs[args.length] = BASE_DIR_PREFIX + baseDir;
}
runner.setArguments(runnerArgs);
runner.run(args);
}
}