Search in sources :

Example 1 with LocalLocationFactory

use of com.continuuity.weave.filesystem.LocalLocationFactory in project weave by continuuity.

the class ApplicationBundlerTest method testFindDependencies.

@Test
public void testFindDependencies() throws IOException, ClassNotFoundException {
    Location location = new LocalLocationFactory(tmpDir.newFolder()).create("test.jar");
    // Create a jar file with by tracing dependency
    ApplicationBundler bundler = new ApplicationBundler(ImmutableList.<String>of());
    bundler.createBundle(location, ApplicationBundler.class);
    File targetDir = tmpDir.newFolder();
    unjar(new File(location.toURI()), targetDir);
    // Load the class back, it should be loaded by the custom classloader
    ClassLoader classLoader = createClassLoader(targetDir);
    Class<?> clz = classLoader.loadClass(ApplicationBundler.class.getName());
    Assert.assertSame(classLoader, clz.getClassLoader());
    // For system classes, they shouldn't be packaged, hence loaded by different classloader.
    clz = classLoader.loadClass(Object.class.getName());
    Assert.assertNotSame(classLoader, clz.getClassLoader());
}
Also used : URLClassLoader(java.net.URLClassLoader) LocalLocationFactory(com.continuuity.weave.filesystem.LocalLocationFactory) ApplicationBundler(com.continuuity.weave.internal.ApplicationBundler) File(java.io.File) Location(com.continuuity.weave.filesystem.Location) Test(org.junit.Test)

Aggregations

LocalLocationFactory (com.continuuity.weave.filesystem.LocalLocationFactory)1 Location (com.continuuity.weave.filesystem.Location)1 ApplicationBundler (com.continuuity.weave.internal.ApplicationBundler)1 File (java.io.File)1 URLClassLoader (java.net.URLClassLoader)1 Test (org.junit.Test)1