private void removeLibraryIfNeeded() {
    ApplicationManager.getApplication().assertIsDispatchThread();

    ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance();
    ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule);
    LibraryOrderEntry goLibraryEntry =
        OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());
    if (goLibraryEntry != null) {
      ApplicationManager.getApplication()
          .runWriteAction(
              () -> {
                Library library = goLibraryEntry.getLibrary();
                if (library != null) {
                  LibraryTable table = library.getTable();
                  if (table != null) {
                    table.removeLibrary(library);
                    model.removeOrderEntry(goLibraryEntry);
                    modelsProvider.commitModuleModifiableModel(model);
                  }
                } else {
                  modelsProvider.disposeModuleModifiableModel(model);
                }
              });
    } else {
      ApplicationManager.getApplication()
          .runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model));
    }
  }
  private static void addDependencyOnDartPackagesLibrary(
      @NotNull final Module module, @NotNull final Library library) {
    final ModifiableRootModel modifiableModel =
        ModuleRootManager.getInstance(module).getModifiableModel();
    try {
      for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
        if (orderEntry instanceof LibraryOrderEntry
            && LibraryTablesRegistrar.PROJECT_LEVEL.equals(
                ((LibraryOrderEntry) orderEntry).getLibraryLevel())
            && DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(
                ((LibraryOrderEntry) orderEntry).getLibraryName())) {
          return; // dependency already exists
        }
      }

      modifiableModel.addLibraryEntry(library);

      ApplicationManager.getApplication()
          .runWriteAction(
              new Runnable() {
                @Override
                public void run() {
                  modifiableModel.commit();
                }
              });
    } finally {
      if (!modifiableModel.isDisposed()) {
        modifiableModel.dispose();
      }
    }
  }
  public void unConfigureModule(@NotNull ModifiableRootModel model) {
    for (OrderEntry orderEntry : model.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry) {
        LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry;

        Library library = libraryOrderEntry.getLibrary();
        if (library != null) {
          String libraryName = library.getName();
          if (libraryName != null && libraryName.equals(this.libraryName)) {

            // Dispose attached roots
            Library.ModifiableModel modifiableModel = library.getModifiableModel();
            for (String rootUrl : library.getRootProvider().getUrls(OrderRootType.CLASSES)) {
              modifiableModel.removeRoot(rootUrl, OrderRootType.CLASSES);
            }
            modifiableModel.commit();

            model.getModuleLibraryTable().removeLibrary(library);

            break;
          }
        }
      }
    }
  }
  public boolean tryToSetUpGroovyFacetOnTheFly(final Module module) {
    final Project project = module.getProject();
    final Library[] libraries = getAllSDKLibraries(project);
    if (libraries.length > 0) {
      final Library library = libraries[0];
      int result =
          Messages.showOkCancelDialog(
              GroovyBundle.message(
                  "groovy.like.library.found.text",
                  module.getName(),
                  library.getName(),
                  getSDKLibVersion(library)),
              GroovyBundle.message("groovy.like.library.found"),
              JetgroovyIcons.Groovy.Groovy_32x32);
      if (result == Messages.OK) {
        AccessToken accessToken = WriteAction.start();

        try {
          ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
          LibraryOrderEntry entry = model.addLibraryEntry(libraries[0]);
          LibrariesUtil.placeEntryToCorrectPlace(model, entry);
          model.commit();
          return true;
        } finally {
          accessToken.finish();
        }
      }
    }
    return false;
  }
  @Override
  public void setupRootModel(final ModifiableRootModel modifiableRootModel)
      throws ConfigurationException {
    String contentEntryPath = getContentEntryPath();
    if (StringUtil.isEmpty(contentEntryPath)) {
      return;
    }
    File contentRootDir = new File(contentEntryPath);
    FileUtilRt.createDirectory(contentRootDir);
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    VirtualFile modelContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir);
    if (modelContentRootDir == null) {
      return;
    }

    modifiableRootModel.addContentEntry(modelContentRootDir);
    modifiableRootModel.inheritSdk();

    final Project project = modifiableRootModel.getProject();

    setupGradleBuildFile(modelContentRootDir);
    setupGradleSettingsFile(modelContentRootDir, modifiableRootModel);

    if (myWizardContext.isCreatingNewProject()) {
      String externalProjectPath = FileUtil.toCanonicalPath(project.getBasePath());
      getExternalProjectSettings().setExternalProjectPath(externalProjectPath);
      AbstractExternalSystemSettings settings =
          ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
      //noinspection unchecked
      settings.linkProject(getExternalProjectSettings());
    } else {
      FileDocumentManager.getInstance().saveAllDocuments();
      ExternalSystemUtil.refreshProjects(project, GradleConstants.SYSTEM_ID, false);
    }
  }
 public void testCompilerOutputInheritance() throws Exception {
   File moduleFile = new File(getTestRoot(), "test.iml");
   Module module = createModule(moduleFile);
   final ModuleRootManagerImpl moduleRootManager =
       (ModuleRootManagerImpl) ModuleRootManager.getInstance(module);
   final ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
   rootModel.getModuleExtension(CompilerModuleExtension.class).inheritCompilerOutputPath(true);
   ApplicationManager.getApplication()
       .runWriteAction(
           new Runnable() {
             @Override
             public void run() {
               rootModel.commit();
             }
           });
   Element element = new Element("root");
   moduleRootManager.getState().writeExternal(element);
   assertElementEquals(
       element,
       "<root inherit-compiler-output=\"true\">"
           + "<exclude-output />"
           + "<orderEntry type=\"sourceFolder\" forTests=\"false\" />"
           + "</root>",
       module);
 }
  protected void setupRootModel(
      final String testDir, final VirtualFile[] sourceDir, final String sdkName) {
    VirtualFile projectDir =
        LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir));
    assertNotNull("could not find project dir " + testDir, projectDir);
    sourceDir[0] = projectDir.findChild("src");
    if (sourceDir[0] == null) {
      sourceDir[0] = projectDir;
    }
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
    final ModifiableRootModel rootModel = rootManager.getModifiableModel();
    rootModel.clear();
    // configure source and output path
    final ContentEntry contentEntry = rootModel.addContentEntry(projectDir);
    contentEntry.addSourceFolder(sourceDir[0], false);
    ext_src =
        LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir + "/ext_src"));
    if (ext_src != null) {
      contentEntry.addSourceFolder(ext_src, false);
    }

    // IMPORTANT! The jdk must be obtained in a way it is obtained in the normal program!
    // ProjectJdkEx jdk = ProjectJdkTable.getInstance().getInternalJdk();

    rootModel.setSdk(getTestProjectSdk());

    rootModel.commit();
  }
