Search in sources :

Example 21 with URLClassLoader

use of java.net.URLClassLoader in project jetty.project by eclipse.

the class ContextHandler method getClassPath.

/* ------------------------------------------------------------ */
/**
     * Make best effort to extract a file classpath from the context classloader
     *
     * @return Returns the classLoader.
     */
@ManagedAttribute("The file classpath")
public String getClassPath() {
    if (_classLoader == null || !(_classLoader instanceof URLClassLoader))
        return null;
    URLClassLoader loader = (URLClassLoader) _classLoader;
    URL[] urls = loader.getURLs();
    StringBuilder classpath = new StringBuilder();
    for (int i = 0; i < urls.length; i++) {
        try {
            Resource resource = newResource(urls[i]);
            File file = resource.getFile();
            if (file != null && file.exists()) {
                if (classpath.length() > 0)
                    classpath.append(File.pathSeparatorChar);
                classpath.append(file.getAbsolutePath());
            }
        } catch (IOException e) {
            LOG.debug(e);
        }
    }
    if (classpath.length() == 0)
        return null;
    return classpath.toString();
}
Also used : URLClassLoader(java.net.URLClassLoader) Resource(org.eclipse.jetty.util.resource.Resource) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) ManagedAttribute(org.eclipse.jetty.util.annotation.ManagedAttribute)

Example 22 with URLClassLoader

use of java.net.URLClassLoader in project zeppelin by apache.

the class DepInterpreter method classPath.

private List<File> classPath(ClassLoader cl) {
    List<File> paths = new LinkedList<>();
    if (cl == null) {
        return paths;
    }
    if (cl instanceof URLClassLoader) {
        URLClassLoader ucl = (URLClassLoader) cl;
        URL[] urls = ucl.getURLs();
        if (urls != null) {
            for (URL url : urls) {
                paths.add(new File(url.getFile()));
            }
        }
    }
    return paths;
}
Also used : URLClassLoader(java.net.URLClassLoader) File(java.io.File) LinkedList(java.util.LinkedList) URL(java.net.URL)

Example 23 with URLClassLoader

use of java.net.URLClassLoader in project hadoop by apache.

the class TestEntityGroupFSTimelineStore method testPluginRead.

@Test
public void testPluginRead() throws Exception {
    // Verify precondition
    assertEquals(EntityGroupPlugInForTest.class.getName(), store.getConfig().get(YarnConfiguration.TIMELINE_SERVICE_ENTITY_GROUP_PLUGIN_CLASSES));
    List<TimelineEntityGroupPlugin> currPlugins = store.getPlugins();
    for (TimelineEntityGroupPlugin plugin : currPlugins) {
        ClassLoader pluginClassLoader = plugin.getClass().getClassLoader();
        assertTrue("Should set up ApplicationClassLoader", pluginClassLoader instanceof ApplicationClassLoader);
        URL[] paths = ((URLClassLoader) pluginClassLoader).getURLs();
        boolean foundJAR = false;
        for (URL path : paths) {
            if (path.toString().contains(testJar.getAbsolutePath())) {
                foundJAR = true;
            }
        }
        assertTrue("Not found path " + testJar.getAbsolutePath() + " for plugin " + plugin.getClass().getName(), foundJAR);
    }
    // Load data and cache item, prepare timeline store by making a cache item
    EntityGroupFSTimelineStore.AppLogs appLogs = store.new AppLogs(mainTestAppId, mainTestAppDirPath, AppState.COMPLETED);
    EntityCacheItem cacheItem = new EntityCacheItem(EntityGroupPlugInForTest.getStandardTimelineGroupId(mainTestAppId), config);
    cacheItem.setAppLogs(appLogs);
    store.setCachedLogs(EntityGroupPlugInForTest.getStandardTimelineGroupId(mainTestAppId), cacheItem);
    MutableCounterLong detailLogEntityRead = store.metrics.getGetEntityToDetailOps();
    MutableStat cacheRefresh = store.metrics.getCacheRefresh();
    long numEntityReadBefore = detailLogEntityRead.value();
    long cacheRefreshBefore = cacheRefresh.lastStat().numSamples();
    // Generate TDM
    TimelineDataManager tdm = PluginStoreTestUtils.getTdmWithStore(config, store);
    // Verify single entity read
    TimelineEntity entity3 = tdm.getEntity("type_3", mainTestAppId.toString(), EnumSet.allOf(TimelineReader.Field.class), UserGroupInformation.getLoginUser());
    assertNotNull(entity3);
    assertEquals(entityNew.getStartTime(), entity3.getStartTime());
    // Verify multiple entities read
    NameValuePair primaryFilter = new NameValuePair(EntityGroupPlugInForTest.APP_ID_FILTER_NAME, mainTestAppId.toString());
    TimelineEntities entities = tdm.getEntities("type_3", primaryFilter, null, null, null, null, null, null, EnumSet.allOf(TimelineReader.Field.class), UserGroupInformation.getLoginUser());
    assertEquals(1, entities.getEntities().size());
    for (TimelineEntity entity : entities.getEntities()) {
        assertEquals(entityNew.getStartTime(), entity.getStartTime());
    }
    // Verify metrics
    assertEquals(numEntityReadBefore + 2L, detailLogEntityRead.value());
    assertEquals(cacheRefreshBefore + 1L, cacheRefresh.lastStat().numSamples());
}
Also used : MutableCounterLong(org.apache.hadoop.metrics2.lib.MutableCounterLong) MutableStat(org.apache.hadoop.metrics2.lib.MutableStat) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) ApplicationClassLoader(org.apache.hadoop.util.ApplicationClassLoader) URL(java.net.URL) TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) URLClassLoader(java.net.URLClassLoader) ApplicationClassLoader(org.apache.hadoop.util.ApplicationClassLoader) URLClassLoader(java.net.URLClassLoader) Test(org.junit.Test)

