use of com.android.ide.common.res2.FileStatus in project atlas by alibaba.
the class AwbApkPackageTask method splitIncrementalAction.
private File splitIncrementalAction(ApkData apkData, @Nullable File processedResources, Map<File, FileStatus> changedInputs) throws IOException {
Set<File> androidResources = getAndroidResources(apkData, processedResources);
File incrementalDirForSplit = new File(getIncrementalFolder(awbBundle), apkData.getFullName());
File cacheByPathDir = new File(incrementalDirForSplit, ZIP_DIFF_CACHE_DIR);
if (!cacheByPathDir.exists()) {
FileUtils.mkdirs(cacheByPathDir);
}
FileCacheByPath cacheByPath = new FileCacheByPath(cacheByPathDir);
KnownFilesSaveData saveData = KnownFilesSaveData.make(incrementalDirForSplit);
final Set<File> assetsFiles = assets.getFiles();
Set<Runnable> cacheUpdates = new HashSet<>();
ImmutableMap<RelativeFile, FileStatus> changedDexFiles = KnownFilesSaveData.getChangedInputs(changedInputs, saveData, KnownFilesSaveData.InputSet.DEX, dexFolders.getFiles(), cacheByPath, cacheUpdates);
ImmutableMap<RelativeFile, FileStatus> changedJavaResources;
try {
changedJavaResources = KnownFilesSaveData.getChangedInputs(changedInputs, saveData, KnownFilesSaveData.InputSet.JAVA_RESOURCE, javaResouresFiles.getFiles(), cacheByPath, cacheUpdates);
} catch (Zip64NotSupportedException e) {
// copy all changedInputs into a smaller jar and rerun.
ImmutableMap.Builder<File, FileStatus> copiedInputs = ImmutableMap.builder();
for (Map.Entry<File, FileStatus> fileFileStatusEntry : changedInputs.entrySet()) {
copiedInputs.put(copyJavaResourcesOnly(getIncrementalFolder(awbBundle), fileFileStatusEntry.getKey()), fileFileStatusEntry.getValue());
}
changedJavaResources = KnownFilesSaveData.getChangedInputs(copiedInputs.build(), saveData, KnownFilesSaveData.InputSet.JAVA_RESOURCE, javaResouresFiles.getFiles(), cacheByPath, cacheUpdates);
}
ImmutableMap<RelativeFile, FileStatus> changedAssets = KnownFilesSaveData.getChangedInputs(changedInputs, saveData, KnownFilesSaveData.InputSet.ASSET, assetsFiles, cacheByPath, cacheUpdates);
ImmutableMap<RelativeFile, FileStatus> changedAndroidResources = KnownFilesSaveData.getChangedInputs(changedInputs, saveData, KnownFilesSaveData.InputSet.ANDROID_RESOURCE, androidResources, cacheByPath, cacheUpdates);
ImmutableMap<RelativeFile, FileStatus> changedNLibs = KnownFilesSaveData.getChangedInputs(changedInputs, saveData, KnownFilesSaveData.InputSet.NATIVE_RESOURCE, jniFolders.getFiles(), cacheByPath, cacheUpdates);
File outputFile = getOutputFile(awbBundle);
Collection<BuildOutput> manifestOutputs = BuildOutputs.load(TaskOutputHolder.TaskOutputType.MERGED_MANIFESTS, awbManifestFolder.getSingleFile().getParentFile());
doTask(apkData, incrementalDirForSplit, outputFile, cacheByPath, manifestOutputs, changedDexFiles, changedJavaResources, changedAssets, changedAndroidResources, changedNLibs);
/*
* Update the cache
*/
cacheUpdates.forEach(Runnable::run);
/*
* Update the save data keep files.
*/
ImmutableMap<RelativeFile, FileStatus> allDex = IncrementalRelativeFileSets.fromZipsAndDirectories(dexFolders);
ImmutableMap<RelativeFile, FileStatus> allJavaResources = IncrementalRelativeFileSets.fromZipsAndDirectories(javaResouresFiles);
ImmutableMap<RelativeFile, FileStatus> allAssets = IncrementalRelativeFileSets.fromZipsAndDirectories(assetsFiles);
ImmutableMap<RelativeFile, FileStatus> allAndroidResources = IncrementalRelativeFileSets.fromZipsAndDirectories(androidResources);
ImmutableMap<RelativeFile, FileStatus> allJniResources = IncrementalRelativeFileSets.fromZipsAndDirectories(jniFolders);
saveData.setInputSet(allDex.keySet(), KnownFilesSaveData.InputSet.DEX);
saveData.setInputSet(allJavaResources.keySet(), KnownFilesSaveData.InputSet.JAVA_RESOURCE);
saveData.setInputSet(allAssets.keySet(), KnownFilesSaveData.InputSet.ASSET);
saveData.setInputSet(allAndroidResources.keySet(), KnownFilesSaveData.InputSet.ANDROID_RESOURCE);
saveData.setInputSet(allJniResources.keySet(), KnownFilesSaveData.InputSet.NATIVE_RESOURCE);
saveData.saveCurrentData();
return outputFile;
}
use of com.android.ide.common.res2.FileStatus in project atlas by alibaba.
the class AwbApkPackageTask method doTask.
private void doTask(@NonNull ApkData apkData, @NonNull File incrementalDirForSplit, @NonNull File outputFile, @NonNull FileCacheByPath cacheByPath, @NonNull Collection<BuildOutput> manifestOutputs, @NonNull ImmutableMap<RelativeFile, FileStatus> changedDex, @NonNull ImmutableMap<RelativeFile, FileStatus> changedJavaResources, @NonNull ImmutableMap<RelativeFile, FileStatus> changedAssets, @NonNull ImmutableMap<RelativeFile, FileStatus> changedAndroidResources, @NonNull ImmutableMap<RelativeFile, FileStatus> changedNLibs) throws IOException {
ImmutableMap.Builder<RelativeFile, FileStatus> javaResourcesForApk = ImmutableMap.builder();
javaResourcesForApk.putAll(changedJavaResources);
if (dexPackagingPolicy == DexPackagingPolicy.INSTANT_RUN_MULTI_APK) {
changedDex = ImmutableMap.copyOf(Maps.filterKeys(changedDex, Predicates.compose(Predicates.in(dexFolders.getFiles()), RelativeFile::getBase)));
}
final ImmutableMap<RelativeFile, FileStatus> dexFilesToPackage = changedDex;
String abiFilter = apkData.getFilter(com.android.build.OutputFile.FilterType.ABI);
// find the manifest file for this split.
BuildOutput manifestForSplit = OutputScope.getOutput(manifestOutputs, TaskOutputHolder.TaskOutputType.MERGED_MANIFESTS, apkData);
FileUtils.mkdirs(outputFile.getParentFile());
try (IncrementalPackager packager = new IncrementalPackagerBuilder().withOutputFile(outputFile).withSigning(null).withCreatedBy(androidBuilder.getCreatedBy()).withMinSdk(miniSdkVersion).withNativeLibraryPackagingMode(PackagingUtils.getNativeLibrariesLibrariesPackagingMode(manifestForSplit == null ? awbManifestFolder.getSingleFile() : manifestForSplit.getOutputFile())).withNoCompressPredicate(PackagingUtils.getNoCompressPredicate(aaptOptionsNoCompress, manifestForSplit == null ? awbManifestFolder.getSingleFile() : manifestForSplit.getOutputFile())).withIntermediateDir(incrementalDirForSplit).withProject(appVariantOutputContext.getScope().getGlobalScope().getProject()).withDebuggableBuild(debug).withAcceptedAbis(abiFilter == null ? supportAbis : ImmutableSet.of(abiFilter)).withJniDebuggableBuild(jniDebug).build()) {
packager.updateDex(dexFilesToPackage);
packager.updateJavaResources(changedJavaResources);
packager.updateAssets(changedAssets);
packager.updateAndroidResources(changedAndroidResources);
packager.updateNativeLibraries(changedNLibs);
// Only report APK as built if it has actually changed.
if (packager.hasPendingChangesWithWait()) {
// FIX-ME : below would not work in multi apk situations. There is code somewhere
// to ensure we only build ONE multi APK for the target device, make sure it is still
// active.
instantRunContext.addChangedFile(FileType.MAIN, outputFile);
}
}
/*
* Save all used zips in the cache.
*/
Stream.concat(dexFilesToPackage.keySet().stream(), Stream.concat(changedJavaResources.keySet().stream(), Stream.concat(changedAndroidResources.keySet().stream(), changedNLibs.keySet().stream()))).map(RelativeFile::getBase).filter(File::isFile).distinct().forEach((File f) -> {
try {
cacheByPath.add(f);
} catch (IOException e) {
throw new IOExceptionWrapper(e);
}
});
}
use of com.android.ide.common.res2.FileStatus in project atlas by alibaba.
the class AwbApkPackageTask method splitFullAction.
public File splitFullAction(@NonNull ApkData apkData, @Nullable File processedResources) throws IOException {
File incrementalDirForSplit = new File(getIncrementalFolder(awbBundle), apkData.getFullName());
/*
* Clear the intermediate build directory. We don't know if anything is in there and
* since this is a full build, we don't want to get any interference from previous state.
*/
if (incrementalDirForSplit.exists()) {
FileUtils.deleteDirectoryContents(incrementalDirForSplit);
} else {
FileUtils.mkdirs(incrementalDirForSplit);
}
File cacheByPathDir = new File(incrementalDirForSplit, ZIP_DIFF_CACHE_DIR);
FileUtils.mkdirs(cacheByPathDir);
FileCacheByPath cacheByPath = new FileCacheByPath(cacheByPathDir);
/*
* Clear the cache to make sure we have do not do an incremental build.
*/
cacheByPath.clear();
Set<File> androidResources = getAndroidResources(apkData, processedResources);
appVariantOutputContext.getVariantContext().getProject().getLogger().warn(awbBundle.getName() + " androidResources File:" + androidResources.iterator().next().getAbsolutePath());
FileUtils.mkdirs(outputDirectory);
File outputFile = getOutputFile(awbBundle);
/*
* Additionally, make sure we have no previous package, if it exists.
*/
FileUtils.deleteIfExists(outputFile);
ImmutableMap<RelativeFile, FileStatus> updatedDex = IncrementalRelativeFileSets.fromZipsAndDirectories(dexFolders);
ImmutableMap<RelativeFile, FileStatus> updatedJavaResources = getJavaResourcesChanges();
ImmutableMap<RelativeFile, FileStatus> updatedAssets = IncrementalRelativeFileSets.fromZipsAndDirectories(assets.getFiles());
ImmutableMap<RelativeFile, FileStatus> updatedAndroidResources = IncrementalRelativeFileSets.fromZipsAndDirectories(androidResources);
ImmutableMap<RelativeFile, FileStatus> updatedJniResources = IncrementalRelativeFileSets.fromZipsAndDirectories(jniFolders);
Collection<BuildOutput> manifestOutputs = BuildOutputs.load(TaskOutputHolder.TaskOutputType.MERGED_MANIFESTS, awbManifestFolder.getSingleFile().getParentFile());
doTask(apkData, incrementalDirForSplit, outputFile, cacheByPath, manifestOutputs, updatedDex, updatedJavaResources, updatedAssets, updatedAndroidResources, updatedJniResources);
/*
* Update the known files.
*/
KnownFilesSaveData saveData = KnownFilesSaveData.make(incrementalDirForSplit);
saveData.setInputSet(updatedDex.keySet(), KnownFilesSaveData.InputSet.DEX);
saveData.setInputSet(updatedJavaResources.keySet(), KnownFilesSaveData.InputSet.JAVA_RESOURCE);
saveData.setInputSet(updatedAssets.keySet(), KnownFilesSaveData.InputSet.ASSET);
saveData.setInputSet(updatedAndroidResources.keySet(), KnownFilesSaveData.InputSet.ANDROID_RESOURCE);
saveData.setInputSet(updatedJniResources.keySet(), KnownFilesSaveData.InputSet.NATIVE_RESOURCE);
saveData.saveCurrentData();
File file;
String outputFileName = outputFile.getName();
file = getAwbPackageOutputFile(appVariantOutputContext.getVariantContext(), outputFileName);
FileUtils.copyFileToDirectory(outputFile, file.getParentFile());
return new File(file.getParentFile(), outputFileName);
}
use of com.android.ide.common.res2.FileStatus in project atlas by alibaba.
the class AtlasIncrementalFileMergeTransformUtils method computeUpdates.
/**
* Computes all updates in a {@link DirectoryInput}.
*
* @param directoryInput the directory input
* @return a mapping from all files that have changed to the type of change
*/
@NonNull
private static ImmutableMap<RelativeFile, FileStatus> computeUpdates(@NonNull DirectoryInput directoryInput) {
ImmutableMap.Builder<RelativeFile, FileStatus> builder = ImmutableMap.builder();
Map<File, Status> changedFiles = directoryInput.getChangedFiles();
for (Map.Entry<File, Status> changedFile : changedFiles.entrySet()) {
RelativeFile rf = new RelativeFile(directoryInput.getFile(), changedFile.getKey());
FileStatus status = mapStatus(changedFile.getValue());
if (status != null && !(new File(rf.getBase(), rf.getRelativePath()).isDirectory())) {
builder.put(rf, status);
}
}
return builder.build();
}
Aggregations