1
14
15 package com.liferay.portal.plugin;
16
17 import com.liferay.portal.kernel.plugin.Version;
18 import com.liferay.portal.kernel.util.StringPool;
19
20 import java.io.Serializable;
21
22 import java.util.Map;
23 import java.util.StringTokenizer;
24 import java.util.concurrent.ConcurrentHashMap;
25
26
31 public class ModuleId implements Serializable {
32
33 public static ModuleId getInstance(String moduleId) {
34 ModuleId moduleIdObj = _moduleIds.get(moduleId);
35
36 if (moduleIdObj == null) {
37 moduleIdObj = new ModuleId(moduleId);
38
39 _moduleIds.put(moduleId, moduleIdObj);
40 }
41
42 return moduleIdObj;
43 }
44
45 public static String toString(
46 String groupId, String artifactId, String version, String type) {
47
48 return groupId + StringPool.SLASH + artifactId + StringPool.SLASH +
49 version + StringPool.SLASH + type;
50 }
51
52 public String getGroupId() {
53 return _groupId;
54 }
55
56 public String getArtifactId() {
57 return _artifactId;
58 }
59
60 public String getPackageId() {
61 return _groupId + StringPool.SLASH + _artifactId;
62 }
63
64 public String getVersion() {
65 return _pluginVersion.toString();
66 }
67
68 public String getType() {
69 return _type;
70 }
71
72 public String getArtifactPath() {
73 return StringPool.SLASH + _groupId + StringPool.SLASH + _artifactId +
74 StringPool.SLASH + _pluginVersion + StringPool.SLASH +
75 getArtifactWARName();
76 }
77
78 public String getArtifactWARName() {
79 return _artifactId + StringPool.DASH + _pluginVersion +
80 StringPool.PERIOD + _type;
81 }
82
83 public boolean isLaterVersionThan(String version) {
84 return _pluginVersion.isLaterVersionThan(version);
85 }
86
87 public boolean isPreviousVersionThan(String version) {
88 return _pluginVersion.isPreviousVersionThan(version);
89 }
90
91 public boolean isSameVersionAs(String version) {
92 return _pluginVersion.isSameVersionAs(version);
93 }
94
95 public boolean equals(Object obj) {
96 if (!(obj instanceof ModuleId)) {
97 return false;
98 }
99
100 ModuleId moduleId = (ModuleId)obj;
101
102 return toString().equals(moduleId.toString());
103 }
104
105 public int hashCode() {
106 return toString().hashCode();
107 }
108
109 public String toString() {
110 return toString(
111 _groupId, _artifactId, _pluginVersion.toString(), _type);
112 }
113
114 protected ModuleId(
115 String groupId, String artifactId, Version pluginVersion, String type) {
116
117 _groupId = groupId;
118 _artifactId = artifactId;
119 _pluginVersion = pluginVersion;
120 _type = type;
121 }
122
123 protected ModuleId(String moduleId) {
124 StringTokenizer st = new StringTokenizer(moduleId, StringPool.SLASH);
125
126 if (st.countTokens() < 4) {
127 throw new RuntimeException(
128 "The moduleId " + moduleId + " is not correct");
129 }
130
131 _groupId = st.nextToken();
132 _artifactId = st.nextToken();
133 _pluginVersion = Version.getInstance(st.nextToken());
134 _type = st.nextToken();
135 }
136
137 private static Map<String, ModuleId> _moduleIds =
138 new ConcurrentHashMap<String, ModuleId>();
139
140 private String _artifactId;
141 private String _groupId;
142 private Version _pluginVersion;
143 private String _type;
144
145 }