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);
                }
              });
    }
  }
Exemplo n.º 2
0
  public static int getCollectionIndex(
      @NotNull final MavenDomDependencies dependencies, @Nullable final Editor editor) {
    if (editor != null) {
      int offset = editor.getCaretModel().getOffset();

      List<MavenDomDependency> dependencyList = dependencies.getDependencies();

      for (int i = 0; i < dependencyList.size(); i++) {
        MavenDomDependency dependency = dependencyList.get(i);
        XmlElement xmlElement = dependency.getXmlElement();

        if (xmlElement != null && xmlElement.getTextRange().getStartOffset() >= offset) {
          return i;
        }
      }
    }
    return -1;
  }