Search in sources :

Example 1 with JarExtractTask

use of com.taobao.android.builder.tasks.library.JarExtractTask in project atlas by alibaba.

the class AtlasLibTaskManager method runTask.

@Override
public void runTask() {
    new UpdatePomTask(project).updatePom();
    libraryExtension.getLibraryVariants().forEach(libraryVariant -> {
        LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, libraryExtension);
        TBuildType tBuildType = libVariantContext.getBuildType();
        if (null != tBuildType) {
            try {
                new AwoPropHandler().process(tBuildType, atlasExtension.getBundleConfig());
            } catch (Exception e) {
                throw new GradleException("process awo exception", e);
            }
        }
        AwbGenerator awbGenerator = new AwbGenerator(atlasExtension);
        Collection<BaseVariantOutput> list = libVariantContext.getBaseVariant().getOutputs();
        if (null != list) {
            for (BaseVariantOutput libVariantOutputData : list) {
                Zip zipTask = ((LibraryVariantOutput) (libVariantOutputData)).getPackageLibrary();
                if (atlasExtension.getBundleConfig().isJarEnabled()) {
                    new JarExtractTask().generateJarArtifict(zipTask);
                }
                // Build the awb and extension
                if (atlasExtension.getBundleConfig().isAwbBundle()) {
                    awbGenerator.generateAwbArtifict(zipTask, libVariantContext);
                }
                if (null != tBuildType && (StringUtils.isNotEmpty(tBuildType.getBaseApDependency()) || null != tBuildType.getBaseApFile()) && libraryVariant.getName().equals("debug")) {
                    atlasExtension.getTBuildConfig().setUseCustomAapt(true);
                    libVariantContext.setBundleTask(zipTask);
                    try {
                        libVariantContext.setAwbBundle(awbGenerator.createAwbBundle(libVariantContext));
                    } catch (IOException e) {
                        throw new GradleException("set awb bundle error");
                    }
                // if (atlasExtension.getBundleConfig().isAwbBundle()) {
                // createAwoTask(libVariantContext, zipTask);
                // } else {
                // createDexTask(libVariantContext, zipTask);
                // }
                }
            }
        // List<TransformTask>transformTasks =  TransformManager.findTransformTaskByTransformType(libVariantContext,LibraryAarJarsTransform.class);
        // for (TransformTask transformTask: transformTasks){
        // Transform transform = transformTask.getTransform();
        // if (transform instanceof LibraryBaseTransform){
        // ReflectUtils.updateField(transform,"excludeListProviders", Lists.newArrayList(new AtlasExcludeListProvider()));
        // }
        // }
        }
    });
}
Also used : Zip(org.gradle.api.tasks.bundling.Zip) JarExtractTask(com.taobao.android.builder.tasks.library.JarExtractTask) UpdatePomTask(com.taobao.android.builder.tasks.library.publish.UpdatePomTask) LibVariantContext(com.android.build.gradle.internal.api.LibVariantContext) IOException(java.io.IOException) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) AwoPropHandler(com.taobao.android.builder.tools.ideaplugin.AwoPropHandler) BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) AwbGenerator(com.taobao.android.builder.tasks.library.AwbGenerator) GradleException(org.gradle.api.GradleException) LibraryVariantOutput(com.android.build.gradle.api.LibraryVariantOutput) TBuildType(com.taobao.android.builder.extension.TBuildType)

Example 2 with JarExtractTask

use of com.taobao.android.builder.tasks.library.JarExtractTask in project atlas by alibaba.

the class AtlasFeatureTaskManager method runTask.

