File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\maven-plugin\src\main\java\hudson\maven\ModuleName.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.maven;
25
26 import org.apache.maven.execution.ExecutionEvent;
27 import org.apache.maven.project.MavenProject;
28 import org.apache.maven.model.Plugin;
29 import org.apache.maven.model.Extension;
30 import org.apache.maven.model.Dependency;
31 import org.apache.maven.model.ReportPlugin;
32
33 import java.io.Serializable;
34
35 /**
36 * Version independent name of a Maven project. GroupID+artifactId.
37 *
38 * @author Kohsuke Kawaguchi
39 * @see ModuleDependency
40 */
41 public class ModuleName implements Comparable<ModuleName>, Serializable {
42 public final String groupId;
43 public final String artifactId;
44
45 public ModuleName(String groupId, String artifactId) {
46 this.groupId = groupId;
47 this.artifactId = artifactId;
48 }
49
50 public ModuleName(ExecutionEvent event) {
51 this(event.getProject());
52 }
53
54 public ModuleName(MavenProject project) {
55 this(project.getGroupId(),project.getArtifactId());
56 }
57
58 public ModuleName(Plugin plugin) {
59 this(plugin.getGroupId(),plugin.getArtifactId());
60 }
61
62 public ModuleName(ReportPlugin plugin) {
63 this(plugin.getGroupId(),plugin.getArtifactId());
64 }
65
66 public ModuleName(Extension ext) {
67 this(ext.getGroupId(),ext.getArtifactId());
68 }
69
70 public ModuleName(Dependency dep) {
71 this(dep.getGroupId(),dep.getArtifactId());
72 }
73
74 /**
75 * Returns the "groupId:artifactId" form.
76 */
77 public String toString() {
78 return groupId+':'+artifactId;
79 }
80
81 /**
82 * Returns the "groupId$artifactId" form,
83 * which is safe for the use as a file name, unlike {@link #toString()}.
84 */
85 public String toFileSystemName() {
86 return groupId+'$'+artifactId;
87 }
88
89 public static ModuleName fromFileSystemName(String n) {
90 int idx = n.indexOf('$');
91 if(idx<0) throw new IllegalArgumentException(n);
92 return new ModuleName(n.substring(0,idx),n.substring(idx+1));
93 }
94
95 public static ModuleName fromString(String n) {
96 int idx = Math.max(n.indexOf(':'),n.indexOf('$'));
97 if(idx<0) throw new IllegalArgumentException(n);
98 return new ModuleName(n.substring(0,idx),n.substring(idx+1));
99 }
100
101 /**
102 * Checks if the given name is valid module name string format
103 * created by {@link #toString()}.
104 */
105 public static boolean isValid(String n) {
106 return Math.max(n.indexOf(':'),n.indexOf('$'))>0;
107 }
108
109 public boolean equals(Object o) {
110 if (this == o) return true;
111 if (o == null || getClass() != o.getClass()) return false;
112
113 ModuleName that = (ModuleName) o;
114
115 return artifactId.equals(that.artifactId)
116 && groupId.equals(that.groupId);
117
118 }
119
120 public int hashCode() {
121 int result;
122 result = groupId.hashCode();
123 result = 31 * result + artifactId.hashCode();
124 return result;
125 }
126
127 public int compareTo(ModuleName that) {
128 int r = this.groupId.compareTo(that.groupId);
129 if(r!=0) return r;
130 return this.artifactId.compareTo(that.artifactId);
131 }
132
133 private static final long serialVersionUID = 1L;
134 }
135