1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
package com.jeantessier.dependencyfinder; |
34 | |
|
35 | |
import java.io.*; |
36 | |
import java.util.jar.*; |
37 | |
|
38 | |
import org.apache.log4j.*; |
39 | |
|
40 | |
public class Version { |
41 | |
public static final String DEFAULT_URL = "http://depfind.sourceforge.net/"; |
42 | |
public static final String DEFAULT_TITLE = "Dependency Finder"; |
43 | |
public static final String DEFAULT_VERSION = "<i>unknown</i>"; |
44 | |
public static final String DEFAULT_VENDOR = "Jean Tessier"; |
45 | |
public static final String DEFAULT_DATE = "<i>unknown</i>"; |
46 | |
public static final String DEFAULT_COPYRIGHT_HOLDER = "Jean Tessier"; |
47 | |
public static final String DEFAULT_COPYRIGHT_DATE = "2001-2009"; |
48 | |
|
49 | 88 | private String resourceURL = null; |
50 | 88 | private String jarName = null; |
51 | |
|
52 | 88 | private Attributes attributes = null; |
53 | |
|
54 | 88 | public Version() { |
55 | 88 | resourceURL = getClass().getResource("Version.class").toString(); |
56 | |
|
57 | 88 | if (resourceURL.startsWith("jar:file:")) { |
58 | 0 | jarName = resourceURL.substring(9, resourceURL.indexOf(".jar!") + 4); |
59 | |
|
60 | |
try { |
61 | 0 | JarFile jar = new JarFile(jarName); |
62 | 0 | Manifest manifest = jar.getManifest(); |
63 | |
|
64 | 0 | attributes = manifest.getMainAttributes(); |
65 | 0 | } catch (IOException ex) { |
66 | 0 | Logger.getLogger(getClass()).error("Could not get version information, using defaults", ex); |
67 | 0 | } |
68 | |
} |
69 | 88 | } |
70 | |
|
71 | |
public String getResourceURL() { |
72 | 0 | return resourceURL; |
73 | |
} |
74 | |
|
75 | |
public String getJarName() { |
76 | 0 | return jarName; |
77 | |
} |
78 | |
|
79 | |
public String getImplementationURL() { |
80 | 344 | String result = DEFAULT_URL; |
81 | |
|
82 | 344 | if (attributes != null) { |
83 | 0 | result = attributes.getValue("Implementation-URL"); |
84 | |
} |
85 | |
|
86 | 344 | return result; |
87 | |
} |
88 | |
|
89 | |
public String getImplementationTitle() { |
90 | 192 | String result = DEFAULT_TITLE; |
91 | |
|
92 | 192 | if (attributes != null) { |
93 | 0 | result = attributes.getValue("Implementation-Title"); |
94 | |
} |
95 | |
|
96 | 192 | return result; |
97 | |
} |
98 | |
|
99 | |
public String getImplementationVersion() { |
100 | 192 | String result = DEFAULT_VERSION; |
101 | |
|
102 | 192 | if (attributes != null) { |
103 | 0 | result = attributes.getValue("Implementation-Version"); |
104 | |
} |
105 | |
|
106 | 192 | return result; |
107 | |
} |
108 | |
|
109 | |
public String getImplementationVendor() { |
110 | 0 | String result = DEFAULT_VENDOR; |
111 | |
|
112 | 0 | if (attributes != null) { |
113 | 0 | result = attributes.getValue("Implementation-Vendor"); |
114 | |
} |
115 | |
|
116 | 0 | return result; |
117 | |
} |
118 | |
|
119 | |
public String getImplementationDate() { |
120 | 192 | String result = DEFAULT_DATE; |
121 | |
|
122 | 192 | if (attributes != null) { |
123 | 0 | result = attributes.getValue("Implementation-Date"); |
124 | |
} |
125 | |
|
126 | 192 | return result; |
127 | |
} |
128 | |
|
129 | |
public String getSpecificationTitle() { |
130 | 0 | String result = DEFAULT_TITLE; |
131 | |
|
132 | 0 | if (attributes != null) { |
133 | 0 | result = attributes.getValue("Specification-Title"); |
134 | |
} |
135 | |
|
136 | 0 | return result; |
137 | |
} |
138 | |
|
139 | |
public String getSpecificationVersion() { |
140 | 0 | String result = DEFAULT_VERSION; |
141 | |
|
142 | 0 | if (attributes != null) { |
143 | 0 | result = attributes.getValue("Specification-Version"); |
144 | |
} |
145 | |
|
146 | 0 | return result; |
147 | |
} |
148 | |
|
149 | |
public String getSpecificationVendor() { |
150 | 0 | String result = DEFAULT_VENDOR; |
151 | |
|
152 | 0 | if (attributes != null) { |
153 | 0 | result = attributes.getValue("Specification-Vendor"); |
154 | |
} |
155 | |
|
156 | 0 | return result; |
157 | |
} |
158 | |
|
159 | |
public String getSpecificationDate() { |
160 | 0 | String result = DEFAULT_DATE; |
161 | |
|
162 | 0 | if (attributes != null) { |
163 | 0 | result = attributes.getValue("Specification-Date"); |
164 | |
} |
165 | |
|
166 | 0 | return result; |
167 | |
} |
168 | |
|
169 | |
public String getCopyrightHolder() { |
170 | 192 | String result = DEFAULT_COPYRIGHT_HOLDER; |
171 | |
|
172 | 192 | if (attributes != null) { |
173 | 0 | result = attributes.getValue("Copyright-Holder"); |
174 | |
} |
175 | |
|
176 | 192 | return result; |
177 | |
} |
178 | |
|
179 | |
public String getCopyrightDate() { |
180 | 192 | String result = DEFAULT_COPYRIGHT_DATE; |
181 | |
|
182 | 192 | if (attributes != null) { |
183 | 0 | result = attributes.getValue("Copyright-Date"); |
184 | |
} |
185 | |
|
186 | 192 | return result; |
187 | |
} |
188 | |
} |