use of org.hotswap.agent.util.spring.path.PathMatchingResourcePatternResolver in project HotswapAgent by HotswapProjects.
the class DeploymentInfo method fromClassLoader.
/**
* Load the deployment info for this classloader.
*
* @param classloader
* the ClassLoader
* @return the deployment info
*/
public static DeploymentInfo fromClassLoader(ClassLoader classloader) {
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(classloader);
Set<MavenInfo> maven = new LinkedHashSet<>();
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(classloader);
try {
Enumeration<URL> urls = classloader.getResources("META-INF/maven/");
while (urls.hasMoreElements()) {
URL u = urls.nextElement();
try {
Resource[] resources = resolver.getResources(u.toExternalForm() + "**/pom.properties");
if (resources != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("META-INF/maven/**/pom.properties FOUND:{}", Arrays.toString(resources));
}
for (Resource resource : resources) {
MavenInfo m = getMavenInfo(resource);
if (m != null) {
maven.add(m);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (IOException e) {
LOGGER.debug("Error trying to find maven properties", e);
}
return new DeploymentInfo(maven, getManifest(classloader));
} finally {
Thread.currentThread().setContextClassLoader(oldContextClassLoader);
}
}
use of org.hotswap.agent.util.spring.path.PathMatchingResourcePatternResolver in project HotswapAgent by HotswapProjects.
the class DeploymentInfo method getManifest.
/**
* Gets the manifest Info.
*
* @param classloader
* the ClassLoader
* @return the manifest
*/
public static Set<ManifestInfo> getManifest(ClassLoader classloader) {
Set<ManifestInfo> manifests = new LinkedHashSet<>();
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(classloader);
try {
Enumeration<URL> urls = classloader.getResources("META-INF/MANIFEST.MF");
while (urls.hasMoreElements()) {
URL u = urls.nextElement();
try {
Resource[] resources = resolver.getResources(u.toExternalForm());
if (resources != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("META-INF/MANIFEST.MF FOUND:\n" + Arrays.toString(resources));
}
for (Resource resource : resources) {
ManifestInfo m = getManifest(resource);
if (m != null) {
manifests.add(m);
}
}
}
} catch (Exception e) {
LOGGER.debug("Error trying to get manifest entries", e);
}
}
} catch (IOException e) {
LOGGER.debug("Error trying to get manifest entries", e);
}
return manifests;
}
Aggregations