1 | /* | |
2 | * JBoss, Home of Professional Open Source | |
3 | * Copyright 2013, Red Hat, Inc. and individual contributors | |
4 | * by the @authors tag. See the copyright.txt in the distribution for a | |
5 | * full listing of individual contributors. | |
6 | * | |
7 | * This is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU Lesser General Public License as | |
9 | * published by the Free Software Foundation; either version 2.1 of | |
10 | * the License, or (at your option) any later version. | |
11 | * | |
12 | * This software is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this software; if not, write to the Free | |
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
21 | */ | |
22 | package com.lowagie.text; | |
23 | ||
24 | import java.io.IOException; | |
25 | import java.io.InputStream; | |
26 | import java.net.JarURLConnection; | |
27 | import java.net.URL; | |
28 | import java.net.URLConnection; | |
29 | import java.security.CodeSource; | |
30 | import java.security.ProtectionDomain; | |
31 | import java.text.MessageFormat; | |
32 | import java.util.jar.Attributes; | |
33 | import java.util.jar.JarFile; | |
34 | import java.util.jar.JarInputStream; | |
35 | import java.util.jar.Manifest; | |
36 | ||
37 | ||
38 | /** | |
39 | * Vendor and version information for A4J project | |
40 | * | |
41 | * @author asmirnov@exadel.com (latest modification by $Author$) | |
42 | * @version $Revision$ $Date$ | |
43 | */ | |
44 | final class VersionBean { | |
45 | public static final Version VERSION = new Version(); | |
46 | ||
47 | /** | |
48 | * Class for incapsulate version info. | |
49 | * | |
50 | * @author asmirnov@exadel.com (latest modification by $Author$) | |
51 | * @version $Revision$ $Date$ | |
52 | */ | |
53 | public static class Version { | |
54 | private static final String UNKNOWN = ""; | |
55 | private String implementationVendor = UNKNOWN; | |
56 | // TODO nick - default value for manifest file absense - review | |
57 | private String implementationVersion = "1.0.0"; | |
58 | private String bundleVersion = "1.0.0"; | |
59 | private String implementationTitle = UNKNOWN; | |
60 | private String scmTimestamp = UNKNOWN; | |
61 | private String fullVersionString = UNKNOWN; | |
62 | private boolean containsDataFromManifest = false; | |
63 | ||
64 | public Version() { | |
65 |
1
1. |
initialize(); |
66 | } | |
67 | ||
68 | private String getAttributeValueOrDefault(Attributes attributes, String name) { | |
69 | String value = attributes.getValue(name); | |
70 |
1
1. getAttributeValueOrDefault : negated conditional → SURVIVED |
if (value == null) { |
71 | value = UNKNOWN; | |
72 | } | |
73 | ||
74 |
1
1. getAttributeValueOrDefault : mutated return of Object value for com/lowagie/text/VersionBean$Version::getAttributeValueOrDefault to ( if (x != null) null else throw new RuntimeException ) → SURVIVED |
return value; |
75 | } | |
76 | ||
77 | private void initialize() { | |
78 | Manifest manifest = null; | |
79 | try { | |
80 | manifest = readManifest(); | |
81 |
1
1. initialize : negated conditional → SURVIVED |
if (manifest != null) { |
82 |
1
1. initialize : removed call to com/lowagie/text/VersionBean$Version::initializePropertiesFromManifest → SURVIVED |
initializePropertiesFromManifest(manifest); |
83 |
1
1. initialize : removed call to com/lowagie/text/VersionBean$Version::initializeDerivativeProperties → SURVIVED |
initializeDerivativeProperties(); |
84 | } | |
85 | } catch (Exception e) { | |
86 | } | |
87 | ||
88 | | |
89 | } | |
90 | ||
91 | private void initializePropertiesFromManifest(Manifest manifest) { | |
92 | containsDataFromManifest = true; | |
93 | ||
94 | Attributes attributes = manifest.getMainAttributes(); | |
95 | implementationVendor = getAttributeValueOrDefault(attributes, "Implementation-Vendor"); | |
96 | implementationVersion = getAttributeValueOrDefault(attributes, "Implementation-Version"); | |
97 | bundleVersion = getAttributeValueOrDefault(attributes, "Bundle-Version"); | |
98 | implementationTitle = getAttributeValueOrDefault(attributes, "Implementation-Title"); | |
99 | scmTimestamp = getAttributeValueOrDefault(attributes, "SCM-Timestamp"); | |
100 | | |
101 |
2
1. initializePropertiesFromManifest : negated conditional → SURVIVED 2. initializePropertiesFromManifest : negated conditional → SURVIVED |
if (isEmpty(implementationVersion) && !isEmpty(bundleVersion)) { |
102 | implementationVersion = bundleVersion; | |
103 | } | |
104 | } | |
105 | private boolean isEmpty(String value) { | |
106 |
3
1. isEmpty : negated conditional → SURVIVED 2. isEmpty : negated conditional → SURVIVED 3. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED |
return value == null || value.length() == 0; |
107 | } | |
108 | ||
109 | private void initializeDerivativeProperties() { | |
110 | fullVersionString = MessageFormat.format("{0}", implementationVersion); | |
111 | } | |
112 | ||
113 | private Manifest readManifest() { | |
114 | ProtectionDomain domain = VersionBean.class.getProtectionDomain(); | |
115 |
1
1. readManifest : negated conditional → SURVIVED |
if (domain != null) { |
116 | CodeSource codeSource = domain.getCodeSource(); | |
117 |
1
1. readManifest : negated conditional → SURVIVED |
if (codeSource != null) { |
118 | URL url = codeSource.getLocation(); | |
119 |
1
1. readManifest : negated conditional → SURVIVED |
if (url != null) { |
120 | InputStream manifestStream = null; | |
121 | try { | |
122 | URL manifestFileUrl; | |
123 |
1
1. readManifest : negated conditional → SURVIVED |
if ("vfs".equals(url.getProtocol())) { |
124 | String manifestFile = String.format("%s/%s", url.toExternalForm(), JarFile.MANIFEST_NAME); | |
125 | manifestFileUrl = new URL(manifestFile); | |
126 | } else { | |
127 | manifestFileUrl = new URL(url, JarFile.MANIFEST_NAME); | |
128 | } | |
129 | manifestStream = urlToStream(manifestFileUrl); | |
130 |
1
1. readManifest : mutated return of Object value for com/lowagie/text/VersionBean$Version::readManifest to ( if (x != null) null else throw new RuntimeException ) → SURVIVED |
return new Manifest(manifestStream); |
131 | } catch (IOException e1) { | |
132 | ||
133 | } finally { | |
134 |
1
1. readManifest : negated conditional → SURVIVED |
if (manifestStream != null) { |
135 | try { | |
136 |
1
1. readManifest : removed call to java/io/InputStream::close → NO_COVERAGE |
manifestStream.close(); |
137 | } catch (IOException e) { | |
138 | } | |
139 | } | |
140 | } | |
141 | ||
142 | JarInputStream jis = null; | |
143 | try { | |
144 | URLConnection urlConnection = url.openConnection(); | |
145 |
1
1. readManifest : removed call to java/net/URLConnection::setUseCaches → SURVIVED |
urlConnection.setUseCaches(false); |
146 | ||
147 |
1
1. readManifest : negated conditional → SURVIVED |
if (urlConnection instanceof JarURLConnection) { |
148 | JarURLConnection jarUrlConnection = (JarURLConnection) urlConnection; | |
149 |
1
1. readManifest : mutated return of Object value for com/lowagie/text/VersionBean$Version::readManifest to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return jarUrlConnection.getManifest(); |
150 | } else { | |
151 | jis = new JarInputStream(urlConnection.getInputStream()); | |
152 |
1
1. readManifest : mutated return of Object value for com/lowagie/text/VersionBean$Version::readManifest to ( if (x != null) null else throw new RuntimeException ) → SURVIVED |
return jis.getManifest(); |
153 | } | |
154 | } catch (IOException e) { | |
155 | } finally { | |
156 |
1
1. readManifest : negated conditional → SURVIVED |
if (jis != null) { |
157 | try { | |
158 |
1
1. readManifest : removed call to java/util/jar/JarInputStream::close → SURVIVED |
jis.close(); |
159 | } catch (IOException e) { | |
160 | } | |
161 | } | |
162 | } | |
163 | } | |
164 | } | |
165 | } | |
166 | ||
167 |
1
1. readManifest : mutated return of Object value for com/lowagie/text/VersionBean$Version::readManifest to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
168 | } | |
169 | ||
170 | ||
171 | /** | |
172 | * Returns {@link InputStream} corresponding to argument {@link URL} but with caching disabled | |
173 | * | |
174 | * @param url {@link URL} of the resource | |
175 | * @return {@link InputStream} instance or <code>null</code> | |
176 | * @throws IOException | |
177 | */ | |
178 | private static InputStream urlToStream(URL url) throws IOException { | |
179 |
1
1. urlToStream : negated conditional → SURVIVED |
if (url != null) { |
180 | URLConnection connection = url.openConnection(); | |
181 | ||
182 | try { | |
183 |
1
1. urlToStream : removed call to java/net/URLConnection::setUseCaches → SURVIVED |
connection.setUseCaches(false); |
184 | } catch (IllegalArgumentException e) { | |
185 | } | |
186 | ||
187 |
1
1. urlToStream : mutated return of Object value for com/lowagie/text/VersionBean$Version::urlToStream to ( if (x != null) null else throw new RuntimeException ) → SURVIVED |
return connection.getInputStream(); |
188 | } else { | |
189 |
1
1. urlToStream : mutated return of Object value for com/lowagie/text/VersionBean$Version::urlToStream to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
190 | } | |
191 | } | |
192 | boolean containsDataFromManifest() { | |
193 | return containsDataFromManifest; | |
194 | } | |
195 | ||
196 | public String getVersion() { | |
197 | return fullVersionString; | |
198 | } | |
199 | ||
200 | public String getImplementationTitle() { | |
201 | return implementationTitle; | |
202 | } | |
203 | ||
204 | public String getImplementationVendor() { | |
205 | return implementationVendor; | |
206 | } | |
207 | ||
208 | public String getImplementationVersion() { | |
209 | return implementationVersion; | |
210 | } | |
211 | ||
212 | public String getScmTimestamp() { | |
213 | return scmTimestamp; | |
214 | } | |
215 | ||
216 | @Override | |
217 | public String toString() { | |
218 | if (this.containsDataFromManifest()) { | |
219 | return getImplementationTitle() + " by " + getImplementationVendor() + ", version " + getVersion(); | |
220 | } else { | |
221 | return getVersion(); | |
222 | } | |
223 | } | |
224 | } | |
225 | ||
226 | public String getVendor() { | |
227 | return VERSION.getImplementationVendor(); | |
228 | } | |
229 | ||
230 | public String getTitle() { | |
231 | return VERSION.getImplementationTitle(); | |
232 | } | |
233 | ||
234 | public String getTimestamp() { | |
235 | return VERSION.getScmTimestamp(); | |
236 | } | |
237 | ||
238 | public Version getVersion() { | |
239 | return VERSION; | |
240 | } | |
241 | ||
242 | @Override | |
243 | public String toString() { | |
244 | return VERSION.toString(); | |
245 | } | |
246 | } | |
Mutations | ||
65 |
1.1 |
|
70 |
1.1 |
|
74 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
101 |
1.1 2.2 |
|
106 |
1.1 2.2 3.3 |
|
115 |
1.1 |
|
117 |
1.1 |
|
119 |
1.1 |
|
123 |
1.1 |
|
130 |
1.1 |
|
134 |
1.1 |
|
136 |
1.1 |
|
145 |
1.1 |
|
147 |
1.1 |
|
149 |
1.1 |
|
152 |
1.1 |
|
156 |
1.1 |
|
158 |
1.1 |
|
167 |
1.1 |
|
179 |
1.1 |
|
183 |
1.1 |
|
187 |
1.1 |
|
189 |
1.1 |