Example usage for java.util.jar JarFile JarFile

List of usage examples for java.util.jar JarFile JarFile

Introduction

In this page you can find the example usage for java.util.jar JarFile JarFile.

Prototype

public JarFile(File file) throws IOException 

Source Link

Document

Creates a new JarFile to read from the specified File object.

Usage

From source file:org.codehaus.mojo.nbm.CreateWebstartAppMojo.java

/**
 * copied from MakeMasterJNLP ant task.//from  w w  w  .  j a  va  2 s . co m
 * @param files
 * @param antProject
 * @param masterPrefix
 * @return
 * @throws java.io.IOException
 */
private String generateExtensions(FileSet files, Project antProject, String masterPrefix) throws IOException {
    StringBuilder buff = new StringBuilder();
    for (String nm : files.getDirectoryScanner(antProject).getIncludedFiles()) {
        File jar = new File(files.getDir(antProject), nm);

        if (!jar.canRead()) {
            throw new IOException("Cannot read file: " + jar);
        }

        try (JarFile theJar = new JarFile(jar)) {
            String codenamebase = theJar.getManifest().getMainAttributes().getValue("OpenIDE-Module");
            if (codenamebase == null) {
                throw new IOException("Not a NetBeans Module: " + jar);
            }
            {
                int slash = codenamebase.indexOf('/');
                if (slash >= 0) {
                    codenamebase = codenamebase.substring(0, slash);
                }
            }
            String dashcnb = codenamebase.replace('.', '-');

            buff.append("    <extension name='").append(codenamebase).append("' href='").append(masterPrefix)
                    .append(dashcnb).append(".jnlp' />\n");
        }
    }
    return buff.toString();

}

From source file:ml.shifu.shifu.ShifuCLI.java

/**
 * print version info for shifu/*from w w w  .ja  va 2s .  com*/
 */
private static void printLogoAndVersion() {
    String findContainingJar = JarManager.findContainingJar(ShifuCLI.class);
    JarFile jar = null;
    try {
        jar = new JarFile(findContainingJar);
        final Manifest manifest = jar.getManifest();

        String vendor = manifest.getMainAttributes().getValue("vendor");
        String title = manifest.getMainAttributes().getValue("title");
        String version = manifest.getMainAttributes().getValue("version");
        String timestamp = manifest.getMainAttributes().getValue("timestamp");
        System.out.println(" ____  _   _ ___ _____ _   _ ");
        System.out.println("/ ___|| | | |_ _|  ___| | | |");
        System.out.println("\\___ \\| |_| || || |_  | | | |");
        System.out.println(" ___) |  _  || ||  _| | |_| |");
        System.out.println("|____/|_| |_|___|_|    \\___/ ");
        System.out.println("                             ");
        System.out.println(vendor + " " + title + " version " + version + " \ncompiled " + timestamp);
    } catch (Exception e) {
        throw new RuntimeException("unable to read pigs manifest file", e);
    } finally {
        if (jar != null) {
            try {
                jar.close();
            } catch (IOException e) {
                throw new RuntimeException("jar closed failed", e);
            }
        }
    }
}

From source file:com.redhat.ceylon.compiler.java.test.cmr.CMRTests.java

@Test
public void testMdlSourceArchive() throws IOException {
    File sourceArchiveFile = getSourceArchive("com.redhat.ceylon.compiler.java.test.cmr.modules.single",
            "6.6.6");
    sourceArchiveFile.delete();/*  ww w  .j av a  2 s  . com*/
    assertFalse(sourceArchiveFile.exists());

    // compile one file
    compile("modules/single/module.ceylon");

    // make sure it was created
    assertTrue(sourceArchiveFile.exists());

    JarFile sourceArchive = new JarFile(sourceArchiveFile);
    assertEquals(2, countEntries(sourceArchive));

    ZipEntry moduleClass = sourceArchive
            .getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/single/module.ceylon");
    assertNotNull(moduleClass);

    ZipEntry moduleClassDir = sourceArchive
            .getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/single/");
    assertNotNull(moduleClassDir);
    sourceArchive.close();

    // now compile another file
    compile("modules/single/subpackage/Subpackage.ceylon");

    // MUST reopen it
    sourceArchive = new JarFile(sourceArchiveFile);
    assertEquals(4, countEntries(sourceArchive));

    ZipEntry subpackageClass = sourceArchive
            .getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/single/subpackage/Subpackage.ceylon");
    assertNotNull(subpackageClass);
    ZipEntry subpackageClassDir = sourceArchive
            .getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/single/subpackage/");
    assertNotNull(subpackageClassDir);

    sourceArchive.close();
}

