org.reflections.vfs.Vfs Java Examples

The following examples show how to use org.reflections.vfs.Vfs. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TomcatClasspathScanHandler.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public Vfs.Dir createDir(final URL url) throws Exception {
    URLConnection urlConnection = url.openConnection();
    Class<?> theClass = warURLConnectionClass.get();
    if (urlConnection.getClass().equals(theClass)) {
        Object wrappedJarUrlConnection = getValue(
                makeAccessible(
                        theClass.getDeclaredField("wrappedJarUrlConnection")
                ),
                urlConnection
        );
        if (wrappedJarUrlConnection instanceof JarURLConnection) {
            return new ZipDir(((JarURLConnection) wrappedJarUrlConnection).getJarFile());
        }
    }
    return null;
}
 
Example #2
Source File: JndiInputDirTest.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void directory_traversal_is_working() throws Exception {
    JndiInputDir jndiInputDir = new JndiInputDir(goodURL);

    List<String> names = Lists.newArrayList();
    List<String> paths = Lists.newArrayList();

    for (Vfs.File file : jndiInputDir.getFiles()) {
        names.add(file.getName());
        paths.add(file.getRelativePath());

        if (file.getName().equals("AAA")) {
            assertThat(file.openInputStream()).isEqualTo(aaaInputStream);
        } else if (file.getName().equals("AB")) {
            assertThat(file.openInputStream()).isEqualTo(abInputStream);
        } else {
            fail("unexpected file " + file.getName());
        }
    }

    assertThat(names).isEqualTo(Lists.newArrayList("AAA", "AB"));
    assertThat(paths).isEqualTo(Lists.newArrayList("A/AA/AAA", "A/AB"));

    jndiInputDir.close();
}
 
Example #3
Source File: KernelManager.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
private KernelManager() {
    // Load Nuun and Reflections classes to force initialization of Vfs url types
    try {
        Class.forName(Vfs.class.getCanonicalName());
        Class.forName(AbstractClasspathScanner.class.getCanonicalName());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Cannot initialize the classpath scanning infrastructure", e);
    }

    // Save existing url types
    savedUrlTypes = Vfs.getDefaultUrlTypes();

    // Find all classpath scan handlers and add their Vfs url types
    List<Vfs.UrlType> urlTypes = new ArrayList<>();
    for (ClasspathScanHandler classpathScanHandler : ServiceLoader.load(ClasspathScanHandler.class)) {
        LOGGER.debug("Classpath handler {} detected", classpathScanHandler.getClass().getCanonicalName());
        urlTypes.addAll(classpathScanHandler.urlTypes());
    }
    LOGGER.debug("Supported URL types for scanning: {}", urlTypes);
    detectedUrlTypes = urlTypes;
}
 
Example #4
Source File: FallbackUrlType.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public Vfs.Dir createDir(final URL url) {
    return new Vfs.Dir() {

        @Override
        public String getPath() {
            return url.getPath();
        }

        @Override
        public Iterable<Vfs.File> getFiles() {
            failedUrls.add(url.toExternalForm());
            return new ArrayList<>();
        }

        @Override
        public void close() {
            // nothing to do
        }
    };
}
 
Example #5
Source File: TomcatClasspathScanHandler.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public List<Vfs.UrlType> urlTypes() {
    return Lists.newArrayList(
            new TomcatWarFileUrlType(),
            new TomcatJndiJarUrlType(),
            new TomcatJndiFileUrlType()
    );
}
 
Example #6
Source File: WebsphereClasspathScanHandlerTest.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testUrlTypes(@SuppressWarnings("unused") @Mocked final WsInputDir wsInputDir) throws Exception {
    WebsphereClasspathScanHandler handler = new WebsphereClasspathScanHandler();
    List<Vfs.UrlType> list = handler.urlTypes();
    Assertions.assertThat(list.size()).isEqualTo(1);
    Vfs.UrlType urlType = list.get(0);

    URLStreamHandler goodStubUrlHandler = new URLStreamHandler() {
        @Override
        protected URLConnection openConnection(URL u) {
            return null;
        }
    };

    final URL warURL = new URL("wsjar", "", -1, "file:C/test.war", goodStubUrlHandler);
    final URL warJarURL = new URL("wsjar", "", -1, "file:C/test.war!test.jar", goodStubUrlHandler);
    final URL badURL = new URL("jar", "", -1, "file:C/test.war");
    Assertions.assertThat(urlType.matches(warURL)).isTrue();
    Assertions.assertThat(urlType.matches(badURL)).isFalse();
    Assertions.assertThat(urlType.matches(warJarURL)).isFalse();

    urlType.createDir(warURL);
    new Verifications() {
        {
            new WsInputDir(warURL);
            times = 1;
        }
    };
}
 
Example #7
Source File: KernelManager.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
private synchronized Kernel createKernel(KernelConfiguration kernelConfiguration,
        DiagnosticManager diagnosticManager) {
    // Kernel instantiation
    Kernel kernel = NuunCore.createKernel(kernelConfiguration);
    FallbackUrlType fallbackUrlType = new FallbackUrlType();
    List<Vfs.UrlType> urlTypes = new ArrayList<>(detectedUrlTypes);
    urlTypes.add(fallbackUrlType);

    // Kernel initialization (it is assumed that only this class alter Vfs default url types)
    Vfs.setDefaultURLTypes(urlTypes);
    kernel.init();
    Vfs.setDefaultURLTypes(savedUrlTypes);

    // Log if any URL were not scanned
    int failedUrlCount = fallbackUrlType.getFailedUrls().size();
    if (failedUrlCount > 0) {
        for (String failedUrl : fallbackUrlType.getFailedUrls()) {
            LOGGER.warn("Could not scan URL: {}", failedUrl);
        }
    }

    diagnosticManager.registerDiagnosticInfoCollector("kernel", () -> {
        Map<String, Object> result = new HashMap<>();
        result.put("scannedUrls", kernel.scannedURLs());
        result.put("failedUrls", fallbackUrlType.getFailedUrls());
        return result;
    });

    return kernel;
}
 
Example #8
Source File: BaseClasspathScanHandler.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public List<Vfs.UrlType> urlTypes() {
    return Lists.newArrayList(
            Vfs.DefaultUrlTypes.jarFile,
            Vfs.DefaultUrlTypes.jarUrl,
            Vfs.DefaultUrlTypes.directory,
            Vfs.DefaultUrlTypes.jarInputStream
    );
}
 
Example #9
Source File: TomcatClasspathScanHandler.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Vfs.Dir createDir(final URL url) {
    return new JndiJarInputDir(url);
}
 
Example #10
Source File: TomcatClasspathScanHandler.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Vfs.Dir createDir(final URL url) {
    return new JndiInputDir(url);
}
 
Example #11
Source File: WebsphereClasspathScanHandler.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public List<Vfs.UrlType> urlTypes() {
    return Lists.newArrayList(new WebSphereJarUrlType());
}
 
Example #12
Source File: WebsphereClasspathScanHandler.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Vfs.Dir createDir(final URL url) {
    return new WsInputDir(url);
}
 
Example #13
Source File: ClasspathScanHandler.java    From seed with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * @return the list of supported {@link Vfs.UrlType}.
 */
List<Vfs.UrlType> urlTypes();