Search in sources :

Example 26 with Path

use of org.apache.tools.ant.types.Path in project ant by apache.

the class AbstractClasspathResource method createClasspath.

/**
 * Add a classpath to use when looking up a resource.
 * @return The classpath to be configured
 */
public Path createClasspath() {
    checkChildrenAllowed();
    if (classpath == null) {
        classpath = new Path(getProject());
    }
    setChecked(false);
    return classpath.createPath();
}
Also used : Path(org.apache.tools.ant.types.Path)

Example 27 with Path

use of org.apache.tools.ant.types.Path in project ant by apache.

the class AbstractClasspathResource method getClassLoader.

/**
 * combines the various ways that could specify a ClassLoader and
 * potentially creates one that needs to be cleaned up when it is
 * no longer needed so that classes can get garbage collected.
 *
 * @return ClassLoaderWithFlag
 */
protected ClassLoaderWithFlag getClassLoader() {
    ClassLoader cl = null;
    if (loader != null) {
        cl = (ClassLoader) loader.getReferencedObject();
    }
    boolean clNeedsCleanup = false;
    if (cl == null) {
        if (getClasspath() != null) {
            Path p = getClasspath().concatSystemClasspath("ignore");
            if (parentFirst) {
                cl = getProject().createClassLoader(p);
            } else {
                cl = AntClassLoader.newAntClassLoader(getProject().getCoreLoader(), getProject(), p, false);
            }
            clNeedsCleanup = loader == null;
        } else {
            cl = JavaResource.class.getClassLoader();
        }
        if (loader != null && cl != null) {
            getProject().addReference(loader.getRefId(), cl);
        }
    }
    return new ClassLoaderWithFlag(cl, clNeedsCleanup);
}
Also used : Path(org.apache.tools.ant.types.Path) AntClassLoader(org.apache.tools.ant.AntClassLoader)

Example 28 with Path

use of org.apache.tools.ant.types.Path in project ant by apache.

the class DependScanner method scan.

/**
 * Scans the base directory for files on which baseClass depends.
 *
 * @exception IllegalStateException when basedir was set incorrectly.
 */
@Override
public synchronized void scan() throws IllegalStateException {
    included = new Vector<>();
    String analyzerClassName = DEFAULT_ANALYZER_CLASS;
    DependencyAnalyzer analyzer;
    try {
        Class<? extends DependencyAnalyzer> analyzerClass = Class.forName(analyzerClassName).asSubclass(DependencyAnalyzer.class);
        analyzer = analyzerClass.newInstance();
    } catch (Exception e) {
        throw new BuildException("Unable to load dependency analyzer: " + analyzerClassName, e);
    }
    analyzer.addClassPath(new Path(null, basedir.getPath()));
    additionalBaseDirs.stream().map(File::getPath).map(p -> new Path(null, p)).forEach(analyzer::addClassPath);
    rootClasses.forEach(analyzer::addRootClass);
    Set<String> parentSet = Stream.of(parentScanner.getIncludedFiles()).collect(Collectors.toSet());
    Enumeration<String> e = analyzer.getClassDependencies();
    while (e.hasMoreElements()) {
        String classname = e.nextElement();
        String filename = classname.replace('.', File.separatorChar) + ".class";
        File depFile = new File(basedir, filename);
        if (depFile.exists() && parentSet.contains(filename)) {
            // This is included
            included.addElement(filename);
        }
    }
}
Also used : Path(org.apache.tools.ant.types.Path) Vector(java.util.Vector) Stream(java.util.stream.Stream) Enumeration(java.util.Enumeration) Set(java.util.Set) BuildException(org.apache.tools.ant.BuildException) DependencyAnalyzer(org.apache.tools.ant.util.depend.DependencyAnalyzer) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Collectors(java.util.stream.Collectors) File(java.io.File) Path(org.apache.tools.ant.types.Path) DependencyAnalyzer(org.apache.tools.ant.util.depend.DependencyAnalyzer) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BuildException(org.apache.tools.ant.BuildException)

Example 29 with Path

use of org.apache.tools.ant.types.Path in project ant by apache.

the class Javadoc method doBootPath.

private void doBootPath(final Commandline toExecute) {
    Path bcp = new Path(getProject());
    if (bootclasspath != null) {
        bcp.append(bootclasspath);
    }
    bcp = bcp.concatSystemBootClasspath("ignore");
    if (bcp.size() > 0) {
        toExecute.createArgument().setValue("-bootclasspath");
        toExecute.createArgument().setPath(bcp);
    }
}
Also used : Path(org.apache.tools.ant.types.Path)

Example 30 with Path

use of org.apache.tools.ant.types.Path in project ant by apache.

the class Javadoc method execute.

/**
 * Execute the task.
 * @throws BuildException on error
 */
