Issue #2262 Sanitize osgi code

Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
Jan Bartel 2018-03-01 17:31:39 +11:00
parent 1173be318c
commit 05e2527b5c
20 changed files with 83 additions and 81 deletions

View File

@ -25,7 +25,6 @@ import java.util.Set;
import javax.servlet.ServletContainerInitializer; import javax.servlet.ServletContainerInitializer;
import org.eclipse.jetty.annotations.AnnotationParser.Handler; import org.eclipse.jetty.annotations.AnnotationParser.Handler;
import org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration; import org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration;
import org.eclipse.jetty.osgi.boot.OSGiWebappConstants; import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
@ -116,6 +115,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
_webInfLibStats = new CounterStatistic(); _webInfLibStats = new CounterStatistic();
Bundle webbundle = (Bundle) context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE); Bundle webbundle = (Bundle) context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
@SuppressWarnings("unchecked")
Set<Bundle> fragAndRequiredBundles = (Set<Bundle>)context.getAttribute(OSGiWebInfConfiguration.FRAGMENT_AND_REQUIRED_BUNDLES); Set<Bundle> fragAndRequiredBundles = (Set<Bundle>)context.getAttribute(OSGiWebInfConfiguration.FRAGMENT_AND_REQUIRED_BUNDLES);
if (fragAndRequiredBundles != null) if (fragAndRequiredBundles != null)
{ {
@ -229,7 +229,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
{ {
Resource bundleRes = parser.getResource(bundle); Resource bundleRes = parser.getResource(bundle);
Set<Handler> handlers = new HashSet<Handler>(); Set<Handler> handlers = new HashSet<>();
handlers.addAll(_discoverableAnnotationHandlers); handlers.addAll(_discoverableAnnotationHandlers);
if (_classInheritanceHandler != null) if (_classInheritanceHandler != null)
handlers.add(_classInheritanceHandler); handlers.add(_classInheritanceHandler);

View File

@ -42,10 +42,10 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa
{ {
private Set<URI> _alreadyParsed = ConcurrentHashMap.newKeySet(); private Set<URI> _alreadyParsed = ConcurrentHashMap.newKeySet();
private ConcurrentHashMap<URI,Bundle> _uriToBundle = new ConcurrentHashMap<URI, Bundle>(); private ConcurrentHashMap<URI,Bundle> _uriToBundle = new ConcurrentHashMap<>();
private ConcurrentHashMap<Bundle,Resource> _bundleToResource = new ConcurrentHashMap<Bundle,Resource>(); private ConcurrentHashMap<Bundle,Resource> _bundleToResource = new ConcurrentHashMap<>();
private ConcurrentHashMap<Resource, Bundle> _resourceToBundle = new ConcurrentHashMap<Resource, Bundle>(); private ConcurrentHashMap<Resource, Bundle> _resourceToBundle = new ConcurrentHashMap<>();
private ConcurrentHashMap<Bundle,URI> _bundleToUri = new ConcurrentHashMap<Bundle, URI>(); private ConcurrentHashMap<Bundle,URI> _bundleToUri = new ConcurrentHashMap<>();
public AnnotationParser(int javaPlatform) public AnnotationParser(int javaPlatform)
{ {
@ -126,7 +126,7 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa
bundleClasspath = "."; bundleClasspath = ".";
} }
//order the paths first by the number of tokens in the path second alphabetically. //order the paths first by the number of tokens in the path second alphabetically.
TreeSet<String> paths = new TreeSet<String>( TreeSet<String> paths = new TreeSet<>(
new Comparator<String>() new Comparator<String>()
{ {
public int compare(String o1, String o2) public int compare(String o1, String o2)
@ -176,6 +176,7 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa
paths.add("/target/classes/"); paths.add("/target/classes/");
} }
} }
@SuppressWarnings("rawtypes")
Enumeration classes = bundle.findEntries("/","*.class",true); Enumeration classes = bundle.findEntries("/","*.class",true);
if (classes == null) if (classes == null)
{ {

View File

@ -48,7 +48,7 @@ public class BundleWebAppProvider extends AbstractWebAppProvider implements Bund
/** /**
* Map of Bundle to App. Used when a Bundle contains a webapp. * Map of Bundle to App. Used when a Bundle contains a webapp.
*/ */
private Map<Bundle, App> _bundleMap = new HashMap<Bundle, App>(); private Map<Bundle, App> _bundleMap = new HashMap<>();
private ServiceRegistration _serviceRegForBundles; 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 = new WebAppTracker(FrameworkUtil.getBundle(this.getClass()).getBundleContext(), getServerInstanceWrapper().getManagedServerName());
_webappTracker.open(); _webappTracker.open();
//register as an osgi service for deploying bundles, advertising the name of the jetty Server instance we are related to //register as an osgi service for deploying bundles, advertising the name of the jetty Server instance we are related to
Dictionary<String,String> properties = new Hashtable<String,String>(); Dictionary<String,String> properties = new Hashtable<>();
properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName()); properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName());
_serviceRegForBundles = FrameworkUtil.getBundle(this.getClass()).getBundleContext().registerService(BundleProvider.class.getName(), this, properties); _serviceRegForBundles = FrameworkUtil.getBundle(this.getClass()).getBundleContext().registerService(BundleProvider.class.getName(), this, properties);
super.doStart(); super.doStart();
@ -175,6 +175,7 @@ public class BundleWebAppProvider extends AbstractWebAppProvider implements Bund
String contextPath = null; String contextPath = null;
try try
{ {
@SuppressWarnings("unchecked")
Dictionary<String,String> headers = bundle.getHeaders(); Dictionary<String,String> headers = bundle.getHeaders();
//does the bundle have a OSGiWebappConstants.JETTY_WAR_FOLDER_PATH //does the bundle have a OSGiWebappConstants.JETTY_WAR_FOLDER_PATH

View File

@ -79,7 +79,7 @@ public class JettyBootstrapActivator implements BundleActivator
_jettyServerServiceTracker.open(); _jettyServerServiceTracker.open();
// Create a default jetty instance right now. // Create a default jetty instance right now.
Server defaultServer = DefaultJettyAtJettyHomeHelper.startJettyAtJettyHome(context); DefaultJettyAtJettyHomeHelper.startJettyAtJettyHome(context);
} }

View File

@ -95,7 +95,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
// 2. DeployerManager.setContextAttribute CONTAINER_BUNDLE_PATTERN // 2. DeployerManager.setContextAttribute CONTAINER_BUNDLE_PATTERN
String tmp = (String)context.getAttribute(CONTAINER_BUNDLE_PATTERN); String tmp = (String)context.getAttribute(CONTAINER_BUNDLE_PATTERN);
Pattern pattern = (tmp==null?null:Pattern.compile(tmp)); Pattern pattern = (tmp==null?null:Pattern.compile(tmp));
List<String> names = new ArrayList<String>(); List<String> names = new ArrayList<>();
tmp = System.getProperty(SYS_PROP_TLD_BUNDLES); tmp = System.getProperty(SYS_PROP_TLD_BUNDLES);
if (tmp != null) if (tmp != null)
{ {
@ -103,7 +103,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
while (tokenizer.hasMoreTokens()) while (tokenizer.hasMoreTokens())
names.add(tokenizer.nextToken()); names.add(tokenizer.nextToken());
} }
HashSet<Resource> matchingResources = new HashSet<Resource>(); HashSet<Resource> matchingResources = new HashSet<>();
if ( !names.isEmpty() || pattern != null) if ( !names.isEmpty() || pattern != null)
{ {
Bundle[] bundles = FrameworkUtil.getBundle(OSGiWebInfConfiguration.class).getBundleContext().getBundles(); Bundle[] bundles = FrameworkUtil.getBundle(OSGiWebInfConfiguration.class).getBundleContext().getBundles();
@ -153,7 +153,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
protected List<Resource> findJars (WebAppContext context) protected List<Resource> findJars (WebAppContext context)
throws Exception throws Exception
{ {
List<Resource> mergedResources = new ArrayList<Resource>(); List<Resource> mergedResources = new ArrayList<>();
//get jars from WEB-INF/lib if there are any //get jars from WEB-INF/lib if there are any
List<Resource> webInfJars = super.findJars(context); List<Resource> webInfJars = super.findJars(context);
if (webInfJars != null) if (webInfJars != null)
@ -163,17 +163,19 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
Bundle[] bundles = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles((Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE)); Bundle[] bundles = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles((Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE));
if (bundles != null && bundles.length > 0) if (bundles != null && bundles.length > 0)
{ {
@SuppressWarnings("unchecked")
Set<Bundle> fragsAndReqsBundles = (Set<Bundle>)context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES); Set<Bundle> fragsAndReqsBundles = (Set<Bundle>)context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES);
if (fragsAndReqsBundles == null) if (fragsAndReqsBundles == null)
{ {
fragsAndReqsBundles = new HashSet<Bundle>(); fragsAndReqsBundles = new HashSet<>();
context.setAttribute(FRAGMENT_AND_REQUIRED_BUNDLES, fragsAndReqsBundles); context.setAttribute(FRAGMENT_AND_REQUIRED_BUNDLES, fragsAndReqsBundles);
} }
@SuppressWarnings("unchecked")
Set<Resource> fragsAndReqsResources = (Set<Resource>)context.getAttribute(FRAGMENT_AND_REQUIRED_RESOURCES); Set<Resource> fragsAndReqsResources = (Set<Resource>)context.getAttribute(FRAGMENT_AND_REQUIRED_RESOURCES);
if (fragsAndReqsResources == null) if (fragsAndReqsResources == null)
{ {
fragsAndReqsResources = new HashSet<Resource>(); fragsAndReqsResources = new HashSet<>();
context.setAttribute(FRAGMENT_AND_REQUIRED_RESOURCES, fragsAndReqsResources); context.setAttribute(FRAGMENT_AND_REQUIRED_RESOURCES, fragsAndReqsResources);
} }
@ -207,12 +209,13 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
@Override @Override
public void configure(WebAppContext context) throws Exception public void configure(WebAppContext context) throws Exception
{ {
TreeMap<String, Resource> prependedResourcesPath = new TreeMap<String, Resource>(); TreeMap<String, Resource> prependedResourcesPath = new TreeMap<>();
TreeMap<String, Resource> appendedResourcesPath = new TreeMap<String, Resource>(); TreeMap<String, Resource> appendedResourcesPath = new TreeMap<>();
Bundle bundle = (Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE); Bundle bundle = (Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
if (bundle != null) if (bundle != null)
{ {
@SuppressWarnings("unchecked")
Set<Bundle> fragments = (Set<Bundle>)context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES); Set<Bundle> fragments = (Set<Bundle>)context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES);
if (fragments != null && !fragments.isEmpty()) if (fragments != null && !fragments.isEmpty())
{ {
@ -238,8 +241,9 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
} }
if (!appendedResourcesPath.isEmpty()) if (!appendedResourcesPath.isEmpty())
{ {
LinkedHashSet<Resource> resources = new LinkedHashSet<Resource>(); LinkedHashSet<Resource> resources = new LinkedHashSet<>();
//Add in any existing setting of extra resource dirs //Add in any existing setting of extra resource dirs
@SuppressWarnings("unchecked")
Set<Resource> resourceDirs = (Set<Resource>)context.getAttribute(WebInfConfiguration.RESOURCE_DIRS); Set<Resource> resourceDirs = (Set<Resource>)context.getAttribute(WebInfConfiguration.RESOURCE_DIRS);
if (resourceDirs != null && !resourceDirs.isEmpty()) if (resourceDirs != null && !resourceDirs.isEmpty())
resources.addAll(resourceDirs); resources.addAll(resourceDirs);
@ -272,7 +276,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
private List<Resource> getBundleAsResource(Bundle bundle) private List<Resource> getBundleAsResource(Bundle bundle)
throws Exception throws Exception
{ {
List<Resource> resources = new ArrayList<Resource>(); List<Resource> resources = new ArrayList<>();
File file = BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(bundle); File file = BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(bundle);
if (file.isDirectory()) if (file.isDirectory())

View File

@ -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.internal.serverfactory.ServerInstanceWrapper;
import org.eclipse.jetty.osgi.boot.utils.Util; import org.eclipse.jetty.osgi.boot.utils.Util;
import org.eclipse.jetty.server.handler.ContextHandler; 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.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.osgi.framework.Bundle; 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 static final Logger LOG = Log.getLogger(AbstractContextProvider.class);
private Map<ServiceReference, App> _serviceMap = new HashMap<ServiceReference, App>(); private Map<ServiceReference, App> _serviceMap = new HashMap<>();
private ServiceRegistration _serviceRegForServices; private ServiceRegistration _serviceRegForServices;
@ -168,7 +167,7 @@ public class ServiceContextProvider extends AbstractContextProvider implements S
contextFile = (String)serviceRef.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH); contextFile = (String)serviceRef.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH);
String[] keys = serviceRef.getPropertyKeys(); String[] keys = serviceRef.getPropertyKeys();
Dictionary properties = new Hashtable<String, Object>(); Dictionary<String,Object> properties = new Hashtable<>();
if (keys != null) if (keys != null)
{ {
for (String key:keys) 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 //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<String,String> properties = new Hashtable<String,String>(); Dictionary<String,String> properties = new Hashtable<>();
properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName()); 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 //register as an osgi service for deploying contexts, advertising the name of the jetty Server instance we are related to

View File

@ -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.internal.serverfactory.ServerInstanceWrapper;
import org.eclipse.jetty.osgi.boot.utils.Util; import org.eclipse.jetty.osgi.boot.utils.Util;
import org.eclipse.jetty.server.handler.ContextHandler; 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.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.webapp.WebAppContext; 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. * Map of ServiceRef to App. Used when it is an osgi service that is a WebAppContext.
*/ */
private Map<ServiceReference, App> _serviceMap = new HashMap<ServiceReference, App>(); private Map<ServiceReference, App> _serviceMap = new HashMap<>();
private ServiceRegistration _serviceRegForServices; private ServiceRegistration _serviceRegForServices;
@ -117,7 +116,7 @@ public class ServiceWebAppProvider extends AbstractWebAppProvider implements Ser
public class ServiceApp extends OSGiApp 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<String,String> properties, String originId)
{ {
super(manager, provider, bundle, properties, originId); super(manager, provider, bundle, properties, originId);
} }
@ -167,7 +166,7 @@ public class ServiceWebAppProvider extends AbstractWebAppProvider implements Ser
WebAppContext webApp = (WebAppContext)context; WebAppContext webApp = (WebAppContext)context;
Dictionary properties = new Hashtable<String,String>(); Dictionary<String,String> properties = new Hashtable<>();
String contextPath = (String)serviceRef.getProperty(OSGiWebappConstants.RFC66_WEB_CONTEXTPATH); String contextPath = (String)serviceRef.getProperty(OSGiWebappConstants.RFC66_WEB_CONTEXTPATH);
if (contextPath == null) if (contextPath == null)
@ -272,7 +271,7 @@ public class ServiceWebAppProvider extends AbstractWebAppProvider implements Ser
webappTracker.open(); webappTracker.open();
//register as an osgi service for deploying bundles, advertising the name of the jetty Server instance we are related to //register as an osgi service for deploying bundles, advertising the name of the jetty Server instance we are related to
Dictionary<String,String> properties = new Hashtable<String,String>(); Dictionary<String,String> properties = new Hashtable<>();
properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName()); 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 //register as an osgi service for deploying contexts (discovered as osgi services), advertising the name of the jetty Server instance we are related to

View File

@ -102,7 +102,7 @@ public class DefaultJettyAtJettyHomeHelper
File jettyHomeDir = null; File jettyHomeDir = null;
Bundle jettyHomeBundle = null; Bundle jettyHomeBundle = null;
Dictionary<String,String> properties = new Hashtable<String,String>(); Dictionary<String, Object> properties = new Hashtable<>();
if (jettyHomeSysProp != null) if (jettyHomeSysProp != null)
{ {
jettyHomeSysProp = Util.resolvePropertyValue(jettyHomeSysProp); jettyHomeSysProp = Util.resolvePropertyValue(jettyHomeSysProp);
@ -157,8 +157,8 @@ public class DefaultJettyAtJettyHomeHelper
List<URL> configURLs = jettyHomeDir != null ? getJettyConfigurationURLs(jettyHomeDir) : getJettyConfigurationURLs(jettyHomeBundle, properties); List<URL> configURLs = jettyHomeDir != null ? getJettyConfigurationURLs(jettyHomeDir) : getJettyConfigurationURLs(jettyHomeBundle, properties);
LOG.info("Configuring the default jetty server with {}",configURLs); LOG.info("Configuring the default jetty server with {}",configURLs);
String home=properties.get(OSGiServerConstants.JETTY_HOME); String home=(String)properties.get(OSGiServerConstants.JETTY_HOME);
String base=properties.get(OSGiServerConstants.JETTY_BASE); String base=(String)properties.get(OSGiServerConstants.JETTY_BASE);
if (base==null) if (base==null)
base=home; base=home;
LOG.info("JETTY.HOME="+home); LOG.info("JETTY.HOME="+home);
@ -178,7 +178,6 @@ public class DefaultJettyAtJettyHomeHelper
Util.setProperty(properties, OSGiServerConstants.JETTY_BASE, base); Util.setProperty(properties, OSGiServerConstants.JETTY_BASE, base);
Server server = ServerInstanceWrapper.configure(null, configURLs, properties); Server server = ServerInstanceWrapper.configure(null, configURLs, properties);
//Register the default Server instance as an OSGi service. //Register the default Server instance as an OSGi service.
//The JettyServerServiceTracker will notice it and set it up to deploy bundles as wars etc //The JettyServerServiceTracker will notice it and set it up to deploy bundles as wars etc
bundleContext.registerService(Server.class.getName(), server, properties); bundleContext.registerService(Server.class.getName(), server, properties);
@ -213,7 +212,7 @@ public class DefaultJettyAtJettyHomeHelper
private static List<URL> getJettyConfigurationURLs(File jettyhome) private static List<URL> getJettyConfigurationURLs(File jettyhome)
throws MalformedURLException throws MalformedURLException
{ {
List<URL> configURLs = new ArrayList<URL>(); List<URL> configURLs = new ArrayList<>();
String jettyetc = System.getProperty(JETTY_ETC_FILES, DEFAULT_JETTY_ETC_FILES); String jettyetc = System.getProperty(JETTY_ETC_FILES, DEFAULT_JETTY_ETC_FILES);
StringTokenizer tokenizer = new StringTokenizer(jettyetc, ";,", false); StringTokenizer tokenizer = new StringTokenizer(jettyetc, ";,", false);
while (tokenizer.hasMoreTokens()) while (tokenizer.hasMoreTokens())
@ -241,7 +240,7 @@ public class DefaultJettyAtJettyHomeHelper
private static List<URL> getJettyConfigurationURLs(Bundle configurationBundle, Dictionary properties) private static List<URL> getJettyConfigurationURLs(Bundle configurationBundle, Dictionary properties)
throws Exception throws Exception
{ {
List<URL> configURLs = new ArrayList<URL>(); List<URL> configURLs = new ArrayList<>();
String files = System.getProperty(JETTY_ETC_FILES, DEFAULT_JETTY_ETC_FILES); String files = System.getProperty(JETTY_ETC_FILES, DEFAULT_JETTY_ETC_FILES);
StringTokenizer tokenizer = new StringTokenizer(files, ";,", false); StringTokenizer tokenizer = new StringTokenizer(files, ";,", false);

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.osgi.boot.internal.serverfactory; package org.eclipse.jetty.osgi.boot.internal.serverfactory;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Properties; import java.util.Properties;
import org.eclipse.jetty.osgi.boot.OSGiServerConstants; 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 (name == null) { throw new IllegalArgumentException("The property " + OSGiServerConstants.MANAGED_JETTY_SERVER_NAME + " is mandatory"); }
if (LOG.isDebugEnabled()) LOG.debug("Adding Server {}", name); if (LOG.isDebugEnabled()) LOG.debug("Adding Server {}", name);
ServerInstanceWrapper wrapper = new ServerInstanceWrapper(name); ServerInstanceWrapper wrapper = new ServerInstanceWrapper(name);
Properties props = new Properties(); Dictionary<String,Object> props = new Hashtable<>();
for (String key : sr.getPropertyKeys()) for (String key : sr.getPropertyKeys())
{ {
Object value = sr.getProperty(key); props.put(key, sr.getProperty(key));
props.put(key, value);
} }
try try
{ {

View File

@ -72,7 +72,7 @@ public class ServerInstanceWrapper
public static final String PROPERTY_THIS_JETTY_XML_FOLDER_URL = "this.jetty.xml.parent.folder.url"; public static final String PROPERTY_THIS_JETTY_XML_FOLDER_URL = "this.jetty.xml.parent.folder.url";
private static Collection<TldBundleDiscoverer> __containerTldBundleDiscoverers = new ArrayList<TldBundleDiscoverer>(); private static Collection<TldBundleDiscoverer> __containerTldBundleDiscoverers = new ArrayList<>();
private static Logger LOG = Log.getLogger(ServerInstanceWrapper.class.getName()); private static Logger LOG = Log.getLogger(ServerInstanceWrapper.class.getName());
@ -114,12 +114,12 @@ public class ServerInstanceWrapper
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public static Server configure(Server server, List<URL> jettyConfigurations, Dictionary props) throws Exception public static Server configure(Server server, List<URL> jettyConfigurations, Dictionary<String, Object> props) throws Exception
{ {
if (jettyConfigurations == null || jettyConfigurations.isEmpty()) { return server; } if (jettyConfigurations == null || jettyConfigurations.isEmpty()) { return server; }
Map<String, Object> id_map = new HashMap<String, Object>(); Map<String, Object> id_map = new HashMap<>();
if (server != null) if (server != null)
{ {
//Put in a mapping for the id "Server" and the name of the server as the instance being configured //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); id_map.put((String)props.get(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME), server);
} }
Map<String, String> properties = new HashMap<String, String>(); Map<String, String> properties = new HashMap<>();
if (props != null) if (props != null)
{ {
Enumeration<Object> en = props.keys(); Enumeration<String> en = props.keys();
while (en.hasMoreElements()) while (en.hasMoreElements())
{ {
Object key = en.nextElement(); String key = en.nextElement();
Object value = props.get(key); Object value = props.get(key);
String keyStr = String.valueOf(key); properties.put(key, value.toString());
String valStr = String.valueOf(value); if (server != null) server.setAttribute(key, value);
properties.put(keyStr, valStr);
if (server != null) server.setAttribute(keyStr, valStr);
} }
} }
@ -153,7 +151,7 @@ public class ServerInstanceWrapper
throw new IllegalStateException("No such jetty server config file: "+r); 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.getIdMap().putAll(id_map);
config.getProperties().putAll(properties); 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<String,Object> props) throws Exception
{ {
_server = server; _server = server;
ClassLoader contextCl = Thread.currentThread().getContextClassLoader(); ClassLoader contextCl = Thread.currentThread().getContextClassLoader();
@ -274,7 +272,7 @@ public class ServerInstanceWrapper
//as on the webapp classpath. //as on the webapp classpath.
if (!__containerTldBundleDiscoverers.isEmpty()) if (!__containerTldBundleDiscoverers.isEmpty())
{ {
Set<URL> urls = new HashSet<URL>(); Set<URL> urls = new HashSet<>();
//discover bundles with tlds that need to be on the container's classpath as URLs //discover bundles with tlds that need to be on the container's classpath as URLs
for (TldBundleDiscoverer d:__containerTldBundleDiscoverers) for (TldBundleDiscoverer d:__containerTldBundleDiscoverers)
{ {
@ -350,7 +348,7 @@ public class ServerInstanceWrapper
if (_ctxtCollection == null) if (_ctxtCollection == null)
throw new IllegalStateException("ERROR: No ContextHandlerCollection configured in Server"); throw new IllegalStateException("ERROR: No ContextHandlerCollection configured in Server");
List<String> providerClassNames = new ArrayList<String>(); List<String> providerClassNames = new ArrayList<>();
// get a deployerManager and some providers // get a deployerManager and some providers
Collection<DeploymentManager> deployers = _server.getBeans(DeploymentManager.class); Collection<DeploymentManager> deployers = _server.getBeans(DeploymentManager.class);
@ -372,7 +370,7 @@ public class ServerInstanceWrapper
} }
_deploymentManager.setUseStandardBindings(false); _deploymentManager.setUseStandardBindings(false);
List<AppLifeCycle.Binding> deploymentLifeCycleBindings = new ArrayList<AppLifeCycle.Binding>(); List<AppLifeCycle.Binding> deploymentLifeCycleBindings = new ArrayList<>();
deploymentLifeCycleBindings.add(new OSGiDeployer(this)); deploymentLifeCycleBindings.add(new OSGiDeployer(this));
deploymentLifeCycleBindings.add(new StandardStarter()); deploymentLifeCycleBindings.add(new StandardStarter());
deploymentLifeCycleBindings.add(new StandardStopper()); deploymentLifeCycleBindings.add(new StandardStopper());
@ -446,7 +444,7 @@ public class ServerInstanceWrapper
private List<File> extractFiles(String propertyValue) private List<File> extractFiles(String propertyValue)
{ {
StringTokenizer tokenizer = new StringTokenizer(propertyValue, ",;", false); StringTokenizer tokenizer = new StringTokenizer(propertyValue, ",;", false);
List<File> files = new ArrayList<File>(); List<File> files = new ArrayList<>();
while (tokenizer.hasMoreTokens()) while (tokenizer.hasMoreTokens())
{ {
String tok = tokenizer.nextToken(); String tok = tokenizer.nextToken();

View File

@ -68,7 +68,7 @@ public class LibExtClassLoaderHelper
public static final Set<IFilesInJettyHomeResourcesProcessor> registeredFilesInJettyHomeResourcesProcessors = new HashSet<IFilesInJettyHomeResourcesProcessor>(); public static final Set<IFilesInJettyHomeResourcesProcessor> registeredFilesInJettyHomeResourcesProcessors = new HashSet<>();
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -83,12 +83,12 @@ public class LibExtClassLoaderHelper
public static ClassLoader createLibEtcClassLoader(File jettyHome, ClassLoader parentClassLoader) throws MalformedURLException public static ClassLoader createLibEtcClassLoader(File jettyHome, ClassLoader parentClassLoader) throws MalformedURLException
{ {
if (jettyHome == null) { return parentClassLoader; } if (jettyHome == null) { return parentClassLoader; }
ArrayList<URL> urls = new ArrayList<URL>(); ArrayList<URL> urls = new ArrayList<>();
File jettyResources = new File(jettyHome, "resources"); File jettyResources = new File(jettyHome, "resources");
if (jettyResources.exists()) if (jettyResources.exists())
{ {
// make sure it contains something else than README: // make sure it contains something else than README:
Map<String, File> jettyResFiles = new HashMap<String, File>(); Map<String, File> jettyResFiles = new HashMap<>();
for (File f : jettyResources.listFiles()) for (File f : jettyResources.listFiles())
{ {
jettyResFiles.put(f.getName(), f); jettyResFiles.put(f.getName(), f);
@ -143,7 +143,7 @@ public class LibExtClassLoaderHelper
throws MalformedURLException throws MalformedURLException
{ {
if (jarsContainerOrJars == null && otherJarsOrFolder == null) { return parentClassLoader; } if (jarsContainerOrJars == null && otherJarsOrFolder == null) { return parentClassLoader; }
List<URL> urls = new ArrayList<URL>(); List<URL> urls = new ArrayList<>();
if (otherJarsOrFolder != null) if (otherJarsOrFolder != null)
{ {
urls.addAll(otherJarsOrFolder); urls.addAll(otherJarsOrFolder);

View File

@ -57,7 +57,7 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
* when a logging framework is setup in the osgi classloaders, it can access * 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. * this and register the classes that must not be found in the jar.
*/ */
public static final Set<String> JAR_WITH_SUCH_CLASS_MUST_BE_EXCLUDED = new HashSet<String>(); public static final Set<String> JAR_WITH_SUCH_CLASS_MUST_BE_EXCLUDED = new HashSet<>();
public static void addClassThatIdentifiesAJarThatMustBeRejected(Class<?> zclass) public static void addClassThatIdentifiesAJarThatMustBeRejected(Class<?> zclass)
{ {
@ -149,7 +149,7 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
private List<URL> toList(Enumeration<URL> e, Enumeration<URL> e2) private List<URL> toList(Enumeration<URL> e, Enumeration<URL> e2)
{ {
List<URL> list = new ArrayList<URL>(); List<URL> list = new ArrayList<>();
while (e != null && e.hasMoreElements()) while (e != null && e.hasMoreElements())
list.add(e.nextElement()); list.add(e.nextElement());
while (e2 != null && e2.hasMoreElements()) while (e2 != null && e2.hasMoreElements())

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.osgi.boot.utils; package org.eclipse.jetty.osgi.boot.utils;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.Enumeration; import java.util.Enumeration;

View File

@ -23,7 +23,6 @@ import java.util.Hashtable;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil; import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.service.event.Event; import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin; import org.osgi.service.event.EventAdmin;
import org.osgi.util.tracker.ServiceTracker; import org.osgi.util.tracker.ServiceTracker;
@ -68,7 +67,7 @@ public class EventSender
{ {
EventAdmin service = (EventAdmin)_serviceTracker.getService(); EventAdmin service = (EventAdmin)_serviceTracker.getService();
if (service != null) { if (service != null) {
Dictionary<String,Object> props = new Hashtable<String,Object>(); Dictionary<String,Object> props = new Hashtable<>();
props.put("bundle.symbolicName", wab.getSymbolicName()); props.put("bundle.symbolicName", wab.getSymbolicName());
props.put("bundle.id", wab.getBundleId()); props.put("bundle.id", wab.getBundleId());
props.put("bundle", wab); props.put("bundle", wab);

View File

@ -165,7 +165,7 @@ public class OSGiClassLoader extends URLClassLoader
*/ */
private List<URL> toList(Enumeration<URL> e, Enumeration<URL> e2) private List<URL> toList(Enumeration<URL> e, Enumeration<URL> e2)
{ {
List<URL> list = new ArrayList<URL>(); List<URL> list = new ArrayList<>();
while (e != null && e.hasMoreElements()) while (e != null && e.hasMoreElements())
list.add(e.nextElement()); list.add(e.nextElement());
while (e2 != null && e2.hasMoreElements()) while (e2 != null && e2.hasMoreElements())

View File

@ -72,7 +72,7 @@ public class Util
* @param manifest the dictionary * @param manifest the dictionary
* @return the value from the manifest * @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<String,String> manifest)
{ {
if (manifest == null) if (manifest == null)
return null; return null;
@ -103,7 +103,7 @@ public class Util
delims = separators; delims = separators;
StringTokenizer tokenizer = new StringTokenizer(val, delims, false); StringTokenizer tokenizer = new StringTokenizer(val, delims, false);
List<URL> urls = new ArrayList<URL>(); List<URL> urls = new ArrayList<>();
while (tokenizer.hasMoreTokens()) while (tokenizer.hasMoreTokens())
{ {
urls.add(BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(new URL(tokenizer.nextToken()))); urls.add(BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(new URL(tokenizer.nextToken())));
@ -113,7 +113,7 @@ public class Util
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public static void setProperty(Dictionary<String,String> properties, String key, String value) public static void setProperty(Dictionary<String,Object> properties, String key, Object value)
{ {
if (value != null) if (value != null)
{ {

View File

@ -38,10 +38,10 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper
private static final Logger LOG = Log.getLogger(BundleClassLoaderHelper.class); private static final Logger LOG = Log.getLogger(BundleClassLoaderHelper.class);
private static enum OSGiContainerType {EquinoxOld, EquinoxLuna, FelixOld, Felix403, Concierge}; private static enum OSGiContainerType {EquinoxOld, EquinoxLuna, FelixOld, Felix403, Concierge};
private static OSGiContainerType osgiContainer; private static OSGiContainerType osgiContainer;
private static Class Equinox_BundleHost_Class; private static Class<?> Equinox_BundleHost_Class;
private static Class Equinox_EquinoxBundle_Class; private static Class<?> Equinox_EquinoxBundle_Class;
private static Class Felix_BundleImpl_Class; private static Class<?> Felix_BundleImpl_Class;
private static Class Felix_BundleWiring_Class; private static Class<?> Felix_BundleWiring_Class;
//old equinox //old equinox
private static Method Equinox_BundleHost_getBundleLoader_method; private static Method Equinox_BundleHost_getBundleLoader_method;
private static Method Equinox_BundleLoader_createClassLoader_method; private static Method Equinox_BundleLoader_createClassLoader_method;
@ -56,8 +56,8 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper
private static Method Felix_BundleWiring_getClassLoader_Method; private static Method Felix_BundleWiring_getClassLoader_Method;
// Concierge // Concierge
private static Class Concierge_BundleImpl_Class; private static Class<?> Concierge_BundleImpl_Class;
private static Class Concierge_BundleWiring_Class; private static Class<?> Concierge_BundleWiring_Class;
private static Method Concierge_BundleImpl_Adapt_Method; private static Method Concierge_BundleImpl_Adapt_Method;
private static Method Concierge_BundleWiring_getClassLoader_Method; private static Method Concierge_BundleWiring_getClassLoader_Method;
@ -267,6 +267,7 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper
* @param bundle * @param bundle
* @return * @return
*/ */
@SuppressWarnings("unchecked")
private static ClassLoader internalGetFelixBundleClassLoader(Bundle bundle) private static ClassLoader internalGetFelixBundleClassLoader(Bundle bundle)
{ {

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.osgi.boot.utils.internal; package org.eclipse.jetty.osgi.boot.utils.internal;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
@ -88,6 +87,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
* @return Its installation location as a file. * @return Its installation location as a file.
* @throws Exception if unable to get the bundle install location * @throws Exception if unable to get the bundle install location
*/ */
@SuppressWarnings("resource")
public File getBundleInstallLocation(Bundle bundle) throws Exception public File getBundleInstallLocation(Bundle bundle) throws Exception
{ {
// String installedBundles = System.getProperty("osgi.bundles"); // String installedBundles = System.getProperty("osgi.bundles");
@ -249,6 +249,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
path = "/" + path; path = "/" + path;
} }
String pattern = last != -1 && last < entryPath.length() - 2 ? entryPath.substring(last + 1) : entryPath; String pattern = last != -1 && last < entryPath.length() - 2 ? entryPath.substring(last + 1) : entryPath;
@SuppressWarnings("unchecked")
Enumeration<URL> enUrls = bundle.findEntries(path, pattern, false); Enumeration<URL> enUrls = bundle.findEntries(path, pattern, false);
return enUrls; return enUrls;
} }
@ -273,7 +274,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
if (jasperLocation.isDirectory()) if (jasperLocation.isDirectory())
{ {
// try to find the jar files inside this folder // try to find the jar files inside this folder
ArrayList<File> urls = new ArrayList<File>(); ArrayList<File> urls = new ArrayList<>();
for (File f : jasperLocation.listFiles()) for (File f : jasperLocation.listFiles())
{ {
if (f.getName().endsWith(".jar") && f.isFile()) if (f.getName().endsWith(".jar") && f.isFile())
@ -327,10 +328,10 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
conn.setDefaultUseCaches(Resource.getDefaultUseCaches()); conn.setDefaultUseCaches(Resource.getDefaultUseCaches());
if (BUNDLE_URL_CONNECTION_getLocalURL == null && match(conn.getClass().getName(), BUNDLE_URL_CONNECTION_CLASSES)) 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); 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; return url;
} }
@ -360,10 +361,10 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
&& &&
match (conn.getClass().getName(), BUNDLE_URL_CONNECTION_CLASSES)) 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); 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; return url;

View File

@ -47,7 +47,7 @@ public class PackageAdminServiceTracker implements ServiceListener
{ {
private BundleContext _context; private BundleContext _context;
private List<BundleActivator> _activatedFragments = new ArrayList<BundleActivator>(); private List<BundleActivator> _activatedFragments = new ArrayList<>();
private boolean _fragmentsWereActivated = false; private boolean _fragmentsWereActivated = false;
@ -153,7 +153,7 @@ public class PackageAdminServiceTracker implements ServiceListener
return null; return null;
} }
PackageAdmin admin = (PackageAdmin) _context.getService(sr); PackageAdmin admin = (PackageAdmin) _context.getService(sr);
LinkedHashMap<String, Bundle> deps = new LinkedHashMap<String, Bundle>(); LinkedHashMap<String, Bundle> deps = new LinkedHashMap<>();
collectFragmentsAndRequiredBundles(bundle, admin, deps, false); collectFragmentsAndRequiredBundles(bundle, admin, deps, false);
return deps.values().toArray(new Bundle[deps.size()]); return deps.values().toArray(new Bundle[deps.size()]);
} }

View File

@ -80,8 +80,8 @@ public class TestJettyOSGiBootContextAsService
@Ignore @Ignore
@Test
public void assertAllBundlesActiveOrResolved() public void assertAllBundlesActiveOrResolved()
{ {
TestOSGiUtil.assertAllBundlesActiveOrResolved(bundleContext); TestOSGiUtil.assertAllBundlesActiveOrResolved(bundleContext);