From source file:org.apache.axis2.wsdl.util.WSDLWrapperReloadImpl.java

private static URL getURLFromJAR(URLClassLoader urlLoader, URL relativeURL) throws WSDLException {

    URL[] urlList = urlLoader.getURLs();

    if (urlList == null) {
        return null;
    }//from   w  w w  .  ja  v  a  2 s . co m

    for (int i = 0; i < urlList.length; i++) {
        URL url = urlList[i];

        if (url == null) {
            return null;
        }

        if ("file".equals(url.getProtocol())) {

            File f = new File(url.getPath());

            //If file is not of type directory then its a jar file
            if (f.exists() && !f.isDirectory()) {
                try {
                    JarFile jf = new JarFile(f);
                    Enumeration entries = jf.entries();
                    // read all entries in jar file and return the first 
                    // wsdl file that matches the relative path
                    while (entries.hasMoreElements()) {
                        JarEntry je = (JarEntry) entries.nextElement();
                        String name = je.getName();
                        if (name.endsWith(".wsdl")) {
                            String relativePath = relativeURL.getPath();
                            if (relativePath.endsWith(name)) {
                                String path = f.getAbsolutePath();

                                // This check is necessary because Unix/Linux file paths begin
                                // with a '/'. When adding the prefix 'jar:file:/' we may end
                                // up with '//' after the 'file:' part. This causes the URL 
                                // object to treat this like a remote resource
                                if (path != null && path.indexOf("/") == 0) {
                                    path = path.substring(1, path.length());
                                }

                                URL absoluteUrl = new URL("jar:file:/" + path + "!/" + je.getName());
                                return absoluteUrl;
                            }
                        }
                    }
                } catch (Exception e) {
                    WSDLException we = new WSDLException("WSDLWrapperReloadImpl : ", e.getMessage(), e);
                    throw we;
                }
            }
        }
    }

    return null;
}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.JavaAutConfigComponent.java

/**
 * The action of the working directory field.
 * @return <code>null</code> if the new value is valid. Otherwise, returns
 *         a status parameter indicating the cause of the problem.
 *//*w  w  w  . j a  va2  s .c  om*/
DialogStatusParameter modifyExecTextField() {
    DialogStatusParameter error = null;
    m_isExecFieldValid = true;
    isExecFieldEmpty = m_execTextField.getText().length() == 0;
    String filename = m_execTextField.getText();
    if (isValid(m_execTextField, true) && !isExecFieldEmpty) {
        if (checkLocalhostServer()) {
            File file = new File(filename);
            if (!file.isAbsolute()) {
                String workingDirString = getConfigValue(AutConfigConstants.WORKING_DIR);
                if (workingDirString != null && workingDirString.length() != 0) {

                    filename = workingDirString + "/" + filename; //$NON-NLS-1$
                    file = new File(filename);
                }
            }

            try {
                if (!file.isFile()) {
                    error = createWarningStatus(
                            NLS.bind(Messages.AUTConfigComponentFileNotFound, file.getCanonicalPath()));
                } else {
                    // Make sure that the user has not entered an executable
                    // JAR file in the wrong field.
                    new JarFile(file);
                    error = createErrorStatus(
                            NLS.bind(Messages.AUTConfigComponentFileJar, file.getCanonicalPath()));
                }
            } catch (ZipException ze) {
                // Expected. This occurs if the given file exists but is not 
                // a JAR file.
            } catch (IOException e) {
                // could not find file
                error = createWarningStatus(NLS.bind(Messages.AUTConfigComponentFileNotFound, filename));
            }
        }
    } else if (!isExecFieldEmpty) {
        error = createErrorStatus(Messages.AUTConfigComponentWrongExecutable);
    }
    if (error != null) {
        m_isExecFieldValid = false;
    }
    putConfigValue(AutConfigConstants.EXECUTABLE, m_execTextField.getText());
    executablePath = filename;

    return error;
}

