Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print registered extensions in framework debug #2988

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions sisu-osgi/sisu-osgi-connect/pom.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.tycho</groupId>
<artifactId>sisu-osgi</artifactId>
<version>5.0.0-SNAPSHOT</version>
</parent>
<artifactId>sisu-osgi-connect</artifactId>
<name>Sisu Implementation of the OSGi R8 Framework Connect Specification</name>

<dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.tycho</groupId>
<artifactId>sisu-osgi</artifactId>
<version>5.0.0-SNAPSHOT</version>
</parent>
<artifactId>sisu-osgi-connect</artifactId>
<name>Sisu Implementation of the OSGi R8 Framework Connect Specification</name>

<dependencies>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>sisu-osgi-api</artifactId>
Expand All @@ -19,13 +21,18 @@
<artifactId>org.eclipse.osgi</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component</artifactId>
<version>1.5.1</version>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.registry</artifactId>
<version>3.11.300</version>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
Expand All @@ -35,9 +42,9 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>
<build>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.sisu.equinox.EquinoxServiceFactory;
import org.eclipse.sisu.equinox.embedder.EquinoxLifecycleListener;
import org.osgi.framework.Bundle;
Expand Down Expand Up @@ -152,8 +156,8 @@ synchronized PlexusConnectFramework getFramework(ClassRealm realm) throws Bundle
for (EquinoxLifecycleListener listener : lifecycleListeners.values()) {
connectFramework.debug("Calling " + listener);
try {
listener.afterFrameworkStarted(connectFramework);
} catch(RuntimeException e) {
listener.afterFrameworkStarted(connectFramework);
} catch (RuntimeException e) {
log.warn("Internal error in EquinoxLifecycleListener " + listener, e);
}
}
Expand Down Expand Up @@ -238,6 +242,62 @@ private static Map<String, String> readProperties(ClassLoader classloader, Logge

private static void printFrameworkState(Framework framework, Logger log) {
Bundle[] bundles = printBundles(framework, log);
printComponents(framework, log);
printExtensions(framework, log);
printServices(log, bundles);
}

private static void printExtensions(Framework framework, Logger log) {
log.info("============ Extension Registry ==================");
ServiceTracker<IExtensionRegistry, IExtensionRegistry> st = new ServiceTracker<>(framework.getBundleContext(),
IExtensionRegistry.class, null);
st.open(true);
try {
IExtensionRegistry registry = st.getService();
if (registry == null) {
log.info("No IExtensionRegistry installed (or started) in this framework");
return;
}
IExtensionPoint[] extensionPoints = registry.getExtensionPoints();
for (IExtensionPoint point : extensionPoints) {
log.info(point.getUniqueIdentifier() + " [contributed by " + point.getContributor() + "]");
for (IExtension extention : point.getExtensions()) {
log.info("\t" + extention.getUniqueIdentifier() + " [from " + extention.getContributor().getName()
+ "]");
for (IConfigurationElement element : extention.getConfigurationElements()) {
printConfigElement(element, 2, log);
}
}
}
} finally {
st.close();
}
}



private static void printConfigElement(IConfigurationElement element, int level, Logger log) {
StringBuilder sb = new StringBuilder();
sb.append("\t".repeat(level));
sb.append(element.getName());
for (String attr : element.getAttributeNames()) {
sb.append(' ');
sb.append(attr);
sb.append('=');
sb.append(element.getAttribute(attr));
}
String value = element.getValue();
if (value != null) {
sb.append(" @value = ");
sb.append(value);
}
log.info(sb.toString());
for (IConfigurationElement child : element.getChildren()) {
printConfigElement(child, level + 1, log);
}
}

private static void printComponents(Framework framework, Logger log) {
ServiceTracker<ServiceComponentRuntime, ServiceComponentRuntime> st = new ServiceTracker<>(
framework.getBundleContext(), ServiceComponentRuntime.class, null);
st.open();
Expand Down Expand Up @@ -268,6 +328,9 @@ private static void printFrameworkState(Framework framework, Logger log) {
} finally {
st.close();
}
}

private static void printServices(Logger log, Bundle[] bundles) {
log.info("============ Registered Services ==================");
Arrays.stream(bundles).map(Bundle::getRegisteredServices).filter(Objects::nonNull).flatMap(Arrays::stream)
.forEach(reference -> {
Expand Down
Loading