use of aQute.bnd.osgi.Resource in project bndtools by bndtools.
the class Printer method printComponents.
/**
* Print the components in this JAR.
*
* @param jar
*/
private void printComponents(Jar jar) throws Exception {
out.println("[COMPONENTS]");
Manifest manifest = jar.getManifest();
if (manifest == null) {
out.println("No manifest");
return;
}
String componentHeader = manifest.getMainAttributes().getValue(Constants.SERVICE_COMPONENT);
Parameters clauses = new Parameters(componentHeader);
boolean printed = false;
for (String path : clauses.keySet()) {
printed = true;
out.println(path);
Resource r = jar.getResource(path);
if (r != null) {
IO.copy(IO.reader(r.openInputStream(), Constants.DEFAULT_CHARSET), or);
} else {
out.println(" - no resource");
warning("No Resource found for service component: " + path);
}
}
if (printed) {
out.println();
}
}
use of aQute.bnd.osgi.Resource in project bndtools by bndtools.
the class PackageListWizardPage method setVisible.
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
if (!loaded) {
try {
getContainer().run(false, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
availablePackages.clear();
selectedPackages.clear();
for (IPath path : paths) {
Jar jar = null;
try {
if (path.isAbsolute())
jar = new Jar(path.toFile());
else
jar = new Jar(ResourcesPlugin.getWorkspace().getRoot().getLocation().append(path).toFile());
Map<String, Map<String, Resource>> dirs = jar.getDirectories();
for (Entry<String, Map<String, Resource>> entry : dirs.entrySet()) {
if (entry.getValue() == null)
continue;
IPath packagePath = new Path(entry.getKey());
if (packagePath.segmentCount() < 1)
continue;
if ("META-INF".equalsIgnoreCase(packagePath.segment(0)))
continue;
availablePackages.add(packagePath);
}
} catch (Exception e) {
} finally {
if (jar != null)
jar.close();
}
}
}
});
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
loaded = true;
}
availableViewer.setInput(availablePackages);
selectedViewer.setInput(selectedPackages);
}
updateUI();
}
use of aQute.bnd.osgi.Resource in project bnd by bndtools.
the class SubsystemExporter method export.
@Override
public Map.Entry<String, Resource> export(String type, final Project project, Map<String, String> options) throws Exception {
Jar jar = new Jar(".");
project.addClose(jar);
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
manifest.getMainAttributes().putValue("Subsystem-ManifestVersion", "1");
List<File> files = new ArrayList<File>();
for (Container c : project.getRunbundles()) {
switch(c.getType()) {
case ERROR:
// skip, already reported
break;
case PROJECT:
case EXTERNAL:
case REPO:
files.add(c.getFile());
break;
case LIBRARY:
c.contributeFiles(files, project);
break;
}
}
for (File file : files) {
Domain domain = Domain.domain(file);
String bsn = domain.getBundleSymbolicName().getKey();
String version = domain.getBundleVersion();
String path = bsn + "-" + version + ".jar";
jar.putResource(path, new FileResource(file));
}
headers(project, manifest.getMainAttributes());
set(manifest.getMainAttributes(), SUBSYSTEM_TYPE, OSGI_SUBSYSTEM_FEATURE);
String ssn = project.getName();
Collection<String> bsns = project.getBsns();
if (bsns.size() > 0) {
ssn = bsns.iterator().next();
}
set(manifest.getMainAttributes(), SUBSYSTEM_SYMBOLIC_NAME, ssn);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
manifest.write(bout);
jar.putResource(OSGI_INF_SUBSYSTEM_MF, new EmbeddedResource(bout.toByteArray(), 0));
final JarResource jarResource = new JarResource(jar);
final String name = ssn + ".esa";
return new Map.Entry<String, Resource>() {
@Override
public String getKey() {
return name;
}
@Override
public Resource getValue() {
return jarResource;
}
@Override
public Resource setValue(Resource arg0) {
throw new UnsupportedOperationException();
}
};
}
use of aQute.bnd.osgi.Resource in project bnd by bndtools.
the class BndMavenPlugin method expandJar.
private void expandJar(Jar jar, File dir) throws Exception {
final long lastModified = jar.lastModified();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Bundle lastModified: %tF %<tT.%<tL", lastModified));
}
dir = dir.getAbsoluteFile();
Files.createDirectories(dir.toPath());
for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) {
File outFile = getFile(dir, entry.getKey());
Resource resource = entry.getValue();
// Skip the copy if the source and target are the same file
if (resource instanceof FileResource) {
@SuppressWarnings("resource") FileResource fr = (FileResource) resource;
if (outFile.equals(fr.getFile())) {
continue;
}
}
if (!outFile.exists() || outFile.lastModified() < lastModified) {
if (logger.isDebugEnabled()) {
if (outFile.exists())
logger.debug(String.format("Updating lastModified: %tF %<tT.%<tL '%s'", outFile.lastModified(), outFile));
else
logger.debug("Creating '{}'", outFile);
}
Files.createDirectories(outFile.toPath().getParent());
try (OutputStream out = buildContext.newFileOutputStream(outFile)) {
IO.copy(resource.openInputStream(), out);
}
}
}
if (manifestOutOfDate() || manifestPath.lastModified() < lastModified) {
if (logger.isDebugEnabled()) {
if (!manifestOutOfDate())
logger.debug(String.format("Updating lastModified: %tF %<tT.%<tL '%s'", manifestPath.lastModified(), manifestPath));
else
logger.debug("Creating '{}'", manifestPath);
}
Files.createDirectories(manifestPath.toPath().getParent());
try (OutputStream manifestOut = buildContext.newFileOutputStream(manifestPath)) {
jar.writeManifest(manifestOut);
}
buildContext.setValue(MANIFEST_LAST_MODIFIED, manifestPath.lastModified());
}
}
use of aQute.bnd.osgi.Resource in project bnd by bndtools.
the class SpringComponent method analyzeJar.
public boolean analyzeJar(Analyzer analyzer) throws Exception {
Jar jar = analyzer.getJar();
Map<String, Resource> dir = jar.getDirectories().get("META-INF/spring");
if (dir == null || dir.isEmpty())
return false;
for (Iterator<Entry<String, Resource>> i = dir.entrySet().iterator(); i.hasNext(); ) {
Entry<String, Resource> entry = i.next();
String path = entry.getKey();
Resource resource = entry.getValue();
if (SPRING_SOURCE.matcher(path).matches()) {
try {
Set<CharSequence> set;
try (InputStream in = resource.openInputStream()) {
set = analyze(in);
}
for (Iterator<CharSequence> r = set.iterator(); r.hasNext(); ) {
PackageRef pack = analyzer.getPackageRef((String) r.next());
if (!QN.matcher(pack.getFQN()).matches())
analyzer.warning("Package does not seem a package in spring resource (%s): %s", path, pack);
if (!analyzer.getReferred().containsKey(pack))
analyzer.getReferred().put(pack, new Attrs());
}
} catch (Exception e) {
analyzer.error("Unexpected exception in processing spring resources(%s): %s", path, e);
}
}
}
return false;
}
Aggregations