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);
}
}
use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class MergeTest method testMerge.
static void testMerge(String type, String[] in, String[] out, String c, int errors, int warnings) throws Exception {
Builder b = new Builder();
try {
b.setClasspath(new File[] { IO.getFile("src/test/split/split-a.jar"), IO.getFile("src/test/split/split-b.jar") });
Properties p = new Properties();
if (type != null)
p.put("Export-Package", "test.split;-split-package:=" + type);
else
p.put("Export-Package", "test.split");
p.put("Import-Package", "");
b.setProperties(p);
Jar jar = b.build();
System.err.println("Errors :" + b.getErrors());
System.err.println("Warnings :" + b.getWarnings());
assertEquals(errors, b.getErrors().size());
assertEquals(warnings, b.getWarnings().size());
if (errors != 0)
return;
for (int i = 0; in != null && i < in.length; i++) assertNotNull("Contains " + in[i], jar.getResource("test/split/" + in[i]));
for (int i = 0; out != null && i < out.length; i++) assertNull("Does not contain " + out[i], jar.getResource("test/split/" + out[i]));
Resource r = jar.getResource("test/split/C");
InputStream is = r.openInputStream();
BufferedReader dis = new BufferedReader(new InputStreamReader(is));
String s = dis.readLine();
assertEquals(s, c);
} finally {
b.close();
}
}
use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class PluginTest method testMissingPluginNotUsed.
public void testMissingPluginNotUsed() throws Exception {
Builder p = new Builder();
p.setProperty("-plugin", "missing;command:=\"-abc,-def\"");
/* List<?> plugins = */
p.getPlugins(Object.class);
assertTrue(p.check());
p.setProperty("-abc", "whatever");
p.setProperty("-resourceonly", "true");
p.setProperty("Include-Resource", "jar/osgi.jar");
p.build();
assertEquals(1, p.getErrors().size());
assertTrue(p.getErrors().get(0).contains("Missing plugin"));
}
use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class PreprocessTest method testPreProcess.
/**
* Spaces at the end of a clause cause the preprocess to fail.
*
* @throws Exception
*/
public static void testPreProcess() throws Exception {
Properties base = new Properties();
base.put(Analyzer.INCLUDE_RESOURCE, "{src/test/top.mf} ");
Builder analyzer = new Builder();
analyzer.setProperties(base);
analyzer.build();
assertTrue(analyzer.check());
Jar jar = analyzer.getJar();
assertTrue(jar.getResource("top.mf") != null);
analyzer.close();
}
use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class PreprocessTest method testPreProcessExcludeExtensionGlobal.
/**
* Check if we can override
*
* @throws Exception
*/
public static void testPreProcessExcludeExtensionGlobal() throws Exception {
Builder b = new Builder();
b.setProperty(Analyzer.PREPROCESSMATCHERS, "!*.TXT:i,*");
b.setProperty(Analyzer.INCLUDE_RESOURCE, "{src/test/builder-preprocess.txt},{src/test/builder-preprocess.txt2}");
b.setProperty("var", "Yes!");
;
b.build();
assertTrue(b.check());
System.out.println("testPreProcessExcludeExtensionsGlobal");
Jar jar = b.getJar();
Resource resource = jar.getResource("builder-preprocess.txt");
String s = IO.collect(resource.openInputStream());
System.out.println(s);
assertTrue(s.contains("${var}"));
assertFalse(s.contains("!Yes"));
resource = jar.getResource("builder-preprocess.txt2");
s = IO.collect(resource.openInputStream());
System.out.println(s);
assertTrue(s.contains("Yes!"));
assertFalse(s.contains("${var}"));
b.close();
}
Aggregations