Merge pull request #2265 from eclipse/jetty-9.4.x-2262-sanitize-osgi-code

Jetty 9.4.x 2262 sanitize osgi code
This commit is contained in:
Greg Wilkins 2018-03-06 17:36:57 +11:00 committed by GitHub
commit 2905d081b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 83 additions and 82 deletions

View File

@ -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;
@ -117,6 +116,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<Bundle> fragAndRequiredBundles = (Set<Bundle>)context.getAttribute(OSGiWebInfConfiguration.FRAGMENT_AND_REQUIRED_BUNDLES);
if (fragAndRequiredBundles != null)
{
@ -230,7 +230,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
{
Resource bundleRes = parser.getResource(bundle);
Set<Handler> handlers = new HashSet<Handler>();
Set<Handler> handlers = new HashSet<>();
handlers.addAll(_discoverableAnnotationHandlers);
if (_classInheritanceHandler != null)
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 ConcurrentHashMap<URI,Bundle> _uriToBundle = new ConcurrentHashMap<URI, Bundle>();
private ConcurrentHashMap<Bundle,Resource> _bundleToResource = new ConcurrentHashMap<Bundle,Resource>();
private ConcurrentHashMap<Resource, Bundle> _resourceToBundle = new ConcurrentHashMap<Resource, Bundle>();
private ConcurrentHashMap<Bundle,URI> _bundleToUri = new ConcurrentHashMap<Bundle, URI>();
private ConcurrentHashMap<URI,Bundle> _uriToBundle = new ConcurrentHashMap<>();
private ConcurrentHashMap<Bundle,Resource> _bundleToResource = new ConcurrentHashMap<>();
private ConcurrentHashMap<Resource, Bundle> _resourceToBundle = new ConcurrentHashMap<>();
private ConcurrentHashMap<Bundle,URI> _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<String> paths = new TreeSet<String>(
TreeSet<String> paths = new TreeSet<>(
new Comparator<String>()
{
@Override
@ -177,6 +177,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)
{

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.
*/
private Map<Bundle, App> _bundleMap = new HashMap<Bundle, App>();
private Map<Bundle, App> _bundleMap = new HashMap<>();
private ServiceRegistration _serviceRegForBundles;
@ -125,7 +125,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<String,String> properties = new Hashtable<String,String>();
Dictionary<String,String> 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();
@ -177,6 +177,7 @@ public class BundleWebAppProvider extends AbstractWebAppProvider implements Bund
String contextPath = null;
try
{
@SuppressWarnings("unchecked")
Dictionary<String,String> headers = bundle.getHeaders();
//does the bundle have a OSGiWebappConstants.JETTY_WAR_FOLDER_PATH

View File

@ -80,7 +80,7 @@ public class JettyBootstrapActivator implements BundleActivator
_jettyServerServiceTracker.open();
// 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
String tmp = (String)context.getAttribute(CONTAINER_BUNDLE_PATTERN);
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);
if (tmp != null)
{
@ -103,7 +103,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
while (tokenizer.hasMoreTokens())
names.add(tokenizer.nextToken());
}
HashSet<Resource> matchingResources = new HashSet<Resource>();
HashSet<Resource> 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<Resource> findJars (WebAppContext context)
throws Exception
{
List<Resource> mergedResources = new ArrayList<Resource>();
List<Resource> mergedResources = new ArrayList<>();
//get jars from WEB-INF/lib if there are any
List<Resource> 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<Bundle> fragsAndReqsBundles = (Set<Bundle>)context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES);
if (fragsAndReqsBundles == null)
{
fragsAndReqsBundles = new HashSet<Bundle>();
fragsAndReqsBundles = new HashSet<>();
context.setAttribute(FRAGMENT_AND_REQUIRED_BUNDLES, fragsAndReqsBundles);
}
@SuppressWarnings("unchecked")
Set<Resource> fragsAndReqsResources = (Set<Resource>)context.getAttribute(FRAGMENT_AND_REQUIRED_RESOURCES);
if (fragsAndReqsResources == null)
{
fragsAndReqsResources = new HashSet<Resource>();
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<String, Resource> prependedResourcesPath = new TreeMap<String, Resource>();
TreeMap<String, Resource> appendedResourcesPath = new TreeMap<String, Resource>();
TreeMap<String, Resource> prependedResourcesPath = new TreeMap<>();
TreeMap<String, Resource> appendedResourcesPath = new TreeMap<>();
Bundle bundle = (Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
if (bundle != null)
{
@SuppressWarnings("unchecked")
Set<Bundle> fragments = (Set<Bundle>)context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES);
if (fragments != null && !fragments.isEmpty())
{
@ -238,8 +241,9 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
}
if (!appendedResourcesPath.isEmpty())
{
LinkedHashSet<Resource> resources = new LinkedHashSet<Resource>();
LinkedHashSet<Resource> resources = new LinkedHashSet<>();
//Add in any existing setting of extra resource dirs
@SuppressWarnings("unchecked")
Set<Resource> resourceDirs = (Set<Resource>)context.getAttribute(WebInfConfiguration.RESOURCE_DIRS);
if (resourceDirs != null && !resourceDirs.isEmpty())
resources.addAll(resourceDirs);
@ -272,7 +276,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
private List<Resource> getBundleAsResource(Bundle bundle)
throws Exception
{
List<Resource> resources = new ArrayList<Resource>();
List<Resource> resources = new ArrayList<>();
File file = BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(bundle);
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.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<ServiceReference, App> _serviceMap = new HashMap<ServiceReference, App>();
private Map<ServiceReference, App> _serviceMap = new HashMap<>();
private ServiceRegistration _serviceRegForServices;
@ -169,7 +168,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<String, Object>();
Dictionary<String,Object> properties = new Hashtable<>();
if (keys != null)
{
for (String key:keys)
@ -228,7 +227,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<String,String> properties = new Hashtable<String,String>();
Dictionary<String,String> 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

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.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<ServiceReference, App> _serviceMap = new HashMap<ServiceReference, App>();
private Map<ServiceReference, App> _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<String,String> properties, String originId)
{
super(manager, provider, bundle, properties, originId);
}
@ -168,7 +167,7 @@ public class ServiceWebAppProvider extends AbstractWebAppProvider implements Ser
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);
if (contextPath == null)
@ -275,7 +274,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<String,String> properties = new Hashtable<String,String>();
Dictionary<String,String> 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

View File

@ -102,7 +102,7 @@ public class DefaultJettyAtJettyHomeHelper
File jettyHomeDir = null;
Bundle jettyHomeBundle = null;
Dictionary<String,String> properties = new Hashtable<String,String>();
Dictionary<String, Object> properties = new Hashtable<>();
if (jettyHomeSysProp != null)
{
jettyHomeSysProp = Util.resolvePropertyValue(jettyHomeSysProp);
@ -157,8 +157,8 @@ public class DefaultJettyAtJettyHomeHelper
List<URL> 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<URL> getJettyConfigurationURLs(File jettyhome)
throws MalformedURLException
{
List<URL> configURLs = new ArrayList<URL>();
List<URL> 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<URL> getJettyConfigurationURLs(Bundle configurationBundle, Dictionary properties)
throws Exception
{
List<URL> configURLs = new ArrayList<URL>();
List<URL> configURLs = new ArrayList<>();
String files = System.getProperty(JETTY_ETC_FILES, DEFAULT_JETTY_ETC_FILES);
StringTokenizer tokenizer = new StringTokenizer(files, ";,", false);

View File

@ -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<String,Object> props = new Hashtable<>();
for (String key : sr.getPropertyKeys())
{
Object value = sr.getProperty(key);
props.put(key, value);
props.put(key, sr.getProperty(key));
}
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";
private static Collection<TldBundleDiscoverer> __containerTldBundleDiscoverers = new ArrayList<TldBundleDiscoverer>();
private static Collection<TldBundleDiscoverer> __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<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; }
Map<String, Object> id_map = new HashMap<String, Object>();
Map<String, Object> 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<String, String> properties = new HashMap<String, String>();
Map<String, String> properties = new HashMap<>();
if (props != null)
{
Enumeration<Object> en = props.keys();
Enumeration<String> 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<String,Object> 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<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
for (TldBundleDiscoverer d:__containerTldBundleDiscoverers)
{
@ -350,7 +348,7 @@ public class ServerInstanceWrapper
if (_ctxtCollection == null)
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
Collection<DeploymentManager> deployers = _server.getBeans(DeploymentManager.class);
@ -372,7 +370,7 @@ public class ServerInstanceWrapper
}
_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 StandardStarter());
deploymentLifeCycleBindings.add(new StandardStopper());
@ -446,7 +444,7 @@ public class ServerInstanceWrapper
private List<File> extractFiles(String propertyValue)
{
StringTokenizer tokenizer = new StringTokenizer(propertyValue, ",;", false);
List<File> files = new ArrayList<File>();
List<File> files = new ArrayList<>();
while (tokenizer.hasMoreTokens())
{
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
{
if (jettyHome == null) { return parentClassLoader; }
ArrayList<URL> urls = new ArrayList<URL>();
ArrayList<URL> urls = new ArrayList<>();
File jettyResources = new File(jettyHome, "resources");
if (jettyResources.exists())
{
// 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())
{
jettyResFiles.put(f.getName(), f);
@ -143,7 +143,7 @@ public class LibExtClassLoaderHelper
throws MalformedURLException
{
if (jarsContainerOrJars == null && otherJarsOrFolder == null) { return parentClassLoader; }
List<URL> urls = new ArrayList<URL>();
List<URL> urls = new ArrayList<>();
if (otherJarsOrFolder != null)
{
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
* 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)
{
@ -150,7 +150,7 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
/* ------------------------------------------------------------ */
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())
list.add(e.nextElement());
while (e2 != null && e2.hasMoreElements())

View File

@ -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;

View File

@ -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<String,Object> props = new Hashtable<String,Object>();
Dictionary<String,Object> props = new Hashtable<>();
props.put("bundle.symbolicName", wab.getSymbolicName());
props.put("bundle.id", wab.getBundleId());
props.put("bundle", wab);

View File

@ -166,7 +166,7 @@ public class OSGiClassLoader extends URLClassLoader
*/
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())
list.add(e.nextElement());
while (e2 != null && e2.hasMoreElements())

View File

@ -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<String,String> manifest)
{
if (manifest == null)
return null;
@ -103,7 +103,7 @@ public class Util
delims = separators;
StringTokenizer tokenizer = new StringTokenizer(val, delims, false);
List<URL> urls = new ArrayList<URL>();
List<URL> 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<String,String> properties, String key, String value)
public static void setProperty(Dictionary<String,Object> properties, String key, Object value)
{
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 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;
@ -268,6 +268,7 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper
* @param bundle
* @return
*/
@SuppressWarnings("unchecked")
private static ClassLoader internalGetFelixBundleClassLoader(Bundle bundle)
{

View File

@ -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,7 +87,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
* @return Its installation location as a file.
* @throws Exception if unable to get the bundle install location
*/
@Override
@SuppressWarnings("resource")
public File getBundleInstallLocation(Bundle bundle) throws Exception
{
// String installedBundles = System.getProperty("osgi.bundles");
@ -252,6 +251,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
path = "/" + path;
}
String pattern = last != -1 && last < entryPath.length() - 2 ? entryPath.substring(last + 1) : entryPath;
@SuppressWarnings("unchecked")
Enumeration<URL> enUrls = bundle.findEntries(path, pattern, false);
return enUrls;
}
@ -277,7 +277,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
if (jasperLocation.isDirectory())
{
// 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())
{
if (f.getName().endsWith(".jar") && f.isFile())
@ -332,10 +332,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;
}
@ -366,10 +366,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;

View File

@ -47,7 +47,7 @@ public class PackageAdminServiceTracker implements ServiceListener
{
private BundleContext _context;
private List<BundleActivator> _activatedFragments = new ArrayList<BundleActivator>();
private List<BundleActivator> _activatedFragments = new ArrayList<>();
private boolean _fragmentsWereActivated = false;
@ -154,7 +154,7 @@ public class PackageAdminServiceTracker implements ServiceListener
return null;
}
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);
return deps.values().toArray(new Bundle[deps.size()]);
}

View File

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