use of org.apache.catalina.WebResourceSet in project tomee by apache.
the class TomcatWebAppBuilder method configuredClasspath.
private static DeploymentLoader.ExternalConfiguration configuredClasspath(final StandardContext standardContext) {
Loader loader = standardContext.getLoader();
if (loader != null && LazyStopLoader.class.isInstance(loader)) {
loader = LazyStopLoader.class.cast(loader).getDelegateLoader();
}
if (loader != null) {
final ClassLoader cl = standardContext.getLoader().getClassLoader();
if (cl == null) {
return null;
}
final Collection<String> cp = new LinkedList<>();
final WebResourceRoot webResources = standardContext.getResources();
if (webResources != null) {
// to enhance
for (final WebResourceSet[] sets : asList(webResources.getPreResources(), webResources.getPostResources(), webResources.getJarResources())) {
for (final WebResourceSet wr : sets) {
final URL base = wr.getBaseUrl();
if (base != null) {
final File baseFile = URLs.toFile(base);
if (baseFile.isDirectory()) {
final String[] libs = wr.list("/WEB-INF/lib/");
if (libs != null) {
for (final String resource : libs) {
cp.add(new File(baseFile, resource).getAbsolutePath());
}
}
final WebResource classes = wr.getResource("/WEB-INF/classes/");
if (classes != null) {
final String path = classes.getCanonicalPath();
if (path != null) {
cp.add(path);
}
}
} else if (baseFile.exists() && baseFile.getName().endsWith(".jar") && wr.getResource("/WEB-INF/classes/").exists()) {
try {
cp.add(baseFile.getCanonicalPath());
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}
}
}
}
}
if (!cp.isEmpty()) {
return new DeploymentLoader.ExternalConfiguration(cp.toArray(new String[cp.size()]), null);
}
}
return null;
}
Aggregations