org.apache.tools.ant.Project.executeTarget()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中org.apache.tools.ant.Project.executeTarget()方法的一些代码示例,展示了Project.executeTarget()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Project.executeTarget()方法的具体详情如下:
包路径:org.apache.tools.ant.Project
类名称:Project
方法名:executeTarget

Project.executeTarget介绍

[英]Execute the specified target and any targets it depends on.
[中]执行指定的目标及其所依赖的任何目标。

代码示例

代码示例来源:origin: org.apache.ant/ant

/** {@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;
  }
}

代码示例来源:origin: groovy/groovy-core

public void testClasspath_missing() {
  try {
    project.executeTarget("groovyClasspath_missing");
    fail();
  } catch (final Exception e) {
    assertEquals(BuildException.class, e.getClass());
  }
}

代码示例来源:origin: groovy/groovy-core

private void ensureExecutes(String target) {
  ensureNotPresent("GroovycTest1");
  project.executeTarget(target);
  ensureResultOK("GroovycTest1");
}

代码示例来源:origin: groovy/groovy-core

public void testGroovyCodeInExternalFileWithOtherClass() {
  assertNull(FLAG);
  project.executeTarget("groovyCodeInExternalFileWithOtherClass");
  assertEquals("from GroovyTest2Class.doSomething()", FLAG);
}

代码示例来源:origin: groovy/groovy-core

public void testClasspath_nestedclasspath() {
  assertNull(FLAG);
  project.executeTarget("groovyClasspath_nestedClasspath");
  assertEquals("from groovytest3.GroovyTest3Class.doSomething()", FLAG);
}

代码示例来源:origin: groovy/groovy-core

public void testGroovyCodeWithinTag() {
  assertNull(FLAG);
  project.executeTarget("groovyCodeWithinTask");
  assertEquals("from groovy inlined in ant", FLAG);
}

代码示例来源:origin: groovy/groovy-core

public void testClasspath_classpathAttribute() {
  assertNull(FLAG);
  project.executeTarget("groovyClasspath_classpathAttribute");
  assertEquals("from groovytest3.GroovyTest3Class.doSomething()", FLAG);
}

代码示例来源:origin: groovy/groovy-core

public void testGroovyArgUsage() {
  assertNull(FLAG);
  project.executeTarget("groovyArgUsage");
  assertEquals("from groovytest3.GroovyTest3Class.doSomethingWithArgs() 1 2 3", FLAG);
}

代码示例来源:origin: groovy/groovy-core

public void testGroovyCodeExternalFile() {
  assertNull(FLAG);
  project.executeTarget("groovyCodeInExternalFile");
  assertEquals("from groovy file called from ant", FLAG);
}

代码示例来源:origin: groovy/groovy-core

public void testClasspath_classpathrefAttribute() {
  assertNull(FLAG);
  project.executeTarget("groovyClasspath_classpathrefAttribute");
  assertEquals("from groovytest3.GroovyTest3Class.doSomething()", FLAG);
}

代码示例来源:origin: groovy/groovy-core

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());
}

代码示例来源:origin: groovy/groovy-core

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();
  }
}

代码示例来源:origin: groovy/groovy-core

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());
    }
  }
}

代码示例来源:origin: groovy/groovy-core

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
  }
}

代码示例来源:origin: stackoverflow.com

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());

代码示例来源:origin: stackoverflow.com

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());

代码示例来源:origin: smooks/smooks

/**
 * 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;
}

代码示例来源:origin: org.fornax.toolsupport/fornax-oaw-m2-plugin

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;
  }
}

代码示例来源:origin: hibernate/hibernate-tools

public void executeTarget(String targetName) {
      logBuffer = new StringBuffer();
      addBuildListener(new BuildListener(this));
      super.executeTarget(targetName);
  }    
}

代码示例来源:origin: stackoverflow.com

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());

相关文章