@NotNull
  private static Map<Module, String> collectJpsPluginModules(@NotNull Module module) {
    XmlFile pluginXml = PluginModuleType.getPluginXml(module);
    if (pluginXml == null) return Collections.emptyMap();

    DomFileElement<IdeaPlugin> fileElement =
        DomManager.getDomManager(module.getProject()).getFileElement(pluginXml, IdeaPlugin.class);
    if (fileElement == null) return Collections.emptyMap();

    Map<Module, String> jpsPluginToOutputPath = new HashMap<Module, String>();
    IdeaPlugin plugin = fileElement.getRootElement();
    List<Extensions> extensions = plugin.getExtensions();
    for (Extensions extensionGroup : extensions) {
      XmlTag extensionsTag = extensionGroup.getXmlTag();
      String defaultExtensionNs = extensionsTag.getAttributeValue("defaultExtensionNs");
      for (XmlTag tag : extensionsTag.getSubTags()) {
        String name = tag.getLocalName();
        String qualifiedName = defaultExtensionNs != null ? defaultExtensionNs + "." + name : name;
        if (CompileServerPlugin.EP_NAME.getName().equals(qualifiedName)) {
          String classpath = tag.getAttributeValue("classpath");
          if (classpath != null) {
            for (String path : StringUtil.split(classpath, ";")) {
              String moduleName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path));
              Module jpsModule =
                  ModuleManager.getInstance(module.getProject()).findModuleByName(moduleName);
              if (jpsModule != null) {
                jpsPluginToOutputPath.put(jpsModule, path);
              }
            }
          }
        }
      }
    }
    return jpsPluginToOutputPath;
  }
  private void exclude() {
    final MavenArtifact artifactToExclude = mavenArtifactNode.getArtifact();
    final MavenArtifactNode oldestParent = getOldestParentMavenArtifact();

    DomFileElement domFileElement = getDomFileElement(oldestParent);

    if (domFileElement != null) {
      final MavenDomProjectModel rootElement =
          (MavenDomProjectModel) domFileElement.getRootElement();
      final MavenDomDependencies dependencies = rootElement.getDependencies();
      boolean found = false;

      for (MavenDomDependency mavenDomDependency : dependencies.getDependencies()) {
        if (isSameDependency(oldestParent.getArtifact(), mavenDomDependency)) {
          found = true;
          final MavenDomExclusions exclusions = mavenDomDependency.getExclusions();
          for (MavenDomExclusion mavenDomExclusion : exclusions.getExclusions()) {
            if (isSameDependency(artifactToExclude, mavenDomExclusion)) {
              return;
            }
          }
          createExclusion(artifactToExclude, exclusions);
          dependencyExcluded();
        }
      }
      if (!found) {
        final Notification notification =
            new Notification(
                MAVEN_HELPER_DEPENDENCY_ANALYZER_NOTIFICATION,
                "",
                "Parent dependency not found, it is probably in parent pom",
                NotificationType.WARNING);
        ApplicationManager.getApplication()
            .invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    Notifications.Bus.notify(notification, project);
                  }
                });
      }
    } else {
      final Notification notification =
          new Notification(
              MAVEN_HELPER_DEPENDENCY_ANALYZER_NOTIFICATION,
              "",
              "Pom file not found",
              NotificationType.WARNING);
      ApplicationManager.getApplication()
          .invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  Notifications.Bus.notify(notification, project);
                }
              });
    }
  }
  @Override
  public void checkFileElement(
      DomFileElement<MavenDomProjectModel> domFileElement, DomElementAnnotationHolder holder) {

    final XmlFile xmlFile = domFileElement.getFile();
    MavenDomProjectModel projectModel = domFileElement.getRootElement();

    checkMavenProjectModel(projectModel, xmlFile, holder);
  }
Exemplo n.º 4
0
 @Nullable
 public static <T extends MavenDomElement> T getMavenDomModel(
     @NotNull PsiFile file, @NotNull Class<T> clazz) {
   DomFileElement<T> fileElement = getMavenDomFile(file, clazz);
   return fileElement == null ? null : fileElement.getRootElement();
 }