use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class ResourcesTest method testOnTheFlyMerge.
/**
* Test the Include-Resource facility to generate resources on the fly. This
* is a a case where multiple resources and up in a single combined
* resource.
*/
public static void testOnTheFlyMerge() throws Exception {
if (!onWindows()) {
Builder b = new Builder();
b.setIncludeResource("count;for='1,2,3';cmd='echo YES_${@}'");
b.setProperty("-resourceonly", "true");
Jar jar = b.build();
assertTrue(b.check());
Resource r = jar.getResource("count");
assertNotNull(r);
String s = IO.collect(r.openInputStream());
assertEquals("YES_1\nYES_2\nYES_3\n", s);
b.close();
}
}
use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class ResourcesTest method testIncludeResourceDirectivesFilterRecursiveFlatten.
public static void testIncludeResourceDirectivesFilterRecursiveFlatten() throws Exception {
Builder b = new Builder();
b.setProperty("Include-Resource", "TargetFolder=testresources/ws/p2/Resources;filter:=re*.txt;flatten:=true");
b.setProperty("-resourceonly", "true");
Jar jar = b.build();
Resource r = jar.getResource("TargetFolder/resource3.txt");
assertNotNull(r);
r = jar.getResource("TargetFolder/resource4.txt");
assertNotNull(r);
r = jar.getResource("TargetFolder/resource6.txt");
assertNotNull(r);
r = jar.getResource("TargetFolder/resource7.txt");
assertNotNull(r);
r = jar.getResource("TargetFolder/resource1.res");
assertNull(r);
}
use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class ResourcesTest method testOnTheFlySingleError.
/**
* Test the Include-Resource facility to generate resources on the fly. This
* is a simple case of one resource with an error.
*/
public static void testOnTheFlySingleError() throws Exception {
if (onWindows())
return;
Builder b = new Builder();
b.setIncludeResource("testresources/x;cmd='I do not exist!!!!!!!!!!!'");
b.setProperty("-resourceonly", "true");
Jar jar = b.build();
assertTrue(b.check("Cmd 'I do not exist!!!!!!!!!!!' failed"));
b.close();
}
use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class Profiles method _create.
public void _create(CreateOptions options) throws Exception {
Builder b = new Builder();
bnd.addClose(b);
b.setBase(bnd.getBase());
if (options.properties() != null) {
for (String propertyFile : options.properties()) {
File pf = bnd.getFile(propertyFile);
b.addProperties(pf);
}
}
if (options.bsn() != null)
b.setProperty(Constants.BUNDLE_SYMBOLICNAME, options.bsn());
if (options.version() != null)
b.setProperty(Constants.BUNDLE_VERSION, options.version().toString());
Instructions match = options.match();
Parameters packages = new Parameters();
Parameters capabilities = new Parameters();
Collection<String> paths = new ArrayList<String>(new Parameters(b.getProperty("-paths"), bnd).keySet());
if (paths.isEmpty())
paths = options._arguments();
logger.debug("input {}", paths);
ResourceBuilder pb = new ResourceBuilder();
for (String root : paths) {
File f = bnd.getFile(root);
if (!f.exists()) {
error("could not find %s", f);
} else {
Glob g = options.extension();
if (g == null)
g = new Glob("*.jar");
Collection<File> files = IO.tree(f, "*.jar");
logger.debug("will profile {}", files);
for (File file : files) {
Domain domain = Domain.domain(file);
if (domain == null) {
error("Not a bundle because no manifest %s", file);
continue;
}
String bsn = domain.getBundleSymbolicName().getKey();
if (bsn == null) {
error("Not a bundle because no manifest %s", file);
continue;
}
if (match != null) {
Instruction instr = match.finder(bsn);
if (instr == null || instr.isNegated()) {
logger.debug("skipped {} because of non matching bsn {}", file, bsn);
continue;
}
}
Parameters eps = domain.getExportPackage();
Parameters pcs = domain.getProvideCapability();
logger.debug("parse {}:\ncaps: {}\npac: {}\n", file, pcs, eps);
packages.mergeWith(eps, false);
capabilities.mergeWith(pcs, false);
}
}
}
b.setProperty(Constants.PROVIDE_CAPABILITY, capabilities.toString());
b.setProperty(Constants.EXPORT_PACKAGE, packages.toString());
logger.debug("Found {} packages and {} capabilities", packages.size(), capabilities.size());
Jar jar = b.build();
File f = b.getOutputFile(options.output());
logger.debug("Saving as {}", f);
jar.write(f);
}
use of aQute.bnd.osgi.Builder 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);
}
}
Aggregations