private void executeSingleScenario(final File scenarioFile, final Project p) { getLog() .info( "Executing scenario " + scenarioFile.getName() + " with sut " + p.getProperty("sutFile")); try { p.fireBuildStarted(); p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference("ant.projectHelper", helper); helper.parse(p, scenarioFile); p.executeTarget(p.getDefaultTarget()); } catch (Exception e) { getLog().error("Failed to execute scenario " + scenarioFile.getName()); getLog().error(e); } finally { p.fireBuildFinished(null); } getLog() .info( "Execution of scenario " + scenarioFile.getName() + " with sut " + p.getProperty("sutFile") + " has ended"); getLog().info("------------------------------------------------------------------------"); }
/** Prepare the callable ant environment for the test. */ private void init() { if (!isInited()) { err = System.err; out = System.out; in = System.in; /* *Use the build.xml in the current directory. */ buildFile = new File("build.xml"); /* *To call into ant, create a new Project and prepare it for use. */ project = new Project(); // msgOutputLevel = Project.MSG_VERBOSE; project.addBuildListener(createLogger()); project.setBasedir("."); project.init(); /* *Set up the project to use the build.xml in the current directory. */ ProjectHelper helper = ProjectHelper.getProjectHelper(); helper.parse(project, buildFile); isInited = true; } }
protected void setUp() throws Exception { project = new Project(); project.setCoreLoader(getClass().getClassLoader()); project.init(); File buildFile = new File("target/test-classes/testbuild.xml"); project.setBaseDir(buildFile.getParentFile()); final ProjectHelper helper = ProjectHelper.getProjectHelper(); helper.parse(project, buildFile); // remove the package previously build File deb = new File("target/test.deb"); if (deb.exists()) { assertTrue("Unable to remove the test archive", deb.delete()); } }
/** * Initializes a new Ant Project. * * @param _buildFile The build File to use. If none is provided, it will be \ defaulted to * "build.xml". * @param _baseDir The project's base directory. If none is provided, will be \ defaulted to "." * (the current directory). * @throws Exception Exceptions are self-explanatory (read their Message) */ public void init(String _buildFile, String _baseDir) throws Exception { // Create a new project, and perform some default initialization project = new Project(); try { project.init(); } catch (BuildException e) { throw new Exception("The default task list could not be loaded."); } // Set the base directory. If none is given, "." is used. if (_baseDir == null) _baseDir = new String("."); try { project.setBasedir(_baseDir); } catch (BuildException e) { throw new Exception("The given basedir doesn't exist, or isn't a directory."); } if (_buildFile == null) _buildFile = new String("build.xml"); try { ProjectHelper.getProjectHelper().parse(project, new File(_buildFile)); } catch (BuildException e) { throw new Exception("Configuration file " + _buildFile + " is invalid, or cannot be read."); } }