use of org.apache.tools.ant.types.Path in project felix by apache.
the class SCRDescriptorTask method setDestdir.
public void setDestdir(File outputDirectory) {
this.destdir = outputDirectory;
if (destdir != null) {
Path dst = new Path(getProject());
dst.setLocation(destdir);
createClasspath().add(dst);
}
}
use of org.apache.tools.ant.types.Path in project felix by apache.
the class IPojoTask method execute.
/**
* Execute the Ant Task.
*
* @see org.apache.tools.ant.Task#execute()
*/
public void execute() {
if (m_input == null && m_directory == null) {
throw new BuildException("Neither input bundle nor directory specified");
}
if (m_input != null && !m_input.exists()) {
throw new BuildException("The input bundle " + m_input.getAbsolutePath() + " does not exist");
}
if (m_directory != null && !m_directory.exists()) {
throw new BuildException("The input directory " + m_directory.getAbsolutePath() + " does not exist");
}
if (m_directory != null && !m_directory.isDirectory()) {
throw new BuildException("The input directory " + m_directory.getAbsolutePath() + " is not a directory");
}
if (m_input != null) {
log("Input bundle file : " + m_input.getAbsolutePath());
} else {
log("Input directory : " + m_directory.getAbsolutePath());
}
if (m_manifest != null) {
if (m_input != null) {
throw new BuildException("The manifest location cannot be used when manipulating an existing bundle");
}
if (!m_manifest.exists()) {
throw new BuildException("The manifest file " + m_manifest.getAbsolutePath() + " does not exist");
}
}
// Get metadata file
if (m_metadata == null) {
m_metadata = new File("./metadata.xml");
if (!m_metadata.exists()) {
// Verify if annotations are ignored
if (m_ignoreAnnotations) {
log("No metadata file found & annotations ignored : nothing to do");
return;
} else {
log("No metadata file found - trying to use only annotations");
m_metadata = null;
}
} else {
log("Metadata file : " + m_metadata.getAbsolutePath());
}
} else {
// Metadata file is specified, check existence
if (!m_metadata.exists()) {
throw new BuildException("No metadata file found - the file " + m_metadata.getAbsolutePath() + " does not exist");
} else {
if (m_metadata.isDirectory()) {
log("Metadata directory : " + m_metadata.getAbsolutePath());
} else {
log("Metadata file : " + m_metadata.getAbsolutePath());
}
}
}
initializeSaxDriver();
log("Start manipulation");
if (m_input != null) {
// Prepare output file
if (m_output == null) {
m_output = new File("./_out.jar");
}
if (m_output.exists()) {
boolean r = m_output.delete();
if (!r) {
throw new BuildException("The file " + m_output.getAbsolutePath() + " cannot be deleted");
}
}
}
AntReporter reporter = new AntReporter(getProject());
Pojoization pojo = new Pojoization(reporter);
if (m_ignoreAnnotations) {
pojo.disableAnnotationProcessing();
}
if (!m_ignoreLocalXSD) {
pojo.setUseLocalXSD();
}
Path classpath = getClasspath();
classpath.addJavaRuntime();
// Adding the input jar or directory
if (m_classpath == null) {
m_classpath = createClasspath();
}
Path element = m_classpath.createPath();
if (m_input != null) {
element.setLocation(m_input.getAbsoluteFile());
} else if (m_directory != null) {
element.setLocation(m_directory.getAbsoluteFile());
}
m_classpath.add(element);
ClassLoader loader = getProject().createClassLoader(getClasspath());
if (m_input != null) {
pojo.pojoization(m_input, m_output, m_metadata, loader);
} else {
pojo.directoryPojoization(m_directory, m_metadata, m_manifest, loader);
}
for (int i = 0; i < reporter.getWarnings().size(); i++) {
log((String) reporter.getWarnings().get(i), Project.MSG_WARN);
}
if (reporter.getErrors().size() > 0) {
throw new BuildException((String) reporter.getErrors().get(0));
}
if (m_input != null) {
String out;
if (m_output.getName().equals("_out.jar")) {
if (m_input.delete()) {
if (!m_output.renameTo(m_input)) {
log("Cannot rename the output jar to " + m_input.getAbsolutePath(), Project.MSG_WARN);
}
} else {
log("Cannot delete the input file : " + m_input.getAbsolutePath(), Project.MSG_WARN);
}
out = m_input.getAbsolutePath();
} else {
out = m_output.getAbsolutePath();
}
log("Bundle manipulation - SUCCESS");
log("Output file : " + out);
} else {
log("Manipulation - SUCCESS");
log("Output files : " + m_directory.getAbsolutePath());
if (m_manifest != null) {
log("Manifest : " + m_manifest.getAbsolutePath());
}
}
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class Javadoc method doJava14.
// Do java1.4 arguments
private void doJava14(final Commandline toExecute) {
for (final Object element : tags) {
if (element instanceof TagArgument) {
final TagArgument ta = (TagArgument) element;
final 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.
final DirectoryScanner tagDefScanner = ta.getDirectoryScanner(getProject());
for (String file : tagDefScanner.getIncludedFiles()) {
final File tagDefFile = new File(tagDir, file);
try (final BufferedReader in = new BufferedReader(new FileReader(tagDefFile))) {
String line;
while ((line = in.readLine()) != null) {
toExecute.createArgument().setValue("-tag");
toExecute.createArgument().setValue(line);
}
} catch (final IOException ioe) {
throw new BuildException("Couldn't read tag file from " + tagDefFile.getAbsolutePath(), ioe);
}
}
}
} else {
final ExtensionInfo tagletInfo = (ExtensionInfo) element;
toExecute.createArgument().setValue("-taglet");
toExecute.createArgument().setValue(tagletInfo.getName());
if (tagletInfo.getPath() != null) {
final Path tagletPath = tagletInfo.getPath().concatSystemClasspath("ignore");
if (!tagletPath.isEmpty()) {
toExecute.createArgument().setValue("-tagletpath");
toExecute.createArgument().setPath(tagletPath);
}
}
}
}
final String sourceArg = source != null ? source : getProject().getProperty(MagicNames.BUILD_JAVAC_SOURCE);
if (sourceArg != null) {
toExecute.createArgument().setValue("-source");
toExecute.createArgument().setValue(sourceArg);
}
if (linksource && doclet == null) {
toExecute.createArgument().setValue("-linksource");
}
if (noqualifier != null && doclet == null) {
toExecute.createArgument().setValue("-noqualifier");
toExecute.createArgument().setValue(noqualifier);
}
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class Javadoc method doDoclet.
private void doDoclet(final Commandline toExecute) {
if (doclet != null) {
if (doclet.getName() == null) {
throw new BuildException("The doclet name must be specified.", getLocation());
}
toExecute.createArgument().setValue("-doclet");
toExecute.createArgument().setValue(doclet.getName());
if (doclet.getPath() != null) {
final Path docletPath = doclet.getPath().concatSystemClasspath("ignore");
if (docletPath.size() != 0) {
toExecute.createArgument().setValue("-docletpath");
toExecute.createArgument().setPath(docletPath);
}
}
for (final DocletParam param : Collections.list(doclet.getParams())) {
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());
}
}
}
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class Javadoc method parsePackages.
/**
* Add the directories matched by the nested dirsets to the Vector
* and the base directories of the dirsets to the Path. It also
* handles the packages and excludepackages attributes and
* elements.
*
* @since 1.5
*/
private void parsePackages(final List<String> pn, final Path sp) {
final Set<String> addedPackages = new HashSet<>();
final List<DirSet> dirSets = new ArrayList<>(packageSets);
// and nested excludepackage elements
if (sourcePath != null) {
final PatternSet ps = new PatternSet();
ps.setProject(getProject());
if (packageNames.isEmpty()) {
ps.createInclude().setName("**");
} else {
packageNames.stream().map(PackageName::getName).map(s -> s.replace('.', '/').replaceFirst("\\*$", "**")).forEach(pkg -> ps.createInclude().setName(pkg));
}
excludePackageNames.stream().map(PackageName::getName).map(s -> s.replace('.', '/').replaceFirst("\\*$", "**")).forEach(pkg -> ps.createExclude().setName(pkg));
for (String pathElement : sourcePath.list()) {
final File dir = new File(pathElement);
if (dir.isDirectory()) {
final DirSet ds = new DirSet();
ds.setProject(getProject());
ds.setDefaultexcludes(useDefaultExcludes);
ds.setDir(dir);
ds.createPatternSet().addConfiguredPatternset(ps);
dirSets.add(ds);
} else {
log("Skipping " + pathElement + " since it is no directory.", Project.MSG_WARN);
}
}
}
for (DirSet ds : dirSets) {
final File baseDir = ds.getDir(getProject());
log("scanning " + baseDir + " for packages.", Project.MSG_DEBUG);
final DirectoryScanner dsc = ds.getDirectoryScanner(getProject());
boolean containsPackages = false;
for (String dir : dsc.getIncludedDirectories()) {
// are there any java files in this directory?
final File pd = new File(baseDir, dir);
final String[] files = pd.list((directory, name) -> name.endsWith(".java") || (includeNoSourcePackages && name.equals("package.html")));
if (files.length > 0) {
if ("".equals(dir)) {
log(baseDir + " contains source files in the default package, you must specify them as source files not packages.", Project.MSG_WARN);
} else {
containsPackages = true;
final String packageName = dir.replace(File.separatorChar, '.');
if (!addedPackages.contains(packageName)) {
addedPackages.add(packageName);
pn.add(packageName);
}
}
}
}
if (containsPackages) {
// We don't need to care for duplicates here,
// Path.list does it for us.
sp.createPathElement().setLocation(baseDir);
} else {
log(baseDir + " doesn\'t contain any packages, dropping it.", Project.MSG_VERBOSE);
}
}
}
Aggregations