23
23
import java .util .ArrayList ;
24
24
import java .util .HashSet ;
25
25
import java .util .List ;
26
+ import java .util .Set ;
26
27
import java .util .StringTokenizer ;
27
28
import java .util .TreeMap ;
28
29
import java .util .regex .Pattern ;
@@ -51,6 +52,9 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
51
52
52
53
53
54
public static final String CONTAINER_BUNDLE_PATTERN = "org.eclipse.jetty.server.webapp.containerIncludeBundlePattern" ;
55
+ public static final String FRAGMENT_AND_REQUIRED_BUNDLES = "org.eclipse.jetty.osgi.fragmentAndRequiredBundles" ;
56
+ public static final String FRAGMENT_AND_REQUIRED_RESOURCES = "org.eclipse.jetty.osgi.fragmentAndRequiredResources" ;
57
+
54
58
55
59
/* ------------------------------------------------------------ */
56
60
/**
@@ -87,7 +91,6 @@ public void preConfigure(final WebAppContext context) throws Exception
87
91
while (tokenizer .hasMoreTokens ())
88
92
names .add (tokenizer .nextToken ());
89
93
}
90
-
91
94
HashSet <Resource > matchingResources = new HashSet <Resource >();
92
95
if ( !names .isEmpty () || pattern != null )
93
96
{
@@ -111,14 +114,20 @@ public void preConfigure(final WebAppContext context) throws Exception
111
114
matchingResources .addAll (getBundleAsResource (bundle ));
112
115
}
113
116
}
114
- }
115
-
117
+ }
116
118
for (Resource r :matchingResources )
117
119
{
118
120
context .getMetaData ().addContainerResource (r );
119
121
}
120
122
}
121
123
124
+ @ Override
125
+ public void postConfigure (WebAppContext context ) throws Exception
126
+ {
127
+ context .setAttribute (FRAGMENT_AND_REQUIRED_BUNDLES , null );
128
+ context .setAttribute (FRAGMENT_AND_REQUIRED_RESOURCES , null );
129
+ super .postConfigure (context );
130
+ }
122
131
123
132
/* ------------------------------------------------------------ */
124
133
/**
@@ -137,12 +146,34 @@ protected List<Resource> findJars (WebAppContext context)
137
146
if (webInfJars != null )
138
147
mergedResources .addAll (webInfJars );
139
148
140
- //add fragment jars as if in WEB-INF/lib of the associated webapp
141
- Bundle [] fragments = PackageAdminServiceTracker .INSTANCE .getFragmentsAndRequiredBundles ((Bundle )context .getAttribute (OSGiWebappConstants .JETTY_OSGI_BUNDLE ));
142
- for ( Bundle frag : fragments )
149
+ //add fragment jars and any Required-Bundles as if in WEB-INF/lib of the associated webapp
150
+ Bundle [] bundles = PackageAdminServiceTracker .INSTANCE .getFragmentsAndRequiredBundles ((Bundle )context .getAttribute (OSGiWebappConstants .JETTY_OSGI_BUNDLE ));
151
+ if ( bundles != null && bundles . length > 0 )
143
152
{
144
- File fragFile = BundleFileLocatorHelperFactory .getFactory ().getHelper ().getBundleInstallLocation (frag );
145
- mergedResources .add (Resource .newResource (fragFile .toURI ()));
153
+ Set <Bundle > fragsAndReqsBundles = (Set <Bundle >)context .getAttribute (FRAGMENT_AND_REQUIRED_BUNDLES );
154
+ if (fragsAndReqsBundles == null )
155
+ {
156
+ fragsAndReqsBundles = new HashSet <Bundle >();
157
+ context .setAttribute (FRAGMENT_AND_REQUIRED_BUNDLES , fragsAndReqsBundles );
158
+ }
159
+
160
+ Set <Resource > fragsAndReqsResources = (Set <Resource >)context .getAttribute (FRAGMENT_AND_REQUIRED_RESOURCES );
161
+ if (fragsAndReqsResources == null )
162
+ {
163
+ fragsAndReqsResources = new HashSet <Resource >();
164
+ context .setAttribute (FRAGMENT_AND_REQUIRED_RESOURCES , fragsAndReqsResources );
165
+ }
166
+
167
+ for (Bundle b : bundles )
168
+ {
169
+ //add to context attribute storing associated fragments and required bundles
170
+ fragsAndReqsBundles .add (b );
171
+ File f = BundleFileLocatorHelperFactory .getFactory ().getHelper ().getBundleInstallLocation (b );
172
+ Resource r = Resource .newResource (f .toURI ());
173
+ //add to convenience context attribute storing fragments and required bundles as Resources
174
+ fragsAndReqsResources .add (r );
175
+ mergedResources .add (r );
176
+ }
146
177
}
147
178
148
179
return mergedResources ;
@@ -165,9 +196,8 @@ public void configure(WebAppContext context) throws Exception
165
196
Bundle bundle = (Bundle )context .getAttribute (OSGiWebappConstants .JETTY_OSGI_BUNDLE );
166
197
if (bundle != null )
167
198
{
168
- //TODO anything we need to do to improve PackageAdminServiceTracker?
169
- Bundle [] fragments = PackageAdminServiceTracker .INSTANCE .getFragmentsAndRequiredBundles (bundle );
170
- if (fragments != null && fragments .length != 0 )
199
+ Set <Bundle > fragments = (Set <Bundle >)context .getAttribute (FRAGMENT_AND_REQUIRED_BUNDLES );
200
+ if (fragments != null && !fragments .isEmpty ())
171
201
{
172
202
// sorted extra resource base found in the fragments.
173
203
// the resources are either overriding the resourcebase found in the
0 commit comments