本文整理汇总了Java中com.android.builder.model.ProductFlavorContainer类的典型用法代码示例。如果您正苦于以下问题:Java ProductFlavorContainer类的具体用法?Java ProductFlavorContainer怎么用?Java ProductFlavorContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProductFlavorContainer类属于com.android.builder.model包,在下文中一共展示了ProductFlavorContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAndroidSources
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
private Map<String, Set<File>> getAndroidSources(ProductFlavorContainer defaultConfig) {
Map<String, Set<File>> sources = new HashMap<>();
ProductFlavor productFlavor = defaultConfig.getProductFlavor();
String name = productFlavor.getName();
SourceProvider sourceProvider = defaultConfig.getSourceProvider();
AndroidSupport.setAndroidSources(sources, sourceProvider, false);
// extra
Collection<SourceProviderContainer> extraSourceProviders =
defaultConfig.getExtraSourceProviders();
extraSourceProviders.forEach(
sourceProviderContainer -> {
String artifactName = sourceProviderContainer.getArtifactName();
SourceProvider provider = sourceProviderContainer.getSourceProvider();
boolean isTest = artifactName.contains(TEST_SUFFIX);
AndroidSupport.setAndroidSources(sources, provider, isTest);
});
return sources;
}
示例2: addResConfigsFromFlavor
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
/**
* Adds in the resConfig values specified by the given flavor container, assuming
* it's in one of the relevant variantFlavors, into the given set
*/
private static void addResConfigsFromFlavor(@NonNull Set<String> relevantDensities,
@Nullable List<String> variantFlavors,
@NonNull ProductFlavorContainer container) {
ProductFlavor flavor = container.getProductFlavor();
if (variantFlavors == null || variantFlavors.contains(flavor.getName())) {
if (!flavor.getResourceConfigurations().isEmpty()) {
for (String densityName : flavor.getResourceConfigurations()) {
Density density = Density.getEnum(densityName);
if (density != null && density.isRecommended()
&& density != Density.NODPI && density != Density.ANYDPI) {
relevantDensities.add(densityName);
}
}
}
}
}
示例3: getResConfigLanguages
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
@Nullable
private static List<String> getResConfigLanguages(@NonNull Project project) {
if (project.isGradleProject() && project.getGradleProjectModel() != null &&
project.getCurrentVariant() != null) {
Set<String> relevantDensities = Sets.newHashSet();
Variant variant = project.getCurrentVariant();
List<String> variantFlavors = variant.getProductFlavors();
AndroidProject gradleProjectModel = project.getGradleProjectModel();
addResConfigsFromFlavor(relevantDensities, null,
project.getGradleProjectModel().getDefaultConfig());
for (ProductFlavorContainer container : gradleProjectModel.getProductFlavors()) {
addResConfigsFromFlavor(relevantDensities, variantFlavors, container);
}
if (!relevantDensities.isEmpty()) {
ArrayList<String> strings = Lists.newArrayList(relevantDensities);
Collections.sort(strings);
return strings;
}
}
return null;
}
示例4: addResConfigsFromFlavor
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
/**
* Adds in the resConfig values specified by the given flavor container, assuming
* it's in one of the relevant variantFlavors, into the given set
*/
private static void addResConfigsFromFlavor(@NonNull Set<String> relevantLanguages,
@Nullable List<String> variantFlavors,
@NonNull ProductFlavorContainer container) {
ProductFlavor flavor = container.getProductFlavor();
if (variantFlavors == null || variantFlavors.contains(flavor.getName())) {
if (!flavor.getResourceConfigurations().isEmpty()) {
for (String resConfig : flavor.getResourceConfigurations()) {
// Look for languages; these are of length 2. (ResConfigs
// can also refer to densities, etc.)
if (resConfig.length() == 2) {
relevantLanguages.add(resConfig);
}
}
}
}
}
示例5: testSourceProviderContainsFile
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
public void testSourceProviderContainsFile() throws Exception {
assertNotNull(myAppFacet.getIdeaAndroidProject());
ProductFlavorContainer paidFlavor = myAppFacet.getIdeaAndroidProject().findProductFlavor("paid");
assertNotNull(paidFlavor);
IdeaSourceProvider paidFlavorSourceProvider = IdeaSourceProvider.create(paidFlavor.getSourceProvider());
assertNotNull(paidFlavorSourceProvider);
VirtualFile moduleFile = myAppFacet.getIdeaAndroidProject().getRootDir();
assertNotNull(moduleFile);
VirtualFile javaSrcFile = moduleFile.findFileByRelativePath("src/paid/java/com/example/projectwithappandlib/app/paid");
assertNotNull(javaSrcFile);
assertTrue(paidFlavorSourceProvider.containsFile(javaSrcFile));
VirtualFile javaMainSrcFile = moduleFile.findFileByRelativePath("src/main/java/com/example/projectwithappandlib/");
assertNotNull(javaMainSrcFile);
assertFalse(paidFlavorSourceProvider.containsFile(javaMainSrcFile));
}
示例6: testSourceProviderIsContainedByFolder
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
public void testSourceProviderIsContainedByFolder() throws Exception {
assertNotNull(myAppFacet.getIdeaAndroidProject());
ProductFlavorContainer paidFlavor = myAppFacet.getIdeaAndroidProject().findProductFlavor("paid");
assertNotNull(paidFlavor);
IdeaSourceProvider paidFlavorSourceProvider = IdeaSourceProvider.create(paidFlavor.getSourceProvider());
assertNotNull(paidFlavorSourceProvider);
VirtualFile moduleFile = myAppFacet.getIdeaAndroidProject().getRootDir();
assertNotNull(moduleFile);
VirtualFile javaSrcFile = moduleFile.findFileByRelativePath("src/paid/java/com/example/projectwithappandlib/app/paid");
assertNotNull(javaSrcFile);
assertFalse(paidFlavorSourceProvider.isContainedBy(javaSrcFile));
VirtualFile flavorRoot = moduleFile.findFileByRelativePath("src/paid");
assertNotNull(flavorRoot);
assertTrue(paidFlavorSourceProvider.isContainedBy(flavorRoot));
VirtualFile srcFile = moduleFile.findChild("src");
assertNotNull(srcFile);
assertTrue(paidFlavorSourceProvider.isContainedBy(srcFile));
}
示例7: sourceRootsForVariant
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
private Iterable<? extends File> sourceRootsForVariant(Variant variant) {
Collection<File> javaDirs = project != null
? project.getDefaultConfig().getSourceProvider().getJavaDirectories()
: Collections.<File>emptySet();
BuildTypeContainer buildTypeContainer = buildConfig.getCurrentBuildTypeContainer();
Collection<File> typeJavaDirs = buildTypeContainer != null
? buildTypeContainer.getSourceProvider().getJavaDirectories()
: Collections.<File>emptySet();
Iterable<File> variantJavaDirs = variant != null
? Iterables.concat(
Iterables.transform(
variant.getProductFlavors(),
new Function<String, Collection<File>>() {
@Override
public Collection<File> apply(String f) {
if (project == null) {
return Collections.<File>emptySet();
}
final ProductFlavorContainer flavor
= ProductFlavors.findFlavorByName(project.getProductFlavors(), f);
if (flavor == null) {
return Collections.<File>emptySet();
}
return flavor.getSourceProvider().getJavaDirectories();
}
}))
: Collections.<File>emptySet();
Collection<File> generatedJavaDirs = variant != null
? variant.getMainArtifact().getGeneratedSourceFolders()
: Collections.<File>emptyList();
return Iterables.concat(
javaDirs,
typeJavaDirs,
variantJavaDirs,
generatedJavaDirs);
}
示例8: get
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
@Override
public Iterable<? extends File> get() {
Collection<File> javaDirs = androidProject != null
? androidProject.getDefaultConfig().getSourceProvider().getJavaDirectories()
: Collections.<File>emptySet();
BuildTypeContainer buildTypeContainer = buildConfig.getCurrentBuildTypeContainer();
Collection<File> typeJavaDirs = buildTypeContainer != null
? buildTypeContainer.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 (androidProject == null) {
return Collections.<File>emptySet();
}
final ProductFlavorContainer flavor = ProductFlavors.findFlavorByName(androidProject.getProductFlavors(), f);
if (flavor == null) {
return Collections.<File>emptySet();
}
return flavor.getSourceProvider().getJavaDirectories();
}
}))
: Collections.<File>emptySet();
Collection<File> generatedJavaDirs = variant != null
? variant.getMainArtifact().getGeneratedSourceFolders()
: Collections.<File>emptyList();
return Iterables.concat(
javaDirs,
typeJavaDirs,
variantJavaDirs,
generatedJavaDirs);
}
示例9: logLoadedProject
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
private void logLoadedProject(AndroidProject aPrj, GradleBuild build) {
if (aPrj != null) {
LOG.log(Level.FINE, "android {0}", aPrj.getName());
LOG.log(Level.FINE, "target {0}", aPrj.getCompileTarget());
LOG.log(Level.FINE, "bootCP {0}", aPrj.getBootClasspath());
LOG.log(Level.FINE, "variants {0}", aPrj.getVariants());
LOG.log(Level.FINE, "build types {0}", aPrj.getBuildTypes());
LOG.log(Level.FINE, "flavors {0}", aPrj.getProductFlavors());
LOG.log(Level.FINE, "default flavor {0}", aPrj.getDefaultConfig());
LOG.log(Level.FINE, "default flavor source providers {0}, flavor {1}",
new Object[]{aPrj.getDefaultConfig().getSourceProvider(), aPrj.getDefaultConfig().getProductFlavor()});
Variant defaultConfig = AndroidBuildVariants.findDebugVariant(aPrj.getVariants());
if (defaultConfig != null) {
printDep(defaultConfig.getMainArtifact().getDependencies());
AndroidArtifact testArtifact = AndroidBuildVariants.instrumentTestArtifact(defaultConfig.getExtraAndroidArtifacts());
if (testArtifact != null) {
printDep(testArtifact.getDependencies());
}
for (ProductFlavorContainer flavor : aPrj.getProductFlavors()) {
LOG.log(Level.FINE, "flavor source providers {0}, flavor {1}",
new Object[]{flavor.getSourceProvider(), flavor.getProductFlavor()});
// printDep(en.getValue().getDependencies());
// printDep(en.getValue().getTestDependencies());
}
}
for (BuildTypeContainer buildType : aPrj.getBuildTypes()) {
LOG.log(Level.FINE, "build cont {0}", buildType.getBuildType().getName());
LOG.log(Level.FINE, "build {0}, {1}, {2}, {3}",
new Object[]{buildType.getBuildType(), buildType.getBuildType().getVersionNameSuffix(),
buildType.getBuildType().getVersionNameSuffix(), buildType.getSourceProvider()});
// printDep(en.getValue().getDependency());
}
}
}
示例10: findFlavorByName
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
@Nullable
public static ProductFlavorContainer findFlavorByName(Iterable<ProductFlavorContainer> flavors, final String name) {
return flavors == null || name == null
? null
: Iterables.find(
flavors,
new Predicate<ProductFlavorContainer>() {
@Override
public boolean apply(ProductFlavorContainer t) {
return name.equals(t.getProductFlavor().getName());
}
},
null);
}
示例11: getSourceProviderContainer
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
@Nullable
public static SourceProviderContainer getSourceProviderContainer(ProductFlavorContainer pfc, final String name) {
return pfc == null || name == null
? null
: Iterables.find(
pfc.getExtraSourceProviders(),
new Predicate<SourceProviderContainer>() {
@Override
public boolean apply(SourceProviderContainer t) {
return name.equals(t.getArtifactName());
}
},
null);
}
示例12: testDefaultSourceSets
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
public static void testDefaultSourceSets(
@NonNull AndroidProject model,
@NonNull File projectDir) {
ProductFlavorContainer defaultConfig = model.getDefaultConfig();
// test the main source provider
new SourceProviderHelper(model.getName(), projectDir,
"main", defaultConfig.getSourceProvider())
.test();
// test the main instrumentTest source provider
SourceProviderContainer testSourceProviders = getSourceProviderContainer(
defaultConfig.getExtraSourceProviders(), ARTIFACT_ANDROID_TEST);
assertNotNull("InstrumentTest source Providers null-check", testSourceProviders);
new SourceProviderHelper(model.getName(), projectDir,
ANDROID_TEST.getPrefix(), testSourceProviders.getSourceProvider())
.test();
// test the source provider for the build types
Collection<BuildTypeContainer> buildTypes = model.getBuildTypes();
assertEquals("Build Type Count", 2, buildTypes.size());
for (BuildTypeContainer btContainer : model.getBuildTypes()) {
new SourceProviderHelper(
model.getName(),
projectDir,
btContainer.getBuildType().getName(),
btContainer.getSourceProvider())
.test();
// For every build type there's the unit test source provider.
assertEquals(1, btContainer.getExtraSourceProviders().size());
}
}
示例13: getProductFlavor
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
@Nullable
public static ProductFlavorContainer getProductFlavor(
@NonNull Collection<ProductFlavorContainer> items,
@NonNull String name) {
for (ProductFlavorContainer item : items) {
assertNotNull("ProductFlavorContainer list item null-check:" + name, item);
assertNotNull("ProductFlavorContainer.getProductFlavor() list item null-check: " + name, item.getProductFlavor());
assertNotNull("ProductFlavorContainer.getProductFlavor().getName() list item null-check: " + name, item.getProductFlavor().getName());
if (name.equals(item.getProductFlavor().getName())) {
return item;
}
}
return null;
}
示例14: testFindSourceProvider
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
public void testFindSourceProvider() throws Exception {
assertNotNull(myAppFacet.getIdeaAndroidProject());
VirtualFile moduleFile = myAppFacet.getIdeaAndroidProject().getRootDir();
assertNotNull(moduleFile);
// Try finding main flavor
IdeaSourceProvider mainFlavorSourceProvider = myAppFacet.getMainIdeaSourceProvider();
assertNotNull(mainFlavorSourceProvider);
VirtualFile javaMainSrcFile = moduleFile.findFileByRelativePath("src/main/java/com/example/projectwithappandlib/");
assertNotNull(javaMainSrcFile);
Collection<IdeaSourceProvider> providers = IdeaSourceProvider.getIdeaSourceProvidersForFile(myAppFacet, javaMainSrcFile, null);
assertEquals(1, providers.size());
IdeaSourceProvider actualProvider = providers.iterator().next();
assertEquals(mainFlavorSourceProvider.getManifestFile(),
actualProvider.getManifestFile());
// Try finding paid flavor
ProductFlavorContainer paidFlavor = myAppFacet.getIdeaAndroidProject().findProductFlavor("paid");
assertNotNull(paidFlavor);
IdeaSourceProvider paidFlavorSourceProvider = IdeaSourceProvider.create(paidFlavor.getSourceProvider());
assertNotNull(paidFlavorSourceProvider);
VirtualFile javaSrcFile = moduleFile.findFileByRelativePath("src/paid/java/com/example/projectwithappandlib/app/paid");
assertNotNull(javaSrcFile);
providers = IdeaSourceProvider.getIdeaSourceProvidersForFile(myAppFacet, javaSrcFile, null);
assertEquals(1, providers.size());
actualProvider = providers.iterator().next();
assertEquals(paidFlavorSourceProvider.getManifestFile(),
actualProvider.getManifestFile());
}
示例15: setUp
import com.android.builder.model.ProductFlavorContainer; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
assumeTrue(CAN_SYNC_PROJECTS);
loadProject("projects/projectWithAppandLib");
assertNotNull(myAndroidFacet);
IdeaAndroidProject gradleProject = myAndroidFacet.getIdeaAndroidProject();
assertNotNull(gradleProject);
// Set up modules
for (Module m : ModuleManager.getInstance(getProject()).getModules()) {
if (m.getName().equals("app")) {
myAppModule = m;
break;
}
}
assertNotNull(myAppModule);
myAppFacet = AndroidFacet.getInstance(myAppModule);
assertNotNull(myAppFacet);
addAndroidSdk(myAppModule, getTestSdkPath(), getPlatformDir());
assertNotNull(AndroidPlatform.getInstance(myAppModule));
assertNotNull(myAppFacet.getIdeaAndroidProject());
ProductFlavorContainer paidFlavor = myAppFacet.getIdeaAndroidProject().findProductFlavor("paid");
assertNotNull(paidFlavor);
myPaidSourceProvider = paidFlavor.getSourceProvider();
assertNotNull(myPaidSourceProvider);
myMainSourceProvider = myAppFacet.getMainSourceProvider();
assertNotNull(myMainSourceProvider);
TemplateMetadata mockMetadata = Mockito.mock(TemplateMetadata.class);
Element elem = new IIOMetadataNode();
elem.setAttribute(ATTR_TYPE, Parameter.Type.STRING.toString());
elem.setAttribute(ATTR_ID, "testParam");
elem.setAttribute(ATTR_DEFAULT, "");
elem.setAttribute(ATTR_SUGGEST, null);
elem.setAttribute(ATTR_NAME, "Test Param");
elem.setAttribute(ATTR_HELP, "This is a test parameter");
elem.setAttribute(ATTR_CONSTRAINTS, "");
myParameter = new Parameter(mockMetadata, elem);
}