本文整理汇总了Java中org.apache.tools.ant.UnknownElement类的典型用法代码示例。如果您正苦于以下问题:Java UnknownElement类的具体用法?Java UnknownElement怎么用?Java UnknownElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnknownElement类属于org.apache.tools.ant包,在下文中一共展示了UnknownElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* Process antlib.xml definitions.
* @param p a project to add definitions to
* @param antlib location of antlib.xml to load
* @param uri a URI to add definitions in, or null
* @param l a class loader to load defined classes from
*/
public static void process(Project p, URL antlib, String uri, ClassLoader l) throws IOException, BuildException {
ComponentHelper helper = ComponentHelper.getComponentHelper(p);
helper.enterAntLib(uri);
Antlib al;
try {
UnknownElement antlibElement = new ProjectHelper2().parseUnknownElement(p, antlib);
al = new NbAntlib(uri, l);
al.setProject(p);
al.setLocation(antlibElement.getLocation());
al.init();
antlibElement.configure(al);
} finally {
helper.exitAntLib();
}
al.execute();
}
示例2: addTaskToTarget
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
private void addTaskToTarget( Target target, Task task ) {
UnknownElement replacement = new UnknownElement( taskType ); // shouldn't do taskType, for Ant 1.6 and later there is a getTaskType method
replacement.setProject( getProject() );
invokeMethod( replacement, "setTaskType", taskType );
replacement.setTaskName( task.getTaskName() );
replacement.setLocation( task.getLocation() );
replacement.setOwningTarget( target );
replacement.setRuntimeConfigurableWrapper( task.getRuntimeConfigurableWrapper() );
invokeMethod( task.getRuntimeConfigurableWrapper(), "setProxy", replacement );
replacement.maybeConfigure();
log("replacement is a " + replacement.getTaskName() + ", " + replacement.getClass().getName());
if (replacement instanceof TaskContainer) {
log("replacement is a TaskContainer");
invokeMethod(replacement, "handleChildren", new Object[]{this, this.getRuntimeConfigurableWrapper()});
}
target.addTask(replacement);
}
示例3: AntBuilder
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
public AntBuilder(final Task parentTask) {
this(parentTask.getProject(), parentTask.getOwningTarget());
// define "owning" task as wrapper to avoid having tasks added to the target
// but it needs to be an UnknownElement and no access is available from
// task to its original UnknownElement
final UnknownElement ue = new UnknownElement(parentTask.getTaskName());
ue.setProject(parentTask.getProject());
ue.setTaskType(parentTask.getTaskType());
ue.setTaskName(parentTask.getTaskName());
ue.setLocation(parentTask.getLocation());
ue.setOwningTarget(parentTask.getOwningTarget());
ue.setRuntimeConfigurableWrapper(parentTask.getRuntimeConfigurableWrapper());
parentTask.getRuntimeConfigurableWrapper().setProxy(ue);
antXmlContext.pushWrapper(parentTask.getRuntimeConfigurableWrapper());
}
示例4: parseUnknownElement
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* Parse an unknown element from a url
*
* @param project the current project
* @param source the url containing the task
* @return a configured task
* @exception BuildException if an error occurs
*/
public UnknownElement parseUnknownElement(Project project, URL source)
throws BuildException {
Target dummyTarget = new Target();
dummyTarget.setProject(project);
AntXMLContext context = new AntXMLContext(project);
context.addTarget(dummyTarget);
context.setImplicitTarget(dummyTarget);
parse(context.getProject(), source, new RootHandler(context, elementHandler));
Task[] tasks = dummyTarget.getTasks();
if (tasks.length != 1) {
throw new BuildException("No tasks defined");
}
return (UnknownElement) tasks[0];
}
示例5: init
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* Initialisation routine called after handler creation
* with the element name and attributes. This configures
* the element with its attributes and sets it up with
* its parent container (if any). Nested elements are then
* added later as the parser encounters them.
*
* @param propType Name of the element which caused this handler
* to be created. Must not be <code>null</code>.
*
* @param attrs Attributes of the element which caused this
* handler to be created. Must not be <code>null</code>.
*
* @exception SAXParseException in case of error, such as a
* BuildException being thrown during configuration.
*/
public void init(String propType, AttributeList attrs) throws SAXParseException {
Class<?> parentClass = parent.getClass();
IntrospectionHelper ih = IntrospectionHelper.getHelper(helperImpl.project, parentClass);
try {
String elementName = propType.toLowerCase(Locale.ENGLISH);
if (parent instanceof UnknownElement) {
UnknownElement uc = new UnknownElement(elementName);
uc.setProject(helperImpl.project);
((UnknownElement) parent).addChild(uc);
child = uc;
} else {
child = ih.createElement(helperImpl.project, parent, elementName);
}
helperImpl.configureId(child, attrs);
childWrapper = new RuntimeConfigurable(child, propType);
childWrapper.setAttributes(attrs);
parentWrapper.addChild(childWrapper);
} catch (BuildException exc) {
throw new SAXParseException(exc.getMessage(), helperImpl.locator, exc);
}
}
示例6: getParams
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* Get all the attributes in the ant-attribute:param
* namespace and place them in a map.
* @param el the element this attribute is in.
* @return a map of attributes.
*/
protected Map<String, String> getParams(UnknownElement el) {
Map<String, String> ret = new HashMap<>();
RuntimeConfigurable rc = el.getWrapper();
Hashtable<String, Object> attributes = rc.getAttributeMap(); // This does a copy!
for (Iterator<Map.Entry<String, Object>> i =
attributes.entrySet().iterator(); i.hasNext();) {
Map.Entry<String, Object> entry = i.next();
String key = entry.getKey();
String value = (String) entry.getValue();
if (key.startsWith("ant-attribute:param")) {
int pos = key.lastIndexOf(':');
ret.put(key.substring(pos + 1),
el.getProject().replaceProperties(value));
}
}
return ret;
}
示例7: taskStarted
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* @see BuildListener#taskStarted
* {@inheritDoc}.
*/
@Override
public void taskStarted(final BuildEvent event) {
if (initialized) {
final Task task = event.getTask();
Object real = task;
if (task instanceof UnknownElement) {
final Object realObj = ((UnknownElement) task).getTask();
if (realObj != null) {
real = realObj;
}
}
final Log log = getLog(real.getClass().getName(), null);
if (log.isTraceEnabled()) {
realLog(log, "Task \"" + task.getTaskName() + "\" started ",
Project.MSG_VERBOSE, null);
}
}
}
示例8: taskFinished
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* @see BuildListener#taskFinished
* {@inheritDoc}.
*/
@Override
public void taskFinished(final BuildEvent event) {
if (initialized) {
final Task task = event.getTask();
Object real = task;
if (task instanceof UnknownElement) {
final Object realObj = ((UnknownElement) task).getTask();
if (realObj != null) {
real = realObj;
}
}
final Log log = getLog(real.getClass().getName(), null);
if (event.getException() == null) {
if (log.isTraceEnabled()) {
realLog(log, "Task \"" + task.getTaskName() + "\" finished.",
Project.MSG_VERBOSE, null);
}
} else {
realLog(log, "Task \"" + task.getTaskName()
+ "\" finished with error.", Project.MSG_ERR,
event.getException());
}
}
}
示例9: concatDescriptions
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
private static void concatDescriptions(Project project, Target t,
StringBuilder description) {
if (t == null) {
return;
}
for (Task task : findElementInTarget(t, "description")) {
if (!(task instanceof UnknownElement)) {
continue;
}
UnknownElement ue = ((UnknownElement) task);
String descComp = ue.getWrapper().getText().toString();
if (descComp != null) {
description.append(project.replaceProperties(descComp));
}
}
}
示例10: execute
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* Execute the nested tasks, setting the classloader for
* any tasks that derive from Definer.
*/
@Override
public void execute() {
//TODO handle tasks added via #addTask()
for (Task task : tasks) {
UnknownElement ue = (UnknownElement) task;
setLocation(ue.getLocation());
ue.maybeConfigure();
Object configuredObject = ue.getRealThing();
if (configuredObject == null) {
continue;
}
if (!(configuredObject instanceof AntlibDefinition)) {
throw new BuildException(
"Invalid task in antlib %s %s does not extend %s",
ue.getTag(), configuredObject.getClass(),
AntlibDefinition.class.getName());
}
AntlibDefinition def = (AntlibDefinition) configuredObject;
def.setURI(uri);
def.setAntlibClassLoader(getClassLoader());
def.init();
def.execute();
}
}
示例11: getNestedTask
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* Convert the nested sequential to an unknown element
* @return the nested sequential as an unknown element.
*/
public UnknownElement getNestedTask() {
UnknownElement ret = new UnknownElement("sequential");
ret.setTaskName("sequential");
ret.setNamespace("");
ret.setQName("sequential");
// stores RuntimeConfigurable as "RuntimeConfigurableWrapper"
// in ret as side effect
new RuntimeConfigurable(ret, "sequential"); //NOSONAR
final int size = nestedSequential.getNested().size();
for (int i = 0; i < size; ++i) {
UnknownElement e =
(UnknownElement) nestedSequential.getNested().get(i);
ret.addChild(e);
ret.getWrapper().addChild(e.getWrapper());
}
return ret;
}
示例12: processTasks
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
private void processTasks() {
if (implicitTag != null) {
return;
}
for (Task task : unknownElements) {
UnknownElement ue = (UnknownElement) task;
String name = ProjectHelper.extractNameFromComponentName(
ue.getTag()).toLowerCase(Locale.ENGLISH);
if (getNsElements().get(name) == null) {
throw new BuildException("unsupported element %s", name);
}
if (presentElements.get(name) != null) {
throw new BuildException("Element %s already present", name);
}
presentElements.put(name, ue);
}
}
示例13: deployApps
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* Deploys all apps in this deployment group, then waits for all the
* deployments in the group to succeed. Deployments in a group will run
* in parallel.
*/
public void deployApps() {
for (Task deployAppTask : deployAppTasks) {
// This is in case of a rare bug that occurs in some JVM implementations
if (deployAppTask instanceof UnknownElement) {
deployAppTask.maybeConfigure();
deployAppTask = ((UnknownElement) deployAppTask).getTask();
}
if (!deployAppTask.getTaskName().equals("deploy-opsworks-app")) {
throw new BuildException(
"Only <deploy-opsworks-app> elements are supported");
}
deployAppTask.execute();
deploymentIds.add(deployAppTask.getDescription());
}
try {
waitForDeploymentGroupToSucceed(deploymentIds, client);
} catch (InterruptedException e) {
throw new BuildException(e.getMessage(), e);
}
}
示例14: getTaskElement
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* Get the TimedElement associated with a task.
*
* Where the task is not found directly, search for unknown elements which
* may be hiding the real task
*/
private TimedElement getTaskElement(Task task) {
TimedElement element = (TimedElement) tasks.get(task);
if (element != null) {
return element;
}
for (Enumeration<Task> e = tasks.keys(); e.hasMoreElements();) {
Task key = (Task) e.nextElement();
if (key instanceof UnknownElement) {
if (((UnknownElement) key).getTask() == task) {
return (TimedElement) tasks.get(key);
}
}
}
return null;
}
示例15: findTask
import org.apache.tools.ant.UnknownElement; //导入依赖的package包/类
/**
* Searches the specified task (the first occurence) within the specified
* target.
*
* @param target
* the target to search for the task for
* @param clazz
* the type of the task to be returned (if several are found the
* first one is returned)
*
* @return the found task
*/
@SuppressWarnings("unchecked")
protected <T extends Task> T findTask(final Target target,
final Class<T> clazz) {
for (final Task task : target.getTasks()) {
if (UnknownElement.class.equals(task.getClass())) {
final UnknownElement unknownTask = (UnknownElement) task;
// make sure we have the real thing
unknownTask.maybeConfigure();
// check it
if (clazz.equals(unknownTask.getRealThing().getClass())) {
return (T) unknownTask.getRealThing();
}
} else if (clazz.equals(task.getClass())) {
return (T) task;
}
}
return null;
}