Search in sources :

Example 26 with Resource

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);
}
Also used : Builder(aQute.bnd.osgi.Builder) JarResource(aQute.bnd.osgi.JarResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar)

Example 27 with Resource

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();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) JarResource(aQute.bnd.osgi.JarResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar)

Example 28 with Resource

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);
}
Also used : Builder(aQute.bnd.osgi.Builder) JarResource(aQute.bnd.osgi.JarResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar)

Example 29 with Resource

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;
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Resource(aQute.bnd.osgi.Resource) Clazz(aQute.bnd.osgi.Clazz) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef)

Example 30 with Resource

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);
}
Also used : SHA1(aQute.libg.cryptography.SHA1) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) Map(java.util.Map)

Aggregations

Resource (aQute.bnd.osgi.Resource)147 Jar (aQute.bnd.osgi.Jar)87 Builder (aQute.bnd.osgi.Builder)83 File (java.io.File)76 XmlTester (aQute.bnd.test.XmlTester)48 JarResource (aQute.bnd.osgi.JarResource)20 Attributes (java.util.jar.Attributes)20 Map (java.util.Map)19 Manifest (java.util.jar.Manifest)19 FileResource (aQute.bnd.osgi.FileResource)17 LogService (org.osgi.service.log.LogService)15 HashMap (java.util.HashMap)14 Document (org.w3c.dom.Document)14 Properties (java.util.Properties)12 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)11 DocumentBuilder (javax.xml.parsers.DocumentBuilder)11 InputStream (java.io.InputStream)9 Attrs (aQute.bnd.header.Attrs)8 ArrayList (java.util.ArrayList)8 TreeMap (java.util.TreeMap)8