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();
}
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);
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations