use of org.apache.felix.ipojo.manipulator.store.DirectoryResourceStore 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);
}
Aggregations