本文整理汇总了Java中org.apache.tools.ant.Target.setName方法的典型用法代码示例。如果您正苦于以下问题:Java Target.setName方法的具体用法?Java Target.setName怎么用?Java Target.setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.ant.Target
的用法示例。
在下文中一共展示了Target.setName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
/**
* Execute all tasks.
*
* @exception BuildException Description of Exception
*/
public void execute() throws BuildException {
for ( int i = initValue; i < maxValue; i += inc ) {
if ( initName != null ) {
getProject().setUserProperty( initName, String.valueOf( i ) );
}
Target target = new Target();
target.setName( "for.subtarget" );
getProject().addOrReplaceTarget( target );
for ( Enumeration e = tasks.elements(); e.hasMoreElements(); ) {
Task task = (Task)e.nextElement();
addTaskToTarget( target, task );
}
target.execute();
}
}
示例2: extracted
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
private Target extracted(Project p) {
Target target = new Target() {
// @Override
// public Project getProject() {
// return p;
// }
};
target.setProject(p);
target.setName("Hello build");
target.setDescription("Runtime Adding Target");
Echo echo = new Echo();
echo.setMessage("Hello ant build");
echo.setProject(p);
target.addTask(echo);
return target;
}
示例3: AntBuilder
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
public AntBuilder(final Project project, final Target owningTarget) {
this.project = project;
/*
* GROOVY-4524: The following is not needed anymore as an ant Project already by default has inputhandler
* set to DefaultInputHandler. And if it is again set here, it mistakenly overrides the custom input handler
* if set using -inputhandler switch.
*/
//this.project.setInputHandler(new DefaultInputHandler());
collectorTarget = owningTarget;
antXmlContext = new AntXMLContext(project);
collectorTarget.setProject(project);
antXmlContext.setCurrentTarget(collectorTarget);
antXmlContext.setLocator(new AntBuilderLocator());
antXmlContext.setCurrentTargets(new HashMap<String, Target>());
implicitTarget = new Target();
implicitTarget.setProject(project);
implicitTarget.setName("");
antXmlContext.setImplicitTarget(implicitTarget);
// FileScanner is a Groovy utility
project.addDataTypeDefinition("fileScanner", FileScanner.class);
}
示例4: getEchoTask
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
public Echo getEchoTask() {
Project project = new Project();
project.setName("testProject");
Target target = new Target();
target.setName("testTarget");
target.setProject(project);
Echo.EchoLevel level = new Echo.EchoLevel();
level.setValue("error");
Echo echoTask = new Echo();
echoTask.setOwningTarget(target);
echoTask.setLevel(level);
echoTask.setTaskName("echo");
echoTask.setTaskType("echo");
echoTask.setMessage("This is a sample message.");
return echoTask;
}
示例5: MockProject
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
public MockProject() {
task = new Task() {
public void execute() {
}
};
task.setTaskName("testTask");
target = new Target();
target.setName("testTarget");
target.setProject(this);
target.addTask(task);
task.setOwningTarget(target);
}
示例6: runClass
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
/**
* Runs the given class via Apache Ant in the same JVM instance.
*
* @param className
* class to be run
*/
private static void runClass(String className, String packageName, String outputDir) {
Project project = new Project();
project.setName("ClassRunner");
project.init();
Target target = new Target();
target.setName(TARGET_NAME);
Java task = new Java();
Path path = task.createClasspath();
path.createPathElement().setPath("./sootOutput/" + outputDir);
path.createPathElement().setPath("./bin");
// TODO: if we don't fork, why do I need to set the classpath?
for (URL url : ((URLClassLoader) ClassLoader.getSystemClassLoader())
.getURLs()) {
path.createPathElement().setPath(url.getPath());
}
task.setClasspath(path);
task.setClassname(packageName + "." + className);
task.setFork(false);
task.setFailonerror(true);
task.setProject(project);
target.addTask(task);
project.addTarget(target);
project.setDefault(TARGET_NAME);
// TODO: check if this is right and explain why (the double execute)
target.execute();
project.executeTarget(project.getDefaultTarget());
}
示例7: fixedModulesBuild
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
/** Execute targets which cannot fail and though throw BuildException */
private void fixedModulesBuild() throws BuildException {
// Somewhat convoluted code because Project.executeTargets does not
// eliminate duplicates when analyzing dependencies! Ecch.
// build fixed modules first
dummy = new Target ();
dummyName = "nbmerge-" + getOwningTarget().getName();
targets = getProject().getTargets();
while (targets.contains (dummyName))
dummyName += "-x";
dummy.setName (dummyName);
for (String fixedmodule : buildfixedmodules) {
dummy.addDependency (targetprefix + fixedmodule);
}
getProject().addTarget(dummy);
getProject().setProperty("fixedmodules-built", "1" );
@SuppressWarnings("unchecked")
Vector<Target> fullList = getProject().topoSort(dummyName, targets);
// Now remove earlier ones: already done.
Vector<Target> doneList = getProject().topoSort(getOwningTarget().getName(), targets);
List<Target> todo = new ArrayList<>(fullList.subList(0, fullList.indexOf(dummy)));
todo.removeAll(doneList.subList(0, doneList.indexOf(getOwningTarget())));
log("Going to execute targets " + todo);
for (Target nexttargit: todo) {
String targetname = nexttargit.getName();
if ( builttargets.indexOf(targetname) < 0 ) {
// XXX poor replacement for Project.fireTargetStarted etc.
System.out.println(""); System.out.println(targetname + ":");
try {
nexttargit.execute();
} catch (BuildException ex) {
log("Failed to build target: " + targetname, Project.MSG_ERR);
throw ex;
}
builttargets.addElement(targetname);
}
}
builtmodules.addAll(buildfixedmodules); // add already built fixed modules to the list
log("fixedmodules=" + buildfixedmodules, Project.MSG_DEBUG);
log("builtmodules=" + builtmodules, Project.MSG_VERBOSE);
}
示例8: modulesBuild
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
/** Execute targets which can fail _without_ throwing BuildException */
private void modulesBuild() throws BuildException {
if ( ! failonerror ) {
// build the rest of modules
for (String module : buildmodules) {
dummy = new Target ();
dummyName = "nbmerge-" + getOwningTarget().getName() + "-" + module;
while (targets.contains (dummyName))
dummyName += "-x";
dummy.setName (dummyName);
dummy.addDependency (targetprefix + module);
getProject().addTarget(dummy);
@SuppressWarnings("unchecked")
Vector<Target> fullList = getProject().topoSort(dummyName, targets);
// Now remove earlier ones: already done.
@SuppressWarnings("unchecked")
Vector<Target> doneList = getProject().topoSort(getOwningTarget().getName(), targets);
List<Target> todo = new ArrayList<>(fullList.subList(0, fullList.indexOf(dummy)));
todo.removeAll(doneList.subList(0, doneList.indexOf(getOwningTarget())));
Iterator<Target> targit = todo.iterator();
try {
while (targit.hasNext()) {
Target nexttargit = targit.next();
String targetname = nexttargit.getName();
if ( builttargets.indexOf(targetname) < 0 ) {
System.out.println(); System.out.println(targetname + ":");
nexttargit.execute();
builttargets.addElement(targetname);
}
}
builtmodules.addElement(module);
} catch (BuildException BE) {
log(BE.toString(), Project.MSG_WARN);
BE.printStackTrace();
failedmodules.addElement(module);
}
}
log("builtmodules=" + builtmodules, Project.MSG_VERBOSE);
log("failedmodules=" + failedmodules, Project.MSG_VERBOSE);
}
}
示例9: parse
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
/**
* Parse a source xml input.
*
* @param project the current project
* @param source the xml source
* @exception BuildException if an error occurs
*/
@Override
public void parse(Project project, Object source) throws BuildException {
getImportStack().addElement(source);
AntXMLContext context = null;
context = (AntXMLContext) project.getReference(REFID_CONTEXT);
if (context == null) {
context = new AntXMLContext(project);
project.addReference(REFID_CONTEXT, context);
project.addReference(REFID_TARGETS, context.getTargets());
}
if (getImportStack().size() > 1) {
// we are in an imported file.
context.setIgnoreProjectTag(true);
Target currentTarget = context.getCurrentTarget();
Target currentImplicit = context.getImplicitTarget();
Map<String, Target> currentTargets = context.getCurrentTargets();
try {
Target newCurrent = new Target();
newCurrent.setProject(project);
newCurrent.setName("");
context.setCurrentTarget(newCurrent);
context.setCurrentTargets(new HashMap<String, Target>());
context.setImplicitTarget(newCurrent);
parse(project, source, new RootHandler(context, mainHandler));
newCurrent.execute();
} finally {
context.setCurrentTarget(currentTarget);
context.setImplicitTarget(currentImplicit);
context.setCurrentTargets(currentTargets);
}
} else {
// top level file
context.setCurrentTargets(new HashMap<String, Target>());
parse(project, source, new RootHandler(context, mainHandler));
// Execute the top-level target
context.getImplicitTarget().execute();
// resolve extensionOf attributes
resolveExtensionOfAttributes(project);
}
}
示例10: init
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
/**
* Initialisation routine called after handler creation
* with the element name and attributes. The attributes which
* this handler can deal with are: <code>"name"</code>,
* <code>"depends"</code>, <code>"if"</code>,
* <code>"unless"</code>, <code>"id"</code> and
* <code>"description"</code>.
*
* @param tag Name of the element which caused this handler
* to be created. Should not be <code>null</code>.
* Ignored in this implementation.
* @param attrs Attributes of the element which caused this
* handler to be created. Must not be <code>null</code>.
*
* @exception SAXParseException if an unexpected attribute is encountered
* or if the <code>"name"</code> attribute is missing.
*/
public void init(String tag, AttributeList attrs) throws SAXParseException {
String name = null;
String depends = "";
String ifCond = null;
String unlessCond = null;
String id = null;
String description = null;
for (int i = 0; i < attrs.getLength(); i++) {
String key = attrs.getName(i);
String value = attrs.getValue(i);
if ("name".equals(key)) {
name = value;
if (name.isEmpty()) {
throw new BuildException("name attribute must not" + " be empty",
new Location(helperImpl.locator));
}
} else if ("depends".equals(key)) {
depends = value;
} else if ("if".equals(key)) {
ifCond = value;
} else if ("unless".equals(key)) {
unlessCond = value;
} else if ("id".equals(key)) {
id = value;
} else if ("description".equals(key)) {
description = value;
} else {
throw new SAXParseException("Unexpected attribute \"" + key + "\"",
helperImpl.locator);
}
}
if (name == null) {
throw new SAXParseException("target element appears without a name attribute",
helperImpl.locator);
}
target = new Target();
// implicit target must be first on dependency list
target.addDependency("");
target.setName(name);
target.setIf(ifCond);
target.setUnless(unlessCond);
target.setDescription(description);
helperImpl.project.addTarget(name, target);
if (id != null && !id.isEmpty()) {
helperImpl.project.addReference(id, target);
}
// take care of dependencies
if (depends.length() > 0) {
target.setDepends(depends);
}
}
示例11: compile
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
/**
* Compile generated code.
*
* @param outdir
*/
private void compile(String outdir) throws Exception {
String cp = null;
try {
BufferedReader br = new BufferedReader(
new FileReader(System.getProperty("basedir", ".") + "/target/cp.txt"));
cp = br.readLine();
} catch (Exception e) {
// Don't care
}
if (cp == null) {
cp = "";
}
//using the ant javac task for compilation
Javac javaCompiler = new Javac();
Project codeGenProject = new Project();
Target compileTarget = new Target();
compileTarget.setName(COMPILE_TARGET_NAME);
compileTarget.addTask(javaCompiler);
codeGenProject.addTarget(compileTarget);
codeGenProject.setSystemProperties();
javaCompiler.setProject(codeGenProject);
javaCompiler.setIncludejavaruntime(true);
javaCompiler.setIncludeantruntime(true);
/*
This harmless looking setFork is actually very important. unless the compiler is
forked it wont work!
*/
javaCompiler.setFork(true);
//Create classpath - The generated output directories also become part of the classpath
//reason for this is that some codegenerators(XMLBeans) produce compiled classes as part of
//generated artifacts
String classdir = outdir + "/classes";
File outputLocationFile = new File(classdir);
outputLocationFile.mkdir();
Path classPath = new Path(codeGenProject, classdir);
classPath.add(new Path(codeGenProject, TEST_CLASSES_DIR));
classPath.addExisting(classPath.concatSystemClasspath(), false);
for (int i = 0; i < moduleNames.length; i++) {
classPath.add(new Path(codeGenProject,
MODULE_PATH_PREFIX + moduleNames[i] + CLASSES_DIR));
}
classPath.add(new Path(codeGenProject, cp));
javaCompiler.setClasspath(classPath);
//set sourcePath - The generated output directories also become part of the sourcepath
Path sourcePath = new Path(codeGenProject, outdir);
sourcePath.setLocation(outputLocationFile);
javaCompiler.setSrcdir(sourcePath);
//output the classes into the output dir as well
javaCompiler.setDestdir(outputLocationFile);
javaCompiler.setDebug(true);
javaCompiler.setVerbose(true);
javaCompiler.execute();
// codeGenProject.executeTarget(COMPILE_TARGET_NAME);
}
示例12: compile
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
/** @param outputLocation */
private void compile(String outputLocation) {
String cp = null;
try {
BufferedReader br = new BufferedReader(
new FileReader(System.getProperty("basedir", ".") + "/target/cp.txt"));
cp = br.readLine();
} catch (Exception e) {
// Don't care
}
if (cp == null) {
cp = "";
}
//using the ant javac task for compilation
Javac javaCompiler = new Javac();
Project codeGenProject = new Project();
Target compileTarget = new Target();
compileTarget.setName(COMPILE_TARGET_NAME);
compileTarget.addTask(javaCompiler);
codeGenProject.addTarget(compileTarget);
codeGenProject.setSystemProperties();
javaCompiler.setProject(codeGenProject);
javaCompiler.setIncludejavaruntime(true);
javaCompiler.setIncludeantruntime(true);
/*
This harmless looking setFork is actually very important. unless the compiler is
forked it wont work!
*/
javaCompiler.setFork(true);
//Create classpath - The generated output directories also become part of the classpath
//reason for this is that some codegenerators(XMLBeans) produce compiled classes as part of
//generated artifacts
File outputLocationFile = new File(outputLocation);
Path classPath = new Path(codeGenProject, outputLocation);
classPath.addExisting(classPath.concatSystemClasspath(), false);
for (int i = 0; i < moduleNames.length; i++) {
classPath.add(new Path(codeGenProject,
MODULE_PATH_PREFIX + moduleNames[i] + CLASSES_DIR));
}
classPath.add(new Path(codeGenProject, cp));
javaCompiler.setClasspath(classPath);
//set sourcePath - The generated output directories also become part of the sourcepath
Path sourcePath = new Path(codeGenProject, outputLocation);
sourcePath.setLocation(outputLocationFile);
javaCompiler.setSrcdir(sourcePath);
//output the classes into the output dir as well
javaCompiler.setDestdir(outputLocationFile);
javaCompiler.setVerbose(true);
javaCompiler.execute();
}
示例13: parseLine
import org.apache.tools.ant.Target; //导入方法依赖的package包/类
/**
* Parse a line from a log file. If the line is invalid, a null will be
* returned.
*
* @param line Text to be parsed
* @param hasStack True if the line contains execution stack information
* @return Information about the log entry line
*/
public static LogEntry parseLine(String line, boolean hasStack) {
LogEntry entry = new LogEntry();
StringBuffer text = new StringBuffer(line);
try {
// Obtain the most recent date
String timestamp = text.substring(0, DATE_FORMAT.length() + 1);
SimpleDateFormat datefmt = new SimpleDateFormat(DATE_FORMAT);
entry.setDate(datefmt.parse(timestamp.trim()));
text = text.delete(0, DATE_FORMAT.length() + 1);
// Obtain the message priority
int spcIdx = text.toString().indexOf(" ");
String priority = text.substring(0, spcIdx).trim();
entry.setPriority(getPriorityAsInt(priority));
text = text.delete(0, spcIdx);
// Obtain the execution stack
if (hasStack) {
int stackBegin = text.toString().indexOf("[");
int stackEnd = text.toString().indexOf("]");
String stack = text.substring(stackBegin + 1, stackEnd).trim();
String stackEntry = null;
StringTokenizer stackTokenizer = new StringTokenizer(stack, STACK_DELIMITER);
while (stackTokenizer.hasMoreTokens()) {
stackEntry = stackTokenizer.nextToken();
int eqIdx = stackEntry.indexOf("=");
String name = stackEntry.substring(eqIdx + 1);
if (stackEntry.startsWith(PROJECT)) {
Project prj = new Project();
prj.setName(name);
entry.add(prj);
} else if (stackEntry.startsWith(TARGET)) {
Target tgt = new Target();
tgt.setName(name);
entry.add(tgt);
} else if (stackEntry.startsWith(TASK)) {
Task tsk = new DummyTask();
tsk.setTaskName(name);
entry.add(tsk);
}
}
text = text.delete(0, stackEnd + 1);
}
// Assume that the remaining text is the message
entry.setMessage(text.toString().trim());
} catch (Exception ex) {
//System.out.println("Error parsing line: " + ex);
entry = null;
}
return entry;
}