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();
}
}
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));
}
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));
}
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());
}
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));
}
Aggregations