use of com.google.common.collect.ImmutableList in project moco by dreamhead.
the class DefaultFailoverExecutor method restoreSessions.
private ImmutableList<Session> restoreSessions(final File file) {
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
List<Session> sessions = Jsons.toObject(inputStream, new TypeReference<List<Session>>() {
});
return copyOf(sessions);
} catch (MocoException me) {
logger.error("exception found", me);
return of();
} catch (IOException e) {
throw new MocoException(e);
} finally {
if (inputStream != null) {
Closeables.closeQuietly(inputStream);
}
}
}
use of com.google.common.collect.ImmutableList in project druid by druid-io.
the class WhiteListBasedDruidToTimelineEventConverter method readMap.
private ImmutableSortedMap<String, ImmutableList<String>> readMap(final String mapPath) {
String fileContent;
String actualPath = mapPath;
try {
if (Strings.isNullOrEmpty(mapPath)) {
actualPath = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json").getFile();
LOGGER.info("using default whiteList map located at [%s]", actualPath);
fileContent = CharStreams.toString(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("defaultWhiteListMap.json")));
} else {
fileContent = Files.asCharSource(new File(mapPath), Charset.forName("UTF-8")).read();
}
return mapper.reader(new TypeReference<ImmutableSortedMap<String, ImmutableList<String>>>() {
}).readValue(fileContent);
} catch (IOException e) {
throw new ISE(e, "Got an exception while parsing file [%s]", actualPath);
}
}
use of com.google.common.collect.ImmutableList in project buck by facebook.
the class AidlStep method getShellCommandInternal.
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
ImmutableList.Builder<String> args = ImmutableList.builder();
// The arguments passed to aidl are based off of what I observed when running Ant in verbose
// mode.
AndroidPlatformTarget androidPlatformTarget = context.getAndroidPlatformTarget();
verifyImportPaths(filesystem, importDirectoryPaths);
args.add(androidPlatformTarget.getAidlExecutable().toString());
// For some reason, all of the flags to aidl do not permit a space between the flag name and
// the flag value.
// file created by --preprocess to import
args.add("-p" + androidPlatformTarget.getAndroidFrameworkIdlFile().toString());
// search path for import statements
for (String importDirectoryPath : importDirectoryPaths) {
Path resolved = filesystem.getPathForRelativePath(Paths.get(importDirectoryPath));
args.add("-I" + resolved);
}
// base output folder for generated files
args.add("-o" + filesystem.resolve(destinationDirectory));
// aidl includes this path in the generated file and so it must not be absolute.
args.add(MorePaths.relativize(workingDirectory, aidlFilePath).toString());
return args.build();
}
use of com.google.common.collect.ImmutableList in project buck by facebook.
the class AndroidAar method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> commands = ImmutableList.builder();
// Create temp folder to store the files going to be zipped
commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));
// Remove the output .aar file
commands.add(new RmStep(getProjectFilesystem(), pathToOutputFile));
// put manifest into tmp folder
commands.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(manifest.getSourcePathToOutput()), temp.resolve("AndroidManifest.xml")));
// put R.txt into tmp folder
commands.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(Preconditions.checkNotNull(androidResource.getPathToTextSymbolsFile())), temp.resolve("R.txt")));
// put res/ and assets/ into tmp folder
commands.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(assembledResourceDirectory), temp.resolve("res"), CopyStep.DirectoryMode.CONTENTS_ONLY));
commands.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(assembledAssetsDirectory), temp.resolve("assets"), CopyStep.DirectoryMode.CONTENTS_ONLY));
// Create our Uber-jar, and place it in the tmp folder.
commands.add(new JarDirectoryStep(getProjectFilesystem(), temp.resolve("classes.jar"), context.getSourcePathResolver().getAllAbsolutePaths(classpathsToIncludeInJar), /* mainClass */
null, /* manifestFile */
null));
// move native libs into tmp folder under jni/
if (assembledNativeLibs.isPresent()) {
commands.add(CopyStep.forDirectory(getProjectFilesystem(), assembledNativeLibs.get(), temp.resolve("jni"), CopyStep.DirectoryMode.CONTENTS_ONLY));
}
// move native assets into tmp folder under assets/lib/
for (SourcePath dir : nativeLibAssetsDirectories) {
CopyNativeLibraries.copyNativeLibrary(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(dir), temp.resolve("assets").resolve("lib"), ImmutableSet.of(), commands);
}
// do the zipping
commands.add(new MkdirStep(getProjectFilesystem(), pathToOutputFile.getParent()));
commands.add(new ZipStep(getProjectFilesystem(), pathToOutputFile, ImmutableSet.of(), false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, temp));
buildableContext.recordArtifact(pathToOutputFile);
return commands.build();
}
use of com.google.common.collect.ImmutableList in project buck by facebook.
the class AndroidBinary method getBuildSteps.
@SuppressWarnings("PMD.PrematureDeclaration")
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
// The `HasInstallableApk` interface needs access to the manifest, so make sure we create our
// own copy of this so that we don't have a runtime dep on the `AaptPackageResources` step.
Path manifestPath = context.getSourcePathResolver().getRelativePath(getManifestPath());
steps.add(new MkdirStep(getProjectFilesystem(), manifestPath.getParent()));
steps.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(androidManifestPath), manifestPath));
buildableContext.recordArtifact(manifestPath);
// Create the .dex files if we aren't doing pre-dexing.
DexFilesInfo dexFilesInfo = addFinalDxSteps(buildableContext, context.getSourcePathResolver(), steps);
////
// BE VERY CAREFUL adding any code below here.
// Any inputs to apkbuilder must be reflected in the hash returned by getAbiKeyForDeps.
////
AndroidPackageableCollection packageableCollection = enhancementResult.getPackageableCollection();
ImmutableSet.Builder<Path> nativeLibraryDirectoriesBuilder = ImmutableSet.builder();
// Copy the transitive closure of native-libs-as-assets to a single directory, if any.
ImmutableSet.Builder<Path> nativeLibraryAsAssetDirectories = ImmutableSet.builder();
for (final APKModule module : enhancementResult.getAPKModuleGraph().getAPKModules()) {
boolean shouldPackageAssetLibraries = packageAssetLibraries || !module.isRootModule();
if (!ExopackageMode.enabledForNativeLibraries(exopackageModes) && enhancementResult.getCopyNativeLibraries().isPresent() && enhancementResult.getCopyNativeLibraries().get().containsKey(module)) {
CopyNativeLibraries copyNativeLibraries = enhancementResult.getCopyNativeLibraries().get().get(module);
if (shouldPackageAssetLibraries) {
nativeLibraryDirectoriesBuilder.add(copyNativeLibraries.getPathToNativeLibsDir());
} else {
nativeLibraryDirectoriesBuilder.add(copyNativeLibraries.getPathToNativeLibsDir());
nativeLibraryDirectoriesBuilder.add(copyNativeLibraries.getPathToNativeLibsAssetsDir());
}
}
if ((!packageableCollection.getNativeLibAssetsDirectories().isEmpty()) || (!packageableCollection.getNativeLinkablesAssets().isEmpty() && shouldPackageAssetLibraries)) {
Path pathForNativeLibsAsAssets = getPathForNativeLibsAsAssets();
final Path libSubdirectory = pathForNativeLibsAsAssets.resolve("assets").resolve(module.isRootModule() ? "lib" : module.getName());
ImmutableCollection<SourcePath> nativeLibDirs = packageableCollection.getNativeLibAssetsDirectories().get(module);
getStepsForNativeAssets(context.getSourcePathResolver(), steps, nativeLibDirs == null ? Optional.empty() : Optional.of(nativeLibDirs), libSubdirectory, module.isRootModule() ? "metadata.txt" : "libs.txt", module);
nativeLibraryAsAssetDirectories.add(pathForNativeLibsAsAssets);
}
}
// If non-english strings are to be stored as assets, pass them to ApkBuilder.
ImmutableSet.Builder<Path> zipFiles = ImmutableSet.builder();
RichStream.from(primaryApkAssetsZips).map(context.getSourcePathResolver()::getRelativePath).forEach(zipFiles::add);
if (ExopackageMode.enabledForNativeLibraries(exopackageModes)) {
// We need to include a few dummy native libraries with our application so that Android knows
// to run it as 32-bit. Android defaults to 64-bit when no libraries are provided at all,
// causing us to fail to load our 32-bit exopackage native libraries later.
String fakeNativeLibraryBundle = System.getProperty("buck.native_exopackage_fake_path");
if (fakeNativeLibraryBundle == null) {
throw new RuntimeException("fake native bundle not specified in properties");
}
zipFiles.add(Paths.get(fakeNativeLibraryBundle));
}
ImmutableSet<Path> allAssetDirectories = ImmutableSet.<Path>builder().addAll(nativeLibraryAsAssetDirectories.build()).addAll(dexFilesInfo.secondaryDexDirs).build();
SourcePathResolver resolver = context.getSourcePathResolver();
Path signedApkPath = getSignedApkPath();
final Path pathToKeystore = resolver.getAbsolutePath(keystorePath);
Supplier<KeystoreProperties> keystoreProperties = Suppliers.memoize(() -> {
try {
return KeystoreProperties.createFromPropertiesFile(pathToKeystore, resolver.getAbsolutePath(keystorePropertiesPath), getProjectFilesystem());
} catch (IOException e) {
throw new RuntimeException();
}
});
ApkBuilderStep apkBuilderCommand = new ApkBuilderStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(resourcesApkPath), getSignedApkPath(), dexFilesInfo.primaryDexPath, allAssetDirectories, nativeLibraryDirectoriesBuilder.build(), zipFiles.build(), packageableCollection.getPathsToThirdPartyJars().stream().map(resolver::getAbsolutePath).collect(MoreCollectors.toImmutableSet()), pathToKeystore, keystoreProperties, /* debugMode */
false, javaRuntimeLauncher);
steps.add(apkBuilderCommand);
// The `ApkBuilderStep` delegates to android tools to build a ZIP with timestamps in it, making
// the output non-deterministic. So use an additional scrubbing step to zero these out.
steps.add(new ZipScrubberStep(getProjectFilesystem(), signedApkPath));
Path apkToRedexAndAlign;
// Optionally, compress the resources file in the .apk.
if (this.isCompressResources()) {
Path compressedApkPath = getCompressedResourcesApkPath();
apkToRedexAndAlign = compressedApkPath;
RepackZipEntriesStep arscComp = new RepackZipEntriesStep(getProjectFilesystem(), signedApkPath, compressedApkPath, ImmutableSet.of("resources.arsc"));
steps.add(arscComp);
} else {
apkToRedexAndAlign = signedApkPath;
}
boolean applyRedex = redexOptions.isPresent();
Path apkPath = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
Path apkToAlign = apkToRedexAndAlign;
// redex
if (applyRedex) {
Path proguardConfigDir = getProguardTextFilesPath();
Path redexedApk = apkPath.getParent().resolve(apkPath.getFileName().toString() + ".redex");
apkToAlign = redexedApk;
ImmutableList<Step> redexSteps = ReDexStep.createSteps(getProjectFilesystem(), resolver, redexOptions.get(), apkToRedexAndAlign, redexedApk, keystoreProperties, proguardConfigDir, context.getSourcePathResolver());
steps.addAll(redexSteps);
}
steps.add(new ZipalignStep(getProjectFilesystem().getRootPath(), apkToAlign, apkPath));
buildableContext.recordArtifact(apkPath);
return steps.build();
}
Aggregations