1 package hudson.maven; 2 3 import org.apache.maven.project.MavenProject; 4 import org.apache.maven.model.Plugin; 5 import org.apache.maven.model.Extension; 6 import org.apache.maven.model.Dependency; 7 import org.apache.maven.model.ReportPlugin; 8 9 import java.io.Serializable ; 10 11 16 public class ModuleName implements Comparable <ModuleName>, Serializable { 17 public final String groupId; 18 public final String artifactId; 19 20 public ModuleName(String groupId, String artifactId) { 21 this.groupId = groupId; 22 this.artifactId = artifactId; 23 } 24 25 public ModuleName(MavenProject project) { 26 this(project.getGroupId(),project.getArtifactId()); 27 } 28 29 public ModuleName(Plugin plugin) { 30 this(plugin.getGroupId(),plugin.getArtifactId()); 31 } 32 33 public ModuleName(ReportPlugin plugin) { 34 this(plugin.getGroupId(),plugin.getArtifactId()); 35 } 36 37 public ModuleName(Extension ext) { 38 this(ext.getGroupId(),ext.getArtifactId()); 39 } 40 41 public ModuleName(Dependency dep) { 42 this(dep.getGroupId(),dep.getArtifactId()); 43 } 44 45 48 public String toString() { 49 return groupId+':'+artifactId; 50 } 51 52 56 public String toFileSystemName() { 57 return groupId+'$'+artifactId; 58 } 59 60 public static ModuleName fromFileSystemName(String n) { 61 int idx = n.indexOf('$'); 62 if(idx<0) throw new IllegalArgumentException (n); 63 return new ModuleName(n.substring(0,idx),n.substring(idx+1)); 64 } 65 66 public static ModuleName fromString(String n) { 67 int idx = n.indexOf(':'); 68 if(idx<0) throw new IllegalArgumentException (n); 69 return new ModuleName(n.substring(0,idx),n.substring(idx+1)); 70 } 71 72 76 public static boolean isValid(String n) { 77 return n.indexOf(':')>0; 78 } 79 80 public boolean equals(Object o) { 81 if (this == o) return true; 82 if (o == null || getClass() != o.getClass()) return false; 83 84 ModuleName that = (ModuleName) o; 85 86 return artifactId.equals(that.artifactId) 87 && groupId.equals(that.groupId); 88 89 } 90 91 public int hashCode() { 92 int result; 93 result = groupId.hashCode(); 94 result = 31 * result + artifactId.hashCode(); 95 return result; 96 } 97 98 public int compareTo(ModuleName that) { 99 int r = this.groupId.compareTo(that.groupId); 100 if(r!=0) return r; 101 return this.artifactId.compareTo(that.artifactId); 102 } 103 104 private static final long serialVersionUID = 1L; 105 } 106 | Popular Tags |