Java 类org.apache.tools.ant.Task 实例源码

项目:incubator-netbeans    文件:NbBuildLogger.java   
public @Override String getTaskName() {
    verifyRunning();
    if (e == null) {
        return null;
    }
    Task task = e.getTask();
    if (task != null) {
        return task.getRuntimeConfigurableWrapper().getElementTag();
    }
    // #49464: guess at task.
    Task lastTask = getLastTask();
    if (lastTask != null) {
        return lastTask.getRuntimeConfigurableWrapper().getElementTag();
    }
    return null;
}
项目:incubator-netbeans    文件:MakeOSGiTest.java   
public void testPrescan() throws Exception {
    File j = new File(getWorkDir(), "x.jar");
    try (OutputStream os = new FileOutputStream(j)) {
        JarOutputStream jos = new JarOutputStream(os, new Manifest(new ByteArrayInputStream("Manifest-Version: 1.0\nBundle-SymbolicName: org.eclipse.mylyn.bugzilla.core;singleton:=true\nExport-Package: org.eclipse.mylyn.internal.bugzilla.core;x-friends:=\"org.eclipse.mylyn.bugzilla.ide,org.eclipse.mylyn.bugzilla.ui\",org.eclipse.mylyn.internal.bugzilla.core.history;x-friends:=\"org.eclipse.mylyn.bugzilla.ide,org.eclipse.mylyn.bugzilla.ui\",org.eclipse.mylyn.internal.bugzilla.core.service;x-internal:=true\n".getBytes())));
        jos.flush();
        jos.close();
    }
    Info info = new MakeOSGi.Info();
    JarFile jf = new JarFile(j);
    try {
        assertEquals("org.eclipse.mylyn.bugzilla.core", MakeOSGi.prescan(jf, info, new Task() {}));
    } finally {
        jf.close();
    }
    assertEquals("[org.eclipse.mylyn.internal.bugzilla.core, org.eclipse.mylyn.internal.bugzilla.core.history, org.eclipse.mylyn.internal.bugzilla.core.service]", info.exportedPackages.toString());
}
项目:incubator-netbeans    文件:InsertModuleAllTargetsTest.java   
public void testInstallAllTargetWithClusters() {

    InsertModuleAllTargets insert = new InsertModuleAllTargets();
    insert.setProject(p);

    insert.execute();

    Object obj = p.getTargets().get("all-java.source.queries");
    assertNotNull("Target found", obj);
    Target t = (Target)obj;

    Set<String> s = depsToNames(t.getDependencies());
    assertEquals("One dep: " + s, 1, s.size());
    assertEquals("Just dep on init", "init", s.iterator().next());

    int callTargets = 0;
    for (Task task : t.getTasks()) {
        if (task instanceof CallTarget) {
            callTargets++;
        }
    }
    assertEquals("One call target to build super cluster", 1, callTargets);
}
项目:incubator-netbeans    文件:InsertModuleAllTargetsTest.java   
public void testInstallAllTargetWithoutClusters() {
    InsertModuleAllTargets insert = new InsertModuleAllTargets();
    insert.setProject(p);
    insert.setUseClusters(false);
    insert.execute();

    Object obj = p.getTargets().get("all-java.source.queries");
    assertNotNull("Target found", obj);
    Target t = (Target)obj;

    Set<String> s = depsToNames(t.getDependencies());
    assertEquals("Three dependencies: " + s, 5, s.size());
    assertTrue("on init", s.contains("init"));
    assertTrue("on all-openide.util", s.contains("all-openide.util"));
    assertTrue("on all-openide.util.lookup", s.contains("all-openide.util.lookup"));
    assertTrue("on all-api.annotations.common", s.contains("all-api.annotations.common"));
    assertTrue("on all-openide.dialogs", s.contains("all-openide.dialogs"));

    int callTargets = 0;
    for (Task task : t.getTasks()) {
        if (task instanceof CallTarget) {
            callTargets++;
        }
    }
    assertEquals("No call targes", 0, callTargets);
}
项目:incubator-netbeans    文件:MakeNBM.java   
static void validateAgainstAUDTDs(InputSource input, final Path updaterJar, final Task task) throws IOException, SAXException {
    XMLUtil.parse(input, true, false, XMLUtil.rethrowHandler(), new EntityResolver() {
        ClassLoader loader = new AntClassLoader(task.getProject(), updaterJar);
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            String remote = "http://www.netbeans.org/dtds/";
            if (systemId.startsWith(remote)) {
                String rsrc = "org/netbeans/updater/resources/" + systemId.substring(remote.length());
                URL u = loader.getResource(rsrc);
                if (u != null) {
                    return new InputSource(u.toString());
                } else {
                    task.log(rsrc + " not found in " + updaterJar, Project.MSG_WARN);
                }
            }
            return null;
        }
    });
}
项目:incubator-netbeans    文件:MakeOSGi.java   
private static void scanClasses(JarFile module, Set<String> importedPackages, Set<String> availablePackages, Task task) throws Exception {
    Map<String, byte[]> classfiles = new TreeMap<>();
    VerifyClassLinkage.read(module, classfiles, new HashSet<>(Collections.singleton(new File(module.getName()))), task, null);
    for (Map.Entry<String,byte[]> entry : classfiles.entrySet()) {
        String available = entry.getKey();
        int idx = available.lastIndexOf('.');
        if (idx != -1) {
            availablePackages.add(available.substring(0, idx));
        }
        for (String clazz : VerifyClassLinkage.dependencies(entry.getValue())) {
            if (classfiles.containsKey(clazz)) {
                // Part of the same module; probably not an external import.
                continue;
            }
            if (clazz.startsWith("java.")) {
                // No need to declare as an import.
                continue;
            }
            idx = clazz.lastIndexOf('.');
            if (idx != -1) {
                importedPackages.add(clazz.substring(0, idx));
            }
        }
    }
}
项目:parabuild-ci    文件:ElseTask.java   
public void execute() throws BuildException {
    // execute all nested tasks
    for ( Enumeration e = tasks.elements(); e.hasMoreElements(); ) {
        Task task = ( Task ) e.nextElement();
        if ( task instanceof Breakable ) {
            task.perform();
            if ( ( ( Breakable ) task ).doBreak() ) {
                setBreak( true );
                return ;
            }
        }
        else {
            task.perform();
        }
    }
}
项目:parabuild-ci    文件:IfTask.java   
/**
 * Add a nested task to execute. <p>
 *
 * @param task  Nested task to execute. <p>
 */
