com.android.builder.model.AndroidArtifact Java Examples
The following examples show how to use
com.android.builder.model.AndroidArtifact.
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: VariantImpl.java From javaide with GNU General Public License v3.0 | 6 votes |
VariantImpl(@NonNull String name, @NonNull String displayName, @NonNull String buildTypeName, @NonNull List<String> productFlavorNames, @NonNull ProductFlavorImpl mergedFlavor, @NonNull AndroidArtifact mainArtifactInfo, @NonNull Collection<AndroidArtifact> extraAndroidArtifacts, @NonNull Collection<JavaArtifact> extraJavaArtifacts) { this.name = name; this.displayName = displayName; this.buildTypeName = buildTypeName; this.productFlavorNames = productFlavorNames; this.mergedFlavor = mergedFlavor; this.mainArtifactInfo = mainArtifactInfo; this.extraAndroidArtifacts = extraAndroidArtifacts; this.extraJavaArtifacts = extraJavaArtifacts; }
Example #2
Source File: ResourceVisibilityLookup.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Looks up a (possibly cached) {@link ResourceVisibilityLookup} for the given {@link * AndroidArtifact} * * @param project the project * @return the corresponding {@link ResourceVisibilityLookup} */ @NonNull public ResourceVisibilityLookup get( @NonNull AndroidProject project, @NonNull Variant variant) { ResourceVisibilityLookup visibility = mInstances.get(variant); if (visibility == null) { if (isVisibilityAwareModel(project)) { AndroidArtifact artifact = variant.getMainArtifact(); visibility = get(artifact); } else { visibility = NONE; } mInstances.put(variant, visibility); } return visibility; }
Example #3
Source File: LintGradleProject.java From javaide with GNU General Public License v3.0 | 5 votes |
private List<SourceProvider> getSourceProviders() { if (mProviders == null) { List<SourceProvider> providers = Lists.newArrayList(); AndroidArtifact mainArtifact = mVariant.getMainArtifact(); providers.add(mProject.getDefaultConfig().getSourceProvider()); for (String flavorName : mVariant.getProductFlavors()) { for (ProductFlavorContainer flavor : mProject.getProductFlavors()) { if (flavorName.equals(flavor.getProductFlavor().getName())) { providers.add(flavor.getSourceProvider()); break; } } } SourceProvider multiProvider = mainArtifact.getMultiFlavorSourceProvider(); if (multiProvider != null) { providers.add(multiProvider); } String buildTypeName = mVariant.getBuildType(); for (BuildTypeContainer buildType : mProject.getBuildTypes()) { if (buildTypeName.equals(buildType.getBuildType().getName())) { providers.add(buildType.getSourceProvider()); break; } } SourceProvider variantProvider = mainArtifact.getVariantSourceProvider(); if (variantProvider != null) { providers.add(variantProvider); } mProviders = providers; } return mProviders; }
Example #4
Source File: PrivateResourceDetectorTest.java From javaide with GNU General Public License v3.0 | 5 votes |
public static AndroidArtifact createMockArtifact(List<AndroidLibrary> libraries) { Dependencies dependencies = mock(Dependencies.class); when(dependencies.getLibraries()).thenReturn(libraries); AndroidArtifact artifact = mock(AndroidArtifact.class); when(artifact.getDependencies()).thenReturn(dependencies); return artifact; }
Example #5
Source File: AndroidClassPathProvider.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
@Override public Iterable<? extends File> get() { Variant variant = buildConfig.getCurrentVariant(); if (variant != null) { AndroidArtifact testArtifact = AndroidBuildVariants.instrumentTestArtifact(variant.getExtraAndroidArtifacts()); Iterable<File> testCompileCPEntries = Collections.<File>singleton(variant.getMainArtifact().getClassesFolder()); if (testArtifact != null) { List<File> javaLibs = new ArrayList<>(); for (JavaLibrary lib : testArtifact.getDependencies().getJavaLibraries()) { collectJavaLibraries(javaLibs, lib); } testCompileCPEntries = Iterables.concat( testCompileCPEntries, Iterables.transform( testArtifact.getDependencies().getLibraries(), new Function<AndroidLibrary, File>() { @Override public File apply(AndroidLibrary f) { return f.getJarFile(); } }), javaLibs); } return testCompileCPEntries; } return Collections.<File>emptyList(); }
Example #6
Source File: AndroidBuildVariants.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
@Nullable public static AndroidArtifact instrumentTestArtifact(Iterable<AndroidArtifact> artifacts) { return artifacts == null ? null : Iterables.find( artifacts, new Predicate<AndroidArtifact>() { @Override public boolean apply(AndroidArtifact a) { return AndroidProject.ARTIFACT_ANDROID_TEST.equals(a.getName()); } }, null); }
Example #7
Source File: Project.java From javaide with GNU General Public License v3.0 | 4 votes |
/** * Returns the set of applicable densities for this project. If null, there are no density * restrictions and all densities apply. * * @return the list of specific densities that apply in this project, or null if all densities * apply */ @Nullable public List<String> getApplicableDensities() { if (mCachedApplicableDensities == null) { // Use the gradle API to set up relevant densities. For example, if the // build.gradle file contains this: // android { // defaultConfig { // resConfigs "nodpi", "hdpi" // } // } // ...then we should only enforce hdpi densities, not all these others! if (isGradleProject() && getGradleProjectModel() != null && getCurrentVariant() != null) { Set<String> relevantDensities = Sets.newHashSet(); Variant variant = getCurrentVariant(); List<String> variantFlavors = variant.getProductFlavors(); AndroidProject gradleProjectModel = getGradleProjectModel(); addResConfigsFromFlavor(relevantDensities, null, getGradleProjectModel().getDefaultConfig()); for (ProductFlavorContainer container : gradleProjectModel.getProductFlavors()) { addResConfigsFromFlavor(relevantDensities, variantFlavors, container); } // Are there any splits that specify densities? if (relevantDensities.isEmpty()) { AndroidArtifact mainArtifact = variant.getMainArtifact(); Collection<AndroidArtifactOutput> outputs = mainArtifact.getOutputs(); for (AndroidArtifactOutput output : outputs) { for (OutputFile file : output.getOutputs()) { final String DENSITY_NAME = OutputFile.FilterType.DENSITY.name(); if (file.getFilterTypes().contains(DENSITY_NAME)) { for (FilterData data : file.getFilters()) { if (DENSITY_NAME.equals(data.getFilterType())) { relevantDensities.add(data.getIdentifier()); } } } } } } if (!relevantDensities.isEmpty()) { mCachedApplicableDensities = Lists.newArrayListWithExpectedSize(10); for (String density : relevantDensities) { String folder = ResourceFolderType.DRAWABLE.getName() + '-' + density; mCachedApplicableDensities.add(folder); } Collections.sort(mCachedApplicableDensities); } else { mCachedApplicableDensities = Collections.emptyList(); } } else { mCachedApplicableDensities = Collections.emptyList(); } } return mCachedApplicableDensities.isEmpty() ? null : mCachedApplicableDensities; }
Example #8
Source File: VariantImpl.java From javaide with GNU General Public License v3.0 | 4 votes |
@NonNull @Override public AndroidArtifact getMainArtifact() { return mainArtifactInfo; }
Example #9
Source File: VariantImpl.java From javaide with GNU General Public License v3.0 | 4 votes |
@NonNull @Override public Collection<AndroidArtifact> getExtraAndroidArtifacts() { return extraAndroidArtifacts; }
Example #10
Source File: ModelBuilder.java From javaide with GNU General Public License v3.0 | 4 votes |
@NonNull private VariantImpl createVariant( @NonNull BaseVariantData<? extends BaseVariantOutputData> variantData) { AndroidArtifact mainArtifact = createAndroidArtifact(ARTIFACT_MAIN, variantData); GradleVariantConfiguration variantConfiguration = variantData.getVariantConfiguration(); String variantName = variantConfiguration.getFullName(); List<AndroidArtifact> extraAndroidArtifacts = Lists.newArrayList( extraModelInfo.getExtraAndroidArtifacts(variantName)); // Make sure all extra artifacts are serializable. Collection<JavaArtifact> extraJavaArtifacts = extraModelInfo.getExtraJavaArtifacts( variantName); List<JavaArtifact> clonedExtraJavaArtifacts = Lists.newArrayListWithCapacity( extraJavaArtifacts.size()); for (JavaArtifact javaArtifact : extraJavaArtifacts) { clonedExtraJavaArtifacts.add(JavaArtifactImpl.clone(javaArtifact)); } // if the target is a codename, override the model value. ApiVersion sdkVersionOverride = null; // we know the getTargetInfo won't return null here. @SuppressWarnings("ConstantConditions") IAndroidTarget androidTarget = androidBuilder.getTargetInfo().getTarget(); AndroidVersion version = androidTarget.getVersion(); if (version.getCodename() != null) { sdkVersionOverride = ApiVersionImpl.clone(version); } return new VariantImpl( variantName, variantConfiguration.getBaseName(), variantConfiguration.getBuildType().getName(), getProductFlavorNames(variantData), ProductFlavorImpl.cloneFlavor( variantConfiguration.getMergedFlavor(), sdkVersionOverride, sdkVersionOverride), mainArtifact, extraAndroidArtifacts, clonedExtraJavaArtifacts); }
Example #11
Source File: ModelBuilder.java From javaide with GNU General Public License v3.0 | 4 votes |
private AndroidArtifact createAndroidArtifact( @NonNull String name, @NonNull BaseVariantData<? extends BaseVariantOutputData> variantData) { VariantScope scope = variantData.getScope(); GradleVariantConfiguration variantConfiguration = variantData.getVariantConfiguration(); SigningConfig signingConfig = variantConfiguration.getSigningConfig(); String signingConfigName = null; if (signingConfig != null) { signingConfigName = signingConfig.getName(); } SourceProviders sourceProviders = determineSourceProviders(variantData); // get the outputs List<? extends BaseVariantOutputData> variantOutputs = variantData.getOutputs(); List<AndroidArtifactOutput> outputs = Lists.newArrayListWithCapacity(variantOutputs.size()); Collection<NativeLibrary> nativeLibraries = ImmutableList.of(); for (BaseVariantOutputData variantOutputData : variantOutputs) { int intVersionCode; if (variantOutputData instanceof ApkVariantOutputData) { intVersionCode = variantOutputData.getVersionCode(); } else { Integer versionCode = variantConfiguration.getMergedFlavor().getVersionCode(); intVersionCode = versionCode != null ? versionCode : 1; } ImmutableCollection.Builder<OutputFile> outputFiles = ImmutableList.builder(); // add the main APK outputFiles.add(new OutputFileImpl( variantOutputData.getMainOutputFile().getFilters(), variantOutputData.getMainOutputFile().getType().name(), variantOutputData.getOutputFile())); for (ApkOutputFile splitApk : variantOutputData.getOutputs()) { if (splitApk.getType() == OutputFile.OutputType.SPLIT) { outputFiles.add(new OutputFileImpl( splitApk.getFilters(), OutputFile.SPLIT, splitApk.getOutputFile())); } } // add the main APK. outputs.add(new AndroidArtifactOutputImpl( outputFiles.build(), "assemble" + variantOutputData.getFullName(), variantOutputData.getScope().getManifestOutputFile(), intVersionCode)); } return new AndroidArtifactImpl( name, outputs, variantData.assembleVariantTask == null ? scope.getTaskName("assemble") : variantData.assembleVariantTask.getName(), variantConfiguration.isSigningReady() || variantData.outputsAreSigned, signingConfigName, variantConfiguration.getApplicationId(), // TODO: Need to determine the tasks' name when the tasks may not be created // in component plugin. scope.getSourceGenTask() == null ? scope.getTaskName("generate", "Sources") : scope.getSourceGenTask().getName(), scope.getCompileTask() == null ? scope.getTaskName("compile", "Sources") : scope.getCompileTask().getName(), getGeneratedSourceFolders(variantData), getGeneratedResourceFolders(variantData), (variantData.javacTask != null) ? variantData.javacTask.getDestinationDir() : scope.getJavaOutputDir(), scope.getJavaResourcesDestinationDir(), DependenciesImpl.cloneDependencies(variantData, androidBuilder), sourceProviders.variantSourceProvider, sourceProviders.multiFlavorSourceProvider, nativeLibraries, variantConfiguration.getMergedBuildConfigFields(), variantConfiguration.getMergedResValues()); }
Example #12
Source File: ExtraModelInfo.java From javaide with GNU General Public License v3.0 | 4 votes |
public Collection<AndroidArtifact> getExtraAndroidArtifacts(@NonNull String variantName) { return extraAndroidArtifacts.get(variantName); }
Example #13
Source File: GradleDetectorTest.java From javaide with GNU General Public License v3.0 | 4 votes |
@Override protected TestLintClient createClient() { return new TestLintClient() { @Nullable @Override public File getSdkHome() { return getMockSupportLibraryInstallation(); } @NonNull @Override protected Project createProject(@NonNull File dir, @NonNull File referenceDir) { if (!"testDependenciesInVariables".equals(getName())) { return super.createProject(dir, referenceDir); } return new Project(this, dir, referenceDir) { @Override public boolean isGradleProject() { return true; } @Nullable @Override public Variant getCurrentVariant() { /* Simulate variant which has an AndroidLibrary with resolved coordinates com.google.android.gms:play-services-wearable:5.0.77" */ MavenCoordinates coordinates = mock(MavenCoordinates.class); when(coordinates.getGroupId()).thenReturn("com.google.android.gms"); when(coordinates.getArtifactId()).thenReturn("play-services-wearable"); when(coordinates.getVersion()).thenReturn("5.0.77"); AndroidLibrary library = mock(AndroidLibrary.class); when(library.getResolvedCoordinates()).thenReturn(coordinates); List<AndroidLibrary> libraries = Collections.singletonList(library); Dependencies dependencies = mock(Dependencies.class); when(dependencies.getLibraries()).thenReturn(libraries); AndroidArtifact artifact = mock(AndroidArtifact.class); when(artifact.getDependencies()).thenReturn(dependencies); Variant variant = mock(Variant.class); when(variant.getMainArtifact()).thenReturn(artifact); return variant; } }; } }; }
Example #14
Source File: PrivateResourceDetectorTest.java From javaide with GNU General Public License v3.0 | 4 votes |
@Override protected TestLintClient createClient() { return new TestLintClient() { @NonNull @Override protected Project createProject(@NonNull File dir, @NonNull File referenceDir) { return new Project(this, dir, referenceDir) { @Override public boolean isGradleProject() { return true; } @Nullable @Override public AndroidProject getGradleProjectModel() { // First version which supported private resources; this does not // need to track later versions we release return createMockProject("1.3.0-alpha2", 3); } @Nullable @Override public Variant getCurrentVariant() { try { AndroidLibrary library = createMockLibrary( "" + "int string my_private_string 0x7f040000\n" + "int string my_public_string 0x7f040001\n" + "int layout my_private_layout 0x7f040002\n", "" + "" + "string my_public_string\n", Collections.<AndroidLibrary>emptyList() ); AndroidArtifact artifact = createMockArtifact( Collections.singletonList(library)); Variant variant = mock(Variant.class); when(variant.getMainArtifact()).thenReturn(artifact); return variant; } catch (Exception e) { fail(e.toString()); return null; } } }; } }; }
Example #15
Source File: AndroidClassPathProvider.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public Iterable<? extends File> get() { SourceProviderContainer spc = androidProjectModel != null ? ProductFlavors.getSourceProviderContainer(androidProjectModel.getDefaultConfig(), AndroidProject.ARTIFACT_ANDROID_TEST) : null; Collection<File> javaDirs = spc != null ? spc.getSourceProvider().getJavaDirectories() : Collections.<File>emptySet(); Variant variant = buildConfig.getCurrentVariant(); Iterable<File> variantJavaDirs = variant != null ? Iterables.concat( Iterables.transform( variant.getProductFlavors(), new Function<String, Collection<File>>() { @Override public Collection<File> apply(String f) { if (androidProjectModel == null) { return Collections.<File>emptySet(); } final ProductFlavorContainer flavor = ProductFlavors.findFlavorByName(androidProjectModel.getProductFlavors(), f); if (flavor == null) { return Collections.<File>emptySet(); } SourceProviderContainer flavorSPC = ProductFlavors.getSourceProviderContainer( flavor, AndroidProject.ARTIFACT_ANDROID_TEST); if (flavorSPC == null) { return Collections.<File>emptySet(); } return flavorSPC.getSourceProvider().getJavaDirectories(); } })) : Collections.<File>emptySet(); AndroidArtifact testArtifact = variant != null ? AndroidBuildVariants.instrumentTestArtifact(variant.getExtraAndroidArtifacts()) : null; Collection<File> generatedJavaDirs = testArtifact != null ? testArtifact.getGeneratedSourceFolders() : Collections.<File>emptyList(); return Iterables.concat( javaDirs, variantJavaDirs, generatedJavaDirs); }