Package org.apache.tools.ant

Examples of org.apache.tools.ant.Target


            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);
View Full Code Here


            String name = null;
            String depends = "";
            String extensionPoint = null;

            Project project = context.getProject();
            Target target = "target".equals(tag)
                ? new Target() : new ExtensionPoint();
            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 if (key.equals("extensionOf")) {
                    extensionPoint = 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());
            }

            String prefix = null;
            boolean isInIncludeMode =
                context.isIgnoringProjectTag() && isInIncludeMode();
            String sep = getCurrentPrefixSeparator();

            if (isInIncludeMode) {
                prefix = getTargetPrefix(context);
                if (prefix == null) {
                    throw new BuildException("can't include build file "
                                             + context.getBuildFile()
                                             + ", no as attribute has been given"
                                             + " and the project tag doesn't"
                                             + " specify a name attribute");
                }
                name = prefix + sep + name;
            }

            // 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) {
                if (!isInIncludeMode) {
                    target.setDepends(depends);
                } else {
                    for (Iterator iter =
                             Target.parseDepends(depends, name, "depends")
                             .iterator();
                         iter.hasNext(); ) {
                        target.addDependency(prefix + sep + iter.next());
                    }
                }
            }
            if (!isInIncludeMode && context.isIgnoringProjectTag()
                && (prefix = getTargetPrefix(context)) != null) {
                // In an imported file (and not completely
                // ignoring the project tag or having a preconfigured prefix)
                String newName = prefix + sep + name;
                Target newTarget = usedTarget ? new Target(target) : target;
                newTarget.setName(newName);
                context.getCurrentTargets().put(newName, newTarget);
                project.addOrReplaceTarget(newName, newTarget);
            }
            if (extensionPoint != null) {
                for (Iterator iter =
                         Target.parseDepends(extensionPoint, name, "extensionOf")
                         .iterator();
                     iter.hasNext(); ) {
                    String tgName = (String) iter.next();
                    if (isInIncludeMode()) {
                        tgName = prefix + sep + tgName;
                    }
                    if (!projectTargets.containsKey(tgName)) {
                        throw new BuildException("can't add target "
                                                 + name + " to extension-point "
                                                 + tgName
                                                 + " because the extension-point"
                                                 + " is unknown.");
                    }
                    Target t = (Target) projectTargets.get(tgName);
                    if (!(t instanceof ExtensionPoint)) {
                        throw new BuildException("referenced target "
                                                 + tgName
                                                 + " is not an extension-point");
                    }
                    t.addDependency(name);
                }
            }
        }
View Full Code Here

{
    protected Project _project = new Project();

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

        ManifestClassPath result = new ManifestClassPath();
        result.setProject(_project);
        result.setOwningTarget(t);
        result.setTaskName("manifestClassPath");
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

            task = new Task(){
                public void execute() {
                }
            };
            task.setTaskName("testTask");
            target = new Target();
            target.setName("testTarget");
            target.setProject(this);
            target.addTask(task);
            task.setOwningTarget(target);
        }
View Full Code Here

                                             + "its own parent target.");
                }
                boolean circular = false;
                for (Iterator it = locals.iterator();
                     !circular && it.hasNext();) {
                    Target other =
                        (Target) (getProject().getTargets().get(it.next()));
                    circular |= (other != null
                                 && other.dependsOn(owningTargetName));
                }
                if (circular) {
                    throw new BuildException(getTaskName()
                                             + " task calling a target"
                                             + " that depends on"
View Full Code Here

        }

        //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);
View Full Code Here

  }
  /**
   * Find a target amid the projet targets
   */
  private 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

     */
    public static String getDescription(Project project) {
        StringBuffer description = new StringBuffer();
        Vector targets = (Vector) project.getReference("ant.targets");
        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

                if (owningTargetName.equals(target)) {
                    throw new BuildException(getTaskName() + " task calling "
                                             + "its own parent target.");
                } else {
                    Target other =
                        (Target) getProject().getTargets().get(target);
                    if (other != null && other.dependsOn(owningTargetName)) {
                        throw new BuildException(getTaskName()
                                                 + " task calling a target"
                                                 + " that depends on"
                                                 + " its parent target \'"
                                                 + owningTargetName
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.