use of com.android.build.gradle.internal.dependency.FilteredArtifactCollection 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");
}
}
}
}
});
}
use of com.android.build.gradle.internal.dependency.FilteredArtifactCollection in project atlas by alibaba.
the class AtlasDependencyGraph method computeArtifactCollection.
public static ArtifactCollection computeArtifactCollection(VariantScope variantScope, @NonNull AtlasAndroidArtifacts.ConsumedConfigType configType, @NonNull AndroidArtifacts.ArtifactScope scope, @NonNull AtlasAndroidArtifacts.AtlasArtifactType artifactType) {
Configuration configuration;
switch(configType) {
case COMPILE_CLASSPATH:
configuration = variantScope.getVariantData().getVariantDependency().getCompileClasspath();
break;
case RUNTIME_CLASSPATH:
configuration = variantScope.getVariantData().getVariantDependency().getRuntimeClasspath();
break;
case BUNDLECOMPILE_CLASSPATH:
configuration = variantScope.getGlobalScope().getProject().getConfigurations().maybeCreate(AtlasPlugin.BUNDLE_COMPILE);
break;
case ANNOTATION_PROCESSOR:
configuration = variantScope.getVariantData().getVariantDependency().getAnnotationProcessorConfiguration();
break;
case METADATA_VALUES:
configuration = variantScope.getVariantData().getVariantDependency().getMetadataValuesConfiguration();
break;
default:
throw new RuntimeException("unknown ConfigType value");
}
Action<AttributeContainer> attributes = container -> container.attribute(ARTIFACT_TYPE, artifactType.getType());
Spec<ComponentIdentifier> filter = getComponentFilter(scope);
boolean lenientMode = Boolean.TRUE.equals(variantScope.getGlobalScope().getProjectOptions().get(BooleanOption.IDE_BUILD_MODEL_ONLY));
ArtifactCollection artifacts = configuration.getIncoming().artifactView(config -> {
config.attributes(attributes);
if (filter != null) {
config.componentFilter(filter);
}
// TODO somehow read the unresolved dependencies?
config.lenient(lenientMode);
}).getArtifacts();
if (configType == AtlasAndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH && variantScope.getVariantConfiguration().getType() == VariantType.FEATURE && artifactType != AtlasAndroidArtifacts.AtlasArtifactType.FEATURE_TRANSITIVE_DEPS) {
artifacts = new FilteredArtifactCollection(variantScope.getGlobalScope().getProject(), artifacts, computeArtifactCollection(variantScope, AtlasAndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH, scope, AtlasAndroidArtifacts.AtlasArtifactType.FEATURE_TRANSITIVE_DEPS).getArtifactFiles());
}
return artifacts;
}
Aggregations