@Override
 public WorkspaceConfig get() {
   SimpleWorkspaceConfig _xblockexpression = null;
   {
     ProjectManager _instance = ProjectManager.getInstance();
     Project[] _openProjects = _instance.getOpenProjects();
     final Project project =
         IterableExtensions.<Project>head(
             ((Iterable<Project>) Conversions.doWrapArray(_openProjects)));
     String _basePath = project.getBasePath();
     final SimpleWorkspaceConfig result = new SimpleWorkspaceConfig(_basePath);
     ModuleManager _instance_1 = ModuleManager.getInstance(project);
     Module[] _modules = _instance_1.getModules();
     final Procedure1<Module> _function =
         new Procedure1<Module>() {
           @Override
           public void apply(final Module m) {
             IdeaModuleConfig _ideaModuleConfig =
                 new IdeaModuleConfig(m, IdeaWorkspaceConfigProvider.this.outputConfigurations);
             result.addProjectConfig(_ideaModuleConfig);
           }
         };
     IterableExtensions.<Module>forEach(
         ((Iterable<Module>) Conversions.doWrapArray(_modules)), _function);
     _xblockexpression = result;
   }
   return _xblockexpression;
 }
예제 #2
0
  private void activate() {

    synchronized (LOCK) {
      for (final Module mod : myModuleManager.getModules()) {

        // currently only modules with MPS facet, later should either take dependencies into account
        // or just take all modules
        if (!hasMPSFacet(mod)) continue;

        trackModule(mod, false);
      }

      // add listeners
      workerConnection = myProject.getMessageBus().connect();
      // setup add/remove module listeners (change in dependencies)
      workerConnection.subscribe(ProjectTopics.MODULES, new ModuleWatcher(myProject));
      // setup project roots listeners
      workerConnection.subscribe(
          ProjectTopics.PROJECT_ROOTS,
          new ModuleRootListener() {
            @Override
            public void beforeRootsChange(ModuleRootEvent moduleRootEvent) {
              // To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void rootsChanged(ModuleRootEvent moduleRootEvent) {
              System.out.println("ROOTS DEBUG: event");
            }
          });
      // setup create/delete files listeners
      VirtualFileManager.getInstance()
          .addVirtualFileListener(
              new VirtualFileAdapter() {
                @Override
                public void fileCreated(VirtualFileEvent event) {

                  System.out.println("VIRT FILE DEBUG: " + event.getFile().getName());

                  // check that it's java and under one of our content roots
                  // ...
                }

                @Override
                public void fileDeleted(VirtualFileEvent event) {
                  synchronized (LOCK) {
                  }
                }
              });

      myIsActivated = true;
    }
  }
 @Nullable
 @Override
 public Element getState() {
   if (myOutputDirPointer == null) {
     return null;
   }
   Element element = new Element("state");
   element.setAttribute(URL, myOutputDirPointer.getUrl());
   for (Module module : myModuleManager.getModules()) {
     val moduleCompilerPathsManager =
         (ModuleCompilerPathsManagerImpl) ModuleCompilerPathsManager.getInstance(module);
     Element state = moduleCompilerPathsManager.getState();
     if (state != null) {
       element.addContent(state);
     }
   }
   return element;
 }
  @NotNull
  private Set<String> getRootsToWatch() {
    final Set<String> rootsToWatch = new HashSet<String>();
    ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    for (Module module : moduleManager.getModules()) {
      ModuleCompilerPathsManager moduleCompilerPathsManager =
          ModuleCompilerPathsManager.getInstance(module);

      for (ContentFolderTypeProvider folderType :
          ContentFolderTypeProvider.filter(ContentFolderScopes.all(false))) {
        String compilerOutputUrl = moduleCompilerPathsManager.getCompilerOutputUrl(folderType);
        assert compilerOutputUrl != null : module.getName() + ":" + folderType + " url is null";
        rootsToWatch.add(ProjectRootManagerImpl.extractLocalPath(compilerOutputUrl));
      }
    }

    rootsToWatch.add(ProjectRootManagerImpl.extractLocalPath(getCompilerOutputUrl()));
    return rootsToWatch;
  }
  @Override
  public void computeInReadAction(@NotNull ProgressIndicator indicator) {
    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(
            new Consumer<List<MavenIndex>>() {
              @Override
              public void consume(List<MavenIndex> indexes) {
                if (myProject.isDisposed()) return;

                final List<String> repositoriesWithEmptyIndex =
                    ContainerUtil.mapNotNull(
                        indexes,
                        new Function<MavenIndex, String>() {
                          @Override
                          public String fun(MavenIndex index) {
                            return 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);
                }
              }
            });
  }
예제 #6
0
 private boolean hasMPSFacet() {
   for (Module mod : myModuleManager.getModules()) {
     if (hasMPSFacet(mod)) return true;
   }
   return false;
 }