001 package org.kuali.maven.plugins.graph.dot; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 006 import org.apache.maven.artifact.Artifact; 007 import org.kuali.maven.plugins.graph.pojo.Hider; 008 import org.kuali.maven.plugins.graph.tree.Helper; 009 010 public class NodeGenerator { 011 public static final String DEFAULT_TYPE = "jar"; 012 013 protected void add(List<String> list, String s, boolean skip) { 014 if (skip || Helper.isBlank(s)) { 015 return; 016 } else { 017 list.add(s); 018 } 019 } 020 021 public String getLabel(Artifact a) { 022 return getLabel(a, new Hider()); 023 } 024 025 public String getLabel(Artifact a, Hider hider) { 026 027 boolean hideType = hider.isHideType() || DEFAULT_TYPE.equalsIgnoreCase(a.getType()); 028 029 List<String> labelTokens = new ArrayList<String>(); 030 add(labelTokens, a.getGroupId(), hider.isHideGroupId()); 031 add(labelTokens, a.getArtifactId(), hider.isHideArtifactId()); 032 add(labelTokens, a.getType(), hideType); 033 add(labelTokens, a.getClassifier(), hider.isHideClassifier()); 034 add(labelTokens, a.getVersion(), hider.isHideVersion()); 035 return getLabel(labelTokens); 036 } 037 038 protected String getLabel(List<String> tokens) { 039 StringBuilder sb = new StringBuilder(); 040 for (int i = 0; i < tokens.size(); i++) { 041 if (i != 0) { 042 sb.append("\\n"); 043 } 044 sb.append(tokens.get(i)); 045 } 046 return sb.toString(); 047 } 048 049 }