private void configDependencies() {
    for (MavenArtifact artifact : myMavenProject.getDependencies()) {
      if (!myMavenProject.isSupportedDependency(artifact, SupportedRequestType.FOR_IMPORT))
        continue;

      DependencyScope scope = selectScope(artifact.getScope());
      MavenProject depProject = myMavenTree.findProject(artifact.getMavenId());

      if (depProject != null) {
        if (depProject == myMavenProject) continue;
        boolean isTestJar =
            MavenConstants.TYPE_TEST_JAR.equals(artifact.getType())
                || "tests".equals(artifact.getClassifier());
        myRootModelAdapter.addModuleDependency(
            myMavenProjectToModuleName.get(depProject), scope, isTestJar);

        Element buildHelperCfg =
            depProject.getPluginGoalConfiguration(
                "org.codehaus.mojo", "build-helper-maven-plugin", "attach-artifact");
        if (buildHelperCfg != null) {
          addAttachArtifactDependency(buildHelperCfg, scope, depProject, artifact);
        }
      } else {
        myRootModelAdapter.addLibraryDependency(
            artifact, scope, myModifiableModelsProvider, myMavenProject);
      }
    }

    configSurefirePlugin();
  }
  public void config(boolean isNewlyCreatedModule) {
    myRootModelAdapter =
        new MavenRootModelAdapter(myMavenProject, myModule, myModifiableModelsProvider);
    myRootModelAdapter.init(isNewlyCreatedModule);

    configFolders();
    configDependencies();
    configLanguageLevel();
    configEncoding();
    configAnnotationProcessors();
    excludeFromCompilationArchetypeResources();
  }
  private void addAttachArtifactDependency(
      @NotNull Element buildHelperCfg,
      @NotNull DependencyScope scope,
      @NotNull MavenProject mavenProject,
      @NotNull MavenArtifact artifact) {
    Library.ModifiableModel libraryModel = null;

    for (Element artifactsElement : (List<Element>) buildHelperCfg.getChildren("artifacts")) {
      for (Element artifactElement : (List<Element>) artifactsElement.getChildren("artifact")) {
        String typeString = artifactElement.getChildTextTrim("type");
        if (typeString != null && !typeString.equals("jar")) continue;

        OrderRootType rootType = OrderRootType.CLASSES;

        String classifier = artifactElement.getChildTextTrim("classifier");
        if ("sources".equals(classifier)) {
          rootType = OrderRootType.SOURCES;
        } else if ("javadoc".equals(classifier)) {
          rootType = JavadocOrderRootType.getInstance();
        }

        String filePath = artifactElement.getChildTextTrim("file");
        if (StringUtil.isEmpty(filePath)) continue;

        VirtualFile file = VfsUtil.findRelativeFile(filePath, mavenProject.getDirectoryFile());
        if (file == null) continue;

        file = JarFileSystem.getInstance().getJarRootForLocalFile(file);
        if (file == null) continue;

        if (libraryModel == null) {
          String libraryName = artifact.getLibraryName();
          assert libraryName.startsWith(MavenArtifact.MAVEN_LIB_PREFIX);
          libraryName =
              MavenArtifact.MAVEN_LIB_PREFIX
                  + "ATTACHED-JAR: "
                  + libraryName.substring(MavenArtifact.MAVEN_LIB_PREFIX.length());

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

          LibraryOrderEntry entry = myRootModelAdapter.getRootModel().addLibraryEntry(library);
          entry.setScope(scope);
        }

        libraryModel.addRoot(file, rootType);
      }
    }
  }
 private void configLanguageLevel() {
   final LanguageLevel level = LanguageLevel.parse(myMavenProject.getSourceLevel());
   myRootModelAdapter.setLanguageLevel(level);
 }
  private void configSurefirePlugin() {
    List<String> urls = new ArrayList<String>();

    AccessToken accessToken = ReadAction.start();
    try {
      MavenDomProjectModel domModel = null;

      Element config =
          myMavenProject.getPluginConfiguration(
              "org.apache.maven.plugins", "maven-surefire-plugin");
      for (String each :
          MavenJDOMUtil.findChildrenValuesByPath(
              config, "additionalClasspathElements", "additionalClasspathElement")) {
        String url = VfsUtil.pathToUrl(each);

        if (domModel == null) {
          domModel =
              MavenDomUtil.getMavenDomProjectModel(myModule.getProject(), myMavenProject.getFile());
        }

        if (domModel != null) {
          url = MavenPropertyResolver.resolve(url, domModel);
        }

        urls.add(url);
      }
    } finally {
      accessToken.finish();
    }

    LibraryTable moduleLibraryTable = myRootModelAdapter.getRootModel().getModuleLibraryTable();

    Library library = moduleLibraryTable.getLibraryByName(SUREFIRE_PLUGIN_LIBRARY_NAME);
    if (library == null) {
      if (urls.isEmpty()) {
        return;
      }

      library = moduleLibraryTable.createLibrary(SUREFIRE_PLUGIN_LIBRARY_NAME);
      LibraryOrderEntry orderEntry =
          myRootModelAdapter.getRootModel().findLibraryOrderEntry(library);
      orderEntry.setScope(DependencyScope.TEST);
    } else {
      if (urls.isEmpty()) {
        moduleLibraryTable.removeLibrary(library);
        return;
      }
    }

    String[] oldUrls = library.getUrls(OrderRootType.CLASSES);
    if (!urls.equals(Arrays.asList(oldUrls))) {
      Library.ModifiableModel modifiableModel = library.getModifiableModel();

      for (String url : oldUrls) {
        modifiableModel.removeRoot(url, OrderRootType.CLASSES);
      }

      for (String url : urls) {
        modifiableModel.addRoot(url, OrderRootType.CLASSES);
      }

      modifiableModel.commit();
    }
  }
 public ModifiableRootModel getRootModel() {
   return myRootModelAdapter.getRootModel();
 }