public void addTask( Task task ) {
   if ( task instanceof ElseTask ) {
      if ( else_task == null ) {
         else_task = task;
         return ;
      }
      else {
         throw new BuildException( "Only one <else> allowed per If." );
      }
   }
   else if ( task instanceof BooleanConditionTask ) {
      if ( condition_task == null ) {
         condition_task = task;
         return ;
      }
      else {
         throw new BuildException( "Only one <bool> allowed per If." );
      }
   }
   tasks.addElement( task );
}
项目:parabuild-ci    文件:IfTask.java   
/**
 * Do the 'if' part of the if/else.
 *
 * @exception BuildException  Description of the Exception
 */
private void doIf() throws BuildException {
   // execute all nested tasks
   for ( Enumeration e = tasks.elements(); e.hasMoreElements(); ) {
      Task task = ( Task ) e.nextElement();
      if ( task instanceof Breakable ) {
         task.perform();
         if ( ( ( Breakable ) task ).doBreak() ) {
            setBreak( true );
            return ;
         }
      }
      else {
         task.perform();
      }
   }
}
项目:parabuild-ci    文件:Foreach.java   
/**
 * Execute this task and all nested Tasks.
 *
 * @exception BuildException  Description of Exception
 */
public void execute() throws BuildException {
    Unset unset = new Unset();
    StringTokenizer st = new StringTokenizer(values, separator);
    while (st.hasMoreTokens()) {
        String value = st.nextToken();
        value = trim ? value.trim() : value;
        if (name != null) {
            unset.setName(name);
            unset.execute();
            getProject().setProperty(name, value);
        }
        for (Enumeration e = tasks.elements(); e.hasMoreElements(); ) {
            try {
                Task task = (Task) e.nextElement();
                task.perform();
            }
            catch (Exception ex) {
                if (failOnError)
                    throw new BuildException(ex.getMessage());
                else
                    log(ex.getMessage());
            }
        }
    }
}
项目:parabuild-ci    文件:TryTask.java   
/**
 * Add a nested task to Try.
 *
 * @param task  Nested task to try to execute
 */
