This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 371db1a3b7 Clean up code, suppress warnings
371db1a3b7 is described below
commit 371db1a3b7b07a0212933740f9cda5a8996a80dc
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Mon Aug 14 14:23:38 2023 +0200
Clean up code, suppress warnings
---
.../internal/core/BundlesConfigurationPrinter.java | 122 +++++----------------
1 file changed, 27 insertions(+), 95 deletions(-)
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesConfigurationPrinter.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesConfigurationPrinter.java
index f06c016b52..6e48c8fe66 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesConfigurationPrinter.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesConfigurationPrinter.java
@@ -19,89 +19,38 @@ package org.apache.felix.webconsole.internal.core;
import java.io.PrintWriter;
import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.Map;
import java.util.TreeMap;
import org.apache.felix.webconsole.internal.AbstractConfigurationPrinter;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.service.packageadmin.PackageAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.osgi.framework.wiring.BundleRevision;
/**
* The <code>BundlesConfigurationPrinter</code> prints out the bundle list.
*/
public class BundlesConfigurationPrinter
- extends AbstractConfigurationPrinter
-{
-
- private ServiceTracker<PackageAdmin, PackageAdmin> packageAdminTracker;
-
- /**
- * @see
org.apache.felix.webconsole.internal.AbstractConfigurationPrinter#activate(org.osgi.framework.BundleContext)
- */
- public void activate(final BundleContext bundleContext)
- {
- super.activate(bundleContext);
- this.packageAdminTracker = new ServiceTracker(bundleContext,
PackageAdmin.class, new ServiceTrackerCustomizer<PackageAdmin, PackageAdmin>() {
- public PackageAdmin addingService(final
org.osgi.framework.ServiceReference<PackageAdmin> reference) {
- return bundleContext.getService(reference);
- }
-
- public void modifiedService(final
org.osgi.framework.ServiceReference<PackageAdmin> reference, final PackageAdmin
service) {
- // nothing to do
- }
-
- public void removedService(final
org.osgi.framework.ServiceReference<PackageAdmin> reference, final PackageAdmin
service) {
- try {
- bundleContext.ungetService(reference);
- } catch (IllegalStateException ise) {
- // ignore, bundle context was shut down concurrently
- }
- }
- });
- this.packageAdminTracker.open();
- }
-
- /**
- * @see
org.apache.felix.webconsole.internal.AbstractConfigurationPrinter#deactivate()
- */
- public void deactivate()
- {
- if ( this.packageAdminTracker != null )
- {
- this.packageAdminTracker.close();
- this.packageAdminTracker = null;
- }
- super.deactivate();
- }
+ extends AbstractConfigurationPrinter {
/**
* @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
*/
- public String getTitle()
- {
+ public String getTitle() {
return "Bundlelist";
}
private String getHeaderValue(final Bundle b, final String name)
{
String val = (String)b.getHeaders().get(name);
- if ( val == null )
- {
+ if ( val == null ) {
val = "";
}
return val;
}
- private String getState(final int state)
- {
- switch (state)
- {
+ private String getState(final int state) {
+ switch (state) {
case Bundle.ACTIVE : return "active";
case Bundle.INSTALLED : return "installed";
case Bundle.RESOLVED : return "resolved";
@@ -112,29 +61,26 @@ public class BundlesConfigurationPrinter
return String.valueOf(state);
}
- private final boolean isFragmentBundle( final Bundle bundle)
- {
- return
((PackageAdmin)this.packageAdminTracker.getService()).getBundleType( bundle )
== PackageAdmin.BUNDLE_TYPE_FRAGMENT;
+ private final boolean isFragmentBundle( final Bundle bundle) {
+ final BundleRevision rev = bundle.adapt(BundleRevision.class);
+ return rev != null && (rev.getTypes() & BundleRevision.TYPE_FRAGMENT)
== BundleRevision.TYPE_FRAGMENT;
}
/**
* @see
org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
*/
- public void printConfiguration( final PrintWriter pw )
- {
+ public void printConfiguration( final PrintWriter pw ) {
final Bundle[] bundles =
BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getBundles();
// create a map for sorting first
- final TreeMap bundlesMap = new TreeMap();
+ final TreeMap<String, String> bundlesMap = new TreeMap<>();
int active = 0, installed = 0, resolved = 0, fragments = 0;
- for( int i =0; i<bundles.length; i++)
- {
+ for( int i =0; i<bundles.length; i++) {
final Bundle bundle = bundles[i];
final String symbolicName = bundle.getSymbolicName();
final String version =
(String)bundle.getHeaders().get(Constants.BUNDLE_VERSION);
// count states and calculate prefix
- switch ( bundle.getState() )
- {
+ switch ( bundle.getState() ) {
case Bundle.ACTIVE:
active++;
break;
@@ -142,12 +88,9 @@ public class BundlesConfigurationPrinter
installed++;
break;
case Bundle.RESOLVED:
- if ( isFragmentBundle( bundle ) )
- {
+ if ( isFragmentBundle( bundle ) ) {
fragments++;
- }
- else
- {
+ } else {
resolved++;
}
break;
@@ -164,54 +107,43 @@ public class BundlesConfigurationPrinter
bundlesMap.put(key, value);
}
- final StringBuffer buffer = new StringBuffer();
+ final StringBuilder buffer = new StringBuilder();
buffer.append("Status: ");
appendBundleInfoCount(buffer, "in total", bundles.length);
- if ( active == bundles.length || active + fragments == bundles.length )
- {
+ if ( active == bundles.length || active + fragments == bundles.length
) {
buffer.append(" - all ");
appendBundleInfoCount(buffer, "active.", bundles.length);
- }
- else
- {
- if ( active != 0 )
- {
+ } else{
+ if ( active != 0 ) {
buffer.append(", ");
appendBundleInfoCount(buffer, "active", active);
}
- if ( fragments != 0 )
- {
+ if ( fragments != 0 ) {
buffer.append(", ");
appendBundleInfoCount(buffer, "active fragments", fragments);
}
- if ( resolved != 0 )
- {
+ if ( resolved != 0 ) {
buffer.append(", ");
appendBundleInfoCount(buffer, "resolved", resolved);
}
- if ( installed != 0 )
- {
+ if ( installed != 0 ) {
buffer.append(", ");
appendBundleInfoCount(buffer, "installed", installed);
}
}
pw.println(buffer.toString());
pw.println();
- final Iterator i = bundlesMap.entrySet().iterator();
- while ( i.hasNext() )
- {
- final Map.Entry entry = (Map.Entry)i.next();
- pw.println(entry.getValue());
-
+ for(final String value : bundlesMap.values()) {
+ pw.println(value);
}
}
- private void appendBundleInfoCount( final StringBuffer buf, String msg,
int count )
- {
+ private void appendBundleInfoCount( final StringBuilder buf, String msg,
int count ) {
buf.append(count);
buf.append(" bundle");
- if ( count != 1 )
+ if ( count != 1 ) {
buf.append( 's' );
+ }
buf.append(' ');
buf.append(msg);
}