/** {@inheritDoc}. */ public void executeTargets(Project project, String[] targetNames) throws BuildException { BuildException thrownException = null; for (String targetName : targetNames) { try { project.executeTarget(targetName); } catch (BuildException ex) { if (project.isKeepGoingMode()) { thrownException = ex; } else { throw ex; } } } if (thrownException != null) { throw thrownException; } }
public void testClasspath_missing() { try { project.executeTarget("groovyClasspath_missing"); fail(); } catch (final Exception e) { assertEquals(BuildException.class, e.getClass()); } }
private void ensureExecutes(String target) { ensureNotPresent("GroovycTest1"); project.executeTarget(target); ensureResultOK("GroovycTest1"); }
public void testGroovyCodeInExternalFileWithOtherClass() { assertNull(FLAG); project.executeTarget("groovyCodeInExternalFileWithOtherClass"); assertEquals("from GroovyTest2Class.doSomething()", FLAG); }
public void testClasspath_nestedclasspath() { assertNull(FLAG); project.executeTarget("groovyClasspath_nestedClasspath"); assertEquals("from groovytest3.GroovyTest3Class.doSomething()", FLAG); }
public void testGroovyCodeWithinTag() { assertNull(FLAG); project.executeTarget("groovyCodeWithinTask"); assertEquals("from groovy inlined in ant", FLAG); }
public void testClasspath_classpathAttribute() { assertNull(FLAG); project.executeTarget("groovyClasspath_classpathAttribute"); assertEquals("from groovytest3.GroovyTest3Class.doSomething()", FLAG); }
public void testGroovyArgUsage() { assertNull(FLAG); project.executeTarget("groovyArgUsage"); assertEquals("from groovytest3.GroovyTest3Class.doSomethingWithArgs() 1 2 3", FLAG); }
public void testGroovyCodeExternalFile() { assertNull(FLAG); project.executeTarget("groovyCodeInExternalFile"); assertEquals("from groovy file called from ant", FLAG); }
public void testClasspath_classpathrefAttribute() { assertNull(FLAG); project.executeTarget("groovyClasspath_classpathrefAttribute"); assertEquals("from groovytest3.GroovyTest3Class.doSomething()", FLAG); }
public void testGroovyc_Joint_NoFork_NestedCompilerArg_WithGroovyClasspath() { // capture ant's output so we can verify the effect of passing compilerarg to javac ByteArrayOutputStream allOutput = new ByteArrayOutputStream(); PrintStream out = new PrintStream(allOutput); PrintStream origOut = System.out; System.setOut(out); ensureNotPresent("IncorrectGenericsUsage"); project.executeTarget("Groovyc_Joint_NoFork_NestedCompilerArg_WithGroovyClasspath"); ensurePresent("IncorrectGenericsUsage"); String antOutput = allOutput.toString(); antOutput = adjustOutputToHandleOpenJDKJavacOutputDifference(antOutput); System.setOut(origOut); // verify if passing -Xlint in compilerarg had its effect Pattern p = Pattern.compile(".*?found[ ]*:[ ]*java.util.ArrayList.*", Pattern.DOTALL); assertTrue("Expected line 1 not found in ant output", p.matcher(antOutput).matches()); p = Pattern.compile(".*?required[ ]*:[ ]*java.util.ArrayList<java.lang.String>.*", Pattern.DOTALL); assertTrue("Expected line 2 not found in ant output", p.matcher(antOutput).matches()); }
private void ensureFails(String target) { File badGroovy = new File(antFile.getParentFile(), "GroovyTestBad1.groovy"); PrintStream ps = null; try { ps = new PrintStream(new FileOutputStream(badGroovy)); } catch (FileNotFoundException e) { fail("Could not create test file:" + badGroovy.getAbsolutePath()); } ps.println("class GroovyTest1Bad { Thi$ $hould Fail! (somehow) };:??''+_|\\|"); ps.close(); ensureNotPresent("GroovycTestBad1"); try { project.executeTarget(target); fail("Ant script should have failed with execution exception"); } catch (BuildException be) { be.printStackTrace(); ensureNotPresent("GroovycTestBad1"); } finally { badGroovy.delete(); } }
private void testFileNameInStackTrace(final String target, final String fileNamePattern) { try { project.executeTarget(target); fail(); } catch (final BuildException e) { assertEquals(BuildException.class, e.getClass()); final Throwable cause = e.getCause(); assertTrue(cause instanceof GroovyRuntimeException); final StringWriter sw = new StringWriter(); cause.printStackTrace(new PrintWriter(sw)); final String stackTrace = sw.toString(); final Pattern pattern = Pattern.compile(fileNamePattern); assertTrue("Does >" + stackTrace + "< contain >" + fileNamePattern + "<?", pattern.matcher(stackTrace).find()); } } }
protected void setUp() throws Exception { super.setUp(); // Potentially throws Exception. project = new Project(); project.init(); ProjectHelper.getProjectHelper().parse(project, antFile); project.executeTarget("clean"); String altJavaHome = System.getProperty("java.home"); if (altJavaHome.lastIndexOf("jre") >= 0) { altJavaHome = altJavaHome.substring(0, altJavaHome.lastIndexOf("jre")); } else { altJavaHome = altJavaHome + File.separator + "jre"; } try { File altFile = new File(altJavaHome); if (altFile.exists()) { project.setProperty("alt.java.home", altJavaHome); } } catch (Exception e) { // could be security, io, etc. Ignore it. // End result is as if .exists() returned null } }
File buildFile = new File("build.xml"); Project p = new Project(); p.setUserProperty("ant.file", buildFile.getAbsolutePath()); p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference("ant.projectHelper", helper); helper.parse(p, buildFile); p.executeTarget(p.getDefaultTarget());
File buildFile = new File("build.xml"); Project p = new Project(); p.setUserProperty("ant.file", buildFile.getAbsolutePath()); p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference("ant.projectHelper", helper); helper.parse(p, buildFile); p.executeTarget(p.getDefaultTarget());
/** * Run a target on the Ant Script. * @param target The target to run. * @return <code>this</code> class instance. */ public AntRunner run(String target) { if(target == null) { throw new IllegalArgumentException("null 'target' argument."); } project.executeTarget(target); return this; }
public boolean run() { try { log.debug(javaTask.getCommandLine().toString()); javaTask.getProject().executeTarget("run-workflow"); return true; } catch (Exception e) { log.error(e.getClass().getSimpleName()+" occurred while running workflow: "+e.getMessage()); log.debug(e); return false; } }
public void executeTarget(String targetName) { logBuffer = new StringBuffer(); addBuildListener(new BuildListener(this)); super.executeTarget(targetName); } }
File buildFile = new File("build.xml"); Project p = new Project(); p.setUserProperty("ant.file", buildFile.getAbsolutePath()); p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference("ant.projectHelper", helper); helper.parse(p, buildFile); p.executeTarget(p.getDefaultTarget());