use of org.apache.tools.ant.BuildException in project bnd by bndtools.
the class RepoIndexTask method execute.
@Override
public void execute() throws BuildException {
printCopyright(System.err);
if (repositoryFile == null)
throw new BuildException("Output file not specified");
try {
// Configure PojoSR
Map<String, Object> pojoSrConfig = new HashMap<String, Object>();
pojoSrConfig.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, new ClasspathScanner());
// Start PojoSR 'framework'
Framework framework = new PojoServiceRegistryFactoryImpl().newFramework(pojoSrConfig);
framework.init();
framework.start();
if (knownBundles) {
registerKnownBundles(framework.getBundleContext());
}
// Look for indexer and run index generation
ServiceTracker<ResourceIndexer, ResourceIndexer> tracker = new ServiceTracker<ResourceIndexer, ResourceIndexer>(framework.getBundleContext(), ResourceIndexer.class, null);
tracker.open();
ResourceIndexer index = tracker.waitForService(1000);
if (index == null)
throw new IllegalStateException("Timed out waiting for ResourceIndexer service.");
// Flatten the file sets into a single list
Set<File> fileList = new LinkedHashSet<File>();
for (FileSet fileSet : fileSets) {
DirectoryScanner ds = fileSet.getDirectoryScanner(getProject());
File basedir = ds.getBasedir();
String[] files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++) fileList.add(new File(basedir, files[i]));
}
// Run
try (OutputStream fos = Files.newOutputStream(repositoryFile.toPath())) {
index.index(fileList, fos, config);
}
} catch (Exception e) {
throw new BuildException(e);
}
}
use of org.apache.tools.ant.BuildException in project bnd by bndtools.
the class BndTask method executeBackwardCompatible.
@SuppressWarnings("cast")
private void executeBackwardCompatible() throws BuildException {
try {
if (files == null)
throw new BuildException("No files set");
if (eclipse) {
File project = getProject().getBaseDir();
EclipseClasspath cp = new EclipseClasspath(this, project.getParentFile(), project);
classpath.addAll(cp.getClasspath());
classpath.addAll(cp.getBootclasspath());
sourcepath.addAll(cp.getSourcepath());
// classpath.add(cp.getOutput());
if (report())
throw new BuildException("Errors during Eclipse Path inspection");
}
if (output == null)
output = getProject().getBaseDir();
for (Iterator<File> f = files.iterator(); f.hasNext(); ) {
File file = f.next();
Builder builder = new Builder();
builder.setPedantic(isPedantic());
if (file.exists()) {
// Do nice property calculations
// merging includes etc.
builder.setProperties(file);
}
// properties, if the inherit flag is specified
if (inherit) {
Properties projectProperties = new UTF8Properties();
@SuppressWarnings("unchecked") Hashtable<Object, Object> antProps = getProject().getProperties();
projectProperties.putAll(antProps);
projectProperties.putAll(builder.getProperties());
builder.setProperties(projectProperties);
}
builder.setClasspath(toFiles(classpath, "classpath"));
builder.setSourcepath(toFiles(sourcepath, "sourcepath"));
Jar[] jars = builder.builds();
// Report both task failures and bnd build failures.
boolean taskFailed = report();
boolean bndFailed = report(builder);
// failed or the bnd build failed.
if (!failok && (taskFailed || bndFailed)) {
throw new BuildException("bnd failed", new org.apache.tools.ant.Location(file.getAbsolutePath()));
}
for (int i = 0; i < jars.length; i++) {
Jar jar = jars[i];
String bsn = jar.getName();
File base = file.getParentFile();
File output = this.output;
String path = builder.getProperty("-output");
if (output == null) {
if (path == null)
output = getFile(base, bsn + ".jar");
else {
output = getFile(base, path);
}
} else if (output.isDirectory()) {
if (path == null)
output = getFile(this.output, bsn + ".jar");
else
output = getFile(this.output, path);
} else if (output.isFile()) {
if (files.size() > 1)
messages.GotFileNeedDir_(output.getAbsoluteFile());
}
String msg = "";
if (!output.exists() || output.lastModified() <= jar.lastModified()) {
jar.write(output);
} else {
msg = "(not modified)";
}
logger.debug("{} ({}) {} {}", jar.getName(), output.getName(), jar.getResources().size(), msg);
report();
jar.close();
}
builder.close();
}
} catch (Exception e) {
// if (exceptions)
e.printStackTrace();
if (!failok)
throw new BuildException("Failed to build jar file: ", e);
}
}
use of org.apache.tools.ant.BuildException in project bnd by bndtools.
the class PrepareTask method execute.
@Override
public void execute() throws BuildException {
try {
if (basedir == null || !basedir.isDirectory())
throw new BuildException("The given base dir does not exist " + basedir);
Workspace workspace = Workspace.getWorkspace(basedir.getParentFile());
workspace.addBasicPlugin(new ConsoleProgress());
Project project = workspace.getProject(basedir.getName());
if (project == null)
throw new BuildException("Unable to find bnd project in directory: " + basedir);
project.setProperty("in.ant", "true");
project.setProperty("environment", "ant");
// top project.
if (top != null && top.length() > 0 && !top.startsWith("$"))
project.setProperty("top", top);
project.setExceptions(true);
Properties properties = project.getFlattenedProperties();
checkForTesting(project, properties);
if (report() || report(workspace) || report(project))
throw new BuildException("Errors during preparing bnd");
copyProperties(properties);
} catch (Exception e) {
e.printStackTrace();
throw new BuildException(e);
}
}
use of org.apache.tools.ant.BuildException in project bnd by bndtools.
the class ProjectBuildOrderTask method execute.
@Override
public void execute() throws BuildException {
try {
if (workspaceLocation == null) {
throw new BuildException("The given workspace dir is not set");
}
if (!workspaceLocation.isDirectory()) {
throw new BuildException("The given workspace dir not exist " + workspaceLocation);
}
if (projectLocation != null && bndFile == null) {
throw new BuildException("Attributes projectLocation and bndFile must be used together.");
}
Collection<Project> projects;
workspaceLocation = workspaceLocation.getCanonicalFile();
Workspace workspace = Workspace.getWorkspace(workspaceLocation);
if (projectLocation == null) {
// all projects in workspace
try {
for (Project project : workspace.getAllProjects()) {
project.setDelayRunDependencies(this.delayRunDependencies);
}
projects = workspace.getBuildOrder();
} catch (Exception e) {
throw new BuildException(e);
}
} else {
try (Project p = new Project(workspace, projectLocation, new File(projectLocation, bndFile))) {
p.setDelayRunDependencies(this.delayRunDependencies);
projects = p.getDependson();
}
}
StringBuilder sb = new StringBuilder();
String sep = "";
for (Project project : projects) {
sb.append(sep);
if (fullpath) {
sb.append(project.getBase().getAbsolutePath());
} else {
sb.append(project.getName());
}
sep = separator;
}
getProject().setProperty(propertyName, sb.toString());
} catch (Exception e) {
throw new BuildException(e);
}
}
use of org.apache.tools.ant.BuildException in project processdash by dtuma.
the class PatchXmlTask method execute.
@Override
public void execute() throws BuildException {
if (patchFile == null)
throw new BuildException("You must specify a patch file");
if (!patchFile.isFile())
throw new BuildException("The file '" + patchFile + "' does not exist");
if (!destDir.isDirectory())
throw new BuildException("The destDir '" + destDir + "' is not a directory");
DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
String[] srcFilenames = ds.getIncludedFiles();
if (srcFilenames.length == 0)
throw new BuildException("You must designate at least one input file.");
long patchFileDate = patchFile.lastModified();
Element patches;
try {
InputStream in = new BufferedInputStream(new FileInputStream(patchFile));
patches = XMLUtils.parse(in).getDocumentElement();
} catch (Exception e) {
throw new BuildException("Could not read '" + patchFile + "'", e);
}
if (patchId != null) {
patches = findElementById(patches, patchId);
if (patches == null)
throw new BuildException("The patch file '" + patchFile + "' does not contain a patch with the id '" + patchId + "'");
}
for (int j = 0; j < srcFilenames.length; j++) {
File inputFile = new File(ds.getBasedir(), srcFilenames[j]);
String baseFilename = inputFile.getName();
File outputFile = new File(destDir, baseFilename);
long inputDate = Math.max(inputFile.lastModified(), patchFileDate);
if (outputFile.lastModified() > inputDate) {
// file is already up-to-date
log("File '" + outputFile + "' is up-to-date", Project.MSG_VERBOSE);
continue;
}
Document document;
try {
document = JAXPUtils.getDocumentBuilder().parse(inputFile);
} catch (Exception e) {
throw new BuildException("Could not parse input file '" + inputFile + "'", e);
}
XmlPatch.apply(document, patches);
try {
// convert the modified document back into text
String docText = XMLUtils.getAsText(document);
// the top of the file
if (docText.indexOf("<html") != -1 && docText.startsWith("<?")) {
int dirEnd = docText.indexOf("?>");
docText = docText.substring(dirEnd + 2);
}
// write the file
OutputStream out = new BufferedOutputStream(new CleanupNewlines(new FileOutputStream(outputFile)));
out.write(docText.getBytes("UTF-8"));
out.close();
} catch (Exception e) {
throw new BuildException("Could not write to output file '" + outputFile + "'", e);
}
log("Wrote '" + outputFile + "'");
}
}
Aggregations