From source file:org.apache.catalina.loader.WebappClassLoader.java

/**
 * Used to periodically signal to the classloader to release JAR resources.
 *///from   w  ww.j a  v a  2 s. c  o m
protected void openJARs() {
    if (started && (jarFiles.length > 0)) {
        lastJarAccessed = System.currentTimeMillis();
        if (jarFiles[0] == null) {
            try {
                for (int i = 0; i < jarFiles.length; i++) {
                    jarFiles[i] = new JarFile(jarRealFiles[i]);
                }
            } catch (IOException e) {
                log("Failed to open JAR", e);
            }
        }
    }
}

From source file:com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.java

/**
 * Check whether the artifact includes a BuildConfig located in a given package.
 * //from  w w w  .  ja  va2 s.  co m
 * @param artifact an AAR artifact to look for BuildConfig in
 * @param packageName BuildConfig package name
 * @throws MojoExecutionException
 */
private boolean isBuildConfigPresent(Artifact artifact, String packageName) throws MojoExecutionException {
    try {
        JarFile jar = new JarFile(getUnpackedAarClassesJar(artifact));
        JarEntry entry = jar.getJarEntry(packageName.replace('.', '/') + "/BuildConfig.class");

        return (entry != null);
    } catch (IOException e) {
        getLog().error("Error generating BuildConfig ", e);
        throw new MojoExecutionException("Error generating BuildConfig", e);
    }
}

From source file:adept.io.Reader.java

/**
 * List directory contents for a resource folder. Not recursive.
 * This is basically a brute-force implementation.
 * Works for regular files and also JARs.
 *
 * @param clazz Any java class that lives in the same place as the resources you want.
 * @param path  Should end with "/", but not start with one.
 * @return Just the name of each member item, not the full paths.
 * @throws URISyntaxException the uRI syntax exception
 * @throws IOException        Signals that an I/O exception has occurred.
 * @author Greg Briggs//  ww  w.  ja  v  a 2s .  co  m
 */
public static String[] getResourceListing(Class clazz, String path) throws URISyntaxException, IOException {

    URL dirURL = clazz.getClassLoader().getResource(path);
    if (dirURL != null && dirURL.getProtocol().equals("file")) {
        /* A file path: easy enough */
        return new File(dirURL.toURI()).list();
    }

    if (dirURL == null) {
        /* 
         * In case of a jar file, we can't actually find a directory.
         * Have to assume the same jar as clazz.
         */
        String me = clazz.getName().replace(".", "/") + ".class";
        dirURL = clazz.getClassLoader().getResource(me);
    }

    if (dirURL.getProtocol().equals("jar")) {
        /* A JAR path */
        String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); //strip out only the JAR file
        JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
        Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
        Set<String> result = new HashSet<String>(); //avoid duplicates in case it is a subdirectory
        while (entries.hasMoreElements()) {
            String name = entries.nextElement().getName();
            if (name.startsWith(path)) { //filter according to the path
                String entry = name.substring(path.length());
                int checkSubdir = entry.indexOf("/");
                if (checkSubdir >= 0) {
                    // if it is a subdirectory, we just return the directory name
                    entry = entry.substring(0, checkSubdir);
                }
                result.add(entry);
            }
        }
        return result.toArray(new String[result.size()]);
    }

    throw new UnsupportedOperationException("Cannot list files for URL " + dirURL);
}

From source file:com.jivesoftware.os.upena.deployable.UpenaMain.java