@Override
public void execute() throws BuildException {
    checkTaskName();
    final List<String> packagesToDoc = new Vector<>();
    final Path sourceDirs = new Path(getProject());
    checkPackageAndSourcePath();
    if (sourcePath != null) {
        sourceDirs.addExisting(sourcePath);
    }
    parsePackages(packagesToDoc, sourceDirs);
    checkPackages(packagesToDoc, sourceDirs);
    final List<SourceFile> sourceFilesToDoc = new ArrayList<>(sourceFiles);
    addSourceFiles(sourceFilesToDoc);
    checkPackagesToDoc(packagesToDoc, sourceFilesToDoc);
    log("Generating Javadoc", Project.MSG_INFO);
    final Commandline toExecute = (Commandline) cmd.clone();
    if (executable != null) {
        toExecute.setExecutable(executable);
    } else {
        toExecute.setExecutable(JavaEnvUtils.getJdkExecutable("javadoc"));
    }
    // Javadoc arguments
    // general Javadoc arguments
    generalJavadocArguments(toExecute);
    // sourcepath
    doSourcePath(toExecute, sourceDirs);
    // arguments for default doclet
    doDoclet(toExecute);
    // bootpath
    doBootPath(toExecute);
    // links arguments
    doLinks(toExecute);
    // group attribute
    doGroup(toExecute);
    // groups attribute
    doGroups(toExecute);
    // docfilessubdir attribute
    doDocFilesSubDirs(toExecute);
    doJava14(toExecute);
    if (breakiterator && (doclet == null || JAVADOC_5)) {
        toExecute.createArgument().setValue("-breakiterator");
    }
    // If using an external file, write the command line options to it
    if (useExternalFile) {
        writeExternalArgs(toExecute);
    }
    File tmpList = null;
    FileWriter wr = null;
    try {
        /**
         * Write sourcefiles and package names to a temporary file
         * if requested.
         */
        BufferedWriter srcListWriter = null;
        if (useExternalFile) {
            tmpList = FILE_UTILS.createTempFile("javadoc", "", null, true, true);
            toExecute.createArgument().setValue("@" + tmpList.getAbsolutePath());
            wr = new FileWriter(tmpList.getAbsolutePath(), true);
            srcListWriter = new BufferedWriter(wr);
        }
        doSourceAndPackageNames(toExecute, packagesToDoc, sourceFilesToDoc, useExternalFile, tmpList, srcListWriter);
        if (useExternalFile) {
            // NOSONAR
            srcListWriter.flush();
        }
    } catch (final IOException e) {
        if (tmpList != null) {
            tmpList.delete();
        }
        throw new BuildException("Error creating temporary file", e, getLocation());
    } finally {
        FileUtils.close(wr);
    }
    if (packageList != null) {
        toExecute.createArgument().setValue("@" + packageList);
    }
    log(toExecute.describeCommand(), Project.MSG_VERBOSE);
    log("Javadoc execution", Project.MSG_INFO);
    final JavadocOutputStream out = new JavadocOutputStream(Project.MSG_INFO);
    final JavadocOutputStream err = new JavadocOutputStream(Project.MSG_WARN);
    final 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());
        final int ret = exe.execute();
        if (ret != 0 && failOnError) {
            throw new BuildException("Javadoc returned " + ret, getLocation());
        }
        if (out.sawWarnings() && failOnWarning) {
            throw new BuildException("Javadoc issued warnings.", getLocation());
        }
        postProcessGeneratedJavadocs();
    } catch (final IOException e) {
        throw new BuildException("Javadoc failed: " + e, e, getLocation());
    } finally {
        if (tmpList != null) {
            tmpList.delete();
            tmpList = null;
        }
        out.logFlush();
        err.logFlush();
        FileUtils.close(out);
        FileUtils.close(err);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) Commandline(org.apache.tools.ant.types.Commandline) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) BuildException(org.apache.tools.ant.BuildException) Vector(java.util.Vector) File(java.io.File)

Aggregations

Path (org.apache.tools.ant.types.Path)174 File (java.io.File)78 BuildException (org.apache.tools.ant.BuildException)55 Test (org.junit.Test)49 Project (org.apache.tools.ant.Project)28 IOException (java.io.IOException)24 Commandline (org.apache.tools.ant.types.Commandline)21 ArrayList (java.util.ArrayList)12 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)10 URL (java.net.URL)8 AntClassLoader (org.apache.tools.ant.AntClassLoader)7 Java (org.apache.tools.ant.taskdefs.Java)7 StringTokenizer (java.util.StringTokenizer)6 FileSet (org.apache.tools.ant.types.FileSet)6 Reference (org.apache.tools.ant.types.Reference)6 Resource (org.apache.tools.ant.types.Resource)6 Test (org.junit.jupiter.api.Test)6 GroovyClassLoader (groovy.lang.GroovyClassLoader)5 Enumeration (java.util.Enumeration)5 Vector (java.util.Vector)5