001 package org.kuali.maven.plugins.graph.sanitize;
002
003 import java.util.Map;
004
005 import org.apache.maven.artifact.Artifact;
006 import org.kuali.maven.plugins.graph.pojo.MavenContext;
007 import org.kuali.maven.plugins.graph.pojo.State;
008 import org.kuali.maven.plugins.graph.tree.TreeHelper;
009 import org.slf4j.Logger;
010 import org.slf4j.LoggerFactory;
011
012 public class ConflictSanitizer extends MavenContextSanitizer {
013 private static final Logger logger = LoggerFactory.getLogger(ConflictSanitizer.class);
014
015 public ConflictSanitizer() {
016 this(null);
017 }
018
019 public ConflictSanitizer(Map<String, MavenContext> included) {
020 super(included, State.CONFLICT);
021 }
022
023 @Override
024 protected void sanitize(MavenContext context, Map<String, MavenContext> included) {
025 String artifactId = TreeHelper.getArtifactId(context.getDependencyNode().getArtifact());
026 MavenContext replacement = included.get(artifactId);
027
028 // This is ok. Kind of. Maven has marked it as a conflict, but it should be duplicate
029 if (replacement != null) {
030 // Emit an "info" level log message and switch to DUPLICATE
031 State switchTo = State.DUPLICATE;
032 logger.info(getSwitchMessage(artifactId, switchTo));
033 logger.info("Identical replacement for a 'conflict' artifact");
034 context.setState(switchTo);
035 return;
036 }
037
038 // Conflict with no related artifact is not ok
039 Artifact related = context.getDependencyNode().getRelatedArtifact();
040 if (related == null) {
041 warnAndSwitch(State.UNKNOWN, artifactId, context, "No related artifact");
042 return;
043 }
044
045 // Examine the related artifact
046 String relatedArtifactId = TreeHelper.getArtifactId(related);
047 replacement = included.get(relatedArtifactId);
048 if (replacement != null) {
049 // This is ok. We located the replacement
050 logger.debug(artifactId + " meets conflict node criteria.");
051 return;
052 } else {
053 // This is not ok. The related artifact is not in the included list
054 warnAndSwitch(State.UNKNOWN, artifactId, context, "No conflict replacement was found");
055 return;
056 }
057 }
058
059 }