01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.maven_plugin;
19:
20: import java.io.IOException;
21:
22: import java.net.MalformedURLException;
23: import java.net.URL;
24: import java.util.Enumeration;
25: import java.util.jar.JarEntry;
26: import java.util.jar.JarFile;
27:
28: public final class CodegenUtils {
29:
30: static long timestamp;
31:
32: private CodegenUtils() {
33: //not consructed
34: }
35:
36: public static long getCodegenTimestamp() {
37: if (timestamp != 0) {
38: return timestamp;
39: }
40:
41: getClassTime(CodegenUtils.class);
42:
43: return timestamp;
44: }
45:
46: private static void getClassTime(Class class1) {
47: String str = "/" + class1.getName().replace('.', '/')
48: + ".class";
49: URL url = class1.getResource(str);
50: if (url != null) {
51: while ("jar".equals(url.getProtocol())) {
52: str = url.getPath();
53: if (str.lastIndexOf("!") != -1) {
54: str = str.substring(0, str.lastIndexOf("!"));
55: }
56: try {
57: url = new URL(str);
58: } catch (MalformedURLException e) {
59: return;
60: }
61: }
62: JarFile jar;
63: try {
64: jar = new JarFile(url.getPath());
65: Enumeration entries = jar.entries();
66: while (entries.hasMoreElements()) {
67: JarEntry entry = (JarEntry) entries.nextElement();
68: if (!entry.isDirectory()
69: && !entry.getName().startsWith("META")
70: && entry.getTime() > timestamp) {
71:
72: timestamp = entry.getTime();
73: }
74: }
75: } catch (IOException e) {
76: // TODO Auto-generated catch block
77: e.printStackTrace();
78: }
79: }
80: }
81:
82: }
|