public void addTask( Task task ) {
   if ( task instanceof CatchTask ) {
      if ( catchTask == null ) {
         catchTask = task;
         return ;
      } else {
         throw new BuildException( "Only one Catch allowed per Try." );
      }
   } else if ( task instanceof FinallyTask ) {
      if ( finallyTask == null ) {
         finallyTask = task;
         return ;
      } else {
         throw new BuildException( "Only one Finally allowed per Try." );
      }
   }
   tasks.addElement( task );
}
项目:parabuild-ci    文件:ForTask.java   
/**
 * 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();
   }
}
项目:parabuild-ci    文件:ForTask.java   
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);
}
项目:greenpepper    文件:SystemUnderDevelopmentElement.java   
/**
 * <p>toArgument.</p>
 *
 * @param task a {@link org.apache.tools.ant.Task} object.
 * @return a {@link java.lang.String} object.
 */
public String toArgument(Task task)
{
    task.log(String.format("System Under Development Class \"%s\"", className), Project.MSG_VERBOSE);

    StringBuilder argumentBuilder = new StringBuilder(className);

    for (TextData argument : arguments)
    {
        task.log(String.format("\tArgument \"%s\"", argument), Project.MSG_VERBOSE);

        argumentBuilder.append(";").append(escapeSemiColon(argument.getText()));
    }

    return argumentBuilder.toString();
}
项目:greenpepper    文件:SectionElement.java   
/**
 * <p>toArgument.</p>
 *
 * @param task a {@link org.apache.tools.ant.Task} object.
 * @return a {@link java.lang.String} object.
 */
public String toArgument(Task task)
{
    StringBuilder argumentBuilder = new StringBuilder();

    for(TextData include : includes) {

        if (argumentBuilder.length() > 0)
           {
            argumentBuilder.append(";");
        }

        argumentBuilder.append(include.getText());

        task.log(String.format("\tSection \"%s\"", include), Project.MSG_VERBOSE);
       }

    return argumentBuilder.toString();
}
项目:greenpepper    文件:RepositoryElement.java   
/**
 * <p>toArgument.</p>
 *
 * @param task a {@link org.apache.tools.ant.Task} object.
 * @return a {@link java.lang.String} object.
 */
public String toArgument(Task task)
{
    task.log(String.format("Repository Class \"%s\"", className), Project.MSG_VERBOSE);

    StringBuilder argumentBuilder = new StringBuilder(className);

    for (TextData argument : arguments)
    {
        task.log(String.format("\tArgument \"%s\"", argument), Project.MSG_VERBOSE);

        argumentBuilder.append(";").append(escapeSemiColon(argument.getText()));
    }

    return argumentBuilder.toString();
}
项目:groovy    文件:AntBuilder.java   
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());
}
项目:ant    文件:ProjectHelper2.java   
/**
 * 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];
}
项目:ant    文件:CommonsLoggingListener.java   
/**
 * @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);
        }
    }
}
项目:ant    文件:CommonsLoggingListener.java   
/**
 * @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());
        }
    }
}
项目:ant    文件:Description.java   
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));
        }
    }
}
项目:ant    文件:Execute.java   
/**
 * A utility method that runs an external command. Writes the output and
 * error streams of the command to the project log.
 *
 * @param task The task that the command is part of. Used for logging
 * @param cmdline The command to execute.
 * @throws BuildException if the command does not exit successfully.
 */