Esempio n. 8
0
 @Override
 @Nullable
 protected ClasspathTableItem<?> createTableItem(final Library item) {
   // clear invalid order entry corresponding to added library if any
   final ModifiableRootModel rootModel = myClasspathPanel.getRootModel();
   final OrderEntry[] orderEntries = rootModel.getOrderEntries();
   for (OrderEntry orderEntry : orderEntries) {
     if (orderEntry instanceof LibraryOrderEntry) {
       final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry;
       if (item.equals(libraryOrderEntry.getLibrary())) {
         return ClasspathTableItem.createItem(libraryOrderEntry, myContext);
       }
       String name = item.getName();
       if (name != null && name.equals(libraryOrderEntry.getLibraryName())) {
         if (orderEntry.isValid()) {
           Messages.showErrorDialog(
               ProjectBundle.message("classpath.message.library.already.added", item.getName()),
               ProjectBundle.message("classpath.title.adding.dependency"));
           return null;
         } else {
           rootModel.removeOrderEntry(orderEntry);
         }
       }
     }
   }
   final LibraryOrderEntry orderEntry = rootModel.addLibraryEntry(item);
   DependencyScope defaultScope = getDefaultScope(item);
   if (defaultScope != null) {
     orderEntry.setScope(defaultScope);
   }
   return ClasspathTableItem.createItem(orderEntry, myContext);
 }
 private void appendChosenAnnotationsRoot(
     @NotNull final OrderEntry entry, @NotNull final VirtualFile vFile) {
   if (entry instanceof LibraryOrderEntry) {
     Library library = ((LibraryOrderEntry) entry).getLibrary();
     LOG.assertTrue(library != null);
     final ModifiableRootModel rootModel =
         ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel();
     final Library.ModifiableModel model = library.getModifiableModel();
     model.addRoot(vFile, AnnotationOrderRootType.getInstance());
     model.commit();
     rootModel.commit();
   } else if (entry instanceof ModuleSourceOrderEntry) {
     final ModifiableRootModel model =
         ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel();
     final JavaModuleExternalPaths extension =
         model.getModuleExtension(JavaModuleExternalPaths.class);
     extension.setExternalAnnotationUrls(
         ArrayUtil.mergeArrays(extension.getExternalAnnotationsUrls(), vFile.getUrl()));
     model.commit();
   } else if (entry instanceof JdkOrderEntry) {
     final SdkModificator sdkModificator = ((JdkOrderEntry) entry).getJdk().getSdkModificator();
     sdkModificator.addRoot(vFile, AnnotationOrderRootType.getInstance());
     sdkModificator.commitChanges();
   }
   myExternalAnnotations.clear();
 }
 private void setupInitialValues(boolean newlyCreatedModule) {
   if (newlyCreatedModule || myRootModel.getSdk() == null) {
     myRootModel.inheritSdk();
   }
   if (newlyCreatedModule) {
     getCompilerExtension().setExcludeOutput(true);
   }
 }
 @Override
 public void apply() throws ConfigurationException {
   myEditor.apply();
   if (myModifiableModel.isChanged()) {
     ApplicationManager.getApplication().runWriteAction(() -> myModifiableModel.commit());
     myEditor.disposeUIResources();
     myTopPanel.remove(myEditor.getComponent());
     createEditor();
   }
 }
 public static void addSourceRoot(
     final ModuleRootManager manager, @NotNull final VirtualFile root) {
   final ModifiableRootModel model = manager.getModifiableModel();
   ContentEntry contentEntry = findContentEntryForRoot(model, root);
   if (contentEntry == null) {
     contentEntry = model.addContentEntry(root);
   }
   contentEntry.addSourceFolder(root, false);
   model.commit();
 }
