use of org.osgi.service.packageadmin.ExportedPackage in project felix by apache.
the class WebConsolePrinter method dumpDuplicatesAsTxt.
@SuppressWarnings("deprecation")
private void dumpDuplicatesAsTxt(final PrintWriter pw, final Map<String, Set<ExportedPackage>> exports) {
pw.println("Duplicate Exported Packages");
pw.println("---------------------------");
final List<String[]> lines = new ArrayList<String[]>();
lines.add(new String[] { "Package", "Exports", "Imports" });
for (Iterator<Entry<String, Set<ExportedPackage>>> entriesIter = exports.entrySet().iterator(); entriesIter.hasNext(); ) {
Entry<String, Set<ExportedPackage>> exportEntry = entriesIter.next();
final Set<ExportedPackage> exportSet = exportEntry.getValue();
if (exportSet.size() > 1) {
String firstCol = exportEntry.getKey();
for (Iterator<ExportedPackage> packageIter = exportSet.iterator(); packageIter.hasNext(); ) {
ExportedPackage exportedPackage = packageIter.next();
final Bundle[] importers = exportedPackage.getImportingBundles();
final String secondCol = "version=" + exportedPackage.getVersion() + ", Bundle " + exportedPackage.getExportingBundle();
if (importers != null && importers.length > 0) {
boolean first = true;
for (int j = 0; j < importers.length; j++) {
final Bundle bundle = importers[j];
if (first) {
lines.add(new String[] { firstCol, secondCol, bundle.toString() });
first = false;
} else {
lines.add(new String[] { "", "", bundle.toString() });
}
}
} else {
lines.add(new String[] { firstCol, secondCol, "" });
}
firstCol = "";
}
}
}
int maxFirst = 0, maxSecond = 0;
for (int i = 0; i < lines.size(); i++) {
final String[] entry = lines.get(i);
if (entry[0].length() > maxFirst) {
maxFirst = entry[0].length();
}
if (entry[1].length() > maxSecond) {
maxSecond = entry[1].length();
}
}
maxFirst += 2;
maxSecond += 2;
for (int i = 0; i < lines.size(); i++) {
final String[] entry = lines.get(i);
padText(pw, entry[0], maxFirst);
padText(pw, entry[1], maxSecond);
pw.println(entry[2]);
}
}
use of org.osgi.service.packageadmin.ExportedPackage in project felix by apache.
the class Inspect42 method printImportedPackages.
private static boolean printImportedPackages(BundleContext bc, Bundle b) {
boolean matches = false;
// Keep track of service references.
List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
// Fragments cannot import packages.
if (!isFragment(b)) {
// Get package admin service.
PackageAdmin pa = Util.getService(bc, PackageAdmin.class, refs);
if (pa == null) {
System.out.println("PackageAdmin service is unavailable.");
} else {
ExportedPackage[] exports = pa.getExportedPackages((Bundle) null);
if (exports != null) {
for (ExportedPackage ep : exports) {
Bundle[] importers = ep.getImportingBundles();
if (importers != null) {
for (Bundle importer : importers) {
if (importer == b) {
matches = true;
System.out.println(LEGACY_PACKAGE_NAMESPACE + "; " + ep.getName() + " resolved by:");
System.out.println(" " + ep.getName() + "; " + ep.getVersion().toString() + " from " + ep.getExportingBundle());
}
}
}
}
}
}
}
Util.ungetServices(bc, refs);
return matches;
}
use of org.osgi.service.packageadmin.ExportedPackage in project felix by apache.
the class Inspect42 method printExportedPackages.
public static boolean printExportedPackages(BundleContext bc, Bundle b) {
boolean matches = false;
// Keep track of service references.
List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
// Fragments cannot export packages.
if (!isFragment(b)) {
// Get package admin service.
PackageAdmin pa = Util.getService(bc, PackageAdmin.class, refs);
if (pa == null) {
System.out.println("PackageAdmin service is unavailable.");
} else {
try {
ExportedPackage[] exports = pa.getExportedPackages(b);
if (exports != null) {
for (ExportedPackage ep : exports) {
matches = true;
Bundle[] importers = ep.getImportingBundles();
if ((importers != null) && (importers.length > 0)) {
String msg = LEGACY_PACKAGE_NAMESPACE + "; " + ep.getName() + "; " + ep.getVersion().toString() + " required by:";
System.out.println(msg);
for (Bundle importer : importers) {
System.out.println(" " + importer);
}
} else {
System.out.println(LEGACY_PACKAGE_NAMESPACE + "; " + ep.getName() + "; " + ep.getVersion().toString() + " " + UNUSED_MESSAGE);
}
}
}
} catch (Exception ex) {
System.err.println(ex.toString());
}
}
}
Util.ungetServices(bc, refs);
return matches;
}
use of org.osgi.service.packageadmin.ExportedPackage in project felix by apache.
the class Permissions method createPermission.
private Permission createPermission(final PermissionInfo permissionInfo, final Class target) {
return (Permission) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
Permission cached = getFromCache(permissionInfo.getEncoded(), target);
if (cached != null) {
return cached;
}
try {
if (m_classLoader.loadClass(target.getName()) == target) {
return addToCache(permissionInfo.getEncoded(), createPermission(permissionInfo.getName(), permissionInfo.getActions(), target));
}
} catch (ClassNotFoundException e1) {
}
ServiceReference[] refs = null;
try {
refs = m_context.getServiceReferences(PackageAdmin.class.getName(), null);
} catch (InvalidSyntaxException e) {
}
if (refs != null) {
for (int i = 0; i < refs.length; i++) {
PackageAdmin admin = (PackageAdmin) m_context.getService(refs[i]);
if (admin != null) {
Permission result = null;
Bundle bundle = admin.getBundle(target);
if (bundle != null) {
ExportedPackage[] exports = admin.getExportedPackages(bundle);
if (exports != null) {
String name = target.getName();
name = name.substring(0, name.lastIndexOf('.'));
for (int j = 0; j < exports.length; j++) {
if (exports[j].getName().equals(name)) {
result = createPermission(permissionInfo.getName(), permissionInfo.getActions(), target);
break;
}
}
}
}
m_context.ungetService(refs[i]);
return addToCache(permissionInfo.getEncoded(), result);
}
}
}
return null;
}
});
}
use of org.osgi.service.packageadmin.ExportedPackage in project rt.equinox.framework by eclipse.
the class PackageAdminImpl method getExportedPackages.
public ExportedPackage[] getExportedPackages(Bundle bundle) {
if (bundle == null) {
return getExportedPackages((String) null);
}
Module module = StartLevelImpl.getModule(bundle);
Collection<ModuleRevision> revisions = module == null ? Collections.<ModuleRevision>emptyList() : module.getRevisions().getModuleRevisions();
Collection<ExportedPackage> allExports = new ArrayList<>();
for (ModuleRevision revision : revisions) {
ModuleWiring wiring = revision.getWiring();
if (wiring != null) {
List<ModuleCapability> providedPackages = wiring.getModuleCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
if (providedPackages != null) {
for (ModuleCapability providedPackage : providedPackages) {
allExports.add(new ExportedPackageImpl(providedPackage, wiring));
}
}
}
}
return allExports.isEmpty() ? null : allExports.toArray(new ExportedPackage[allExports.size()]);
}
Aggregations