public static void runCommand(Task task, String... cmdline)
    throws BuildException {
    try {
        task.log(Commandline.describeCommand(cmdline),
                 Project.MSG_VERBOSE);
        Execute exe = new Execute(
            new LogStreamHandler(task, Project.MSG_INFO, Project.MSG_ERR));
        exe.setAntRun(task.getProject());
        exe.setCommandline(cmdline);
        int retval = exe.execute();
        if (isFailure(retval)) {
            throw new BuildException(cmdline[0]
                + " failed with return code " + retval, task.getLocation());
        }
    } catch (IOException exc) {
        throw new BuildException("Could not launch " + cmdline[0] + ": "
            + exc, task.getLocation());
    }
}
项目:ant    文件:Antlib.java   
/**
 * 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();
    }
}
项目:ant    文件:MacroInstance.java   
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);
    }
}
项目:ant-easyant-core    文件:TaskCollectorFromImplicitTargetListener.java   
public void taskStarted(BuildEvent buildEvent) {
    gatherRootModuleLocation(buildEvent.getProject(), buildEvent.getTask().getLocation());
    if (buildEvent.getTarget().getName().equals("")) {
        Task task = buildEvent.getTask();
        if (task.getTaskType() != null) {
            Class<?> taskClass = ComponentHelper.getComponentHelper(buildEvent.getProject()).getComponentClass(
                    task.getTaskType());
            if (taskClass != null) {
                for (Class<?> supportedClass : supportedClasses) {
                    if (supportedClass.isAssignableFrom(taskClass)) {
                        tasksCollected.add(task);
                    }
                }
            }
        }

    }
}
项目:ant-easyant-tasks    文件:DebugUtils.java   
public static List searchTask(Class expectedTaskClass, Project project) {
    List result = new ArrayList();
    for (Iterator iterator = project.getTargets().values().iterator(); iterator
            .hasNext();) {
        Target t = (Target) iterator.next();
        for (int i = 0; i < t.getTasks().length; i++) {
            Task task = t.getTasks()[i];
            Class taskClass = ComponentHelper.getComponentHelper(project)
                    .getComponentClass(task.getTaskType());
            // will need to see in what cases it could return a null type
            // perhaps failing when the task is using a custom antlib
            // defined task
            if (taskClass != null && taskClass.equals(expectedTaskClass)) {
                result.add(task);
            }
        }
    }
    return result;
}
项目:andes    文件:Foreach.java   
public void execute() {
    validate("property", property).required().nonempty();
    validate("list", property).required();

    if (list.length() == 0) {
        return;
    }

    String[] values = list.split(delim);
    for (int i = 0; i < values.length; i++) {
        String value = values[i];
        if (stop != null && stop.length() > 0 &&
            value.equals(stop)) {
            break;
        }
        getProject().setProperty(property, value);
        for (Task t : tasks) {
            t.perform();
        }
    }
}
项目:aws-ant-tasks    文件:IncrementalDeploymentTask.java   
/**
 * 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);
    }
}
项目:rectangular-antlib    文件:Once.java   
@Override
public void execute() throws BuildException
{
    if (property == null || property.length() == 0)
    {
        throw new BuildException("Property name must be specified.");
    }
    else
    {
        String propertyValue = getProject().getProperty(property);
        // If no value is specified, the tasks are performed if the property
        // is set to any value.  If a value is specified, the tasks are only
        // performed if the property matches that value.
        if (propertyValue == null)
        {
            for (Task task : tasks)
            {
                task.perform();
            }
            getProject().setProperty(property, "done");
        }
    }
}
项目:build-management    文件:Repeat.java   
/**
 * Iterate through the list of tasks to execute each task. 
 */
private void performTasks() throws BuildException {
    try {
        // executing nested tasks
        for (int i = 0; i < tasks.size(); i++) {
            Task currentTask = (Task) tasks.get(i);
            try {
                currentTask.perform();
            } catch (Exception ex) {
                if (failOnError) {
                    throw ex;
                }
            }
        }
    } catch (Exception e) {
        if (failOnError) {
            throw new BuildException(e.getMessage());
        } else {
            log(e.getMessage());
        }
    }
}
项目:build-management    文件:TimeoutTask.java   
/**
    * Attempt to interrupt the specified threads.
    *
    * @param   threads     List of threads that should be killed
    */
   @SuppressWarnings("deprecation")