Esempio n. 13
0
 private void setupContentRoot() {
   ModifiableRootModel modifiableModel =
       ModuleRootManager.getInstance(myModule).getModifiableModel();
   ContentEntry contentEntry = modifiableModel.addContentEntry(getContentRoot());
   VirtualFile src = getContentRoot().findChild("src");
   if (src != null) {
     contentEntry.addSourceFolder(src, false);
   }
   modifiableModel.commit();
 }
 private void syncExistingAndRemoveObsolete(
     @NotNull IdeModifiableModelsProvider modelsProvider,
     @NotNull Map<Set<String>, LibraryDependencyData> moduleLibrariesToImport,
     @NotNull Map<String, LibraryDependencyData> projectLibrariesToImport,
     @NotNull Set<LibraryDependencyData> toImport,
     @NotNull Map<OrderEntry, OrderAware> orderEntryDataMap,
     @NotNull ModifiableRootModel moduleRootModel,
     boolean hasUnresolvedLibraries) {
   for (OrderEntry entry : moduleRootModel.getOrderEntries()) {
     if (entry instanceof ModuleLibraryOrderEntryImpl) {
       ModuleLibraryOrderEntryImpl moduleLibraryOrderEntry = (ModuleLibraryOrderEntryImpl) entry;
       Library library = moduleLibraryOrderEntry.getLibrary();
       if (library == null) {
         LOG.warn(
             "Skipping module-level library entry because it doesn't have backing Library object. Entry: "
                 + entry);
         continue;
       }
       final VirtualFile[] libraryFiles = library.getFiles(OrderRootType.CLASSES);
       final Set<String> moduleLibraryKey = ContainerUtilRt.newHashSet(libraryFiles.length);
       for (VirtualFile file : libraryFiles) {
         moduleLibraryKey.add(
             ExternalSystemApiUtil.getLocalFileSystemPath(file)
                 + moduleLibraryOrderEntry.getScope().name());
       }
       LibraryDependencyData existing = moduleLibrariesToImport.remove(moduleLibraryKey);
       if (existing == null || !StringUtil.equals(existing.getInternalName(), library.getName())) {
         moduleRootModel.removeOrderEntry(entry);
       } else {
         orderEntryDataMap.put(entry, existing);
         syncExistingLibraryDependency(
             modelsProvider,
             existing,
             library,
             moduleRootModel,
             moduleLibraryOrderEntry.getOwnerModule());
         toImport.remove(existing);
       }
     } else if (entry instanceof LibraryOrderEntry) {
       LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
       String libraryName = libraryOrderEntry.getLibraryName();
       LibraryDependencyData existing =
           projectLibrariesToImport.remove(libraryName + libraryOrderEntry.getScope().name());
       if (existing != null) {
         toImport.remove(existing);
         orderEntryDataMap.put(entry, existing);
       } else if (!hasUnresolvedLibraries) {
         // There is a possible case that a project has been successfully imported from external
         // model and after
         // that network/repo goes down. We don't want to drop existing binary mappings then.
         moduleRootModel.removeOrderEntry(entry);
       }
     }
   }
 }
  private boolean askAndRemoveDuplicatedLibraryEntry(
      @NotNull ModifiableRootModel rootModel, @NotNull CustomLibraryDescription description) {
    List<OrderEntry> existingEntries = new ArrayList<OrderEntry>();
    final LibrariesContainer container = myModel.getLibrariesContainer();
    for (OrderEntry entry : rootModel.getOrderEntries()) {
      if (!(entry instanceof LibraryOrderEntry)) continue;
      final Library library = ((LibraryOrderEntry) entry).getLibrary();
      if (library == null) continue;

      if (LibraryPresentationManager.getInstance()
          .isLibraryOfKind(library, container, description.getSuitableLibraryKinds())) {
        existingEntries.add(entry);
      }
    }

    if (!existingEntries.isEmpty()) {
      String message;
      if (existingEntries.size() > 1) {
        message =
            "There are already "
                + existingEntries.size()
                + " "
                + myFrameworkType.getPresentableName()
                + " libraries.\n Do you want to replace they?";
      } else {
        final String name = existingEntries.get(0).getPresentableName();
        message =
            "There is already a "
                + myFrameworkType.getPresentableName()
                + " library '"
                + name
                + "'.\n Do you want to replace it?";
      }
      final int result =
          Messages.showYesNoCancelDialog(
              rootModel.getProject(),
              message,
              "Library Already Exists",
              "&Replace",
              "&Add",
              "&Cancel",
              null);
      if (result == 0) {
        for (OrderEntry entry : existingEntries) {
          rootModel.removeOrderEntry(entry);
        }
      } else if (result != 1) {
        return false;
      }
    }

    return true;
  }
  private static void removeGenModule(@NotNull final Module libModule) {
    final String genModuleName = getGenModuleName(libModule);
    final ModuleManager moduleManager = ModuleManager.getInstance(libModule.getProject());
    final ModifiableRootModel model = ModuleRootManager.getInstance(libModule).getModifiableModel();

    for (OrderEntry entry : model.getOrderEntries()) {
      if (entry instanceof ModuleOrderEntry
          && genModuleName.equals(((ModuleOrderEntry) entry).getModuleName())) {
        model.removeOrderEntry(entry);
      }
    }

    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              @Override
              public void run() {
                model.commit();
              }
            });

    final Module genModule = moduleManager.findModuleByName(genModuleName);
    if (genModule == null) {
      return;
    }
    moduleManager.disposeModule(genModule);

    final VirtualFile moduleFile = genModule.getModuleFile();

    if (moduleFile != null) {
      ApplicationManager.getApplication()
          .invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  ApplicationManager.getApplication()
                      .runWriteAction(
                          new Runnable() {
                            @Override
                            public void run() {
                              try {
                                moduleFile.delete(libModule.getProject());
                              } catch (IOException e) {
                                LOG.error(e);
                              }
                            }
                          });
                }
              });
    }
  }
