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 5acfff8628 Clean up code, suppress warnings
5acfff8628 is described below
commit 5acfff86288dbb0008e060979e0fa25b7466cdcb
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Mon Aug 14 11:47:17 2023 +0200
Clean up code, suppress warnings
---
webconsole/pom.xml | 14 ++---
.../felix/webconsole/AbstractWebConsolePlugin.java | 4 +-
.../felix/webconsole/DefaultVariableResolver.java | 1 +
.../internal/AbstractConfigurationPrinter.java | 6 +--
.../org/apache/felix/webconsole/internal/Util.java | 59 ++--------------------
.../webconsole/internal/compendium/LogServlet.java | 2 +-
.../internal/i18n/ResourceBundleManager.java | 39 ++++----------
.../webconsole/internal/misc/LicenseServlet.java | 1 +
.../webconsole/internal/servlet/OsgiManager.java | 14 +++--
.../felix/webconsole/internal/servlet/Plugin.java | 6 +--
.../webconsole/internal/servlet/PluginHolder.java | 6 +--
11 files changed, 39 insertions(+), 113 deletions(-)
diff --git a/webconsole/pom.xml b/webconsole/pom.xml
index 7fd4e313b8..1a6f58f147 100644
--- a/webconsole/pom.xml
+++ b/webconsole/pom.xml
@@ -369,10 +369,16 @@
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.log</artifactId>
+ <version>1.3.0</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
- <version>8.0.0</version>
+ <version>7.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -399,12 +405,6 @@
<version>1.1.2</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.log</artifactId>
- <version>1.3.0</version>
- <scope>provided</scope>
- </dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.wireadmin</artifactId>
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
index 434ea6031b..f8226fa8e5 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
@@ -47,7 +47,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.felix.webconsole.internal.servlet.OsgiManager;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogLevel;
+import org.osgi.service.log.LogService;
/**
@@ -969,7 +969,7 @@ public abstract class AbstractWebConsolePlugin extends
HttpServlet
}
// template file does not exist, return an empty string
- log( LogLevel.ERROR.ordinal(), "readTemplateFile: File '" +
templateFile + "' not found through class " + clazz ); //$NON-NLS-1$
//$NON-NLS-2$
+ log( LogService.LOG_ERROR, "readTemplateFile: File '" + templateFile +
"' not found through class " + clazz ); //$NON-NLS-1$ //$NON-NLS-2$
return ""; //$NON-NLS-1$
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/DefaultVariableResolver.java
b/webconsole/src/main/java/org/apache/felix/webconsole/DefaultVariableResolver.java
index c0bafb52d8..0ec2f609c2 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/DefaultVariableResolver.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/DefaultVariableResolver.java
@@ -78,6 +78,7 @@ public class DefaultVariableResolver extends HashMap
implements VariableResolver
* @param source the map whose variables are to be placed in this
resolver.
* @see HashMap#HashMap(Map)
*/
+ @SuppressWarnings({"unchecked"})
public DefaultVariableResolver( final Map source )
{
super( source );
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/AbstractConfigurationPrinter.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/AbstractConfigurationPrinter.java
index 6360fc1474..9e45457b7a 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/AbstractConfigurationPrinter.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/AbstractConfigurationPrinter.java
@@ -18,7 +18,6 @@ package org.apache.felix.webconsole.internal;
import org.apache.felix.webconsole.ConfigurationPrinter;
-import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
@@ -26,12 +25,13 @@ import org.osgi.framework.ServiceRegistration;
* AbstractConfigurationPrinter is an utility class, that provides a basic
implementation
* of {@link ConfigurationPrinter} and {@link OsgiManagerPlugin} interfaces.
*/
+@SuppressWarnings("deprecation")
public abstract class AbstractConfigurationPrinter implements
ConfigurationPrinter, OsgiManagerPlugin
{
private BundleContext bundleContext;
- private ServiceRegistration registration;
+ private ServiceRegistration<ConfigurationPrinter> registration;
/**
@@ -40,7 +40,7 @@ public abstract class AbstractConfigurationPrinter implements
ConfigurationPrint
public void activate( BundleContext bundleContext )
{
this.bundleContext = bundleContext;
- this.registration = bundleContext.registerService( SERVICE, this, null
);
+ this.registration = bundleContext.registerService(
ConfigurationPrinter.class, this, null );
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
index c58294e198..51e8874b41 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
@@ -18,10 +18,8 @@ package org.apache.felix.webconsole.internal;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
-import java.util.Enumeration;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
@@ -37,31 +35,7 @@ import org.osgi.framework.Version;
* The <code>Util</code> class contains various utility methods used internally
* by the web console implementation and the build-in plugins.
*/
-public class Util
-{
-
- // FIXME: from the constants below only PARAM_ACTION is used, consider
removal of others?
-
- /** web apps subpage */
- public static final String PAGE_WEBAPPS = "/webapps";
-
- /** vm statistics subpage */
- public static final String PAGE_VM_STAT = "/vmstat";
-
- /** Logs subpage */
- public static final String PAGE_LOGS = "/logs";
-
- /** Parameter name */
- public static final String PARAM_ACTION = "action";
-
- /** Parameter name */
- public static final String PARAM_CONTENT = "content";
-
- /** Parameter name */
- public static final String PARAM_SHUTDOWN = "shutdown";
-
- /** Parameter value */
- public static final String VALUE_SHUTDOWN = "shutdown";
+public class Util {
/**
* Return a display name for the given <code>bundle</code>:
@@ -129,25 +103,6 @@ public class Util
Arrays.sort( bundles, new BundleNameComparator( locale ) );
}
-
- /**
- * This method is the same as Collections#list(Enumeration). The reason to
- * duplicate it here, is that it is missing in OSGi/Minimum execution
- * environment.
- *
- * @param e the enumeration which to convert
- * @return the list containing all enumeration entries.
- */
- public static final ArrayList list( Enumeration e )
- {
- ArrayList l = new ArrayList();
- while ( e.hasMoreElements() )
- {
- l.add( e.nextElement() );
- }
- return l;
- }
-
/**
* This method expects a locale string in format language_COUNTRY, or
* language. The method will determine which is the correct form of locale
@@ -185,23 +140,15 @@ public class Util
return new Locale(language, country);
}
- private static final class BundleNameComparator implements Comparator
+ private static final class BundleNameComparator implements
Comparator<Bundle>
{
private final Locale locale;
- BundleNameComparator( final Locale locale )
- {
+ BundleNameComparator( final Locale locale ) {
this.locale = locale;
}
-
- public int compare( Object o1, Object o2 )
- {
- return compare( ( Bundle ) o1, ( Bundle ) o2 );
- }
-
-
public int compare( Bundle b1, Bundle b2 )
{
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java
index a8d07ab3b6..1a196eca56 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java
@@ -68,7 +68,7 @@ public class LogServlet extends SimpleWebConsolePlugin
implements OsgiManagerPlu
*/
protected void doPost( HttpServletRequest req, HttpServletResponse resp )
throws IOException
{
- final int minLevel = WebConsoleUtil.getParameterInt( req, "minLevel",
LogService.LOG_DEBUG ); //$NON-NLS-1$
+ final int minLevel = WebConsoleUtil.getParameterInt( req, "minLevel",
LogService.LOG_DEBUG); //$NON-NLS-1$
resp.setContentType( "application/json" ); //$NON-NLS-1$
resp.setCharacterEncoding( "utf-8" ); //$NON-NLS-1$
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ResourceBundleManager.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ResourceBundleManager.java
index 03c9e706f6..391a46b548 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ResourceBundleManager.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ResourceBundleManager.java
@@ -19,10 +19,10 @@
package org.apache.felix.webconsole.internal.i18n;
-import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
+import java.util.concurrent.ConcurrentHashMap;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -35,26 +35,22 @@ import org.osgi.framework.BundleListener;
* It contains a local cache, for bundles, but when a bundle is being
unistalled,
* its resources stored in the cache are cleaned up.
*/
-public class ResourceBundleManager implements BundleListener
-{
+public class ResourceBundleManager implements BundleListener {
private final BundleContext bundleContext;
private final ResourceBundleCache consoleResourceBundleCache;
- private final Map resourceBundleCaches;
-
+ private final Map<Long, ResourceBundleCache> resourceBundleCaches = new
ConcurrentHashMap<>();
/**
* Creates a new object and adds self as a bundle listener
*
* @param bundleContext the bundle context of the Web Console.
*/
- public ResourceBundleManager( final BundleContext bundleContext )
- {
+ public ResourceBundleManager( final BundleContext bundleContext ) {
this.bundleContext = bundleContext;
this.consoleResourceBundleCache = new ResourceBundleCache(
bundleContext.getBundle() );
- this.resourceBundleCaches = new HashMap();
bundleContext.addBundleListener( this );
}
@@ -78,8 +74,7 @@ public class ResourceBundleManager implements BundleListener
* @return the resource bundle - if not bundle with the requested locale
exists,
* the default locale is used.
*/
- public ResourceBundle getResourceBundle( final Bundle provider, final
Locale locale )
- {
+ public ResourceBundle getResourceBundle( final Bundle provider, final
Locale locale ) {
// check whether we have to return the resource bundle for the
// Web Console itself in which case we directly return it
final ResourceBundle defaultResourceBundle =
consoleResourceBundleCache.getResourceBundle( locale );
@@ -88,17 +83,7 @@ public class ResourceBundleManager implements BundleListener
return defaultResourceBundle;
}
- ResourceBundleCache cache;
- synchronized ( resourceBundleCaches )
- {
- Long key = new Long( provider.getBundleId() );
- cache = ( ResourceBundleCache ) resourceBundleCaches.get( key );
- if ( cache == null )
- {
- cache = new ResourceBundleCache( provider );
- resourceBundleCaches.put( key, cache );
- }
- }
+ final ResourceBundleCache cache =
this.resourceBundleCaches.computeIfAbsent(provider.getBundleId(), key -> new
ResourceBundleCache(provider));
final ResourceBundle bundleResourceBundle = cache.getResourceBundle(
locale );
return new CombinedResourceBundle( bundleResourceBundle,
defaultResourceBundle, locale );
@@ -110,15 +95,9 @@ public class ResourceBundleManager implements BundleListener
/**
* @see
org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent)
*/
- public final void bundleChanged( BundleEvent event )
- {
- if ( event.getType() == BundleEvent.STOPPED )
- {
- Long key = new Long( event.getBundle().getBundleId() );
- synchronized ( resourceBundleCaches )
- {
- resourceBundleCaches.remove( key );
- }
+ public final void bundleChanged( BundleEvent event ) {
+ if ( event.getType() == BundleEvent.STOPPED ) {
+ resourceBundleCaches.remove( event.getBundle().getBundleId() );
}
}
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
index a608469616..6503cdc93d 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
@@ -109,6 +109,7 @@ public final class LicenseServlet extends
SimpleWebConsolePlugin implements Osgi
/**
* @see
org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
*/
+ @SuppressWarnings("unchecked")
protected void renderContent( HttpServletRequest request,
HttpServletResponse res ) throws IOException
{
Bundle[] bundles = getBundleContext().getBundles();
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
index 7aa869937a..d7426e9ed3 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
@@ -75,7 +75,7 @@ import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.http.context.ServletContextHelper;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
-import org.osgi.service.log.LogLevel;
+import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -178,7 +178,7 @@ public class OsgiManager extends GenericServlet {
/** The timeout for VMStat plugin page reload */
public static final String PROP_RELOAD_TIMEOUT = "reload.timeout";
- public static final int DEFAULT_LOG_LEVEL = LogLevel.WARN.ordinal();
+ public static final int DEFAULT_LOG_LEVEL = LogService.LOG_WARNING;
static final String DEFAULT_PAGE = BundlesServlet.NAME;
@@ -330,12 +330,12 @@ public class OsgiManager extends GenericServlet {
// message is just a class name, try to be more descriptive
message = "Class " + message + " missing";
}
- log(LogLevel.INFO.ordinal(), pluginClassName + " not enabled.
Reason: "
+ log(LogService.LOG_INFO, pluginClassName + " not enabled.
Reason: "
+ message);
}
catch (Throwable t)
{
- log(LogLevel.INFO.ordinal(), "Failed to instantiate plugin "
+ log(LogService.LOG_INFO, "Failed to instantiate plugin "
+ pluginClassName + ". Reason: " + t);
}
}
@@ -427,7 +427,7 @@ public class OsgiManager extends GenericServlet {
// register servlet context helper, servlet, resources
this.registerHttpWhiteboardServices();
} else {
- log(LogLevel.INFO.ordinal(), "Not all requirements met for the Web
Console. Required security providers: "
+ log(LogService.LOG_INFO, "Not all requirements met for the Web
Console. Required security providers: "
+ this.registeredSecurityProviders + " Registered security
providers: " + this.registeredSecurityProviders);
// Not all requirements met, unregister services
this.unregisterHttpWhiteboardServices();
@@ -776,8 +776,6 @@ public class OsgiManager extends GenericServlet {
}
}
- // TODO: check UserAdmin ?
-
if (locale == null)
locale = configuredLocale;
if (locale == null)
@@ -995,7 +993,7 @@ public class OsgiManager extends GenericServlet {
this.servletRegistration =
getBundleContext().registerService(Servlet.class, this, props);
}
} catch (final Exception e) {
- log(LogLevel.ERROR.ordinal(), "registerHttpWhiteboardServices:
Problem setting up", e);
+ log(LogService.LOG_ERROR, "registerHttpWhiteboardServices: Problem
setting up", e);
this.unregisterHttpWhiteboardServices();
}
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java
index 5ad14c3144..9ea34a5adf 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java
@@ -35,7 +35,7 @@ import
org.apache.felix.webconsole.internal.WebConsolePluginAdapter;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogLevel;
+import org.osgi.service.log.LogService;
public abstract class Plugin implements ServletConfig, Comparable<Plugin> {
@@ -279,7 +279,7 @@ public abstract class Plugin implements ServletConfig,
Comparable<Plugin> {
protected AbstractWebConsolePlugin doGetConsolePlugin() {
if (!isEnabled()) {
if (doLog) {
- osgiManager.log( LogLevel.INFO.ordinal(), "Ignoring plugin
" + pluginClassName + ": Disabled by configuration" );
+ osgiManager.log( LogService.LOG_INFO, "Ignoring plugin " +
pluginClassName + ": Disabled by configuration" );
doLog = false;
}
return null;
@@ -299,7 +299,7 @@ public abstract class Plugin implements ServletConfig,
Comparable<Plugin> {
} catch (final Throwable t) {
plugin = null; // in case only activate has faled!
if (doLog) {
- osgiManager.log( LogLevel.WARN.ordinal(), "Failed to
instantiate plugin " + pluginClassName, t );
+ osgiManager.log( LogService.LOG_WARNING, "Failed to
instantiate plugin " + pluginClassName, t );
doLog = false;
}
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
index 17d305bd6d..198dbc02ce 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
@@ -40,7 +40,7 @@ import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogLevel;
+import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -362,14 +362,14 @@ class PluginHolder implements
ServiceTrackerCustomizer<Servlet, Plugin> {
if (!first.init()) {
list.remove(plugin);
} else if (oldPlugin != null) {
- osgiManager.log(LogLevel.WARN.ordinal(), "Overwriting
existing plugin " + oldPlugin.getId()
+ osgiManager.log(LogService.LOG_WARNING, "Overwriting
existing plugin " + oldPlugin.getId()
+ " having label " + plugin.getLabel() + " with
new plugin " + plugin.getId()
+ " due to higher ranking " );
oldPlugin.dispose();
}
}
if (first == oldPlugin) {
- osgiManager.log(LogLevel.WARN.ordinal(), "Ignoring new plugin
" + plugin.getId()
+ osgiManager.log(LogService.LOG_WARNING, "Ignoring new plugin "
+ plugin.getId()
+ " having existing label " + plugin.getLabel() + "
due to lower ranking than old plugin " + oldPlugin.getId() );
}
}