Example 24 with URLClassLoader

use of java.net.URLClassLoader in project hive by apache.

the class MetaStoreUtils method addToClassPath.

/**
   * Add new elements to the classpath.
   *
   * @param newPaths
   *          Array of classpath elements
   */
public static ClassLoader addToClassPath(ClassLoader cloader, String[] newPaths) throws Exception {
    URLClassLoader loader = (URLClassLoader) cloader;
    List<URL> curPath = Arrays.asList(loader.getURLs());
    ArrayList<URL> newPath = new ArrayList<URL>();
    // get a list with the current classpath components
    for (URL onePath : curPath) {
        newPath.add(onePath);
    }
    curPath = newPath;
    for (String onestr : newPaths) {
        URL oneurl = urlFromPathString(onestr);
        if (oneurl != null && !curPath.contains(oneurl)) {
            curPath.add(oneurl);
        }
    }
    return new URLClassLoader(curPath.toArray(new URL[0]), loader);
}
Also used : URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) URL(java.net.URL)

Example 25 with URLClassLoader

use of java.net.URLClassLoader in project zeppelin by apache.

the class FlinkInterpreter method classPath.

private List<File> classPath(ClassLoader cl) {
    List<File> paths = new LinkedList<>();
    if (cl == null) {
        return paths;
    }
    if (cl instanceof URLClassLoader) {
        URLClassLoader ucl = (URLClassLoader) cl;
        URL[] urls = ucl.getURLs();
        if (urls != null) {
            for (URL url : urls) {
                paths.add(new File(url.getFile()));
            }
        }
    }
    return paths;
}
Also used : URLClassLoader(java.net.URLClassLoader) File(java.io.File) URL(java.net.URL)

Aggregations

URLClassLoader (java.net.URLClassLoader)1351 URL (java.net.URL)872 File (java.io.File)514 Test (org.junit.Test)317 IOException (java.io.IOException)256 ArrayList (java.util.ArrayList)202 MalformedURLException (java.net.MalformedURLException)186 Method (java.lang.reflect.Method)177 InvocationTargetException (java.lang.reflect.InvocationTargetException)68 JarFile (java.util.jar.JarFile)54 InputStream (java.io.InputStream)50 HashSet (java.util.HashSet)49 HashMap (java.util.HashMap)44 URISyntaxException (java.net.URISyntaxException)41 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)35 Path (java.nio.file.Path)33 QuickTest (com.hazelcast.test.annotation.QuickTest)32 Test (org.junit.jupiter.api.Test)28 URI (java.net.URI)27 List (java.util.List)27