com.android.build.gradle.internal.publishing.AndroidArtifacts Java Examples

The following examples show how to use com.android.build.gradle.internal.publishing.AndroidArtifacts. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardizeLibManifestTask.java    From atlas with Apache License 2.0 6 votes vote down vote up
@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);

        }
 
Example #2
Source File: BuildAtlasEnvTask.java    From atlas with Apache License 2.0 6 votes vote down vote up
@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");
    }
}
 
Example #3
Source File: AtlasDependencyGraph.java    From atlas with Apache License 2.0 6 votes vote down vote up
@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");
    }
}
 
Example #4
Source File: AtlasDependencyGraph.java    From atlas with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: GenerateHensonNavigatorTask.java    From dart with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #6
Source File: CompileDependenciesFileGenerator.java    From Phantom with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #7
Source File: CompileDependenciesFileGenerator.java    From Phantom with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #8
Source File: AwbJavaCompileConfigAction.java    From atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #9
Source File: AwbDataBindingExportBuildInfoTask.java    From atlas with Apache License 2.0 4 votes vote down vote up
@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));

        }
 
Example #10
Source File: AppendMainArtifactsCollection.java    From atlas with Apache License 2.0 4 votes vote down vote up
public AppendMainArtifactsCollection(Project project, ArtifactCollection artifactResults, AwbBundle awbBundle, AndroidArtifacts.ArtifactType artifactType) {
    this.artifactResults = artifactResults;
    this.awbBundle = awbBundle;
    this.project = project;
    this.artifactType = artifactType;
}
 
Example #11
Source File: AppendMainArtifactsCollection.java    From atlas with Apache License 2.0 4 votes vote down vote up
public AppendMainArtifactsCollection(Project project, FileCollection filesResults, AwbBundle awbBundle, AndroidArtifacts.ArtifactType artifactType) {
    this.filesResults = filesResults;
    this.awbBundle = awbBundle;
    this.project = project;
    this.artifactType = artifactType;
}
 
Example #12
Source File: BuildAtlasEnvTask.java    From atlas with Apache License 2.0 4 votes vote down vote up
@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();
                }
            });

        }
 
Example #13
Source File: AtlasConfigurationHelper.java    From atlas with Apache License 2.0 4 votes vote down vote up
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);
                }
        );


    }
 
Example #14
Source File: AtlasDependencyGraph.java    From atlas with Apache License 2.0 4 votes vote down vote up
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;
}