Esempio n. 17
0
  @NotNull
  private static JPanel createLayerConfigurationPanel(@NotNull final ModuleEditor moduleEditor) {
    BorderLayoutPanel panel = JBUI.Panels.simplePanel();

    ModifiableRootModel moduleRootModel = moduleEditor.getModifiableRootModelProxy();

    final MutableCollectionComboBoxModel<String> model =
        new MutableCollectionComboBoxModel<String>(
            new ArrayList<String>(moduleRootModel.getLayers().keySet()),
            moduleRootModel.getCurrentLayerName());

    final ComboBox comboBox = new ComboBox(model);
    comboBox.setEnabled(model.getSize() > 1);

    moduleEditor.addChangeListener(
        new ModuleEditor.ChangeListener() {
          @Override
          public void moduleStateChanged(ModifiableRootModel moduleRootModel) {
            model.update(new ArrayList<String>(moduleRootModel.getLayers().keySet()));
            model.setSelectedItem(moduleRootModel.getCurrentLayerName());
            model.update();

            comboBox.setEnabled(comboBox.getItemCount() > 1);
          }
        });

    comboBox.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
              moduleEditor
                  .getModifiableRootModelProxy()
                  .setCurrentLayer((String) comboBox.getSelectedItem());
            }
          }
        });

    DefaultActionGroup group = new DefaultActionGroup();
    group.add(new NewLayerAction(moduleEditor, false));
    group.add(new DeleteLayerAction(moduleEditor));
    group.add(new NewLayerAction(moduleEditor, true));

    ActionToolbar actionToolbar =
        ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    JComponent toolbarComponent = actionToolbar.getComponent();
    toolbarComponent.setBorder(JBUI.Borders.empty());

    panel.addToLeft(LabeledComponent.left(comboBox, "Layer")).addToRight(toolbarComponent);
    return panel;
  }
 protected Module createModule(final String name) {
   final Module module = super.createModule(name);
   final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
   final LibraryTable.ModifiableModel modifiableModel =
       model.getModuleLibraryTable().getModifiableModel();
   final Library library = modifiableModel.createLibrary("junit");
   final Library.ModifiableModel libModel = library.getModifiableModel();
   libModel.addRoot(
       VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Before.class))),
       OrderRootType.CLASSES);
   libModel.commit();
   model.commit();
   return module;
 }
  public ModuleConfigurationEditor[] createEditors(@NotNull ModuleConfigurationState state) {
    ModifiableRootModel rootModel = state.getRootModel();
    Module module = rootModel.getModule();
    if (!(ModuleType.get(module) instanceof GoModuleType)) {
      return ModuleConfigurationEditor.EMPTY;
    }

    String moduleName = module.getName();
    List<ModuleConfigurationEditor> editors = new ArrayList<ModuleConfigurationEditor>();
    editors.add(new ContentEntriesEditor(moduleName, state));
    editors.add(new OutputEditorEx(state));
    editors.add(new ClasspathEditor(state));
    return editors.toArray(new ModuleConfigurationEditor[editors.size()]);
  }
