marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(repo, obrFile);
}
public static Repository generateOBRModel(String obrName, org.apache.geronimo.kernel.repository.Repository geronimoRepository, Set<Artifact> artifacts) throws IOException {
Repository repo = new Repository();
repo.setName(obrName);
for (Artifact artifact : artifacts) {
File location = geronimoRepository.getLocation(artifact);
if (LOG.isDebugEnabled()) {
LOG.debug("Generating OBR Metadata for " + location.getAbsolutePath());
}
Manifest mf = null;
if (location.isFile()) {
JarFile file = new JarFile(location);
try {
mf = file.getManifest();
} finally {
try { file.close(); } catch (IOException ignore) {}
}
} else if (location.isDirectory()) {
File mfFile = new File(location, JarFile.MANIFEST_NAME);
FileInputStream in = new FileInputStream(mfFile);
try {
mf = new Manifest(in);
} finally {
try { in.close(); } catch (IOException ignore) {}
}
} else {
continue;
}
if (mf == null) {
continue;
}
BundleDescription desc = new BundleDescription(mf);
ResourceBuilder builder = new ResourceBuilder(desc);
Resource resource = null;
try {
resource = builder.createResource();
} catch (RuntimeException e) {
LOG.debug("Failed to generate OBR information for " + artifact + " artifact", e);
continue;
}
if (resource != null) {
resource.setUri(getURL(artifact));
if (location.isFile()) {
resource.setSize(location.length());
}
repo.getResource().add(resource);
} else {
LOG.debug("Did not generate OBR information for {} artifact. It is not a bundle.", artifact);
}
}
return repo;