/** Add facet to App Engine module on imported modules */
  @Override
  public void importData(
      @NotNull final Collection<DataNode<IdeaAppEngineProject>> toImport,
      @NotNull final Project project,
      boolean synchronous) {
    if (toImport.isEmpty()) {
      return;
    }

    RunResult result =
        new WriteCommandAction.Simple(project) {
          @Override
          protected void run() throws Throwable {
            Map<String, IdeaAppEngineProject> importModulesMap = indexByModuleName(toImport);
            for (Module module : ModuleManager.getInstance(project).getModules()) {
              if (importModulesMap.containsKey(module.getName())) {
                AppEngineGradleFacet facet =
                    addAppEngineGradleFacet(importModulesMap.get(module.getName()), module);
                addAppEngineRunConfiguration(module, facet);
                UsageTracker.getInstance()
                    .trackEvent(GctTracking.CATEGORY, GctTracking.GRADLE_IMPORT, null, null);
              }
            }
          }
        }.execute();
    Throwable error = result.getThrowable();
    if (error != null) {
      LOG.error(String.format("Failed to set up App Engine Gradle Modules"));
      syncFailed(project, error.getMessage());
    }
  }
예제 #2
0
  private static Library addProjectLibrary(
      Module module,
      ModifiableRootModel model,
      String libName,
      List<VirtualFile> classesRoots,
      List<VirtualFile> sourceRoots) {
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
    RunResult<Library> result =
        new WriteAction<Library>() {
          @Override
          protected void run(@NotNull Result<Library> result) throws Throwable {
            Library library = libraryTable.createLibrary(libName);
            Library.ModifiableModel libraryModel = library.getModifiableModel();
            try {
              for (VirtualFile root : classesRoots) {
                libraryModel.addRoot(root, OrderRootType.CLASSES);
              }
              for (VirtualFile root : sourceRoots) {
                libraryModel.addRoot(root, OrderRootType.SOURCES);
              }
              libraryModel.commit();
            } catch (Throwable t) {
              //noinspection SSBasedInspection
              libraryModel.dispose();
              throw t;
            }

            model.addLibraryEntry(library);
            OrderEntry[] orderEntries = model.getOrderEntries();
            OrderEntry last = orderEntries[orderEntries.length - 1];
            System.arraycopy(orderEntries, 0, orderEntries, 1, orderEntries.length - 1);
            orderEntries[0] = last;
            model.rearrangeOrderEntries(orderEntries);
            result.setResult(library);
          }
        }.execute();
    result.throwException();
    return result.getResultObject();
  }