private void injectUI(String upenaVersion, AWSClientFactory awsClientFactory, ObjectMapper storeMapper,
        ObjectMapper mapper, JDIAPI jvmapi, AmzaService amzaService, PathToRepo localPathToRepo,
        RepositoryProvider repositoryProvider, HostKey hostKey, UpenaRingHost ringHost,
        UpenaSSLConfig upenaSSLConfig, int port, SessionStore sessionStore, UbaService ubaService,
        UpenaHealth upenaHealth, UpenaStore upenaStore, UpenaConfigStore upenaConfigStore,
        UpenaJerseyEndpoints jerseyEndpoints, String humanReadableUpenaClusterName,
        DiscoveredRoutes discoveredRoutes) throws SoySyntaxException, IOException {

    SoyFileSet.Builder soyFileSetBuilder = new SoyFileSet.Builder();

    LOG.info("Add....");

    URL dirURL = UpenaMain.class.getClassLoader().getResource("resources/soy/");
    if (dirURL != null && dirURL.getProtocol().equals("jar")) {
        String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!"));
        JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
        Enumeration<JarEntry> entries = jar.entries();
        while (entries.hasMoreElements()) {
            String name = entries.nextElement().getName();
            if (name.endsWith(".soy") && name.startsWith("resources/soy/")) {
                String soyName = name.substring(name.lastIndexOf('/') + 1);
                LOG.info("/" + name + " " + soyName);
                soyFileSetBuilder.add(this.getClass().getResource("/" + name), soyName);
            }/*from w w w . ja  v  a 2  s  .co  m*/
        }
    } else {
        List<String> soyFiles = IOUtils.readLines(this.getClass().getResourceAsStream("resources/soy/"),
                StandardCharsets.UTF_8);
        for (String soyFile : soyFiles) {
            LOG.info("Adding {}", soyFile);
            soyFileSetBuilder.add(this.getClass().getResource("/resources/soy/" + soyFile), soyFile);
        }
    }

    SoyFileSet sfs = soyFileSetBuilder.build();
    SoyTofu tofu = sfs.compileToTofu();
    SoyRenderer renderer = new SoyRenderer(tofu, new SoyDataUtils());
    SoyService soyService = new SoyService(upenaVersion, renderer,
            //new HeaderRegion("soy.upena.chrome.headerRegion", renderer),
            new MenuRegion("soy.upena.chrome.menuRegion", renderer),
            new HomeRegion("soy.upena.page.homeRegion", renderer, hostKey, upenaStore, ubaService),
            humanReadableUpenaClusterName, hostKey, upenaStore);

    AuthPluginRegion authRegion = new AuthPluginRegion("soy.upena.page.authPluginRegion", renderer);
    OktaMFAAuthPluginRegion oktaMFAAuthRegion = new OktaMFAAuthPluginRegion(
            "soy.upena.page.oktaMFAAuthPluginRegion", renderer);
    jerseyEndpoints.addInjectable(OktaMFAAuthPluginRegion.class, oktaMFAAuthRegion);

    UnauthorizedPluginRegion unauthorizedRegion = new UnauthorizedPluginRegion(
            "soy.upena.page.unauthorizedPluginRegion", renderer);

    PluginHandle auth = new PluginHandle("login", null, "Login", "/ui/auth/login", AuthPluginEndpoints.class,
            authRegion, null, "read");

    HealthPluginRegion healthPluginRegion = new HealthPluginRegion(mapper, System.currentTimeMillis(), ringHost,
            "soy.upena.page.healthPluginRegion", "soy.upena.page.instanceHealthPluginRegion",
            "soy.upena.page.healthPopup", renderer, upenaHealth, upenaStore);
    ReleasesPluginRegion releasesPluginRegion = new ReleasesPluginRegion(mapper, repositoryProvider,
            "soy.upena.page.releasesPluginRegion", "soy.upena.page.releasesPluginRegionList", renderer,
            upenaStore);
    HostsPluginRegion hostsPluginRegion = new HostsPluginRegion("soy.upena.page.hostsPluginRegion",
            "soy.upena.page.removeHostPluginRegion", renderer, upenaStore);
    InstancesPluginRegion instancesPluginRegion = new InstancesPluginRegion(
            "soy.upena.page.instancesPluginRegion", "soy.upena.page.instancesPluginRegionList", renderer,
            upenaHealth, upenaStore, hostKey, healthPluginRegion, awsClientFactory);

    PluginHandle health = new PluginHandle("fire", null, "Health", "/ui/health", HealthPluginEndpoints.class,
            healthPluginRegion, null, "read");

    PluginHandle topology = new PluginHandle("th", null, "Topology", "/ui/topology",
            TopologyPluginEndpoints.class,
            new TopologyPluginRegion(mapper, "soy.upena.page.topologyPluginRegion",
                    "soy.upena.page.connectionsHealth", renderer, upenaHealth, amzaService, upenaSSLConfig,
                    upenaStore, healthPluginRegion, hostsPluginRegion, releasesPluginRegion,
                    instancesPluginRegion, discoveredRoutes),
            null, "read");

    PluginHandle connectivity = new PluginHandle("transfer", null, "Connectivity", "/ui/connectivity",
            ConnectivityPluginEndpoints.class,
            new ConnectivityPluginRegion(mapper, "soy.upena.page.connectivityPluginRegion",
                    "soy.upena.page.connectionsHealth", "soy.upena.page.connectionOverview", renderer,
                    upenaHealth, amzaService, upenaSSLConfig, upenaStore, healthPluginRegion, discoveredRoutes),
            null, "read");

    PluginHandle changes = new PluginHandle("road", null, "Changes", "/ui/changeLog",
            ChangeLogPluginEndpoints.class,
            new ChangeLogPluginRegion("soy.upena.page.changeLogPluginRegion", renderer, upenaStore), null,
            "read");

    PluginHandle instances = new PluginHandle("star", null, "Instances", "/ui/instances",
            InstancesPluginEndpoints.class, instancesPluginRegion, null, "read");

    PluginHandle config = new PluginHandle("cog", null, "Config", "/ui/config", ConfigPluginEndpoints.class,
            new ConfigPluginRegion(mapper, "soy.upena.page.configPluginRegion", renderer, upenaSSLConfig,
                    upenaStore, upenaConfigStore),
            null, "read");

    PluginHandle repo = new PluginHandle("hdd", null, "Repository", "/ui/repo", RepoPluginEndpoints.class,
            new RepoPluginRegion("soy.upena.page.repoPluginRegion", renderer, upenaStore, localPathToRepo),
            null, "read");

    PluginHandle projects = new PluginHandle("folder-open", null, "Projects", "/ui/projects",
            ProjectsPluginEndpoints.class,
            new ProjectsPluginRegion("soy.upena.page.projectsPluginRegion", "soy.upena.page.projectBuildOutput",
                    "soy.upena.page.projectBuildOutputTail", renderer, upenaStore, localPathToRepo),
            null, "read");

    PluginHandle users = new PluginHandle("user", null, "Users", "/ui/users", UsersPluginEndpoints.class,
            new UsersPluginRegion("soy.upena.page.usersPluginRegion", renderer, upenaStore), null, "read");

    PluginHandle permissions = new PluginHandle("lock", null, "Permission", "/ui/permissions",
            PermissionsPluginEndpoints.class,
            new PermissionsPluginRegion("soy.upena.page.permissionsPluginRegion", renderer, upenaStore), null,
            "read");

    PluginHandle clusters = new PluginHandle("cloud", null, "Clusters", "/ui/clusters",
            ClustersPluginEndpoints.class,
            new ClustersPluginRegion("soy.upena.page.clustersPluginRegion", renderer, upenaStore), null,
            "read");

    PluginHandle hosts = new PluginHandle("tasks", null, "Hosts", "/ui/hosts", HostsPluginEndpoints.class,
            hostsPluginRegion, null, "read");

    PluginHandle services = new PluginHandle("tint", null, "Services", "/ui/services",
            ServicesPluginEndpoints.class,
            new ServicesPluginRegion(mapper, "soy.upena.page.servicesPluginRegion", renderer, upenaStore), null,
            "read");

    PluginHandle releases = new PluginHandle("send", null, "Releases", "/ui/releases",
            ReleasesPluginEndpoints.class, releasesPluginRegion, null, "read");

    PluginHandle modules = new PluginHandle("wrench", null, "Modules", "/ui/modules",
            ModulesPluginEndpoints.class, new ModulesPluginRegion(mapper, repositoryProvider,
                    "soy.upena.page.modulesPluginRegion", renderer, upenaStore),
            null, "read");

    PluginHandle proxy = new PluginHandle("random", null, "Proxies", "/ui/proxy", ProxyPluginEndpoints.class,
            new ProxyPluginRegion("soy.upena.page.proxyPluginRegion", renderer), null, "read", "debug");

    PluginHandle ring = new PluginHandle("leaf", null, "Upena", "/ui/ring", UpenaRingPluginEndpoints.class,
            new UpenaRingPluginRegion(storeMapper, "soy.upena.page.upenaRingPluginRegion", renderer,
                    amzaService, upenaStore, upenaConfigStore),
            null, "read", "debug");

    PluginHandle loadBalancer = new PluginHandle("scale", null, "Load Balancer", "/ui/loadbalancers",
            LoadBalancersPluginEndpoints.class,
            new LoadBalancersPluginRegion("soy.upena.page.loadBalancersPluginRegion", renderer, upenaStore,
                    awsClientFactory),
            null, "read", "debug");

    ServicesCallDepthStack servicesCallDepthStack = new ServicesCallDepthStack();
    PerfService perfService = new PerfService(servicesCallDepthStack);

    PluginHandle profiler = new PluginHandle("hourglass", null, "Profiler", "/ui/profiler",
            ProfilerPluginEndpoints.class, new ProfilerPluginRegion("soy.upena.page.profilerPluginRegion",
                    renderer, new VisualizeProfile(new NameUtils(), servicesCallDepthStack)),
            null, "read", "debug");

    PluginHandle jvm = null;
    PluginHandle breakpointDumper = null;
    if (jvmapi != null) {
        jvm = new PluginHandle("camera", null, "JVM", "/ui/jvm", JVMPluginEndpoints.class,
                new JVMPluginRegion("soy.upena.page.jvmPluginRegion", renderer, upenaStore, jvmapi), null,
                "read", "debug");

        breakpointDumper = new PluginHandle("record", null, "Breakpoint Dumper", "/ui/breakpoint",
                BreakpointDumperPluginEndpoints.class,
                new BreakpointDumperPluginRegion("soy.upena.page.breakpointDumperPluginRegion", renderer,
                        upenaStore, jvmapi),
                null, "read", "debug");
    }

    PluginHandle aws = null;
    aws = new PluginHandle("globe", null, "AWS", "/ui/aws", AWSPluginEndpoints.class,
            new AWSPluginRegion("soy.upena.page.awsPluginRegion", renderer, awsClientFactory), null, "read",
            "debug");

    PluginHandle monkey = new PluginHandle("flash", null, "Chaos", "/ui/chaos", MonkeyPluginEndpoints.class,
            new MonkeyPluginRegion("soy.upena.page.monkeyPluginRegion", renderer, upenaStore), null, "read",
            "debug");

    PluginHandle api = new PluginHandle("play-circle", null, "API", "/ui/api", ApiPluginEndpoints.class, null,
            null, "read", "debug");

    PluginHandle thrown = new PluginHandle("equalizer", null, "Thrown", "/ui/thrown",
            ThrownPluginEndpoints.class,
            new ThrownPluginRegion(hostKey, "soy.upena.page.thrownPluginRegion", renderer, upenaStore), null,
            "read", "debug");

    PluginHandle probe = new PluginHandle("hand-right", null, "Deployable", "/ui/deployable",
            ManagedDeployablePluginEndpoints.class, new ManagedDeployablePluginRegion(sessionStore, hostKey,
                    "soy.upena.page.deployablePluginRegion", renderer, upenaStore, upenaSSLConfig, port),
            null, "read", "debug");

    List<PluginHandle> plugins = new ArrayList<>();
    plugins.add(auth);
    plugins.add(new PluginHandle(null, null, "API", null, null, null, "separator", "read"));
    plugins.add(api);
    plugins.add(new PluginHandle(null, null, "Build", null, null, null, "separator", "read"));
    plugins.add(repo);
    plugins.add(projects);
    plugins.add(modules);
    plugins.add(new PluginHandle(null, null, "Config", null, null, null, "separator", "read"));
    plugins.add(aws);
    plugins.add(changes);
    plugins.add(config);
    plugins.add(clusters);
    plugins.add(hosts);
    plugins.add(services);
    plugins.add(releases);
    plugins.add(instances);
    plugins.add(loadBalancer);
    plugins.add(new PluginHandle(null, null, "Health", null, null, null, "separator", "read"));
    plugins.add(health);
    plugins.add(connectivity);
    plugins.add(topology);
    plugins.add(new PluginHandle(null, null, "Tools", null, null, null, "separator", "read", "debug"));
    plugins.add(monkey);
    plugins.add(proxy);
    if (jvm != null) {
        plugins.add(jvm);
        plugins.add(thrown);
        plugins.add(breakpointDumper);
    }
    plugins.add(profiler);
    plugins.add(ring);
    plugins.add(users);
    plugins.add(permissions);

    jerseyEndpoints.addInjectable(SessionStore.class, sessionStore);
    jerseyEndpoints.addInjectable(UpenaSSLConfig.class, upenaSSLConfig);
    jerseyEndpoints.addInjectable(SoyService.class, soyService);
    jerseyEndpoints.addEndpoint(AsyncLookupEndpoints.class);
    jerseyEndpoints.addInjectable(AsyncLookupService.class, new AsyncLookupService(upenaSSLConfig, upenaStore));

    jerseyEndpoints.addEndpoint(PerfServiceEndpoints.class);
    jerseyEndpoints.addInjectable(PerfService.class, perfService);

    for (PluginHandle plugin : plugins) {
        soyService.registerPlugin(plugin);
        if (plugin.separator == null) {
            jerseyEndpoints.addEndpoint(plugin.endpointsClass);
            if (plugin.region != null) {
                jerseyEndpoints.addInjectable(plugin.region.getClass(), plugin.region);
            }
        }
    }

    jerseyEndpoints.addEndpoint(probe.endpointsClass);
    jerseyEndpoints.addInjectable(probe.region.getClass(), probe.region);

    jerseyEndpoints.addInjectable(UnauthorizedPluginRegion.class, unauthorizedRegion);
    //jerseyEndpoints.addEndpoint(UpenaPropagatorEndpoints.class);
}

