Java源码示例:com.android.build.gradle.internal.publishing.AndroidArtifacts
示例1
@Override
public void execute(StandardizeLibManifestTask task) {
VariantScope variantScope = appVariantContext.getScope();
final GradleVariantConfiguration config = variantScope.getVariantConfiguration();
task.mainManifestFile = config.getMainManifest();
task.libraryManifests = variantScope.getArtifactCollection(AndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH, AndroidArtifacts.ArtifactScope.ALL, AndroidArtifacts.ArtifactType.MANIFEST);
task.appVariantContext = appVariantContext;
baseVariantOutput.getProcessManifest().doFirst(
new PreProcessManifestAction(appVariantContext, baseVariantOutput));
// if (!appVariantContext.getAtlasExtension().getTBuildConfig().isIncremental()) {
baseVariantOutput.getProcessManifest().doLast(
new PostProcessManifestAction(appVariantContext, baseVariantOutput));
File proxySrcDir = appVariantContext.getAtlasProxySourceDir();
appVariantContext.getVariantData().javacTask.source(proxySrcDir);
}
示例2
@Nullable
private static Spec<ComponentIdentifier> getComponentFilter(
@NonNull AndroidArtifacts.ArtifactScope scope) {
switch (scope) {
case ALL:
return null;
case EXTERNAL:
// since we want both Module dependencies and file based dependencies in this case
// the best thing to do is search for non ProjectComponentIdentifier.
return id -> !(id instanceof ProjectComponentIdentifier);
case MODULE:
return id -> id instanceof ProjectComponentIdentifier;
default:
throw new RuntimeException("unknown ArtifactScope value");
}
}
示例3
@Nullable
private static Spec<ComponentIdentifier> getComponentFilter(
@NonNull AndroidArtifacts.ArtifactScope scope) {
switch (scope) {
case ALL:
return null;
case EXTERNAL:
// since we want both Module dependencies and file based dependencies in this case
// the best thing to do is search for non ProjectComponentIdentifier.
return id -> !(id instanceof ProjectComponentIdentifier);
case MODULE:
return id -> id instanceof ProjectComponentIdentifier;
default:
throw new RuntimeException("unknown ArtifactScope value");
}
}
示例4
@NonNull
private static ArtifactCollection computeArtifactList(
@NonNull VariantScope variantScope,
@NonNull AtlasAndroidArtifacts.ConsumedConfigType consumedConfigType,
@NonNull AndroidArtifacts.ArtifactScope scope,
@NonNull AtlasAndroidArtifacts.AtlasArtifactType type) {
ArtifactCollection artifacts =
computeArtifactCollection(variantScope,consumedConfigType, scope, type);
// because the ArtifactCollection could be a collection over a test variant which ends
// up being a ArtifactCollectionWithExtraArtifact, we need to get the actual list
// without the tested artifact.
if (artifacts instanceof ArtifactCollectionWithExtraArtifact) {
return ((ArtifactCollectionWithExtraArtifact) artifacts).getParentArtifacts();
}
return artifacts;
}
示例5
@InputFiles
@Classpath
FileCollection getJarDependencies() {
//Thanks to Xavier Durcrohet for this
//https://android.googlesource.com/platform/tools/base/+/gradle_3.0.0/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/scope/VariantScopeImpl.java#1037
Action<AttributeContainer> attributes =
container ->
container.attribute(ARTIFACT_TYPE, AndroidArtifacts.ArtifactType.CLASSES.getType());
boolean lenientMode = false;
return variant
.getCompileConfiguration()
.getIncoming()
.artifactView(
config -> {
config.attributes(attributes);
config.lenient(lenientMode);
})
.getArtifacts()
.getArtifactFiles();
}
示例6
private Set<String> getCompileArtifactsForAgp31x() {
ImmutableMap<String, String> buildMapping = ModelBuilder.computeBuildMapping(project.getGradle());
final Set<ArtifactDependencyGraph.HashableResolvedArtifactResult> allArtifacts =
ArtifactDependencyGraph.getAllArtifacts(
applicationVariant.getVariantData().getScope(),
AndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH,
null,
buildMapping);
return getMavenArtifacts(allArtifacts);
}
示例7
private Set<String> getCompileArtifactsForAgp30x() {
final Set<ArtifactDependencyGraph.HashableResolvedArtifactResult> allArtifacts = Reflect.on("com.android.build.gradle.internal.ide.ArtifactDependencyGraph")
.call("getAllArtifacts",
applicationVariant.getVariantData().getScope(),
AndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH,
null)
.get();
return getMavenArtifacts(allArtifacts);
}
示例8
private FileCollection getInputJars() {
FileCollection classpath = scope.getJavaClasspath(AndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH, AndroidArtifacts.ArtifactType.JAR);
Set<File> dependencies = new HashSet<File>();
dependencies.addAll(classpath.getFiles());
//Increase the awb dependency
dependencies.addAll(awbBundle.getLibraryJars());
FileCollection allClassPatch = appVariantOutputContext.getVariantContext()
.getProject()
.files(dependencies);
return allClassPatch;
}
示例9
@Override
public void execute(DataBindingExportBuildInfoTask task) {
final BaseVariantData variantData = appVariantContext.getScope()
.getVariantData();
task.setXmlProcessor(
AwbXmlProcessor.getLayoutXmlProcessor(appVariantContext, awbBundle, dataBindingBuilder));
task.setSdkDir(appVariantContext.getScope().getGlobalScope().getSdkHandler().getSdkFolder());
if (!appVariantContext.getAwbLayoutInfoOutputForDataBinding(awbBundle).exists()) {
appVariantContext.getAwbLayoutInfoOutputForDataBinding(awbBundle).mkdirs();
}
task.setXmlOutFolder(appVariantContext.getAwbLayoutInfoOutputForDataBinding(awbBundle));
ReflectUtils.updateField(task, "compilerClasspath", (Supplier<FileCollection>) () -> appVariantContext.getScope().getJavaClasspath(AndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH, AndroidArtifacts.ArtifactType.CLASSES));
Object o = new Supplier<Collection<ConfigurableFileTree>>() {
@Override
public Collection<ConfigurableFileTree> get() {
Iterable ier = Iterables.filter(appVariantContext.getAwSourceOutputDir(awbBundle), new Predicate<ConfigurableFileTree>() {
@Override
public boolean apply(ConfigurableFileTree input) {
File dataBindingOut = appVariantContext
.getAwbClassOutputForDataBinding(awbBundle);
return !dataBindingOut.equals(input.getDir());
}
});
return ImmutableList.copyOf(ier);
}
};
ReflectUtils.updateField(task, "compilerSources", o);
// new Predicate<ConfigurableFileTree>() {
// @Override
// public boolean apply(ConfigurableFileTree input) {
// File
// dataBindingOut = appVariantContext
// .getAwbClassOutputForDataBinding(awbBundle);
// return !dataBindingOut.equals(input.getDir());
// }
// })));
//
// ConventionMappingHelper
// .map(task, "compilerSources", new Callable<Iterable<ConfigurableFileTree>>() {
// @Override
// public Iterable<ConfigurableFileTree> call() throws Exception {
// return Iterables.filter(appVariantContext.getAwSourceOutputDir(awbBundle),
// new Predicate<ConfigurableFileTree>() {
// @Override
// public boolean apply(ConfigurableFileTree input) {
// File
// dataBindingOut = appVariantContext
// .getAwbClassOutputForDataBinding(awbBundle);
// return !dataBindingOut.equals(input.getDir());
// }
// });
// }
// });
task.setExportClassListTo(variantData.getType().isExportDataBindingClassList() ?
new File(appVariantContext.getAwbLayoutFolderOutputForDataBinding(awbBundle),
"_generated.txt") : null);
//task.setPrintMachineReadableErrors(printMachineReadableErrors);
task.setDataBindingClassOutput(appVariantContext.getAwbClassOutputForDataBinding(awbBundle));
}
示例10
public AppendMainArtifactsCollection(Project project, ArtifactCollection artifactResults, AwbBundle awbBundle, AndroidArtifacts.ArtifactType artifactType) {
this.artifactResults = artifactResults;
this.awbBundle = awbBundle;
this.project = project;
this.artifactType = artifactType;
}
示例11
public AppendMainArtifactsCollection(Project project, FileCollection filesResults, AwbBundle awbBundle, AndroidArtifacts.ArtifactType artifactType) {
this.filesResults = filesResults;
this.awbBundle = awbBundle;
this.project = project;
this.artifactType = artifactType;
}
示例12
@Override
public void execute(BuildAtlasEnvTask updateDependenciesTask) {
super.execute(updateDependenciesTask);
updateDependenciesTask.appVariantContext = this.appVariantContext;
updateDependenciesTask.compileManifests =
appVariantContext.getScope().getArtifactCollection(COMPILE_CLASSPATH, ALL, MANIFEST);
updateDependenciesTask.compileJars =
appVariantContext.getScope().getArtifactCollection(COMPILE_CLASSPATH, ALL, CLASSES);
updateDependenciesTask.appVariantOutputContext = getAppVariantOutputContext();
updateDependenciesTask.nativeLibs = appVariantContext.getScope().getArtifactCollection(COMPILE_CLASSPATH, ALL, JNI);
updateDependenciesTask.nativeLibs2 = AtlasDependencyGraph.computeArtifactCollection(variantContext.getScope(), AtlasAndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH, ALL, AtlasAndroidArtifacts.AtlasArtifactType.LIBS);
updateDependenciesTask.javaResources = appVariantContext.getScope().getArtifactCollection(COMPILE_CLASSPATH, ALL, JAVA_RES);
updateDependenciesTask.res = appVariantContext.getScope().getArtifactCollection(COMPILE_CLASSPATH, ALL, ANDROID_RES);
updateDependenciesTask.assets = appVariantContext.getScope().getArtifactCollection(COMPILE_CLASSPATH, ALL, ASSETS);
updateDependenciesTask.symbolListWithPackageNames = appVariantContext.getScope().getArtifactCollection(
RUNTIME_CLASSPATH,
ALL,
AndroidArtifacts.ArtifactType.SYMBOL_LIST_WITH_PACKAGE_NAME);
List<ProjectDependency> projectDependencies = new ArrayList<>();
appVariantContext.getScope().getVariantDependencies().getCompileClasspath().getAllDependencies().forEach(dependency -> {
if (dependency instanceof ProjectDependency) {
projectDependencies.add((ProjectDependency) dependency);
// ((ProjectDependency) dependency).getDependencyProject().getConfigurations().getByName("compile").
// getIncoming()
// .artifactView(
// config -> {
// config.attributes(attributes);
// if (filter != null) {
// config.componentFilter(filter);
// }
// // TODO somehow read the unresolved dependencies?
// config.lenient(lenientMode);
// })
// .getArtifacts();
}
});
}
示例13
public void registAtlasStreams() {
DependencyHandler dependencyHandler = project.getDependencies();
final String explodedAwbType = AtlasAndroidArtifacts.TYPE_EXPLODED_AWB;
final String explodedApType = AtlasAndroidArtifacts.TYPE_EXPLODED_AP;
final String explodedSolibType = AtlasAndroidArtifacts.TYPE_EXPLODED_SOLIB;
dependencyHandler.registerTransform(
reg -> {
reg.getFrom().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.TYPE_AWB);
reg.getTo().attribute(ARTIFACT_FORMAT, explodedAwbType);
reg.artifactTransform(ExtractAwbTransform.class);
});
for (AndroidArtifacts.ArtifactType transformTarget : AarTransform.getTransformTargets()) {
dependencyHandler.registerTransform(
reg -> {
reg.getFrom().attribute(ARTIFACT_FORMAT, explodedAwbType);
reg.getTo().attribute(ARTIFACT_FORMAT, transformTarget.getType());
reg.artifactTransform(
AarTransform.class, config -> config.params(transformTarget));
});
}
dependencyHandler.registerTransform(
reg -> {
reg.getFrom().attribute(ARTIFACT_FORMAT, explodedAwbType);
reg.getTo()
.attribute(
ARTIFACT_FORMAT,
AndroidArtifacts.ArtifactType.SYMBOL_LIST_WITH_PACKAGE_NAME.getType());
reg.artifactTransform(LibrarySymbolTableTransform.class);
});
dependencyHandler.registerTransform(
reg -> {
reg.getFrom().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.TYPE_AP);
reg.getTo().attribute(ARTIFACT_FORMAT, explodedApType);
reg.artifactTransform(ExtractApTransform.class);
});
dependencyHandler.registerTransform(
reg -> {
reg.getFrom().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.TYPE_SOLIB);
reg.getTo().attribute(ARTIFACT_FORMAT, explodedSolibType);
reg.artifactTransform(ExtractSolibTransform.class);
});
dependencyHandler.registerTransform(
reg -> {
reg.getFrom().attribute(ARTIFACT_FORMAT, explodedSolibType);
reg.getTo().attribute(ARTIFACT_FORMAT, AndroidArtifacts.ArtifactType.JNI.getType());
reg.artifactTransform(LoadSolibTransform.class);
});
dependencyHandler.registerTransform(
reg -> {
reg.getFrom().attribute(ARTIFACT_FORMAT, explodedAwbType);
reg.getTo().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.TYPE_LIBS);
reg.artifactTransform(LoadSolibFromLibsTransform.class);
}
);
dependencyHandler.registerTransform(
reg -> {
reg.getFrom().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.AtlasArtifactType.EXPLODED_AAR.getType());
reg.getTo().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.TYPE_LIBS);
reg.artifactTransform(LoadSolibFromLibsTransform.class);
}
);
}
示例14
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;
}