Search in sources :

Example 1 with DefaultManifestBuilder

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

the class DefaultManifestBuilderTestCase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    attributes.putValue("Import-Package", ORG_OSGI_FRAMEWORK_VERSION_1_5);
    attributes.putValue("Created-By", "TestCase");
    builder = new DefaultManifestBuilder();
    builder.addReferredPackage(Collections.singleton("org.osgi.service.http"));
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) DefaultManifestBuilder(org.apache.felix.ipojo.manipulator.store.builder.DefaultManifestBuilder)

Example 2 with DefaultManifestBuilder

use of org.apache.felix.ipojo.manipulator.store.builder.DefaultManifestBuilder 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 3 with DefaultManifestBuilder

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

the class Pojoization method directoryPojoization.

/**
 * Manipulates an expanded bundles.
 * Classes are in the specified directory.
 * this method allows to update a customized manifest.
 *
 * @param directory    the directory containing classes
 * @param metadataFile the metadata file
 * @param manifestFile the manifest file. <code>null</code> to use directory/META-INF/MANIFEST.mf
 * @param loader       the classloader used to compute the bytecode frames.
 */
public void directoryPojoization(File directory, File metadataFile, File manifestFile, ClassLoader loader) {
    // Get the metadata.xml location if not null
    MetadataProvider provider = new EmptyMetadataProvider();
    if (metadataFile != null) {
        FileMetadataProvider fileMetadataProvider = new FileMetadataProvider(metadataFile, m_reporter);
        fileMetadataProvider.setValidateUsingLocalSchemas(m_useLocalXSD);
        provider = fileMetadataProvider;
    }
    ManifestProvider manifestProvider;
    File selectedManifestFile;
    if (manifestFile != null) {
        if (manifestFile.isFile()) {
            try {
                manifestProvider = new FileManifestProvider(manifestFile);
                selectedManifestFile = manifestFile;
            } catch (IOException e) {
                m_reporter.error("Cannot read Manifest from '" + manifestFile.getAbsolutePath() + "'");
                return;
            }
        } else {
            m_reporter.error("The manifest file " + manifestFile.getAbsolutePath() + " does not exist");
            return;
        }
    } else {
        // If the manifest is not specified, the m_dir/META-INF/MANIFEST.MF is used.
        File metaInf = new File(directory, "META-INF");
        File original = new File(metaInf, "MANIFEST.MF");
        if (original.isFile()) {
            try {
                manifestProvider = new FileManifestProvider(original);
                selectedManifestFile = original;
            } catch (IOException e) {
                m_reporter.error("Cannot read Manifest from '" + original.getAbsolutePath() + "'");
                return;
            }
        } else {
            m_reporter.error("The manifest file " + original.getAbsolutePath() + " does not exist");
            return;
        }
    }
    DirectoryResourceStore store;
    if (directory.exists() && directory.isDirectory()) {
        store = new DirectoryResourceStore(directory);
        File webinf = new File(directory, "WEB-INF");
        if (directory.getName().endsWith(".war") || webinf.isDirectory()) {
            // this is a war file, use the right mapper
            store.setResourceMapper(new WABResourceMapper());
        }
        store.setManifest(manifestProvider.getManifest());
        store.setManifestFile(selectedManifestFile);
        DefaultManifestBuilder dmb = new DefaultManifestBuilder();
        dmb.setMetadataRenderer(new MetadataRenderer());
        store.setManifestBuilder(dmb);
    } else {
        m_reporter.error("The directory " + directory.getAbsolutePath() + " does not exist or is not a directory.");
        return;
    }
    ManipulationVisitor visitor = createDefaultVisitorChain(store);
    pojoization(store, provider, visitor, loader);
}
Also used : MetadataRenderer(org.apache.felix.ipojo.manipulator.render.MetadataRenderer) DirectoryResourceStore(org.apache.felix.ipojo.manipulator.store.DirectoryResourceStore) IOException(java.io.IOException) WABResourceMapper(org.apache.felix.ipojo.manipulator.store.mapper.WABResourceMapper) FileManifestProvider(org.apache.felix.ipojo.manipulator.manifest.FileManifestProvider) JarFile(java.util.jar.JarFile) File(java.io.File) FileManifestProvider(org.apache.felix.ipojo.manipulator.manifest.FileManifestProvider) DefaultManifestBuilder(org.apache.felix.ipojo.manipulator.store.builder.DefaultManifestBuilder)

Example 4 with DefaultManifestBuilder

use of org.apache.felix.ipojo.manipulator.store.builder.DefaultManifestBuilder 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

DefaultManifestBuilder (org.apache.felix.ipojo.manipulator.store.builder.DefaultManifestBuilder)4 IOException (java.io.IOException)3 JarFile (java.util.jar.JarFile)3 MetadataRenderer (org.apache.felix.ipojo.manipulator.render.MetadataRenderer)3 DirectoryResourceStore (org.apache.felix.ipojo.manipulator.store.DirectoryResourceStore)3 WABResourceMapper (org.apache.felix.ipojo.manipulator.store.mapper.WABResourceMapper)3 JarFileResourceStore (org.apache.felix.ipojo.manipulator.store.JarFileResourceStore)2 File (java.io.File)1 Attributes (java.util.jar.Attributes)1 Manifest (java.util.jar.Manifest)1 FileManifestProvider (org.apache.felix.ipojo.manipulator.manifest.FileManifestProvider)1