Merge branch 'master' into twatson/container
diff --git a/bundles/org.eclipse.equinox.console/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.console/META-INF/MANIFEST.MF
index 2834ae5..5f9b88c 100755
--- a/bundles/org.eclipse.equinox.console/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.console/META-INF/MANIFEST.MF
@@ -10,10 +10,14 @@
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.apache.felix.service.command;status=provisional;version="0.8.0",
org.eclipse.osgi.framework.console,
+ org.eclipse.osgi.report.resolution; version="[1.0,2.0)",
org.eclipse.osgi.service.environment,
- org.eclipse.osgi.service.resolver,
org.eclipse.osgi.util,
org.osgi.framework,
+ org.osgi.framework.hooks.resolver; version="[1.0, 2.0)",
+ org.osgi.framework.namespace;version="1.1.0",
+ org.osgi.framework.wiring;version="1.1.0",
+ org.osgi.resource;version="1.0.0",
org.osgi.service.cm;resolution:=optional,
org.osgi.service.condpermadmin,
org.osgi.service.packageadmin,
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/Activator.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/Activator.java
index 350ee36..11d8e2d 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/Activator.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/Activator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2012 IBM Corporation, SAP AG.
+ * Copyright (c) 2010, 2013 IBM Corporation, SAP AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -41,7 +41,6 @@
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.startlevel.StartLevel;
import org.osgi.service.permissionadmin.PermissionAdmin;
-import org.eclipse.osgi.service.resolver.PlatformAdmin;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -53,7 +52,6 @@
private ServiceTracker<ConditionalPermissionAdmin, ?> condPermAdminTracker;
private ServiceTracker<PermissionAdmin, ?> permissionAdminTracker;
private ServiceTracker<PackageAdmin, PackageAdmin> packageAdminTracker;
- private ServiceTracker<PlatformAdmin, ?> platformAdminTracker;
private static boolean isFirstProcessor = true;
private static TelnetCommand telnetConnection = null;
@@ -218,9 +216,6 @@
packageAdminTracker = new ServiceTracker<PackageAdmin, PackageAdmin>(context, PackageAdmin.class, null);
packageAdminTracker.open();
-
- platformAdminTracker = new ServiceTracker<PlatformAdmin, Object>(context, PlatformAdmin.class.getName(), null);
- platformAdminTracker.open();
equinoxCmdProvider = new EquinoxCommandProvider(context, this);
equinoxCmdProvider.startService();
@@ -268,10 +263,6 @@
return (PackageAdmin) getServiceFromTracker(packageAdminTracker, PackageAdmin.class.getName());
}
- public PlatformAdmin getPlatformAdmin() {
- return (PlatformAdmin) getServiceFromTracker(platformAdminTracker, PlatformAdmin.class.getName());
- }
-
private static Object getServiceFromTracker(ServiceTracker<?, ?> tracker, String serviceClass) {
if (tracker == null)
throw new IllegalStateException("Missing service: " + serviceClass);
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties
index cae002d..dbc4ff4 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2003, 2012 IBM Corporation and others.
+# Copyright (c) 2003, 2013 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -24,7 +24,6 @@
CONSOLE_IMPORTS_MESSAGE=imports
CONSOLE_STALE_MESSAGE=stale
CONSOLE_NO_EXPORTED_PACKAGES_NO_PACKAGE_ADMIN_MESSAGE=No exported packages [PackageAdmin service is not registered]
-CONSOLE_NO_EXPORTED_PACKAGES_NO_PLATFORM_ADMIN_MESSAGE=No exported packages [PlatformAdmin service is not registered]
CONSOLE_SERVICES_IN_USE_MESSAGE=Services in use:
CONSOLE_NO_SERVICES_IN_USE_MESSAGE=No services in use.
CONSOLE_STATUS_MESSAGE=Status={0}
@@ -55,7 +54,6 @@
STARTLEVEL_INITIAL_BUNDLE_STARTLEVEL=Initial Bundle Start Level = {0}
STARTLEVEL_BUNDLE_STARTLEVEL=Bundle {0} Start Level = {1}
STARTLEVEL_POSITIVE_INTEGER=Startlevel must be a positive integer.
-CONSOLE_NAMED_CLASS_SPACE_MESSAGE=Named class space
CONSOLE_PROVIDED_MESSAGE=[provided]
CONSOLE_HOST_MESSAGE=Host bundles
CONSOLE_NO_HOST_MESSAGE=No host bundles
@@ -77,7 +75,6 @@
CONSOLE_STATE_BUNDLE_FILE_NAME_HEADER = "State Bundle File Name"
CONSOLE_REGISTERED_SERVICES_MESSAGE = "Registered Services"
CONSOLE_NO_CONSTRAINTS_NO_PLATFORM_ADMIN_MESSAGE=No unresolved constraints [PlatformAdmin service is not registered].
-CONSOLE_CANNOT_FIND_BUNDLE_ERROR=Cannot find bundle {0}.
CONSOLE_NO_CONSTRAINTS=No unresolved constraints.
CONSOLE_DIRECT_CONSTRAINTS=Direct constraints which are unresolved:
CONSOLE_LEAF_CONSTRAINTS=Leaf constraints in the dependency chain which are unresolved:
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java
index 5d3bca2..269a425 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2012 IBM Corporation and others.
+ * Copyright (c) 2004, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -34,7 +34,6 @@
public static String CONSOLE_IMPORTS_MESSAGE;
public static String CONSOLE_STALE_MESSAGE;
public static String CONSOLE_NO_EXPORTED_PACKAGES_NO_PACKAGE_ADMIN_MESSAGE;
- public static String CONSOLE_NO_EXPORTED_PACKAGES_NO_PLATFORM_ADMIN_MESSAGE;
public static String CONSOLE_NO_EXPORTED_PACKAGES_MESSAGE;
public static String CONSOLE_REMOVAL_PENDING_MESSAGE;
public static String CONSOLE_SERVICES_IN_USE_MESSAGE;
@@ -53,7 +52,6 @@
public static String CONSOLE_FRAGMENT_MESSAGE;
public static String CONSOLE_NO_FRAGMENT_MESSAGE;
public static String CONSOLE_NO_NAMED_CLASS_SPACES_MESSAGE;
- public static String CONSOLE_NAMED_CLASS_SPACE_MESSAGE;
public static String CONSOLE_PROVIDED_MESSAGE;
public static String CONSOLE_REQUIRED_BUNDLES_MESSAGE;
public static String CONSOLE_NO_REQUIRED_BUNDLES_MESSAGE;
@@ -76,7 +74,6 @@
public static String CONSOLE_REQUIRES_MESSAGE;
public static String CONSOLE_CANNOT_ACCESS_SYSTEM_PROPERTIES;
public static String CONSOLE_NO_CONSTRAINTS_NO_PLATFORM_ADMIN_MESSAGE;
- public static String CONSOLE_CANNOT_FIND_BUNDLE_ERROR;
public static String CONSOLE_NO_CONSTRAINTS;
public static String CONSOLE_DIRECT_CONSTRAINTS;
public static String CONSOLE_LEAF_CONSTRAINTS;
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java
index 529c2df..b89fba1 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2012 IBM Corporation and others.
+ * Copyright (c) 2003, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,13 +20,20 @@
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;
+import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.StringTokenizer;
+import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.felix.service.command.CommandProcessor;
@@ -34,20 +41,10 @@
import org.apache.felix.service.command.Descriptor;
import org.apache.felix.service.command.Parameter;
import org.eclipse.equinox.console.command.adapter.Activator;
+import org.eclipse.osgi.report.resolution.ResolutionReport;
+import org.eclipse.osgi.report.resolution.ResolutionReport.Entry;
+import org.eclipse.osgi.report.resolution.ResolutionReport.Listener;
import org.eclipse.osgi.service.environment.EnvironmentInfo;
-import org.eclipse.osgi.service.resolver.BundleDescription;
-import org.eclipse.osgi.service.resolver.BundleSpecification;
-import org.eclipse.osgi.service.resolver.DisabledInfo;
-import org.eclipse.osgi.service.resolver.ExportPackageDescription;
-import org.eclipse.osgi.service.resolver.GenericSpecification;
-import org.eclipse.osgi.service.resolver.HostSpecification;
-import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
-import org.eclipse.osgi.service.resolver.NativeCodeSpecification;
-import org.eclipse.osgi.service.resolver.PlatformAdmin;
-import org.eclipse.osgi.service.resolver.ResolverError;
-import org.eclipse.osgi.service.resolver.State;
-import org.eclipse.osgi.service.resolver.StateHelper;
-import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -58,12 +55,26 @@
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.framework.hooks.resolver.ResolverHook;
+import org.osgi.framework.hooks.resolver.ResolverHookFactory;
+import org.osgi.framework.namespace.BundleNamespace;
+import org.osgi.framework.namespace.HostNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleRevisions;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.framework.wiring.FrameworkWiring;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
import org.osgi.service.condpermadmin.ConditionalPermissionUpdate;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
-import org.osgi.service.packageadmin.RequiredBundle;
import org.osgi.service.permissionadmin.PermissionAdmin;
import org.osgi.service.startlevel.StartLevel;
@@ -139,7 +150,6 @@
"setibsl", "requiredBundles", "classSpaces", "profilelog", "getPackages", "getprop", "diag", "enableBundle",
"disableBundle", "disabledBundles"};
- private static final String POLICY_CONSOLE = "org.eclipse.equinox.console"; //$NON-NLS-1$
/**
* Constructor.
@@ -783,7 +793,6 @@
*
* @param bundles bundle(s) to display details for
*/
- @SuppressWarnings({ "deprecation" })
@Descriptor(ConsoleMsg.CONSOLE_HELP_BUNDLE_COMMAND_DESCRIPTION)
public void bundle(@Descriptor(ConsoleMsg.CONSOLE_HELP_IDLOCATION_ARGUMENT_DESCRIPTION)Bundle[] bundles) throws Exception {
if (bundles.length == 0) {
@@ -792,301 +801,209 @@
}
for (Bundle bundle : bundles) {
- long id = bundle.getBundleId();
- System.out.println(bundle);
+ long id = bundle.getBundleId();
+ System.out.println(bundle);
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.print(NLS.bind(ConsoleMsg.CONSOLE_ID_MESSAGE, String.valueOf(id)));
+ System.out.print(", "); //$NON-NLS-1$
+ System.out.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle)));
+ if (id != 0) {
+ File dataRoot = bundle.getDataFile(""); //$NON-NLS-1$
+ String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath();
+ System.out.print(NLS.bind(ConsoleMsg.CONSOLE_DATA_ROOT_MESSAGE, root));
+ System.out.println();
+ } else {
+ System.out.println();
+ }
+
+ ServiceReference<?>[] services = bundle.getRegisteredServices();
+ if (services != null) {
System.out.print(" "); //$NON-NLS-1$
- System.out.print(NLS.bind(ConsoleMsg.CONSOLE_ID_MESSAGE, String.valueOf(id)));
- System.out.print(", "); //$NON-NLS-1$
- System.out.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle)));
- if (id != 0) {
- File dataRoot = bundle.getDataFile(""); //$NON-NLS-1$
- String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath();
- System.out.print(NLS.bind(ConsoleMsg.CONSOLE_DATA_ROOT_MESSAGE, root));
- System.out.println();
- } else {
- System.out.println();
+ System.out.println(ConsoleMsg.CONSOLE_REGISTERED_SERVICES_MESSAGE);
+ for (int j = 0; j < services.length; j++) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(services[j]);
}
+ } else {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(ConsoleMsg.CONSOLE_NO_REGISTERED_SERVICES_MESSAGE);
+ }
- ServiceReference<?>[] services = bundle.getRegisteredServices();
- if (services != null) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_REGISTERED_SERVICES_MESSAGE);
- for (int j = 0; j < services.length; j++) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(services[j]);
+ services = bundle.getServicesInUse();
+ if (services != null) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(ConsoleMsg.CONSOLE_SERVICES_IN_USE_MESSAGE);
+ for (int j = 0; j < services.length; j++) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(services[j]);
+ }
+ } else {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(ConsoleMsg.CONSOLE_NO_SERVICES_IN_USE_MESSAGE);
+ }
+
+ BundleRevision revision = bundle.adapt(BundleRevision.class);
+ if (revision == null) {
+ continue;
+ }
+
+ BundleWiring wiring = revision.getWiring();
+ if (wiring == null) {
+ continue;
+ }
+ boolean title = true;
+ List<BundleCapability> exports = wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
+ if ( exports.isEmpty()) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(ConsoleMsg.CONSOLE_NO_EXPORTED_PACKAGES_MESSAGE);
+ } else {
+ title = true;
+
+ for (BundleCapability export : exports) {
+ if (title) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(ConsoleMsg.CONSOLE_EXPORTED_PACKAGES_MESSAGE);
+ title = false;
}
- } else {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NO_REGISTERED_SERVICES_MESSAGE);
- }
-
- services = bundle.getServicesInUse();
- if (services != null) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_SERVICES_IN_USE_MESSAGE);
- for (int j = 0; j < services.length; j++) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(services[j]);
+ Map<String, Object> exportAttrs = export.getAttributes();
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.print(exportAttrs.get(PackageNamespace.PACKAGE_NAMESPACE));
+ System.out.print("; version=\""); //$NON-NLS-1$
+ System.out.print(exportAttrs.get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE));
+ System.out.print("\""); //$NON-NLS-1$
+ if (!wiring.isCurrent()) {
+ System.out.println(ConsoleMsg.CONSOLE_EXPORTED_REMOVAL_PENDING_MESSAGE);
+ } else {
+ System.out.println(ConsoleMsg.CONSOLE_EXPORTED_MESSAGE);
}
- } else {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NO_SERVICES_IN_USE_MESSAGE);
}
- PackageAdmin packageAdmin = activator.getPackageAdmin();
- if (packageAdmin == null) {
+ if (title) {
System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NO_EXPORTED_PACKAGES_NO_PACKAGE_ADMIN_MESSAGE);
- continue;
+ System.out.println(ConsoleMsg.CONSOLE_NO_EXPORTED_PACKAGES_MESSAGE);
}
-
- PlatformAdmin platAdmin = activator.getPlatformAdmin();
-
- if (platAdmin != null) {
- BundleDescription desc = platAdmin.getState(false).getBundle(bundle.getBundleId());
- if (desc != null) {
- boolean title = true;
-
- ExportPackageDescription[] exports = desc.getExportPackages();
- if (exports == null || exports.length == 0) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NO_EXPORTED_PACKAGES_MESSAGE);
- } else {
- title = true;
+ }
+ title = true;
- for (int i = 0; i < exports.length; i++) {
- if (title) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_EXPORTED_PACKAGES_MESSAGE);
- title = false;
- }
- System.out.print(" "); //$NON-NLS-1$
- System.out.print(exports[i].getName());
- System.out.print("; version=\""); //$NON-NLS-1$
- System.out.print(exports[i].getVersion());
- System.out.print("\""); //$NON-NLS-1$
- if (desc.isRemovalPending()) {
- System.out.println(ConsoleMsg.CONSOLE_EXPORTED_REMOVAL_PENDING_MESSAGE);
- } else {
- System.out.println(ConsoleMsg.CONSOLE_EXPORTED_MESSAGE);
- }
- }
+ // Get all resolved imports
+ Map<String, List<PackageSource>> packages = getPackagesInternal(wiring);
+ List<BundleRequirement> unresolvedImports = getUnresolvedImports(packages, wiring);
- if (title) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NO_EXPORTED_PACKAGES_MESSAGE);
- }
- }
- title = true;
- if (desc != null) {
- List<ImportPackageSpecification> fragmentsImportPackages = new ArrayList<ImportPackageSpecification>();
+ title = printImportedPackages(packages, title);
+ title = printUnwiredDynamicImports(unresolvedImports, title);
- // Get bundle' fragments imports
- BundleDescription[] fragments = desc.getFragments();
- for (int i = 0; i < fragments.length; i++) {
- ImportPackageSpecification[] fragmentImports = fragments[i].getImportPackages();
- for (int j = 0; j < fragmentImports.length; j++) {
- fragmentsImportPackages.add(fragmentImports[j]);
- }
- }
+ if (title) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(ConsoleMsg.CONSOLE_NO_IMPORTED_PACKAGES_MESSAGE);
+ }
- // Get all bundle imports
- ImportPackageSpecification[] importPackages;
- if (fragmentsImportPackages.size() > 0) {
- ImportPackageSpecification[] directImportPackages = desc.getImportPackages();
- importPackages = new ImportPackageSpecification[directImportPackages.length + fragmentsImportPackages.size()];
-
- for (int i = 0; i < directImportPackages.length; i++) {
- importPackages[i] = directImportPackages[i];
- }
-
- int offset = directImportPackages.length;
- for (int i = 0; i < fragmentsImportPackages.size(); i++) {
- importPackages[offset + i] = fragmentsImportPackages.get(i);
- }
- } else {
- importPackages = desc.getImportPackages();
- }
-
- // Get all resolved imports
- ExportPackageDescription[] imports = null;
- imports = desc.getContainingState().getStateHelper().getVisiblePackages(desc, StateHelper.VISIBLE_INCLUDE_EE_PACKAGES | StateHelper.VISIBLE_INCLUDE_ALL_HOST_WIRES);
-
- // Get the unresolved optional and dynamic imports
- List<ImportPackageSpecification> unresolvedImports = new ArrayList<ImportPackageSpecification>();
-
- for (int i = 0; i < importPackages.length; i++) {
- if (importPackages[i].getDirective(Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_OPTIONAL)) {
- if (importPackages[i].getSupplier() == null) {
- unresolvedImports.add(importPackages[i]);
- }
- } else if (importPackages[i].getDirective(org.osgi.framework.Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_DYNAMIC)) {
- boolean isResolvable = false;
-
- // Check if the dynamic import can be resolved by any of the wired imports,
- // and if not - add it to the list of unresolved imports
- for (int j = 0; j < imports.length; j++) {
- if (importPackages[i].isSatisfiedBy(imports[j])) {
- isResolvable = true;
- }
- }
-
- if (isResolvable == false) {
- unresolvedImports.add(importPackages[i]);
- }
- }
- }
-
- title = printImportedPackages(imports, title);
-
- if (desc.isResolved() && (unresolvedImports.isEmpty() == false)) {
- printUnwiredDynamicImports(unresolvedImports);
- title = false;
- }
- }
-
- if (title) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NO_IMPORTED_PACKAGES_MESSAGE);
- }
-
- if (packageAdmin != null) {
- System.out.print(" "); //$NON-NLS-1$
- if ((packageAdmin.getBundleType(bundle) & PackageAdmin.BUNDLE_TYPE_FRAGMENT) > 0) {
- org.osgi.framework.Bundle[] hosts = packageAdmin.getHosts(bundle);
- if (hosts != null) {
- System.out.println(ConsoleMsg.CONSOLE_HOST_MESSAGE);
- for (int i = 0; i < hosts.length; i++) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(hosts[i]);
- }
- } else {
- System.out.println(ConsoleMsg.CONSOLE_NO_HOST_MESSAGE);
- }
- } else {
- org.osgi.framework.Bundle[] fragments = packageAdmin.getFragments(bundle);
- if (fragments != null) {
- System.out.println(ConsoleMsg.CONSOLE_FRAGMENT_MESSAGE);
- for (int i = 0; i < fragments.length; i++) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(fragments[i]);
- }
- } else {
- System.out.println(ConsoleMsg.CONSOLE_NO_FRAGMENT_MESSAGE);
- }
- }
-
- RequiredBundle[] requiredBundles = packageAdmin.getRequiredBundles(null);
- RequiredBundle requiredBundle = null;
- if (requiredBundles != null) {
- for (RequiredBundle rb : requiredBundles) {
- if (rb.getBundle() == bundle) {
- requiredBundle = rb;
- break;
- }
- }
- }
-
- if (requiredBundle == null) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NO_NAMED_CLASS_SPACES_MESSAGE);
- } else {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NAMED_CLASS_SPACE_MESSAGE);
- System.out.print(" "); //$NON-NLS-1$
- System.out.print(requiredBundle);
- if (requiredBundle.isRemovalPending()) {
- System.out.println(ConsoleMsg.CONSOLE_REMOVAL_PENDING_MESSAGE);
- } else {
- System.out.println(ConsoleMsg.CONSOLE_PROVIDED_MESSAGE);
- }
- }
- title = true;
- if (requiredBundles != null) {
- for (RequiredBundle rb : requiredBundles) {
- if (rb == requiredBundle)
- continue;
-
- org.osgi.framework.Bundle[] depBundles = rb.getRequiringBundles();
- if (depBundles == null)
- continue;
-
- for (int j = 0; j < depBundles.length; j++) {
- if (depBundles[j] == bundle) {
- if (title) {
- System.out.print(" "); //$NON-NLS-1$
- System.out
- .println(ConsoleMsg.CONSOLE_REQUIRED_BUNDLES_MESSAGE);
- title = false;
- }
- System.out.print(" "); //$NON-NLS-1$
- System.out.print(rb);
-
- org.osgi.framework.Bundle provider = rb.getBundle();
- System.out.print("<"); //$NON-NLS-1$
- System.out.print(provider);
- System.out.println(">"); //$NON-NLS-1$
- }
- }
- }
- }
- if (title) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NO_REQUIRED_BUNDLES_MESSAGE);
- }
-
- }
- }
- System.out.println();
- System.out.println();
+ System.out.print(" "); //$NON-NLS-1$
+ if ((revision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
+ List<BundleWire> hostWires = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE);
+ if (hostWires.isEmpty()) {
+ System.out.println(ConsoleMsg.CONSOLE_NO_HOST_MESSAGE);
} else {
+ System.out.println(ConsoleMsg.CONSOLE_HOST_MESSAGE);
+ for (BundleWire hostWire : hostWires) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(hostWire.getProvider().getBundle());
+ }
+ }
+ } else {
+ List<BundleWire> fragmentWires = wiring.getProvidedWires(HostNamespace.HOST_NAMESPACE);
+ if (fragmentWires.isEmpty()) {
+ System.out.println(ConsoleMsg.CONSOLE_NO_FRAGMENT_MESSAGE);
+ } else {
+ System.out.println(ConsoleMsg.CONSOLE_FRAGMENT_MESSAGE);
+ for (BundleWire fragmentWire : fragmentWires) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(fragmentWire.getRequirer().getBundle());
+ }
+ }
+
+ List<BundleWire> requiredBundles = wiring.getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE);
+ title = true;
+ for (BundleWire requiredBundle : requiredBundles) {
+ if (title) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(ConsoleMsg.CONSOLE_REQUIRED_BUNDLES_MESSAGE);
+ title = false;
+ }
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(requiredBundle.getProvider());
+ }
+ if (title) {
System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NO_EXPORTED_PACKAGES_NO_PLATFORM_ADMIN_MESSAGE);
- }
+ System.out.println(ConsoleMsg.CONSOLE_NO_REQUIRED_BUNDLES_MESSAGE);
+ }
+
+ }
+
+ System.out.println();
+ System.out.println();
+ }
+ }
+
+ private List<BundleRequirement> getUnresolvedImports(
+ Map<String, List<PackageSource>> packages, BundleWiring wiring) {
+
+ // TODO need to get this information
+ return Collections.emptyList();
+ }
+
+ private boolean printImportedPackages(Map<String, List<PackageSource>> packages, boolean title) {
+ for (List<PackageSource> packageList : packages.values()) {
+ for (PackageSource packageSource : packageList) {
+ if (title) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(ConsoleMsg.CONSOLE_IMPORTED_PACKAGES_MESSAGE);
+ title = false;
+ }
+ printCapability(" ", packageSource.getCapability(), packageSource.getWire(), PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
+ }
+ }
+ return title;
+ }
+
+ private void printCapability(String prepend, BundleCapability capability, BundleWire wire, String versionKey) {
+ Map<String, Object> exportAttrs = capability.getAttributes();
+ System.out.print(prepend);
+ System.out.print(exportAttrs.get(capability.getNamespace()));
+ if (versionKey != null) {
+ System.out.print("; " + versionKey + "=\""); //$NON-NLS-1$
+ System.out.print(exportAttrs.get(versionKey));
+ System.out.print("\""); //$NON-NLS-1$
+ }
+
+ Bundle exporter = wire == null ? capability.getRevision().getBundle() : wire.getProvider().getBundle();
+ if (exporter != null) {
+ System.out.print(" <"); //$NON-NLS-1$
+ System.out.print(exporter);
+ System.out.println(">"); //$NON-NLS-1$
+ } else {
+ System.out.print(" <"); //$NON-NLS-1$
+ System.out.print(ConsoleMsg.CONSOLE_STALE_MESSAGE);
+ System.out.println(">"); //$NON-NLS-1$
}
}
- private boolean printImportedPackages(ExportPackageDescription[] importedPkgs, boolean title) {
- for (int i = 0; i < importedPkgs.length; i++) {
+ private boolean printUnwiredDynamicImports(List<BundleRequirement> dynamicImports, boolean title) {
+ for (BundleRequirement importReq : dynamicImports) {
if (title) {
System.out.print(" "); //$NON-NLS-1$
System.out.println(ConsoleMsg.CONSOLE_IMPORTED_PACKAGES_MESSAGE);
title = false;
}
System.out.print(" "); //$NON-NLS-1$
- System.out.print(importedPkgs[i].getName());
- System.out.print("; version=\""); //$NON-NLS-1$
- System.out.print(importedPkgs[i].getVersion());
- System.out.print("\""); //$NON-NLS-1$
- Bundle exporter = context.getBundle(importedPkgs[i].getSupplier().getBundleId());
- if (exporter != null) {
- System.out.print("<"); //$NON-NLS-1$
- System.out.print(exporter);
- System.out.println(">"); //$NON-NLS-1$
- } else {
- System.out.print("<"); //$NON-NLS-1$
- System.out.print(ConsoleMsg.CONSOLE_STALE_MESSAGE);
- System.out.println(">"); //$NON-NLS-1$
- }
- }
- return title;
- }
-
- private void printUnwiredDynamicImports(List<ImportPackageSpecification> dynamicImports) {
- for (int i = 0; i < dynamicImports.size(); i++) {
- ImportPackageSpecification importPackage = dynamicImports.get(i);
- System.out.print(" "); //$NON-NLS-1$
- System.out.print(importPackage.getName());
- System.out.print("; version=\""); //$NON-NLS-1$
- System.out.print(importPackage.getVersionRange());
- System.out.print("\""); //$NON-NLS-1$
- System.out.print("<"); //$NON-NLS-1$
+ System.out.print(importReq);
+ System.out.print(";<"); //$NON-NLS-1$
System.out.print("unwired"); //$NON-NLS-1$
System.out.print(">"); //$NON-NLS-1$
System.out.print("<"); //$NON-NLS-1$
- System.out.print(importPackage.getDirective(org.osgi.framework.Constants.RESOLUTION_DIRECTIVE));
+ System.out.print(importReq.getDirectives().get(PackageNamespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
System.out.println(">"); //$NON-NLS-1$
}
+ return title;
}
/**
@@ -1673,54 +1590,57 @@
@Descriptor(ConsoleMsg.CONSOLE_HELP_REQUIRED_BUNDLES_COMMAND_DESCRIPTION)
public void classSpaces(@Descriptor(ConsoleMsg.CONSOLE_HELP_REQUIRED_BUNDLES_COMMAND_ARGUMENT_DESCRIPTION) String... symbolicName) {
PackageAdmin packageAdmin = activator.getPackageAdmin();
- if (packageAdmin != null) {
- RequiredBundle[] symBundles = null;
- String name;
- if(symbolicName == null || symbolicName.length == 0) {
- name = null;
- } else {
- name = symbolicName[0];
- }
- symBundles = packageAdmin.getRequiredBundles(name);
-
- if (symBundles == null) {
- System.out.println(ConsoleMsg.CONSOLE_NO_NAMED_CLASS_SPACES_MESSAGE);
- } else {
- for (RequiredBundle symBundle : symBundles) {
-
- System.out.print(symBundle);
-
- boolean removalPending = symBundle.isRemovalPending();
- if (removalPending) {
- System.out.print("("); //$NON-NLS-1$
- System.out.print(ConsoleMsg.CONSOLE_REMOVAL_PENDING_MESSAGE);
- System.out.println(")"); //$NON-NLS-1$
- }
-
- Bundle provider = symBundle.getBundle();
- if (provider != null) {
- System.out.print("<"); //$NON-NLS-1$
- System.out.print(provider);
- System.out.println(">"); //$NON-NLS-1$
-
- Bundle[] requiring = symBundle.getRequiringBundles();
- if (requiring != null)
- for (int j = 0; j < requiring.length; j++) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.print(requiring[j]);
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_REQUIRES_MESSAGE);
- }
- } else {
- System.out.print("<"); //$NON-NLS-1$
- System.out.print(ConsoleMsg.CONSOLE_STALE_MESSAGE);
- System.out.println(">"); //$NON-NLS-1$
- }
-
+ if (packageAdmin == null) {
+ System.out.println(ConsoleMsg.CONSOLE_NO_EXPORTED_PACKAGES_NO_PACKAGE_ADMIN_MESSAGE);
+ return;
+ }
+ String[] names;
+ if(symbolicName == null || symbolicName.length == 0) {
+ names = null;
+ } else {
+ names = symbolicName;
+ }
+ List<Bundle> bundles = new ArrayList<Bundle>();
+ if (names == null) {
+ bundles.addAll(Arrays.asList(packageAdmin.getBundles(null, null)));
+ } else {
+ for (String name : names) {
+ Bundle[] sameName = packageAdmin.getBundles(name, null);
+ if (sameName != null) {
+ bundles.addAll(Arrays.asList(sameName));
}
}
+ }
+ if (bundles.isEmpty()) {
+ System.out.println(ConsoleMsg.CONSOLE_NO_NAMED_CLASS_SPACES_MESSAGE);
} else {
- System.out.println(ConsoleMsg.CONSOLE_NO_EXPORTED_PACKAGES_NO_PACKAGE_ADMIN_MESSAGE);
+ for (Bundle bundle : bundles) {
+ BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
+ List<BundleRevision> revisionList = revisions.getRevisions();
+ BundleRevision revision = revisionList.isEmpty() ? null : revisionList.get(0);
+ BundleWiring wiring = revision == null ? null : revision.getWiring();
+ System.out.print(revision);
+ if (wiring == null) {
+ System.out.print("<"); //$NON-NLS-1$
+ System.out.print(ConsoleMsg.CONSOLE_STALE_MESSAGE);
+ System.out.println(">"); //$NON-NLS-1$
+ } else if (!wiring.isCurrent()){
+ System.out.print("<"); //$NON-NLS-1$
+ System.out.print(ConsoleMsg.CONSOLE_REMOVAL_PENDING_MESSAGE);
+ System.out.println(">"); //$NON-NLS-1$
+ } else {
+ System.out.println();
+ }
+ if (wiring != null) {
+ List<BundleWire> requiring = wiring.getProvidedWires(BundleNamespace.BUNDLE_NAMESPACE);
+ for (BundleWire requiringWire : requiring) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.print(requiringWire.getRequirer().getBundle());
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.println(ConsoleMsg.CONSOLE_REQUIRES_MESSAGE);
+ }
+ }
+ }
}
}
@@ -1738,15 +1658,125 @@
* Lists all packages visible from the specified bundle
* @param bundle bundle to list visible packages
*/
+
@Descriptor(ConsoleMsg.CONSOLE_HELP_VISIBLE_PACKAGES_COMMAND_DESCRIPTION)
public void getPackages(@Descriptor(ConsoleMsg.CONSOLE_HELP_VISIBLE_PACKAGES_COMMAND_ARGUMENTS_DESCRIPTION) Bundle bundle) {
- PlatformAdmin platformAdmin = activator.getPlatformAdmin();
- if (platformAdmin == null)
+ BundleRevision revision = bundle.adapt(BundleRevision.class);
+ if (revision == null) {
+ System.out.println("Bundle is uninstalled.");
return;
- BundleDescription bundleDescription = platformAdmin.getState(false).getBundle(bundle.getBundleId());
- ExportPackageDescription[] exports = platformAdmin.getStateHelper().getVisiblePackages(bundleDescription, StateHelper.VISIBLE_INCLUDE_EE_PACKAGES | StateHelper.VISIBLE_INCLUDE_ALL_HOST_WIRES);
- for (int i = 0; i < exports.length; i++) {
- System.out.println(exports[i] + ": " + platformAdmin.getStateHelper().getAccessCode(bundleDescription, exports[i])); //$NON-NLS-1$
+ }
+
+ if ((revision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
+ System.out.println("Bundle is a fragment.");
+ return;
+ }
+
+ BundleWiring wiring = revision.getWiring();
+ if (wiring == null) {
+ System.out.println("Bundle is not resolved.");
+ return;
+ }
+
+ Map<String, List<PackageSource>> packages = getPackagesInternal(wiring);
+ for (List<PackageSource> packageSources : packages.values()) {
+ for (PackageSource packageSource : packageSources) {
+ printCapability(" ", packageSource.getCapability(), packageSource.getWire(), PackageNamespace.PACKAGE_NAMESPACE);
+ }
+ }
+ }
+
+ class PackageSource {
+ private final BundleCapability cap;
+ private final BundleWire wire;
+
+ PackageSource(BundleCapability cap, BundleWire wire) {
+ this.cap = cap;
+ this.wire = wire;
+ }
+
+ BundleCapability getCapability() {
+ return cap;
+ }
+
+ BundleWire getWire() {
+ return wire;
+ }
+ }
+ private Map<String, List<PackageSource>> getPackagesInternal(BundleWiring wiring) {
+ Map<String, List<PackageSource>> packages = new TreeMap<String, List<PackageSource>>();
+ // first get the imported packages
+ List<BundleWire> packageWires = wiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
+ Set<String> importedPackageNames = new HashSet<String>();
+ for (BundleWire packageWire : packageWires) {
+ String packageName = (String) packageWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
+ importedPackageNames.add(packageName);
+ List<PackageSource> packageSources = new ArrayList<PackageSource>();
+ packageSources.add(new PackageSource(packageWire.getCapability(), packageWire));
+ packages.put(packageName, packageSources);
+ }
+
+ // now get packages from required bundles
+ for (BundleWire requiredWire : wiring.getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE)) {
+ getRequiredBundlePackages(requiredWire, importedPackageNames, packages);
+ }
+
+ return packages;
+ }
+
+ private void getRequiredBundlePackages(BundleWire requiredWire, Set<String> importedPackageNames, Map<String, List<PackageSource>> packages) {
+ BundleWiring providerWiring = requiredWire.getProviderWiring();
+ for (BundleCapability packageCapability : providerWiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
+ String packageName = (String) packageCapability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
+ if (!importedPackageNames.contains(packageName)) {
+ List<PackageSource> packageSources = packages.get(packageName);
+ if (packageSources == null) {
+ packageSources = new ArrayList<PackageSource>();
+ packages.put(packageName, packageSources);
+ }
+ boolean sourceFound = false;
+ for (PackageSource packageSource : packageSources) {
+ sourceFound |= packageCapability.equals(packageSource);
+ if (sourceFound) {
+ break;
+ }
+ }
+ if (!sourceFound) {
+ packageSources.add(new PackageSource(packageCapability, requiredWire));
+ }
+ }
+ }
+
+ // get substituted packages
+ Set<String> declaredPackageNames = new HashSet<String>();
+ for (BundleCapability declaredPackage : providerWiring.getRevision().getDeclaredCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
+ declaredPackageNames.add((String) declaredPackage.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
+ }
+ // and fragments
+ for (BundleWire fragmentWire : providerWiring.getProvidedWires(HostNamespace.HOST_NAMESPACE)) {
+ for (BundleCapability declaredPackage : fragmentWire.getRequirer().getDeclaredCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
+ declaredPackageNames.add((String) declaredPackage.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
+ }
+ }
+
+ for (BundleWire packageWire : providerWiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE)) {
+ String packageName = (String) packageWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
+ if (declaredPackageNames.contains(packageName)) {
+ List<PackageSource> packageSources = packages.get(packageName);
+ if (packageSources == null) {
+ packageSources = new ArrayList<PackageSource>();
+ packages.put(packageName, packageSources);
+ }
+ packageSources.add(new PackageSource(packageWire.getCapability(), packageWire));
+ }
+ }
+
+ // now get packages from re-exported requires of the required bundle
+ for (BundleWire providerBundleWire : providerWiring.getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE)) {
+ String visibilityDirective = providerBundleWire.getRequirement().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE);
+ if (BundleNamespace.VISIBILITY_REEXPORT.equals(visibilityDirective)) {
+ getRequiredBundlePackages(providerBundleWire, importedPackageNames, packages);
+ }
}
}
@@ -1783,9 +1813,6 @@
return "UNINSTALLED "; //$NON-NLS-1$
case Bundle.INSTALLED :
- if (isDisabled(bundle)) {
- return "<DISABLED> "; //$NON-NLS-1$
- }
return "INSTALLED "; //$NON-NLS-1$
case Bundle.RESOLVED :
@@ -1810,29 +1837,6 @@
}
}
- private boolean isDisabled(Bundle bundle) {
- boolean disabled = false;
- ServiceReference<?> platformAdminRef = null;
- try {
- platformAdminRef = context.getServiceReference(PlatformAdmin.class.getName());
- if (platformAdminRef != null) {
- PlatformAdmin platAdmin = (PlatformAdmin) context.getService(platformAdminRef);
- if (platAdmin != null) {
- State state = platAdmin.getState(false);
- BundleDescription bundleDesc = state.getBundle(bundle.getBundleId());
- DisabledInfo[] disabledInfos = state.getDisabledInfos(bundleDesc);
- if ((disabledInfos != null) && (disabledInfos.length != 0)) {
- disabled = true;
- }
- }
- }
- } finally {
- if (platformAdminRef != null)
- context.ungetService(platformAdminRef);
- }
- return disabled;
- }
-
/**
* Answers all thread groups in the system.
*
@@ -1897,190 +1901,151 @@
}
@Descriptor(ConsoleMsg.CONSOLE_HELP_DIAG_COMMAND_DESCRIPTION)
- public void diag(@Descriptor(ConsoleMsg.CONSOLE_HELP_DIAG_COMMAND_ARGUMENT_DESCRIPTION) long[] bundleIds) throws Exception {
- if (bundleIds.length == 0) {
- System.out.println(ConsoleMsg.CONSOLE_NO_BUNDLE_SPECIFIED_ERROR);
- return;
- }
-
- PlatformAdmin platformAdmin = activator.getPlatformAdmin();
- if (platformAdmin == null) {
- System.out.println(ConsoleMsg.CONSOLE_NO_CONSTRAINTS_NO_PLATFORM_ADMIN_MESSAGE);
- return;
- }
-
- State systemState = platformAdmin.getState(false);
- for (long bundleId : bundleIds) {
- BundleDescription bundle = systemState.getBundle(bundleId);
- if (bundle == null) {
- System.out.println(NLS.bind(ConsoleMsg.CONSOLE_CANNOT_FIND_BUNDLE_ERROR, bundleId));
- continue;
- }
- System.out.println(bundle.getLocation() + " [" + bundle.getBundleId() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
- VersionConstraint[] unsatisfied = platformAdmin.getStateHelper().getUnsatisfiedConstraints(bundle);
- ResolverError[] resolverErrors = platformAdmin.getState(false).getResolverErrors(bundle);
- for (int i = 0; i < resolverErrors.length; i++) {
- if ((resolverErrors[i].getType() & (ResolverError.MISSING_FRAGMENT_HOST | ResolverError.MISSING_GENERIC_CAPABILITY | ResolverError.MISSING_IMPORT_PACKAGE | ResolverError.MISSING_REQUIRE_BUNDLE)) != 0)
- continue;
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(resolverErrors[i].toString());
- }
-
- if (unsatisfied.length == 0 && resolverErrors.length == 0) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_NO_CONSTRAINTS);
- }
- if (unsatisfied.length > 0) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_DIRECT_CONSTRAINTS);
- }
- for (int i = 0; i < unsatisfied.length; i++) {
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(getResolutionFailureMessage(unsatisfied[i]));
- }
- VersionConstraint[] unsatisfiedLeaves = platformAdmin.getStateHelper().getUnsatisfiedLeaves(new BundleDescription[] {bundle});
- boolean foundLeaf = false;
- for (int i = 0; i < unsatisfiedLeaves.length; i++) {
- if (unsatisfiedLeaves[i].getBundle() == bundle)
- continue;
- if (!foundLeaf) {
- foundLeaf = true;
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(ConsoleMsg.CONSOLE_LEAF_CONSTRAINTS);
+ public void diag(@Descriptor(ConsoleMsg.CONSOLE_HELP_DIAG_COMMAND_ARGUMENT_DESCRIPTION) Bundle[] bundles) throws Exception {
+ if (bundles.length == 0) {
+ List<Bundle> unresolved = new ArrayList<Bundle>();
+ Bundle[] allBundles = context.getBundles();
+ for (Bundle bundle : allBundles) {
+ BundleRevision revision = bundle.adapt(BundleRevision.class);
+ if (revision != null && revision.getWiring() == null) {
+ unresolved.add(bundle);
}
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(unsatisfiedLeaves[i].getBundle().getLocation() + " [" + unsatisfiedLeaves[i].getBundle().getBundleId() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.print(" "); //$NON-NLS-1$
- System.out.println(getResolutionFailureMessage(unsatisfiedLeaves[i]));
+ }
+ if (unresolved.isEmpty()) {
+ System.out.println("No unresolved bundles.");
+ return;
+ }
+ bundles = unresolved.toArray(new Bundle[unresolved.size()]);
+ }
+ ResolutionReport report = getResolutionReport(bundles);
+ Map<Resource, List<ResolutionReport.Entry>> reportEntries = report.getEntries();
+
+ for (Bundle bundle : bundles) {
+ BundleRevision revision = bundle.adapt(BundleRevision.class);
+ if (revision != null) {
+ printResolutionReport("", revision, reportEntries, null);
}
}
}
-
- @Descriptor(ConsoleMsg.CONSOLE_HELP_ENABLE_COMMAND_DESCRIPTION)
- public void enableBundle(@Descriptor(ConsoleMsg.CONSOLE_HELP_ENABLE_COMMAND_ARGUMENT_DESCRIPTION) long[] bundleIds) throws Exception {
- if (bundleIds.length == 0) {
- System.out.println(ConsoleMsg.CONSOLE_NO_BUNDLE_SPECIFIED_ERROR);
+
+ private void printResolutionReport(String prepend, BundleRevision revision, Map<Resource, List<ResolutionReport.Entry>> reportEntries, Set<BundleRevision> visited) {
+ if (visited == null) {
+ visited = new HashSet<BundleRevision>();
+ }
+ if (visited.contains(revision)) {
return;
}
-
- PlatformAdmin platformAdmin = activator.getPlatformAdmin();
- if (platformAdmin == null) {
- System.out.println(ConsoleMsg.CONSOLE_CANNOT_ENABLE_NO_PLATFORM_ADMIN_MESSAGE);
- return;
- }
+ visited.add(revision);
+ Bundle bundle = revision.getBundle();
+ System.out.println(prepend + bundle.getLocation() + " [" + bundle.getBundleId() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
-
- State systemState = platformAdmin.getState(false);
- for (long bundleId : bundleIds) {
- BundleDescription bundle = systemState.getBundle(bundleId);
- if (bundle == null) {
- System.out.println(NLS.bind(ConsoleMsg.CONSOLE_CANNOT_FIND_BUNDLE_ERROR, bundleId));
- continue;
- }
-
- DisabledInfo[] infos = systemState.getDisabledInfos(bundle);
- for (int i = 0; i < infos.length; i++) {
- platformAdmin.removeDisabledInfo(infos[i]);
+ List<ResolutionReport.Entry> revisionEntries = reportEntries.get(revision);
+ if (revisionEntries == null) {
+ System.out.println(prepend + " " + "No resolution report for the bundle.");
+ } else {
+ for (ResolutionReport.Entry entry : revisionEntries) {
+ printResolutionEntry(prepend + " ", entry, reportEntries, visited);
}
}
-
}
-
- @Descriptor(ConsoleMsg.CONSOLE_HELP_DISABLE_COMMAND_DESCRIPTION)
- public void disableBundle(@Descriptor(ConsoleMsg.CONSOLE_HELP_DISABLE_COMMAND_ARGUMENT_DESCRIPTION) long[] bundleIds) throws Exception {
- if (bundleIds.length == 0) {
- System.out.println(ConsoleMsg.CONSOLE_NO_BUNDLE_SPECIFIED_ERROR);
- return;
- }
-
- PlatformAdmin platformAdmin = activator.getPlatformAdmin();
- if (platformAdmin == null) {
- System.out.println(ConsoleMsg.CONSOLE_CANNOT_DISABLE_NO_PLATFORM_ADMIN_MESSAGE);
- return;
- }
-
- State systemState = platformAdmin.getState(false);
- for (long bundleId : bundleIds) {
- BundleDescription bundle = systemState.getBundle(bundleId);
- if (bundle == null) {
- System.out.println(NLS.bind(ConsoleMsg.CONSOLE_CANNOT_FIND_BUNDLE_ERROR, bundleId));
- continue;
+ private void printResolutionEntry(String prepend, ResolutionReport.Entry entry, Map<Resource, List<ResolutionReport.Entry>> reportEntries, Set<BundleRevision> visited) {
+ switch (entry.getType()) {
+ case MISSING_CAPABILITY:
+ System.out.print(prepend);
+ System.out.println("Unresolved requirement: " + entry.getData());
+ break;
+ case SINGLETON_SELECTION:
+ System.out.print(prepend);
+ System.out.println("Another singleton bundle selected: " + entry.getData());
+ break;
+ case UNRESOLVED_PROVIDER:
+ @SuppressWarnings("unchecked")
+ Map<Requirement, Set<Capability>> unresolvedProviders = (Map<Requirement, Set<Capability>>) entry.getData();
+ for (Map.Entry<Requirement, Set<Capability>> unresolvedRequirement : unresolvedProviders.entrySet()) {
+ // for now only printing the first possible unresolved candidates
+ Set<Capability> unresolvedCapabilities = unresolvedRequirement.getValue();
+ if (!unresolvedCapabilities.isEmpty()) {
+ Capability unresolvedCapability = unresolvedCapabilities.iterator().next();
+ // make sure this is not a case of importing and exporting the same package
+ if (!unresolvedRequirement.getKey().getResource().equals(unresolvedCapability.getResource())) {
+ System.out.print(prepend);
+ System.out.println("Unresolved requirement: " + unresolvedRequirement.getKey());
+ System.out.print(prepend);
+ System.out.println(" -> " + unresolvedCapability);
+ printResolutionReport(prepend + " ", (BundleRevision) unresolvedCapability.getResource(), reportEntries, visited);
+ }
+ }
}
- DisabledInfo info = new DisabledInfo(POLICY_CONSOLE, ConsoleMsg.CONSOLE_CONSOLE_BUNDLE_DISABLED_MESSAGE, bundle);
- platformAdmin.addDisabledInfo(info);
- }
- }
-
- @Descriptor(ConsoleMsg.CONSOLE_HELP_LD_COMMAND_DESCRIPTION)
- public void disabledBundles() throws Exception {
-
- PlatformAdmin platformAdmin = activator.getPlatformAdmin();
- if (platformAdmin == null) {
- System.out.println(ConsoleMsg.CONSOLE_CANNOT_LIST_DISABLED_NO_PLATFORM_ADMIN_MESSAGE);
- return;
- }
-
- State systemState = platformAdmin.getState(false);
- BundleDescription[] disabledBundles = systemState.getDisabledBundles();
-
- System.out.println(NLS.bind(ConsoleMsg.CONSOLE_DISABLED_COUNT_MESSAGE, String.valueOf(disabledBundles.length)));
-
- if (disabledBundles.length > 0) {
- System.out.println();
- }
- for (int i = 0; i < disabledBundles.length; i++) {
- DisabledInfo[] disabledInfos = systemState.getDisabledInfos(disabledBundles[i]);
-
- System.out.println(NLS.bind(ConsoleMsg.CONSOLE_DISABLED_BUNDLE_HEADER, formatBundleName(disabledBundles[i]), String.valueOf(disabledBundles[i].getBundleId())));
- System.out.print(NLS.bind(ConsoleMsg.CONSOLE_DISABLED_BUNDLE_REASON, disabledInfos[0].getMessage(), disabledInfos[0].getPolicyName()));
-
- for (int j = 1; j < disabledInfos.length; j++) {
- System.out.print(NLS.bind(ConsoleMsg.CONSOLE_DISABLED_BUNDLE_REASON, disabledInfos[j].getMessage(), String.valueOf(disabledInfos[j].getPolicyName())));
- }
-
- System.out.println();
+ break;
+ case FILTERED_BY_RESOLVER_HOOK:
+ System.out.println("Bundle was filtered by a resolver hook.");
+ break;
+ default:
+ System.out.println("Unknown error: type=" + entry.getType() + " data=" + entry.getData());
+ break;
}
}
- private String formatBundleName(BundleDescription b) {
- String label = b.getSymbolicName();
- if (label == null || label.length() == 0)
- label = b.toString();
- else
- label = label + "_" + b.getVersion(); //$NON-NLS-1$
-
- return label;
- }
-
- private String getResolutionFailureMessage(VersionConstraint unsatisfied) {
- if (unsatisfied.isResolved())
- throw new IllegalArgumentException();
- if (unsatisfied instanceof ImportPackageSpecification) {
- if (ImportPackageSpecification.RESOLUTION_OPTIONAL.equals(((ImportPackageSpecification) unsatisfied).getDirective(Constants.RESOLUTION_DIRECTIVE)))
- return NLS.bind(ConsoleMsg.CONSOLE_MISSING_OPTIONAL_IMPORTED_PACKAGE, versionToString(unsatisfied));
- if (ImportPackageSpecification.RESOLUTION_DYNAMIC.equals(((ImportPackageSpecification) unsatisfied).getDirective(Constants.RESOLUTION_DIRECTIVE)))
- return NLS.bind(ConsoleMsg.CONSOLE_MISSING_DYNAMIC_IMPORTED_PACKAGE, versionToString(unsatisfied));
- return NLS.bind(ConsoleMsg.CONSOLE_MISSING_IMPORTED_PACKAGE, versionToString(unsatisfied));
- } else if (unsatisfied instanceof BundleSpecification) {
- if (((BundleSpecification) unsatisfied).isOptional())
- return NLS.bind(ConsoleMsg.CONSOLE_MISSING_OPTIONAL_REQUIRED_BUNDLE, versionToString(unsatisfied));
- return NLS.bind(ConsoleMsg.CONSOLE_MISSING_REQUIRED_BUNDLE, versionToString(unsatisfied));
- } else if (unsatisfied instanceof HostSpecification) {
- return NLS.bind(ConsoleMsg.CONSOLE_MISSING_HOST, versionToString(unsatisfied));
- } else if (unsatisfied instanceof NativeCodeSpecification) {
- return NLS.bind(ConsoleMsg.CONSOLE_MISSING_NATIVECODE, unsatisfied.toString());
- } else if (unsatisfied instanceof GenericSpecification) {
- return NLS.bind(ConsoleMsg.CONSOLE_MISSING_REQUIRED_CAPABILITY, unsatisfied.toString());
+ private ResolutionReport getResolutionReport(Bundle[] bundles) {
+ DiagReportListener reportListener = new DiagReportListener(bundles);
+ ServiceRegistration<ResolverHookFactory> hookReg = context.registerService(ResolverHookFactory.class, reportListener, null);
+ try {
+ Bundle systemBundle = context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION);
+ FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
+ frameworkWiring.resolveBundles(Arrays.asList(bundles));
+ return reportListener.getReport();
+ } finally {
+ hookReg.unregister();
}
- return NLS.bind(ConsoleMsg.CONSOLE_MISSING_REQUIREMENT, unsatisfied.toString());
}
-
- private static String versionToString(VersionConstraint constraint) {
- org.eclipse.osgi.service.resolver.VersionRange versionRange = constraint.getVersionRange();
- if (versionRange == null)
- return constraint.getName();
- return constraint.getName() + '_' + versionRange;
+
+ private static class DiagReportListener implements ResolverHookFactory {
+ private final Collection<BundleRevision> targetTriggers = new ArrayList<BundleRevision>();
+ public DiagReportListener(Bundle[] bundles) {
+ for (Bundle bundle : bundles) {
+ BundleRevision revision = bundle.adapt(BundleRevision.class);
+ if (revision != null && revision.getWiring() == null) {
+ targetTriggers.add(revision);
+ }
+ }
+
+ }
+ volatile ResolutionReport report = null;
+ class DiagResolverHook implements ResolverHook, ResolutionReport.Listener {
+
+ public void handleResolutionReport(ResolutionReport report) {
+ DiagReportListener.this.report = report;
+ }
+
+ public void filterResolvable(Collection<BundleRevision> candidates) {
+ // nothing
+ }
+
+ public void filterSingletonCollisions(BundleCapability singleton,
+ Collection<BundleCapability> collisionCandidates) {
+ // nothing
+ }
+
+ public void filterMatches(BundleRequirement requirement,
+ Collection<BundleCapability> candidates) {
+ // nothing
+ }
+
+ public void end() {
+ // nothing
+ }
+
+ }
+ public ResolverHook begin(Collection<BundleRevision> triggers) {
+ if (triggers.containsAll(targetTriggers)) {
+ return new DiagResolverHook();
+ }
+ return null;
+ }
+ ResolutionReport getReport() {
+ return report;
+ }
}
/**
diff --git a/bundles/org.eclipse.equinox.security.ui/plugin.xml b/bundles/org.eclipse.equinox.security.ui/plugin.xml
index 7f9233e..21ae2e3 100644
--- a/bundles/org.eclipse.equinox.security.ui/plugin.xml
+++ b/bundles/org.eclipse.equinox.security.ui/plugin.xml
@@ -11,17 +11,6 @@
</extension>
-<!--
- <extension point="org.eclipse.ui.preferencePages">
- <page
- name="%certificates"
- class="org.eclipse.equinox.internal.security.ui.preferences.CertificatesPage"
- id="org.eclipse.equinox.security.ui.certificates"
- category="org.eclipse.equinox.security.ui.category">
- </page>
- </extension>
--->
-
<extension point="org.eclipse.ui.preferencePages">
<page
name="%storage"
@@ -40,23 +29,6 @@
</page>
</extension>
-
-<!--
- <extension
- point="org.eclipse.ui.importWizards">
- <wizard
- category="org.eclipse.ui.Basic"
- class="org.eclipse.equinox.internal.security.ui.wizard.CertificateImportWizard"
- icon="icons/full/obj16/signed_yes_tbl.gif"
- id="org.eclipse.equinox.security.ui.importWizards.ImportWizard"
- name="%certificateFile">
- <description>
- %certificateFileDescription
- </description>
- <selection class="org.eclipse.core.resources.IResource" />
- </wizard>
- </extension>
--->
<!-- The default UI password provider -->
<extension
id="DefaultPasswordProvider"
diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/AdvancedPage.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/AdvancedPage.java
deleted file mode 100644
index f6c0b48..0000000
--- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/AdvancedPage.java
+++ /dev/null
@@ -1,464 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.security.ui.preferences;
-
-import java.security.Provider;
-import java.security.Security;
-import java.util.*;
-import java.util.List;
-import org.eclipse.equinox.internal.security.ui.SecurityUIMsg;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.jface.viewers.*;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.osgi.framework.Bundle;
-
-public class AdvancedPage extends PreferencePage implements IWorkbenchPreferencePage {
-
- private static final String ALG_ALIAS = "Alg.Alias."; //$NON-NLS-1$
- private static final String PROVIDER = "Provider."; //$NON-NLS-1$
-
- TreeViewer providerViewer;
- Combo providerCombo;
- Label versionText;
- Label descriptionText;
-
- public AdvancedPage() {
- //empty
- }
-
- public void init(IWorkbench workbench) {
- this.noDefaultAndApplyButton();
- }
-
- protected Control createContents(Composite parent) {
-
- Composite area = new Composite(parent, SWT.NONE);
- area.setLayout(new FormLayout());
-
- Label providerLabel = new Label(area, SWT.NONE);
- providerLabel.setText(SecurityUIMsg.ADVPAGE_LABEL_PROVIDER);
- FormData data = new FormData();
- data.top = new FormAttachment(0, 0);
- providerLabel.setData(data);
-
- providerCombo = new Combo(area, SWT.DROP_DOWN | SWT.READ_ONLY);
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- data.left = new FormAttachment(providerLabel, 0);
- //data.right = new FormAttachment(100, 0);
- //data.height = 5 * providerCombo.getItemHeight();
- data.width = 100;
- providerCombo.setLayoutData(data);
-
- Provider[] providers = Security.getProviders();
- for (int i = 0; i < providers.length; i++) {
- providerCombo.add(i + ": " + providers[i].getName()); //$NON-NLS-1$
- }
- providerCombo.setVisibleItemCount(providers.length);
- providerCombo.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- Provider provider = Security.getProviders()[providerCombo.getSelectionIndex()];
- providerViewer.setInput(getContent(provider));
- versionText.setText(String.valueOf(provider.getVersion()));
- descriptionText.setText(provider.getInfo());
- }
- });
-
- /*
- Link link = new Link(area, SWT.NONE);
- link.setText(SecurityUIMsg.ADVPAGE_LABEL_LINK);
- link.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- //todo
- }
- });
-
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- data.right = new FormAttachment(100, 0);
- link.setLayoutData(data);
- */
-
- Label versionLabel = new Label(area, SWT.NONE);
- versionLabel.setText(SecurityUIMsg.ADVPAGE_LABEL_VERSION);
- data = new FormData();
- data.top = new FormAttachment(providerCombo, 0);
- data.left = new FormAttachment(0, 0);
- versionLabel.setLayoutData(data);
-
- versionText = new Label(area, SWT.NONE);
- data = new FormData();
- data.top = new FormAttachment(providerCombo, 0);
- data.left = new FormAttachment(versionLabel, 0);
- data.right = new FormAttachment(100, 0);
- versionText.setLayoutData(data);
-
- Label descriptionLabel = new Label(area, SWT.NONE);
- descriptionLabel.setText(SecurityUIMsg.ADVPAGE_LABEL_DESCRIPTION);
- data = new FormData();
- data.top = new FormAttachment(versionLabel, 0);
- data.left = new FormAttachment(0, 0);
- descriptionLabel.setLayoutData(data);
-
- descriptionText = new Label(area, SWT.NONE);
- data = new FormData();
- data.top = new FormAttachment(versionText, 0);
- data.left = new FormAttachment(versionLabel, 0);
- data.right = new FormAttachment(100, 0);
- data.width = 250;
- descriptionText.setLayoutData(data);
-
- Group serviceGroup = new Group(area, SWT.NONE);
- serviceGroup.setText(SecurityUIMsg.ADVPAGE_LABEL_SERVICES);
- data = new FormData();
- data.top = new FormAttachment(descriptionLabel, 0);
- data.bottom = new FormAttachment(100, 0);
- data.left = new FormAttachment(0, 0);
- data.right = new FormAttachment(100, 0);
- serviceGroup.setLayoutData(data);
-
- serviceGroup.setLayout(new FormLayout());
-
- providerViewer = new TreeViewer(serviceGroup);
- providerViewer.setContentProvider(new ProviderContentProvider());
- providerViewer.setLabelProvider(new ProviderLabelProvider());
- Tree tree = (Tree) providerViewer.getControl();
-
- data = new FormData();
- data.top = new FormAttachment(0, 5);
- data.left = new FormAttachment(0, 5);
- data.right = new FormAttachment(100, -5);
- data.bottom = new FormAttachment(100, -5);
- data.height = (10 * tree.getItemHeight()) + tree.getHeaderHeight();
- providerViewer.getControl().setLayoutData(data);
-
- providerCombo.select(0);
- Provider provider = Security.getProviders()[0];
- providerViewer.setInput(getContent(provider));
- versionText.setText(String.valueOf(provider.getVersion()));
- descriptionText.setText(provider.getInfo());
-
- return area;
- }
-
- Object[] getContent(Provider provider) {
-
- Set providerKeys = provider.keySet();
- Hashtable serviceList = new Hashtable();
- Hashtable attributeMap = new Hashtable(); // "type" => "Hashtable of (attribute,value) pairs"
- Hashtable aliasMap = new Hashtable(); // "type" => "Arraylist of aliases"
- for (Iterator it = providerKeys.iterator(); it.hasNext();) {
- String key = (String) it.next();
-
- // this is provider info, available off the Provider API
- if (key.startsWith(PROVIDER)) {
- continue;
- }
-
- // this is an alias
- if (key.startsWith(ALG_ALIAS)) {
- String value = key.substring(key.indexOf(ALG_ALIAS) + ALG_ALIAS.length(), key.length());
- String type = (String) provider.get(key);
- String algo = value.substring(0, value.indexOf('.'));
- String alias = value.substring(value.indexOf('.') + 1, value.length());
- ArrayList aliasList = (ArrayList) aliasMap.get(type + '.' + algo);
- if (aliasList == null) {
- aliasList = new ArrayList();
- aliasList.add(alias);
- aliasMap.put(type, aliasList);
- } else {
- aliasList.add(alias);
- }
- }
-
- // this is an attribute
- else if (key.indexOf(' ') > -1) {
- String type = key.substring(0, key.indexOf('.'));
- String algorithm = key.substring(key.indexOf('.') + 1, key.indexOf(' '));
- String attribute = key.substring(key.indexOf(' ') + 1, key.length());
- String value = (String) provider.get(key);
- Hashtable attributeTable = (Hashtable) attributeMap.get(type + '.' + algorithm);
- if (attributeTable == null) {
- attributeTable = new Hashtable();
- attributeTable.put(attribute, value);
- attributeMap.put(type + '.' + algorithm, attributeTable);
- } else {
- attributeTable.put(attribute, value);
- }
- }
-
- // else this is a service
- else {
- serviceList.put(key, provider.get(key));
- }
- }
-
- ProviderService[] serviceArray = new ProviderService[serviceList.size()];
- Set serviceKeys = serviceList.keySet();
- int serviceCount = 0;
- for (Iterator it = serviceKeys.iterator(); it.hasNext();) {
- String key = (String) it.next();
- String type = key.substring(0, key.indexOf('.'));
- String algo = key.substring(key.indexOf('.') + 1, key.length());
- String className = (String) serviceList.get(key);
- List aliases = (List) aliasMap.get(algo);
- Map attributes = (Map) attributeMap.get(key);
-
- serviceArray[serviceCount] = new ProviderService(type, algo, className, aliases, attributes, null);
- serviceCount++;
- }
-
- // sort the provider services
- Arrays.sort(serviceArray, new Comparator() {
- public int compare(Object arg0, Object arg1) {
- ProviderService s0 = (ProviderService) arg0;
- ProviderService s1 = (ProviderService) arg1;
- return s0.getType().compareTo(s1.getType());
- }
- });
-
- return serviceArray;
- }
-
- class ProviderContentProvider implements ITreeContentProvider {
-
- public Object[] getElements(Object inputElement) {
- Object[] returnValue = null;
- if (inputElement instanceof ProviderService[]) {
- returnValue = (Object[]) inputElement;
- }
- return returnValue;
- }
-
- public Object getParent(Object element) {
- Object returnValue = null;
- if (element instanceof ProviderServiceDetail) {
- returnValue = ((ProviderServiceDetail) element).getParent();
- }
- return returnValue;
- }
-
- public Object[] getChildren(Object parentElement) {
- Object[] returnValue = null;
- if (parentElement instanceof ProviderService) {
- ProviderService service = (ProviderService) parentElement;
- ArrayList detailList = new ArrayList();
- detailList.add(new ProviderServiceDetail(service, TYPE_CLASSNAME, service.getClassName()));
- if (service.getAliases() != null) {
- detailList.add(new ProviderServiceDetail(service, TYPE_ALIASES, service.getAliases()));
- }
- if (service.getAttributes() != null) {
- detailList.add(new ProviderServiceDetail(service, TYPE_ATTRIBUTES, service.getAttributes()));
- }
- returnValue = detailList.toArray(new ProviderServiceDetail[] {});
- } else if (parentElement instanceof ProviderServiceDetail) {
- returnValue = ((ProviderServiceDetail) parentElement).getChildren();
- }
- return returnValue;
- }
-
- public boolean hasChildren(Object element) {
- boolean returnValue = false;
- if (element instanceof ProviderService) {
- returnValue = true;
- } else if (element instanceof ProviderServiceDetail) {
- returnValue = ((ProviderServiceDetail) element).hasChildren();
- }
- return returnValue;
- }
-
- public void dispose() {
- //nothing to do
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- //empty
- }
- }
-
- class ProviderLabelProvider implements ILabelProvider {
-
- public Image getImage(Object element) {
- return null;
- }
-
- public String getText(Object element) {
- String returnValue = null;
- if (element instanceof String) {
- returnValue = (String) element;
- } else if (element instanceof ProviderService) {
- ProviderService service = (ProviderService) element;
- returnValue = service.getType() + ": " + service.getAlgorithm(); //$NON-NLS-1$
- } else if (element instanceof ProviderServiceDetail) {
- ProviderServiceDetail detail = (ProviderServiceDetail) element;
- returnValue = detail.toString();
- } else if (element instanceof ProviderServiceAttribute) {
- ProviderServiceAttribute attribute = (ProviderServiceAttribute) element;
- returnValue = attribute.toString();
- }
- return returnValue;
- }
-
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- public void addListener(ILabelProviderListener listener) {
- //empty
- }
-
- public void removeListener(ILabelProviderListener listener) {
- //empty
- }
-
- public void dispose() {
- //empty
- }
- }
-
- private class ProviderService {
- private final String type;
- private final String algorithm;
- private final String className;
- private final List aliases;
- private final Map attributes;
-
- public ProviderService(String type, String algorithm, String className, List aliases, Map attributes, Bundle providingBundle) {
- this.type = type;
- this.algorithm = algorithm;
- this.className = className;
- this.aliases = aliases;
- this.attributes = attributes;
- }
-
- public String getType() {
- return type;
- }
-
- public String getAlgorithm() {
- return algorithm;
- }
-
- public String getClassName() {
- return className;
- }
-
- public List getAliases() {
- return aliases;
- }
-
- public Map getAttributes() {
- return attributes;
- }
- }
-
- // private static final int TYPE_ALGORITHM = 0;
- // private static final int TYPE_TYPE = 1;
- // private static final int TYPE_BUNDLEID = 2;
- private static final int TYPE_CLASSNAME = 3;
- private static final int TYPE_ALIASES = 4;
- private static final int TYPE_ATTRIBUTES = 5;
-
- private class ProviderServiceDetail {
-
- ProviderService parent;
- int type;
- Object data;
-
- ProviderServiceDetail(ProviderService parent, int type, Object data) {
- this.parent = parent;
- this.type = type;
- this.data = data;
- }
-
- int getType() {
- return type;
- }
-
- Object getData() {
- return data;
- }
-
- ProviderService getParent() {
- return parent;
- }
-
- public String toString() {
- String returnValue = null;
- switch (getType()) {
- case TYPE_CLASSNAME :
- returnValue = SecurityUIMsg.ADVPAGE_LABEL_CLASS + (String) getData();
- break;
-
- case TYPE_ALIASES :
- StringBuffer buffer = new StringBuffer();
- buffer.append(SecurityUIMsg.ADVPAGE_LABEL_ALIASES);
- String[] aliases = (String[]) ((List) getData()).toArray(new String[] {});
- for (int i = 0; i < aliases.length; i++) {
- buffer.append(aliases[i]);
- if (i < aliases.length - 1) {
- buffer.append(", "); //$NON-NLS-1$
- }
- }
- returnValue = buffer.toString();
- break;
-
- case TYPE_ATTRIBUTES :
- returnValue = SecurityUIMsg.ADVPAGE_LABEL_ATTRIBUTES;
- break;
- }
- return returnValue;
- }
-
- boolean hasChildren() {
- boolean returnValue = false;
- if (getType() == TYPE_ATTRIBUTES) {
- returnValue = true;
- }
- return returnValue;
- }
-
- Object[] getChildren() {
- Object[] returnValue = null;
- if (getType() == TYPE_ATTRIBUTES) {
- Map attributeMap = (Map) getData();
- ArrayList attributeList = new ArrayList();
- for (Iterator it = attributeMap.keySet().iterator(); it.hasNext();) {
- String key = (String) it.next();
- String value = (String) attributeMap.get(key);
- attributeList.add(new ProviderServiceAttribute(key, value));
- }
- returnValue = attributeList.toArray(new ProviderServiceAttribute[] {});
- }
- return returnValue;
- }
- }
-
- private class ProviderServiceAttribute {
-
- String key;
- String value;
-
- public ProviderServiceAttribute(String key, String value) {
- this.key = key;
- this.value = value;
- }
-
- public String toString() {
- return key + ": " + value; //$NON-NLS-1$
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/CertificatesPage.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/CertificatesPage.java
deleted file mode 100644
index 6e56dd2..0000000
--- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/CertificatesPage.java
+++ /dev/null
@@ -1,437 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.security.ui.preferences;
-
-import java.security.cert.Certificate;
-import java.security.cert.X509Certificate;
-import java.util.*;
-import org.eclipse.equinox.internal.provisional.security.ui.X500PrincipalHelper;
-import org.eclipse.equinox.internal.provisional.security.ui.X509CertificateViewDialog;
-import org.eclipse.equinox.internal.security.ui.*;
-import org.eclipse.equinox.internal.security.ui.wizard.CertificateImportWizard;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.jface.viewers.*;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.osgi.service.security.TrustEngine;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-
-//potential enhancements
-//
-public class CertificatesPage extends PreferencePage implements IWorkbenchPreferencePage {
-
- private static final int VIEW_ISSUE_TO_COLUMN_INDEX = 0;
- private static final int VIEW_ISSUE_BY_COLUMN_INDEX = 1;
- private static final int VIEW_PROVIDER_COLUMN_INDEX = 2;
-
- TrustEngine[] activeTrustEngines;
- TableViewer tableViewer;
- Table tableCert;
- CertRowEntry currentSelection;
- Button removeBtn;
- Button viewButton;
-
- private class CertTableSorter implements Listener {
-
- final int columnSelected;
- private final CertRowEntry[] certRowEntry;
-
- CertTableSorter(final int columnSelected, final CertRowEntry[] certRowEntry) {
- this.columnSelected = columnSelected;
- this.certRowEntry = certRowEntry;
- }
-
- public void handleEvent(Event e) {
-
- // get the sort column and figure out the direction
- TableColumn sortColumn = tableCert.getSortColumn();
- TableColumn currentColumn = (TableColumn) e.widget;
- int dir = tableCert.getSortDirection();
-
- if (sortColumn == currentColumn) {
- dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
- } else {
- tableCert.setSortColumn(currentColumn);
- dir = SWT.UP;
- }
-
- final int direction = dir;
- Arrays.sort(certRowEntry, new Comparator() {
- public int compare(Object arg0, Object arg1) {
-
- if (columnSelected == VIEW_ISSUE_TO_COLUMN_INDEX) {
- String issueTo1 = getSubjectCommonName(((CertRowEntry) arg0).cert);
- String issueTo2 = getSubjectCommonName(((CertRowEntry) arg1).cert);
- if (direction == SWT.UP)
- return issueTo1.compareTo(issueTo2);
- return issueTo2.compareTo(issueTo1);
-
- } else if (columnSelected == VIEW_ISSUE_BY_COLUMN_INDEX) {
- String issueOrg1 = getIssuerOrg(((CertRowEntry) arg0).cert);
- String issueOrg2 = getIssuerOrg(((CertRowEntry) arg1).cert);
- if (direction == SWT.UP)
- return issueOrg1.compareTo(issueOrg2);
- return issueOrg2.compareTo(issueOrg1);
- } else {
- String provider1 = activeTrustEngines[((CertRowEntry) arg0).trustEngineIndex].getName();
- String provider2 = activeTrustEngines[((CertRowEntry) arg1).trustEngineIndex].getName();
- if (direction == SWT.UP)
- return provider1.compareTo(provider2);
- return provider2.compareTo(provider1);
- }
- }
- });
- // update data displayed in table
- tableCert.setSortDirection(dir);
- tableCert.clearAll();
- tableViewer.setInput(certRowEntry);
- }
- }
-
- public CertificatesPage() {
- //empty
- }
-
- public void init(IWorkbench workbench) {
- this.noDefaultAndApplyButton();
- }
-
- protected Control createContents(Composite parent) {
- initTrustEngines();
-
- Composite page = new Composite(parent, SWT.NONE);
- FormLayout layout = new FormLayout();
- page.setLayout(layout);
-
- Label titleLabel = new Label(page, SWT.NONE);
- titleLabel.setText(SecurityUIMsg.CERTPAGE_LABEL_TITLE);
-
- FormData data = new FormData();
- data.top = new FormAttachment(0, 0);
- //data.bottom = new FormAttachment(100, 0);
- data.left = new FormAttachment(0, 0);
- //data.right = new FormAttachment(100, 0);
- //data.width = 100;
- titleLabel.setLayoutData(data);
-
- Link link = new Link(page, SWT.NONE);
- link.setText(SecurityUIMsg.CERTPAGE_LABEL_LINK);
- link.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- //todo
- }
- });
-
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- //data.bottom = new FormAttachment(100, 0);
- //data.left = new FormAttachment(tableArea, 0);
- data.right = new FormAttachment(100, 0);
- //data.width = 100;
- link.setLayoutData(data);
-
- Label tableLabel = new Label(page, SWT.NONE);
- tableLabel.setText(SecurityUIMsg.CERTPAGE_TABLE_LABEL);
-
- data = new FormData();
- data.top = new FormAttachment(titleLabel, 10);
- //data.bottom = new FormAttachment(100, 0);
- data.left = new FormAttachment(0, 0);
- //data.right = new FormAttachment(100, 0);
- //data.width = 100;
- tableLabel.setLayoutData(data);
-
- Composite tableArea = new Composite(page, SWT.NONE);
- FormLayout tableLayout = new FormLayout();
- tableArea.setLayout(tableLayout);
-
- Composite buttonArea = new Composite(page, SWT.NONE);
- FormLayout buttonLayout = new FormLayout();
- buttonArea.setLayout(buttonLayout);
-
- data = new FormData();
- data.top = new FormAttachment(tableLabel, 5);
- data.bottom = new FormAttachment(100, 0);
- //data.left = new FormAttachment(tableArea, 0);
- data.right = new FormAttachment(100, 0);
- //data.width = 100;
- buttonArea.setLayoutData(data);
-
- data = new FormData();
- data.top = new FormAttachment(tableLabel, 5);
- data.bottom = new FormAttachment(100, 0);
- data.left = new FormAttachment(0, 0);
- data.right = new FormAttachment(buttonArea, 0);
- tableArea.setLayoutData(data);
-
- tableViewer = new TableViewer(tableArea, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
- tableCert = (Table) tableViewer.getControl();
- tableCert.setHeaderVisible(true);
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- data.bottom = new FormAttachment(100, 0);
- data.left = new FormAttachment(0, 0);
- data.right = new FormAttachment(100, 0);
- data.height = (10 * tableCert.getItemHeight());
- tableCert.setLayoutData(data);
-
- TableColumn column1 = new TableColumn(tableCert, SWT.NULL);
- column1.setText(SecurityUIMsg.CERTPAGE_TABLE_HEADER_ISSUEDTO);
- column1.setWidth(200);
- column1.addListener(SWT.Selection, new CertTableSorter(VIEW_ISSUE_TO_COLUMN_INDEX, getCertificates()));
-
- TableColumn column2 = new TableColumn(tableCert, SWT.NULL);
- column2.setText(SecurityUIMsg.CERTPAGE_TABLE_HEADER_ISSUEDBY);
- column2.setWidth(200);
- column2.addListener(SWT.Selection, new CertTableSorter(VIEW_ISSUE_BY_COLUMN_INDEX, getCertificates()));
-
- TableColumn column3 = new TableColumn(tableCert, SWT.NULL);
- column3.setText(SecurityUIMsg.CERTPAGE_TABLE_HEADER_PROVIDER);
- column3.setWidth(200);
- column3.addListener(SWT.Selection, new CertTableSorter(VIEW_PROVIDER_COLUMN_INDEX, getCertificates()));
-
- Button button1 = new Button(buttonArea, SWT.PUSH);
- button1.setText(SecurityUIMsg.CERTPAGE_BUTTON_IMPORT);
- button1.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- //do nothing
- }
-
- public void widgetSelected(SelectionEvent e) {
- openImportWizard();
- }
-
- });
-
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- //data.bottom = new FormAttachment(100, 0);
- data.left = new FormAttachment(0, 5);
- data.right = new FormAttachment(100, 0);
- data.width = 100;
- data.height = 25;
- button1.setLayoutData(data);
-
- Button button2 = new Button(buttonArea, SWT.PUSH);
- button2.setText(SecurityUIMsg.CERTPAGE_BUTTON_EXPORT);
- data = new FormData();
- data.top = new FormAttachment(button1, 5);
- //data.bottom = new FormAttachment(100, 0);null
- data.left = new FormAttachment(0, 5);
- //data.right = new FormAttachment(100, 0);
- data.width = 100;
- data.height = 25;
- button2.setLayoutData(data);
-
- viewButton = new Button(buttonArea, SWT.PUSH);
- viewButton.setText(SecurityUIMsg.CERTPAGE_BUTTON_VIEW);
- viewButton.setEnabled(false);
- data = new FormData();
- data.top = new FormAttachment(button2, 5);
- //data.bottom = new FormAttachment(100, 0);null
- data.left = new FormAttachment(0, 5);
- //data.right = new FormAttachment(100, 0);
- data.width = 100;
- data.height = 25;
- viewButton.setLayoutData(data);
-
- viewButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- // TODO Auto-generated method stub
- }
-
- public void widgetSelected(SelectionEvent e) {
- X509CertificateViewDialog certViewer = new X509CertificateViewDialog(tableViewer.getTable().getShell(), (X509Certificate) currentSelection.cert);
- certViewer.open();
- }
- });
-
- removeBtn = new Button(buttonArea, SWT.PUSH);
- removeBtn.setEnabled(false);
- removeBtn.setText(SecurityUIMsg.CERTPAGE_BUTTON_REMOVE);
- data = new FormData();
- data.top = new FormAttachment(viewButton, 5);
- //data.bottom = new FormAttachment(100, 0);
- data.left = new FormAttachment(0, 5);
- data.right = new FormAttachment(100, 0);
- data.width = 100;
- data.height = 25;
- removeBtn.setLayoutData(data);
- removeBtn.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- // TODO Auto-generated method stub
- }
-
- public void widgetSelected(SelectionEvent e) {
- removeSelected();
- }
- });
-
- initTrustEngines();
- tableViewer.setContentProvider(new SystemCertificatesContentProvider());
- tableViewer.setLabelProvider(new SystemCertificatesLabelProvider(activeTrustEngines));
- tableViewer.setInput(getCertificates());
- tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- if (event.getSelection() instanceof IStructuredSelection) {
- viewButton.setEnabled(true);
- currentSelection = (CertRowEntry) ((IStructuredSelection) event.getSelection()).getFirstElement();
- if (null != currentSelection && !activeTrustEngines[currentSelection.trustEngineIndex].isReadOnly()) {
- removeBtn.setEnabled(true);
-
- }
- }
-
- }
- });
-
- return page;
- }
-
- protected void openImportWizard() {
- CertificateImportWizard wizard = new CertificateImportWizard();
- WizardDialog dialog = new WizardDialog(getShell(), wizard);
- dialog.create();
- if (dialog.open() == 0) {
- // reload the table viewer
- tableViewer.setInput(getCertificates());
- }
- }
-
- void removeSelected() {
- try {
- // get the confirmation first
- ConfirmationDialog confirmationDilaog = new ConfirmationDialog(tableViewer.getTable().getShell(), currentSelection.cert);
- if (confirmationDilaog.open() == ConfirmationDialog.YES) {
- activeTrustEngines[currentSelection.trustEngineIndex].removeTrustAnchor(currentSelection.cert);
- tableViewer.setInput(getCertificates());
- removeBtn.setEnabled(false);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private CertRowEntry[] getCertificates() {
- ArrayList certs = new ArrayList();
- try {
- for (int i = 0; i < activeTrustEngines.length; i++) {
- String[] aliases = activeTrustEngines[i].getAliases();
- for (int j = 0; j < aliases.length; j++) {
- CertRowEntry certRowEntry = new CertRowEntry(activeTrustEngines[i].getTrustAnchor(aliases[j]), i);
- certs.add(certRowEntry);
- }
- }
- return (CertRowEntry[]) certs.toArray(new CertRowEntry[] {});
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- private void initTrustEngines() {
- if (activeTrustEngines == null) {
- activeTrustEngines = Activator.getTrustEngines();
- }
- }
-
- private class CertRowEntry {
- public Certificate cert;
- public int trustEngineIndex;
-
- public CertRowEntry(Certificate cert, int trustIndex) {
- this.cert = cert;
- this.trustEngineIndex = trustIndex;
- }
- }
-
- class SystemCertificatesContentProvider implements IStructuredContentProvider {
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // TODO Auto-generated method stub
- }
-
- public Object[] getElements(Object inputElement) {
-
- if (inputElement instanceof CertRowEntry[]) {
- return (Object[]) inputElement;
- }
- throw new IllegalArgumentException();
- }
-
- public void dispose() {
- //nothing to dispose
- }
- }
-
- class SystemCertificatesLabelProvider extends LabelProvider implements ITableLabelProvider {
-
- private TrustEngine[] tEngines;
-
- public SystemCertificatesLabelProvider(TrustEngine[] engines) {
- this.tEngines = engines;
- }
-
- public Image getColumnImage(Object element, int columnIndex) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- String label = null;
- CertRowEntry certRowEntry = (CertRowEntry) element;
- switch (columnIndex) {
- case 0 :
- label = getSubjectCommonName(certRowEntry.cert);
- break;
-
- case 1 :
- label = getIssuerOrg(certRowEntry.cert);
- break;
-
- case 2 :
- label = tEngines[certRowEntry.trustEngineIndex].getName();
- break;
-
- default :
- break;
- }
- return label;
- }
- }
-
- static String getSubjectCommonName(Certificate cert) {
- if (cert instanceof X509Certificate) {
- X500PrincipalHelper cnHelper = new X500PrincipalHelper(((X509Certificate) cert).getSubjectX500Principal());
- //If there isn't a CN attribute, return the OU instead
- return (cnHelper.getCN() != null ? cnHelper.getCN() : cnHelper.getOU());
- }
- return SecurityUIMsg.CERTPAGE_ERROR_UNKNOWN_FORMAT;
- }
-
- static String getIssuerOrg(Certificate cert) {
- if (cert instanceof X509Certificate) {
- X500PrincipalHelper cnHelper = new X500PrincipalHelper(((X509Certificate) cert).getIssuerX500Principal());
- String retOrg = (cnHelper.getO() != null ? cnHelper.getO() : cnHelper.getOU());
- return retOrg;
- }
- return SecurityUIMsg.CERTPAGE_ERROR_UNKNOWN_FORMAT;
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/PolicyPage.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/PolicyPage.java
deleted file mode 100644
index 735b60f..0000000
--- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/PolicyPage.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.security.ui.preferences;
-
-import org.eclipse.equinox.internal.security.ui.Activator;
-import org.eclipse.equinox.internal.security.ui.SecurityUIMsg;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.osgi.internal.provisional.service.security.AuthorizationEngine;
-import org.eclipse.osgi.internal.service.security.DefaultAuthorizationEngine;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-
-public class PolicyPage extends PreferencePage implements IWorkbenchPreferencePage {
-
- Button anyButton;
- Button anysignedButton;
- Button onlytrustedButton;
- Button expiredButton;
- //TabFolder folder;
- private int selectedPolicy;
- private static final int BIT_TRUST_EXPIRED = DefaultAuthorizationEngine.ENFORCE_VALIDITY | DefaultAuthorizationEngine.ENFORCE_TRUSTED | DefaultAuthorizationEngine.ENFORCE_SIGNED;
- private static final int BIT_TRUST = DefaultAuthorizationEngine.ENFORCE_TRUSTED | DefaultAuthorizationEngine.ENFORCE_SIGNED;
-
- protected Control createContents(Composite parent) {
-
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout compositeLayout = new GridLayout();
- compositeLayout.marginWidth = 0;
- compositeLayout.marginHeight = 0;
- composite.setLayout(compositeLayout);
- composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
-
- //Group gives nice box around the radio buttons
- Group buttonGroup = new Group(composite, SWT.LEFT);
- GridLayout buttonLayout = new GridLayout();
- buttonGroup.setLayout(buttonLayout);
- GridData compositeData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
- buttonGroup.setLayoutData(compositeData);
- buttonGroup.setText(SecurityUIMsg.POLPAGE_LABEL_DESC);
-
- anyButton = new Button(buttonGroup, SWT.RADIO);
- anysignedButton = new Button(buttonGroup, SWT.RADIO);
- onlytrustedButton = new Button(buttonGroup, SWT.RADIO);
-
- expiredButton = new Button(buttonGroup, SWT.CHECK);
- expiredButton.setEnabled(true); //since onlytrustedButton is default on
-
- GridData data = new GridData();
- data.horizontalIndent = 20;
- expiredButton.setLayoutData(data);
-
- expiredButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- //do nothing
- }
-
- public void widgetSelected(SelectionEvent event) {
- if (expiredButton.getSelection())
- persistPolicySetting(DefaultAuthorizationEngine.ENFORCE_VALIDITY | DefaultAuthorizationEngine.ENFORCE_TRUSTED | DefaultAuthorizationEngine.ENFORCE_SIGNED);
- else
- persistPolicySetting(DefaultAuthorizationEngine.ENFORCE_TRUSTED | DefaultAuthorizationEngine.ENFORCE_SIGNED);
- }
-
- });
-
- // select the default authorization engine
- AuthorizationEngine authEngine = Activator.getAuthorizationEngine();
- // check if osgi.signedcontent.support property is enable
- if (System.getProperty("osgi.signedcontent.support") != null && authEngine instanceof DefaultAuthorizationEngine) {
- DefaultAuthorizationEngine defaultAuthEngine = (DefaultAuthorizationEngine) authEngine;
- selectedPolicy = defaultAuthEngine.getLoadPolicy();
-
- if ((selectedPolicy & BIT_TRUST_EXPIRED) == BIT_TRUST_EXPIRED) {
- onlytrustedButton.setSelection(true);
- expiredButton.setSelection(true);
- expiredButton.setEnabled(true);
- } else if ((selectedPolicy & BIT_TRUST) == BIT_TRUST) {
- onlytrustedButton.setSelection(true);
- expiredButton.setEnabled(true);
- } else if ((selectedPolicy & DefaultAuthorizationEngine.ENFORCE_SIGNED) == DefaultAuthorizationEngine.ENFORCE_SIGNED)
- anysignedButton.setSelection(true);
- else
- anyButton.setSelection(true);
- } else {
- anyButton.setSelection(true);
- }
-
- anyButton.setText(SecurityUIMsg.POLPAGE_BUTTON_ALLOW_ANY);
- anyButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- //do nothing
- }
-
- public void widgetSelected(SelectionEvent event) {
- expiredButton.setEnabled(false);
- expiredButton.setSelection(false);
- persistPolicySetting(DefaultAuthorizationEngine.ENFORCE_NONE);
- }
- });
-
- anysignedButton.setText(SecurityUIMsg.POLPAGE_BUTTON_ALLOW_ANY_SIGNED);
- anysignedButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- //do nothing
- }
-
- public void widgetSelected(SelectionEvent event) {
- expiredButton.setSelection(false);
- expiredButton.setEnabled(false);
- persistPolicySetting(DefaultAuthorizationEngine.ENFORCE_SIGNED);
- }
- });
-
- onlytrustedButton.setText(SecurityUIMsg.POLPAGE_BUTTON_ALLOW_ONLY_TRUSTED);
- onlytrustedButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- //do nothing
- }
-
- public void widgetSelected(SelectionEvent event) {
- expiredButton.setEnabled(true);
- persistPolicySetting(DefaultAuthorizationEngine.ENFORCE_TRUSTED | DefaultAuthorizationEngine.ENFORCE_SIGNED);
- }
-
- });
-
- /*
- whitelistButton.setText(STR_whiteList);
- whitelistButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- //do nothing
- }
-
- public void widgetSelected(SelectionEvent event) {
- whitelistTable.setEnabled(true);
- promptButton.setEnabled(true);
- }
-
- });
- data = new FormData();
- data.top = new FormAttachment(anytrustedButton, 2);
- data.left = new FormAttachment(0, 5);
- whitelistButton.setLayoutData(data);
-
- Composite whitelistArea = new Composite(loadArea, SWT.NONE);
- whitelistArea.setLayout(new FormLayout());
-
- data = new FormData();
- data.top = new FormAttachment(whitelistButton, 2);
- data.left = new FormAttachment(0, 25);
- data.bottom = new FormAttachment(promptButton, -2);
- data.right = new FormAttachment(100, 0);
- whitelistArea.setLayoutData(data);
-
- Button addButton = new Button(whitelistArea, SWT.PUSH);
- addButton.setText("Add...");
-
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- data.right = new FormAttachment(100, -5);
- data.width = 100;
- data.height = 25;
- addButton.setLayoutData(data);
-
- Button removeButton = new Button(whitelistArea, SWT.PUSH);
- removeButton.setText("Remove");
-
- data = new FormData();
- data.top = new FormAttachment(addButton, 5);
- data.right = new FormAttachment(100, -5);
- data.width = 100;
- data.height = 25;
- removeButton.setLayoutData(data);
-
- whitelistTable = new Table(whitelistArea, SWT.BORDER | SWT.V_SCROLL);
- whitelistTable.setEnabled(false);
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- data.left = new FormAttachment(0, 0);
- data.bottom = new FormAttachment(100, 0);
- data.right = new FormAttachment(addButton, -5);
- data.height = whitelistTable.getItemHeight() * 5;
- whitelistTable.setLayoutData(data);
-
- promptButton.setText(STR_promptUntrusted);
- promptButton.setEnabled(false);
- data = new FormData();
- //data.top = new FormAttachment(whitelistTable, 10);
- data.bottom = new FormAttachment(expiredButton, 0);
- data.left = new FormAttachment(0, 5);
- promptButton.setLayoutData(data);
- */
- expiredButton.setText(SecurityUIMsg.POLPAGE_BUTTON_ALLOW_EXPIRED);
-
- // onlytrustedButton.setSelection(true);
- // expiredButton.setEnabled(true);
-
- return composite;
- }
-
- //protected void enableSecurityWidgets() {
- // folder.setEnabled(true);
- //}
-
- //protected void disableSecurityWidgets() {
- // folder.setEnabled(false);
- //}
-
- public boolean performOk() {
- // update the policy iff the page is dirty
- AuthorizationEngine authEngine = Activator.getAuthorizationEngine();
- if (authEngine instanceof DefaultAuthorizationEngine) {
- DefaultAuthorizationEngine defaultAuthEngine = (DefaultAuthorizationEngine) authEngine;
- defaultAuthEngine.setLoadPolicy(selectedPolicy);
- } else {
- // log the error
- }
-
- return super.performOk();
- }
-
- void persistPolicySetting(int policy) {
- selectedPolicy = policy;
- }
-
- public void init(IWorkbench workbench) {
- this.noDefaultAndApplyButton();
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/SecurityCategoryPage.java b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/SecurityCategoryPage.java
index b324b06..e696a19 100644
--- a/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/SecurityCategoryPage.java
+++ b/bundles/org.eclipse.equinox.security.ui/src/org/eclipse/equinox/internal/security/ui/preferences/SecurityCategoryPage.java
@@ -42,9 +42,6 @@
storageLinkArea.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
Dialog.applyDialogFont(pageArea);
- //PreferenceLinkArea certsLinkArea = new PreferenceLinkArea(pageArea, SWT.NONE, "org.eclipse.equinox.security.ui.certificates", SecurityUIMsg.CATPAGE_LABEL_CERTIFICATES, (IWorkbenchPreferenceContainer) getContainer(), null); //$NON-NLS-1$
- //certsLinkArea.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
-
return pageArea;
}
}
diff --git a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/CSVParser.java b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/CSVParser.java
index 6f197ef..223972a 100644
--- a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/CSVParser.java
+++ b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/CSVParser.java
@@ -17,6 +17,8 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
+import org.eclipse.osgi.internal.framework.EquinoxContainer;
+import org.eclipse.osgi.internal.log.EquinoxLogServices;
/**
* This class is used by the transformer hook to parse urls provided by transform developers that specifies the particular transforms that should be utilized for a particular transformer.
@@ -33,7 +35,7 @@
* @return an array of tuples derived from the contents of the file
* @throws IOException thrown if there are issues parsing the file
*/
- public static TransformTuple[] parse(URL transformMapURL) throws IOException {
+ public static TransformTuple[] parse(URL transformMapURL, EquinoxLogServices logServices) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(transformMapURL.openStream()));
String currentLine = null;
List list = new ArrayList();
@@ -61,14 +63,14 @@
tuple.transformerUrl = transformerURL;
list.add(tuple);
} catch (IOException e) {
- TransformerHook.log(FrameworkLogEntry.ERROR, "Could not add transform :" + transformerURL.toString(), e); //$NON-NLS-1$
+ logServices.log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Could not add transform :" + transformerURL.toString(), e); //$NON-NLS-1$
}
} catch (PatternSyntaxException e) {
- TransformerHook.log(FrameworkLogEntry.ERROR, "Could not add compile transform matching regular expression", e); //$NON-NLS-1$
+ logServices.log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Could not add compile transform matching regular expression", e); //$NON-NLS-1$
}
} catch (NoSuchElementException e) {
- TransformerHook.log(FrameworkLogEntry.ERROR, "Could not parse transform file record :" + currentLine, e); //$NON-NLS-1$
+ logServices.log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Could not parse transform file record :" + currentLine, e); //$NON-NLS-1$
}
}
return (TransformTuple[]) list.toArray(new TransformTuple[list.size()]);
diff --git a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformInstanceListData.java b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformInstanceListData.java
index 074a613..8be5f32 100644
--- a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformInstanceListData.java
+++ b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformInstanceListData.java
@@ -14,6 +14,7 @@
import java.io.IOException;
import java.net.URL;
import java.util.*;
+import org.eclipse.osgi.internal.log.EquinoxLogServices;
import org.osgi.framework.*;
import org.osgi.util.tracker.ServiceTracker;
@@ -44,16 +45,19 @@
* Map from bundle ID -> boolean representing whether or not a given bundle currently has any transforms registered against it.
*/
private Map bundleIdToTransformPresence = new HashMap();
+ private final EquinoxLogServices logServices;
/**
* Create a new transform list bound to the given context. If new transforms are registered against the given context the contents of this list will change.
* @param context the bundle context
+ * @param logServices
* @throws InvalidSyntaxException thrown if there's an issue listening for changes to the given transformer type
*/
- public TransformInstanceListData(BundleContext context) throws InvalidSyntaxException {
+ public TransformInstanceListData(BundleContext context, EquinoxLogServices logServices) throws InvalidSyntaxException {
super(context, context.createFilter("(&(objectClass=" //$NON-NLS-1$
+ URL.class.getName() + ")(" + TransformTuple.TRANSFORMER_TYPE //$NON-NLS-1$
+ "=*))"), null); //$NON-NLS-1$
+ this.logServices = logServices;
open();
}
@@ -128,7 +132,7 @@
URL url = (URL) getService(serviceReference);
TransformTuple[] transforms;
try {
- transforms = CSVParser.parse(url);
+ transforms = CSVParser.parse(url, logServices);
TransformTuple[] existing = (TransformTuple[]) transformerToTuple.get(type);
if (existing != null) {
TransformTuple[] newTransforms = new TransformTuple[existing.length + transforms.length];
diff --git a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformedBundleEntry.java b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformedBundleEntry.java
index 6a73d44..a35629a 100644
--- a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformedBundleEntry.java
+++ b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformedBundleEntry.java
@@ -14,8 +14,9 @@
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
+import org.eclipse.osgi.internal.framework.EquinoxContainer;
+import org.eclipse.osgi.storage.bundlefile.BundleEntry;
/**
* This class is capable of providing a transformed version of an entry contained within a base bundle entity.
@@ -85,9 +86,8 @@
stream = new ByteArrayInputStream(tempBuffer.toByteArray());
}
} catch (IOException e) {
- TransformerHook.log(FrameworkLogEntry.ERROR, "Problem calculating size of stream for file. Stream may now be corrupted : " //$NON-NLS-1$
+ bundleFile.getGeneration().getBundleInfo().getStorage().getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Problem calculating size of stream for file. Stream may now be corrupted : " //$NON-NLS-1$
+ getName(), e);
-
}
return tempBuffer.size();
diff --git a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformedBundleFile.java b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformedBundleFile.java
index f47adc5..5a348a2 100644
--- a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformedBundleFile.java
+++ b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformedBundleFile.java
@@ -16,12 +16,12 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.equinox.internal.transforms.LazyInputStream.InputStreamProvider;
-import org.eclipse.osgi.baseadaptor.BaseData;
-import org.eclipse.osgi.baseadaptor.bundlefile.*;
-import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
-import org.eclipse.osgi.internal.baseadaptor.AdaptorMsg;
-import org.eclipse.osgi.internal.baseadaptor.AdaptorUtil;
+import org.eclipse.osgi.internal.debug.Debug;
+import org.eclipse.osgi.internal.framework.EquinoxContainer;
+import org.eclipse.osgi.storage.BundleInfo.Generation;
+import org.eclipse.osgi.storage.*;
+import org.eclipse.osgi.storage.bundlefile.*;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
@@ -33,7 +33,8 @@
private final TransformerHook transformerHook;
private final BundleFile delegate;
- private final BaseData data;
+ private final Generation generation;
+ private final Debug debug;
/**
* Create a wrapped bundle file.
@@ -42,10 +43,16 @@
* @param data the original data
* @param delegate the original file
*/
- public TransformedBundleFile(TransformerHook transformerHook, BaseData data, BundleFile delegate) {
+ public TransformedBundleFile(TransformerHook transformerHook, Generation generation, BundleFile delegate) {
+ super(delegate.getBaseFile());
this.transformerHook = transformerHook;
- this.data = data;
+ this.generation = generation;
this.delegate = delegate;
+ this.debug = generation.getBundleInfo().getStorage().getConfiguration().getDebug();
+ }
+
+ Generation getGeneration() {
+ return generation;
}
public void close() throws IOException {
@@ -67,7 +74,7 @@
public BundleEntry getEntry(String path) {
final BundleEntry original = delegate.getEntry(path);
- if (data.getBundle() == null || path == null || original == null)
+ if (generation.getRevision() == null || path == null || original == null)
return original;
LazyInputStream stream = new LazyInputStream(new InputStreamProvider() {
@@ -76,7 +83,7 @@
return original.getInputStream();
}
});
- InputStream wrappedStream = getInputStream(stream, data.getBundle(), path);
+ InputStream wrappedStream = getInputStream(stream, generation.getRevision().getBundle(), path);
if (wrappedStream == null)
return original;
return new TransformedBundleEntry(this, original, wrappedStream);
@@ -111,8 +118,9 @@
try {
return transformer.getInputStream(inputStream, transformTuple.transformerUrl);
} catch (IOException e) {
- TransformerHook.log(FrameworkLogEntry.ERROR, "Problem obtaining transformed stream from transformer : " //$NON-NLS-1$
+ generation.getBundleInfo().getStorage().getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Problem obtaining transformed stream from transformer : " //$NON-NLS-1$
+ transformer.getClass().getName(), e);
+
}
}
}
@@ -153,7 +161,7 @@
if (nested != null) {
if (nested.exists()) {
/* the entry is already cached */
- if (Debug.DEBUG_GENERAL)
+ if (debug.DEBUG_GENERAL)
Debug.println("File already present: " + nested.getPath()); //$NON-NLS-1$
if (nested.isDirectory())
// must ensure the complete directory is extracted (bug
@@ -162,9 +170,9 @@
} else {
if (originalFile.isDirectory()) {
if (!nested.mkdirs()) {
- if (Debug.DEBUG_GENERAL)
+ if (debug.DEBUG_GENERAL)
Debug.println("Unable to create directory: " + nested.getPath()); //$NON-NLS-1$
- throw new IOException(NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, nested.getAbsolutePath()));
+ throw new IOException(NLS.bind(StorageMsg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, nested.getAbsolutePath()));
}
extractDirectory(path);
} else {
@@ -173,26 +181,27 @@
return null;
// if (in instanceof )
/* the entry has not been cached */
- if (Debug.DEBUG_GENERAL)
+ if (debug.DEBUG_GENERAL)
Debug.println("Creating file: " + nested.getPath()); //$NON-NLS-1$
/* create the necessary directories */
File dir = new File(nested.getParent());
if (!dir.exists() && !dir.mkdirs()) {
- if (Debug.DEBUG_GENERAL)
+ if (debug.DEBUG_GENERAL)
Debug.println("Unable to create directory: " + dir.getPath()); //$NON-NLS-1$
- throw new IOException(NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, dir.getAbsolutePath()));
+ throw new IOException(NLS.bind(StorageMsg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, dir.getAbsolutePath()));
}
/* copy the entry to the cache */
- AdaptorUtil.readFile(in, nested);
- if (nativeCode)
- setPermissions(nested);
+ StorageUtil.readFile(in, nested);
+ if (nativeCode) {
+ generation.getBundleInfo().getStorage().setPermissions(nested);
+ }
}
}
return nested;
}
} catch (IOException e) {
- if (Debug.DEBUG_GENERAL)
+ if (debug.DEBUG_GENERAL)
Debug.printStackTrace(e);
}
return null;
@@ -209,7 +218,7 @@
private boolean hasTransforms(String path) {
if (!transformerHook.hasTransformers())
return false;
- return transformerHook.hasTransformsFor(data.getBundle());
+ return transformerHook.hasTransformsFor(generation.getRevision().getBundle());
}
/**
@@ -235,8 +244,6 @@
}
protected File getExtractFile(String entryName) {
- if (data == null)
- return null;
String path = ".tf"; /* put all these entries in this subdir *///$NON-NLS-1$
String name = entryName.replace('/', File.separatorChar);
/*
@@ -246,7 +253,7 @@
path = path.concat(name);
else
path = path + File.separator + name;
- return data.getExtractFile(path);
+ return generation.getExtractFile(path);
}
public int hashCode() {
diff --git a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerHook.java b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerHook.java
index d8323e3..0ff8701 100644
--- a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerHook.java
+++ b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerHook.java
@@ -12,53 +12,44 @@
package org.eclipse.equinox.internal.transforms;
import java.io.IOException;
-import java.net.URLConnection;
-import java.util.Properties;
-import org.eclipse.osgi.baseadaptor.*;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
-import org.eclipse.osgi.baseadaptor.hooks.AdaptorHook;
-import org.eclipse.osgi.baseadaptor.hooks.BundleFileWrapperFactoryHook;
-import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
-import org.eclipse.osgi.framework.log.FrameworkLog;
-import org.eclipse.osgi.framework.log.FrameworkLogEntry;
+import org.eclipse.osgi.internal.framework.EquinoxContainer;
+import org.eclipse.osgi.internal.hookregistry.*;
+import org.eclipse.osgi.internal.log.EquinoxLogServices;
+import org.eclipse.osgi.storage.BundleInfo.Generation;
+import org.eclipse.osgi.storage.bundlefile.BundleFile;
import org.osgi.framework.*;
/**
* The framework extension that is capable of applying transforms to bundle content.
*/
-public class TransformerHook implements BundleFileWrapperFactoryHook, HookConfigurator, AdaptorHook {
+public class TransformerHook implements BundleFileWrapperFactoryHook, HookConfigurator, ActivatorHookFactory, BundleActivator {
private volatile TransformerList transformers;
private volatile TransformInstanceListData templates;
- private static BaseAdaptor ADAPTOR;
+ private EquinoxLogServices logServices;
/**
* @throws IOException
*/
- public BundleFile wrapBundleFile(BundleFile bundleFile, Object content, BaseData data, boolean base) throws IOException {
- return new TransformedBundleFile(this, data, bundleFile);
+ public BundleFile wrapBundleFile(BundleFile bundleFile, Generation generation, boolean base) {
+ if (transformers == null || templates == null)
+ return null;
+ return new TransformedBundleFile(this, generation, bundleFile);
}
public void addHooks(HookRegistry hookRegistry) {
- hookRegistry.addAdaptorHook(this);
+ hookRegistry.addActivatorHookFactory(this);
hookRegistry.addBundleFileWrapperFactoryHook(this);
+ logServices = hookRegistry.getContainer().getLogServices();
}
- public void addProperties(Properties properties) {
- // no properties to add
- }
-
- public FrameworkLog createFrameworkLog() {
- return null;
- }
-
- public void frameworkStart(BundleContext context) throws BundleException {
+ public void start(BundleContext context) throws BundleException {
try {
- this.transformers = new TransformerList(context);
+ this.transformers = new TransformerList(context, logServices);
} catch (InvalidSyntaxException e) {
throw new BundleException("Problem registering service tracker: transformers", e); //$NON-NLS-1$
}
try {
- this.templates = new TransformInstanceListData(context);
+ this.templates = new TransformInstanceListData(context, logServices);
} catch (InvalidSyntaxException e) {
transformers.close();
transformers = null;
@@ -67,43 +58,22 @@
}
- public void frameworkStop(BundleContext context) {
+ public void stop(BundleContext context) {
transformers.close();
templates.close();
}
- protected BundleContext getContext() {
- return TransformerHook.ADAPTOR.getContext();
- }
-
- public void frameworkStopping(BundleContext context) {
- //nothing to do here
- }
-
- public void handleRuntimeError(Throwable error) {
- //no special handling by this framework extension
- }
-
- public void initialize(BaseAdaptor adaptor) {
- TransformerHook.ADAPTOR = adaptor;
- }
-
- public URLConnection mapLocationToURLConnection(String location) {
- return null;
- }
-
- public boolean matchDNChain(String pattern, String[] dnChain) {
- return false;
- }
-
- static void log(int severity, String msg, Throwable t) {
- if (TransformerHook.ADAPTOR == null) {
+ void log(int severity, String msg, Throwable t) {
+ if (logServices == null) {
System.err.println(msg);
t.printStackTrace();
return;
}
- FrameworkLogEntry entry = new FrameworkLogEntry(FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME, severity, 0, msg, 0, t, null);
- TransformerHook.ADAPTOR.getFrameworkLog().log(entry);
+ logServices.log(EquinoxContainer.NAME, severity, msg, t);
+ }
+
+ public BundleActivator createActivator() {
+ return this;
}
public String[] getTransformTypes() {
diff --git a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerList.java b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerList.java
index ce29668..5a9cabc 100644
--- a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerList.java
+++ b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerList.java
@@ -13,6 +13,8 @@
import java.util.HashMap;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
+import org.eclipse.osgi.internal.framework.EquinoxContainer;
+import org.eclipse.osgi.internal.log.EquinoxLogServices;
import org.osgi.framework.*;
import org.osgi.util.tracker.ServiceTracker;
@@ -30,16 +32,18 @@
* Local cache of transformers.
*/
private HashMap transformers = new HashMap();
+ private final EquinoxLogServices logServices;
/**
* Create a new instance of this list.
* @param context the context to track
* @throws InvalidSyntaxException thrown if there's an issue listening for changes to the given transformer type
*/
- public TransformerList(BundleContext context) throws InvalidSyntaxException {
+ public TransformerList(BundleContext context, EquinoxLogServices logServices) throws InvalidSyntaxException {
super(context, context.createFilter("(&(objectClass=" //$NON-NLS-1$
+ Object.class.getName() + ")(" + TransformTuple.TRANSFORMER_TYPE //$NON-NLS-1$
+ "=*))"), null); //$NON-NLS-1$
+ this.logServices = logServices;
open();
}
@@ -87,9 +91,9 @@
transformer = new ProxyStreamTransformer(object);
transformers.put(type, transformer);
} catch (SecurityException e) {
- TransformerHook.log(FrameworkLogEntry.ERROR, "Problem creating transformer", e); //$NON-NLS-1$
+ logServices.log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Problem creating transformer", e); //$NON-NLS-1$
} catch (NoSuchMethodException e) {
- TransformerHook.log(FrameworkLogEntry.ERROR, "Problem creating transformer", e); //$NON-NLS-1$
+ logServices.log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Problem creating transformer", e); //$NON-NLS-1$
}
}
}
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.weaving.aspectj/META-INF/MANIFEST.MF
index 6def945..475d97e 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/META-INF/MANIFEST.MF
@@ -5,15 +5,16 @@
Bundle-Version: 1.0.300.qualifier
Bundle-Activator: org.eclipse.equinox.weaving.aspectj.AspectJWeavingActivator
Import-Package: org.aspectj.weaver;version="1.6.3";resolution:=optional,
+ org.aspectj.weaver.bcel;version="1.6.3";resolution:=optional,
org.aspectj.weaver.loadtime;version="1.6.3";resolution:=optional,
org.aspectj.weaver.loadtime.definition;version="1.6.3";resolution:=optional,
org.aspectj.weaver.tools;version="1.6.3";resolution:=optional,
- org.aspectj.weaver.bcel;version="1.6.3";resolution:=optional,
org.eclipse.equinox.service.weaving,
org.eclipse.osgi.service.debug,
- org.eclipse.osgi.service.resolver,
org.eclipse.osgi.util;version="1.1.0",
- org.osgi.framework
+ org.osgi.framework,
+ org.osgi.framework.namespace;version="1.1.0",
+ org.osgi.framework.wiring;version="1.1.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.eclipse.equinox.weaving.aspectj;x-friends:="org.eclipse.equinox.weaving.tests",
org.eclipse.equinox.weaving.aspectj.loadtime;x-friends:="org.eclipse.equinox.weaving.tests"
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/AspectJWeavingService.java b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/AspectJWeavingService.java
index 780ef81..e7d7264 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/AspectJWeavingService.java
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/AspectJWeavingService.java
@@ -28,15 +28,14 @@
import org.eclipse.equinox.weaving.aspectj.loadtime.AspectResolver;
import org.eclipse.equinox.weaving.aspectj.loadtime.OSGiWeavingAdaptor;
import org.eclipse.equinox.weaving.aspectj.loadtime.OSGiWeavingContext;
-import org.eclipse.osgi.service.resolver.BundleDescription;
-import org.eclipse.osgi.service.resolver.State;
import org.osgi.framework.Bundle;
+import org.osgi.framework.wiring.BundleRevision;
public class AspectJWeavingService implements IWeavingService {
private List<Definition> aspectDefinitions;
- private BundleDescription bundleDescription;
+ private BundleRevision bundleRevision;
private boolean enabled;
@@ -52,23 +51,23 @@
}
public AspectJWeavingService(final ClassLoader loader, final Bundle bundle,
- final State state, final BundleDescription bundleDescription,
+ final BundleRevision bundleRevision,
final ISupplementerRegistry supplementerRegistry,
final AspectAdmin aspectAdmin) {
- this.bundleDescription = bundleDescription;
+ this.bundleRevision = bundleRevision;
- final AspectResolver aspectResolver = new AspectResolver(state,
+ final AspectResolver aspectResolver = new AspectResolver(
supplementerRegistry, aspectAdmin, AspectJWeavingStarter
.getDefault().getContext());
final AspectConfiguration aspectConfig = aspectResolver
- .resolveAspectsFor(bundle, bundleDescription);
+ .resolveAspectsFor(bundle, bundleRevision);
this.namespaceAddOn = aspectConfig.getFingerprint();
this.aspectDefinitions = aspectConfig.getAspectDefinitions();
this.enabled = this.aspectDefinitions.size() > 0;
if (this.enabled) {
this.weavingContext = new OSGiWeavingContext(loader,
- bundleDescription, aspectDefinitions);
+ bundleRevision, aspectDefinitions);
this.weavingAdaptor = new OSGiWeavingAdaptor(loader,
weavingContext, namespaceAddOn.toString());
} else {
@@ -80,6 +79,10 @@
}
}
+ private void ensureAdaptorInit() {
+ weavingAdaptor.initialize();
+ }
+
/**
* @see org.eclipse.equinox.service.weaving.IWeavingService#flushGeneratedClasses(java.lang.ClassLoader)
*/
@@ -122,7 +125,7 @@
public String getKey() {
if (AspectJWeavingStarter.DEBUG)
System.out.println("> WeavingService.getKey() bundle="
- + bundleDescription.getSymbolicName());
+ + bundleRevision.getSymbolicName());
final String namespace = namespaceAddOn.toString();
@@ -142,8 +145,8 @@
if (enabled) {
if (AspectJWeavingStarter.DEBUG)
System.out.println("> WeavingService.preProcess() bundle="
- + bundleDescription.getSymbolicName() + ", name="
- + name + ", bytes=" + classbytes.length);
+ + bundleRevision.getSymbolicName() + ", name=" + name
+ + ", bytes=" + classbytes.length);
byte[] newBytes;
ensureAdaptorInit();
@@ -158,8 +161,4 @@
}
}
- private void ensureAdaptorInit() {
- weavingAdaptor.initialize();
- }
-
}
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/AspectJWeavingServiceFactory.java b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/AspectJWeavingServiceFactory.java
index 805187f..115095a 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/AspectJWeavingServiceFactory.java
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/AspectJWeavingServiceFactory.java
@@ -15,9 +15,8 @@
import org.eclipse.equinox.service.weaving.IWeavingService;
import org.eclipse.equinox.service.weaving.IWeavingServiceFactory;
import org.eclipse.equinox.weaving.aspectj.loadtime.AspectAdminImpl;
-import org.eclipse.osgi.service.resolver.BundleDescription;
-import org.eclipse.osgi.service.resolver.State;
import org.osgi.framework.Bundle;
+import org.osgi.framework.wiring.BundleRevision;
/**
* The factory to create AspectJ-based weavers.
@@ -28,23 +27,20 @@
private final AspectAdminImpl aspectDefinitionRegistry;
- public AspectJWeavingServiceFactory(final AspectAdminImpl aspectDefinitionRegistry) {
+ public AspectJWeavingServiceFactory(
+ final AspectAdminImpl aspectDefinitionRegistry) {
this.aspectDefinitionRegistry = aspectDefinitionRegistry;
}
/**
- * @see org.eclipse.equinox.service.weaving.IWeavingServiceFactory#createWeavingService(java.lang.ClassLoader,
- * org.osgi.framework.Bundle, org.eclipse.osgi.service.resolver.State,
- * org.eclipse.osgi.service.resolver.BundleDescription,
- * org.eclipse.equinox.service.weaving.ISupplementerRegistry)
+ * @see org.eclipse.equinox.service.weaving.IWeavingServiceFactory#createWeavingService(ClassLoader,
+ * Bundle, BundleRevision, ISupplementerRegistry)
*/
public IWeavingService createWeavingService(final ClassLoader loader,
- final Bundle bundle, final State resolverState,
- final BundleDescription bundleDesciption,
+ final Bundle bundle, final BundleRevision bundleRevision,
final ISupplementerRegistry supplementerRegistry) {
- return new AspectJWeavingService(loader, bundle, resolverState,
- bundleDesciption, supplementerRegistry,
- aspectDefinitionRegistry);
+ return new AspectJWeavingService(loader, bundle, bundleRevision,
+ supplementerRegistry, aspectDefinitionRegistry);
}
}
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectAdminImpl.java b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectAdminImpl.java
index 357f083..5a04602 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectAdminImpl.java
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectAdminImpl.java
@@ -135,7 +135,7 @@
* @return The path to the aspect definition relately to the given bundle
*/
public String getDefinitionLocation(final Bundle bundle) {
- String aopContextHeader = (String) bundle.getHeaders().get(
+ String aopContextHeader = bundle.getHeaders("").get( //$NON-NLS-1$
AOP_CONTEXT_LOCATION_HEADER);
if (aopContextHeader != null) {
aopContextHeader = aopContextHeader.trim();
@@ -351,7 +351,7 @@
}
// parse export package headers
- final Dictionary<?, ?> manifest = bundle.getHeaders();
+ final Dictionary<?, ?> manifest = bundle.getHeaders(""); //$NON-NLS-1$
final ManifestElement[] exports = ManifestElement.parseHeader(
Constants.EXPORT_PACKAGE, (String) manifest
.get(Constants.EXPORT_PACKAGE));
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectResolver.java b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectResolver.java
index f6df097..beb1a77 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectResolver.java
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectResolver.java
@@ -22,14 +22,18 @@
import org.eclipse.equinox.service.weaving.Supplementer;
import org.eclipse.equinox.weaving.aspectj.AspectAdmin;
import org.eclipse.equinox.weaving.aspectj.AspectConfiguration;
-import org.eclipse.osgi.service.resolver.BundleDescription;
-import org.eclipse.osgi.service.resolver.ExportPackageDescription;
-import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.osgi.framework.namespace.BundleNamespace;
+import org.osgi.framework.namespace.HostNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
/**
* The aspect resolver is responsible for finding the right connections between
@@ -43,8 +47,6 @@
private final AspectAdmin aspectAdmin;
- private final State state;
-
private final ISupplementerRegistry supplementerRegistry;
private final BundleContext weavingBundleContext;
@@ -64,45 +66,13 @@
* @param bundleContext The bundle context in which the aspect resolver is
* used
*/
- public AspectResolver(final State state,
- final ISupplementerRegistry supplementerRegistry,
+ public AspectResolver(final ISupplementerRegistry supplementerRegistry,
final AspectAdmin aspectAdmin, final BundleContext bundleContext) {
- this.state = state;
this.supplementerRegistry = supplementerRegistry;
this.aspectAdmin = aspectAdmin;
this.weavingBundleContext = bundleContext;
}
- /**
- * Resolve the aspects to be woven into the given bundle
- *
- * @param bundle The bundle in which the aspects should be woven into
- * @param bundleDescription The description of the bundle to be woven into
- * @return The configuration of aspects what should be woven into the bundle
- */
- public AspectConfiguration resolveAspectsFor(final Bundle bundle,
- final BundleDescription bundleDescription) {
- final List<String> fingerprintElements = new ArrayList<String>();
-
- final List<Definition> definitions = resolveAspectsForBundle(
- fingerprintElements, bundle, bundleDescription);
-
- final Definition[] foundDefinitions = definitions
- .toArray(new Definition[definitions.size()]);
-
- Collections.sort(fingerprintElements);
- final StringBuilder fingerprint = new StringBuilder();
- final Iterator<String> iterator = fingerprintElements.iterator();
- while (iterator.hasNext()) {
- final String element = iterator.next();
- fingerprint.append(element);
- fingerprint.append(';');
- }
-
- return new AspectConfiguration(bundle, foundDefinitions, fingerprint
- .toString());
- }
-
private int getApplyAspectsPolicy(final ManifestElement[] headers,
final String manifestValue) {
int result = AspectAdmin.ASPECT_APPLY_POLICY_NOT_DEFINED;
@@ -124,24 +94,54 @@
}
private String getBundleVersion(final Bundle bundle) {
- return state.getBundle(bundle.getBundleId()).getVersion().toString();
+ return bundle.getVersion().toString();
+ }
+
+ /**
+ * Resolve the aspects to be woven into the given bundle
+ *
+ * @param bundle The bundle in which the aspects should be woven into
+ * @param bundlerevision The revision of the bundle to be woven into
+ * @return The configuration of aspects what should be woven into the bundle
+ */
+ public AspectConfiguration resolveAspectsFor(final Bundle bundle,
+ final BundleRevision bundleRevision) {
+ final List<String> fingerprintElements = new ArrayList<String>();
+
+ final List<Definition> definitions = resolveAspectsForBundle(
+ fingerprintElements, bundle, bundleRevision);
+
+ final Definition[] foundDefinitions = definitions
+ .toArray(new Definition[definitions.size()]);
+
+ Collections.sort(fingerprintElements);
+ final StringBuilder fingerprint = new StringBuilder();
+ final Iterator<String> iterator = fingerprintElements.iterator();
+ while (iterator.hasNext()) {
+ final String element = iterator.next();
+ fingerprint.append(element);
+ fingerprint.append(';');
+ }
+
+ return new AspectConfiguration(bundle, foundDefinitions,
+ fingerprint.toString());
}
private List<Definition> resolveAspectsForBundle(
final List<String> fingerprintElements, final Bundle bundle,
- final BundleDescription bundleDescription) {
+ final BundleRevision bundleRevision) {
final List<Definition> result = new ArrayList<Definition>();
+ final BundleWiring wiring = bundleRevision.getWiring();
- if (weavingBundleContext != null) {
+ if (wiring != null && weavingBundleContext != null) {
Definition aspects = null;
// fragments
- final BundleDescription[] fragments = bundleDescription
- .getFragments();
- for (int i = 0; i < fragments.length; i++) {
- final Bundle fragmentBundle = weavingBundleContext
- .getBundle(fragments[i].getBundleId());
+ for (final BundleWire hostWire : wiring
+ .getProvidedWires(HostNamespace.HOST_NAMESPACE)) {
+ final Bundle fragmentBundle = hostWire.getRequirer()
+ .getBundle();
if (fragmentBundle != null) {
aspects = aspectAdmin.getAspectDefinition(fragmentBundle);
if (aspects != null) {
@@ -149,27 +149,28 @@
fingerprintElements.add(fragmentBundle
.getSymbolicName()
+ ":" //$NON-NLS-1$
- + fragments[i].getVersion().toString());
+ + hostWire.getRequirer().getVersion()
+ .toString());
}
}
}
// required bundles
- final BundleDescription[] resolvedRequires = bundleDescription
- .getResolvedRequires();
+ final List<BundleWire> requiredBundles = wiring
+ .getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE);
ManifestElement[] requireHeaders = null;
- if (resolvedRequires.length > 0) {
+ if (!requiredBundles.isEmpty()) {
try {
requireHeaders = ManifestElement
- .parseHeader(Constants.REQUIRE_BUNDLE,
- (String) bundle.getHeaders().get(
- Constants.REQUIRE_BUNDLE));
+ .parseHeader(
+ Constants.REQUIRE_BUNDLE,
+ bundle.getHeaders("").get(Constants.REQUIRE_BUNDLE)); //$NON-NLS-1$
} catch (final BundleException e) {
}
}
- for (int i = 0; i < resolvedRequires.length; i++) {
- final Bundle requiredBundle = weavingBundleContext
- .getBundle(resolvedRequires[i].getBundleId());
+ for (final BundleWire requiredBundleWire : requiredBundles) {
+ final Bundle requiredBundle = requiredBundleWire.getProvider()
+ .getBundle();
if (requiredBundle != null) {
final int applyPolicy = getApplyAspectsPolicy(
requireHeaders, requiredBundle.getSymbolicName());
@@ -182,30 +183,32 @@
fingerprintElements.add(requiredBundle
.getSymbolicName()
+ ":" //$NON-NLS-1$
- + resolvedRequires[i].getVersion().toString());
+ + requiredBundleWire.getProvider().getVersion()
+ .toString());
}
}
}
// imported packages
- final ExportPackageDescription[] resolvedImports = bundleDescription
- .getResolvedImports();
+ final List<BundleWire> importedPackages = wiring
+ .getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
ManifestElement[] importHeaders = null;
- if (resolvedImports.length > 0) {
+ if (!importedPackages.isEmpty()) {
try {
importHeaders = ManifestElement
- .parseHeader(Constants.IMPORT_PACKAGE,
- (String) bundle.getHeaders().get(
- Constants.IMPORT_PACKAGE));
+ .parseHeader(
+ Constants.IMPORT_PACKAGE,
+ bundle.getHeaders("").get(Constants.IMPORT_PACKAGE)); //$NON-NLS-1$
} catch (final BundleException e) {
}
}
- for (int i = 0; i < resolvedImports.length; i++) {
- final Bundle exportingBundle = weavingBundleContext
- .getBundle(resolvedImports[i].getExporter()
- .getBundleId());
+ for (final BundleWire importPackageWire : importedPackages) {
+ final Bundle exportingBundle = importPackageWire.getProvider()
+ .getBundle();
if (exportingBundle != null) {
- final String importedPackage = resolvedImports[i].getName();
+ final String importedPackage = (String) importPackageWire
+ .getCapability().getAttributes()
+ .get(PackageNamespace.PACKAGE_NAMESPACE);
final int applyPolicy = getApplyAspectsPolicy(
importHeaders, importedPackage);
@@ -215,15 +218,21 @@
if (aspects != null) {
result.add(aspects);
+ final Object v = importPackageWire
+ .getCapability()
+ .getAttributes()
+ .get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
+ final String version = v == null ? Version.emptyVersion
+ .toString() : v.toString();
fingerprintElements.add(importedPackage + ":" //$NON-NLS-1$
- + resolvedImports[i].getVersion().toString());
+ + v);
}
}
}
// supplementers
final Supplementer[] supplementers = this.supplementerRegistry
- .getSupplementers(bundleDescription.getBundleId());
+ .getSupplementers(bundleRevision.getBundle().getBundleId());
for (int i = 0; i < supplementers.length; i++) {
aspects = aspectAdmin
@@ -241,14 +250,14 @@
// this bundle
aspects = aspectAdmin.getAspectDefinition(bundle);
if (aspects != null) {
- final String finishedValue = (String) bundle.getHeaders().get(
+ final String finishedValue = bundle.getHeaders("").get( //$NON-NLS-1$
AspectAdmin.AOP_BUNDLE_FINISHED_HEADER);
if (finishedValue == null
|| !AspectAdmin.AOP_BUNDLE_FINISHED_VALUE
.equals(finishedValue)) {
result.add(aspects);
fingerprintElements.add(bundle.getSymbolicName() + ":" //$NON-NLS-1$
- + bundleDescription.getVersion().toString());
+ + bundleRevision.getVersion().toString());
}
}
}
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingContext.java b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingContext.java
index 7586258..87355eb 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingContext.java
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingContext.java
@@ -20,7 +20,7 @@
import org.aspectj.weaver.loadtime.definition.Definition;
import org.aspectj.weaver.tools.WeavingAdaptor;
import org.eclipse.equinox.weaving.aspectj.AspectJWeavingStarter;
-import org.eclipse.osgi.service.resolver.BundleDescription;
+import org.osgi.framework.wiring.BundleRevision;
/**
* The weaving context for AspectJs load-time weaving API that deals with the
@@ -30,18 +30,17 @@
private final List<Definition> aspectDefinitions;
- private final BundleDescription bundleDescription;
+ private final BundleRevision bundleRevision;
public OSGiWeavingContext(final ClassLoader loader,
- final BundleDescription bundleDescription,
+ final BundleRevision bundleRevision,
final List<Definition> aspectDefinitions) {
super(loader);
- this.bundleDescription = bundleDescription;
+ this.bundleRevision = bundleRevision;
this.aspectDefinitions = aspectDefinitions;
if (AspectJWeavingStarter.DEBUG)
System.out.println("- WeavingContext.WeavingContext() locader="
- + loader + ", bundle="
- + bundleDescription.getSymbolicName());
+ + loader + ", bundle=" + bundleRevision.getSymbolicName());
}
/**
@@ -49,7 +48,7 @@
*/
@Override
public String getClassLoaderName() {
- return bundleDescription.getSymbolicName();
+ return bundleRevision.getSymbolicName();
}
/**
@@ -75,12 +74,12 @@
*/
@Override
public String getId() {
- return bundleDescription.getSymbolicName();
+ return bundleRevision.getSymbolicName();
}
@Override
public String toString() {
- return getClass().getName() + "[" + bundleDescription.getSymbolicName()
+ return getClass().getName() + "[" + bundleRevision.getSymbolicName()
+ "]";
}
diff --git a/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/CachingServiceFactory.java b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/CachingServiceFactory.java
index 4a4ef32..f64b235 100644
--- a/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/CachingServiceFactory.java
+++ b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/CachingServiceFactory.java
@@ -23,8 +23,8 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
-import org.osgi.framework.Constants;
import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.framework.Version;
/**
* {@link ICachingService} used as "singleton" OSGi service by
@@ -112,12 +112,8 @@
* @return The unique id of the cache for the given bundle
*/
public String getCacheId(final Bundle bundle) {
- String bundleVersion = (String) bundle.getHeaders().get(
- Constants.BUNDLE_VERSION);
- if (bundleVersion == null || bundleVersion.length() == 0) {
- bundleVersion = "0.0.0"; //$NON-NLS-1$
- }
- return bundle.getSymbolicName() + "_" + bundleVersion; //$NON-NLS-1$
+ final Version v = bundle.getVersion();
+ return bundle.getSymbolicName() + "_" + v; //$NON-NLS-1$
}
/**
diff --git a/bundles/org.eclipse.equinox.weaving.hook/.options b/bundles/org.eclipse.equinox.weaving.hook/.options
index b588b6c..04751aa 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/.options
+++ b/bundles/org.eclipse.equinox.weaving.hook/.options
@@ -1,6 +1,6 @@
-org.aspectj.osgi/debug=false
-org.aspectj.osgi/debug/bundle=false
-org.aspectj.osgi/debug/weave=true
-org.aspectj.osgi/debug/cache=false
-org.aspectj.osgi/debug/supplements=false
-org.aspectj.osgi/debug/bundleName=false
+org.eclipse.equinox.weaving.hook/debug=false
+org.eclipse.equinox.weaving.hook/debug/bundle=false
+org.eclipse.equinox.weaving.hook/debug/weave=true
+org.eclipse.equinox.weaving.hook/debug/cache=false
+org.eclipse.equinox.weaving.hook/debug/supplements=false
+org.eclipse.equinox.weaving.hook/debug/bundleName=false
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/IWeavingServiceFactory.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/IWeavingServiceFactory.java
index 480c250..676aee3 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/IWeavingServiceFactory.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/IWeavingServiceFactory.java
@@ -11,9 +11,8 @@
package org.eclipse.equinox.service.weaving;
-import org.eclipse.osgi.service.resolver.BundleDescription;
-import org.eclipse.osgi.service.resolver.State;
import org.osgi.framework.Bundle;
+import org.osgi.framework.wiring.BundleRevision;
/**
* This is the central interface for other bundles to implement when they would
@@ -32,16 +31,14 @@
*
* @param loader The classloader of the bundle for which to create a weaver
* @param bundle The bundle for which to create the weaver
- * @param resolverState The state service of the OSGi runtime
- * @param bundleDesciption The description of the bundle for which to create
- * a weaver
+ * @param bundleRevision The revision of the bundle for which to create a
+ * weaver
* @param supplementerRegistry The supplementer registry which is used by
* the core equinox aspects hook
* @return The created weaver for the given bundle
*/
public IWeavingService createWeavingService(ClassLoader loader,
- Bundle bundle, State resolverState,
- BundleDescription bundleDesciption,
+ Bundle bundle, BundleRevision bundleRevision,
ISupplementerRegistry supplementerRegistry);
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/Debug.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/Debug.java
index 957ff90..e3d281c 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/Debug.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/Debug.java
@@ -11,23 +11,23 @@
package org.eclipse.equinox.weaving.adaptors;
-import org.eclipse.osgi.framework.debug.FrameworkDebugOptions;
+import org.eclipse.osgi.service.debug.DebugOptions;
public class Debug {
public static final String ASPECTJ_OSGI = "org.eclipse.equinox.weaving.hook"; //$NON-NLS-1$
- public static boolean DEBUG_BUNDLE;
+ public static boolean DEBUG_BUNDLE = false;
public static String DEBUG_BUNDLENAME;
- public static boolean DEBUG_CACHE;
+ public static boolean DEBUG_CACHE = false;
- public static boolean DEBUG_GENERAL;
+ public static boolean DEBUG_GENERAL = false;
- public static boolean DEBUG_SUPPLEMENTS;
+ public static boolean DEBUG_SUPPLEMENTS = false;
- public static boolean DEBUG_WEAVE;
+ public static boolean DEBUG_WEAVE = false;
public static final String OPTION_DEBUG_BUNDLE = ASPECTJ_OSGI
+ "/debug/bundle"; //$NON-NLS-1$
@@ -46,23 +46,23 @@
public static final String OPTION_DEBUG_WEAVE = ASPECTJ_OSGI
+ "/debug/weave"; //$NON-NLS-1$
- static {
- final FrameworkDebugOptions fdo = FrameworkDebugOptions.getDefault();
- if (fdo != null) {
- DEBUG_GENERAL = fdo.getBooleanOption(OPTION_DEBUG_GENERAL, false);
- DEBUG_BUNDLE = fdo.getBooleanOption(OPTION_DEBUG_BUNDLE, false);
- DEBUG_WEAVE = fdo.getBooleanOption(OPTION_DEBUG_WEAVE, false);
- DEBUG_CACHE = fdo.getBooleanOption(OPTION_DEBUG_CACHE, false);
- DEBUG_BUNDLENAME = fdo.getOption(OPTION_DEBUG_BUNDLENAME, "");
- DEBUG_SUPPLEMENTS = fdo.getBooleanOption(OPTION_DEBUG_SUPPLEMENTS,
- false);
- }
- }
-
public static boolean bundleNameMatches(final String name) {
return name.equals(DEBUG_BUNDLENAME);
}
+ public static void init(final DebugOptions options) {
+ if (options != null) {
+ DEBUG_GENERAL = options.getBooleanOption(OPTION_DEBUG_GENERAL,
+ false);
+ DEBUG_BUNDLE = options.getBooleanOption(OPTION_DEBUG_BUNDLE, false);
+ DEBUG_WEAVE = options.getBooleanOption(OPTION_DEBUG_WEAVE, false);
+ DEBUG_CACHE = options.getBooleanOption(OPTION_DEBUG_CACHE, false);
+ DEBUG_BUNDLENAME = options.getOption(OPTION_DEBUG_BUNDLENAME, "");
+ DEBUG_SUPPLEMENTS = options.getBooleanOption(
+ OPTION_DEBUG_SUPPLEMENTS, false);
+ }
+ }
+
public static void println(final String s) {
/* if (s.indexOf("org.eclipse.osgi.tests") != -1) */System.err
.println(s);
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/IWeavingAdaptor.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/IWeavingAdaptor.java
index a92f793..9c5bb66 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/IWeavingAdaptor.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/IWeavingAdaptor.java
@@ -15,7 +15,6 @@
import java.net.URL;
import org.eclipse.equinox.service.weaving.CacheEntry;
-import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
public interface IWeavingAdaptor {
@@ -23,7 +22,7 @@
public void initialize();
- public void setBaseClassLoader(BaseClassLoader baseClassLoader);
+ public boolean isInitialized();
public boolean storeClass(String name, URL sourceFileURL, Class clazz,
byte[] classbytes);
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptor.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptor.java
index 20d5074..79b5a08 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptor.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptor.java
@@ -24,12 +24,12 @@
import org.eclipse.equinox.service.weaving.ICachingService;
import org.eclipse.equinox.service.weaving.IWeavingService;
import org.eclipse.equinox.weaving.hooks.WeavingBundleFile;
-import org.eclipse.osgi.baseadaptor.BaseData;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
-import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
-import org.eclipse.osgi.framework.internal.core.BundleFragment;
-import org.eclipse.osgi.framework.internal.core.BundleHost;
+import org.eclipse.osgi.container.ModuleRevision;
+import org.eclipse.osgi.internal.loader.ModuleClassLoader;
+import org.eclipse.osgi.storage.BundleInfo.Generation;
+import org.eclipse.osgi.storage.bundlefile.BundleFile;
import org.osgi.framework.Bundle;
+import org.osgi.framework.wiring.BundleRevision;
public class WeavingAdaptor implements IWeavingAdaptor {
@@ -40,6 +40,11 @@
return set.contains(obj);
}
+ @Override
+ protected Object initialValue() {
+ return new HashSet();
+ }
+
public void put(final Object obj) {
final Set set = (Set) get();
if (set.contains(obj)) {
@@ -55,47 +60,43 @@
}
set.remove(obj);
}
-
- @Override
- protected Object initialValue() {
- return new HashSet();
- }
}
private static ThreadLocalSet identifyRecursionSet = new ThreadLocalSet();
- private BaseClassLoader baseLoader;
-
private Bundle bundle;
private ICachingService cachingService;
- private final BaseData data;
-
private final WeavingAdaptorFactory factory;
+ private final Generation generation;
+
private boolean initialized = false;
- private String symbolicName;
+ private final ModuleClassLoader moduleLoader;
+
+ private final String symbolicName;
private IWeavingService weavingService;
- public WeavingAdaptor(final BaseData baseData,
+ public WeavingAdaptor(final Generation generation,
final WeavingAdaptorFactory serviceFactory,
- final BaseClassLoader baseClassLoader,
final IWeavingService weavingService,
- final ICachingService cachingService) {
- this.data = baseData;
+ final ICachingService cachingService,
+ final ModuleClassLoader classLoader) {
+ this.generation = generation;
this.factory = serviceFactory;
- this.symbolicName = baseData.getLocation();
+ this.symbolicName = generation.getRevision().getSymbolicName();
+ this.moduleLoader = classLoader;
if (Debug.DEBUG_GENERAL)
- Debug.println("- AspectJAdaptor.AspectJAdaptor() bundle="
+ Debug.println("- WeavingAdaptor.WeavingAdaptor() bundle="
+ symbolicName);
}
public CacheEntry findClass(final String name, final URL sourceFileURL) {
if (Debug.DEBUG_CACHE)
- Debug.println("> AspectJAdaptor.findClass() bundle=" + symbolicName
+ Debug.println("> WeavingAdaptor.findClass() bundle=" + symbolicName
+ ", url=" + sourceFileURL + ", name=" + name);
CacheEntry cacheEntry = null;
@@ -106,7 +107,7 @@
}
if (Debug.DEBUG_CACHE)
- Debug.println("< AspectJAdaptor.findClass() cacheEntry="
+ Debug.println("< WeavingAdaptor.findClass() cacheEntry="
+ cacheEntry);
return cacheEntry;
}
@@ -115,80 +116,70 @@
synchronized (this) {
if (initialized) return;
- this.bundle = data.getBundle();
- this.symbolicName = data.getSymbolicName();
+ this.bundle = generation.getRevision().getBundle();
if (!identifyRecursionSet.contains(this)) {
identifyRecursionSet.put(this);
if (Debug.DEBUG_GENERAL)
- Debug.println("> AspectJAdaptor.initialize() bundle="
- + symbolicName + ", baseLoader=" + baseLoader);
+ Debug.println("> WeavingAdaptor.initialize() bundle="
+ + symbolicName + ", moduleLoader=" + moduleLoader);
if (symbolicName.startsWith("org.aspectj")) {
if (Debug.DEBUG_GENERAL)
- Debug
- .println("- AspectJAdaptor.initialize() symbolicName="
- + symbolicName
- + ", baseLoader="
- + baseLoader);
- } else if (baseLoader != null) {
- weavingService = factory.getWeavingService(baseLoader);
- cachingService = factory.getCachingService(baseLoader,
+ Debug.println("- WeavingAdaptor.initialize() symbolicName="
+ + symbolicName
+ + ", moduleLoader="
+ + moduleLoader);
+ } else if (moduleLoader != null) {
+ weavingService = factory.getWeavingService(moduleLoader);
+ cachingService = factory.getCachingService(moduleLoader,
bundle, weavingService);
- } else if (bundle instanceof BundleFragment) {
- final BundleFragment fragment = (BundleFragment) bundle;
- final BundleHost host = (BundleHost) factory
- .getHost(fragment);
- if (Debug.DEBUG_GENERAL)
- Debug
- .println("- AspectJAdaptor.initialize() symbolicName="
- + symbolicName + ", host=" + host);
+ } else if ((generation.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
- final BaseData hostData = (BaseData) host.getBundleData();
- // System.err.println("? AspectJAdaptor.initialize() bundleData=" + hostData);
- final BundleFile bundleFile = hostData.getBundleFile();
+ final Bundle host = factory.getHost(bundle);
+ if (Debug.DEBUG_GENERAL)
+ Debug.println("- WeavingAdaptor.initialize() symbolicName="
+ + symbolicName + ", host=" + host);
+
+ final Generation hostGeneration = (Generation) ((ModuleRevision) host
+ .adapt(BundleRevision.class)).getRevisionInfo();
+ final BundleFile bundleFile = hostGeneration
+ .getBundleFile();
if (bundleFile instanceof WeavingBundleFile) {
final WeavingBundleFile hostFile = (WeavingBundleFile) bundleFile;
- // System.err.println("? AspectJAdaptor.initialize() bundleFile=" + hostFile);
final WeavingAdaptor hostAdaptor = (WeavingAdaptor) hostFile
.getAdaptor();
- // System.err.println("? AspectJAdaptor.initialize() bundleFile=" + hostAdaptor);
weavingService = hostAdaptor.weavingService;
cachingService = factory.getCachingService(
- hostAdaptor.baseLoader, bundle, weavingService);
+ hostAdaptor.moduleLoader, bundle,
+ weavingService);
}
} else {
if (Debug.DEBUG_GENERAL)
- Debug
- .println("W AspectJAdaptor.initialize() symbolicName="
- + symbolicName
- + ", baseLoader="
- + baseLoader);
+ Debug.println("W WeavingAdaptor.initialize() symbolicName="
+ + symbolicName + ", baseLoader=" + moduleLoader);
}
initialized = true;
identifyRecursionSet.remove(this);
}
if (Debug.DEBUG_GENERAL)
- Debug.println("< AspectJAdaptor.initialize() weavingService="
+ Debug.println("< WeavingAdaptor.initialize() weavingService="
+ (weavingService != null) + ", cachingService="
+ (cachingService != null));
}
}
- public void setBaseClassLoader(final BaseClassLoader baseClassLoader) {
- this.baseLoader = baseClassLoader;
-
- if (Debug.DEBUG_GENERAL)
- Debug.println("- AspectJAdaptor.setBaseClassLoader() bundle="
- + symbolicName + ", baseLoader=" + baseLoader);
+ public boolean isInitialized() {
+ return initialized;
}
public boolean storeClass(final String name, final URL sourceFileURL,
final Class clazz, final byte[] classbytes) {
if (Debug.DEBUG_CACHE)
- Debug.println("> AspectJAdaptor.storeClass() bundle="
- + symbolicName + ", url=" + sourceFileURL + ", name="
+ Debug.println("> WeavingAdaptor.storeClass() bundle=" //$NON-NLS-1$
+ + symbolicName + ", url=" + sourceFileURL
+ + ", name="
+ name + ", clazz=" + clazz);
boolean stored = false;
@@ -196,8 +187,8 @@
if (cachingService != null) {
//have we generated a closure?
if (weavingService != null
- && weavingService.generatedClassesExistFor(
- (ClassLoader) baseLoader, name)) {
+ && weavingService.generatedClassesExistFor(moduleLoader,
+ name)) {
//If so we need to ask the cache if its capable of handling generated closures
if (cachingService.canCacheGeneratedClasses()) {
final Map<String, byte[]> generatedClasses = weavingService
@@ -206,35 +197,33 @@
stored = cachingService.storeClassAndGeneratedClasses("",
sourceFileURL, clazz, classbytes, generatedClasses);
} else {
- weavingService
- .flushGeneratedClasses((ClassLoader) baseLoader);
+ weavingService.flushGeneratedClasses(moduleLoader);
if (Debug.DEBUG_CACHE)
- Debug
- .println("- AspectJAdaptor.storeClass() generatedClassesExistFor=true");
+ Debug.println("- WeavingAdaptor.storeClass() generatedClassesExistFor=true"); //$NON-NLS-1$
}
} else {
- stored = cachingService.storeClass("", sourceFileURL, clazz,
+ stored = cachingService.storeClass("", sourceFileURL, clazz, //$NON-NLS-1$
classbytes);
if (!stored) {
if (Debug.DEBUG_CACHE)
- Debug.println("E AspectJHook.storeClass() bundle="
- + symbolicName + ", name=" + name);
+ Debug.println("E WeavingAdaptor.storeClass() bundle=" //$NON-NLS-1$
+ + symbolicName + ", name=" + name); //$NON-NLS-1$
}
}
}
if (Debug.DEBUG_CACHE)
- Debug.println("< AspectJAdaptor.storeClass() stored=" + stored);
+ Debug.println("< WeavingAdaptor.storeClass() stored=" + stored); //$NON-NLS-1$
return stored;
}
@Override
public String toString() {
- return "AspectJAdaptor[" + symbolicName + "]";
+ return "WeavingAdaptor[" + symbolicName + "]";
}
public byte[] weaveClass(final String name, final byte[] bytes) {
if (Debug.DEBUG_WEAVE)
- Debug.println("> AspectJAdaptor.weaveClass() bundle="
+ Debug.println("> WeavingAdaptor.weaveClass() bundle="
+ symbolicName + ", name=" + name + ", bytes="
+ bytes.length);
byte[] newBytes = null;
@@ -242,15 +231,14 @@
initialize();
if (/* shouldWeave(bytes) && */weavingService != null) {
try {
- newBytes = weavingService.preProcess(name, bytes,
- (ClassLoader) baseLoader);
+ newBytes = weavingService.preProcess(name, bytes, moduleLoader);
} catch (final IOException ex) {
throw new ClassFormatError(ex.toString());
}
}
if (Debug.DEBUG_WEAVE)
- Debug.println("< AspectJAdaptor.weaveClass() newBytes=" + newBytes);
+ Debug.println("< WeavingAdaptor.weaveClass() newBytes=" + newBytes);
return newBytes;
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptorFactory.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptorFactory.java
index 83458bb..1069ff0 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptorFactory.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/WeavingAdaptorFactory.java
@@ -17,22 +17,18 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.equinox.service.weaving.ICachingService;
import org.eclipse.equinox.service.weaving.ICachingServiceFactory;
import org.eclipse.equinox.service.weaving.ISupplementerRegistry;
import org.eclipse.equinox.service.weaving.IWeavingService;
import org.eclipse.equinox.service.weaving.IWeavingServiceFactory;
-import org.eclipse.osgi.baseadaptor.BaseData;
-import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
-import org.eclipse.osgi.service.resolver.BundleDescription;
-import org.eclipse.osgi.service.resolver.State;
+import org.eclipse.osgi.internal.loader.ModuleClassLoader;
+import org.eclipse.osgi.storage.BundleInfo.Generation;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -46,15 +42,15 @@
public class WeavingAdaptorFactory {
- private static final Collection IGNORE_WEAVING_SERVICE_BUNDLES = Arrays
- .asList(new String[] { "org.eclipse.equinox.weaving.aspectj",
- "org.eclipse.equinox.weaving.caching",
- "org.eclipse.equinox.weaving.caching.j9",
- "org.eclipse.update.configurator",
- "org.eclipse.equinox.simpleconfigurator",
- "org.eclipse.equinox.common" });
+ private static final Collection<String> IGNORE_WEAVING_SERVICE_BUNDLES = Arrays
+ .asList(new String[] { "org.eclipse.equinox.weaving.aspectj", //$NON-NLS-1$
+ "org.eclipse.equinox.weaving.caching", //$NON-NLS-1$
+ "org.eclipse.equinox.weaving.caching.j9", //$NON-NLS-1$
+ "org.eclipse.update.configurator", //$NON-NLS-1$
+ "org.eclipse.equinox.simpleconfigurator", //$NON-NLS-1$
+ "org.eclipse.equinox.common" }); //$NON-NLS-1$
- private static final String WEAVING_SERVICE_DYNAMICS_PROPERTY = "equinox.weaving.service.dynamics";
+ private static final String WEAVING_SERVICE_DYNAMICS_PROPERTY = "equinox.weaving.service.dynamics"; //$NON-NLS-1$
private ServiceTracker cachingServiceFactoryTracker;
@@ -68,11 +64,7 @@
private ServiceListener weavingServiceListener;
- /**
- * Bundle -> Local weaving service
- */
- private final Map weavingServices = Collections
- .synchronizedMap(new HashMap());
+ private final Map<Bundle, IWeavingService> weavingServices = new ConcurrentHashMap<Bundle, IWeavingService>();
public WeavingAdaptorFactory() {
}
@@ -81,35 +73,86 @@
context.removeServiceListener(weavingServiceListener);
if (Debug.DEBUG_WEAVE)
- Debug.println("> Removed service listener for weaving service.");
+ Debug.println("> Removed service listener for weaving service."); //$NON-NLS-1$
weavingServiceFactoryTracker.close();
if (Debug.DEBUG_WEAVE)
- Debug.println("> Closed service tracker for weaving service.");
+ Debug.println("> Closed service tracker for weaving service."); //$NON-NLS-1$
cachingServiceFactoryTracker.close();
if (Debug.DEBUG_CACHE)
- Debug.println("> Closed service tracker for caching service.");
+ Debug.println("> Closed service tracker for caching service."); //$NON-NLS-1$
+ }
+
+ protected ICachingService getCachingService(final ModuleClassLoader loader,
+ final Bundle bundle, final IWeavingService weavingService) {
+ if (Debug.DEBUG_CACHE)
+ Debug.println("> WeavingAdaptorFactory.getCachingService() bundle=" //$NON-NLS-1$
+ + bundle + ", weavingService=" + weavingService); //$NON-NLS-1$
+ ICachingService service = null;
+ String key = "";
+
+ if (weavingService != null) {
+ key = weavingService.getKey();
+ }
+ final ICachingServiceFactory cachingServiceFactory = (ICachingServiceFactory) cachingServiceFactoryTracker
+ .getService();
+ if (cachingServiceFactory != null) {
+ service = cachingServiceFactory.createCachingService(loader,
+ bundle, key);
+ }
+ if (Debug.DEBUG_CACHE)
+ Debug.println("< WeavingAdaptorFactory.getCachingService() service=" //$NON-NLS-1$
+ + service + ", key='" + key + "'"); //$NON-NLS-1$
+ return service;
}
public Bundle getHost(final Bundle fragment) {
if (Debug.DEBUG_GENERAL)
- Debug.println("> AspectJAdaptorFactory.getHost() fragment="
- + fragment);
+ Debug.println("> WeavingAdaptorFactory.getHost() fragment=" + fragment); //$NON-NLS-1$
Bundle host = null;
if (packageAdminService != null)
host = packageAdminService.getHosts(fragment)[0];
if (Debug.DEBUG_GENERAL)
- Debug.println("< AspectJAdaptorFactory.getHost() " + host);
+ Debug.println("< WeavingAdaptorFactory.getHost() " + host); //$NON-NLS-1$
return host;
}
+ protected IWeavingService getWeavingService(final ModuleClassLoader loader) {
+ if (Debug.DEBUG_WEAVE)
+ Debug.println("> WeavingAdaptorFactory.getWeavingService() baseClassLoader=" //$NON-NLS-1$
+ + loader);
+
+ final Generation generation = loader.getClasspathManager()
+ .getGeneration();
+ final Bundle bundle = loader.getBundle();
+
+ IWeavingService weavingService = null;
+ if (!IGNORE_WEAVING_SERVICE_BUNDLES.contains(bundle.getSymbolicName())) {
+ final IWeavingServiceFactory weavingServiceFactory = (IWeavingServiceFactory) weavingServiceFactoryTracker
+ .getService();
+ if (weavingServiceFactory != null) {
+ weavingService = weavingServiceFactory.createWeavingService(
+ loader, bundle, generation.getRevision(),
+ supplementerRegistry);
+
+ if (weavingService != null) {
+ weavingServices.put(bundle, weavingService);
+ }
+ }
+ }
+ if (Debug.DEBUG_WEAVE)
+ Debug.println("< WeavingAdaptorFactory.getWeavingService() service=" //$NON-NLS-1$
+ + weavingService);
+ return weavingService;
+ }
+
public void initialize(final BundleContext context,
final ISupplementerRegistry supplementerRegistry) {
if (Debug.DEBUG_GENERAL)
- Debug.println("> AspectJAdaptorFactory.initialize() context="
+ Debug.println("> WeavingAdaptorFactory.initialize() context=" //$NON-NLS-1$
+ context);
this.supplementerRegistry = supplementerRegistry;
@@ -121,7 +164,7 @@
IWeavingServiceFactory.class.getName(), null);
weavingServiceFactoryTracker.open();
if (Debug.DEBUG_WEAVE)
- Debug.println("> Opened service tracker for weaving service.");
+ Debug.println("> Opened service tracker for weaving service."); //$NON-NLS-1$
// Service listener for weaving service
weavingServiceListener = new ServiceListener() {
@@ -130,22 +173,16 @@
if (event.getType() == ServiceEvent.REGISTERED) {
final List<Bundle> bundlesToRefresh = new ArrayList<Bundle>();
- final Iterator bundleEntries = weavingServices.entrySet()
- .iterator();
synchronized (weavingServices) {
+ final Iterator<Bundle> bundleEntries = weavingServices
+ .keySet().iterator();
while (bundleEntries.hasNext()) {
- final Entry entry = (Entry) bundleEntries.next();
- final Bundle bundle = (Bundle) entry.getKey();
- if (entry.getValue() == null) {
- bundleEntries.remove();
- System.err
- .println("bundle update because of weaving service start: "
- + bundle.getSymbolicName());
- bundlesToRefresh.add(bundle);
- if (Debug.DEBUG_WEAVE)
- Debug.println("> Updated bundle "
- + bundle.getSymbolicName());
- }
+ final Bundle bundle = bundleEntries.next();
+ bundleEntries.remove();
+ bundlesToRefresh.add(bundle);
+ if (Debug.DEBUG_WEAVE)
+ Debug.println("> Updated bundle " //$NON-NLS-1$
+ + bundle.getSymbolicName());
}
}
@@ -159,22 +196,16 @@
&& startLevelService.getStartLevel() > 0) {
final List<Bundle> bundlesToRefresh = new ArrayList<Bundle>();
- final Iterator bundleEntries = weavingServices.entrySet()
- .iterator();
synchronized (weavingServices) {
+ final Iterator<Bundle> bundleEntries = weavingServices
+ .keySet().iterator();
while (bundleEntries.hasNext()) {
- final Entry entry = (Entry) bundleEntries.next();
- final Bundle bundle = (Bundle) entry.getKey();
- if (entry.getValue() != null) {
- bundleEntries.remove();
- System.err
- .println("bundle update because of weaving service stop: "
- + bundle.getSymbolicName());
- bundlesToRefresh.add(bundle);
- if (Debug.DEBUG_WEAVE)
- Debug.println("> Updated bundle "
- + bundle.getSymbolicName());
- }
+ final Bundle bundle = bundleEntries.next();
+ bundleEntries.remove();
+ bundlesToRefresh.add(bundle);
+ if (Debug.DEBUG_WEAVE)
+ Debug.println("> Updated bundle " //$NON-NLS-1$
+ + bundle.getSymbolicName());
}
}
if (bundlesToRefresh.size() > 0) {
@@ -185,15 +216,15 @@
}
};
- if (System.getProperty(WEAVING_SERVICE_DYNAMICS_PROPERTY, "false")
- .equals("true")) {
- try {
- context.addServiceListener(weavingServiceListener, "("
- + Constants.OBJECTCLASS + "="
- + IWeavingService.class.getName() + ")");
- } catch (final InvalidSyntaxException e) { // This is correct!
- }
+ // if (System.getProperty(WEAVING_SERVICE_DYNAMICS_PROPERTY, "false")
+ // .equals("true")) {
+ try {
+ context.addServiceListener(weavingServiceListener, "("
+ + Constants.OBJECTCLASS + "="
+ + IWeavingServiceFactory.class.getName() + ")");
+ } catch (final InvalidSyntaxException e) { // This is correct!
}
+ // }
// Service tracker for caching service
cachingServiceFactoryTracker = new ServiceTracker(context,
@@ -203,67 +234,10 @@
Debug.println("> Opened service tracker for caching service.");
}
- protected ICachingService getCachingService(final BaseClassLoader loader,
- final Bundle bundle, final IWeavingService weavingService) {
- if (Debug.DEBUG_CACHE)
- Debug.println("> AspectJAdaptorFactory.getCachingService() bundle="
- + bundle + ", weavingService=" + weavingService);
- ICachingService service = null;
- String key = "";
-
- if (weavingService != null) {
- key = weavingService.getKey();
- }
- final ICachingServiceFactory cachingServiceFactory = (ICachingServiceFactory) cachingServiceFactoryTracker
- .getService();
- if (cachingServiceFactory != null) {
- service = cachingServiceFactory.createCachingService(
- (ClassLoader) loader, bundle, key);
- }
- if (Debug.DEBUG_CACHE)
- Debug
- .println("< AspectJAdaptorFactory.getCachingService() service="
- + service + ", key='" + key + "'");
- return service;
- }
-
- protected IWeavingService getWeavingService(final BaseClassLoader loader) {
- if (Debug.DEBUG_WEAVE)
- Debug
- .println("> AspectJAdaptorFactory.getWeavingService() baseClassLoader="
- + loader);
-
- final BaseData baseData = loader.getClasspathManager().getBaseData();
- final State state = baseData.getAdaptor().getState();
- final Bundle bundle = baseData.getBundle();
- final BundleDescription bundleDescription = state.getBundle(bundle
- .getBundleId());
-
- IWeavingService weavingService = null;
- if (!IGNORE_WEAVING_SERVICE_BUNDLES.contains(bundle.getSymbolicName())) {
- final IWeavingServiceFactory weavingServiceFactory = (IWeavingServiceFactory) weavingServiceFactoryTracker
- .getService();
- if (weavingServiceFactory != null) {
- weavingService = weavingServiceFactory.createWeavingService(
- (ClassLoader) loader, bundle, state, bundleDescription,
- supplementerRegistry);
- }
- synchronized (weavingServices) {
- weavingServices.put(bundle, weavingService);
- }
- }
- if (Debug.DEBUG_WEAVE)
- Debug
- .println("< AspectJAdaptorFactory.getWeavingService() service="
- + weavingService);
- return weavingService;
- }
-
private void initializePackageAdminService(final BundleContext context) {
if (Debug.DEBUG_GENERAL)
- Debug
- .println("> AspectJAdaptorFactory.initializePackageAdminService() context="
- + context);
+ Debug.println("> AdaptorFactory.initializePackageAdminService() context="
+ + context);
final ServiceReference ref = context
.getServiceReference(PackageAdmin.class.getName());
@@ -272,16 +246,14 @@
}
if (Debug.DEBUG_GENERAL)
- Debug
- .println("< AspectJAdaptorFactory.initializePackageAdminService() "
- + packageAdminService);
+ Debug.println("< AdaptorFactory.initializePackageAdminService() "
+ + packageAdminService);
}
private void initializeStartLevelService(final BundleContext context) {
if (Debug.DEBUG_GENERAL)
- Debug
- .println("> AspectJAdaptorFactory.initializeStartLevelService() context="
- + context);
+ Debug.println("> AdaptorFactory.initializeStartLevelService() context="
+ + context);
final ServiceReference ref = context
.getServiceReference(StartLevel.class.getName());
@@ -290,8 +262,7 @@
}
if (Debug.DEBUG_GENERAL)
- Debug
- .println("< AspectJAdaptorFactory.initializeStartLevelService() "
- + startLevelService);
+ Debug.println("< AdaptorFactory.initializeStartLevelService() "
+ + startLevelService);
}
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AbstractWeavingBundleFile.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AbstractWeavingBundleFile.java
index ecc67be..cabd782 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AbstractWeavingBundleFile.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AbstractWeavingBundleFile.java
@@ -19,16 +19,18 @@
import java.util.Enumeration;
import org.eclipse.equinox.weaving.adaptors.IWeavingAdaptor;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
+import org.eclipse.osgi.container.Module;
+import org.eclipse.osgi.storage.bundlefile.BundleEntry;
+import org.eclipse.osgi.storage.bundlefile.BundleFile;
public abstract class AbstractWeavingBundleFile extends BundleFile {
- protected BundleFile delegate;
-
private final BundleAdaptorProvider adaptorProvider;
- public AbstractWeavingBundleFile(final BundleAdaptorProvider adaptorProvider,
+ protected BundleFile delegate;
+
+ public AbstractWeavingBundleFile(
+ final BundleAdaptorProvider adaptorProvider,
final BundleFile bundleFile) {
super(bundleFile.getBaseFile());
this.adaptorProvider = adaptorProvider;
@@ -36,7 +38,7 @@
}
/**
- * @see org.eclipse.osgi.baseadaptor.bundlefile.BundleFile#close()
+ * @see BundleFile#close()
*/
@Override
public void close() throws IOException {
@@ -44,7 +46,7 @@
}
/**
- * @see org.eclipse.osgi.baseadaptor.bundlefile.BundleFile#containsDir(java.lang.String)
+ * @see BundleFile#containsDir(java.lang.String)
*/
@Override
public boolean containsDir(final String dir) {
@@ -59,7 +61,7 @@
}
/**
- * @see org.eclipse.osgi.baseadaptor.bundlefile.BundleFile#getBaseFile()
+ * @see BundleFile#getBaseFile()
*/
@Override
public File getBaseFile() {
@@ -68,7 +70,7 @@
}
/**
- * @see org.eclipse.osgi.baseadaptor.bundlefile.BundleFile#getEntry(java.lang.String)
+ * @see BundleFile#getEntry(java.lang.String)
*/
@Override
public BundleEntry getEntry(final String path) {
@@ -76,16 +78,15 @@
}
/**
- * @see org.eclipse.osgi.baseadaptor.bundlefile.BundleFile#getEntryPaths(java.lang.String)
+ * @see BundleFile#getEntryPaths(java.lang.String)
*/
@Override
- public Enumeration getEntryPaths(final String path) {
+ public Enumeration<String> getEntryPaths(final String path) {
return delegate.getEntryPaths(path);
}
/**
- * @see org.eclipse.osgi.baseadaptor.bundlefile.BundleFile#getFile(java.lang.String,
- * boolean)
+ * @see BundleFile#getFile(java.lang.String, boolean)
*/
@Override
public File getFile(final String path, final boolean nativeCode) {
@@ -93,26 +94,17 @@
}
/**
- * @deprecated
+ * @see BundleFile#getResourceURL(java.lang.String,
+ * org.eclipse.osgi.container.Module, int)
*/
- @Deprecated
@Override
- public URL getResourceURL(final String path, final long hostBundleID) {
- return delegate.getResourceURL(path, hostBundleID);
- }
-
- /**
- * @deprecated
- */
- @Deprecated
- @Override
- public URL getResourceURL(final String path, final long hostBundleID,
+ public URL getResourceURL(final String path, final Module hostModule,
final int index) {
- return delegate.getResourceURL(path, hostBundleID, index);
+ return delegate.getResourceURL(path, hostModule, index);
}
/**
- * @see org.eclipse.osgi.baseadaptor.bundlefile.BundleFile#open()
+ * @see BundleFile#open()
*/
@Override
public void open() throws IOException {
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AbstractWeavingHook.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AbstractWeavingHook.java
index e25d047..c77e71b 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AbstractWeavingHook.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AbstractWeavingHook.java
@@ -12,32 +12,14 @@
package org.eclipse.equinox.weaving.hooks;
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.ProtectionDomain;
-import java.util.ArrayList;
-import java.util.Properties;
-
import org.eclipse.equinox.service.weaving.ISupplementerRegistry;
-import org.eclipse.osgi.baseadaptor.BaseAdaptor;
-import org.eclipse.osgi.baseadaptor.BaseData;
-import org.eclipse.osgi.baseadaptor.HookConfigurator;
-import org.eclipse.osgi.baseadaptor.HookRegistry;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
-import org.eclipse.osgi.baseadaptor.hooks.AdaptorHook;
-import org.eclipse.osgi.baseadaptor.hooks.BundleFileWrapperFactoryHook;
-import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook;
-import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingStatsHook;
-import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
-import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;
-import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
-import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;
-import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
-import org.eclipse.osgi.framework.log.FrameworkLog;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
+import org.eclipse.equinox.weaving.adaptors.Debug;
+import org.eclipse.osgi.internal.hookregistry.ActivatorHookFactory;
+import org.eclipse.osgi.internal.hookregistry.BundleFileWrapperFactoryHook;
+import org.eclipse.osgi.internal.hookregistry.ClassLoaderHook;
+import org.eclipse.osgi.internal.hookregistry.HookConfigurator;
+import org.eclipse.osgi.internal.hookregistry.HookRegistry;
+import org.osgi.framework.BundleActivator;
/**
* Default implementation of all the necessary adaptor hooks. Used to keep the
@@ -46,9 +28,9 @@
* @author Matthew Webster
* @author Martin Lippert
*/
-public abstract class AbstractWeavingHook implements HookConfigurator,
- AdaptorHook, BundleFileWrapperFactoryHook, ClassLoadingHook,
- ClassLoadingStatsHook, IAdaptorProvider {
+public abstract class AbstractWeavingHook extends ClassLoaderHook implements
+ HookConfigurator, BundleFileWrapperFactoryHook, IAdaptorProvider,
+ ActivatorHookFactory, BundleActivator {
/**
* flag to indicate whether to print out detailed information or not
@@ -59,19 +41,6 @@
private ISupplementerRegistry supplementerRegistry;
/**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#addClassPathEntry(java.util.ArrayList,
- * java.lang.String,
- * org.eclipse.osgi.baseadaptor.loader.ClasspathManager,
- * org.eclipse.osgi.baseadaptor.BaseData,
- * java.security.ProtectionDomain)
- */
- public boolean addClassPathEntry(final ArrayList cpEntries,
- final String cp, final ClasspathManager hostmanager,
- final BaseData sourcedata, final ProtectionDomain sourcedomain) {
- return false;
- }
-
- /**
* @see org.eclipse.osgi.baseadaptor.HookConfigurator#addHooks(org.eclipse.osgi.baseadaptor.HookRegistry)
*/
public void addHooks(final HookRegistry hooks) {
@@ -79,75 +48,21 @@
System.err
.println("[org.eclipse.equinox.weaving.hook] info adding AspectJ hooks ..."); //$NON-NLS-1$
+ Debug.init(hooks.getConfiguration().getDebugOptions());
supplementerRegistry = new SupplementerRegistry(this);
- hooks.addAdaptorHook(this);
- hooks.addClassLoadingHook(this);
+ hooks.addClassLoaderHook(this);
hooks.addBundleFileWrapperFactoryHook(this);
- hooks.addClassLoadingStatsHook(this);
- hooks.addClassLoaderDelegateHook(new WeavingLoaderDelegateHook(
+ hooks.addActivatorHookFactory(this);
+ hooks.addClassLoaderHook(new WeavingLoaderDelegateHook(
supplementerRegistry));
}
/**
- * @see org.eclipse.osgi.baseadaptor.hooks.AdaptorHook#addProperties(java.util.Properties)
+ * @see org.eclipse.osgi.internal.hookregistry.ActivatorHookFactory#createActivator()
*/
- public void addProperties(final Properties properties) {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#createClassLoader(java.lang.ClassLoader,
- * org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate,
- * org.eclipse.osgi.framework.adaptor.BundleProtectionDomain,
- * org.eclipse.osgi.baseadaptor.BaseData, java.lang.String[])
- */
- public BaseClassLoader createClassLoader(final ClassLoader parent,
- final ClassLoaderDelegate delegate,
- final BundleProtectionDomain domain, final BaseData data,
- final String[] bundleclasspath) {
- return null;
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.AdaptorHook#createFrameworkLog()
- */
- public FrameworkLog createFrameworkLog() {
- return null;
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#findLibrary(org.eclipse.osgi.baseadaptor.BaseData,
- * java.lang.String)
- */
- public String findLibrary(final BaseData data, final String libName) {
- return null;
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.AdaptorHook#frameworkStart(org.osgi.framework.BundleContext)
- */
- public void frameworkStart(final BundleContext context)
- throws BundleException {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.AdaptorHook#frameworkStop(org.osgi.framework.BundleContext)
- */
- public void frameworkStop(final BundleContext context)
- throws BundleException {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.AdaptorHook#frameworkStopping(org.osgi.framework.BundleContext)
- */
- public void frameworkStopping(final BundleContext context) {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#getBundleClassLoaderParent()
- */
- public ClassLoader getBundleClassLoaderParent() {
- return null;
+ public BundleActivator createActivator() {
+ return this;
}
/**
@@ -160,107 +75,4 @@
return this.supplementerRegistry;
}
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.AdaptorHook#handleRuntimeError(java.lang.Throwable)
- */
- public void handleRuntimeError(final Throwable error) {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.AdaptorHook#initialize(org.eclipse.osgi.baseadaptor.BaseAdaptor)
- */
- public void initialize(final BaseAdaptor adaptor) {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#initializedClassLoader(org.eclipse.osgi.baseadaptor.loader.BaseClassLoader,
- * org.eclipse.osgi.baseadaptor.BaseData)
- */
- public void initializedClassLoader(final BaseClassLoader baseClassLoader,
- final BaseData data) {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.AdaptorHook#mapLocationToURLConnection(java.lang.String)
- */
- public URLConnection mapLocationToURLConnection(final String location)
- throws IOException {
- return null;
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.AdaptorHook#matchDNChain(java.lang.String,
- * java.lang.String[])
- */
- public boolean matchDNChain(final String pattern, final String[] dnChain) {
- return false;
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingStatsHook#postFindLocalClass(java.lang.String,
- * java.lang.Class,
- * org.eclipse.osgi.baseadaptor.loader.ClasspathManager)
- */
- public void postFindLocalClass(final String name, final Class clazz,
- final ClasspathManager manager) {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingStatsHook#postFindLocalResource(java.lang.String,
- * java.net.URL, org.eclipse.osgi.baseadaptor.loader.ClasspathManager)
- */
- public void postFindLocalResource(final String name, final URL resource,
- final ClasspathManager manager) {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingStatsHook#preFindLocalClass(java.lang.String,
- * org.eclipse.osgi.baseadaptor.loader.ClasspathManager)
- */
- public void preFindLocalClass(final String name,
- final ClasspathManager manager) throws ClassNotFoundException {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingStatsHook#preFindLocalResource(java.lang.String,
- * org.eclipse.osgi.baseadaptor.loader.ClasspathManager)
- */
- public void preFindLocalResource(final String name,
- final ClasspathManager manager) {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook#processClass(java.lang.String,
- * byte[], org.eclipse.osgi.baseadaptor.loader.ClasspathEntry,
- * org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry,
- * org.eclipse.osgi.baseadaptor.loader.ClasspathManager)
- */
- public byte[] processClass(final String name, final byte[] classbytes,
- final ClasspathEntry classpathEntry, final BundleEntry entry,
- final ClasspathManager manager) {
- return null;
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.ClassLoadingStatsHook#recordClassDefine(java.lang.String,
- * java.lang.Class, byte[],
- * org.eclipse.osgi.baseadaptor.loader.ClasspathEntry,
- * org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry,
- * org.eclipse.osgi.baseadaptor.loader.ClasspathManager)
- */
- public void recordClassDefine(final String name, final Class clazz,
- final byte[] classbytes, final ClasspathEntry classpathEntry,
- final BundleEntry entry, final ClasspathManager manager) {
- }
-
- /**
- * @see org.eclipse.osgi.baseadaptor.hooks.BundleFileWrapperFactoryHook#wrapBundleFile(org.eclipse.osgi.baseadaptor.bundlefile.BundleFile,
- * java.lang.Object, org.eclipse.osgi.baseadaptor.BaseData, boolean)
- */
- public BundleFile wrapBundleFile(final BundleFile bundleFile,
- final Object content, final BaseData data, final boolean base)
- throws IOException {
- return null;
- }
-
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/BaseWeavingBundleFile.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/BaseWeavingBundleFile.java
index 69be72b..342d4bb 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/BaseWeavingBundleFile.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/BaseWeavingBundleFile.java
@@ -12,14 +12,12 @@
package org.eclipse.equinox.weaving.hooks;
-import java.io.IOException;
-
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
+import org.eclipse.osgi.storage.bundlefile.BundleFile;
public class BaseWeavingBundleFile extends WeavingBundleFile {
public BaseWeavingBundleFile(final BundleAdaptorProvider adaptorProvider,
- final BundleFile bundleFile) throws IOException {
+ final BundleFile bundleFile) {
super(adaptorProvider, bundleFile);
}
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/BundleAdaptorProvider.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/BundleAdaptorProvider.java
index 01c934b..fc365dd 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/BundleAdaptorProvider.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/BundleAdaptorProvider.java
@@ -12,27 +12,29 @@
package org.eclipse.equinox.weaving.hooks;
import org.eclipse.equinox.weaving.adaptors.IWeavingAdaptor;
-import org.eclipse.osgi.baseadaptor.BaseData;
-import org.eclipse.osgi.framework.internal.core.BundleFragment;
+import org.eclipse.osgi.storage.BundleInfo.Generation;
+import org.osgi.framework.wiring.BundleRevision;
public class BundleAdaptorProvider {
private final IAdaptorProvider adaptorProvider;
- private final BaseData baseData;
+ private final Generation generation;
- public BundleAdaptorProvider(final BaseData data,
+ public BundleAdaptorProvider(final Generation generation,
final IAdaptorProvider adaptorProvider) {
- this.baseData = data;
+ this.generation = generation;
this.adaptorProvider = adaptorProvider;
}
public IWeavingAdaptor getAdaptor() {
- if (this.baseData.getBundle() instanceof BundleFragment) {
- return this.adaptorProvider.getHostBundleAdaptor(this.baseData
- .getBundleID());
+
+ if ((generation.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
+ return this.adaptorProvider.getHostBundleAdaptor(this.generation
+ .getBundleInfo().getBundleId());
} else {
- return this.adaptorProvider.getAdaptor(this.baseData.getBundleID());
+ return this.adaptorProvider.getAdaptor(this.generation
+ .getBundleInfo().getBundleId());
}
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/CachedClassBundleEntry.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/CachedClassBundleEntry.java
index d2897b9..a43d15e 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/CachedClassBundleEntry.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/CachedClassBundleEntry.java
@@ -16,7 +16,7 @@
import java.net.URL;
import org.eclipse.equinox.weaving.adaptors.IWeavingAdaptor;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
+import org.eclipse.osgi.storage.bundlefile.BundleEntry;
public class CachedClassBundleEntry extends BundleEntry {
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/CachedGeneratedClassBundleEntry.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/CachedGeneratedClassBundleEntry.java
index c2dedf4..ee71888 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/CachedGeneratedClassBundleEntry.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/CachedGeneratedClassBundleEntry.java
@@ -17,7 +17,7 @@
import java.net.URL;
import org.eclipse.equinox.weaving.adaptors.IWeavingAdaptor;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
+import org.eclipse.osgi.storage.bundlefile.BundleEntry;
public class CachedGeneratedClassBundleEntry extends BundleEntry {
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementerRegistry.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementerRegistry.java
index d089a11..aeee5aa 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementerRegistry.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementerRegistry.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Martin Lippert and others.
+ * Copyright (c) 2008, 2013 Martin Lippert and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -28,6 +28,7 @@
import org.eclipse.equinox.service.weaving.ISupplementerRegistry;
import org.eclipse.equinox.service.weaving.Supplementer;
+import org.eclipse.equinox.weaving.adaptors.IWeavingAdaptor;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -35,9 +36,14 @@
import org.osgi.framework.Constants;
import org.osgi.service.packageadmin.PackageAdmin;
+/**
+ * The supplementer registry controls the set of installed supplementer bundles
+ * and calculates which other bundles are supplemented by them.
+ *
+ * @author mlippert
+ */
public class SupplementerRegistry implements ISupplementerRegistry {
- //knibb
/**
* Manifest header (named "Supplement-Bundle") identifying the
* names (and optionally, version numbers) of any bundles supplemented by
@@ -82,7 +88,7 @@
private PackageAdmin packageAdmin;
- private final Map<String, Supplementer> supplementers; // keys of type String (symbolic name of supplementer bundle), values of type Supplementer
+ private final Map<String, Supplementer> supplementers; // keys of type String (symbolic name of supplementer bundle)
private final Map<Long, Supplementer[]> supplementersByBundle;
@@ -124,40 +130,50 @@
*/
public void addSupplementedBundle(final Bundle bundle) {
try {
- final Dictionary<?, ?> manifest = bundle.getHeaders();
+ final Dictionary<?, ?> manifest = bundle.getHeaders(""); //$NON-NLS-1$
final ManifestElement[] imports = ManifestElement.parseHeader(
- Constants.IMPORT_PACKAGE, (String) manifest
- .get(Constants.IMPORT_PACKAGE));
+ Constants.IMPORT_PACKAGE,
+ (String) manifest.get(Constants.IMPORT_PACKAGE));
final ManifestElement[] exports = ManifestElement.parseHeader(
- Constants.EXPORT_PACKAGE, (String) manifest
- .get(Constants.EXPORT_PACKAGE));
+ Constants.EXPORT_PACKAGE,
+ (String) manifest.get(Constants.EXPORT_PACKAGE));
final List<Supplementer> supplementers = getMatchingSupplementers(
bundle.getSymbolicName(), imports, exports);
if (supplementers.size() > 0) {
this.addSupplementedBundle(bundle, supplementers);
}
+
this.supplementersByBundle.put(bundle.getBundleId(), supplementers
.toArray(new Supplementer[supplementers.size()]));
} catch (final BundleException e) {
}
}
+ private void addSupplementedBundle(final Bundle supplementedBundle,
+ final List<Supplementer> supplementers) {
+ for (final Iterator<Supplementer> iterator = supplementers.iterator(); iterator
+ .hasNext();) {
+ final Supplementer supplementer = iterator.next();
+ supplementer.addSupplementedBundle(supplementedBundle);
+ }
+ }
+
/**
* @see org.eclipse.equinox.service.weaving.ISupplementerRegistry#addSupplementer(org.osgi.framework.Bundle,
* boolean)
*/
public void addSupplementer(final Bundle bundle, final boolean updateBundles) {
try {
- final Dictionary<?, ?> manifest = bundle.getHeaders();
+ final Dictionary<?, ?> manifest = bundle.getHeaders(""); //$NON-NLS-1$
final ManifestElement[] supplementBundle = ManifestElement
- .parseHeader(SUPPLEMENT_BUNDLE, (String) manifest
- .get(SUPPLEMENT_BUNDLE));
+ .parseHeader(SUPPLEMENT_BUNDLE,
+ (String) manifest.get(SUPPLEMENT_BUNDLE));
final ManifestElement[] supplementImporter = ManifestElement
- .parseHeader(SUPPLEMENT_IMPORTER, (String) manifest
- .get(SUPPLEMENT_IMPORTER));
+ .parseHeader(SUPPLEMENT_IMPORTER,
+ (String) manifest.get(SUPPLEMENT_IMPORTER));
final ManifestElement[] supplementExporter = ManifestElement
- .parseHeader(SUPPLEMENT_EXPORTER, (String) manifest
- .get(SUPPLEMENT_EXPORTER));
+ .parseHeader(SUPPLEMENT_EXPORTER,
+ (String) manifest.get(SUPPLEMENT_EXPORTER));
if (supplementBundle != null || supplementImporter != null
|| supplementExporter != null) {
@@ -231,22 +247,38 @@
}
}
+ private boolean isSupplementerMatching(final String symbolicName,
+ final ManifestElement[] imports, final ManifestElement[] exports,
+ final Supplementer supplementer) {
+ final String supplementerName = supplementer.getSymbolicName();
+ if (!supplementerName.equals(symbolicName)) {
+ if (supplementer.matchSupplementer(symbolicName)
+ || (imports != null && supplementer
+ .matchesSupplementImporter(imports))
+ || (exports != null && supplementer
+ .matchesSupplementExporter(exports))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Refreshes the given bundles
*
* @param bundles The bundles to refresh
*/
public void refreshBundles(final Bundle[] bundles) {
- if (this.packageAdmin != null) {
- if (AbstractWeavingHook.verbose) {
- for (int i = 0; i < bundles.length; i++) {
- System.out.println("refresh bundle: "
- + bundles[i].getSymbolicName());
- }
- }
-
- this.packageAdmin.refreshPackages(bundles);
- }
+ // if (this.packageAdmin != null) {
+ // if (AbstractWeavingHook.verbose) {
+ // for (int i = 0; i < bundles.length; i++) {
+ // System.out.println("refresh bundle: "
+ // + bundles[i].getSymbolicName());
+ // }
+ // }
+ //
+ // this.packageAdmin.refreshPackages(bundles);
+ // }
}
/**
@@ -296,51 +328,12 @@
final List<Supplementer> supplementerList = new ArrayList<Supplementer>(
Arrays.asList(this.supplementersByBundle.get(bundleId)));
supplementerList.remove(supplementer);
- this.supplementersByBundle.put(bundleId, supplementerList
- .toArray(new Supplementer[0]));
+ this.supplementersByBundle.put(bundleId,
+ supplementerList.toArray(new Supplementer[0]));
}
}
}
- /**
- * @see org.eclipse.equinox.service.weaving.ISupplementerRegistry#setBundleContext(org.osgi.framework.BundleContext)
- */
- public void setBundleContext(final BundleContext context) {
- this.context = context;
- }
-
- /**
- * @see org.eclipse.equinox.service.weaving.ISupplementerRegistry#setPackageAdmin(org.osgi.service.packageadmin.PackageAdmin)
- */
- public void setPackageAdmin(final PackageAdmin packageAdmin) {
- this.packageAdmin = packageAdmin;
- }
-
- private void addSupplementedBundle(final Bundle supplementedBundle,
- final List<Supplementer> supplementers) {
- for (final Iterator<Supplementer> iterator = supplementers.iterator(); iterator
- .hasNext();) {
- final Supplementer supplementer = iterator.next();
- supplementer.addSupplementedBundle(supplementedBundle);
- }
- }
-
- private boolean isSupplementerMatching(final String symbolicName,
- final ManifestElement[] imports, final ManifestElement[] exports,
- final Supplementer supplementer) {
- final String supplementerName = supplementer.getSymbolicName();
- if (!supplementerName.equals(symbolicName)) {
- if (supplementer.matchSupplementer(symbolicName)
- || (imports != null && supplementer
- .matchesSupplementImporter(imports))
- || (exports != null && supplementer
- .matchesSupplementExporter(exports))) {
- return true;
- }
- }
- return false;
- }
-
private void removeSupplementedBundle(final Bundle bundle) {
for (final Iterator<Supplementer> iterator = this.supplementers
.values().iterator(); iterator.hasNext();) {
@@ -370,17 +363,19 @@
}
// find out which of the installed bundles matches the new supplementer
- final Dictionary<?, ?> manifest = bundle.getHeaders();
+ final Dictionary<?, ?> manifest = bundle.getHeaders(""); //$NON-NLS-1$
final ManifestElement[] imports = ManifestElement.parseHeader(
- Constants.IMPORT_PACKAGE, (String) manifest
- .get(Constants.IMPORT_PACKAGE));
+ Constants.IMPORT_PACKAGE,
+ (String) manifest.get(Constants.IMPORT_PACKAGE));
final ManifestElement[] exports = ManifestElement.parseHeader(
- Constants.EXPORT_PACKAGE, (String) manifest
- .get(Constants.EXPORT_PACKAGE));
+ Constants.EXPORT_PACKAGE,
+ (String) manifest.get(Constants.EXPORT_PACKAGE));
if (isSupplementerMatching(bundle.getSymbolicName(), imports,
exports, supplementer)) {
- if (this.adaptorProvider.getAdaptor(bundle.getBundleId()) != null) {
+ final IWeavingAdaptor adaptor = this.adaptorProvider
+ .getAdaptor(bundle.getBundleId());
+ if (adaptor != null && adaptor.isInitialized()) {
bundlesToRefresh.add(bundle);
} else {
supplementer.addSupplementedBundle(bundle);
@@ -415,4 +410,18 @@
refreshBundles(bundles);
}
}
+
+ /**
+ * @see org.eclipse.equinox.service.weaving.ISupplementerRegistry#setBundleContext(org.osgi.framework.BundleContext)
+ */
+ public void setBundleContext(final BundleContext context) {
+ this.context = context;
+ }
+
+ /**
+ * @see org.eclipse.equinox.service.weaving.ISupplementerRegistry#setPackageAdmin(org.osgi.service.packageadmin.PackageAdmin)
+ */
+ public void setPackageAdmin(final PackageAdmin packageAdmin) {
+ this.packageAdmin = packageAdmin;
+ }
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingBundleEntry.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingBundleEntry.java
index 4ec862d..3adb0ab 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingBundleEntry.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingBundleEntry.java
@@ -19,7 +19,7 @@
import java.net.URL;
import org.eclipse.equinox.weaving.adaptors.IWeavingAdaptor;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
+import org.eclipse.osgi.storage.bundlefile.BundleEntry;
public class WeavingBundleEntry extends BundleEntry {
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingBundleFile.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingBundleFile.java
index 782c18d..ac1657c 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingBundleFile.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingBundleFile.java
@@ -15,13 +15,14 @@
package org.eclipse.equinox.weaving.hooks;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.equinox.service.weaving.CacheEntry;
import org.eclipse.equinox.weaving.adaptors.Debug;
import org.eclipse.equinox.weaving.adaptors.IWeavingAdaptor;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
+import org.eclipse.osgi.storage.bundlefile.BundleEntry;
+import org.eclipse.osgi.storage.bundlefile.BundleFile;
/**
* This is a wrapper for bundle files that allows the weaving runtime to create
@@ -43,9 +44,14 @@
* @throws IOException
*/
public WeavingBundleFile(final BundleAdaptorProvider adaptorProvider,
- final BundleFile bundleFile) throws IOException {
+ final BundleFile bundleFile) {
super(adaptorProvider, bundleFile);
- this.url = delegate.getBaseFile().toURL();
+ try {
+ this.url = delegate.getBaseFile().toURL();
+ } catch (final MalformedURLException e) {
+ throw new RuntimeException(
+ "Unexpected error getting bundle file URL.", e);
+ }
}
@Override
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingHook.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingHook.java
index 0b7d8f1..39596e7 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingHook.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingHook.java
@@ -13,7 +13,6 @@
package org.eclipse.equinox.weaving.hooks;
-import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
@@ -23,12 +22,12 @@
import org.eclipse.equinox.weaving.adaptors.IWeavingAdaptor;
import org.eclipse.equinox.weaving.adaptors.WeavingAdaptor;
import org.eclipse.equinox.weaving.adaptors.WeavingAdaptorFactory;
-import org.eclipse.osgi.baseadaptor.BaseData;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
-import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
-import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
-import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;
-import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
+import org.eclipse.osgi.internal.loader.ModuleClassLoader;
+import org.eclipse.osgi.internal.loader.classpath.ClasspathEntry;
+import org.eclipse.osgi.internal.loader.classpath.ClasspathManager;
+import org.eclipse.osgi.storage.BundleInfo.Generation;
+import org.eclipse.osgi.storage.bundlefile.BundleEntry;
+import org.eclipse.osgi.storage.bundlefile.BundleFile;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -44,28 +43,53 @@
private BundleContext bundleContext;
public WeavingHook() {
- if (Debug.DEBUG_GENERAL) Debug.println("- AspectJHook.<init>()");
+ if (Debug.DEBUG_GENERAL) Debug.println("- WeavingHook.<init>()");
+
this.adaptorFactory = new WeavingAdaptorFactory();
this.adaptors = new HashMap<Long, IWeavingAdaptor>();
}
- /**
- * @see org.eclipse.equinox.weaving.hooks.AbstractWeavingHook#frameworkStart(org.osgi.framework.BundleContext)
- */
@Override
- public void frameworkStart(final BundleContext context)
- throws BundleException {
- // Debug.println("? AspectJHook.frameworkStart() context=" + context + ", fdo=" + FrameworkDebugOptions.getDefault());
- initialize(context);
+ public void classLoaderCreated(final ModuleClassLoader classLoader) {
+ if (Debug.DEBUG_GENERAL)
+ Debug.println("> WeavingHook.initializedClassLoader() bundle="
+ + classLoader.getBundle().getSymbolicName()
+ + ", loader="
+ + classLoader
+ + ", bundleFile="
+ + classLoader.getClasspathManager().getGeneration()
+ .getBundleFile());
+
+ final IWeavingAdaptor adaptor = createWeavingAdaptor(classLoader
+ .getClasspathManager().getGeneration(), classLoader);
+ this.adaptors.put(classLoader.getBundle().getBundleId(), adaptor);
+
+ if (Debug.DEBUG_GENERAL)
+ Debug.println("< WeavingHook.initializedClassLoader() adaptor="
+ + adaptor);
}
- /**
- * @see org.eclipse.equinox.weaving.hooks.AbstractWeavingHook#frameworkStop(org.osgi.framework.BundleContext)
- */
- @Override
- public void frameworkStop(final BundleContext context)
- throws BundleException {
- adaptorFactory.dispose(context);
+ private IWeavingAdaptor createWeavingAdaptor(final Generation generation,
+ final ModuleClassLoader classLoader) {
+ if (Debug.DEBUG_GENERAL)
+ Debug.println("> WeavingHook.createAspectJAdaptor() location="
+ + generation.getRevision().getRevisions().getModule()
+ .getLocation());
+ IWeavingAdaptor adaptor = null;
+
+ if (adaptorFactory != null) {
+ adaptor = new WeavingAdaptor(generation, adaptorFactory, null,
+ null, classLoader);
+ } else {
+ if (Debug.DEBUG_GENERAL)
+ Debug.println("- WeavingHook.createAspectJAdaptor() factory="
+ + adaptorFactory);
+ }
+
+ if (Debug.DEBUG_GENERAL)
+ Debug.println("< WeavingHook.createAspectJAdaptor() adaptor="
+ + adaptor);
+ return adaptor;
}
public IWeavingAdaptor getAdaptor(final long bundleID) {
@@ -84,28 +108,37 @@
return null;
}
- /**
- * @see org.eclipse.equinox.weaving.hooks.AbstractWeavingHook#initializedClassLoader(org.eclipse.osgi.baseadaptor.loader.BaseClassLoader,
- * org.eclipse.osgi.baseadaptor.BaseData)
- */
- @Override
- public void initializedClassLoader(final BaseClassLoader baseClassLoader,
- final BaseData data) {
+ private void initialize(final BundleContext context) {
if (Debug.DEBUG_GENERAL)
- Debug
- .println("> AspectJHook.initializedClassLoader() bundle="
- + data.getSymbolicName() + ", loader="
- + baseClassLoader + ", data=" + data
- + ", bundleFile=" + data.getBundleFile());
+ Debug.println("> WeavingHook.initialize() context=" + context);
- final IWeavingAdaptor adaptor = createAspectJAdaptor(data);
- adaptor.setBaseClassLoader(baseClassLoader);
- adaptor.initialize();
- this.adaptors.put(data.getBundleID(), adaptor);
+ this.bundleContext = context;
+
+ final ISupplementerRegistry supplementerRegistry = getSupplementerRegistry();
+ adaptorFactory.initialize(context, supplementerRegistry);
+
+ final ServiceReference serviceReference = context
+ .getServiceReference(PackageAdmin.class.getName());
+ final PackageAdmin packageAdmin = (PackageAdmin) context
+ .getService(serviceReference);
+
+ supplementerRegistry.setBundleContext(context);
+ supplementerRegistry.setPackageAdmin(packageAdmin);
+ context.addBundleListener(new SupplementBundleListener(
+ supplementerRegistry));
+
+ // final re-build supplementer final registry state for final installed bundles
+ final Bundle[] installedBundles = context.getBundles();
+ for (int i = 0; i < installedBundles.length; i++) {
+ supplementerRegistry.addSupplementer(installedBundles[i], false);
+ }
+ for (int i = 0; i < installedBundles.length; i++) {
+ supplementerRegistry.addSupplementedBundle(installedBundles[i]);
+ }
if (Debug.DEBUG_GENERAL)
- Debug.println("< AspectJHook.initializedClassLoader() adaptor="
- + adaptor);
+ Debug.println("< WeavingHook.initialize() adaptorFactory="
+ + adaptorFactory);
}
/**
@@ -160,92 +193,45 @@
this.adaptors.remove(bundleID);
}
- @Override
+ /**
+ * @see org.eclipse.equinox.weaving.hooks.AbstractWeavingHook#frameworkStart(org.osgi.framework.BundleContext)
+ */
+ public void start(final BundleContext context) throws BundleException {
+ initialize(context);
+ }
+
+ /**
+ * @see org.eclipse.equinox.weaving.hooks.AbstractWeavingHook#frameworkStop(org.osgi.framework.BundleContext)
+ */
+ public void stop(final BundleContext context) throws BundleException {
+ adaptorFactory.dispose(context);
+ }
+
+ /**
+ * @see org.eclipse.osgi.internal.hookregistry.BundleFileWrapperFactoryHook#wrapBundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile,
+ * org.eclipse.osgi.storage.BundleInfo.Generation, boolean)
+ */
public BundleFile wrapBundleFile(final BundleFile bundleFile,
- final Object content, final BaseData data, final boolean base)
- throws IOException {
+ final Generation generation, final boolean base) {
BundleFile wrapped = null;
if (Debug.DEBUG_BUNDLE)
- Debug
- .println("> AspectJBundleFileWrapperFactoryHook.wrapBundleFile() bundle="
- + data.getSymbolicName()
- + " bundleFile="
- + bundleFile
- + ", content="
- + content
- + ", data="
- + data
- + ", base="
- + base
- + ", baseFile="
- + bundleFile.getBaseFile());
+ Debug.println("> WeavingHook.wrapBundleFile() bundle="
+ + (generation.getRevision() != null ? generation
+ .getRevision().getSymbolicName() : generation
+ .getBundleInfo().getBundleId()) + " bundleFile="
+ + bundleFile + ", generation=" + generation + ", base="
+ + base + ", baseFile=" + bundleFile.getBaseFile());
if (base) {
- wrapped = new BaseWeavingBundleFile(new BundleAdaptorProvider(data,
- this), bundleFile);
+ wrapped = new BaseWeavingBundleFile(new BundleAdaptorProvider(
+ generation, this), bundleFile);
} else {
- wrapped = new WeavingBundleFile(new BundleAdaptorProvider(data,
- this), bundleFile);
+ wrapped = new WeavingBundleFile(new BundleAdaptorProvider(
+ generation, this), bundleFile);
}
if (Debug.DEBUG_BUNDLE)
- Debug
- .println("< AspectJBundleFileWrapperFactoryHook.wrapBundleFile() wrapped="
- + wrapped);
+ Debug.println("< WeavingHook.wrapBundleFile() wrapped=" + wrapped);
return wrapped;
}
- private IWeavingAdaptor createAspectJAdaptor(final BaseData baseData) {
- if (Debug.DEBUG_GENERAL)
- Debug.println("> AspectJHook.createAspectJAdaptor() location="
- + baseData.getLocation());
- IWeavingAdaptor adaptor = null;
-
- if (adaptorFactory != null) {
- adaptor = new WeavingAdaptor(baseData, adaptorFactory, null, null,
- null);
- } else {
- if (Debug.DEBUG_GENERAL)
- Debug.println("- AspectJHook.createAspectJAdaptor() factory="
- + adaptorFactory);
- }
-
- if (Debug.DEBUG_GENERAL)
- Debug.println("< AspectJHook.createAspectJAdaptor() adaptor="
- + adaptor);
- return adaptor;
- }
-
- private void initialize(final BundleContext context) {
- if (Debug.DEBUG_GENERAL)
- Debug.println("> AspectJHook.initialize() context=" + context);
-
- this.bundleContext = context;
-
- final ISupplementerRegistry supplementerRegistry = getSupplementerRegistry();
- adaptorFactory.initialize(context, supplementerRegistry);
-
- final ServiceReference serviceReference = context
- .getServiceReference(PackageAdmin.class.getName());
- final PackageAdmin packageAdmin = (PackageAdmin) context
- .getService(serviceReference);
-
- supplementerRegistry.setBundleContext(context);
- supplementerRegistry.setPackageAdmin(packageAdmin);
- context.addBundleListener(new SupplementBundleListener(
- supplementerRegistry));
-
- // final re-build supplementer final registry state for final installed bundles
- final Bundle[] installedBundles = context.getBundles();
- for (int i = 0; i < installedBundles.length; i++) {
- supplementerRegistry.addSupplementer(installedBundles[i], false);
- }
- for (int i = 0; i < installedBundles.length; i++) {
- supplementerRegistry.addSupplementedBundle(installedBundles[i]);
- }
-
- if (Debug.DEBUG_GENERAL)
- Debug.println("< AspectJHook.initialize() adaptorFactory="
- + adaptorFactory);
- }
-
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingLoaderDelegateHook.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingLoaderDelegateHook.java
index 7f029fa..bd7ddcb 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingLoaderDelegateHook.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/WeavingLoaderDelegateHook.java
@@ -20,9 +20,8 @@
import org.eclipse.equinox.service.weaving.ISupplementerRegistry;
import org.eclipse.equinox.service.weaving.Supplementer;
-import org.eclipse.osgi.framework.adaptor.BundleClassLoader;
-import org.eclipse.osgi.framework.adaptor.BundleData;
-import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook;
+import org.eclipse.osgi.internal.hookregistry.ClassLoaderHook;
+import org.eclipse.osgi.internal.loader.ModuleClassLoader;
/**
* This class implements the delegate hook for the class loader to allow
@@ -35,7 +34,7 @@
* information to broaden type and resource visibility according to the
* supplementer registry information.
*/
-public class WeavingLoaderDelegateHook implements ClassLoaderDelegateHook {
+public class WeavingLoaderDelegateHook extends ClassLoaderHook {
private final ThreadLocal<Set<String>> postFindClassCalls = new ThreadLocal<Set<String>>() {
@@ -77,14 +76,14 @@
}
/**
- * @see org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook#postFindClass(java.lang.String,
- * org.eclipse.osgi.framework.adaptor.BundleClassLoader,
- * org.eclipse.osgi.framework.adaptor.BundleData)
+ *
+ * @see org.eclipse.osgi.internal.hookregistry.ClassLoaderHook#postFindClass(java.lang.String,
+ * org.eclipse.osgi.internal.loader.ModuleClassLoader)
*/
- public Class postFindClass(final String name,
- final BundleClassLoader classLoader, final BundleData data)
- throws ClassNotFoundException {
- final long bundleID = data.getBundleID();
+ @Override
+ public Class<?> postFindClass(final String name,
+ final ModuleClassLoader classLoader) throws ClassNotFoundException {
+ final long bundleID = classLoader.getBundle().getBundleId();
final String callKey = bundleID + name;
if (postFindClassCalls.get().contains(callKey)) {
@@ -115,24 +114,14 @@
}
/**
- * @see org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook#postFindLibrary(java.lang.String,
- * org.eclipse.osgi.framework.adaptor.BundleClassLoader,
- * org.eclipse.osgi.framework.adaptor.BundleData)
+ *
+ * @see org.eclipse.osgi.internal.hookregistry.ClassLoaderHook#postFindResource(java.lang.String,
+ * org.eclipse.osgi.internal.loader.ModuleClassLoader)
*/
- public String postFindLibrary(final String name,
- final BundleClassLoader classLoader, final BundleData data) {
- return null;
- }
-
- /**
- * @see org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook#postFindResource(java.lang.String,
- * org.eclipse.osgi.framework.adaptor.BundleClassLoader,
- * org.eclipse.osgi.framework.adaptor.BundleData)
- */
+ @Override
public URL postFindResource(final String name,
- final BundleClassLoader classLoader, final BundleData data)
- throws FileNotFoundException {
- final long bundleID = data.getBundleID();
+ final ModuleClassLoader classLoader) throws FileNotFoundException {
+ final long bundleID = classLoader.getBundle().getBundleId();
final String callKey = bundleID + name;
if (postFindResourceCalls.get().contains(callKey)) {
@@ -164,14 +153,14 @@
}
/**
- * @see org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook#postFindResources(java.lang.String,
- * org.eclipse.osgi.framework.adaptor.BundleClassLoader,
- * org.eclipse.osgi.framework.adaptor.BundleData)
+ *
+ * @see org.eclipse.osgi.internal.hookregistry.ClassLoaderHook#postFindResources(java.lang.String,
+ * org.eclipse.osgi.internal.loader.ModuleClassLoader)
*/
- public Enumeration postFindResources(final String name,
- final BundleClassLoader classLoader, final BundleData data)
- throws FileNotFoundException {
- final long bundleID = data.getBundleID();
+ @Override
+ public Enumeration<URL> postFindResources(final String name,
+ final ModuleClassLoader classLoader) throws FileNotFoundException {
+ final long bundleID = classLoader.getBundle().getBundleId();
final String callKey = bundleID + name;
if (postFindResourcesCalls.get().contains(callKey)) {
@@ -185,7 +174,7 @@
if (supplementers != null) {
for (int i = 0; i < supplementers.length; i++) {
try {
- final Enumeration<?> resource = supplementers[i]
+ final Enumeration<URL> resource = supplementers[i]
.getSupplementerHost().getResources(name);
if (resource != null) {
// TODO: if more than one enumeration is found, we should return all items
@@ -202,49 +191,4 @@
return null;
}
-
- /**
- * @see org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook#preFindClass(java.lang.String,
- * org.eclipse.osgi.framework.adaptor.BundleClassLoader,
- * org.eclipse.osgi.framework.adaptor.BundleData)
- */
- public Class preFindClass(final String name,
- final BundleClassLoader classLoader, final BundleData data)
- throws ClassNotFoundException {
- return null;
- }
-
- /**
- * @see org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook#preFindLibrary(java.lang.String,
- * org.eclipse.osgi.framework.adaptor.BundleClassLoader,
- * org.eclipse.osgi.framework.adaptor.BundleData)
- */
- public String preFindLibrary(final String name,
- final BundleClassLoader classLoader, final BundleData data)
- throws FileNotFoundException {
- return null;
- }
-
- /**
- * @see org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook#preFindResource(java.lang.String,
- * org.eclipse.osgi.framework.adaptor.BundleClassLoader,
- * org.eclipse.osgi.framework.adaptor.BundleData)
- */
- public URL preFindResource(final String name,
- final BundleClassLoader classLoader, final BundleData data)
- throws FileNotFoundException {
- return null;
- }
-
- /**
- * @see org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook#preFindResources(java.lang.String,
- * org.eclipse.osgi.framework.adaptor.BundleClassLoader,
- * org.eclipse.osgi.framework.adaptor.BundleData)
- */
- public Enumeration preFindResources(final String name,
- final BundleClassLoader classLoader, final BundleData data)
- throws FileNotFoundException {
- return null;
- }
-
}