Example usage for com.google.common.reflect ClassPath getResources

List of usage examples for com.google.common.reflect ClassPath getResources

Introduction

In this page you can find the example usage for com.google.common.reflect ClassPath getResources.

Prototype

public ImmutableSet<ResourceInfo> getResources() 

Source Link

Document

Returns all resources loadable from the current class path, including the class files of all loadable classes but excluding the "META-INF/MANIFEST.MF" file.

Usage

From source file:org.wisdom.test.internals.ClassPathResource.java

/**
 * Adds all the resources found in the given classpath to the given jar. Are excluded resources matching the
 * 'doNotCopy' pattern./* w  w  w  .j  a va2s  .  c o  m*/
 *
 * @param jar       the jar in which the resources are added
 * @param classpath the classpath
 * @param doNotCopy the do not copy pattern
 */
public static void build(Jar jar, ClassPath classpath, Pattern doNotCopy) {
    ImmutableSet<ClassPath.ResourceInfo> resources = classpath.getResources();
    for (ClassPath.ResourceInfo resource : resources) {
        if (doNotCopy != null && doNotCopy.matcher(resource.getResourceName()).matches()) {
            continue;
        }
        jar.putResource(resource.getResourceName(), new ClassPathResource(resource));
    }
}

From source file:com.phoenixnap.oss.ramlapisync.plugin.CommonApiSyncMojo.java

/**
 * Main entrypoint for raml generation//w w w.j  ava 2s . co  m
 * @throws MojoExecutionException Kaboom.
 * @throws MojoFailureException Kaboom.
 * @throws IOException Kaboom.
 */
protected void prepareRaml() throws MojoExecutionException, MojoFailureException, IOException {
    ClassLoaderUtils.addLocationsToClassLoader(project);
    List<String> targetPacks = ClassLoaderUtils.loadPackages(project);
    if (dependencyPackagesList != null && !dependencyPackagesList.isEmpty()) {
        targetPacks.addAll(dependencyPackagesList);
    }

    ClassPath classPath = ClassPath.from(Thread.currentThread().getContextClassLoader());
    for (String pack : targetPacks) {
        scanPack(pack, classPath);
    }

    for (ClassPath.ResourceInfo resourceInfo : classPath.getResources()) {
        if (resourceInfo.getResourceName().endsWith(documentationSuffix)) {
            try {
                documents.add(new ApiDocumentMetadata(resourceInfo, documentationSuffix));
                this.getLog().info("Adding Documentation File " + resourceInfo.getResourceName());
            } catch (Throwable ex) {
                this.getLog().warn("Skipping Resource: Unable to load" + resourceInfo.getResourceName(), ex);
            }
        }
    }

    ClassLoaderUtils.restoreOriginalClassLoader();
}