Search in sources :

Example 76 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project buck by facebook.

the class DxAnalysisMain method loadAllClasses.

private static ImmutableMap<String, ClassNode> loadAllClasses(String zipFileName) throws IOException {
    ImmutableMap.Builder<String, ClassNode> allClassesBuilder = ImmutableMap.builder();
    try (ZipFile inJar = new ZipFile(zipFileName)) {
        for (ZipEntry entry : Collections.list(inJar.entries())) {
            if (!entry.getName().endsWith(".class")) {
                continue;
            }
            // Skip external libraries.
            if (entry.getName().startsWith("junit/") || entry.getName().startsWith("org/junit/") || entry.getName().startsWith("com/google/common/")) {
                continue;
            }
            byte[] rawClass = ByteStreams.toByteArray(inJar.getInputStream(entry));
            ClassNode klass = new ClassNode();
            new ClassReader(rawClass).accept(klass, ClassReader.EXPAND_FRAMES);
            allClassesBuilder.put(klass.name, klass);
        }
    }
    return allClassesBuilder.build();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ClassReader(org.objectweb.asm.ClassReader) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 77 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project MinecraftForge by MinecraftForge.

the class MultiLayerModel method process.

@Override
public MultiLayerModel process(ImmutableMap<String, String> customData) {
    ImmutableMap.Builder<Optional<BlockRenderLayer>, ModelResourceLocation> builder = ImmutableMap.builder();
    for (String key : customData.keySet()) {
        if ("base".equals(key)) {
            builder.put(Optional.<BlockRenderLayer>absent(), getLocation(customData.get(key)));
        }
        for (BlockRenderLayer layer : BlockRenderLayer.values()) {
            if (layer.toString().equals(key)) {
                builder.put(Optional.of(layer), getLocation(customData.get(key)));
            }
        }
    }
    ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models = builder.build();
    if (models.isEmpty())
        return INSTANCE;
    return new MultiLayerModel(models);
}
Also used : Optional(com.google.common.base.Optional) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 78 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project buck by facebook.

the class CxxLinkableEnhancerTest method platformLdFlags.

@Test
public void platformLdFlags() throws Exception {
    ImmutableMap<Linker.LinkableDepType, String> runtimes = ImmutableMap.of(Linker.LinkableDepType.SHARED, "-ldummy-shared-libc", Linker.LinkableDepType.STATIC, "-ldummy-static-libc", Linker.LinkableDepType.STATIC_PIC, "-ldummy-static-pic-libc");
    CxxPlatform cxxPlatform = CxxPlatform.builder().from(CXX_PLATFORM).putAllRuntimeLdflags(runtimes.asMultimap()).build();
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    for (Map.Entry<Linker.LinkableDepType, String> ent : runtimes.entrySet()) {
        CxxLink lib = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, cxxPlatform, params, ruleResolver, pathResolver, ruleFinder, target, Linker.LinkType.SHARED, Optional.empty(), DEFAULT_OUTPUT, ent.getKey(), EMPTY_DEPS, Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(DEFAULT_INPUTS).build());
        assertThat(Arg.stringify(lib.getArgs(), pathResolver), hasItem(ent.getValue()));
    }
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 79 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project buck by facebook.

the class CxxPlatformsTest method invalidArchiverOverrideFails.

@Test
public void invalidArchiverOverrideFails() {
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("ar", Paths.get("fake_path").toString(), "archiver_platform", "WRONG_PLATFORM"));
    CxxBuckConfig buckConfig = new CxxBuckConfig(FakeBuckConfig.builder().setSections(sections).setFilesystem(new FakeProjectFilesystem(ImmutableSet.of(Paths.get("fake_path")))).build());
    expectedException.expect(RuntimeException.class);
    ((LazyDelegatingArchiver) CxxPlatformUtils.build(buckConfig).getAr()).getDelegate();
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 80 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project buck by facebook.

the class CxxPlatformsTest method returnsKnownDefaultPlatformSetInConfig.

@Test
public void returnsKnownDefaultPlatformSetInConfig() {
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("default_platform", "borland_cxx_452"));
    CompilerProvider compiler = new CompilerProvider(Paths.get("borland"), Optional.of(CxxToolProvider.Type.GCC));
    PreprocessorProvider preprocessor = new PreprocessorProvider(Paths.get("borland"), Optional.of(CxxToolProvider.Type.GCC));
    CxxPlatform borlandCxx452Platform = CxxPlatform.builder().setFlavor(InternalFlavor.of("borland_cxx_452")).setAs(compiler).setAspp(preprocessor).setCc(compiler).setCpp(preprocessor).setCxx(compiler).setCxxpp(preprocessor).setLd(new DefaultLinkerProvider(LinkerProvider.Type.GNU, new ConstantToolProvider(new HashedFileTool(Paths.get("borland"))))).setStrip(new HashedFileTool(Paths.get("borland"))).setSymbolNameTool(new PosixNmSymbolNameTool(new HashedFileTool(Paths.get("borland")))).setAr(new GnuArchiver(new HashedFileTool(Paths.get("borland")))).setRanlib(new HashedFileTool(Paths.get("borland"))).setSharedLibraryExtension("so").setSharedLibraryVersionedExtensionFormat(".so.%s").setStaticLibraryExtension("a").setObjectFileExtension("so").setCompilerDebugPathSanitizer(CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER).setAssemblerDebugPathSanitizer(CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER).setHeaderVerification(CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification()).build();
    BuckConfig buckConfig = FakeBuckConfig.builder().setSections(sections).build();
    assertThat(CxxPlatforms.getConfigDefaultCxxPlatform(new CxxBuckConfig(buckConfig), ImmutableMap.of(borlandCxx452Platform.getFlavor(), borlandCxx452Platform), CxxPlatformUtils.DEFAULT_PLATFORM), equalTo(borlandCxx452Platform));
}
Also used : ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) ImmutableMap(com.google.common.collect.ImmutableMap) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) HashedFileTool(com.facebook.buck.rules.HashedFileTool) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)702 Map (java.util.Map)346 Test (org.junit.Test)195 HashMap (java.util.HashMap)144 ImmutableList (com.google.common.collect.ImmutableList)126 Path (java.nio.file.Path)104 List (java.util.List)100 ImmutableSet (com.google.common.collect.ImmutableSet)89 IOException (java.io.IOException)84 ArrayList (java.util.ArrayList)74 Set (java.util.Set)69 Optional (java.util.Optional)61 BuildTarget (com.facebook.buck.model.BuildTarget)57 File (java.io.File)57 Collectors (java.util.stream.Collectors)45 HashSet (java.util.HashSet)44 SourcePath (com.facebook.buck.rules.SourcePath)41 VisibleForTesting (com.google.common.annotations.VisibleForTesting)39 Nullable (javax.annotation.Nullable)39 LinkedHashMap (java.util.LinkedHashMap)36