List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:org.sonar.classloader.ClassloaderBuilderTest.java
/** * - sibling contains A and B//from www. j a v a 2 s . c o m * - child contains C and excludes A from sibling -> sees only B and C */ @Test public void sibling_mask() throws Exception { Map<String, ClassLoader> newClassloaders = sut.newClassloader("sib1") .addURL("sib1", new File("tester/a.jar").toURL()).addURL("sib1", new File("tester/b.jar").toURL()) .newClassloader("the-child").addURL("the-child", new File("tester/c.jar").toURL()) .addSibling("the-child", "sib1", Mask.builder().exclude("A.class", "a.txt").build()).build(); ClassLoader sib1 = newClassloaders.get("sib1"); assertThat(canLoadClass(sib1, "A")).isTrue(); assertThat(canLoadClass(sib1, "B")).isTrue(); assertThat(canLoadResource(sib1, "a.txt")).isTrue(); assertThat(canLoadResource(sib1, "b.txt")).isTrue(); ClassLoader child = newClassloaders.get("the-child"); assertThat(canLoadClass(child, "A")).isFalse(); assertThat(canLoadClass(child, "B")).isTrue(); assertThat(canLoadClass(child, "C")).isTrue(); assertThat(canLoadResource(child, "a.txt")).isFalse(); assertThat(canLoadResource(child, "b.txt")).isTrue(); assertThat(canLoadResource(child, "c.txt")).isTrue(); assertThat(Collections.list(child.getResources("a.txt"))).hasSize(0); assertThat(Collections.list(child.getResources("b.txt"))).hasSize(1); assertThat(Collections.list(child.getResources("c.txt"))).hasSize(1); }
From source file:org.opencms.workplace.tools.workplace.logging.CmsLog4JAdminDialog.java
/** * Simple check if the logger has the global log file <p> or a single one. * * @param logchannel the channel that has do be checked * @return true if the the log channel has a single log file * *///w w w . j a v a 2s . com protected boolean isloggingactivated(Logger logchannel) { boolean check = false; @SuppressWarnings("unchecked") List<Appender> appenders = Collections.list(logchannel.getAllAppenders()); Iterator<Appender> app = appenders.iterator(); while (app.hasNext()) { check = app.next().getName().equals(logchannel.getName()); } return check; }
From source file:org.rimudb.editor.RimuDBEditor.java
protected void driverCheck() { driverMap = getPreferences().getDrivers(); if (driverMap != null) { Set<String> keyset = driverMap.keySet(); for (String driverName : keyset) { DriverEntry driverEntry = driverMap.get(driverName); boolean found = false; try { Class.forName(driverEntry.getJdbcDriver()); found = true;// ww w . ja v a 2 s . c o m } catch (Exception e) { log.info("driverCheck() Could not find driverClass", e); } driverEntry.setFound(found); } List<Driver> drivers = Collections.list(DriverManager.getDrivers()); for (int i = 0; i < drivers.size(); i++) { Driver driver = (Driver) drivers.get(i); // Find the driver in the map and add the version to the DriverEntry Collection<DriverEntry> values = driverMap.values(); for (DriverEntry driverEntry : values) { if (driverEntry.getJdbcDriver().trim().equals(driver.getClass().getName())) { driverEntry.setDriverVersion(driver.getMajorVersion() + "." + driver.getMinorVersion()); } } } } }
From source file:org.apache.nifi.registry.jetty.JettyServer.java
private void dumpUrls() throws SocketException { final List<String> urls = new ArrayList<>(); for (Connector connector : server.getConnectors()) { if (connector instanceof ServerConnector) { final ServerConnector serverConnector = (ServerConnector) connector; Set<String> hosts = new HashSet<>(); // determine the hosts if (StringUtils.isNotBlank(serverConnector.getHost())) { hosts.add(serverConnector.getHost()); } else { Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); if (networkInterfaces != null) { for (NetworkInterface networkInterface : Collections.list(networkInterfaces)) { for (InetAddress inetAddress : Collections.list(networkInterface.getInetAddresses())) { hosts.add(inetAddress.getHostAddress()); }//ww w.j ava 2 s . c o m } } } // ensure some hosts were found if (!hosts.isEmpty()) { String scheme = "http"; if (properties.getSslPort() != null && serverConnector.getPort() == properties.getSslPort()) { scheme = "https"; } // dump each url for (String host : hosts) { urls.add(String.format("%s://%s:%s", scheme, host, serverConnector.getPort())); } } } } if (urls.isEmpty()) { logger.warn( "NiFi Registry has started, but the UI is not available on any hosts. Please verify the host properties."); } else { // log the ui location logger.info("NiFi Registry has started. The UI is available at the following URLs:"); for (final String url : urls) { logger.info(String.format("%s/nifi-registry", url)); } } }
From source file:info.pancancer.arch3.worker.WorkerRunnable.java
/** * Get the IP address of this machine, preference is given to returning an IPv4 address, if there is one. * * @return An InetAddress object.//from w w w .j a va 2s . c o m * @throws SocketException */ public InetAddress getFirstNonLoopbackAddress() throws SocketException { final String dockerInterfaceName = "docker"; for (NetworkInterface i : Collections.list(NetworkInterface.getNetworkInterfaces())) { if (i.getName().contains(dockerInterfaceName)) { // the virtual ip address for the docker mount is useless but is not a loopback address continue; } log.info("Examining " + i.getName()); for (InetAddress addr : Collections.list(i.getInetAddresses())) { if (!addr.isLoopbackAddress()) { // Prefer IP v4 if (addr instanceof Inet4Address) { return addr; } } } } Log.info("Could not find an ipv4 address"); for (NetworkInterface i : Collections.list(NetworkInterface.getNetworkInterfaces())) { log.info("Examining " + i.getName()); if (i.getName().contains(dockerInterfaceName)) { // the virtual ip address for the docker mount is useless but is not a loopback address continue; } // If we got here it means we never found an IP v4 address, so we'll have to return the IPv6 address. for (InetAddress addr : Collections.list(i.getInetAddresses())) { // InetAddress addr = (InetAddress) en2.nextElement(); if (!addr.isLoopbackAddress()) { return addr; } } } return null; }
From source file:au.edu.anu.portal.portlets.basiclti.BasicLTIPortlet.java
/** * Processes the init params to get the adapter class map. This method iterates over every init-param, selects the appropriate adapter ones, * fetches the param value and then strips the 'adapter-class-' prefix from the param name for storage in the map. * @param config PortletConfig//w w w . j a va 2 s . co m * @return Map of adapter names and classes */ private Map<String, String> initAdapters(PortletConfig config) { Map<String, String> m = new HashMap<String, String>(); String ADAPTER_CLASS_PREFIX = "adapter-class-"; //get it into a usable form List<String> paramNames = Collections.list((Enumeration<String>) config.getInitParameterNames()); //iterate over, select the appropriate ones, retrieve the param value then strip param name for storage. for (String paramName : paramNames) { if (StringUtils.startsWith(paramName, ADAPTER_CLASS_PREFIX)) { String adapterName = StringUtils.removeStart(paramName, ADAPTER_CLASS_PREFIX); String adapterClass = config.getInitParameter(paramName); m.put(adapterName, adapterClass); log.info("Registered adapter: " + adapterName + " with class: " + adapterClass); } } log.info("Autowired: " + m.size() + " adapters"); return m; }
From source file:org.eclipse.virgo.ide.ui.editors.SpringBundleSourcePage.java
private boolean isSpringHeader(String key) { ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.virgo.ide.ui.editors.text.headers"); List<String> headers = Collections.list(bundle.getKeys()); return headers.contains(key); }
From source file:org.apache.hadoop.hive.ql.exec.mr2.MR2ExecDriver.java
@SuppressWarnings("unchecked") public static void main(String[] args) throws IOException, HiveException { String planFileName = null;/*from w w w. j a v a2 s .c om*/ String jobConfFileName = null; boolean noLog = false; String files = null; boolean localtask = false; try { for (int i = 0; i < args.length; i++) { if (args[i].equals("-plan")) { planFileName = args[++i]; } else if (args[i].equals("-jobconffile")) { jobConfFileName = args[++i]; } else if (args[i].equals("-nolog")) { noLog = true; } else if (args[i].equals("-files")) { files = args[++i]; } else if (args[i].equals("-localtask")) { localtask = true; } } } catch (IndexOutOfBoundsException e) { System.err.println("Missing argument to option"); printUsage(); } JobConf conf; if (localtask) { conf = new JobConf(MapredLocalTask.class); } else { conf = new JobConf(MR2ExecDriver.class); } if (jobConfFileName != null) { conf.addResource(new Path(jobConfFileName)); } if (files != null) { conf.set("tmpfiles", files); } if (UserGroupInformation.isSecurityEnabled()) { String hadoopAuthToken = System.getenv(UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION); if (hadoopAuthToken != null) { conf.set("mapreduce.job.credentials.binary", hadoopAuthToken); } } boolean isSilent = HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVESESSIONSILENT); String queryId = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEQUERYID, "").trim(); if (queryId.isEmpty()) { queryId = "unknown-" + System.currentTimeMillis(); } System.setProperty(HiveConf.ConfVars.HIVEQUERYID.toString(), queryId); if (noLog) { // If started from main(), and noLog is on, we should not output // any logs. To turn the log on, please set -Dtest.silent=false BasicConfigurator.resetConfiguration(); BasicConfigurator.configure(new NullAppender()); } else { setupChildLog4j(conf); } Log LOG = LogFactory.getLog(MR2ExecDriver.class.getName()); LogHelper console = new LogHelper(LOG, isSilent); if (planFileName == null) { console.printError("Must specify Plan File Name"); printUsage(); } // print out the location of the log file for the user so // that it's easy to find reason for local mode execution failures for (Appender appender : Collections .list((Enumeration<Appender>) LogManager.getRootLogger().getAllAppenders())) { if (appender instanceof FileAppender) { console.printInfo("Execution log at: " + ((FileAppender) appender).getFile()); } } // the plan file should always be in local directory Path p = new Path(planFileName); FileSystem fs = FileSystem.getLocal(conf); InputStream pathData = fs.open(p); // this is workaround for hadoop-17 - libjars are not added to classpath of the // child process. so we add it here explicitly String auxJars = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEAUXJARS); String addedJars = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEADDEDJARS); try { // see also - code in CliDriver.java ClassLoader loader = conf.getClassLoader(); if (StringUtils.isNotBlank(auxJars)) { loader = Utilities.addToClassPath(loader, StringUtils.split(auxJars, ",")); } if (StringUtils.isNotBlank(addedJars)) { loader = Utilities.addToClassPath(loader, StringUtils.split(addedJars, ",")); } conf.setClassLoader(loader); // Also set this to the Thread ContextClassLoader, so new threads will // inherit // this class loader, and propagate into newly created Configurations by // those // new threads. Thread.currentThread().setContextClassLoader(loader); } catch (Exception e) { throw new HiveException(e.getMessage(), e); } int ret; if (localtask) { memoryMXBean = ManagementFactory.getMemoryMXBean(); MapredLocalWork plan = Utilities.deserializePlan(pathData, MapredLocalWork.class, conf); MapredLocalTask ed = new MapredLocalTask(plan, conf, isSilent); ret = ed.executeInProcess(new DriverContext()); } else { MR2Work plan = Utilities.deserializePlan(pathData, MR2Work.class, conf); MR2ExecDriver ed = new MR2ExecDriver(plan, conf, isSilent); ret = ed.execute(new DriverContext()); } if (ret != 0) { System.exit(ret); } }
From source file:cn.teamlab.wg.framework.struts2.json.PackageBasedActionConfigBuilder.java
private List<URL> readUrls() throws IOException { List<URL> resourceUrls = new ArrayList<URL>(); // Usually the "classes" dir. ArrayList<URL> classesList = Collections.list(getClassLoaderInterface().getResources("")); for (URL url : classesList) { resourceUrls.addAll(fileManager.getAllPhysicalUrls(url)); }/*from w w w. j a v a 2 s . co m*/ return buildUrlSet(resourceUrls).getUrls(); }
From source file:org.sonar.classloader.ClassloaderBuilderTest.java
/** * - sibling contains A and B but exports only B * - child contains C -> sees only B and C *//* ww w . ja va 2 s . com*/ @Test public void sibling_export_mask() throws Exception { Map<String, ClassLoader> newClassloaders = sut.newClassloader("sib1") .addURL("sib1", new File("tester/a.jar").toURL()).addURL("sib1", new File("tester/b.jar").toURL()) .setExportMask("sib1", Mask.builder().include("B.class", "b.txt").build()) .newClassloader("the-child").addURL("the-child", new File("tester/c.jar").toURL()) .addSibling("the-child", "sib1", Mask.ALL).build(); ClassLoader sib1 = newClassloaders.get("sib1"); assertThat(canLoadClass(sib1, "A")).isTrue(); assertThat(canLoadClass(sib1, "B")).isTrue(); assertThat(canLoadResource(sib1, "a.txt")).isTrue(); assertThat(canLoadResource(sib1, "b.txt")).isTrue(); ClassLoader child = newClassloaders.get("the-child"); assertThat(canLoadClass(child, "A")).isFalse(); assertThat(canLoadClass(child, "B")).isTrue(); assertThat(canLoadClass(child, "C")).isTrue(); assertThat(canLoadResource(child, "a.txt")).isFalse(); assertThat(canLoadResource(child, "b.txt")).isTrue(); assertThat(canLoadResource(child, "c.txt")).isTrue(); assertThat(Collections.list(child.getResources("a.txt"))).hasSize(0); assertThat(Collections.list(child.getResources("b.txt"))).hasSize(1); assertThat(Collections.list(child.getResources("c.txt"))).hasSize(1); }