Search in sources :

Example 1 with PathMatchingResourcePatternResolver

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Resource(org.hotswap.agent.util.spring.io.resource.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.hotswap.agent.util.spring.path.PathMatchingResourcePatternResolver) URL(java.net.URL) IOException(java.io.IOException)

Example 2 with PathMatchingResourcePatternResolver

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Resource(org.hotswap.agent.util.spring.io.resource.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.hotswap.agent.util.spring.path.PathMatchingResourcePatternResolver) URL(java.net.URL) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 URL (java.net.URL)2 LinkedHashSet (java.util.LinkedHashSet)2 Resource (org.hotswap.agent.util.spring.io.resource.Resource)2 PathMatchingResourcePatternResolver (org.hotswap.agent.util.spring.path.PathMatchingResourcePatternResolver)2