Lines 20-28
Link Here
|
20 |
import java.io.FileInputStream; |
20 |
import java.io.FileInputStream; |
21 |
import java.io.IOException; |
21 |
import java.io.IOException; |
22 |
import java.io.InputStream; |
22 |
import java.io.InputStream; |
23 |
import java.util.ArrayList; |
23 |
import java.util.HashSet; |
24 |
import java.util.Iterator; |
24 |
import java.util.List; |
25 |
import java.util.Locale; |
25 |
import java.util.Locale; |
|
|
26 |
import java.util.Set; |
26 |
import java.util.StringTokenizer; |
27 |
import java.util.StringTokenizer; |
27 |
import java.util.jar.JarInputStream; |
28 |
import java.util.jar.JarInputStream; |
28 |
import java.util.jar.Manifest; |
29 |
import java.util.jar.Manifest; |
Lines 56-67
Link Here
|
56 |
private static final StringManager sm = |
57 |
private static final StringManager sm = |
57 |
StringManager.getManager("org.apache.catalina.util"); |
58 |
StringManager.getManager("org.apache.catalina.util"); |
58 |
|
59 |
|
59 |
private static volatile ArrayList<Extension> containerAvailableExtensions = |
60 |
private static final String MANIFEST_PATH = "/META-INF/MANIFEST.MF"; |
60 |
null; |
|
|
61 |
private static final ArrayList<ManifestResource> containerManifestResources = |
62 |
new ArrayList<>(); |
63 |
|
61 |
|
|
|
62 |
private static volatile Set<Extension> containerAvailableExtensions; |
63 |
private static final Set<ManifestResource> containerManifestResources = |
64 |
new HashSet<>(); |
64 |
|
65 |
|
|
|
66 |
|
65 |
// ----------------------------------------------------- Static Initializer |
67 |
// ----------------------------------------------------- Static Initializer |
66 |
|
68 |
|
67 |
|
69 |
|
Lines 129-144
Link Here
|
129 |
throws IOException { |
131 |
throws IOException { |
130 |
|
132 |
|
131 |
String appName = context.getName(); |
133 |
String appName = context.getName(); |
132 |
ArrayList<ManifestResource> appManifestResources = new ArrayList<>(); |
134 |
Set<ManifestResource> appManifestResources = new HashSet<>(); |
133 |
|
135 |
|
134 |
// Web application manifest |
136 |
// Web application manifest |
135 |
WebResource resource = resources.getResource("/META-INF/MANIFEST.MF"); |
137 |
WebResource resource = resources.getResource(MANIFEST_PATH); |
136 |
if (resource.isFile()) { |
138 |
if (resource.isFile()) { |
137 |
try (InputStream inputStream = resource.getInputStream()) { |
139 |
try (InputStream inputStream = resource.getInputStream()) { |
138 |
Manifest manifest = new Manifest(inputStream); |
140 |
Manifest manifest = new Manifest(inputStream); |
139 |
ManifestResource mre = new ManifestResource |
141 |
ManifestResource mre = new ManifestResource |
140 |
(sm.getString("extensionValidator.web-application-manifest"), |
142 |
(sm.getString("extensionValidator.web-application-manifest"), |
141 |
manifest, ManifestResource.WAR); |
143 |
manifest, ManifestResource.ResourceType.WAR); |
142 |
appManifestResources.add(mre); |
144 |
appManifestResources.add(mre); |
143 |
} |
145 |
} |
144 |
} |
146 |
} |
Lines 145-160
Link Here
|
145 |
|
147 |
|
146 |
// Web application library manifests |
148 |
// Web application library manifests |
147 |
WebResource[] manifestResources = |
149 |
WebResource[] manifestResources = |
148 |
resources.getClassLoaderResources("/META-INF/MANIFEST.MF"); |
150 |
resources.getClassLoaderResources(MANIFEST_PATH); |
149 |
for (WebResource manifestResource : manifestResources) { |
151 |
for (WebResource manifestResource : manifestResources) { |
150 |
if (manifestResource.isFile()) { |
152 |
if (manifestResource.isFile()) { |
151 |
// Primarily used for error reporting |
153 |
// Primarily used for error reporting |
152 |
String jarName = manifestResource.getURL().toExternalForm(); |
154 |
String jarName = manifestResource.getURL().toExternalForm(); |
153 |
Manifest jmanifest = null; |
|
|
154 |
try (InputStream is = manifestResource.getInputStream()) { |
155 |
try (InputStream is = manifestResource.getInputStream()) { |
155 |
jmanifest = new Manifest(is); |
156 |
Manifest jmanifest = new Manifest(is); |
156 |
ManifestResource mre = new ManifestResource(jarName, |
157 |
ManifestResource mre = new ManifestResource(jarName, |
157 |
jmanifest, ManifestResource.APPLICATION); |
158 |
jmanifest, ManifestResource.ResourceType.APPLICATION); |
158 |
appManifestResources.add(mre); |
159 |
appManifestResources.add(mre); |
159 |
} |
160 |
} |
160 |
} |
161 |
} |
Lines 176-182
Link Here
|
176 |
Manifest manifest = getManifest(is); |
177 |
Manifest manifest = getManifest(is); |
177 |
if (manifest != null) { |
178 |
if (manifest != null) { |
178 |
ManifestResource mre = new ManifestResource(jarFile.getAbsolutePath(), manifest, |
179 |
ManifestResource mre = new ManifestResource(jarFile.getAbsolutePath(), manifest, |
179 |
ManifestResource.SYSTEM); |
180 |
ManifestResource.ResourceType.SYSTEM); |
180 |
containerManifestResources.add(mre); |
181 |
containerManifestResources.add(mre); |
181 |
} |
182 |
} |
182 |
} |
183 |
} |
Lines 187-193
Link Here
|
187 |
|
188 |
|
188 |
|
189 |
|
189 |
/** |
190 |
/** |
190 |
* Validates a <code>ArrayList</code> of <code>ManifestResource</code> |
191 |
* Validates a <code>Set</code> of <code>ManifestResource</code> |
191 |
* objects. This method requires an application name (which is the |
192 |
* objects. This method requires an application name (which is the |
192 |
* context root of the application at runtime). |
193 |
* context root of the application at runtime). |
193 |
* |
194 |
* |
Lines 206-220
Link Here
|
206 |
* @return true if manifest resource file requirements are met |
207 |
* @return true if manifest resource file requirements are met |
207 |
*/ |
208 |
*/ |
208 |
private static boolean validateManifestResources(String appName, |
209 |
private static boolean validateManifestResources(String appName, |
209 |
ArrayList<ManifestResource> resources) { |
210 |
Set<ManifestResource> resources) { |
210 |
boolean passes = true; |
211 |
boolean passes = true; |
211 |
int failureCount = 0; |
212 |
int failureCount = 0; |
212 |
ArrayList<Extension> availableExtensions = null; |
213 |
Set<Extension> availableExtensions = null; |
213 |
|
214 |
|
214 |
Iterator<ManifestResource> it = resources.iterator(); |
215 |
for (ManifestResource mre : resources) { |
215 |
while (it.hasNext()) { |
216 |
List<Extension> requiredList = mre.getRequiredExtensions(); |
216 |
ManifestResource mre = it.next(); |
|
|
217 |
ArrayList<Extension> requiredList = mre.getRequiredExtensions(); |
218 |
if (requiredList == null) { |
217 |
if (requiredList == null) { |
219 |
continue; |
218 |
continue; |
220 |
} |
219 |
} |
Lines 228-246
Link Here
|
228 |
// yet |
227 |
// yet |
229 |
if (containerAvailableExtensions == null) { |
228 |
if (containerAvailableExtensions == null) { |
230 |
containerAvailableExtensions |
229 |
containerAvailableExtensions |
231 |
= buildAvailableExtensionsList(containerManifestResources); |
230 |
= buildAvailableExtensionsList(containerManifestResources); |
232 |
} |
231 |
} |
233 |
|
232 |
|
234 |
// iterate through the list of required extensions |
233 |
// iterate through the list of required extensions |
235 |
Iterator<Extension> rit = requiredList.iterator(); |
234 |
for (Extension requiredExt : requiredList) { |
236 |
while (rit.hasNext()) { |
|
|
237 |
boolean found = false; |
235 |
boolean found = false; |
238 |
Extension requiredExt = rit.next(); |
236 |
|
239 |
// check the application itself for the extension |
237 |
// check the application itself for the extension |
240 |
if (availableExtensions != null) { |
238 |
if (availableExtensions != null) { |
241 |
Iterator<Extension> ait = availableExtensions.iterator(); |
239 |
for (Extension targetExt : availableExtensions) { |
242 |
while (ait.hasNext()) { |
|
|
243 |
Extension targetExt = ait.next(); |
244 |
if (targetExt.isCompatibleWith(requiredExt)) { |
240 |
if (targetExt.isCompatibleWith(requiredExt)) { |
245 |
requiredExt.setFulfilled(true); |
241 |
requiredExt.setFulfilled(true); |
246 |
found = true; |
242 |
found = true; |
Lines 248-259
Link Here
|
248 |
} |
244 |
} |
249 |
} |
245 |
} |
250 |
} |
246 |
} |
|
|
247 |
|
251 |
// check the container level list for the extension |
248 |
// check the container level list for the extension |
252 |
if (!found && containerAvailableExtensions != null) { |
249 |
if (!found && containerAvailableExtensions != null) { |
253 |
Iterator<Extension> cit = |
250 |
for (Extension targetExt : containerAvailableExtensions) { |
254 |
containerAvailableExtensions.iterator(); |
|
|
255 |
while (cit.hasNext()) { |
256 |
Extension targetExt = cit.next(); |
257 |
if (targetExt.isCompatibleWith(requiredExt)) { |
251 |
if (targetExt.isCompatibleWith(requiredExt)) { |
258 |
requiredExt.setFulfilled(true); |
252 |
requiredExt.setFulfilled(true); |
259 |
found = true; |
253 |
found = true; |
Lines 261-272
Link Here
|
261 |
} |
255 |
} |
262 |
} |
256 |
} |
263 |
} |
257 |
} |
|
|
258 |
|
264 |
if (!found) { |
259 |
if (!found) { |
265 |
// Failure |
260 |
// Failure |
266 |
log.info(sm.getString( |
261 |
log.info(sm.getString( |
267 |
"extensionValidator.extension-not-found-error", |
262 |
"extensionValidator.extension-not-found-error", |
268 |
appName, mre.getResourceName(), |
263 |
appName, mre.getResourceName(), |
269 |
requiredExt.getExtensionName())); |
264 |
requiredExt.getExtensionName())); |
270 |
passes = false; |
265 |
passes = false; |
271 |
failureCount++; |
266 |
failureCount++; |
272 |
} |
267 |
} |
Lines 299-323
Link Here
|
299 |
* |
294 |
* |
300 |
* @return HashMap Map of available extensions |
295 |
* @return HashMap Map of available extensions |
301 |
*/ |
296 |
*/ |
302 |
private static ArrayList<Extension> buildAvailableExtensionsList( |
297 |
private static Set<Extension> buildAvailableExtensionsList( |
303 |
ArrayList<ManifestResource> resources) { |
298 |
Set<ManifestResource> resources) { |
304 |
|
299 |
|
305 |
ArrayList<Extension> availableList = null; |
300 |
Set<Extension> availableList = null; |
306 |
|
301 |
|
307 |
Iterator<ManifestResource> it = resources.iterator(); |
302 |
for (ManifestResource mre : resources) { |
308 |
while (it.hasNext()) { |
303 |
List<Extension> list = mre.getAvailableExtensions(); |
309 |
ManifestResource mre = it.next(); |
|
|
310 |
ArrayList<Extension> list = mre.getAvailableExtensions(); |
311 |
if (list != null) { |
304 |
if (list != null) { |
312 |
Iterator<Extension> values = list.iterator(); |
305 |
for (Extension ext : list) { |
313 |
while (values.hasNext()) { |
|
|
314 |
Extension ext = values.next(); |
315 |
if (availableList == null) { |
306 |
if (availableList == null) { |
316 |
availableList = new ArrayList<>(); |
307 |
availableList = new HashSet<>(); |
317 |
availableList.add(ext); |
|
|
318 |
} else { |
319 |
availableList.add(ext); |
320 |
} |
308 |
} |
|
|
309 |
availableList.add(ext); |
321 |
} |
310 |
} |
322 |
} |
311 |
} |
323 |
} |
312 |
} |
Lines 332-338
Link Here
|
332 |
* @return The WAR's or JAR's manifest |
321 |
* @return The WAR's or JAR's manifest |
333 |
*/ |
322 |
*/ |
334 |
private static Manifest getManifest(InputStream inStream) throws IOException { |
323 |
private static Manifest getManifest(InputStream inStream) throws IOException { |
335 |
Manifest manifest = null; |
324 |
Manifest manifest; |
336 |
try (JarInputStream jin = new JarInputStream(inStream)) { |
325 |
try (JarInputStream jin = new JarInputStream(inStream)) { |
337 |
manifest = jin.getManifest(); |
326 |
manifest = jin.getManifest(); |
338 |
} |
327 |
} |
Lines 359-373
Link Here
|
359 |
if (files == null) { |
348 |
if (files == null) { |
360 |
continue; |
349 |
continue; |
361 |
} |
350 |
} |
362 |
for (int i = 0; i < files.length; i++) { |
351 |
|
363 |
if (files[i].getName().toLowerCase(Locale.ENGLISH).endsWith(".jar") && |
352 |
for (File file : files) { |
364 |
files[i].isFile()) { |
353 |
if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar") && |
|
|
354 |
file.isFile()) { |
365 |
try { |
355 |
try { |
366 |
addSystemResource(files[i]); |
356 |
addSystemResource(file); |
367 |
} catch (IOException e) { |
357 |
} catch (IOException e) { |
368 |
log.error |
358 |
log.error |
369 |
(sm.getString |
359 |
(sm.getString |
370 |
("extensionValidator.failload", files[i]), e); |
360 |
("extensionValidator.failload", file), e); |
371 |
} |
361 |
} |
372 |
} |
362 |
} |
373 |
} |
363 |
} |