From 05e2527b5c781db8c7179a134ac1bf800e830580 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 1 Mar 2018 17:31:39 +1100 Subject: [PATCH] Issue #2262 Sanitize osgi code Signed-off-by: Jan Bartel --- .../annotations/AnnotationConfiguration.java | 4 +-- .../osgi/annotations/AnnotationParser.java | 11 +++---- .../jetty/osgi/boot/BundleWebAppProvider.java | 5 ++-- .../osgi/boot/JettyBootstrapActivator.java | 2 +- .../osgi/boot/OSGiWebInfConfiguration.java | 22 ++++++++------ .../osgi/boot/ServiceContextProvider.java | 7 ++--- .../osgi/boot/ServiceWebAppProvider.java | 9 +++--- .../DefaultJettyAtJettyHomeHelper.java | 11 ++++--- .../JettyServerServiceTracker.java | 7 +++-- .../serverfactory/ServerInstanceWrapper.java | 30 +++++++++---------- .../webapp/LibExtClassLoaderHelper.java | 8 ++--- .../webapp/OSGiWebappClassLoader.java | 4 +-- .../boot/utils/BundleFileLocatorHelper.java | 1 - .../jetty/osgi/boot/utils/EventSender.java | 3 +- .../osgi/boot/utils/OSGiClassLoader.java | 2 +- .../eclipse/jetty/osgi/boot/utils/Util.java | 6 ++-- .../DefaultBundleClassLoaderHelper.java | 13 ++++---- .../internal/DefaultFileLocatorHelper.java | 13 ++++---- .../internal/PackageAdminServiceTracker.java | 4 +-- .../TestJettyOSGiBootContextAsService.java | 2 +- 20 files changed, 83 insertions(+), 81 deletions(-) diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java index e2eaaaa2c6b..b9bb4cf4a7b 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java @@ -25,7 +25,6 @@ import java.util.Set; import javax.servlet.ServletContainerInitializer; - import org.eclipse.jetty.annotations.AnnotationParser.Handler; import org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration; import org.eclipse.jetty.osgi.boot.OSGiWebappConstants; @@ -116,6 +115,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot _webInfLibStats = new CounterStatistic(); Bundle webbundle = (Bundle) context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE); + @SuppressWarnings("unchecked") Set fragAndRequiredBundles = (Set)context.getAttribute(OSGiWebInfConfiguration.FRAGMENT_AND_REQUIRED_BUNDLES); if (fragAndRequiredBundles != null) { @@ -229,7 +229,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot { Resource bundleRes = parser.getResource(bundle); - Set handlers = new HashSet(); + Set handlers = new HashSet<>(); handlers.addAll(_discoverableAnnotationHandlers); if (_classInheritanceHandler != null) handlers.add(_classInheritanceHandler); diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java index e52dd8e26e5..27a030641d5 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java @@ -42,10 +42,10 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa { private Set _alreadyParsed = ConcurrentHashMap.newKeySet(); - private ConcurrentHashMap _uriToBundle = new ConcurrentHashMap(); - private ConcurrentHashMap _bundleToResource = new ConcurrentHashMap(); - private ConcurrentHashMap _resourceToBundle = new ConcurrentHashMap(); - private ConcurrentHashMap _bundleToUri = new ConcurrentHashMap(); + private ConcurrentHashMap _uriToBundle = new ConcurrentHashMap<>(); + private ConcurrentHashMap _bundleToResource = new ConcurrentHashMap<>(); + private ConcurrentHashMap _resourceToBundle = new ConcurrentHashMap<>(); + private ConcurrentHashMap _bundleToUri = new ConcurrentHashMap<>(); public AnnotationParser(int javaPlatform) { @@ -126,7 +126,7 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa bundleClasspath = "."; } //order the paths first by the number of tokens in the path second alphabetically. - TreeSet paths = new TreeSet( + TreeSet paths = new TreeSet<>( new Comparator() { public int compare(String o1, String o2) @@ -176,6 +176,7 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa paths.add("/target/classes/"); } } + @SuppressWarnings("rawtypes") Enumeration classes = bundle.findEntries("/","*.class",true); if (classes == null) { diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleWebAppProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleWebAppProvider.java index 2f7af241c0d..62eb0fcd282 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleWebAppProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleWebAppProvider.java @@ -48,7 +48,7 @@ public class BundleWebAppProvider extends AbstractWebAppProvider implements Bund /** * Map of Bundle to App. Used when a Bundle contains a webapp. */ - private Map _bundleMap = new HashMap(); + private Map _bundleMap = new HashMap<>(); private ServiceRegistration _serviceRegForBundles; @@ -124,7 +124,7 @@ public class BundleWebAppProvider extends AbstractWebAppProvider implements Bund _webappTracker = new WebAppTracker(FrameworkUtil.getBundle(this.getClass()).getBundleContext(), getServerInstanceWrapper().getManagedServerName()); _webappTracker.open(); //register as an osgi service for deploying bundles, advertising the name of the jetty Server instance we are related to - Dictionary properties = new Hashtable(); + Dictionary properties = new Hashtable<>(); properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName()); _serviceRegForBundles = FrameworkUtil.getBundle(this.getClass()).getBundleContext().registerService(BundleProvider.class.getName(), this, properties); super.doStart(); @@ -175,6 +175,7 @@ public class BundleWebAppProvider extends AbstractWebAppProvider implements Bund String contextPath = null; try { + @SuppressWarnings("unchecked") Dictionary headers = bundle.getHeaders(); //does the bundle have a OSGiWebappConstants.JETTY_WAR_FOLDER_PATH diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/JettyBootstrapActivator.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/JettyBootstrapActivator.java index 5c4acbcc6ad..3adb4f2ea56 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/JettyBootstrapActivator.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/JettyBootstrapActivator.java @@ -79,7 +79,7 @@ public class JettyBootstrapActivator implements BundleActivator _jettyServerServiceTracker.open(); // Create a default jetty instance right now. - Server defaultServer = DefaultJettyAtJettyHomeHelper.startJettyAtJettyHome(context); + DefaultJettyAtJettyHomeHelper.startJettyAtJettyHome(context); } diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java index 9a1cc855545..44301b47f5b 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java @@ -95,7 +95,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration // 2. DeployerManager.setContextAttribute CONTAINER_BUNDLE_PATTERN String tmp = (String)context.getAttribute(CONTAINER_BUNDLE_PATTERN); Pattern pattern = (tmp==null?null:Pattern.compile(tmp)); - List names = new ArrayList(); + List names = new ArrayList<>(); tmp = System.getProperty(SYS_PROP_TLD_BUNDLES); if (tmp != null) { @@ -103,7 +103,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration while (tokenizer.hasMoreTokens()) names.add(tokenizer.nextToken()); } - HashSet matchingResources = new HashSet(); + HashSet matchingResources = new HashSet<>(); if ( !names.isEmpty() || pattern != null) { Bundle[] bundles = FrameworkUtil.getBundle(OSGiWebInfConfiguration.class).getBundleContext().getBundles(); @@ -153,7 +153,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration protected List findJars (WebAppContext context) throws Exception { - List mergedResources = new ArrayList(); + List mergedResources = new ArrayList<>(); //get jars from WEB-INF/lib if there are any List webInfJars = super.findJars(context); if (webInfJars != null) @@ -163,17 +163,19 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration Bundle[] bundles = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles((Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE)); if (bundles != null && bundles.length > 0) { + @SuppressWarnings("unchecked") Set fragsAndReqsBundles = (Set)context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES); if (fragsAndReqsBundles == null) { - fragsAndReqsBundles = new HashSet(); + fragsAndReqsBundles = new HashSet<>(); context.setAttribute(FRAGMENT_AND_REQUIRED_BUNDLES, fragsAndReqsBundles); } + @SuppressWarnings("unchecked") Set fragsAndReqsResources = (Set)context.getAttribute(FRAGMENT_AND_REQUIRED_RESOURCES); if (fragsAndReqsResources == null) { - fragsAndReqsResources = new HashSet(); + fragsAndReqsResources = new HashSet<>(); context.setAttribute(FRAGMENT_AND_REQUIRED_RESOURCES, fragsAndReqsResources); } @@ -207,12 +209,13 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration @Override public void configure(WebAppContext context) throws Exception { - TreeMap prependedResourcesPath = new TreeMap(); - TreeMap appendedResourcesPath = new TreeMap(); + TreeMap prependedResourcesPath = new TreeMap<>(); + TreeMap appendedResourcesPath = new TreeMap<>(); Bundle bundle = (Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE); if (bundle != null) { + @SuppressWarnings("unchecked") Set fragments = (Set)context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES); if (fragments != null && !fragments.isEmpty()) { @@ -238,8 +241,9 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration } if (!appendedResourcesPath.isEmpty()) { - LinkedHashSet resources = new LinkedHashSet(); + LinkedHashSet resources = new LinkedHashSet<>(); //Add in any existing setting of extra resource dirs + @SuppressWarnings("unchecked") Set resourceDirs = (Set)context.getAttribute(WebInfConfiguration.RESOURCE_DIRS); if (resourceDirs != null && !resourceDirs.isEmpty()) resources.addAll(resourceDirs); @@ -272,7 +276,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration private List getBundleAsResource(Bundle bundle) throws Exception { - List resources = new ArrayList(); + List resources = new ArrayList<>(); File file = BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(bundle); if (file.isDirectory()) diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceContextProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceContextProvider.java index ab8d060fd04..ff04d3c45c9 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceContextProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceContextProvider.java @@ -29,7 +29,6 @@ import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper; import org.eclipse.jetty.osgi.boot.utils.Util; import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.osgi.framework.Bundle; @@ -52,7 +51,7 @@ public class ServiceContextProvider extends AbstractContextProvider implements S { private static final Logger LOG = Log.getLogger(AbstractContextProvider.class); - private Map _serviceMap = new HashMap(); + private Map _serviceMap = new HashMap<>(); private ServiceRegistration _serviceRegForServices; @@ -168,7 +167,7 @@ public class ServiceContextProvider extends AbstractContextProvider implements S contextFile = (String)serviceRef.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH); String[] keys = serviceRef.getPropertyKeys(); - Dictionary properties = new Hashtable(); + Dictionary properties = new Hashtable<>(); if (keys != null) { for (String key:keys) @@ -226,7 +225,7 @@ public class ServiceContextProvider extends AbstractContextProvider implements S //register as an osgi service for deploying contexts defined in a bundle, advertising the name of the jetty Server instance we are related to - Dictionary properties = new Hashtable(); + Dictionary properties = new Hashtable<>(); properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName()); //register as an osgi service for deploying contexts, advertising the name of the jetty Server instance we are related to diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceWebAppProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceWebAppProvider.java index 6a6d6d0a4cf..f90646b3392 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceWebAppProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceWebAppProvider.java @@ -29,7 +29,6 @@ import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper; import org.eclipse.jetty.osgi.boot.utils.Util; import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.WebAppContext; @@ -53,7 +52,7 @@ public class ServiceWebAppProvider extends AbstractWebAppProvider implements Ser /** * Map of ServiceRef to App. Used when it is an osgi service that is a WebAppContext. */ - private Map _serviceMap = new HashMap(); + private Map _serviceMap = new HashMap<>(); private ServiceRegistration _serviceRegForServices; @@ -117,7 +116,7 @@ public class ServiceWebAppProvider extends AbstractWebAppProvider implements Ser public class ServiceApp extends OSGiApp { - public ServiceApp(DeploymentManager manager, AppProvider provider, Bundle bundle, Dictionary properties, String originId) + public ServiceApp(DeploymentManager manager, AppProvider provider, Bundle bundle, Dictionary properties, String originId) { super(manager, provider, bundle, properties, originId); } @@ -167,7 +166,7 @@ public class ServiceWebAppProvider extends AbstractWebAppProvider implements Ser WebAppContext webApp = (WebAppContext)context; - Dictionary properties = new Hashtable(); + Dictionary properties = new Hashtable<>(); String contextPath = (String)serviceRef.getProperty(OSGiWebappConstants.RFC66_WEB_CONTEXTPATH); if (contextPath == null) @@ -272,7 +271,7 @@ public class ServiceWebAppProvider extends AbstractWebAppProvider implements Ser webappTracker.open(); //register as an osgi service for deploying bundles, advertising the name of the jetty Server instance we are related to - Dictionary properties = new Hashtable(); + Dictionary properties = new Hashtable<>(); properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName()); //register as an osgi service for deploying contexts (discovered as osgi services), advertising the name of the jetty Server instance we are related to diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java index 5372618a8ff..2988ccbb146 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java @@ -102,7 +102,7 @@ public class DefaultJettyAtJettyHomeHelper File jettyHomeDir = null; Bundle jettyHomeBundle = null; - Dictionary properties = new Hashtable(); + Dictionary properties = new Hashtable<>(); if (jettyHomeSysProp != null) { jettyHomeSysProp = Util.resolvePropertyValue(jettyHomeSysProp); @@ -157,8 +157,8 @@ public class DefaultJettyAtJettyHomeHelper List configURLs = jettyHomeDir != null ? getJettyConfigurationURLs(jettyHomeDir) : getJettyConfigurationURLs(jettyHomeBundle, properties); LOG.info("Configuring the default jetty server with {}",configURLs); - String home=properties.get(OSGiServerConstants.JETTY_HOME); - String base=properties.get(OSGiServerConstants.JETTY_BASE); + String home=(String)properties.get(OSGiServerConstants.JETTY_HOME); + String base=(String)properties.get(OSGiServerConstants.JETTY_BASE); if (base==null) base=home; LOG.info("JETTY.HOME="+home); @@ -178,7 +178,6 @@ public class DefaultJettyAtJettyHomeHelper Util.setProperty(properties, OSGiServerConstants.JETTY_BASE, base); Server server = ServerInstanceWrapper.configure(null, configURLs, properties); - //Register the default Server instance as an OSGi service. //The JettyServerServiceTracker will notice it and set it up to deploy bundles as wars etc bundleContext.registerService(Server.class.getName(), server, properties); @@ -213,7 +212,7 @@ public class DefaultJettyAtJettyHomeHelper private static List getJettyConfigurationURLs(File jettyhome) throws MalformedURLException { - List configURLs = new ArrayList(); + List configURLs = new ArrayList<>(); String jettyetc = System.getProperty(JETTY_ETC_FILES, DEFAULT_JETTY_ETC_FILES); StringTokenizer tokenizer = new StringTokenizer(jettyetc, ";,", false); while (tokenizer.hasMoreTokens()) @@ -241,7 +240,7 @@ public class DefaultJettyAtJettyHomeHelper private static List getJettyConfigurationURLs(Bundle configurationBundle, Dictionary properties) throws Exception { - List configURLs = new ArrayList(); + List configURLs = new ArrayList<>(); String files = System.getProperty(JETTY_ETC_FILES, DEFAULT_JETTY_ETC_FILES); StringTokenizer tokenizer = new StringTokenizer(files, ";,", false); diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServerServiceTracker.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServerServiceTracker.java index 09607a16c16..5656c10baf6 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServerServiceTracker.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServerServiceTracker.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.osgi.boot.internal.serverfactory; +import java.util.Dictionary; +import java.util.Hashtable; import java.util.Properties; import org.eclipse.jetty.osgi.boot.OSGiServerConstants; @@ -52,11 +54,10 @@ public class JettyServerServiceTracker implements ServiceTrackerCustomizer if (name == null) { throw new IllegalArgumentException("The property " + OSGiServerConstants.MANAGED_JETTY_SERVER_NAME + " is mandatory"); } if (LOG.isDebugEnabled()) LOG.debug("Adding Server {}", name); ServerInstanceWrapper wrapper = new ServerInstanceWrapper(name); - Properties props = new Properties(); + Dictionary props = new Hashtable<>(); for (String key : sr.getPropertyKeys()) { - Object value = sr.getProperty(key); - props.put(key, value); + props.put(key, sr.getProperty(key)); } try { diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java index cfe10098ff4..65246c5cc12 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java @@ -72,7 +72,7 @@ public class ServerInstanceWrapper public static final String PROPERTY_THIS_JETTY_XML_FOLDER_URL = "this.jetty.xml.parent.folder.url"; - private static Collection __containerTldBundleDiscoverers = new ArrayList(); + private static Collection __containerTldBundleDiscoverers = new ArrayList<>(); private static Logger LOG = Log.getLogger(ServerInstanceWrapper.class.getName()); @@ -114,12 +114,12 @@ public class ServerInstanceWrapper /* ------------------------------------------------------------ */ - public static Server configure(Server server, List jettyConfigurations, Dictionary props) throws Exception + public static Server configure(Server server, List jettyConfigurations, Dictionary props) throws Exception { if (jettyConfigurations == null || jettyConfigurations.isEmpty()) { return server; } - Map id_map = new HashMap(); + Map id_map = new HashMap<>(); if (server != null) { //Put in a mapping for the id "Server" and the name of the server as the instance being configured @@ -127,18 +127,16 @@ public class ServerInstanceWrapper id_map.put((String)props.get(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME), server); } - Map properties = new HashMap(); + Map properties = new HashMap<>(); if (props != null) { - Enumeration en = props.keys(); + Enumeration en = props.keys(); while (en.hasMoreElements()) { - Object key = en.nextElement(); + String key = en.nextElement(); Object value = props.get(key); - String keyStr = String.valueOf(key); - String valStr = String.valueOf(value); - properties.put(keyStr, valStr); - if (server != null) server.setAttribute(keyStr, valStr); + properties.put(key, value.toString()); + if (server != null) server.setAttribute(key, value); } } @@ -153,7 +151,7 @@ public class ServerInstanceWrapper throw new IllegalStateException("No such jetty server config file: "+r); } - XmlConfiguration config = new XmlConfiguration(r.getURL()); + XmlConfiguration config = new XmlConfiguration(r.getURI().toURL()); config.getIdMap().putAll(id_map); config.getProperties().putAll(properties); @@ -243,7 +241,7 @@ public class ServerInstanceWrapper } /* ------------------------------------------------------------ */ - public void start(Server server, Dictionary props) throws Exception + public void start(Server server, Dictionary props) throws Exception { _server = server; ClassLoader contextCl = Thread.currentThread().getContextClassLoader(); @@ -274,7 +272,7 @@ public class ServerInstanceWrapper //as on the webapp classpath. if (!__containerTldBundleDiscoverers.isEmpty()) { - Set urls = new HashSet(); + Set urls = new HashSet<>(); //discover bundles with tlds that need to be on the container's classpath as URLs for (TldBundleDiscoverer d:__containerTldBundleDiscoverers) { @@ -350,7 +348,7 @@ public class ServerInstanceWrapper if (_ctxtCollection == null) throw new IllegalStateException("ERROR: No ContextHandlerCollection configured in Server"); - List providerClassNames = new ArrayList(); + List providerClassNames = new ArrayList<>(); // get a deployerManager and some providers Collection deployers = _server.getBeans(DeploymentManager.class); @@ -372,7 +370,7 @@ public class ServerInstanceWrapper } _deploymentManager.setUseStandardBindings(false); - List deploymentLifeCycleBindings = new ArrayList(); + List deploymentLifeCycleBindings = new ArrayList<>(); deploymentLifeCycleBindings.add(new OSGiDeployer(this)); deploymentLifeCycleBindings.add(new StandardStarter()); deploymentLifeCycleBindings.add(new StandardStopper()); @@ -446,7 +444,7 @@ public class ServerInstanceWrapper private List extractFiles(String propertyValue) { StringTokenizer tokenizer = new StringTokenizer(propertyValue, ",;", false); - List files = new ArrayList(); + List files = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { String tok = tokenizer.nextToken(); diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java index 4a90a0ebcbc..95123b51f50 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java @@ -68,7 +68,7 @@ public class LibExtClassLoaderHelper - public static final Set registeredFilesInJettyHomeResourcesProcessors = new HashSet(); + public static final Set registeredFilesInJettyHomeResourcesProcessors = new HashSet<>(); /* ------------------------------------------------------------ */ @@ -83,12 +83,12 @@ public class LibExtClassLoaderHelper public static ClassLoader createLibEtcClassLoader(File jettyHome, ClassLoader parentClassLoader) throws MalformedURLException { if (jettyHome == null) { return parentClassLoader; } - ArrayList urls = new ArrayList(); + ArrayList urls = new ArrayList<>(); File jettyResources = new File(jettyHome, "resources"); if (jettyResources.exists()) { // make sure it contains something else than README: - Map jettyResFiles = new HashMap(); + Map jettyResFiles = new HashMap<>(); for (File f : jettyResources.listFiles()) { jettyResFiles.put(f.getName(), f); @@ -143,7 +143,7 @@ public class LibExtClassLoaderHelper throws MalformedURLException { if (jarsContainerOrJars == null && otherJarsOrFolder == null) { return parentClassLoader; } - List urls = new ArrayList(); + List urls = new ArrayList<>(); if (otherJarsOrFolder != null) { urls.addAll(otherJarsOrFolder); diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java index 517bb109685..e69d3016779 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java @@ -57,7 +57,7 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe * when a logging framework is setup in the osgi classloaders, it can access * this and register the classes that must not be found in the jar. */ - public static final Set JAR_WITH_SUCH_CLASS_MUST_BE_EXCLUDED = new HashSet(); + public static final Set JAR_WITH_SUCH_CLASS_MUST_BE_EXCLUDED = new HashSet<>(); public static void addClassThatIdentifiesAJarThatMustBeRejected(Class zclass) { @@ -149,7 +149,7 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe /* ------------------------------------------------------------ */ private List toList(Enumeration e, Enumeration e2) { - List list = new ArrayList(); + List list = new ArrayList<>(); while (e != null && e.hasMoreElements()) list.add(e.nextElement()); while (e2 != null && e2.hasMoreElements()) diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/BundleFileLocatorHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/BundleFileLocatorHelper.java index 0e2aab02a4a..0d6cfbc51ab 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/BundleFileLocatorHelper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/BundleFileLocatorHelper.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.osgi.boot.utils; import java.io.File; -import java.io.IOException; import java.net.URL; import java.util.Enumeration; diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/EventSender.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/EventSender.java index 833ac1f9cf0..cd8f2bb3f1c 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/EventSender.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/EventSender.java @@ -23,7 +23,6 @@ import java.util.Hashtable; import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; import org.osgi.service.event.Event; import org.osgi.service.event.EventAdmin; import org.osgi.util.tracker.ServiceTracker; @@ -68,7 +67,7 @@ public class EventSender { EventAdmin service = (EventAdmin)_serviceTracker.getService(); if (service != null) { - Dictionary props = new Hashtable(); + Dictionary props = new Hashtable<>(); props.put("bundle.symbolicName", wab.getSymbolicName()); props.put("bundle.id", wab.getBundleId()); props.put("bundle", wab); diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/OSGiClassLoader.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/OSGiClassLoader.java index 53353aff2e7..0567218f745 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/OSGiClassLoader.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/OSGiClassLoader.java @@ -165,7 +165,7 @@ public class OSGiClassLoader extends URLClassLoader */ private List toList(Enumeration e, Enumeration e2) { - List list = new ArrayList(); + List list = new ArrayList<>(); while (e != null && e.hasMoreElements()) list.add(e.nextElement()); while (e2 != null && e2.hasMoreElements()) diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/Util.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/Util.java index 770974d3a64..c28846ab975 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/Util.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/Util.java @@ -72,7 +72,7 @@ public class Util * @param manifest the dictionary * @return the value from the manifest */ - public static String getManifestHeaderValue (String name, String altName, Dictionary manifest) + public static String getManifestHeaderValue (String name, String altName, Dictionary manifest) { if (manifest == null) return null; @@ -103,7 +103,7 @@ public class Util delims = separators; StringTokenizer tokenizer = new StringTokenizer(val, delims, false); - List urls = new ArrayList(); + List urls = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { urls.add(BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(new URL(tokenizer.nextToken()))); @@ -113,7 +113,7 @@ public class Util /* ------------------------------------------------------------ */ - public static void setProperty(Dictionary properties, String key, String value) + public static void setProperty(Dictionary properties, String key, Object value) { if (value != null) { diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultBundleClassLoaderHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultBundleClassLoaderHelper.java index afaa2a97b84..6166ce3543a 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultBundleClassLoaderHelper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultBundleClassLoaderHelper.java @@ -38,10 +38,10 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper private static final Logger LOG = Log.getLogger(BundleClassLoaderHelper.class); private static enum OSGiContainerType {EquinoxOld, EquinoxLuna, FelixOld, Felix403, Concierge}; private static OSGiContainerType osgiContainer; - private static Class Equinox_BundleHost_Class; - private static Class Equinox_EquinoxBundle_Class; - private static Class Felix_BundleImpl_Class; - private static Class Felix_BundleWiring_Class; + private static Class Equinox_BundleHost_Class; + private static Class Equinox_EquinoxBundle_Class; + private static Class Felix_BundleImpl_Class; + private static Class Felix_BundleWiring_Class; //old equinox private static Method Equinox_BundleHost_getBundleLoader_method; private static Method Equinox_BundleLoader_createClassLoader_method; @@ -56,8 +56,8 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper private static Method Felix_BundleWiring_getClassLoader_Method; // Concierge - private static Class Concierge_BundleImpl_Class; - private static Class Concierge_BundleWiring_Class; + private static Class Concierge_BundleImpl_Class; + private static Class Concierge_BundleWiring_Class; private static Method Concierge_BundleImpl_Adapt_Method; private static Method Concierge_BundleWiring_getClassLoader_Method; @@ -267,6 +267,7 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper * @param bundle * @return */ + @SuppressWarnings("unchecked") private static ClassLoader internalGetFelixBundleClassLoader(Bundle bundle) { diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultFileLocatorHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultFileLocatorHelper.java index c44725b220d..441fb002e3d 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultFileLocatorHelper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultFileLocatorHelper.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.osgi.boot.utils.internal; import java.io.File; -import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URI; @@ -88,6 +87,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper * @return Its installation location as a file. * @throws Exception if unable to get the bundle install location */ + @SuppressWarnings("resource") public File getBundleInstallLocation(Bundle bundle) throws Exception { // String installedBundles = System.getProperty("osgi.bundles"); @@ -249,6 +249,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper path = "/" + path; } String pattern = last != -1 && last < entryPath.length() - 2 ? entryPath.substring(last + 1) : entryPath; + @SuppressWarnings("unchecked") Enumeration enUrls = bundle.findEntries(path, pattern, false); return enUrls; } @@ -273,7 +274,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper if (jasperLocation.isDirectory()) { // try to find the jar files inside this folder - ArrayList urls = new ArrayList(); + ArrayList urls = new ArrayList<>(); for (File f : jasperLocation.listFiles()) { if (f.getName().endsWith(".jar") && f.isFile()) @@ -327,10 +328,10 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper conn.setDefaultUseCaches(Resource.getDefaultUseCaches()); if (BUNDLE_URL_CONNECTION_getLocalURL == null && match(conn.getClass().getName(), BUNDLE_URL_CONNECTION_CLASSES)) { - BUNDLE_URL_CONNECTION_getLocalURL = conn.getClass().getMethod("getLocalURL", null); + BUNDLE_URL_CONNECTION_getLocalURL = conn.getClass().getMethod("getLocalURL"); BUNDLE_URL_CONNECTION_getLocalURL.setAccessible(true); } - if (BUNDLE_URL_CONNECTION_getLocalURL != null) { return (URL) BUNDLE_URL_CONNECTION_getLocalURL.invoke(conn, null); } + if (BUNDLE_URL_CONNECTION_getLocalURL != null) { return (URL) BUNDLE_URL_CONNECTION_getLocalURL.invoke(conn); } } return url; } @@ -360,10 +361,10 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper && match (conn.getClass().getName(), BUNDLE_URL_CONNECTION_CLASSES)) { - BUNDLE_URL_CONNECTION_getFileURL = conn.getClass().getMethod("getFileURL", null); + BUNDLE_URL_CONNECTION_getFileURL = conn.getClass().getMethod("getFileURL"); BUNDLE_URL_CONNECTION_getFileURL.setAccessible(true); } - if (BUNDLE_URL_CONNECTION_getFileURL != null) { return (URL) BUNDLE_URL_CONNECTION_getFileURL.invoke(conn, null); } + if (BUNDLE_URL_CONNECTION_getFileURL != null) { return (URL) BUNDLE_URL_CONNECTION_getFileURL.invoke(conn); } } return url; diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/PackageAdminServiceTracker.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/PackageAdminServiceTracker.java index 47cba90371f..bf9a346806e 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/PackageAdminServiceTracker.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/PackageAdminServiceTracker.java @@ -47,7 +47,7 @@ public class PackageAdminServiceTracker implements ServiceListener { private BundleContext _context; - private List _activatedFragments = new ArrayList(); + private List _activatedFragments = new ArrayList<>(); private boolean _fragmentsWereActivated = false; @@ -153,7 +153,7 @@ public class PackageAdminServiceTracker implements ServiceListener return null; } PackageAdmin admin = (PackageAdmin) _context.getService(sr); - LinkedHashMap deps = new LinkedHashMap(); + LinkedHashMap deps = new LinkedHashMap<>(); collectFragmentsAndRequiredBundles(bundle, admin, deps, false); return deps.values().toArray(new Bundle[deps.size()]); } diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootContextAsService.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootContextAsService.java index 99bbce570f0..c6003278949 100644 --- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootContextAsService.java +++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootContextAsService.java @@ -80,8 +80,8 @@ public class TestJettyOSGiBootContextAsService + @Ignore - @Test public void assertAllBundlesActiveOrResolved() { TestOSGiUtil.assertAllBundlesActiveOrResolved(bundleContext);