void close() { if (status == RUNNING) { status = CLOSED; Utils.close(driver); } }
String commonCompletion = Utils.findLongestCommonPrefix(completions.getValues()); if (commonCompletion.length() > 0) { delimiter.escape(commonCompletion, sb);
@Override protected Iterable<PropertyDescriptor<?>> createConfigurationCapabilities() { return Utils.<PropertyDescriptor<?>>list(SMTP_HOST, SMTP_PORT, SMTP_SECURE, SMTP_USERNAME, SMTP_PASSWORD, SMTP_FROM, DEBUG); }
public void testMany() throws Exception { output.clear(); lifeCycle.bindGroovy("consume_command", consume_command); lifeCycle.bindGroovy("produce_command", produce_command); assertOk("produce_command | filter -p A:C -p A:B | consume_command"); assertEquals(list(map(map("A", "B"), "B", "B"), map(map("A", "C"), "B", "A")), output); }
private static ByteArrayOutputStream read(InputStream in) throws IOException { if (in == null) { throw new NullPointerException(); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); copy(in, baos); return baos; }
List<JavaFileObject> classes = collect(Utils.list(resolver.resolve("java.util", false))); assertEquals(2, classes.size()); assertEndsWith("/HashMap.class", classes.get(0).getName()); byte[] bytes = Utils.readAsBytes(in); assertTrue(bytes.length > 0); classes = collect(Utils.list(resolver.resolve("java.util", true))); assertEquals(3, classes.size()); assertEndsWith("/ConcurrentHashMap.class", classes.get(0).getName());
public static boolean instanceOf(Class c, List<String> types) { for (String type: types) { if (instanceOf(c, type)) { return true; } } return false; }
public void afterPropertiesSet() throws Exception { // Initialise the registerable drivers try { drivers.put("classpath", new ClassPathMountFactory(loader)); drivers.put("file", new FileMountFactory(Utils.getCurrentDirectory())); } catch (Exception e) { log.log(Level.SEVERE, "Coult not initialize classpath driver", e); return; } // List beans Map<String,Object> attributes = new HashMap<String, Object>(); attributes.put("factory", factory); if (factory instanceof ListableBeanFactory) { ListableBeanFactory listable = (ListableBeanFactory)factory; attributes.put("beans", new SpringMap(listable)); } // PluginDiscovery discovery = new SpringPluginDiscovery(loader, factory); // start(Collections.unmodifiableMap(attributes), discovery, loader); }
public static List<BindingRenderer.BindingData> lookup(List<String> filters, String name, Boolean verbose) { Pattern pattern = null; if (name != null) { pattern = Pattern.compile("^" + Utils.globexToRegex(name) + "$"); } List<BindingRenderer.BindingData> data = new ArrayList<BindingRenderer.BindingData>(); data.addAll(get(filters, pattern, verbose, "")); data.addAll(get(filters, pattern, verbose, "java:/")); data.addAll(get(filters, pattern, verbose, "java:comp/env/jdbc")); data.addAll(get(filters, pattern, verbose, "java:jboss")); data.addAll(get(filters, pattern, verbose, "java:global")); data.addAll(get(filters, pattern, verbose, "java:app")); data.addAll(get(filters, pattern, verbose, "java:module")); return data; }
private CRaSHTaskDef validateAndParseCronLine(String cronLine) { // cronLine = cronLine.trim(); if (cronLine.length() == 0 || cronLine.charAt(0) == '#') { return null; } // List<String> cronLineParts = Arrays.asList(cronLine.split("\\s+")); if (cronLineParts.size() < 6) { return null; } // String schedulePart = Utils.join(cronLineParts.subList(0, 5), " "); String commandPart = Utils.join(cronLineParts.subList(5, cronLineParts.size()), " "); try { return new CRaSHTaskDef(new SchedulingPattern(schedulePart), commandPart); } catch (InvalidPatternException e) { // ? return null; } } }
/** * The path property is resolved from the servlet context parameters. When the parameter does not exist, * the <code>defaultValue</code> argument is used instead, so it should not be null. * After the path is resolved, it is interpolated using the JVM system properties and the syntax * defined by the {@link org.crsh.util.Utils#interpolate(String, java.util.Map)} function. * * @param propertyName the property name to resolve * @param defaultValue the default property value * @return the path value */ private String resolvePathProperty(String propertyName, String defaultValue) { String path = context.getInitParameter(propertyName); if (path == null) { path = defaultValue; } return Utils.interpolate(path, System.getProperties()); }
private static int width(int width, Iterator<Object> stream, CharSequence current, Integer from) { while (current == null) { if (stream.hasNext()) { Object next = stream.next(); if (next instanceof CharSequence) { current = (CharSequence)next; from = 0; } } else { break; } } if (current == null) { return width; } else { int pos = Utils.indexOf(current, from, '\n'); if (pos == -1) { return width(width + current.length() - from, stream, current, from); } else { return Math.max(width + pos - from, width(0, stream, null, 0)); } } }
private void copyConf(org.crsh.vfs.File src, File dst) throws IOException { if (!src.hasChildren()) { if (!dst.exists()) { Resource resource = ResourceManager.loadConf(src); if (resource != null) { log.info("Copied resource " + src.getPath().getValue() + " to " + dst.getCanonicalPath()); Utils.copy(new ByteArrayInputStream(resource.getContent()), new FileOutputStream(dst)); } } } }
public void testIntersect() throws Exception { output.clear(); lifeCycle.bindGroovy("consume_command", consume_command); lifeCycle.bindGroovy("produce_command", produce_command); assertOk("produce_command | filter -p A:C -p B:A | consume_command"); assertEquals(list(map(map("A", "C"), "B", "A")), output); }
public static boolean instanceOf(Class c, String type) { if (c.getName().equals(type)) { return true; } for (Class i : c.getInterfaces()) { if (instanceOf(i, type)) { return true; } } if (c.getSuperclass() != null) { return instanceOf(c.getSuperclass(), type); } return false; }
private FS.Builder createBuilder() throws IOException { FileMountFactory fileDriver = new FileMountFactory(Utils.getCurrentDirectory()); ClassPathMountFactory classpathDriver = new ClassPathMountFactory(Thread.currentThread().getContextClassLoader()); return new FS.Builder().register("file", fileDriver).register("classpath", classpathDriver); }
private void assertMatchGlob(String test, String globex) { Pattern p = Pattern.compile("^" + Utils.globexToRegex(globex) + "$"); Matcher matcher = p.matcher(test); assertTrue("Was expecting " + test + " to match " + globex, matcher.matches()); }
public void assertRender(LineReader renderer, int width, String... expected) { List<String> result = render(renderer, width); if (result.size() != expected.length) { throw failure("Was expecting the same number of lines got:" + Utils.join(result, "/") + " expected:" + Utils.join(Arrays.asList(expected), "/")); } else { for (int i = 0;i < expected.length;i++) { if (!result.get(i).equals(expected[i])) { throw failure("Was expecting line " + i + " <" + result.get(i) + "> to be equals to <" + expected[i] + ">"); } } } } }