Search in sources :

Example 1 with Commandline

use of org.apache.tools.ant.types.Commandline in project error-prone by google.

the class ErrorProneExternalCompilerAdapter method execute.

@Override
public boolean execute() throws BuildException {
    if (getJavac().isForkedJavac()) {
        attributes.log("Using external Error Prone compiler", Project.MSG_VERBOSE);
        Commandline cmd = new Commandline();
        cmd.setExecutable(JavaEnvUtils.getJdkExecutable("java"));
        if (memoryStackSize != null) {
            cmd.createArgument().setValue("-Xss" + memoryStackSize);
        }
        String memoryParameterPrefix = "-X";
        if (memoryInitialSize != null) {
            cmd.createArgument().setValue(memoryParameterPrefix + "ms" + this.memoryInitialSize);
            // Prevent setupModernJavacCommandlineSwitches() from doing it also
            memoryInitialSize = null;
        }
        if (memoryMaximumSize != null) {
            cmd.createArgument().setValue(memoryParameterPrefix + "mx" + this.memoryMaximumSize);
            // Prevent setupModernJavacCommandlineSwitches() from doing it also
            memoryMaximumSize = null;
        }
        for (Argument arg : jvmArgs) {
            for (String part : arg.getParts()) {
                cmd.createArgument().setValue(part);
            }
        }
        Path bootclasspath = new Path(getProject());
        addResourceSource(bootclasspath, "com/google/errorprone/ErrorProneExternalCompilerAdapter.class");
        cmd.createArgument().setValue("-Xbootclasspath/p:" + bootclasspath);
        if (classpath != null) {
            cmd.createArgument().setValue("-classpath");
            cmd.createArgument().setPath(classpath);
        }
        cmd.createArgument().setValue(ErrorProneCompiler.class.getName());
        setupModernJavacCommandlineSwitches(cmd);
        int firstFile = cmd.size();
        logAndAddFilesToCompile(cmd);
        return executeExternalCompile(cmd.getCommandline(), firstFile, true) == 0;
    } else {
        attributes.log("You must set fork=\"yes\" to use the external Error Prone compiler", Project.MSG_ERR);
        return false;
    }
}
Also used : Path(org.apache.tools.ant.types.Path) Commandline(org.apache.tools.ant.types.Commandline) Argument(org.apache.tools.ant.types.Commandline.Argument)

Example 2 with Commandline

use of org.apache.tools.ant.types.Commandline in project groovy-core by groovy.

the class Groovy method createNewArgs.

private void createNewArgs(String txt) throws IOException {
    final String[] args = cmdline.getCommandline();
    // Temporary file - delete on exit, create (assured unique name).
    final File tempFile = FileUtils.getFileUtils().createTempFile(PREFIX, SUFFIX, null, true, true);
    final String[] commandline = new String[args.length + 1];
    ResourceGroovyMethods.write(tempFile, txt);
    commandline[0] = tempFile.getCanonicalPath();
    System.arraycopy(args, 0, commandline, 1, args.length);
    super.clearArgs();
    for (String arg : commandline) {
        final Commandline.Argument argument = super.createArg();
        argument.setValue(arg);
    }
}
Also used : Commandline(org.apache.tools.ant.types.Commandline) File(java.io.File)

Example 3 with Commandline

use of org.apache.tools.ant.types.Commandline in project groovy by apache.

the class Groovy method createNewArgs.

private void createNewArgs(String txt) throws IOException {
    final String[] args = cmdline.getCommandline();
    // Temporary file - delete on exit, create (assured unique name).
    final File tempFile = FileUtils.getFileUtils().createTempFile(PREFIX, SUFFIX, null, true, true);
    final String[] commandline = new String[args.length + 1];
    ResourceGroovyMethods.write(tempFile, txt);
    commandline[0] = tempFile.getCanonicalPath();
    System.arraycopy(args, 0, commandline, 1, args.length);
    super.clearArgs();
    for (String arg : commandline) {
        final Commandline.Argument argument = super.createArg();
        argument.setValue(arg);
    }
}
Also used : Commandline(org.apache.tools.ant.types.Commandline) File(java.io.File)

Example 4 with Commandline

use of org.apache.tools.ant.types.Commandline in project jangaroo-tools by CoreMedia.

