1 package de.matthias_burbach.deputy.core.project; 2 3 import java.util.ArrayList; 4 import java.util.Iterator; 5 import java.util.List; 6 7 8 /*** 9 * @author Matthias Burbach 10 */ 11 public class ProjectConflictGroup { 12 /*** 13 * The estimated severity INFO of this version conflict. 14 * INFO means that versions only differ in their micro versions. 15 */ 16 public static final int SEVERITY_INFO = 0; 17 18 /*** 19 * The estimated severity WARNING of this version conflict. 20 * WARNING means that versions differ in their minor versions. 21 */ 22 public static final int SEVERITY_WARNING = 1; 23 24 /*** 25 * The estimated severity ERROR of this version conflict. 26 * ERROR means that versions even differ in their major versions. 27 */ 28 public static final int SEVERITY_ERROR = 2; 29 30 /*** 31 * The list of projects of type {@link Project} that are members 32 * of this conflict group. They all share the same artifact id but 33 * have pairwise different versions. 34 */ 35 private List projects = new ArrayList(); 36 37 /*** 38 * The common artifact id of the projects of this conflict group. 39 */ 40 private String artifactId; 41 42 /*** 43 * @return The common artifact id of the projects of this conflict group. 44 */ 45 public String getArtifactId() { 46 return artifactId; 47 } 48 49 /*** 50 * @param artifactId The common artifact id of the projects of this conflict 51 * group. 52 */ 53 public void setArtifactId(final String artifactId) { 54 this.artifactId = artifactId; 55 } 56 57 /*** 58 * @return The list of projects of type {@link Project} that are members 59 * of this conflict group. They all share the same artifact id but 60 * have pairwise different versions. 61 */ 62 public List getProjects() { 63 return projects; 64 } 65 66 /*** 67 * @param projects The list of projects of type {@link Project} that are 68 * members of this conflict group. They all share the same 69 * artifact id but have pairwise different versions. 70 */ 71 public void setProjects(final List projects) { 72 this.projects = projects; 73 } 74 75 /*** 76 * @return The estimated severity of the conflict. Is one of 77 * {@link #SEVERITY_INFO}, {@link #SEVERITY_WARNING}, 78 * {@link #SEVERITY_ERROR}. 79 */ 80 public int getSeverity() { 81 int result = SEVERITY_INFO; 82 int major = -1; 83 int minor = -1; 84 for (Iterator iter = projects.iterator(); iter.hasNext();) { 85 Project project = (Project) iter.next(); 86 if (project.getMajorVersion() != null) { 87 if (major == -1) { 88 major = project.getMajorVersion().intValue(); 89 } else if (major != project.getMajorVersion().intValue()) { 90 result = SEVERITY_ERROR; 91 break; 92 } 93 if (project.getMinorVersion() != null) { 94 if (minor == -1) { 95 minor = project.getMinorVersion().intValue(); 96 } else if (minor != project.getMinorVersion().intValue()) { 97 result = SEVERITY_WARNING; 98 } 99 if (project.getMicroVersion() == null) { 100 result = SEVERITY_WARNING; 101 } 102 } else { 103 result = SEVERITY_WARNING; 104 } 105 } else { 106 result = SEVERITY_WARNING; 107 } 108 } 109 return result; 110 } 111 }