Search in sources :

Example 1 with JarFileResourceStore

use of org.apache.felix.ipojo.manipulator.store.JarFileResourceStore in project felix by apache.

the class Pojoization method pojoization.

/**
 * Manipulates an input bundle.
 * This method creates an iPOJO bundle based on the given metadata file.
 * The original and final bundles must be different.
 *
 * @param in           the original bundle.
 * @param out          the final bundle.
 * @param metadataFile the iPOJO metadata file (XML).
 * @param loader       the classloader used to compute the bytecode frames.
 */
public void pojoization(File in, File out, File metadataFile, ClassLoader loader) {
    MetadataProvider provider = new EmptyMetadataProvider();
    if (metadataFile != null) {
        FileMetadataProvider fileMetadataProvider = new FileMetadataProvider(metadataFile, m_reporter);
        fileMetadataProvider.setValidateUsingLocalSchemas(m_useLocalXSD);
        provider = fileMetadataProvider;
    }
    ResourceStore store;
    try {
        JarFile origin = new JarFile(in);
        JarFileResourceStore jfrs = new JarFileResourceStore(origin, out);
        jfrs.setClassLoader(loader);
        if (in.getName().endsWith(".war")) {
            // this is a war file, use the right mapper
            jfrs.setResourceMapper(new WABResourceMapper());
        }
        jfrs.setManifest(origin.getManifest());
        DefaultManifestBuilder dmb = new DefaultManifestBuilder();
        dmb.setMetadataRenderer(new MetadataRenderer());
        jfrs.setManifestBuilder(dmb);
        store = jfrs;
    } catch (IOException e) {
        m_reporter.error("The input file " + in.getAbsolutePath() + " is not a Jar file");
        return;
    }
    ManipulationVisitor visitor = createDefaultVisitorChain(store);
    pojoization(store, provider, visitor, loader);
}
Also used : MetadataRenderer(org.apache.felix.ipojo.manipulator.render.MetadataRenderer) JarFileResourceStore(org.apache.felix.ipojo.manipulator.store.JarFileResourceStore) DirectoryResourceStore(org.apache.felix.ipojo.manipulator.store.DirectoryResourceStore) JarFileResourceStore(org.apache.felix.ipojo.manipulator.store.JarFileResourceStore) WABResourceMapper(org.apache.felix.ipojo.manipulator.store.mapper.WABResourceMapper) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) DefaultManifestBuilder(org.apache.felix.ipojo.manipulator.store.builder.DefaultManifestBuilder)

Example 2 with JarFileResourceStore

use of org.apache.felix.ipojo.manipulator.store.JarFileResourceStore in project felix by apache.

the class Pojoization method pojoization.

/**
 * Manipulates an input bundle.
 * This method creates an iPOJO bundle based on the given metadata file.
 * The original and final bundles must be different.
 *
 * @param in       the original bundle.
 * @param out      the final bundle.
 * @param metadata the iPOJO metadata input stream.
 * @param loader   the classloader used to compute the bytecode frames.
 */
public void pojoization(File in, File out, InputStream metadata, ClassLoader loader) {
    StreamMetadataProvider provider = new StreamMetadataProvider(metadata, m_reporter);
    provider.setValidateUsingLocalSchemas(m_useLocalXSD);
    ResourceStore store;
    try {
        JarFile origin = new JarFile(in);
        JarFileResourceStore jfrs = new JarFileResourceStore(origin, out);
        jfrs.setClassLoader(loader);
        if (in.getName().endsWith(".war")) {
            // this is a war file, use the right mapper
            jfrs.setResourceMapper(new WABResourceMapper());
        }
        jfrs.setManifest(origin.getManifest());
        DefaultManifestBuilder dmb = new DefaultManifestBuilder();
        dmb.setMetadataRenderer(new MetadataRenderer());
        jfrs.setManifestBuilder(dmb);
        store = jfrs;
    } catch (IOException e) {
        m_reporter.error("The input file " + in.getAbsolutePath() + " is not a Jar file");
        return;
    }
    ManipulationVisitor visitor = createDefaultVisitorChain(store);
    pojoization(store, provider, visitor, loader);
}
Also used : MetadataRenderer(org.apache.felix.ipojo.manipulator.render.MetadataRenderer) JarFileResourceStore(org.apache.felix.ipojo.manipulator.store.JarFileResourceStore) DirectoryResourceStore(org.apache.felix.ipojo.manipulator.store.DirectoryResourceStore) JarFileResourceStore(org.apache.felix.ipojo.manipulator.store.JarFileResourceStore) WABResourceMapper(org.apache.felix.ipojo.manipulator.store.mapper.WABResourceMapper) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) DefaultManifestBuilder(org.apache.felix.ipojo.manipulator.store.builder.DefaultManifestBuilder)

Aggregations

IOException (java.io.IOException)2 JarFile (java.util.jar.JarFile)2 MetadataRenderer (org.apache.felix.ipojo.manipulator.render.MetadataRenderer)2 DirectoryResourceStore (org.apache.felix.ipojo.manipulator.store.DirectoryResourceStore)2 JarFileResourceStore (org.apache.felix.ipojo.manipulator.store.JarFileResourceStore)2 DefaultManifestBuilder (org.apache.felix.ipojo.manipulator.store.builder.DefaultManifestBuilder)2 WABResourceMapper (org.apache.felix.ipojo.manipulator.store.mapper.WABResourceMapper)2