Search in sources :

Example 1 with NativeBuildSystemType

use of com.google.wireless.android.sdk.stats.GradleNativeAndroidModule.NativeBuildSystemType 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)));
    }
}
Also used : NativeBuildSystemType(com.google.wireless.android.sdk.stats.GradleNativeAndroidModule.NativeBuildSystemType) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) GradleVersion(com.android.ide.common.repository.GradleVersion) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) VisibleForTesting(com.android.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.android.annotations.VisibleForTesting)1 GradleVersion (com.android.ide.common.repository.GradleVersion)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)1 NativeBuildSystemType (com.google.wireless.android.sdk.stats.GradleNativeAndroidModule.NativeBuildSystemType)1 Module (com.intellij.openapi.module.Module)1