Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2014-06-30 20:37:41 -0400
committerJan Bartel2014-06-30 20:40:58 -0400
commit839485797b74e8dac0180348e14a7464a7816525 (patch)
tree40bf95f851b1f7b19a464f15ec5fcf5a1d2fbb0b /jetty-osgi/jetty-osgi-boot/src
parent0751256559e35937dc20bc45aaf3317b153b81c8 (diff)
downloadorg.eclipse.jetty.project-839485797b74e8dac0180348e14a7464a7816525.tar.gz
org.eclipse.jetty.project-839485797b74e8dac0180348e14a7464a7816525.tar.xz
org.eclipse.jetty.project-839485797b74e8dac0180348e14a7464a7816525.zip
437419 Allow scanning of META-INF for resources,fragments,tlds for unpacked jars
Diffstat (limited to 'jetty-osgi/jetty-osgi-boot/src')
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java3
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiMetaInfConfiguration.java129
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java52
3 files changed, 43 insertions, 141 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 322aec55e7..14c796d213 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
@@ -23,6 +23,7 @@ import java.util.Set;
import org.eclipse.jetty.annotations.AnnotationParser.Handler;
import org.eclipse.jetty.annotations.ClassNameResolver;
+import org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration;
import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
import org.eclipse.jetty.util.log.Log;
@@ -92,7 +93,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
AnnotationParser oparser = (AnnotationParser)parser;
Bundle webbundle = (Bundle) context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
- Bundle[] fragAndRequiredBundles = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles(webbundle);
+ Set<Bundle> fragAndRequiredBundles = (Set<Bundle>)context.getAttribute(OSGiWebInfConfiguration.FRAGMENT_AND_REQUIRED_BUNDLES);
if (fragAndRequiredBundles != null)
{
//index and scan fragments
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiMetaInfConfiguration.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiMetaInfConfiguration.java
deleted file mode 100644
index 7b85f62a2d..0000000000
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiMetaInfConfiguration.java
+++ /dev/null
@@ -1,129 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.osgi.boot;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelperFactory;
-import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.webapp.MetaInfConfiguration;
-import org.eclipse.jetty.webapp.WebAppContext;
-import org.osgi.framework.Bundle;
-
-/**
- * OSGiMetaInfConfiguration
- *
- * Extension of standard Jetty MetaInfConfiguration class to handle OSGi bundle
- * fragments that may also need to be scanned for META-INF info.
- *
- * @deprecated
- */
-public class OSGiMetaInfConfiguration extends MetaInfConfiguration
-{
- private static final Logger LOG = Log.getLogger(OSGiMetaInfConfiguration.class);
-
-
- /**
- * Inspect bundle fragments associated with the bundle of the webapp for web-fragment, resources, tlds.
- *
- * @see org.eclipse.jetty.webapp.MetaInfConfiguration#preConfigure(org.eclipse.jetty.webapp.WebAppContext)
- */
- @Override
- public void preConfigure(final WebAppContext context) throws Exception
- {
- Map<Resource, Resource> frags = (Map<Resource, Resource>) context.getAttribute(METAINF_FRAGMENTS);
- Set<Resource> resfrags = (Set<Resource>) context.getAttribute(METAINF_RESOURCES);
- List<Resource> tldfrags = (List<Resource>) context.getAttribute(METAINF_TLDS);
-
- Bundle[] fragments = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles((Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE));
- //TODO not convinced we need to do this, as we added any fragment jars to the MetaData.webInfJars in OSGiWebInfConfiguration,
- //so surely the web-fragments and resources tlds etc can be discovered normally?
- for (Bundle frag : fragments)
- {
- URL webFrag = frag.getEntry("/META-INF/web-fragment.xml");
- Enumeration<URL> resEnum = frag.findEntries("/META-INF/resources", "*", true);
- Enumeration<URL> tldEnum = frag.findEntries("/META-INF", "*.tld", false);
- if (webFrag != null || (resEnum != null && resEnum.hasMoreElements()) || (tldEnum != null && tldEnum.hasMoreElements()))
- {
- try
- {
- if (webFrag != null)
- {
- if (frags == null)
- {
- frags = new HashMap<Resource,Resource>();
- context.setAttribute(METAINF_FRAGMENTS, frags);
- }
- frags.put(Resource.newResource(BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(frag).toURI()),
- Resource.newResource(webFrag));
- }
- if (resEnum != null && resEnum.hasMoreElements())
- {
- URL resourcesEntry = frag.getEntry("/META-INF/resources/");
- if (resourcesEntry == null)
- {
- // probably we found some fragments to a
- // bundle.
- // those are already contributed.
- // so we skip this.
- }
- else
- {
- if (resfrags == null)
- {
- resfrags = new HashSet<Resource>();
- context.setAttribute(METAINF_RESOURCES, resfrags);
- }
- resfrags.add(Resource.newResource(BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(resourcesEntry)));
- }
- }
- if (tldEnum != null && tldEnum.hasMoreElements())
- {
- if (tldfrags == null)
- {
- tldfrags = new ArrayList<Resource>();
- context.setAttribute(METAINF_TLDS, tldfrags);
- }
- while (tldEnum.hasMoreElements())
- {
- URL tldUrl = tldEnum.nextElement();
- tldfrags.add(Resource.newResource(BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(tldUrl)));
- }
- }
- }
- catch (Exception e)
- {
- LOG.warn("Unable to locate the bundle " + frag.getBundleId(), e);
- }
- }
- }
-
- super.preConfigure(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 ce3c141ae5..69a7ce8cdb 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
@@ -23,6 +23,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.regex.Pattern;
@@ -51,6 +52,9 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
public static final String CONTAINER_BUNDLE_PATTERN = "org.eclipse.jetty.server.webapp.containerIncludeBundlePattern";
+ public static final String FRAGMENT_AND_REQUIRED_BUNDLES = "org.eclipse.jetty.osgi.fragmentAndRequiredBundles";
+ public static final String FRAGMENT_AND_REQUIRED_RESOURCES = "org.eclipse.jetty.osgi.fragmentAndRequiredResources";
+
/* ------------------------------------------------------------ */
/**
@@ -87,7 +91,6 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
while (tokenizer.hasMoreTokens())
names.add(tokenizer.nextToken());
}
-
HashSet<Resource> matchingResources = new HashSet<Resource>();
if ( !names.isEmpty() || pattern != null)
{
@@ -111,14 +114,20 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
matchingResources.addAll(getBundleAsResource(bundle));
}
}
- }
-
+ }
for (Resource r:matchingResources)
{
context.getMetaData().addContainerResource(r);
}
}
+ @Override
+ public void postConfigure(WebAppContext context) throws Exception
+ {
+ context.setAttribute(FRAGMENT_AND_REQUIRED_BUNDLES, null);
+ context.setAttribute(FRAGMENT_AND_REQUIRED_RESOURCES, null);
+ super.postConfigure(context);
+ }
/* ------------------------------------------------------------ */
/**
@@ -137,12 +146,34 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
if (webInfJars != null)
mergedResources.addAll(webInfJars);
- //add fragment jars as if in WEB-INF/lib of the associated webapp
- Bundle[] fragments = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles((Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE));
- for (Bundle frag : fragments)
+ //add fragment jars and any Required-Bundles as if in WEB-INF/lib of the associated webapp
+ Bundle[] bundles = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles((Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE));
+ if (bundles != null && bundles.length > 0)
{
- File fragFile = BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(frag);
- mergedResources.add(Resource.newResource(fragFile.toURI()));
+ Set<Bundle> fragsAndReqsBundles = (Set<Bundle>)context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES);
+ if (fragsAndReqsBundles == null)
+ {
+ fragsAndReqsBundles = new HashSet<Bundle>();
+ context.setAttribute(FRAGMENT_AND_REQUIRED_BUNDLES, fragsAndReqsBundles);
+ }
+
+ Set<Resource> fragsAndReqsResources = (Set<Resource>)context.getAttribute(FRAGMENT_AND_REQUIRED_RESOURCES);
+ if (fragsAndReqsResources == null)
+ {
+ fragsAndReqsResources = new HashSet<Resource>();
+ context.setAttribute(FRAGMENT_AND_REQUIRED_RESOURCES, fragsAndReqsResources);
+ }
+
+ for (Bundle b : bundles)
+ {
+ //add to context attribute storing associated fragments and required bundles
+ fragsAndReqsBundles.add(b);
+ File f = BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(b);
+ Resource r = Resource.newResource(f.toURI());
+ //add to convenience context attribute storing fragments and required bundles as Resources
+ fragsAndReqsResources.add(r);
+ mergedResources.add(r);
+ }
}
return mergedResources;
@@ -165,9 +196,8 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
Bundle bundle = (Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
if (bundle != null)
{
- //TODO anything we need to do to improve PackageAdminServiceTracker?
- Bundle[] fragments = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles(bundle);
- if (fragments != null && fragments.length != 0)
+ Set<Bundle> fragments = (Set<Bundle>)context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES);
+ if (fragments != null && !fragments.isEmpty())
{
// sorted extra resource base found in the fragments.
// the resources are either overriding the resourcebase found in the

Back to the top