Package org.apache.tools.ant

Examples of org.apache.tools.ant.Target


  /**
   * Find a target amid the projet targets
   */
  public Target findTargetByName(String target) {
    Target targetToFind = null;
    Hashtable targets = getProject().getTargets();
    for (Iterator i = targets.keySet().iterator(); i.hasNext();) {
      String targetName = (String) i.next();
      Target aTarget = (Target) targets.get(targetName);
      if (aTarget.getName().equals(target)) {
        targetToFind = aTarget;
      }
    }
    return targetToFind;
  }
View Full Code Here


            throws SAXParseException {
            String name = null;
            String depends = "";

            Project project = context.getProject();
            Target target = new Target();
            target.setProject(project);
            context.addTarget(target);

            for (int i = 0; i < attrs.getLength(); i++) {
                String attrUri = attrs.getURI(i);
                if (attrUri != null
                    && !attrUri.equals("")
                    && !attrUri.equals(uri)) {
                    continue; // Ignore attributes from unknown uris
                }
                String key = attrs.getLocalName(i);
                String value = attrs.getValue(i);

                if (key.equals("name")) {
                    name = value;
                    if ("".equals(name)) {
                        throw new BuildException("name attribute must "
                            + "not be empty");
                    }
                } else if (key.equals("depends")) {
                    depends = value;
                } else if (key.equals("if")) {
                    target.setIf(value);
                } else if (key.equals("unless")) {
                    target.setUnless(value);
                } else if (key.equals("id")) {
                    if (value != null && !value.equals("")) {
                        context.getProject().addReference(value, target);
                    }
                } else if (key.equals("description")) {
                    target.setDescription(value);
                } else {
                    throw new SAXParseException("Unexpected attribute \""
                        + key + "\"", context.getLocator());
                }
            }

            if (name == null) {
                throw new SAXParseException("target element appears without "
                    + "a name attribute", context.getLocator());
            }

            Hashtable currentTargets = project.getTargets();

            // If the name has already been defined ( import for example )
            if (currentTargets.containsKey(name)) {
                if (!context.isIgnoringProjectTag()) {
                    // not in a import'ed file
                    throw new BuildException(
                        "Duplicate target '" + name + "'",
                        new Location(context.getLocator().getSystemId(),
                                     context.getLocator().getLineNumber(),
                                     context.getLocator().getColumnNumber()));
                }
                // Alter the name.
                if (context.getCurrentProjectName() != null) {
                    String newName = context.getCurrentProjectName()
                        + "." + name;
                    project.log("Already defined in main or a previous import, "
                        + "define " + name + " as " + newName,
                                Project.MSG_VERBOSE);
                    name = newName;
                } else {
                    project.log("Already defined in main or a previous import, "
                        + "ignore " + name, Project.MSG_VERBOSE);
                    name = null;
                }
            }

            if (name != null) {
                target.setName(name);
                project.addOrReplaceTarget(name, target);
            }

            // take care of dependencies
            if (depends.length() > 0) {
                target.setDepends(depends);
            }
        }
View Full Code Here

     * @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];
    }
