Search in sources :

Example 6 with UnknownElement

use of org.apache.tools.ant.UnknownElement in project ant by apache.

the class CommonsLoggingListener method taskStarted.

/**
 * @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);
        }
    }
}
Also used : Task(org.apache.tools.ant.Task) Log(org.apache.commons.logging.Log) UnknownElement(org.apache.tools.ant.UnknownElement)

Example 7 with UnknownElement

use of org.apache.tools.ant.UnknownElement in project groovy by apache.

the class AntBuilderLocator method performTask.

// Copied from org.apache.tools.ant.Task, since we need to get a real thing before it gets nulled in DispatchUtils.execute
private Object performTask(Task task) {
    Throwable reason = null;
    try {
        // Have to call fireTestStared/fireTestFinished via reflection as they unfortunately have protected access in Project
        final Method fireTaskStarted = Project.class.getDeclaredMethod("fireTaskStarted", Task.class);
        ReflectionUtils.trySetAccessible(fireTaskStarted);
        fireTaskStarted.invoke(project, task);
        Object realThing;
        realThing = task;
        task.maybeConfigure();
        if (task instanceof UnknownElement) {
            realThing = ((UnknownElement) task).getRealThing();
        }
        DispatchUtils.execute(task);
        return realThing != null ? realThing : task;
    } catch (BuildException ex) {
        if (ex.getLocation() == Location.UNKNOWN_LOCATION) {
            ex.setLocation(task.getLocation());
        }
        reason = ex;
        throw ex;
    } catch (Exception ex) {
        reason = ex;
        BuildException be = new BuildException(ex);
        be.setLocation(task.getLocation());
        throw be;
    } catch (Error ex) {
        reason = ex;
        throw ex;
    } finally {
        try {
            final Method fireTaskFinished = Project.class.getDeclaredMethod("fireTaskFinished", Task.class, Throwable.class);
            ReflectionUtils.trySetAccessible(fireTaskFinished);
            fireTaskFinished.invoke(project, task, reason);
        } catch (Exception e) {
            BuildException be = new BuildException(e);
            be.setLocation(task.getLocation());
            throw be;
        }
    }
}
Also used : UnknownElement(org.apache.tools.ant.UnknownElement) Method(java.lang.reflect.Method) BuildException(org.apache.tools.ant.BuildException) BuildException(org.apache.tools.ant.BuildException) SAXParseException(org.xml.sax.SAXParseException)

Example 8 with UnknownElement

use of org.apache.tools.ant.UnknownElement in project cayenne by apache.

the class DbImporterTaskTest method getCdbImport.

private DbImporterTask getCdbImport(String buildFile) {
    Project project = new Project();
    File map = distDir(buildFile);
    ResourceUtil.copyResourceToFile(getPackagePath() + "/" + buildFile, map);
    ProjectHelper.configureProject(project, map);
    UnknownElement task = (UnknownElement) project.getTargets().get("dist").getTasks()[0];
    task.maybeConfigure();
    return (DbImporterTask) task.getRealThing();
}
Also used : Project(org.apache.tools.ant.Project) UnknownElement(org.apache.tools.ant.UnknownElement) File(java.io.File)

Example 9 with UnknownElement

use of org.apache.tools.ant.UnknownElement in project ant by apache.

the class MacroDef method getNestedTask.

/**
 * 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
    // NOSONAR
    new RuntimeConfigurable(ret, "sequential");
    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;
}
Also used : RuntimeConfigurable(org.apache.tools.ant.RuntimeConfigurable) UnknownElement(org.apache.tools.ant.UnknownElement)

Example 10 with UnknownElement

use of org.apache.tools.ant.UnknownElement in project ant by apache.

the class MacroInstance method processTasks.

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);
    }
}
Also used : Task(org.apache.tools.ant.Task) UnknownElement(org.apache.tools.ant.UnknownElement) BuildException(org.apache.tools.ant.BuildException)

Aggregations

UnknownElement (org.apache.tools.ant.UnknownElement)13 BuildException (org.apache.tools.ant.BuildException)8 Task (org.apache.tools.ant.Task)8 Method (java.lang.reflect.Method)2 Log (org.apache.commons.logging.Log)2 RuntimeConfigurable (org.apache.tools.ant.RuntimeConfigurable)2 Target (org.apache.tools.ant.Target)2 File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URLConnection (java.net.URLConnection)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 ComponentHelper (org.apache.tools.ant.ComponentHelper)1 DynamicAttribute (org.apache.tools.ant.DynamicAttribute)1 Project (org.apache.tools.ant.Project)1 ProjectHelper (org.apache.tools.ant.ProjectHelper)1