/** returns the base directory or JAR from which the context is class-loaded, if possible; * throws exception if not found */ public String getClassLoaderDir() { if (contextObject==null) throw new IllegalArgumentException("No suitable context ("+context+") to auto-detect classloader dir"); Class<?> cc = contextObject instanceof Class ? (Class<?>)contextObject : contextObject.getClass(); return getClassLoaderDir(cc.getCanonicalName().replace('.', '/')+".class"); }
@Test(expectedExceptions={NoSuchElementException.class}) public void testClassLoaderDirNotFound() throws Exception { String d = utils.getClassLoaderDir("/somewhere/not/found/XXX.xxx"); // above should fail log.warn("Uh oh found imaginary resource in: "+d); }
@Test public void testClassLoaderDirFromJarWithSlash() throws Exception { String d = utils.getClassLoaderDir("/java/lang/Object.class"); log.info("Found Object in: "+d); assertTrue(d.toLowerCase().endsWith(".jar")); }
@Test public void testClassLoaderDir() throws Exception { String d = utils.getClassLoaderDir(); log.info("Found resource "+this+" in: "+d); assertTrue(new File(d, "brooklyn/util/").exists()); }
@Test public void testClassLoaderDirFromJar() throws Exception { String d = utils.getClassLoaderDir("java/lang/Object.class"); log.info("Found Object in: "+d); assertTrue(d.toLowerCase().endsWith(".jar")); }
@BeforeMethod(alwaysRun = true) public void setUp() throws Exception { if (BROOKLYN_THIS_CLASSPATH==null) { BROOKLYN_THIS_CLASSPATH = ResourceUtils.create(MAIN_CLASS).getClassLoaderDir(); } app = TestApplication.Factory.newManagedInstanceForTests(); loc = app.newLocalhostProvisioningLocation(MutableMap.of("address", "localhost")); }
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { mementoDir = Files.createTempDir(); managementContext = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader); if (BROOKLYN_THIS_CLASSPATH==null) { BROOKLYN_THIS_CLASSPATH = ResourceUtils.create(MAIN_CLASS).getClassLoaderDir(); } app = TestApplication.Factory.newManagedInstanceForTests(managementContext); loc = app.newLocalhostProvisioningLocation(MutableMap.of("address", "localhost")); }
new File(Os.mergePaths(ResourceUtils.create(this).getClassLoaderDir(), "org/apache/brooklyn/entity/messaging/storm/topologies")), "org/apache/brooklyn/entity/messaging/storm/"); System.setProperty("storm.jar", jar);