the class JoodocTask method execute.

public void execute() throws BuildException {
    if ("javadoc2".equals(taskType)) {
        log("!! javadoc2 is deprecated. Use javadoc instead. !!");
    }
    Vector packagesToDoc = new Vector();
    Path sourceDirs = new Path(getProject());
    if (packageList != null && sourcePath == null) {
        String msg = "sourcePath attribute must be set when " + "specifying packagelist.";
        throw new BuildException(msg);
    }
    if (sourcePath != null) {
        sourceDirs.addExisting(sourcePath);
    }
    parsePackages(packagesToDoc, sourceDirs);
    if (packagesToDoc.size() != 0 && sourceDirs.size() == 0) {
        String msg = "sourcePath attribute must be set when " + "specifying package names.";
        throw new BuildException(msg);
    }
    Vector sourceFilesToDoc = (Vector) sourceFiles.clone();
    addFileSets(sourceFilesToDoc);
    if (packageList == null && packagesToDoc.size() == 0 && sourceFilesToDoc.size() == 0) {
        throw new BuildException("No source files and no packages have " + "been specified.");
    }
    log("Generating Javadoc", Project.MSG_INFO);
    Commandline toExecute = (Commandline) cmd.clone();
    // ------------------------------------------ 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);
        }
    }
    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());
                }
            }
        }
        //                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;
                    toExecute.createArgument().setValue("-tag");
                    toExecute.createArgument().setValue(ta.getParameter());
                } 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);
            }
        }
    }
    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);
                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) {
                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 = 0;
        String[] arguments = toExecute.getArguments();
        for (int i = 0; i < arguments.length; i++) {
            String argument = arguments[i];
            System.out.println(i + ") " + argument);
        }
        // int ret =exe.execute();
        Main.main(arguments);
        if (ret != 0 && failOnError) {
            throw new BuildException("Javadoc returned " + ret, getLocation());
        }
    } finally {
        if (tmpList != null) {
            tmpList.delete();
            tmpList = null;
        }
        out.logFlush();
        err.logFlush();
        try {
            out.close();
            err.close();
        } catch (IOException e) {
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Commandline(org.apache.tools.ant.types.Commandline) Execute(org.apache.tools.ant.taskdefs.Execute) FileWriter(java.io.FileWriter) URL(java.net.URL) PumpStreamHandler(org.apache.tools.ant.taskdefs.PumpStreamHandler) Vector(java.util.Vector) PrintWriter(java.io.PrintWriter) Path(org.apache.tools.ant.types.Path) Enumeration(java.util.Enumeration) IOException(java.io.IOException) StringTokenizer(java.util.StringTokenizer) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 5 with Commandline

use of org.apache.tools.ant.types.Commandline in project ceylon-compiler by ceylon.

the class CeylonAntTask method buildCommandline.

/**
     * Builds the command line to be executed
     * @return the command line to be executed, 
     * or null if there is no command to be executed
     */
protected Commandline buildCommandline() {
    Commandline cmd = new Commandline();
    cmd.setExecutable(findExecutable());
    if (stacktraces) {
        appendOption(cmd, "--stacktraces");
    }
    if (getCwd() != null) {
        appendOption(cmd, "--cwd=" + getCwd());
    } else {
        appendOption(cmd, "--cwd=" + getProject().getBaseDir().getPath());
    }
    if (getConfig() != null) {
        appendOption(cmd, "--config=" + getConfig());
    }
    cmd.createArgument().setValue(toolName);
    completeCommandline(cmd);
    return cmd;
}
Also used : Commandline(org.apache.tools.ant.types.Commandline)

Aggregations

Commandline (org.apache.tools.ant.types.Commandline)6 File (java.io.File)3 Path (org.apache.tools.ant.types.Path)2 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Enumeration (java.util.Enumeration)1 StringTokenizer (java.util.StringTokenizer)1 Vector (java.util.Vector)1 BuildException (org.apache.tools.ant.BuildException)1 Execute (org.apache.tools.ant.taskdefs.Execute)1 PumpStreamHandler (org.apache.tools.ant.taskdefs.PumpStreamHandler)1 Argument (org.apache.tools.ant.types.Commandline.Argument)1