From source file:org.apache.storm.utils.Utils.java

public static Map<String, Object> getConfigFromClasspath(List<String> cp, Map<String, Object> conf)
        throws IOException {
    if (cp == null || cp.isEmpty()) {
        return conf;
    }//from  ww w  .j a va2s. com
    Yaml yaml = new Yaml(new SafeConstructor());
    Map<String, Object> defaultsConf = null;
    Map<String, Object> stormConf = null;
    for (String part : cp) {
        File f = new File(part);
        if (f.isDirectory()) {
            if (defaultsConf == null) {
                defaultsConf = readConfIgnoreNotFound(yaml, new File(f, "defaults.yaml"));
            }

            if (stormConf == null) {
                stormConf = readConfIgnoreNotFound(yaml, new File(f, "storm.yaml"));
            }
        } else {
            //Lets assume it is a jar file
            try (JarFile jarFile = new JarFile(f)) {
                Enumeration<JarEntry> jarEnums = jarFile.entries();
                while (jarEnums.hasMoreElements()) {
                    JarEntry entry = jarEnums.nextElement();
                    if (!entry.isDirectory()) {
                        if (defaultsConf == null && entry.getName().equals("defaults.yaml")) {
                            try (InputStream in = jarFile.getInputStream(entry)) {
                                defaultsConf = (Map<String, Object>) yaml.load(new InputStreamReader(in));
                            }
                        }

                        if (stormConf == null && entry.getName().equals("storm.yaml")) {
                            try (InputStream in = jarFile.getInputStream(entry)) {
                                stormConf = (Map<String, Object>) yaml.load(new InputStreamReader(in));
                            }
                        }
                    }
                }
            }
        }
    }
    if (stormConf != null) {
        defaultsConf.putAll(stormConf);
    }
    return defaultsConf;
}