GradleUtil { @NotNull public static String getParentModulePath(@NotNull String gradlePath) { int parentPathEnd = gradlePath.lastIndexOf(GRADLE_PATH_SEPARATOR); if (parentPathEnd <= 0) { return ""; } else { return gradlePath.substring(0, parentPathEnd); } } private  GradleUtil(); @NotNull static File getCacheFolderRootPath(@NotNull Project project); static boolean isSupportedGradleVersion(@NotNull GradleVersion gradleVersion); @Deprecated @NotNull static AndroidArtifactOutput getOutput(@NotNull AndroidArtifact artifact); @NotNull static Icon getModuleIcon(@NotNull Module module); @NotNull static Icon getAndroidModuleIcon(@NotNull AndroidModuleModel androidModuleModel); @NotNull static Icon getAndroidModuleIcon(int androidProjectType); @Nullable static IdeAndroidProject getAndroidProject(@NotNull Module module); @Nullable static NativeAndroidProject getNativeAndroidProject(@NotNull Module module); @Nullable static String getGradlePath(@NotNull Module module); static boolean isRootModuleWithNoSources(@NotNull Module module); @NotNull static List<Library> getModuleDependencies(@NotNull IdeVariant variant); @Nullable static Module findModuleByGradlePath(@NotNull Project project, @NotNull String gradlePath); @NotNull static List<String> getPathSegments(@NotNull String gradlePath); @Nullable static VirtualFile getGradleBuildFile(@NotNull Module module); static boolean isGradleScript(@NotNull VirtualFile file); @Nullable static VirtualFile findGradleBuildFile(@NotNull VirtualFile parentDir); @Nullable static VirtualFile findGradleSettingsFile(@NotNull VirtualFile parentDir); @Nullable static VirtualFile getGradleBuildFile(@NotNull File dirPath); @Nullable static VirtualFile getGradleSettingsFile(@NotNull File dirPath); @NotNull static GradleExecutionSettings getOrCreateGradleExecutionSettings(@NotNull Project project); @Nullable static GradleExecutionSettings getGradleExecutionSettings(@NotNull Project project); @Nullable static GradleProjectSettings getGradleProjectSettings(@NotNull Project project); static void stopAllGradleDaemonsAndRestart(); @NotNull static String getDefaultPhysicalPathFromGradlePath(@NotNull String gradlePath); static boolean isDirectChild(String childPath, String parentPath); @NotNull static Set<String> getAllParentModulesPaths(@NotNull String gradlePath); @NotNull static String getParentModulePath(@NotNull String gradlePath); @NotNull static Path getModuleDefaultPath(@NotNull Path parentDir, @NotNull String gradlePath); static int isValidGradlePath(@NotNull String gradlePath); static boolean hasModule(@Nullable Project project, @NotNull String gradlePath); @Nullable static GradleVersion getAndroidGradleModelVersionInUse(@NotNull Project project); @Nullable static GradleVersion getAndroidGradleModelVersionInUse(@NotNull Module module); static void attemptToUseEmbeddedGradle(@NotNull Project project); static boolean dependsOn(@NonNull AndroidModuleModel androidModel, @NonNull String artifact); static boolean dependsOnJavaLibrary(@NonNull AndroidModuleModel androidModel, @NonNull String artifact); static boolean dependsOnAndroidTest(@NonNull AndroidModuleModel androidModel, @NonNull String artifact); static boolean dependsOn(@NonNull AndroidLibrary library, @NonNull String artifact, boolean transitively); static boolean dependsOn(@NonNull Library library, @NonNull String artifact); static boolean hasCause(@NotNull Throwable e, @NotNull Class<?> causeClass); @Nullable static File getGradleUserSettingsFile(); @Nullable static Library findLibrary(@NotNull File bundleDir, @NotNull IdeVariant variant); @NotNull static String mapConfigurationName(@NotNull String configuration,
                                            @Nullable GradleVersion pluginVersion,
                                            boolean preferApi); @NotNull static String mapConfigurationName(@NotNull String configuration,
                                            @Nullable String pluginVersion,
                                            boolean preferApi); static boolean useCompatibilityConfigurationNames(@NotNull Project project); static boolean useCompatibilityConfigurationNames(@Nullable GradleVersion gradleVersion); static boolean isAaptGeneratedSourcesFolder(@NotNull File folder, @NotNull File buildFolder); @VisibleForTesting static boolean isDataBindingGeneratedBaseClassesFolder(@NotNull File folder, @NotNull File buildFolder); static Collection<File> getGeneratedSourceFoldersToUse(@NotNull IdeBaseArtifact artifact, @NotNull AndroidModuleModel model); static Set<String> projectBuildFilesTypes(@NotNull Project project); static boolean hasKtsBuildFiles(@NotNull Project project); static boolean isKtsFile(@Nullable VirtualFile file); @Nullable static String getLastKnownAndroidGradlePluginVersion(@NotNull Project project); @Nullable static String getLastSuccessfulAndroidGradlePluginVersion(@NotNull Project project); static final ProjectSystemId GRADLE_SYSTEM_ID; @NonNls static final String BUILD_DIR_DEFAULT_NAME; @NonNls static final String GRADLEW_PROPERTIES_PATH; }
@Test public void getParentModulePath() { assertEquals(":foo", GradleUtil.getParentModulePath(":foo:buz")); assertEquals(":foo:bar", GradleUtil.getParentModulePath(":foo:bar:buz")); assertEquals("", GradleUtil.getParentModulePath(":")); }