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