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;
}
use of com.android.tools.idea.gradle.project.model.NdkModuleModel in project android by JetBrains.
the class ProjectStructureUsageTracker method trackProjectStructure.
@VisibleForTesting
void trackProjectStructure(@NotNull Module[] modules) {
AndroidModuleModel appModel = null;
AndroidModuleModel libModel = null;
int appCount = 0;
int libCount = 0;
List<GradleLibrary> gradleLibraries = new ArrayList<>();
for (Module module : modules) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
if (androidModel.getProjectType() == PROJECT_TYPE_LIBRARY) {
libModel = androidModel;
libCount++;
continue;
}
appModel = androidModel;
appCount++;
GradleLibrary gradleLibrary = trackExternalDependenciesInAndroidApp(androidModel);
if (gradleLibrary != null) {
gradleLibraries.add(gradleLibrary);
}
}
}
// Ideally we would like to get data from an "app" module, but if the project does not have one (which would be unusual, we can use
// an Android library one.)
AndroidModuleModel model = appModel != null ? appModel : libModel;
if (model != null) {
List<GradleAndroidModule> gradleAndroidModules = new ArrayList<>();
List<GradleNativeAndroidModule> gradleNativeAndroidModules = new ArrayList<>();
String appId = AndroidStudioUsageTracker.anonymizeUtf8(model.getApplicationId());
AndroidProject androidProject = model.getAndroidProject();
GradleVersion gradleVersion = GradleVersions.getInstance().getGradleVersion(myProject);
if (gradleVersion == null) {
gradleVersion = new GradleVersion(0, 0, 0);
}
GradleModule gradleModule = GradleModule.newBuilder().setTotalModuleCount(modules.length).setAppModuleCount(appCount).setLibModuleCount(libCount).build();
for (Module module : modules) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
gradleAndroidModules.add(GradleAndroidModule.newBuilder().setModuleName(AndroidStudioUsageTracker.anonymizeUtf8(module.getName())).setSigningConfigCount(androidModel.getAndroidProject().getSigningConfigs().size()).setIsLibrary(androidModel.getProjectType() == PROJECT_TYPE_LIBRARY).setBuildTypeCount(androidModel.getBuildTypeNames().size()).setFlavorCount(androidModel.getProductFlavorNames().size()).setFlavorDimension(getFlavorDimensions(androidModel).size()).build());
}
boolean shouldReportNative = false;
NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
NativeBuildSystemType buildSystemType = NativeBuildSystemType.UNKNOWN_NATIVE_BUILD_SYSTEM_TYPE;
String moduleName = "";
if (ndkModuleModel != null) {
shouldReportNative = true;
if (ndkModuleModel.modelVersionIsAtLeast("2.2.0")) {
for (String buildSystem : ndkModuleModel.getAndroidProject().getBuildSystems()) {
buildSystemType = stringToBuildSystemType(buildSystem);
}
} else {
buildSystemType = NativeBuildSystemType.GRADLE_EXPERIMENTAL;
}
moduleName = AndroidStudioUsageTracker.anonymizeUtf8(ndkModuleModel.getModuleName());
} else if (androidModel != null && areNativeLibrariesPresent(androidModel.getAndroidProject())) {
shouldReportNative = true;
if (AndroidPluginGeneration.find(module) == COMPONENT) {
buildSystemType = NativeBuildSystemType.GRADLE_EXPERIMENTAL;
} else {
buildSystemType = NativeBuildSystemType.NDK_COMPILE;
}
}
if (shouldReportNative) {
gradleNativeAndroidModules.add(GradleNativeAndroidModule.newBuilder().setModuleName(moduleName).setBuildSystemType(buildSystemType).build());
}
}
UsageTracker.getInstance().log(AndroidStudioEvent.newBuilder().setCategory(EventCategory.GRADLE).setKind(AndroidStudioEvent.EventKind.GRADLE_BUILD_DETAILS).setGradleBuildDetails(GradleBuildDetails.newBuilder().setAppId(appId).setAndroidPluginVersion(androidProject.getModelVersion()).setGradleVersion(gradleVersion.toString()).setUserEnabledIr(InstantRunSettings.isInstantRunEnabled()).setModelSupportsIr(InstantRunGradleUtils.modelSupportsInstantRun(model)).setVariantSupportsIr(InstantRunGradleUtils.variantSupportsInstantRun(model)).addAllLibraries(gradleLibraries).addModules(gradleModule).addAllAndroidModules(gradleAndroidModules).addAllNativeAndroidModules(gradleNativeAndroidModules)));
}
}
use of com.android.tools.idea.gradle.project.model.NdkModuleModel in project android by JetBrains.
the class BuildVariantView method updateContents.
public void updateContents() {
GradleSyncState syncState = GradleSyncState.getInstance(myProject);
if (syncState.isSyncInProgress() && !syncState.isSyncSkipped()) {
projectImportStarted();
return;
}
final List<Object[]> rows = Lists.newArrayList();
final List<BuildVariantItem[]> variantNamesPerRow = Lists.newArrayList();
for (Module module : getGradleModulesWithAndroidProjects()) {
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
NdkFacet ndkFacet = NdkFacet.getInstance(module);
// getGradleModules() returns only relevant modules.
assert androidFacet != null || ndkFacet != null;
String variantName = null;
if (androidFacet != null) {
JpsAndroidModuleProperties facetProperties = androidFacet.getProperties();
variantName = facetProperties.SELECTED_BUILD_VARIANT;
}
BuildVariantItem[] variantNames = getVariantItems(module);
if (variantNames != null) {
if (androidFacet != null) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
// AndroidModel may be null when applying a quick fix (e.g. "Fix Gradle version")
if (androidModel != null) {
variantName = androidModel.getSelectedVariant().getName();
}
} else {
// As only the modules backed by either AndroidGradleModel or NativeAndroidGradleModel are shown in the Build Variants View,
// when a module is not backed by AndroidGradleModel, it surely contains a valid NativeAndroidGradleModel.
NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
if (ndkModuleModel != null) {
variantName = ndkModuleModel.getSelectedVariant().getName();
}
}
variantNamesPerRow.add(variantNames);
}
if (variantName != null) {
Object[] row = { module, variantName };
rows.add(row);
}
}
Runnable setModelTask = () -> getVariantsTable().setModel(rows, variantNamesPerRow);
Application application = ApplicationManager.getApplication();
if (application.isDispatchThread()) {
setModelTask.run();
} else {
application.invokeLater(setModelTask);
}
}
use of com.android.tools.idea.gradle.project.model.NdkModuleModel 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);
}
}
Aggregations