Search in sources :

Example 1 with OriginalStream

use of com.android.build.gradle.internal.pipeline.OriginalStream in project atlas by alibaba.

the class AtlasProguardTransform method doMainBundleProguard.

private void doMainBundleProguard(TransformInvocation invocation) throws Exception {
    // apply bundle Inout
    Profiler.enter("bundleKeep");
    File bundleKeep = AtlasProguardHelper.generateBundleKeepCfg(appVariantContext);
    Profiler.release();
    Input input = new Input();
    AwbBundle awbBundle = new AwbBundle();
    awbBundle.getAndroidLibraries().addAll(AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getVariantName()).getMainBundle().getAndroidLibraries());
    AwbTransform awbTransform = new AwbTransform(awbBundle);
    input.getAwbBundles().add(awbTransform);
    List<File> unProguardJars = new ArrayList<>();
    // Enter the input
    for (TransformInput transformInput : invocation.getInputs()) {
        for (JarInput jarInput : transformInput.getJarInputs()) {
            File file = jarInput.getFile();
            if (file.getName().startsWith("combined-rmerge")) {
                unProguardJars.add(file);
            } else if (AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).inMainDex(jarInput)) {
                awbTransform.getInputLibraries().add(file);
            }
        }
        for (DirectoryInput directoryInput : transformInput.getDirectoryInputs()) {
            if (AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).getInputDirs().contains(directoryInput.getFile())) {
                awbTransform.getInputLibraries().add(directoryInput.getFile());
            }
        }
    }
    // inputting librarys
    input.getLibraries().addAll(appVariantContext.getScope().getGlobalScope().getAndroidBuilder().getBootClasspath(true));
    input.getLibraries().addAll(unProguardJars);
    // The default proguard configuration
    input.getDefaultProguardFiles().addAll(defaultProguardFiles);
    // bundle keeps
    input.getParentKeeps().add(bundleKeep);
    File outFile = invocation.getOutputProvider().getContentLocation("main", getOutputTypes(), getScopes(), Format.JAR);
    outFile.delete();
    input.proguardOutputDir = invocation.getOutputProvider().getContentLocation("main", getOutputTypes(), getScopes(), Format.DIRECTORY);
    input.printMapping = (File) ReflectUtils.getField(oldTransform, "printMapping");
    input.dump = (File) ReflectUtils.getField(oldTransform, "dump");
    input.printSeeds = (File) ReflectUtils.getField(oldTransform, "printSeeds");
    input.printUsage = (File) ReflectUtils.getField(oldTransform, "printUsage");
    input.printConfiguration = new File(appVariantContext.getProject().getBuildDir(), "outputs/proguard.cfg");
    Profiler.enter("executeproguard");
    BundleProguarder.execute(appVariantContext, input);
    transformInput(input);
    Profiler.release();
    for (File jar : unProguardJars) {
        File to = invocation.getOutputProvider().getContentLocation(FileNameUtils.getUniqueJarName(jar), getOutputTypes(), getScopes(), Format.JAR);
        FileUtils.copyFile(jar, to);
    }
    OriginalStream originalStream = OriginalStream.builder(appVariantContext.getProject(), "proguard-classes").addContentTypes(com.android.build.gradle.internal.pipeline.TransformManager.CONTENT_CLASS).addScope(QualifiedContent.Scope.PROJECT).setFileCollection(appVariantContext.getProject().files(AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).getAllMainDexJars())).build();
    if (nextTransformTask != null) {
        Collection consumedInputStreams = (Collection) ReflectUtils.getField(nextTransformTask, "consumedInputStreams");
        if (appVariantContext.getAtlasExtension().getTBuildConfig().isFastProguard() && consumedInputStreams != null) {
            consumedInputStreams.add(originalStream);
        }
    }
}
Also used : Input(com.taobao.android.builder.tools.proguard.domain.Input) AwbTransform(com.android.build.gradle.internal.api.AwbTransform) ArrayList(java.util.ArrayList) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) Collection(java.util.Collection) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File) OriginalStream(com.android.build.gradle.internal.pipeline.OriginalStream)

Aggregations

AwbTransform (com.android.build.gradle.internal.api.AwbTransform)1 OriginalStream (com.android.build.gradle.internal.pipeline.OriginalStream)1 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)1 Input (com.taobao.android.builder.tools.proguard.domain.Input)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 ConfigurableFileCollection (org.gradle.api.file.ConfigurableFileCollection)1