List of usage examples for com.google.common.collect ImmutableList toArray
<T> T[] toArray(T[] a);
From source file:com.google.caliper.runner.ExperimentModule.java
private static Method findBenchmarkMethod(Class<?> benchmark, String methodName, ImmutableList<Class<?>> methodParameterClasses) { Class<?>[] params = methodParameterClasses.toArray(new Class[methodParameterClasses.size()]); try {//from w w w . j a v a 2s .c o m return benchmark.getDeclaredMethod(methodName, params); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (SecurityException e) { // assertion error? throw new RuntimeException(e); } }
From source file:com.facebook.buck.features.haskell.HaskellTestUtils.java
/** Assume that we can find a haskell compiler on the system. */ static HaskellVersion assumeSystemCompiler() throws IOException { ExecutableFinder executableFinder = new ExecutableFinder(); Optional<Path> compilerOptional = executableFinder.getOptionalExecutable(Paths.get("ghc"), EnvVariablesProvider.getSystemEnv()); assumeTrue(compilerOptional.isPresent()); // Find the major version of the haskell compiler. ImmutableList<String> cmd = ImmutableList.of(compilerOptional.get().toString(), "--version"); Process process = Runtime.getRuntime().exec(cmd.toArray(new String[0])); String output = new String(ByteStreams.toByteArray(process.getInputStream()), Charsets.UTF_8); Pattern versionPattern = Pattern.compile(".*version ([0-9]+).*"); Matcher matcher = versionPattern.matcher(output.trim()); assertTrue(String.format("Cannot match version from `ghc --version` output (using %s): %s", versionPattern, output), matcher.matches()); return HaskellVersion.of(Integer.valueOf(matcher.group(1))); }
From source file:com.facebook.presto.jdbc.client.FailureInfo.java
private static FailureException toException(FailureInfo failureInfo) { if (failureInfo == null) { return null; }//from w ww . j a v a2 s . c o m FailureException failure = new FailureException(failureInfo.getType(), failureInfo.getMessage(), toException(failureInfo.getCause())); ImmutableList.Builder<StackTraceElement> stackTraceBuilder = ImmutableList.builder(); for (String stack : failureInfo.getStack()) { stackTraceBuilder.add(toStackTraceElement(stack)); } ImmutableList<StackTraceElement> stackTrace = stackTraceBuilder.build(); failure.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()])); return failure; }
From source file:com.facebook.presto.client.FailureInfo.java
private static FailureException toException(FailureInfo failureInfo) { if (failureInfo == null) { return null; }//w w w . j a v a 2 s . co m FailureException failure = new FailureException(failureInfo.getType(), failureInfo.getMessage(), toException(failureInfo.getCause())); for (FailureInfo suppressed : failureInfo.getSuppressed()) { failure.addSuppressed(toException(suppressed)); } ImmutableList.Builder<StackTraceElement> stackTraceBuilder = ImmutableList.builder(); for (String stack : failureInfo.getStack()) { stackTraceBuilder.add(toStackTraceElement(stack)); } ImmutableList<StackTraceElement> stackTrace = stackTraceBuilder.build(); failure.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()])); return failure; }
From source file:com.facebook.presto.execution.ExecutionFailureInfo.java
private static Failure toException(ExecutionFailureInfo executionFailureInfo) { if (executionFailureInfo == null) { return null; }/*from w ww . j av a 2 s . com*/ Failure failure = new Failure(executionFailureInfo.getType(), executionFailureInfo.getMessage(), executionFailureInfo.getErrorCode(), toException(executionFailureInfo.getCause())); for (ExecutionFailureInfo suppressed : executionFailureInfo.getSuppressed()) { failure.addSuppressed(toException(suppressed)); } ImmutableList.Builder<StackTraceElement> stackTraceBuilder = ImmutableList.builder(); for (String stack : executionFailureInfo.getStack()) { stackTraceBuilder.add(toStackTraceElement(stack)); } ImmutableList<StackTraceElement> stackTrace = stackTraceBuilder.build(); failure.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()])); return failure; }
From source file:org.eclipse.buildship.core.configuration.GradleProjectBuilder.java
/** * Configures the builder on the target project if it was not added previously. * <p/>/* w w w .j a v a2s . co m*/ * This method requires the {@link org.eclipse.core.resources.IWorkspaceRoot} scheduling rule. * * @param project the target project */ public static void configureOnProject(IProject project) { try { Preconditions.checkState(project.isOpen()); // check if the builder is already registered with the project IProjectDescription description = project.getDescription(); List<ICommand> buildSpecs = Arrays.asList(description.getBuildSpec()); boolean exists = FluentIterable.from(buildSpecs).anyMatch(new Predicate<ICommand>() { @Override public boolean apply(ICommand command) { return command.getBuilderName().equals(ID); } }); // register the builder with the project if it is not already registered if (!exists) { ICommand buildSpec = description.newCommand(); buildSpec.setBuilderName(ID); ImmutableList<ICommand> newBuildSpecs = ImmutableList.<ICommand>builder().addAll(buildSpecs) .add(buildSpec).build(); description.setBuildSpec(newBuildSpecs.toArray(new ICommand[newBuildSpecs.size()])); project.setDescription(description, new NullProgressMonitor()); } } catch (CoreException e) { CorePlugin.logger() .error(String.format("Failed to add Gradle Project Builder to project %s.", project.getName())); } }
From source file:com.google.testing.junit.runner.junit4.JUnit4Options.java
/** * Parses the given array of arguments and returns a JUnit4Options * object representing the parsed arguments. *///from w w w.ja v a 2 s .com static JUnit4Options parse(Map<String, String> envVars, List<String> args) { ImmutableList.Builder<String> unparsedArgsBuilder = ImmutableList.builder(); Map<String, String> optionsMap = Maps.newHashMap(); optionsMap.put(TEST_INCLUDE_FILTER_OPTION, null); optionsMap.put(TEST_EXCLUDE_FILTER_OPTION, null); for (Iterator<String> it = args.iterator(); it.hasNext();) { String arg = it.next(); int indexOfEquals = arg.indexOf("="); if (indexOfEquals > 0) { String optionName = arg.substring(0, indexOfEquals); if (optionsMap.containsKey(optionName)) { optionsMap.put(optionName, arg.substring(indexOfEquals + 1)); continue; } } else if (optionsMap.containsKey(arg)) { // next argument is the regexp if (!it.hasNext()) { throw new RuntimeException("No filter expression specified after " + arg); } optionsMap.put(arg, it.next()); continue; } unparsedArgsBuilder.add(arg); } // If TESTBRIDGE_TEST_ONLY is set in the environment, forward it to the // --test_filter flag. String testFilter = envVars.get(TESTBRIDGE_TEST_ONLY); if (testFilter != null && optionsMap.get(TEST_INCLUDE_FILTER_OPTION) == null) { optionsMap.put(TEST_INCLUDE_FILTER_OPTION, testFilter); } ImmutableList<String> unparsedArgs = unparsedArgsBuilder.build(); return new JUnit4Options(optionsMap.get(TEST_INCLUDE_FILTER_OPTION), optionsMap.get(TEST_EXCLUDE_FILTER_OPTION), unparsedArgs.toArray(new String[unparsedArgs.size()])); }
From source file:com.github.jsdossier.Main.java
@VisibleForTesting static void run(String[] args, FileSystem fileSystem) { Flags flags = Flags.parse(args, fileSystem); Config config = null;// w w w . j av a 2 s . c o m try (InputStream stream = newInputStream(flags.config)) { config = Config.load(stream, fileSystem); } catch (IOException e) { e.printStackTrace(System.err); System.exit(-1); } if (flags.printConfig) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String header = " Configuration "; int len = header.length(); String pad = Strings.repeat("=", len / 2); System.err.println(pad + header + pad); System.err.println(gson.toJson(config.toJson())); System.err.println(Strings.repeat("=", 79)); System.exit(1); } Iterable<String> standardFlags = STANDARD_FLAGS; if (config.isStrict()) { standardFlags = transform(standardFlags, new Function<String, String>() { @Override public String apply(String input) { return input.replace("--jscomp_warning", "--jscomp_error"); } }); } ImmutableList<String> compilerFlags = ImmutableList.<String>builder() .addAll(transform(config.getSources(), toFlag("--js="))) .addAll(transform(config.getModules(), toFlag("--js="))) .addAll(transform(config.getExterns(), toFlag("--externs="))) .add("--language_in=" + config.getLanguage().getName()).addAll(standardFlags).build(); PrintStream nullStream = new PrintStream(ByteStreams.nullOutputStream()); args = compilerFlags.toArray(new String[compilerFlags.size()]); Logger log = Logger.getLogger(Main.class.getPackage().getName()); log.setLevel(Level.WARNING); log.addHandler(new Handler() { @Override public void publish(LogRecord record) { System.err.printf("[%s][%s] %s\n", record.getLevel(), record.getLoggerName(), record.getMessage()); } @Override public void flush() { } @Override public void close() { } }); Main main = new Main(args, nullStream, System.err, config); main.runCompiler(); }
From source file:li.klass.fhem.testsuite.category.CategorySuite.java
private static Class[] getSuiteClasses() { final String basePath = getBasePath(); File basePathFile = new File(basePath); ImmutableList<Class<?>> classes = Files.fileTreeTraverser().breadthFirstTraversal(basePathFile) .filter(new Predicate<File>() { @Override//from w w w . ja v a 2s. com public boolean apply(File input) { return input.getName().endsWith(".java"); } }).transform(new Function<File, Class<?>>() { @Override public Class<?> apply(File input) { return toClass(input, basePath); } }).filter(new Predicate<Class<?>>() { @Override public boolean apply(Class<?> input) { return input != null && !Modifier.isAbstract(input.getModifiers()); } }).toList(); return (classes.toArray(new Class[classes.size()])); }
From source file:com.spectralogic.ds3cli.views.cli.GetBucketView.java
protected String[][] formatTableContents() { final ImmutableList.Builder<String[]> builder = ImmutableList.builder(); for (final Contents content : contents) { final String[] arrayEntry = new String[5]; arrayEntry[0] = nullGuard(content.getKey()); arrayEntry[1] = nullGuard(Long.toString(content.getSize())); arrayEntry[2] = nullGuard(content.getOwner().getDisplayName()); arrayEntry[3] = nullGuardFromDate(content.getLastModified(), DATE_FORMAT); arrayEntry[4] = nullGuard(content.getETag()); builder.add(arrayEntry);//from ww w. j a v a 2 s.c om } final ImmutableList<String[]> contentStrings = builder.build(); return contentStrings.toArray(new String[contentStrings.size()][]); }