use of com.android.builder.model.AndroidProject in project kotlin by JetBrains.
the class Project method getResourceVisibility.
/**
* Returns a shared {@link ResourceVisibilityLookup}
*
* @return a shared provider for looking up resource visibility
*/
@NonNull
public ResourceVisibilityLookup getResourceVisibility() {
if (mResourceVisibility == null) {
if (isGradleProject()) {
AndroidProject project = getGradleProjectModel();
Variant variant = getCurrentVariant();
if (project != null && variant != null) {
mResourceVisibility = mClient.getResourceVisibilityProvider().get(project, variant);
} else if (getGradleLibraryModel() != null) {
try {
mResourceVisibility = mClient.getResourceVisibilityProvider().get(getGradleLibraryModel());
} catch (Exception ignore) {
// Handle talking to older Gradle plugins (where we don't
// have access to the model version to check up front
}
}
}
if (mResourceVisibility == null) {
mResourceVisibility = ResourceVisibilityLookup.NONE;
}
}
return mResourceVisibility;
}
use of com.android.builder.model.AndroidProject 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.AndroidProject in project android by JetBrains.
the class AndroidGeneratedSourcesFilterTest method createAndroidModel.
@NotNull
private static AndroidModuleModel createAndroidModel(@NotNull VirtualFile buildFolder) {
AndroidProject androidProject = mock(AndroidProject.class);
when(androidProject.getBuildFolder()).thenReturn(virtualToIoFile(buildFolder));
AndroidModuleModel androidModel = mock(AndroidModuleModel.class);
when(androidModel.getAndroidProject()).thenReturn(androidProject);
return androidModel;
}
use of com.android.builder.model.AndroidProject in project android by JetBrains.
the class InternalAndroidModelView method updateContents.
private void updateContents() {
myTree.setRootVisible(true);
if (GradleSyncState.getInstance(myProject).isSyncInProgress()) {
myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Gradle project sync in progress ...")));
return;
} else {
myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Loading ...")));
}
ApplicationManager.getApplication().executeOnPooledThread(() -> {
final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(myProject.getName());
for (Module module : ModuleManager.getInstance(myProject).getModules()) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module.getName());
AndroidProject androidProject = androidModel.waitForAndGetProxyAndroidProject();
addProxyObject(moduleNode, androidProject);
rootNode.add(moduleNode);
}
NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
if (ndkModuleModel != null) {
String nodeName = androidModel == null ? module.getName() : module.getName() + " (native)";
DefaultMutableTreeNode nativeModuleNode = new DefaultMutableTreeNode(nodeName);
NativeAndroidProject nativeAndroidProject = ndkModuleModel.waitForAndGetProxyAndroidProject();
addProxyObject(nativeModuleNode, nativeAndroidProject);
rootNode.add(nativeModuleNode);
}
}
invokeLaterIfNeeded(() -> {
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setOpenIcon(AllIcons.Nodes.NewFolder);
renderer.setClosedIcon(AllIcons.Nodes.NewFolder);
renderer.setLeafIcon(AllIcons.ObjectBrowser.ShowModules);
myTree.setCellRenderer(renderer);
DefaultTreeModel model = new DefaultTreeModel(rootNode);
myTree.setRootVisible(false);
myTree.setModel(model);
});
});
}
use of com.android.builder.model.AndroidProject in project android by JetBrains.
the class ModuleSetup method setUpModule.
public void setUpModule(@NotNull Module module, @NotNull SyncAction.ModuleModels models, @NotNull ProgressIndicator indicator) {
boolean isProjectRootFolder = false;
File gradleSettingsFile = new File(getModulePath(module), FN_SETTINGS_GRADLE);
if (gradleSettingsFile.isFile() && !models.hasModel(AndroidProject.class) && !models.hasModel(NativeAndroidProject.class)) {
// This is just a root folder for a group of Gradle projects. We don't set an IdeaGradleProject so the JPS builder won't try to
// compile it using Gradle. We still need to create the module to display files inside it.
isProjectRootFolder = true;
}
myGradleModuleSetup.setUpModule(module, myIdeModelsProvider, models);
AndroidProject androidProject = models.findModel(AndroidProject.class);
if (androidProject != null) {
AndroidModuleModel androidModel = createAndroidModel(module, androidProject);
if (androidModel != null) {
// This is an Android module without variants.
myAndroidModuleSetup.setUpModule(module, myIdeModelsProvider, androidModel, models, indicator);
} else {
// This is an Android module without variants. Treat as a non-buildable Java module.
removeAndroidFacetFrom(module);
setUpJavaModule(module, models, indicator, true);
}
return;
}
// This is not an Android module. Remove any AndroidFacet set in a previous sync operation.
removeAndroidFacetFrom(module);
NativeAndroidProject nativeAndroidProject = models.findModel(NativeAndroidProject.class);
if (nativeAndroidProject != null) {
NdkModuleModel ndkModuleModel = new NdkModuleModel(module.getName(), getModulePath(module), nativeAndroidProject);
myNdkModuleSetup.setUpModule(module, myIdeModelsProvider, ndkModuleModel, models, indicator);
return;
}
// This is not an Android module. Remove any AndroidFacet set in a previous sync operation.
removeAllFacets(myIdeModelsProvider.getModifiableFacetModel(module), NdkFacet.getFacetTypeId());
if (!isProjectRootFolder) {
setUpJavaModule(module, models, indicator, false);
}
}
Aggregations