use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.
the class GradleBuildInvoker method cleanProject.
public void cleanProject() {
setProjectBuildMode(CLEAN);
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
// "Clean" also generates sources.
List<String> tasks = findTasksToExecute(moduleManager.getModules(), SOURCE_GEN, TestCompileType.NONE);
tasks.add(0, CLEAN_TASK_NAME);
executeTasks(tasks, Collections.singletonList(createGenerateSourcesOnlyProperty()));
}
use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.
the class FmGetAppManifestDirMethod method findAppModuleIfAny.
@Nullable
private Module findAppModuleIfAny() {
String modulePath = (String) myParamMap.get(TemplateMetadata.ATTR_PROJECT_OUT);
if (modulePath != null) {
VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(modulePath.replace('/', File.separatorChar)));
if (file != null) {
Project project = ProjectLocator.getInstance().guessProjectForFile(file);
if (project != null) {
ModuleManager manager = ModuleManager.getInstance(project);
Module module = manager.findModuleByName(APP_NAME);
if (module != null) {
return module;
}
return manager.findModuleByName(MOBILE_NAME);
}
}
}
return null;
}
use of com.intellij.openapi.module.ModuleManager in project intellij-community by JetBrains.
the class ImportMavenRepositoriesTask method performTask.
private void performTask() {
if (myProject.isDisposed())
return;
if (ApplicationManager.getApplication().isUnitTestMode())
return;
final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
final List<PsiFile> psiFileList = ContainerUtil.newArrayList();
final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
for (Module module : moduleManager.getModules()) {
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
continue;
final String modulePath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (modulePath == null)
continue;
String buildScript = FileUtil.findFileInProvidedPath(modulePath, GradleConstants.DEFAULT_SCRIPT_NAME);
if (StringUtil.isEmpty(buildScript))
continue;
VirtualFile virtualFile = localFileSystem.refreshAndFindFileByPath(buildScript);
if (virtualFile == null)
continue;
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
if (psiFile == null)
continue;
psiFileList.add(psiFile);
}
final PsiFile[] psiFiles = ArrayUtil.toObjectArray(psiFileList, PsiFile.class);
final Set<MavenRemoteRepository> mavenRemoteRepositories = new ReadAction<Set<MavenRemoteRepository>>() {
@Override
protected void run(@NotNull Result<Set<MavenRemoteRepository>> result) throws Throwable {
Set<MavenRemoteRepository> myRemoteRepositories = ContainerUtil.newHashSet();
for (PsiFile psiFile : psiFiles) {
List<GrClosableBlock> repositoriesBlocks = ContainerUtil.newArrayList();
repositoriesBlocks.addAll(findClosableBlocks(psiFile, "repositories"));
for (GrClosableBlock closableBlock : findClosableBlocks(psiFile, "buildscript", "subprojects", "allprojects", "project", "configure")) {
repositoriesBlocks.addAll(findClosableBlocks(closableBlock, "repositories"));
}
for (GrClosableBlock repositoriesBlock : repositoriesBlocks) {
myRemoteRepositories.addAll(findMavenRemoteRepositories(repositoriesBlock));
}
}
result.setResult(myRemoteRepositories);
}
}.execute().getResultObject();
if (mavenRemoteRepositories == null || mavenRemoteRepositories.isEmpty())
return;
// register imported maven repository URLs but do not force to download the index
// the index can be downloaded and/or updated later using Maven Configuration UI (Settings -> Build, Execution, Deployment -> Build tools -> Maven -> Repositories)
MavenRepositoriesHolder.getInstance(myProject).update(mavenRemoteRepositories);
MavenProjectIndicesManager.getInstance(myProject).scheduleUpdateIndicesList(indexes -> {
if (myProject.isDisposed())
return;
final List<String> repositoriesWithEmptyIndex = ContainerUtil.mapNotNull(indexes, index -> index.getUpdateTimestamp() == -1 && MavenRepositoriesHolder.getInstance(myProject).contains(index.getRepositoryPathOrUrl()) ? index.getRepositoryPathOrUrl() : null);
if (!repositoriesWithEmptyIndex.isEmpty()) {
final NotificationData notificationData = new NotificationData(GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.title"), "\n<br>" + GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.text", StringUtil.join(repositoriesWithEmptyIndex, "<br>")), NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC);
notificationData.setBalloonNotification(true);
notificationData.setBalloonGroup(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP);
notificationData.setListener("#open", new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
ShowSettingsUtil.getInstance().showSettingsDialog(myProject, MavenRepositoriesConfigurable.class);
}
});
notificationData.setListener("#disable", new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
final int result = Messages.showYesNoDialog(myProject, "Notification will be disabled for all projects.\n\n" + "Settings | Appearance & Behavior | Notifications | " + UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP + "\ncan be used to configure the notification.", "Unindexed Maven Repositories Gradle Detection", "Disable Notification", CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
if (result == Messages.YES) {
NotificationsConfigurationImpl.getInstanceImpl().changeSettings(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP, NotificationDisplayType.NONE, false, false);
notification.hideBalloon();
}
}
});
ExternalSystemNotificationManager.getInstance(myProject).showNotification(GradleConstants.SYSTEM_ID, notificationData);
}
});
}
use of com.intellij.openapi.module.ModuleManager in project intellij-community by JetBrains.
the class ModuleDeleteProvider method deleteElement.
@Override
public void deleteElement(@NotNull DataContext dataContext) {
final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
assert modules != null;
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
assert project != null;
String names = StringUtil.join(Arrays.asList(modules), module -> "\'" + module.getName() + "\'", ", ");
int ret = Messages.showOkCancelDialog(getConfirmationText(modules, names), getActionTitle(), Messages.getQuestionIcon());
if (ret != Messages.OK)
return;
CommandProcessor.getInstance().executeCommand(project, () -> {
final Runnable action = () -> {
final ModuleManager moduleManager = ModuleManager.getInstance(project);
final Module[] currentModules = moduleManager.getModules();
final ModifiableModuleModel modifiableModuleModel = moduleManager.getModifiableModel();
final Map<Module, ModifiableRootModel> otherModuleRootModels = new HashMap<>();
for (final Module module : modules) {
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
for (final Module otherModule : currentModules) {
if (otherModule == module || ArrayUtilRt.find(modules, otherModule) != -1)
continue;
if (!otherModuleRootModels.containsKey(otherModule)) {
otherModuleRootModels.put(otherModule, ModuleRootManager.getInstance(otherModule).getModifiableModel());
}
}
removeModule(module, modifiableModel, otherModuleRootModels.values(), modifiableModuleModel);
}
final ModifiableRootModel[] modifiableRootModels = otherModuleRootModels.values().toArray(new ModifiableRootModel[otherModuleRootModels.size()]);
ModifiableModelCommitter.multiCommit(modifiableRootModels, modifiableModuleModel);
};
ApplicationManager.getApplication().runWriteAction(action);
}, ProjectBundle.message("module.remove.command"), null);
}
use of com.intellij.openapi.module.ModuleManager in project intellij-community by JetBrains.
the class DirectoryIndexTest method testModuleUnderIgnoredDir.
public void testModuleUnderIgnoredDir() {
final VirtualFile ignored = createChildDirectory(myRootVFile, ".git");
assertTrue(FileTypeManager.getInstance().isFileIgnored(ignored));
assertTrue(myFileIndex.isExcluded(ignored));
assertTrue(myFileIndex.isUnderIgnored(ignored));
final VirtualFile module4 = createChildDirectory(ignored, "module4");
assertFalse(FileTypeManager.getInstance().isFileIgnored(module4));
assertTrue(myFileIndex.isExcluded(module4));
assertTrue(myFileIndex.isUnderIgnored(module4));
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA.getId());
PsiTestUtil.addContentRoot(module, module4);
assertNotInProject(ignored);
checkInfo(module4, module, false, false, null, null);
}
}.execute().throwException();
}
Aggregations