use of com.android.builder.model.ProductFlavorContainer in project kotlin by JetBrains.
the class Project method getApplicableDensities.
/**
* 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) {
// ...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;
}
use of com.android.builder.model.ProductFlavorContainer in project android by JetBrains.
the class IdeaSourceProviderTest method testFindSourceProvider.
public void testFindSourceProvider() throws Exception {
assertNotNull(myAppFacet.getAndroidModel());
VirtualFile moduleFile = myAppFacet.getAndroidModel().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 = AndroidModuleModel.get(myAppFacet).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());
}
use of com.android.builder.model.ProductFlavorContainer in project android by JetBrains.
the class IdeaSourceProviderTest method testSourceProviderIsContainedByFolder.
public void testSourceProviderIsContainedByFolder() throws Exception {
assertNotNull(myAppFacet.getAndroidModel());
ProductFlavorContainer paidFlavor = AndroidModuleModel.get(myAppFacet).findProductFlavor("paid");
assertNotNull(paidFlavor);
IdeaSourceProvider paidFlavorSourceProvider = IdeaSourceProvider.create(paidFlavor.getSourceProvider());
assertNotNull(paidFlavorSourceProvider);
VirtualFile moduleFile = myAppFacet.getAndroidModel().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));
}
use of com.android.builder.model.ProductFlavorContainer in project kotlin by JetBrains.
the class RegistrationDetector method reportMissing.
private static void reportMissing(@NonNull JavaContext context, @NonNull PsiClass node, @NonNull String className, @NonNull String tag) {
if (tag.equals(TAG_RECEIVER)) {
// Receivers can be registered in code; don't flag these.
return;
}
// Don't flag activities registered in test source sets
if (context.getProject().isGradleProject()) {
AndroidProject model = context.getProject().getGradleProjectModel();
if (model != null) {
String javaSource = context.file.getPath();
for (SourceProviderContainer extra : model.getDefaultConfig().getExtraSourceProviders()) {
String artifactName = extra.getArtifactName();
if (AndroidProject.ARTIFACT_ANDROID_TEST.equals(artifactName)) {
for (File file : extra.getSourceProvider().getJavaDirectories()) {
if (SdkUtils.startsWithIgnoreCase(javaSource, file.getPath())) {
return;
}
}
}
}
for (ProductFlavorContainer container : model.getProductFlavors()) {
for (SourceProviderContainer extra : container.getExtraSourceProviders()) {
String artifactName = extra.getArtifactName();
if (AndroidProject.ARTIFACT_ANDROID_TEST.equals(artifactName)) {
for (File file : extra.getSourceProvider().getJavaDirectories()) {
if (SdkUtils.startsWithIgnoreCase(javaSource, file.getPath())) {
return;
}
}
}
}
}
}
}
Location location = context.getNameLocation(node);
String message = String.format("The `<%1$s> %2$s` is not registered in the manifest", tag, className);
context.report(ISSUE, node, location, message);
}
use of com.android.builder.model.ProductFlavorContainer in project android by JetBrains.
the class UniqueParameterTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
loadProject(PROJECT_WITH_APPAND_LIB);
assertNotNull(myAndroidFacet);
AndroidModel androidModel = AndroidModuleModel.get(myAndroidFacet);
assertNotNull(androidModel);
// 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);
addLatestAndroidSdk(myAppModule);
assertNotNull(AndroidPlatform.getInstance(myAppModule));
assertNotNull(myAppFacet.getAndroidModel());
// TODO: b/23032990
ProductFlavorContainer paidFlavor = AndroidModuleModel.get(myAppFacet).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);
}
Aggregations