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); } }); } }
private void createExclusion(MavenArtifact artifactToExclude, MavenDomExclusions exclusions) { MavenDomExclusion exclusion = exclusions.addExclusion(); exclusion.getGroupId().setValue(artifactToExclude.getGroupId()); exclusion.getArtifactId().setValue(artifactToExclude.getArtifactId()); }