Package org.apache.tools.ant

Examples of org.apache.tools.ant.Target


        AntXMLContext antParsingContext = (AntXMLContext) project.getReference("ant.parsing.context");
        Vector targets = antParsingContext.getTargets();
        int bundleTaskCount = 0;
        Task unconfiguredBundleTask = null;
        for (Object targetObj : targets) {
            Target target = (Target) targetObj;
            Task[] tasks = target.getTasks();
            for (Task task : tasks) {
                if (task.getTaskName().equals(BUNDLE_TASK_NAME)) {
                    abortIfTaskWithinTarget(target, task);
                    bundleTaskCount++;
                    unconfiguredBundleTask = task;
View Full Code Here


    }

    private void logEvent(BuildEvent event, String additionalMessage) {
        String message = event.getMessage();
        Throwable exception = event.getException();
        Target target = event.getTarget();
        Task task = event.getTask();

        if (additionalMessage != null) {
            this.output.println(additionalMessage);
        }

        if (target != null) {
            String targetName = (target.getName() != null) ? target.getName() : "";
            this.output.print("[" + targetName + "] ");
        }

        if (task != null) {
            this.output.print("<" + task.getTaskName() + "> ");
View Full Code Here

                getProject().getBundleVersion(), getProject().getBundleDescription(), complianceToUse);

            if (this.preinstallTarget != null) {
                getProject().auditLog(AuditStatus.SUCCESS, "Pre-Install Started", "The pre install target will start",
                    "The pre install target named [" + this.preinstallTarget + "] will start", null);
                Target target = (Target) getProject().getTargets().get(this.preinstallTarget);
                if (target == null) {
                    try {
                        getProject().auditLog(
                            AuditStatus.FAILURE,
                            "Pre-Install Failure",
                            "The pre install target does not exist",
                            "The pre install target specified in the recipe [" + this.preinstallTarget
                                + "] does not exist.", null);
                    } catch (Throwable ignore) {
                        // swallow any errors that occur here, we want to throw the real build exception
                    }
                    throw new BuildException("Specified preinstall target (" + this.preinstallTarget
                        + ") does not exist.");
                }
                target.performTasks();
                getProject().auditLog(AuditStatus.SUCCESS, "Pre-Install Finished",
                    "The pre install target has finished", null, null);
            }

            boolean haveSomethingToDo = false;
            if (!this.files.isEmpty()) {
                haveSomethingToDo = true;
                log("Deploying files " + this.files + "...", Project.MSG_VERBOSE);
            }
            if (!this.urlFiles.isEmpty()) {
                haveSomethingToDo = true;
                log("Deploying files from URL " + this.urlFiles + "...", Project.MSG_VERBOSE);
            }
            if (!this.archives.isEmpty()) {
                haveSomethingToDo = true;
                log("Deploying archives " + this.archives + "...", Project.MSG_VERBOSE);
            }
            if (!this.urlArchives.isEmpty()) {
                haveSomethingToDo = true;
                log("Deploying archives from URL " + this.urlArchives + "...", Project.MSG_VERBOSE);
            }
            if (!this.contentToHandover.isEmpty()) {
                haveSomethingToDo = true;
                log("Handing over " + this.contentToHandover.size() + " file(s)/archive(s)...", Project.MSG_VERBOSE);
            }
            if (!haveSomethingToDo) {
                throw new BuildException(
                    "You must specify at least one file to deploy via nested file, archive, url-file, url-archive types in your recipe");
            }

            log("Destination compliance set to '" + complianceToUse + "'.", Project.MSG_VERBOSE);
            switch (complianceToUse) {
            case full:
                if (!dryRun) {
                    getProject()
                        .auditLog(
                            AuditStatus.INFO,
                            "Managing Top Level Deployment Directory",
                            "The top level deployment directory will be managed - files found there will be backed up and removed!",
                            "The bundle recipe has requested that the top level deployment directory be fully managed by RHQ."
                                + "This means any files currently located in the top level deployment directory will be removed and backed up",
                            null);
                }
                break;
            case filesAndDirectories:
                log("Files and directories in the destination directory not contained in the bundle will be kept intact.\n"
                    + "Note that the contents of the directories that ARE contained in the bundle will be synced with "
                    + "the contents as specified in the bundle. I.e. the subdirectories in the destination that are also "
                    + "contained in the bundle are made compliant with the bundle.", Project.MSG_VERBOSE);
                break;
            default:
                throw new IllegalStateException("Unhandled destination compliance mode: " + complianceToUse.toString());
            }

            Map<File, File> allArchives = new HashMap<File, File>(this.archives);
            Map<File, File> allFiles = new HashMap<File, File>(this.files);
            Map<File, Pattern> allArchiveReplacePatterns = new HashMap<File, Pattern>(this.archiveReplacePatterns);
            Set<File> allRawFilesToReplace = new HashSet<File>(this.rawFilesToReplace);
            Map<File, Boolean> allArchivesExploded = new HashMap<File, Boolean>(this.archivesExploded);

            downloadFilesFromUrlEndpoints(allArchives, allFiles, allArchiveReplacePatterns, allRawFilesToReplace,
                allArchivesExploded);

            handoverRemoteContentDownloadDirectory = createTempDirectory("handover-", ".download", baseDir);
            Map<HasHandover, File> downloadedFilesToHandover = downloadRemoteContentToHandover(handoverRemoteContentDownloadDirectory);

            try {
                DeploymentData deploymentData = new DeploymentData(deploymentProps, baseDir, deployDir, allFiles,
                    allRawFilesToReplace, allArchives, allArchiveReplacePatterns, templateEngine, this.ignorePattern,
                    allArchivesExploded);
                Deployer deployer = new Deployer(deploymentData);
                DeployDifferences diffs = getProject().getDeployDifferences();

                // we only want to emit audit trail when something is really going to happen on disk; don't log if doing a dry run
                if (!dryRun) {
                    getProject().auditLog(AuditStatus.SUCCESS, "Deployer Started", "The deployer has started its work",
                        null, null);
                }

                if (revert) {
                    deployer.redeployAndRestoreBackupFiles(diffs, clean, dryRun);
                } else {
                    deployer.deploy(diffs, clean, dryRun);
                }

                HandoverTarget handoverTarget = getProject().getHandoverTarget();
                if (handoverTarget != null) {
                    for (HasHandover hasHandoverReference : contentToHandover) {
                        Handover handoverTag = hasHandoverReference.getHandover();
                        File source = getFileSource(hasHandoverReference, downloadedFilesToHandover, templateEngine);
                        FileInputStream contentStream = new FileInputStream(source);

                        HandoverInfo.Builder builder = new HandoverInfo.Builder();
                        builder.setContent(contentStream);
                        builder.setFilename(source.getName());
                        builder.setAction(handoverTag.getAction());
                        builder.setParams(handoverTag.getHandoverParams());
                        builder.setRevert(revert);
                        HandoverInfo handoverInfo = builder.createHandoverInfo();

                        if (!dryRun) {
                            try {
                                boolean handoverSuccess = handoverTarget.handoverContent(handoverInfo);
                                String informationMessage = "Source: " + source.getName() + ", " + handoverTag;
                                if (handoverSuccess) {
                                    getProject().auditLog(AuditStatus.INFO, "Handover",
                                        "Handover target reported success", informationMessage, null);
                                } else {
                                    if (handoverTag.isFailonerror()) {
                                        getProject().auditLog(AuditStatus.FAILURE, "Handover",
                                            "Handover target reported a failure", informationMessage, null);
                                        throw new Exception("Handover failed: " + handoverTag);
                                    } else {
                                        getProject().auditLog(AuditStatus.WARN, "Handover",
                                            "Handover target reported a failure", informationMessage, null);
                                    }
                                }
                            } finally {
                                safeClose(contentStream);
                            }
                        }
                    }
                }

                // we only want to emit audit trail when something is really going to happen on disk; don't log if doing a dry run
                if (!dryRun) {
                    getProject().auditLog(AuditStatus.SUCCESS, "Deployer Finished",
                        "The deployer has finished its work", null, diffs.toString());
                }
            } catch (Throwable t) {
                try {
                    getProject().auditLog(AuditStatus.FAILURE, "Deployer Failed",
                        "The deployer encountered an error and could not finished", ThrowableUtil.getAllMessages(t),
                        ThrowableUtil.getStackAsString(t));
                } catch (Throwable ignore) {
                    // swallow any errors that occur here, we want to throw the real build exception
                }
                throw new BuildException("Failed to deploy bundle [" + getProject().getBundleName() + "] version ["
                    + getProject().getBundleVersion() + "]: " + t, t);
            }

            if (this.systemService != null) {
                this.systemService.install();
            }

            if (this.postinstallTarget != null) {
                getProject().auditLog(AuditStatus.SUCCESS, "Post-Install Started",
                    "The post install target will start",
                    "The post install target named [" + this.postinstallTarget + "] will start", null);
                Target target = (Target) getProject().getTargets().get(this.postinstallTarget);
                if (target == null) {
                    try {
                        getProject().auditLog(
                            AuditStatus.FAILURE,
                            "Post-Install Failure",
                            "The post install target does not exist",
                            "The post install target specified in the recipe [" + this.postinstallTarget
                                + "] does not exist.", null);
                    } catch (Throwable ignore) {
                        // swallow any errors that occur here, we want to throw the real build exception
                    }
                    throw new BuildException("Specified postinstall target (" + this.postinstallTarget
                        + ") does not exist.");
                }
                target.performTasks();
                getProject().auditLog(AuditStatus.SUCCESS, "Post-Install Finished",
                    "The post install target has finished", null, null);
            }
        } catch (Throwable t) {
            try {
View Full Code Here

    if(m_onHaltTarget != null) {
      if(m_outputDir != null) {
        getProject().setProperty("testng.outputdir", m_outputDir.getAbsolutePath());
      }
      getProject().setProperty("testng.returncode", String.valueOf(exitValue));
      Target t= (Target) getProject().getTargets().get(m_onHaltTarget);
      if(t != null) {
        t.execute();
      }
    }
  }
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

            project.addReference(REFID_TARGETS, context.getTargets());
        }
        if (getImportStack().size() > 1) {
            // we are in an imported file.
            context.setIgnoreProjectTag(true);
            Target currentTarget = context.getCurrentTarget();
            Target currentImplicit = context.getImplicitTarget();
            Map    currentTargets = context.getCurrentTargets();
            try {
                Target newCurrent = new Target();
                newCurrent.setProject(project);
                newCurrent.setName("");
                context.setCurrentTarget(newCurrent);
                context.setCurrentTargets(new HashMap());
                context.setImplicitTarget(newCurrent);
                parse(project, source, new RootHandler(context, mainHandler));
                newCurrent.execute();
            } finally {
                context.setCurrentTarget(currentTarget);
                context.setImplicitTarget(currentImplicit);
                context.setCurrentTargets(currentTargets);
            }
        } else {
            // top level file
            context.setCurrentTargets(new HashMap());
            parse(project, source, new RootHandler(context, mainHandler));
            // Execute the top-level target
            context.getImplicitTarget().execute();

            // resolve extensionOf attributes
            for (Iterator i = getExtensionStack().iterator(); i.hasNext(); ) {
                String[] extensionInfo = (String[]) i.next();
                String tgName = extensionInfo[0];
                String name = extensionInfo[1];
                Hashtable projectTargets = project.getTargets();
                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

            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.getBuildFileURL()
                                             + ", 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) {
                ProjectHelper helper =
View Full Code Here

            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

   public void onDepthChange(Hermes hermes, DestinationConfig dConfig, long currentDepth)
   {
      if (currentDepth > depth)
      {
         final Target invokeTarget = (Target) getProject().getTargets().get(getTarget());

         log(dConfig.getName() + " on " + hermes.getId() + " has triggered, currentDepth=" + currentDepth);

         System.setProperty(getHermesProperty(), hermes.getId());
         System.setProperty(getDestinationProperty(), dConfig.getName());
         System.setProperty(getMessageProperty(), "depth=" + currentDepth);
         invokeTarget.execute();
      }
   }
View Full Code Here

     */
    private void compile(String outputLocation){
        //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

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.