Search in sources :

Example 16 with ClassPath

use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.

the class DummyClassPathApp method main.

/**
 * The Main Method.
 *
 * @param args
 */
public static void main(String[] args) {
    try {
        ClassLoader classLoader = DummyClassPathApp.class.getClassLoader();
        ClassPath classPath;
        if (classLoader instanceof ContainerClassLoader) {
            classPath = ((ContainerClassLoader) classLoader).getClassPath();
        } else {
            classPath = ClassPath.ofSystem();
        }
        for (String path : classPath) {
            System.out.println(path);
        }
        Class.forName(args[0]);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) ContainerClassLoader(com.oracle.bedrock.runtime.java.container.ContainerClassLoader) ContainerClassLoader(com.oracle.bedrock.runtime.java.container.ContainerClassLoader)

Example 17 with ClassPath

use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.

the class ContainerClassLoaderTest method shouldLoadClassFromParentClassLoaderIfPackageIsInExcludedList.

/**
 * Ensure that the ContainerClassLoader can exclude packages when
 * loading classes.
 *
 * @throws Exception
 */
@Test
public void shouldLoadClassFromParentClassLoaderIfPackageIsInExcludedList() throws Exception {
    ClassPath classPath = ClassPath.ofClass(DummyParentLoadedClass.class);
    System.setProperty(ContainerClassLoader.PROPERTY_EXCLUDED_PACKAGES, "classloader.parent");
    ClassLoader loader = ContainerClassLoader.newInstance("Test", classPath, System.getProperties());
    Class<?> result = loader.loadClass(DummyParentLoadedClass.class.getCanonicalName());
    assertThat(result.getClassLoader(), not(sameInstance(loader)));
    assertThat(result.getCanonicalName(), is(DummyParentLoadedClass.class.getCanonicalName()));
    assertThat(result.equals(DummyParentLoadedClass.class), is(true));
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) DummyParentLoadedClass(classloader.parent.DummyParentLoadedClass) Test(org.junit.Test)

Example 18 with ClassPath

use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.

the class ContainerClassLoaderTest method shouldUseSpecifiedClassPath.

/**
 * Ensure that we can create a ContainerClassLoader using a
 * custom ClassPath.
 *
 * @throws Exception
 */
@Test
public void shouldUseSpecifiedClassPath() throws Exception {
    String pathElement1 = File.separator + "test1.jar";
    String pathElement2 = "test2.jar";
    ClassPath classPath = new ClassPath(pathElement1 + File.pathSeparator + pathElement2);
    ContainerClassLoader loader = ContainerClassLoader.newInstance("Test", classPath, System.getProperties());
    ClassPath loaderClassPath = loader.getClassPath();
    assertTrue(classPath.contains(pathElement1));
    assertTrue(classPath.contains(pathElement2));
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) Test(org.junit.Test)

Example 19 with ClassPath

use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.

the class ContainerClassLoaderTest method shouldNotBeAbleToLoadClassNotOnClassPath.

/**
 * Ensure that the ContainerClassLoader won't load a Class
 * from a ClassPath that doesn't contain the said Class, but the said Class
 * is available (ie: Class scoping and isolation)
 *
 * @throws Exception
 */
@Test(expected = ClassNotFoundException.class)
public void shouldNotBeAbleToLoadClassNotOnClassPath() throws Exception {
    ClassPath classPath = new ClassPath("test.jar");
    ClassLoader loader = ContainerClassLoader.newInstance("Test", classPath, System.getProperties());
    loader.loadClass(DummyClass.class.getCanonicalName());
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) DummyClass(classloader.child.DummyClass) Test(org.junit.Test)

Example 20 with ClassPath

use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.

the class TestClassesTest method shouldCreateTestClassesFromEmptyClassPath.

@Test
public void shouldCreateTestClassesFromEmptyClassPath() throws Exception {
    TestClasses testClasses = TestClasses.from(new ClassPath());
    Set<Class<?>> classes = testClasses.resolveTestClasses();
    assertThat(classes, is(notNullValue()));
    assertThat(classes.isEmpty(), is(true));
}
Also used : TestClasses(com.oracle.bedrock.testsupport.junit.options.TestClasses) ClassPath(com.oracle.bedrock.runtime.java.ClassPath) Test(org.junit.Test)

Aggregations

ClassPath (com.oracle.bedrock.runtime.java.ClassPath)29 Test (org.junit.Test)21 File (java.io.File)12 TestClasses (com.oracle.bedrock.testsupport.junit.options.TestClasses)10 AbstractJUnit4Test (com.oracle.bedrock.testsupport.junit.AbstractJUnit4Test)9 JUnit3Test (com.oracle.bedrock.testsupport.junit.JUnit3Test)9 JUnit4Test (com.oracle.bedrock.testsupport.junit.JUnit4Test)9 RunWithAnnotatedTest (com.oracle.bedrock.testsupport.junit.RunWithAnnotatedTest)9 OptionsByType (com.oracle.bedrock.OptionsByType)4 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)4 MetaClass (com.oracle.bedrock.runtime.MetaClass)4 JavaAgent (com.oracle.bedrock.runtime.java.options.JavaAgent)3 DummyClass (classloader.child.DummyClass)2 AvailablePortIterator (com.oracle.bedrock.runtime.network.AvailablePortIterator)2 JUnit3Suite (com.oracle.bedrock.testsupport.junit.JUnit3Suite)2 Capture (com.oracle.bedrock.util.Capture)2 LinkedHashSet (java.util.LinkedHashSet)2 DummyParentLoadedClass (classloader.parent.DummyParentLoadedClass)1 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)1 ContainerClassLoader (com.oracle.bedrock.runtime.java.container.ContainerClassLoader)1