@Override
public void runTask() {
    if (featureExtension.getBaseFeature()) {
        return;
    }
    featureExtension.getFeatureVariants().forEach(featureVariant -> {
        FeatureVariantContext featureVariantContext = new FeatureVariantContext((FeatureVariantImpl) featureVariant, project, atlasExtension, featureExtension);
        ArtifactCollection allArtifacts = featureVariantContext.getScope().getArtifactCollection(AndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH, AndroidArtifacts.ArtifactScope.EXTERNAL, AndroidArtifacts.ArtifactType.CLASSES);
        ArtifactCollection artifacts = featureVariantContext.getScope().getArtifactCollection(AndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH, AndroidArtifacts.ArtifactScope.ALL, AndroidArtifacts.ArtifactType.FEATURE_TRANSITIVE_DEPS);
        ArtifactCollection filterArtifacts = new FilteredArtifactCollection(featureVariantContext.getProject(), allArtifacts, artifacts.getArtifactFiles());
        List<TransformTask> transformTasks = TransformManager.findTransformTaskByTransformType(featureVariantContext, FixStackFramesTransform.class);
        if (transformTasks != null) {
            for (TransformTask transformTask : transformTasks) {
                try {
                    Field field = StreamBasedTask.class.getDeclaredField("consumedInputStreams");
                    Field field1 = StreamBasedTask.class.getDeclaredField("referencedInputStreams");
                    field1.setAccessible(true);
                    field.setAccessible(true);
                    Collection<TransformStream> consumedInputStreams = (Collection<TransformStream>) field.get(transformTask);
                    Collection<TransformStream> referencedInputStreams = (Collection<TransformStream>) field1.get(transformTask);
                    for (TransformStream stream : consumedInputStreams) {
                        if (stream.getContentTypes().contains(QualifiedContent.DefaultContentType.CLASSES) && stream.getScopes().contains(QualifiedContent.Scope.EXTERNAL_LIBRARIES)) {
                            ReflectUtils.updateField(stream, "fileCollection", filterArtifacts.getArtifactFiles());
                            ReflectUtils.updateField(stream, "artifactCollection", filterArtifacts);
                            break;
                        }
                    }
                    for (TransformStream transformStream : referencedInputStreams) {
                        if (transformStream.getContentTypes().contains(QualifiedContent.DefaultContentType.CLASSES) && transformStream.getScopes().contains(QualifiedContent.Scope.PROVIDED_ONLY)) {
                            ReflectUtils.updateField(transformStream, "fileCollection", project.files());
                        // ReflectUtils.updateField(transformStream, "artifactCollection", filterArtifacts);
                        }
                    }
                } catch (Exception e) {
                }
            }
        }
        featureVariantContext.getScope().getProcessResourcesTask().get(new TaskContainerAdaptor(featureVariantContext.getProject().getTasks())).setEnableAapt2(true);
    });
    featureExtension.getLibraryVariants().forEach(libraryVariant -> {
        LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, featureExtension);
        TBuildType tBuildType = libVariantContext.getBuildType();
        if (null != tBuildType) {
            try {
                new AwoPropHandler().process(tBuildType, atlasExtension.getBundleConfig());
            } catch (Exception e) {
                throw new GradleException("process awo exception", e);
            }
        }
        AwbGenerator awbGenerator = new AwbGenerator(atlasExtension);
        Collection<BaseVariantOutput> list = libVariantContext.getBaseVariant().getOutputs();
        if (null != list) {
            for (BaseVariantOutput libVariantOutputData : list) {
                Zip zipTask = ((LibraryVariantOutput) (libVariantOutputData)).getPackageLibrary();
                if (atlasExtension.getBundleConfig().isJarEnabled()) {
                    new JarExtractTask().generateJarArtifict(zipTask);
                }
                // Build the awb and extension
                // if (atlasExtension.getBundleConfig().isAwbBundle()) {
                awbGenerator.generateAwbArtifict(zipTask, libVariantContext);
                if (null != tBuildType && (StringUtils.isNotEmpty(tBuildType.getBaseApDependency()) || null != tBuildType.getBaseApFile()) && libraryVariant.getName().equals("debug")) {
                    atlasExtension.getTBuildConfig().setUseCustomAapt(true);
                    libVariantContext.setBundleTask(zipTask);
                    try {
                        libVariantContext.setAwbBundle(awbGenerator.createAwbBundle(libVariantContext));
                    } catch (IOException e) {
                        throw new GradleException("set awb bundle error");
                    }
                }
            }
        }
    });
}
Also used : Zip(org.gradle.api.tasks.bundling.Zip) FeatureVariantContext(com.android.build.gradle.internal.api.FeatureVariantContext) JarExtractTask(com.taobao.android.builder.tasks.library.JarExtractTask) LibVariantContext(com.android.build.gradle.internal.api.LibVariantContext) IOException(java.io.IOException) FilteredArtifactCollection(com.android.build.gradle.internal.dependency.FilteredArtifactCollection) TaskContainerAdaptor(com.android.build.gradle.internal.TaskContainerAdaptor) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) AwoPropHandler(com.taobao.android.builder.tools.ideaplugin.AwoPropHandler) Field(java.lang.reflect.Field) BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) AwbGenerator(com.taobao.android.builder.tasks.library.AwbGenerator) ArtifactCollection(org.gradle.api.artifacts.ArtifactCollection) FilteredArtifactCollection(com.android.build.gradle.internal.dependency.FilteredArtifactCollection) GradleException(org.gradle.api.GradleException) LibraryVariantOutput(com.android.build.gradle.api.LibraryVariantOutput) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Collection(java.util.Collection) ArtifactCollection(org.gradle.api.artifacts.ArtifactCollection) FilteredArtifactCollection(com.android.build.gradle.internal.dependency.FilteredArtifactCollection) FileCollection(org.gradle.api.file.FileCollection) TransformStream(com.android.build.gradle.internal.pipeline.TransformStream) TBuildType(com.taobao.android.builder.extension.TBuildType)

Aggregations

BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)2 LibraryVariantOutput (com.android.build.gradle.api.LibraryVariantOutput)2 LibVariantContext (com.android.build.gradle.internal.api.LibVariantContext)2 TBuildType (com.taobao.android.builder.extension.TBuildType)2 AwbGenerator (com.taobao.android.builder.tasks.library.AwbGenerator)2 JarExtractTask (com.taobao.android.builder.tasks.library.JarExtractTask)2 AwoPropHandler (com.taobao.android.builder.tools.ideaplugin.AwoPropHandler)2 IOException (java.io.IOException)2 GradleException (org.gradle.api.GradleException)2 Zip (org.gradle.api.tasks.bundling.Zip)2 TaskContainerAdaptor (com.android.build.gradle.internal.TaskContainerAdaptor)1 FeatureVariantContext (com.android.build.gradle.internal.api.FeatureVariantContext)1 FilteredArtifactCollection (com.android.build.gradle.internal.dependency.FilteredArtifactCollection)1 TransformStream (com.android.build.gradle.internal.pipeline.TransformStream)1 TransformTask (com.android.build.gradle.internal.pipeline.TransformTask)1 UpdatePomTask (com.taobao.android.builder.tasks.library.publish.UpdatePomTask)1 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1 ArtifactCollection (org.gradle.api.artifacts.ArtifactCollection)1 FileCollection (org.gradle.api.file.FileCollection)1