Package org.apache.tools.ant.types

Examples of org.apache.tools.ant.types.Commandline


     * <p>
     * Builds a command line to execute cleartool and then calls Exec's run method
     * to execute the command line.
     */
    public void execute() throws BuildException {
        Commandline commandLine = new Commandline();
        Project aProj = getProject();
        int result = 0;

        // Default the viewpath to basedir if it is not specified
        if (getViewPath() == null) {
            setViewPath(aProj.getBaseDir().getPath());
        }

        // build the command line from what we got the format is
        // cleartool update [options...] [viewpath ...]
        // as specified in the CLEARTOOL.EXE help
        commandLine.setExecutable(getClearToolCommand());
        commandLine.createArgument().setValue(COMMAND_UPDATE);

        // Check the command line options
        checkOptions(commandLine);

        // For debugging
        System.out.println(commandLine.toString());

        result = run(commandLine);
        if (result != 0) {
            String msg = "Failed executing: " + commandLine.toString();
            throw new BuildException(msg, location);
        }
    }
View Full Code Here


            // re-implement legacy behaviour:
            this.setCommand(AbstractCvsTask.default_command);
        }

        String c = this.getCommand();
        Commandline cloned = null;
        if (c != null) {
            cloned = (Commandline) cmd.clone();
            cloned.createArgument(true).setLine(c);
            this.addConfiguredCommandline(cloned, true);
        }

        try {
            for (int i = 0; i < vecCommandlines.size(); i++) {
View Full Code Here

     * <p>
     * Builds a command line to execute cleartool and then calls Exec's run method
     * to execute the command line.
     */
    public void execute() throws BuildException {
        Commandline commandLine = new Commandline();
        Project aProj = getProject();
        int result = 0;

        // Default the viewpath to basedir if it is not specified
        if (getViewPath() == null) {
            setViewPath(aProj.getBaseDir().getPath());
        }

        // build the command line from what we got the format is
        // cleartool checkout [options...] [viewpath ...]
        // as specified in the CLEARTOOL.EXE help
        commandLine.setExecutable(getClearToolCommand());
        commandLine.createArgument().setValue(COMMAND_CHECKOUT);

        checkOptions(commandLine);

        result = run(commandLine);
        if (result != 0) {
            String msg = "Failed executing: " + commandLine.toString();
            throw new BuildException(msg, location);
        }
    }
View Full Code Here

*/
public class WLRmic extends DefaultRmicAdapter {

    public boolean execute() throws BuildException {
        getRmic().log("Using WebLogic rmic", Project.MSG_VERBOSE);
        Commandline cmd = setupRmicCommand(new String[] {"-noexit"});

        AntClassLoader loader = null;
        try {
            // Create an instance of the rmic
            Class c = null;
            if (getRmic().getClasspath() == null) {
                c = Class.forName("weblogic.rmic");
            } else {
                loader = new AntClassLoader(getRmic().getProject(),
                                            getRmic().getClasspath());
                c = loader.loadClass("weblogic.rmic");
                AntClassLoader.initializeClass(c);
            }
            Method doRmic = c.getMethod("main",
                                        new Class [] { String[].class });
            doRmic.invoke(null, new Object[] {cmd.getArguments()  });
            return true;
        } catch (ClassNotFoundException ex) {
            throw new BuildException("Cannot use WebLogic rmic, as it is not "
                                     + "available.  A common solution is to "
                                     + "set the environment variable "
View Full Code Here

*/
public class KaffeRmic extends DefaultRmicAdapter {

    public boolean execute() throws BuildException {
        getRmic().log("Using Kaffe rmic", Project.MSG_VERBOSE);
        Commandline cmd = setupRmicCommand();

        try {

            Class c = Class.forName("kaffe.rmi.rmic.RMIC");
            Constructor cons = c.getConstructor(new Class[] { String[].class });
            Object rmic = cons.newInstance(new Object[] { cmd.getArguments() });
            Method doRmic = c.getMethod("run", null);
            Boolean ok = (Boolean) doRmic.invoke(rmic, null);

            return ok.booleanValue();
        } catch (ClassNotFoundException ex) {
View Full Code Here

    }

    public void execute() throws BuildException {
        checkOptions();
        try {
            Commandline cmdl = new Commandline();
            // we need to run Coverage from his directory due to dll/jar issues
            cmdl.setExecutable(new File(home, "jpcovreport").getAbsolutePath());
            String[] params = getParameters();
            for (int i = 0; i < params.length; i++) {
                cmdl.createArgument().setValue(params[i]);
            }

            // use the custom handler for stdin issues
            LogStreamHandler handler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);
            Execute exec = new Execute(handler);
            log(cmdl.describeCommand(), Project.MSG_VERBOSE);
            exec.setCommandline(cmdl.getCommandline());
            int exitValue = exec.execute();
            if (exitValue != 0) {
                throw new BuildException("JProbe Coverage Report failed (" + exitValue + ")");
            }
            log("coveragePath: " + coveragePath, Project.MSG_VERBOSE);
View Full Code Here

        project.setBasedir(".");
        ej.setClasspath(new Path(project, getTestClassPath()));
    }

    private Commandline getCommandline(int timetorun) throws Exception {
        Commandline cmd = new Commandline();
        cmd.setExecutable(TimeProcess.class.getName());
        cmd.createArgument().setValue(String.valueOf(timetorun));
        return cmd;
    }
View Full Code Here

        cmd.createArgument().setValue(String.valueOf(timetorun));
        return cmd;
    }

    public void testNoTimeOut() throws Exception {
        Commandline cmd = getCommandline(TIME_OUT/2);
        ej.setJavaCommand(cmd);
        ej.execute(project);
        assertTrue("process should not have been killed", !ej.killedProcess());
    }
View Full Code Here

        assertTrue("process should not have been killed", !ej.killedProcess());
    }

    // test that the watchdog ends the process
    public void testTimeOut() throws Exception {
        Commandline cmd = getCommandline(TIME_OUT*2);
        ej.setJavaCommand(cmd);
        long now = System.currentTimeMillis();
        ej.execute(project);
        long elapsed = System.currentTimeMillis() - now;
        assertTrue("process should have been killed", ej.killedProcess());
View Full Code Here

                                     + "been specified.");
        }

        log("Generating Javadoc", Project.MSG_INFO);

        Commandline toExecute = (Commandline) cmd.clone();
        toExecute.setExecutable(JavaEnvUtils.getJdkExecutable("javadoc"));

        // ------------------------------------------ general javadoc arguments
        if (doctitle != null) {
            toExecute.createArgument().setValue("-doctitle");
            toExecute.createArgument().setValue(expand(doctitle.getText()));
        }
        if (header != null) {
            toExecute.createArgument().setValue("-header");
            toExecute.createArgument().setValue(expand(header.getText()));
        }
        if (footer != null) {
            toExecute.createArgument().setValue("-footer");
            toExecute.createArgument().setValue(expand(footer.getText()));
        }
        if (bottom != null) {
            toExecute.createArgument().setValue("-bottom");
            toExecute.createArgument().setValue(expand(bottom.getText()));
        }

        if (classpath == null) {
            classpath = (new Path(getProject())).concatSystemClasspath("last");
        } else {
            classpath = classpath.concatSystemClasspath("ignore");
        }

        if (!javadoc1) {
            if (classpath.size() > 0) {
                toExecute.createArgument().setValue("-classpath");
                toExecute.createArgument().setPath(classpath);
            }
            if (sourceDirs.size() > 0) {
                toExecute.createArgument().setValue("-sourcepath");
                toExecute.createArgument().setPath(sourceDirs);
            }
        } else {
            sourceDirs.append(classpath);
            if (sourceDirs.size() > 0) {
                toExecute.createArgument().setValue("-classpath");
                toExecute.createArgument().setPath(sourceDirs);
            }
        }

        if (version && doclet == null) {
            toExecute.createArgument().setValue("-version");
        }
        if (author && doclet == null) {
            toExecute.createArgument().setValue("-author");
        }

        if (javadoc1 || doclet == null) {
            if (destDir == null) {
                String msg = "destDir attribute must be set!";
                throw new BuildException(msg);
            }
        }

        // ---------------------------- javadoc2 arguments for default doclet

        if (!javadoc1) {
            if (doclet != null) {
                if (doclet.getName() == null) {
                    throw new BuildException("The doclet name must be "
                                             + "specified.", getLocation());
                } else {
                    toExecute.createArgument().setValue("-doclet");
                    toExecute.createArgument().setValue(doclet.getName());
                    if (doclet.getPath() != null) {
                        Path docletPath
                            = doclet.getPath().concatSystemClasspath("ignore");
                        if (docletPath.size() != 0) {
                            toExecute.createArgument().setValue("-docletpath");
                            toExecute.createArgument().setPath(docletPath);
                        }
                    }
                    for (Enumeration e = doclet.getParams();
                         e.hasMoreElements();) {
                        DocletParam param = (DocletParam) e.nextElement();
                        if (param.getName() == null) {
                            throw new BuildException("Doclet parameters must "
                                                     + "have a name");
                        }

                        toExecute.createArgument().setValue(param.getName());
                        if (param.getValue() != null) {
                            toExecute.createArgument()
                                .setValue(param.getValue());
                        }
                    }
                }
            }
            if (bootclasspath != null && bootclasspath.size() > 0) {
                toExecute.createArgument().setValue("-bootclasspath");
                toExecute.createArgument().setPath(bootclasspath);
            }

            // add the links arguments
            if (links.size() != 0) {
                for (Enumeration e = links.elements(); e.hasMoreElements();) {
                    LinkArgument la = (LinkArgument) e.nextElement();

                    if (la.getHref() == null || la.getHref().length() == 0) {
                        log("No href was given for the link - skipping",
                            Project.MSG_VERBOSE);
                        continue;
                    } else {
                        // is the href a valid URL
                        try {
                            URL base = new URL("file://.");
                            new URL(base, la.getHref());
                        } catch (MalformedURLException mue) {
                            // ok - just skip
                            log("Link href \"" + la.getHref()
                                + "\" is not a valid url - skipping link",
                                Project.MSG_WARN);
                            continue;
                        }
                    }

                    if (la.isLinkOffline()) {
                        File packageListLocation = la.getPackagelistLoc();
                        if (packageListLocation == null) {
                            throw new BuildException("The package list "
                                                     + " location for link " + la.getHref()
                                                     + " must be provided because the link is "
                                                     + "offline");
                        }
                        File packageListFile =
                            new File(packageListLocation, "package-list");
                        if (packageListFile.exists()) {
                            try {
                                String packageListURL =
                                    fileUtils.getFileURL(packageListLocation)
                                    .toExternalForm();
                                toExecute.createArgument()
                                    .setValue("-linkoffline");
                                toExecute.createArgument()
                                    .setValue(la.getHref());
                                toExecute.createArgument()
                                    .setValue(packageListURL);
                            } catch (MalformedURLException ex) {
                                log("Warning: Package list location was "
                                    + "invalid " + packageListLocation,
                                    Project.MSG_WARN);
                            }
                        } else {
                            log("Warning: No package list was found at "
                                + packageListLocation, Project.MSG_VERBOSE);
                        }
                    } else {
                        toExecute.createArgument().setValue("-link");
                        toExecute.createArgument().setValue(la.getHref());
                    }
                }
            }

            // add the single group arguments
            // Javadoc 1.2 rules:
            //   Multiple -group args allowed.
            //   Each arg includes 3 strings: -group [name] [packagelist].
            //   Elements in [packagelist] are colon-delimited.
            //   An element in [packagelist] may end with the * wildcard.

            // Ant javadoc task rules for group attribute:
            //   Args are comma-delimited.
            //   Each arg is 2 space-delimited strings.
            //   E.g., group="XSLT_Packages org.apache.xalan.xslt*,
            //                XPath_Packages org.apache.xalan.xpath*"
            if (group != null) {
                StringTokenizer tok = new StringTokenizer(group, ",", false);
                while (tok.hasMoreTokens()) {
                    String grp = tok.nextToken().trim();
                    int space = grp.indexOf(" ");
                    if (space > 0) {
                        String name = grp.substring(0, space);
                        String pkgList = grp.substring(space + 1);
                        toExecute.createArgument().setValue("-group");
                        toExecute.createArgument().setValue(name);
                        toExecute.createArgument().setValue(pkgList);
                    }
                }
            }

            // add the group arguments
            if (groups.size() != 0) {
                for (Enumeration e = groups.elements(); e.hasMoreElements();) {
                    GroupArgument ga = (GroupArgument) e.nextElement();
                    String title = ga.getTitle();
                    String packages = ga.getPackages();
                    if (title == null || packages == null) {
                        throw new BuildException("The title and packages must "
                                                 + "be specified for group "
                                                 + "elements.");
                    }
                    toExecute.createArgument().setValue("-group");
                    toExecute.createArgument().setValue(expand(title));
                    toExecute.createArgument().setValue(packages);
                }
            }

            // JavaDoc 1.4 parameters
            if (javadoc4) {
                for (Enumeration e = tags.elements(); e.hasMoreElements();) {
                    Object element = e.nextElement();
                    if (element instanceof TagArgument) {
                        TagArgument ta = (TagArgument) element;
                        File tagDir = ta.getDir(getProject());
                        if (tagDir == null) {
                            // The tag element is not used as a fileset,
                            // but specifies the tag directly.
                            toExecute.createArgument().setValue ("-tag");
                            toExecute.createArgument().setValue (ta.getParameter());
                        } else {
                            // The tag element is used as a fileset. Parse all the files and
                            // create -tag arguments.
                            DirectoryScanner tagDefScanner = ta.getDirectoryScanner(getProject());
                            String[] files = tagDefScanner.getIncludedFiles();
                            for (int i = 0; i < files.length; i++) {
                                File tagDefFile = new File(tagDir, files[i]);
                                try {
                                    BufferedReader in
                                        = new BufferedReader(new FileReader(tagDefFile));
                                    String line = null;
                                    while ((line = in.readLine()) != null) {
                                        toExecute.createArgument().setValue ("-tag");
                                        toExecute.createArgument().setValue (line);
                                    }
                                    in.close();
                                } catch (IOException ioe) {
                                    throw new BuildException("Couldn't read "
                                        + " tag file from "
                                        + tagDefFile.getAbsolutePath(), ioe);
                                }
                            }
                        }
                    } else {
                        ExtensionInfo tagletInfo = (ExtensionInfo) element;
                        toExecute.createArgument().setValue("-taglet");
                        toExecute.createArgument().setValue(tagletInfo
                                                            .getName());
                        if (tagletInfo.getPath() != null) {
                            Path tagletPath = tagletInfo.getPath()
                                .concatSystemClasspath("ignore");
                            if (tagletPath.size() != 0) {
                                toExecute.createArgument()
                                    .setValue("-tagletpath");
                                toExecute.createArgument().setPath(tagletPath);
                            }
                        }
                    }
                }

                if (source != null) {
                    toExecute.createArgument().setValue("-source");
                    toExecute.createArgument().setValue(source);
                }

                if (linksource && doclet == null) {
                    toExecute.createArgument().setValue("-linksource");
                }
                if (breakiterator && doclet == null) {
                    toExecute.createArgument().setValue("-breakiterator");
                }
                if (noqualifier != null && doclet == null) {
                    toExecute.createArgument().setValue("-noqualifier");
                    toExecute.createArgument().setValue(noqualifier);
                }
            }

        }

        File tmpList = null;
        PrintWriter srcListWriter = null;
        try {

            /**
             * Write sourcefiles and package names to a temporary file
             * if requested.
             */
            if (useExternalFile) {
                if (tmpList == null) {
                    tmpList = fileUtils.createTempFile("javadoc", "", null);
                    tmpList.deleteOnExit();
                    toExecute.createArgument()
                        .setValue("@" + tmpList.getAbsolutePath());
                }
                srcListWriter = new PrintWriter(
                                                new FileWriter(tmpList.getAbsolutePath(),
                                                               true));
            }

            Enumeration e = packagesToDoc.elements();
            while (e.hasMoreElements()) {
                String packageName = (String) e.nextElement();
                if (useExternalFile) {
                    srcListWriter.println(packageName);
                } else {
                    toExecute.createArgument().setValue(packageName);
                }
            }

            e = sourceFilesToDoc.elements();
            while (e.hasMoreElements()) {
                SourceFile sf = (SourceFile) e.nextElement();
                String sourceFileName = sf.getFile().getAbsolutePath();
                if (useExternalFile) {
                    if (javadoc4 && sourceFileName.indexOf(" ") > -1) {
                        srcListWriter.println("\"" + sourceFileName + "\"");
                    } else {
                        srcListWriter.println(sourceFileName);
                    }
                } else {
                    toExecute.createArgument().setValue(sourceFileName);
                }
            }

        } catch (IOException e) {
            tmpList.delete();
            throw new BuildException("Error creating temporary file",
                                     e, getLocation());
        } finally {
            if (srcListWriter != null) {
                srcListWriter.close();
            }
        }

        if (packageList != null) {
            toExecute.createArgument().setValue("@" + packageList);
        }
        log(toExecute.describeCommand(), Project.MSG_VERBOSE);

        log("Javadoc execution", Project.MSG_INFO);

        JavadocOutputStream out = new JavadocOutputStream(Project.MSG_INFO);
        JavadocOutputStream err = new JavadocOutputStream(Project.MSG_WARN);
        Execute exe = new Execute(new PumpStreamHandler(out, err));
        exe.setAntRun(getProject());

        /*
         * No reason to change the working directory as all filenames and
         * path components have been resolved already.
         *
         * Avoid problems with command line length in some environments.
         */
        exe.setWorkingDirectory(null);
        try {
            exe.setCommandline(toExecute.getCommandline());
            int ret = exe.execute();
            if (ret != 0 && failOnError) {
                throw new BuildException("Javadoc returned " + ret, getLocation());
            }
        } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.types.Commandline

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.