@SuppressWarnings("MethodMayBeStatic") public void removeModules(@NotNull final Collection<? extends Module> modules) { if (modules.isEmpty()) { return; } Project project = modules.iterator().next().getProject(); GradleUtil.executeProjectChangeAction( project, modules, new Runnable() { @Override public void run() { for (Module module : modules) { ModuleManager moduleManager = ModuleManager.getInstance(module.getProject()); String path = module.getModuleFilePath(); moduleManager.disposeModule(module); File file = new File(path); if (file.isFile()) { boolean success = file.delete(); if (!success) { GradleLog.LOG.warn("Can't remove module file at '" + path + "'"); } } } } }); }
private static GradleProject populateProject( @NotNull IdeaProject project, @NotNull String projectPath) { String projectDirPath = GradleUtil.toCanonicalPath(PathUtil.getParentPath(projectPath)); // Gradle API doesn't expose project compile output path yet. GradleProject result = new GradleProject(projectDirPath, projectDirPath + "/out"); result.setName(project.getName()); result.setJdkVersion(project.getJdkName()); result.setLanguageLevel(project.getLanguageLevel().getLevel()); return result; }
/** * Performs argument type-based dispatch and delegates to one of strongly typed <code> * 'buildLocalChanges()'</code> methods. * * @param entity target intellij-local entity that doesn't present at the gradle side * @param context changes calculation context to use */ public static void buildLocalChanges( @NotNull Object entity, @NotNull final GradleChangesCalculationContext context) { if (entity instanceof GradleEntity) { buildLocalChanges((GradleEntity) entity, context); } else { GradleUtil.dispatch( entity, new IntellijEntityVisitor() { @Override public void visit(@NotNull Project project) {} @Override public void visit(@NotNull Module module) { context.register(new GradleModulePresenceChange(null, module)); for (ModuleAwareContentRoot contentRoot : context.getPlatformFacade().getContentRoots(module)) { visit(contentRoot); } for (OrderEntry entry : context.getPlatformFacade().getOrderEntries(module)) { GradleUtil.dispatch(entry, this); } } @Override public void visit(@NotNull ModuleAwareContentRoot contentRoot) { context.register(new GradleContentRootPresenceChange(null, contentRoot)); } @Override public void visit(@NotNull LibraryOrderEntry libraryDependency) { context.register(new GradleLibraryDependencyPresenceChange(null, libraryDependency)); } @Override public void visit(@NotNull ModuleOrderEntry moduleDependency) { final Module module = moduleDependency.getModule(); if (module != null) { context.register(new GradleModuleDependencyPresenceChange(null, moduleDependency)); } } @Override public void visit(@NotNull Library library) {} }); } }