Esempio n. 20
0
  public void setSdk(final Sdk newJDK) {
    final ModifiableRootModel model = getModel();
    if (newJDK != null) {
      model.setSdk(newJDK);
    } else {
      model.inheritSdk();
    }

    if (myPanel != null) {
      myPanel.forceInitFromModel();
    }

    flushChangesToModel();
  }
 private void initOrderEntries() {
   for (OrderEntry e : myRootModel.getOrderEntries()) {
     if (e instanceof ModuleSourceOrderEntry || e instanceof JdkOrderEntry) continue;
     if (e instanceof LibraryOrderEntry) {
       if (!isMavenLibrary(((LibraryOrderEntry) e).getLibrary())) continue;
     }
     if (e instanceof ModuleOrderEntry) {
       Module m = ((ModuleOrderEntry) e).getModule();
       if (m != null
           && !MavenProjectsManager.getInstance(myRootModel.getProject()).isMavenizedModule(m))
         continue;
     }
     myRootModel.removeOrderEntry(e);
   }
 }
 private static int rearrangeOrderEntryOfType(
     ModifiableRootModel rootModel, Class<? extends OrderEntry> orderEntryClass) {
   OrderEntry[] orderEntries = rootModel.getOrderEntries();
   int moduleSourcesIdx = 0;
   for (OrderEntry orderEntry : orderEntries) {
     if (orderEntryClass.isAssignableFrom(orderEntry.getClass())) {
       break;
     }
     moduleSourcesIdx++;
   }
   orderEntries = ArrayUtil.append(orderEntries, orderEntries[moduleSourcesIdx]);
   orderEntries = ArrayUtil.remove(orderEntries, moduleSourcesIdx);
   rootModel.rearrangeOrderEntries(orderEntries);
   return orderEntries.length - 1;
 }
  @Override
  public void setupRootModel(ModifiableRootModel model) throws ConfigurationException {
    String contentPath = getContentEntryPath();
    if (StringUtil.isEmpty(contentPath)) {
      return;
    }
    File contentRootDir = new File(contentPath);
    FileUtilRt.createDirectory(contentRootDir);
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    VirtualFile vContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir);
    if (vContentRootDir == null) {
      return;
    }

    model.addContentEntry(vContentRootDir);

    VirtualFile configFile = getExternalProjectConfigFile(vContentRootDir);
    if (configFile != null && myTemplateConfigName != null) {
      FileTemplateManager manager = FileTemplateManager.getInstance();
      FileTemplate template = manager.getInternalTemplate(myTemplateConfigName);
      try {
        VfsUtil.saveText(configFile, template.getText());
      } catch (IOException e) {
        LOG.warn(
            String.format(
                "Unexpected exception on applying template %s config",
                myExternalSystemId.getReadableName()),
            e);
        throw new ConfigurationException(
            e.getMessage(),
            String.format(
                "Can't apply %s template config text", myExternalSystemId.getReadableName()));
      }
    }

    AbstractExternalSystemSettings settings =
        ExternalSystemApiUtil.getSettings(model.getProject(), myExternalSystemId);
    S externalProjectSettings = createSettings();
    if (myExternalProjectSettingsControl != null) {
      String errorMessage = myExternalProjectSettingsControl.apply(externalProjectSettings);
      myExternalProjectSettingsControl.disposeUIResources();
      if (errorMessage != null) {
        throw new ConfigurationException(errorMessage);
      }
    }
    //noinspection unchecked
    settings.linkProject(externalProjectSettings);
  }
  public void unregisterAll(String path, boolean under, boolean unregisterSources) {
    Url url = toUrl(path);

    for (ContentEntry eachEntry : myRootModel.getContentEntries()) {
      if (unregisterSources) {
        for (SourceFolder eachFolder : eachEntry.getSourceFolders()) {
          String ancestor = under ? url.getUrl() : eachFolder.getUrl();
          String child = under ? eachFolder.getUrl() : url.getUrl();
          if (isEqualOrAncestor(ancestor, child)) {
            eachEntry.removeSourceFolder(eachFolder);
          }
        }
      }

      for (ExcludeFolder eachFolder : eachEntry.getExcludeFolders()) {
        String ancestor = under ? url.getUrl() : eachFolder.getUrl();
        String child = under ? eachFolder.getUrl() : url.getUrl();

        if (isEqualOrAncestor(ancestor, child)) {
          if (eachFolder.isSynthetic()) {
            getCompilerExtension().setExcludeOutput(false);
          } else {
            eachEntry.removeExcludeFolder(eachFolder);
          }
        }
      }
    }
  }
  public void addLibraryDependency(
      MavenArtifact artifact,
      DependencyScope scope,
      MavenModifiableModelsProvider provider,
      MavenProject project) {
    String libraryName = artifact.getLibraryName();

    Library library = provider.getLibraryByName(libraryName);
    if (library == null) {
      library = provider.createLibrary(libraryName);
    }
    Library.ModifiableModel libraryModel = provider.getLibraryModel(library);

    updateUrl(libraryModel, OrderRootType.CLASSES, artifact, null, null, true);
    if (!MavenConstants.SCOPE_SYSTEM.equals(artifact.getScope())) {
      updateUrl(
          libraryModel,
          OrderRootType.SOURCES,
          artifact,
          MavenExtraArtifactType.SOURCES,
          project,
          false);
      updateUrl(
          libraryModel,
          JavadocOrderRootType.getInstance(),
          artifact,
          MavenExtraArtifactType.DOCS,
          project,
          false);
    }

    LibraryOrderEntry e = myRootModel.addLibraryEntry(library);
    e.setScope(scope);
  }
 public void setLanguageLevel(LanguageLevel level) {
   try {
     myRootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(level);
   } catch (IllegalArgumentException e) {
     // bad value was stored
   }
 }
 public OrderEntry[] getOrderEntries() {
   if (myModifiableRootModel == null) { // do not clone all model if not necessary
     return ModuleRootManager.getInstance(getModule()).getOrderEntries();
   } else {
     return myModifiableRootModel.getOrderEntries();
   }
 }
  @Nullable
  @Override
  public Element getSerializedState(
      @NotNull Boolean storageData,
      Object component,
      @NotNull String componentName,
      boolean archive) {
    if (storageData) {
      return null;
    }

    Element element = new Element("component");
    ModifiableRootModel model = null;
    AccessToken token = ReadAction.start();
    try {
      model = ((ModuleRootManagerImpl) component).getModifiableModel();
      // IDEA-137969 Eclipse integration: external remove of classpathentry is not synchronized
      model.clear();
      try {
        myConverter.readClasspath(model);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      ((RootModelImpl) model).writeExternal(element);
    } catch (WriteExternalException e) {
      LOG.error(e);
    } finally {
      try {
        token.finish();
      } finally {
        if (model != null) {
          model.dispose();
        }
      }
    }

    if (myPathMacroSubstitutor != null) {
      myPathMacroSubstitutor.expandPaths(element);
      myPathMacroSubstitutor.addUnknownMacros(
          "NewModuleRootManager", PathMacrosCollector.getMacroNames(element));
    }

    getStorageDataRef().set(true);
    return element;
  }
 public boolean isAlreadyExcluded(File f) {
   String url = toUrl(f.getPath()).getUrl();
   for (ContentEntry eachEntry : myRootModel.getContentEntries()) {
     for (ExcludeFolder eachFolder : eachEntry.getExcludeFolders()) {
       if (isEqualOrAncestor(eachFolder.getUrl(), url)) return true;
     }
   }
   return false;
 }
 public void addJavaRuntimeLibrary(final Module module, final ModifiableRootModel rootModel) {
   final Library library = this.createOrGetXtendJavaLibrary(rootModel, module);
   boolean _and = false;
   boolean _notEquals = (!Objects.equal(library, null));
   if (!_notEquals) {
     _and = false;
   } else {
     LibraryOrderEntry _findLibraryOrderEntry = rootModel.findLibraryOrderEntry(library);
     boolean _tripleEquals = (_findLibraryOrderEntry == null);
     _and = _tripleEquals;
   }
   if (_and) {
     boolean _isWritable = rootModel.isWritable();
     if (_isWritable) {
       rootModel.addLibraryEntry(library);
     }
   }
 }