@Override public ImmutableList<Step> getBuildSteps( BuildContext context, BuildableContext buildableContext) { ImmutableList.Builder<Step> steps = ImmutableList.builder(); final Path pathToNativeLibs = getPathToNativeLibsDir(); steps.add(new MakeCleanDirectoryStep(pathToNativeLibs)); final Path pathToNativeLibsAssets = getPathToNativeLibsAssetsDir(); steps.add(new MakeCleanDirectoryStep(pathToNativeLibsAssets)); for (SourcePath nativeLibDir : nativeLibDirectories.asList().reverse()) { copyNativeLibrary( getProjectFilesystem(), getResolver().getPath(nativeLibDir), pathToNativeLibs, cpuFilters, steps); } addStepsForCopyingNativeLibrariesOrAssets(filteredNativeLibraries, pathToNativeLibs, steps); addStepsForCopyingNativeLibrariesOrAssets( filteredNativeLibrariesAssets, pathToNativeLibsAssets, steps); final Path pathToMetadataTxt = getPathToMetadataTxt(); steps.add( new AbstractExecutionStep("hash_native_libs") { @Override public int execute(ExecutionContext context) { ProjectFilesystem filesystem = context.getProjectFilesystem(); ImmutableList.Builder<String> metadataLines = ImmutableList.builder(); try { for (Path nativeLib : filesystem.getFilesUnderPath(pathToNativeLibs)) { String filesha1 = filesystem.computeSha1(nativeLib); Path relativePath = pathToNativeLibs.relativize(nativeLib); metadataLines.add(String.format("%s %s", relativePath.toString(), filesha1)); } for (Path nativeLib : filesystem.getFilesUnderPath(pathToNativeLibsAssets)) { String filesha1 = filesystem.computeSha1(nativeLib); Path relativePath = pathToNativeLibsAssets.relativize(nativeLib); metadataLines.add(String.format("%s %s", relativePath.toString(), filesha1)); } filesystem.writeLinesToPath(metadataLines.build(), pathToMetadataTxt); } catch (IOException e) { context.logError(e, "There was an error hashing native libraries."); return 1; } return 0; } }); buildableContext.recordArtifact(pathToNativeLibs); buildableContext.recordArtifact(pathToNativeLibsAssets); buildableContext.recordArtifact(pathToMetadataTxt); return steps.build(); }
@Test public void defensiveCopyEqualsInitialSet() throws Exception { // given ImmutableSet<String> initialSet = ImmutableSet.of("red", "yellow", "blue"); // when ImmutableSet<String> copy = ImmutableSet.copyOf(initialSet.asList()); // then Assert.assertEquals(copy, initialSet); }
private ImmutableSet<String> appendDefaultDBPriv( ImmutableSet<String> privileges, Authorizable[] authorizables) { // Only for switch db if ((authorizables != null) && (authorizables.length == 4) && (authorizables[2].getName().equals("+"))) { if ((privileges.size() == 1) && hasOnlyServerPrivilege(privileges.asList().get(0))) { // Assuming authorizable[0] will always be the server // This Code is only reachable only when user fires a 'use default' // and the user has a privilege on atleast 1 privilized Object String defaultPriv = "Server=" + authorizables[0].getName() + "->Db=default->Table=*->Column=*->action=select"; HashSet<String> newPrivs = Sets.newHashSet(defaultPriv); return ImmutableSet.copyOf(newPrivs); } } return privileges; }
/** * Returns a definition for each scenario. * * @param scenarioNames the names of the scenarios * @param mappings the filters and perturbations that define the scenarios * @return the perturbations that should be applied in each scenario */ private static List<SingleScenarioDefinition> createScenarios( ImmutableSet<String> scenarioNames, List<? extends PerturbationMapping<?>> mappings, boolean allCombinations) { ImmutableList.Builder<List<SinglePerturbationMapping>> singleMappingsBuilder = ImmutableList.builder(); // Flatten the perturbation mappings into lists of single perturbations. // The mappings contain a filter and multiple perturbations used across multiple scenarios. // The single perturbation mappings contain a filter and a perturbation, and are used in a // single scenario for (PerturbationMapping mapping : mappings) { singleMappingsBuilder.add(flattenPerturbations(mapping)); } List<List<SinglePerturbationMapping>> perturbations = singleMappingsBuilder.build(); List<String> scenarioNamesList = scenarioNames.asList(); if (allCombinations) { return createScenariosForAllCombinations(perturbations, scenarioNamesList); } else { return createScenariosForSimpleCombinations(perturbations, scenarioNamesList); } }
@Override protected List<String> create(String[] elements) { Comparator<String> comparator = createExplicitComparator(elements); ImmutableSet<String> set = ImmutableSortedSet.copyOf(comparator, Arrays.asList(elements)); return set.asList(); }