private void interrupt(Vector<Thread> threads) {
       Thread staleThread = null;
       Task staleTask = null;

       // Interrupt each of the threads
       for (int idx = 0; idx < threads.size(); idx++) {
           staleThread = (Thread)threads.get(idx);
           staleTask = project.getThreadTask(staleThread);
           log("Attempting to interrupt the stale thread: " +
               "name=" + staleThread.getName() + ", " +
               "task=" + staleTask.getTaskName());
           staleThread.interrupt();
       }

   }
项目:build-management    文件:TimeoutTask.java   
/**
    * Attempt to stop the specified threads.
    *
    * @param   threads     List of threads that should be killed
    */
   @SuppressWarnings("deprecation")
private void stop(Vector<Thread> threads) {
       Thread staleThread = null;
       Task staleTask = null;

       // Interrupt each of the threads
       for (int idx = 0; idx < threads.size(); idx++) {
           staleThread = (Thread)threads.get(idx);
           staleTask = project.getThreadTask(staleThread);
           log("Attempting to stop the stale thread: " +
               "name=" + staleThread.getName() + ", " +
               "task=" + staleTask.getTaskName());
           staleThread.stop();
       }

   }
项目:build-management    文件:FrequentXmlLogger.java   
/**
 * 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;
}
项目:ant-processenabler    文件:ClassPathBuildFileTest.java   
/**
 * 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;
}
项目:japp-maven-plugin    文件:AbstractAntWorker.java   
/**
 * A utility method to create Ant worker tasks.
 */
protected <T extends Task> T createTask(Class<T> type) {

    if (type == null) {
        throw new NullPointerException("Null task class");
    }

    T task;
    try {
        task = type.newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Can't create Ant task: " + type.getName());
    }

    task.setProject(project);
    task.setTaskName(type.getSimpleName());
    task.setLocation(Location.UNKNOWN_LOCATION);
    return task;
}
项目:Reer    文件:PublishArtifactNotationParserFactory.java   
@Override
protected ConfigurablePublishArtifact parseType(File file) {
    Module module = metaDataProvider.getModule();
    ArtifactFile artifactFile = new ArtifactFile(file, module.getVersion());
    return instantiator.newInstance(DefaultPublishArtifact.class, artifactFile.getName(), artifactFile.getExtension(),
        artifactFile.getExtension(), artifactFile.getClassifier(), null, file, new Task[0]);
}
项目:incubator-netbeans    文件:NbBuildLogger.java   
public @Override TaskStructure getTaskStructure() {
    verifyRunning();
    Task task = e.getTask();
    if (task != null) {
        return LoggerTrampoline.TASK_STRUCTURE_CREATOR.makeTaskStructure(new TaskStructureImpl(task.getRuntimeConfigurableWrapper()));
    }
    // #49464: guess at task.
    Task lastTask = getLastTask();
    if (lastTask != null) {
        return LoggerTrampoline.TASK_STRUCTURE_CREATOR.makeTaskStructure(new TaskStructureImpl(lastTask.getRuntimeConfigurableWrapper()));
    }
    return null;
}
项目:incubator-netbeans    文件:ForEach.java   
/**
 * Constructs a new instance of the {@link ForEach} task. It simply sets the
 * default values for the attributes.
 */
public ForEach() {
    separator = DEFAULT_SEPARATOR;

    from = DEFAULT_FROM;
    to = DEFAULT_TO;
    increment = DEFAULT_INCREMENT;

    children = new LinkedList<Task>();
}
项目:incubator-netbeans    文件:ForEach.java   
/**
 * Sets the specified property to the given value and executes the children.
 */
private void executeChildren(String value) throws BuildException {
    getProject().setProperty(this.property, value);

    for (Task task: this.children) {
        task.perform();
    }
}
项目:oscm    文件:ForEachTask.java   
@Override
public void execute() throws BuildException {
    final String bak = getProject().getProperty(property);
    for (String token : tokens) {
        getProject().setProperty(property, token);
        for (Task task : tasks) {
            task.maybeConfigure();
            task.execute();
        }
    }
    if (bak != null) {
        getProject().setProperty(property, bak);
    }
}