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: import org.apache.cxf.tools.wsdlto.WSDLToJava;
29:
30: public final class CodegenUtils {
31:
32: static long timestamp;
33:
34: private CodegenUtils() {
35: //not consructed
36: }
37:
38: public static long getCodegenTimestamp() {
39: if (timestamp != 0) {
40: return timestamp;
41: }
42:
43: getClassTime(CodegenUtils.class);
44: getClassTime(WSDLToJava.class);
45:
46: return timestamp;
47: }
48:
49: private static void getClassTime(Class class1) {
50: String str = "/" + class1.getName().replace('.', '/')
51: + ".class";
52: URL url = class1.getResource(str);
53: if (url != null) {
54: while ("jar".equals(url.getProtocol())) {
55: str = url.getPath();
56: if (str.lastIndexOf("!") != -1) {
57: str = str.substring(0, str.lastIndexOf("!"));
58: }
59: try {
60: url = new URL(str);
61: } catch (MalformedURLException e) {
62: return;
63: }
64: }
65: JarFile jar;
66: try {
67: jar = new JarFile(url.getPath());
68: Enumeration entries = jar.entries();
69: while (entries.hasMoreElements()) {
70: JarEntry entry = (JarEntry) entries.nextElement();
71: if (!entry.isDirectory()
72: && !entry.getName().startsWith("META")
73: && entry.getTime() > timestamp) {
74:
75: timestamp = entry.getTime();
76: }
77: }
78: } catch (IOException e) {
79: // TODO Auto-generated catch block
80: e.printStackTrace();
81: }
82: }
83: }
84:
85: }
|