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();
}
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);
}
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()));
}
}
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();
}
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));
}
Aggregations