use of aQute.bnd.osgi.Resource in project bnd by bndtools.
the class ResourcesTest method testIncludeResourceDirectivesFilterRecursive.
public static void testIncludeResourceDirectivesFilterRecursive() throws Exception {
Builder b = new Builder();
b.setProperty("Include-Resource", "TargetFolder=testresources/ws/p2/Resources;filter:=re*.txt");
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/more/resource6.txt");
assertNotNull(r);
r = jar.getResource("TargetFolder/more/resource7.txt");
assertNotNull(r);
r = jar.getResource("TargetFolder/text.txt");
assertNull(r);
}
use of aQute.bnd.osgi.Resource 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.Resource 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.Resource in project bnd by bndtools.
the class DiffPluginImpl method hasSource.
private boolean hasSource(Analyzer analyzer, String path) throws Exception {
if (!path.endsWith(".class"))
return false;
TypeRef type = analyzer.getTypeRefFromPath(path);
PackageRef packageRef = type.getPackageRef();
Clazz clazz = analyzer.findClass(type);
if (clazz == null)
return false;
String sourceFile = clazz.getSourceFile();
if (sourceFile == null)
return false;
String source = "OSGI-OPT/src/" + packageRef.getBinary() + "/" + sourceFile;
Resource sourceResource = analyzer.getJar().getResource(source);
if (sourceResource == null)
return false;
return true;
}
use of aQute.bnd.osgi.Resource in project bnd by bndtools.
the class DiffPluginImpl method resourcesElement.
private Element resourcesElement(Analyzer analyzer) throws Exception {
Jar jar = analyzer.getJar();
List<Element> resources = new ArrayList<Element>();
for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) {
if (META_INF_P.matcher(entry.getKey()).matches())
continue;
if (localIgnore != null && localIgnore.matches(entry.getKey()))
continue;
//
// #794 Use sources for shas of classes in baselining
// Since the compilers generate different bytecodes the
// resource comparison by sha is very awkward for classes.
// This code will not create an element for classes if a
// directory with source code can be found.
//
String path = entry.getKey();
if (path.endsWith(Constants.EMPTY_HEADER))
continue;
if (analyzer.since(About._3_0)) {
if (hasSource(analyzer, path))
continue;
}
Resource resource = entry.getValue();
try (InputStream in = resource.openInputStream()) {
Digester<SHA1> digester = SHA1.getDigester();
IO.copy(in, digester);
String value = Hex.toHexString(digester.digest().digest());
resources.add(new Element(Type.RESOURCE, entry.getKey(), Arrays.asList(new Element(Type.SHA, value)), CHANGED, CHANGED, null));
}
}
return new Element(Type.RESOURCES, "<resources>", resources, CHANGED, CHANGED, null);
}
Aggregations