1 /**
2 *
3 * Copyright 2005 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.geronimo.system.plugin;
18
19 import java.io.Serializable;
20 import java.net.URL;
21 import java.util.List;
22 import java.util.ArrayList;
23 import org.apache.geronimo.kernel.repository.Artifact;
24 import org.apache.geronimo.system.configuration.GBeanOverride;
25
26 /**
27 * Various metadata on a configuration that's used when listing, importing,
28 * and exporting configurations.
29 *
30 * @version $Rev: 427388 $ $Date: 2006-07-31 17:43:46 -0700 (Mon, 31 Jul 2006) $
31 */
32 public class PluginMetadata implements Serializable, Comparable {
33 private final String name;
34 private final Artifact moduleId;
35 private final String category;
36 private final String description;
37 private final String pluginURL;
38 private final String author;
39 private License[] licenses = new License[0];
40 private final Hash hash;
41 private String[] geronimoVersions = new String[0];
42 private String[] jvmVersions = new String[0];
43 private Prerequisite[] prerequisites = new Prerequisite[0];
44 private String[] dependencies = new String[0];
45 private String[] forceStart = new String[0];
46 private String[] obsoletes = new String[0];
47 private URL[] repositories = new URL[0];
48 private CopyFile[] filesToCopy = new CopyFile[0];
49 private GBeanOverride[] configXmls = new GBeanOverride[0];
50
51 private final boolean installed;
52 private final boolean eligible;
53
54 public PluginMetadata(String name, Artifact moduleId, String category, String description, String pluginURL, String author, Hash hash, boolean installed, boolean eligible) {
55 this.name = name;
56 this.moduleId = moduleId;
57 this.category = category;
58 this.description = description;
59 this.pluginURL = pluginURL;
60 this.author = author;
61 this.hash = hash;
62 this.installed = installed;
63 this.eligible = eligible;
64 }
65
66 public void setDependencies(String[] dependencies) {
67 this.dependencies = dependencies;
68 }
69
70 public void setObsoletes(String[] obsoletes) {
71 this.obsoletes = obsoletes;
72 }
73
74 public void setForceStart(String[] forceStart) {
75 this.forceStart = forceStart;
76 }
77
78 /**
79 * Gets the Config ID for this configuration, which is a globally unique
80 * identifier.
81 */
82 public Artifact getModuleId() {
83 return moduleId;
84 }
85
86 /**
87 * Gets a human-readable name for this configuration.
88 */
89 public String getName() {
90 return name;
91 }
92
93 /**
94 * Gets a description of this configuration and why it is interesting
95 */
96 public String getDescription() {
97 return description;
98 }
99
100 /**
101 * Gets a description of this module in HTML format (with paragraph
102 * markers).
103 */
104 public String getHTMLDescription() {
105 String[] paras = splitParas(description);
106 StringBuffer buf = new StringBuffer();
107 for (int i = 0; i < paras.length; i++) {
108 String para = paras[i];
109 buf.append("<p>").append(para).append("</p>\n");
110 }
111 return buf.toString();
112 }
113
114 /**
115 * Gets a category name for this configuration. In a list, configurations
116 * in the same category will be listed together. There are no specific
117 * allowed values, though each repository may have standards for that.
118 */
119 public String getCategory() {
120 return category;
121 }
122
123 public boolean isInstalled() {
124 return installed;
125 }
126
127 public String getVersion() {
128 return moduleId.getVersion() == null ? "unknown version" : moduleId.getVersion().toString();
129 }
130
131 /**
132 * Gets the JAR or configuration dependencies for this configuration, Each
133 * String in the result is an Artifact (or Config ID) in String form.
134 * Generally speaking, the dependency names may be partial artifact names
135 * (but not, for example, if this whole thing is a plugin list).
136 */
137 public String[] getDependencies() {
138 return dependencies;
139 }
140
141 /**
142 * Gets the configurations obsoleted by this configuration. Each
143 * String in the result is an Artifact (or Config ID) in String form.
144 */
145 public String[] getObsoletes() {
146 return obsoletes;
147 }
148
149 /**
150 * Gets the configurations that should definitely be started when the
151 * install process completes.
152 */
153 public String[] getForceStart() {
154 return forceStart;
155 }
156
157 public String[] getGeronimoVersions() {
158 return geronimoVersions;
159 }
160
161 public String getAuthor() {
162 return author;
163 }
164
165 public Hash getHash() {
166 return hash;
167 }
168
169 public String getPluginURL() {
170 return pluginURL;
171 }
172
173 public URL[] getRepositories() {
174 return repositories;
175 }
176
177 public void setGeronimoVersions(String[] geronimoVersions) {
178 this.geronimoVersions = geronimoVersions;
179 }
180
181 public License[] getLicenses() {
182 return licenses;
183 }
184
185 public void setLicenses(License[] licenses) {
186 this.licenses = licenses;
187 }
188
189 public String[] getJvmVersions() {
190 return jvmVersions;
191 }
192
193 public void setJvmVersions(String[] jdkVersions) {
194 this.jvmVersions = jdkVersions;
195 }
196
197 public Prerequisite[] getPrerequisites() {
198 return prerequisites;
199 }
200
201 public void setRepositories(URL[] repositories) {
202 this.repositories = repositories;
203 }
204
205 public void setPrerequisites(Prerequisite[] prerequisites) {
206 this.prerequisites = prerequisites;
207 }
208
209 public boolean isEligible() {
210 return eligible;
211 }
212
213 /**
214 * Gets a list of files to copy from the plugin CAR into the server installation.
215 */
216 public CopyFile[] getFilesToCopy() {
217 return filesToCopy;
218 }
219
220 public void setFilesToCopy(CopyFile[] filesToCopy) {
221 this.filesToCopy = filesToCopy;
222 }
223
224 /**
225 * Gets a list of settings to populate in config.xml
226 */
227 public GBeanOverride[] getConfigXmls() {
228 return configXmls;
229 }
230
231 public void setConfigXmls(GBeanOverride[] configXmls) {
232 this.configXmls = configXmls;
233 }
234
235 public int compareTo(Object o) {
236 PluginMetadata other = (PluginMetadata) o;
237 int test = category.compareTo(other.category);
238 if(test != 0) return test;
239 test = name.compareTo(other.name);
240
241 return test;
242 }
243
244 public static class License implements Serializable {
245 private final String name;
246 private final boolean osiApproved;
247
248 public License(String name, boolean osiApproved) {
249 this.name = name;
250 this.osiApproved = osiApproved;
251 }
252
253 public String getName() {
254 return name;
255 }
256
257 public boolean isOsiApproved() {
258 return osiApproved;
259 }
260 }
261
262 public static class Hash implements Serializable {
263 private final String type;
264 private final String value;
265
266 public Hash(String type, String value) {
267 this.type = type;
268 this.value = value;
269 }
270
271 public String getType() {
272 return type;
273 }
274
275 public String getValue() {
276 return value;
277 }
278 }
279
280 public static class CopyFile implements Serializable {
281 private final boolean relativeToVar;
282 private final String sourceFile;
283 private final String destDir;
284
285 public CopyFile(boolean relativeToVar, String sourceFile, String destDir) {
286 this.relativeToVar = relativeToVar;
287 this.sourceFile = sourceFile;
288 this.destDir = destDir;
289 }
290
291 public boolean isRelativeToVar() {
292 return relativeToVar;
293 }
294
295 public String getSourceFile() {
296 return sourceFile;
297 }
298
299 public String getDestDir() {
300 return destDir;
301 }
302 }
303
304 public static class Prerequisite implements Serializable {
305 private final Artifact moduleId;
306 private final String resourceType;
307 private final String description;
308 private final boolean present;
309
310 public Prerequisite(Artifact moduleId, boolean present) {
311 this.moduleId = moduleId;
312 this.present = present;
313 resourceType = null;
314 description = null;
315 }
316
317 public Prerequisite(Artifact moduleId, boolean present, String resourceType, String description) {
318 this.moduleId = moduleId;
319 this.present = present;
320 this.resourceType = resourceType;
321 this.description = description;
322 }
323
324 public Artifact getModuleId() {
325 return moduleId;
326 }
327
328 public String getResourceType() {
329 return resourceType;
330 }
331
332 public String getDescription() {
333 return description;
334 }
335
336 public boolean isPresent() {
337 return present;
338 }
339
340 public String getModuleIdWithStars() {
341 StringBuffer buf = new StringBuffer();
342 if(moduleId.getGroupId() == null) {
343 buf.append("*");
344 } else {
345 buf.append(moduleId.getGroupId());
346 }
347 buf.append("/");
348 if(moduleId.getArtifactId() == null) {
349 buf.append("*");
350 } else {
351 buf.append(moduleId.getArtifactId());
352 }
353 buf.append("/");
354 if(moduleId.getVersion() == null) {
355 buf.append("*");
356 } else {
357 buf.append(moduleId.getVersion());
358 }
359 buf.append("/");
360 if(moduleId.getType() == null) {
361 buf.append("*");
362 } else {
363 buf.append(moduleId.getType());
364 }
365 return buf.toString();
366 }
367 }
368
369 private static String[] splitParas(String desc) {
370 int start = 0, last=0;
371 List list = new ArrayList();
372 boolean inSpace = false, multiple = false;
373 for(int i=0; i<desc.length(); i++) {
374 char c = desc.charAt(i);
375 if(inSpace) {
376 if(Character.isWhitespace(c)) {
377 if(c == '\r' || c == '\n') {
378 multiple = true;
379 for(int j=i+1; j<desc.length(); j++) {
380 char d = desc.charAt(j);
381 if(d != c && (d == '\r' || d == '\n')) {
382 i = j;
383 } else {
384 break;
385 }
386 }
387 }
388 } else {
389 if(multiple) {
390 list.add(desc.substring(last, start).trim());
391 last = i;
392 }
393 inSpace = false;
394 }
395 } else {
396 if(c == '\r' || c == '\n') {
397 inSpace = true;
398 multiple = false;
399 start = i;
400 for(int j=i+1; j<desc.length(); j++) {
401 char d = desc.charAt(j);
402 if(d != c && (d == '\r' || d == '\n')) {
403 i = j;
404 } else {
405 break;
406 }
407 }
408 }
409 }
410 }
411 if(last < desc.length()) {
412 list.add(desc.substring(last).trim());
413 }
414 return (String[]) list.toArray(new String[list.size()]);
415 }
416 }