View Full Code Here

        }

        if (getImportStack().size() > 1) {
            // we are in an imported file.
            context.setIgnoreProjectTag(true);
            Target currentTarget = context.getCurrentTarget();
            try {
                Target newCurrent = new Target();
                newCurrent.setProject(project);
                newCurrent.setName("");
                context.setCurrentTarget(newCurrent);
                parse(project, source, new RootHandler(context, mainHandler));
                newCurrent.execute();
            } finally {
                context.setCurrentTarget(currentTarget);
            }
        } else {
            // top level file
View Full Code Here

        ret.setQName(ue.getQName());
        ret.setTaskType(ue.getTaskType());
        ret.setTaskName(ue.getTaskName());
        ret.setLocation(ue.getLocation());
        if (getOwningTarget() == null) {
            Target t = new Target();
            t.setProject(getProject());
            ret.setOwningTarget(t);
        } else {
            ret.setOwningTarget(getOwningTarget());
        }
        RuntimeConfigurable rc = new RuntimeConfigurable(
View Full Code Here

    private void addMXMLCTarget(Project project)
    {
        String mxmlFile = project.getProperty("mxmlFile");
        String mxmlFileLocation = project.getProperty("mxmlFileLocation");
       
        Target target = new Target();
        target.setName("compile");
        project.addTarget("compile", target);
       
        MxmlcTask mxmlcTask = new MxmlcTask();
        mxmlcTask.setTaskName("mxmlc");
        mxmlcTask.setFile(mxmlFileLocation + mxmlFile + ".mxml");
        mxmlcTask.setFork(true);
       
        mxmlcTask.setDynamicAttribute("services", servicesFilePath);
        mxmlcTask.setDynamicAttribute("keep-generated-actionscript", "false");
        mxmlcTask.setDynamicAttribute("debug", project.getProperty("debug"));
        mxmlcTask.setDynamicAttribute("context-root", project.getProperty("contextRoot"));
        ((NestedAttributeElement)mxmlcTask.createDynamicElement("load-config")).setDynamicAttribute("filename", flexConfigPath);
       
        mxmlcTask.setProject(project);
        target.addTask(mxmlcTask)
       
        HtmlWrapperTask htmlTask = new HtmlWrapperTask();
        htmlTask.setTaskName("html-wrapper");
        htmlTask.setTitle( mxmlFile+ " Flex Application");
        htmlTask.setFile(mxmlFile +".html");
        htmlTask.setHeight("100%");
        htmlTask.setWidth("100%");
        htmlTask.setApplication(mxmlFile + " app");
        htmlTask.setSwf(mxmlFile);
        htmlTask.setOutput(mxmlFileLocation);
       
        htmlTask.setProject(project);
        target.addTask(htmlTask);
    }
View Full Code Here

    protected Project _project = new Project();

    protected ConstructRegistry create()
    {
        Target t = new Target();

        ConstructRegistry result = new ConstructRegistry();
        result.setProject(_project);
        result.setOwningTarget(t);
        result.setTaskName("constructRegistry");
View Full Code Here

            throws SAXParseException {
            String name = null;
            String depends = "";

            Project project = context.getProject();
            Target target = new Target();
            target.setProject(project);
            target.setLocation(new Location(context.getLocator()));
            context.addTarget(target);

            for (int i = 0; i < attrs.getLength(); i++) {
                String attrUri = attrs.getURI(i);
                if (attrUri != null
                    && !attrUri.equals("")
                    && !attrUri.equals(uri)) {
                    continue; // Ignore attributes from unknown uris
                }
                String key = attrs.getLocalName(i);
                String value = attrs.getValue(i);

                if (key.equals("name")) {
                    name = value;
                    if ("".equals(name)) {
                        throw new BuildException("name attribute must "
                            + "not be empty");
                    }
                } else if (key.equals("depends")) {
                    depends = value;
                } else if (key.equals("if")) {
                    target.setIf(value);
                } else if (key.equals("unless")) {
                    target.setUnless(value);
                } else if (key.equals("id")) {
                    if (value != null && !value.equals("")) {
                        context.getProject().addReference(value, target);
                    }
                } else if (key.equals("description")) {
                    target.setDescription(value);
                } else {
                    throw new SAXParseException("Unexpected attribute \""
                        + key + "\"", context.getLocator());
                }
            }

            if (name == null) {
                throw new SAXParseException("target element appears without "
                    + "a name attribute", context.getLocator());
            }

            // Check if this target is in the current build file
            if (context.getCurrentTargets().get(name) != null) {
                throw new BuildException(
                    "Duplicate target '" + name + "'", target.getLocation());
            }

            Hashtable projectTargets = project.getTargets();
            boolean   usedTarget = false;
            // If the name has not already been defined define it
            if (projectTargets.containsKey(name)) {
                project.log("Already defined in main or a previous import, "
                            + "ignore " + name, Project.MSG_VERBOSE);
            } else {
                target.setName(name);
                context.getCurrentTargets().put(name, target);
                project.addOrReplaceTarget(name, target);
                usedTarget = true;
            }

            if (depends.length() > 0) {
                target.setDepends(depends);
            }

            if (context.isIgnoringProjectTag() && context.getCurrentProjectName() != null
                && context.getCurrentProjectName().length() != 0) {
                // In an impored file (and not completely
                // ignoring the project tag)
                String newName = context.getCurrentProjectName()
                    + "." + name;
                Target newTarget = usedTarget ? new Target(target) : target;
                newTarget.setName(newName);
                context.getCurrentTargets().put(newName, newTarget);
                project.addOrReplaceTarget(newName, newTarget);
            }
        }
View Full Code Here

        if (targets == null) {
            return null;
        }
        StringBuffer description = new StringBuffer();
        for (int i = 0; i < targets.size(); i++) {
            Target t = (Target) targets.elementAt(i);
            concatDescriptions(project, t, description);
        }
        return description.toString();
    }
View Full Code Here

     * @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];
    }
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.Target

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.