use of com.android.builder.model.NativeAndroidProject 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.NativeAndroidProject 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.builder.model.NativeAndroidProject in project android by JetBrains.
the class AndroidGradleProjectResolver method populateModuleContentRoots.
@Override
public void populateModuleContentRoots(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule) {
ImportedModule importedModule = new ImportedModule(gradleModule);
ideModule.createChild(IMPORTED_MODULE, importedModule);
GradleProject gradleProject = gradleModule.getGradleProject();
GradleScript buildScript = null;
try {
buildScript = gradleProject.getBuildScript();
} catch (UnsupportedOperationException ignore) {
}
if (buildScript == null || !isAndroidGradleProject()) {
nextResolver.populateModuleContentRoots(gradleModule, ideModule);
return;
}
// do not derive module root dir based on *.iml file location
File moduleRootDirPath = new File(toSystemDependentName(ideModule.getData().getLinkedExternalProjectPath()));
AndroidProject androidProject = resolverCtx.getExtraProject(gradleModule, AndroidProject.class);
boolean androidProjectWithoutVariants = false;
String moduleName = gradleModule.getName();
if (androidProject != null) {
Variant selectedVariant = myVariantSelector.findVariantToSelect(androidProject);
if (selectedVariant == null) {
// If an Android project does not have variants, it would be impossible to build. This is a possible but invalid use case.
// For now we are going to treat this case as a Java library module, because everywhere in the IDE (e.g. run configurations,
// editors, test support, variants tool window, project building, etc.) we have the assumption that there is at least one variant
// per Android project, and changing that in the code base is too risky, for very little benefit.
// See https://code.google.com/p/android/issues/detail?id=170722
androidProjectWithoutVariants = true;
} else {
String variantName = selectedVariant.getName();
AndroidModuleModel model = new AndroidModuleModel(moduleName, moduleRootDirPath, androidProject, variantName);
ideModule.createChild(ANDROID_MODEL, model);
}
}
NativeAndroidProject nativeAndroidProject = resolverCtx.getExtraProject(gradleModule, NativeAndroidProject.class);
if (nativeAndroidProject != null) {
NdkModuleModel ndkModuleModel = new NdkModuleModel(moduleName, moduleRootDirPath, nativeAndroidProject);
ideModule.createChild(NDK_MODEL, ndkModuleModel);
}
File gradleSettingsFile = new File(moduleRootDirPath, FN_SETTINGS_GRADLE);
if (gradleSettingsFile.isFile() && androidProject == null && nativeAndroidProject == null) {
// 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.
createJavaProject(gradleModule, ideModule, false);
return;
}
BuildScriptClasspathModel buildScriptModel = resolverCtx.getExtraProject(BuildScriptClasspathModel.class);
String gradleVersion = buildScriptModel != null ? buildScriptModel.getGradleVersion() : null;
File buildFilePath = buildScript.getSourceFile();
GradleModuleModel gradleModuleModel = new GradleModuleModel(moduleName, gradleProject, buildFilePath, gradleVersion);
ideModule.createChild(GRADLE_MODULE_MODEL, gradleModuleModel);
if (nativeAndroidProject == null && (androidProject == null || androidProjectWithoutVariants)) {
// This is a Java lib module.
createJavaProject(gradleModule, ideModule, androidProjectWithoutVariants);
}
}
use of com.android.builder.model.NativeAndroidProject in project android by JetBrains.
the class ProjectStructureCleanupStep method cleanUpProject.
@Override
public void cleanUpProject(@NotNull Project project, @NotNull IdeModifiableModelsProvider ideModifiableModelsProvider, @Nullable ProgressIndicator indicator) {
Set<Sdk> androidSdks = new HashSet<>();
for (Module module : ideModifiableModelsProvider.getModules()) {
ModifiableRootModel rootModel = ideModifiableModelsProvider.getModifiableRootModel(module);
adjustInterModuleDependencies(module, ideModifiableModelsProvider);
Sdk sdk = rootModel.getSdk();
if (sdk != null) {
if (myAndroidSdks.isAndroidSdk(sdk)) {
androidSdks.add(sdk);
}
continue;
}
NativeAndroidProject nativeAndroidProject = getNativeAndroidProject(module);
if (nativeAndroidProject != null) {
// Native modules does not need any jdk entry.
continue;
}
Sdk jdk = IdeSdks.getInstance().getJdk();
rootModel.setSdk(jdk);
}
for (Sdk sdk : androidSdks) {
myAndroidSdks.refreshLibrariesIn(sdk);
}
}
use of com.android.builder.model.NativeAndroidProject in project android by JetBrains.
the class NdkModuleNode method getNativeSourceNodes.
@NotNull
public static Collection<AbstractTreeNode> getNativeSourceNodes(@NotNull Project project, @NotNull NdkModuleModel ndkModuleModel, @NotNull ViewSettings viewSettings) {
NativeAndroidProject nativeAndroidProject = ndkModuleModel.getAndroidProject();
Collection<String> sourceFileExtensions = nativeAndroidProject.getFileExtensions().keySet();
NdkModuleModel.NdkVariant variant = ndkModuleModel.getSelectedVariant();
Multimap<String, NativeArtifact> nativeLibraries = HashMultimap.create();
for (NativeArtifact artifact : variant.getArtifacts()) {
String artifactOutputFileName = artifact.getOutputFile().getName();
nativeLibraries.put(artifactOutputFileName, artifact);
}
if (nativeLibraries.keySet().size() == 1) {
return getSourceDirectoryNodes(project, nativeLibraries.values(), viewSettings, sourceFileExtensions);
}
List<AbstractTreeNode> children = Lists.newArrayList();
for (String name : nativeLibraries.keySet()) {
String nativeLibraryType = "";
String nativeLibraryName = trimEnd(name, ".so");
if (nativeLibraryName.length() < name.length()) {
nativeLibraryType = "Shared Library";
} else {
nativeLibraryName = trimEnd(name, ".a");
if (nativeLibraryName.length() < name.length()) {
nativeLibraryType = "Static Library";
}
}
nativeLibraryName = trimStart(nativeLibraryName, "lib");
children.add(new NativeAndroidLibraryNode(project, nativeLibraryName, nativeLibraryType, nativeLibraries.get(name), viewSettings, sourceFileExtensions));
}
return children;
}
Aggregations