01: package org.objectweb.celtix.maven_plugin;
02:
03: import java.io.IOException;
04:
05: import java.net.MalformedURLException;
06: import java.net.URL;
07: import java.util.Enumeration;
08: import java.util.jar.JarEntry;
09: import java.util.jar.JarFile;
10:
11: import org.objectweb.celtix.tools.WSDLToJava;
12:
13: public final class CodegenUtils {
14:
15: static long timestamp;
16:
17: private CodegenUtils() {
18: //not consructed
19: }
20:
21: public static long getCodegenTimestamp() {
22: if (timestamp != 0) {
23: return timestamp;
24: }
25:
26: getClassTime(CodegenUtils.class);
27: getClassTime(WSDLToJava.class);
28:
29: return timestamp;
30: }
31:
32: private static void getClassTime(Class class1) {
33: String str = "/" + class1.getName().replace('.', '/')
34: + ".class";
35: URL url = class1.getResource(str);
36: if (url != null) {
37: while ("jar".equals(url.getProtocol())) {
38: str = url.getPath();
39: if (str.lastIndexOf("!") != -1) {
40: str = str.substring(0, str.lastIndexOf("!"));
41: }
42: try {
43: url = new URL(str);
44: } catch (MalformedURLException e) {
45: return;
46: }
47: }
48: JarFile jar;
49: try {
50: jar = new JarFile(url.getPath());
51: Enumeration entries = jar.entries();
52: while (entries.hasMoreElements()) {
53: JarEntry entry = (JarEntry) entries.nextElement();
54: if (!entry.isDirectory()
55: && !entry.getName().startsWith("META")
56: && entry.getTime() > timestamp) {
57:
58: timestamp = entry.getTime();
59: }
60: }
61: } catch (IOException e) {
62: // TODO Auto-generated catch block
63: e.printStackTrace();
64: }
65: }
66: }
67:
68: }
|