use of com.android.tools.idea.gradle.project.model.NdkModuleModel 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.tools.idea.gradle.project.model.NdkModuleModel in project android by JetBrains.
the class DataNodeCaches method isCacheMissingModels.
private static boolean isCacheMissingModels(@NotNull DataNode<ModuleData> cache, @NotNull Module module) {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet != null) {
DataNode<GradleModuleModel> gradleDataNode = find(cache, GRADLE_MODULE_MODEL);
if (gradleDataNode == null) {
return true;
}
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet != null) {
DataNode<AndroidModuleModel> androidDataNode = find(cache, ANDROID_MODEL);
if (androidDataNode == null || !isValidProxyObject(androidDataNode.getData().getAndroidProject())) {
return true;
}
} else {
JavaFacet javaFacet = JavaFacet.getInstance(module);
if (javaFacet != null) {
DataNode<JavaModuleModel> javaProjectDataNode = find(cache, JAVA_MODULE_MODEL);
if (javaProjectDataNode == null) {
return true;
}
}
}
}
NdkFacet ndkFacet = NdkFacet.getInstance(module);
if (ndkFacet != null) {
DataNode<NdkModuleModel> ndkModuleModelDataNode = find(cache, NDK_MODEL);
if (ndkModuleModelDataNode == null || !isValidProxyObject(ndkModuleModelDataNode.getData().getAndroidProject())) {
return true;
}
}
return false;
}
use of com.android.tools.idea.gradle.project.model.NdkModuleModel 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);
}
}
use of com.android.tools.idea.gradle.project.model.NdkModuleModel in project android by JetBrains.
the class LinkExternalCppProjectAction method isValidAndroidGradleModuleSelected.
private static boolean isValidAndroidGradleModuleSelected(@NotNull DataContext dataContext) {
Module module = getSelectedModule(dataContext);
if (module == null) {
return false;
}
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel == null || !androidModel.getFeatures().isExternalBuildSupported()) {
return false;
}
AndroidPluginGeneration pluginGeneration = AndroidPluginGeneration.find(module);
if (pluginGeneration == COMPONENT) {
// Updating experimental plugin DSL is not yet supported.
return false;
}
NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
if (ndkModuleModel != null) {
// Some external native project is already linked to this module.
return false;
}
if (GradleBuildModel.get(module) == null) {
// This should never for an fully synced module, but checking for just in case.
return false;
}
return true;
}
use of com.android.tools.idea.gradle.project.model.NdkModuleModel in project android by JetBrains.
the class GradleFiles method areGradleFilesModified.
/**
* Indicates whether a project sync with Gradle is needed if the following files:
* <ul>
* <li>gradle.properties</li>
* <li>build.gradle</li>
* <li>settings.gradle</li>
* <li>external build files (e.g. cmake files)</li>
* </ul>
* were modified after the given time.
*
* @param referenceTimeInMillis the given time, in milliseconds.
* @return {@code true} if any of the Gradle files changed, {@code false} otherwise.
* @throws IllegalArgumentException if the given time is less than or equal to zero.
*/
public boolean areGradleFilesModified(long referenceTimeInMillis) {
if (referenceTimeInMillis <= 0) {
throw new IllegalArgumentException("Reference time (in milliseconds) should be greater than zero");
}
setExternalBuildFilesModified(false);
if (areFilesInProjectRootFolderModified(referenceTimeInMillis, FN_GRADLE_PROPERTIES, FN_SETTINGS_GRADLE)) {
return true;
}
for (Module module : ModuleManager.getInstance(myProject).getModules()) {
VirtualFile buildFile = getGradleBuildFile(module);
if (buildFile != null) {
if (myDocumentManager.isFileModified(buildFile)) {
return true;
}
File buildFilePath = virtualToIoFile(buildFile);
if (buildFilePath.lastModified() > referenceTimeInMillis) {
return true;
}
}
NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
if (ndkModuleModel != null) {
for (File externalBuildFile : ndkModuleModel.getAndroidProject().getBuildFiles()) {
if (externalBuildFile.lastModified() > referenceTimeInMillis) {
setExternalBuildFilesModified(true);
return true;
}
// TODO find a better way to find a VirtualFile without refreshing the file systerm. It is expensive.
VirtualFile virtualFile = findFileByIoFile(externalBuildFile, true);
if (virtualFile != null && myDocumentManager.isFileModified(virtualFile)) {
setExternalBuildFilesModified(true);
return true;
}
}
}
}
return false;
}
Aggregations