| 1 | // Copyright (c) 2018, Yubico AB | |
| 2 | // All rights reserved. | |
| 3 | // | |
| 4 | // Redistribution and use in source and binary forms, with or without | |
| 5 | // modification, are permitted provided that the following conditions are met: | |
| 6 | // | |
| 7 | // 1. Redistributions of source code must retain the above copyright notice, this | |
| 8 | // list of conditions and the following disclaimer. | |
| 9 | // | |
| 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 11 | // this list of conditions and the following disclaimer in the documentation | |
| 12 | // and/or other materials provided with the distribution. | |
| 13 | // | |
| 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
| 18 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 19 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 20 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 21 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
| 22 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 | ||
| 25 | package com.yubico.webauthn.meta; | |
| 26 | ||
| 27 | import com.yubico.internal.util.ExceptionUtil; | |
| 28 | import java.io.IOException; | |
| 29 | import java.net.URL; | |
| 30 | import java.time.LocalDate; | |
| 31 | import java.util.Enumeration; | |
| 32 | import java.util.NoSuchElementException; | |
| 33 | import java.util.jar.Manifest; | |
| 34 | import lombok.Value; | |
| 35 | import lombok.extern.slf4j.Slf4j; | |
| 36 | ||
| 37 | /** | |
| 38 | * Contains version information for the com.yubico.webauthn package. | |
| 39 | * | |
| 40 | * @see Specification | |
| 41 | */ | |
| 42 | @Slf4j | |
| 43 | @Value | |
| 44 | public class VersionInfo { | |
| 45 | ||
| 46 | private static VersionInfo instance; | |
| 47 | ||
| 48 | public static VersionInfo getInstance() { | |
| 49 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (instance == null) { |
| 50 | try { | |
| 51 | instance = new VersionInfo(); | |
| 52 | } catch (IOException e) { | |
| 53 | throw ExceptionUtil.wrapAndLog(log, "Failed to create VersionInfo", e); | |
| 54 | } | |
| 55 | } | |
| 56 | ||
| 57 |
1
1. getInstance : replaced return value with null for com/yubico/webauthn/meta/VersionInfo::getInstance → NO_COVERAGE |
return instance; |
| 58 | } | |
| 59 | ||
| 60 | /** Represents the specification this implementation is based on */ | |
| 61 | private final Specification specification = | |
| 62 | Specification.builder() | |
| 63 | .url(new URL(findValueInManifest("Specification-Url"))) | |
| 64 | .latestVersionUrl(new URL(findValueInManifest("Specification-Url-Latest"))) | |
| 65 | .status(DocumentStatus.fromString(findValueInManifest("Specification-W3c-Status")).get()) | |
| 66 | .releaseDate(LocalDate.parse(findValueInManifest("Specification-Release-Date"))) | |
| 67 | .build(); | |
| 68 | ||
| 69 | /** Description of this version of this library */ | |
| 70 | private final Implementation implementation = | |
| 71 | new Implementation( | |
| 72 | findValueInManifest("Implementation-Version"), | |
| 73 | new URL(findValueInManifest("Implementation-Source-Url")), | |
| 74 | findValueInManifest("Git-Commit")); | |
| 75 | ||
| 76 | private VersionInfo() throws IOException {} | |
| 77 | ||
| 78 | private String findValueInManifest(String key) throws IOException { | |
| 79 | final Enumeration<URL> resources = | |
| 80 | getClass().getClassLoader().getResources("META-INF/MANIFEST.MF"); | |
| 81 | ||
| 82 |
1
1. findValueInManifest : negated conditional → NO_COVERAGE |
while (resources.hasMoreElements()) { |
| 83 | final URL resource = resources.nextElement(); | |
| 84 | final Manifest manifest = new Manifest(resource.openStream()); | |
| 85 | if ("java-webauthn-server" | |
| 86 |
1
1. findValueInManifest : negated conditional → NO_COVERAGE |
.equals(manifest.getMainAttributes().getValue("Implementation-Id"))) { |
| 87 |
1
1. findValueInManifest : replaced return value with "" for com/yubico/webauthn/meta/VersionInfo::findValueInManifest → NO_COVERAGE |
return manifest.getMainAttributes().getValue(key); |
| 88 | } | |
| 89 | } | |
| 90 | throw new NoSuchElementException("Could not find \"" + key + "\" in manifest."); | |
| 91 | } | |
| 92 | } | |
Mutations | ||
| 49 |
1.1 |
|
| 57 |
1.1 |
|
| 82 |
1.1 |
|
| 86 |
1.1 |
|
| 87 |
1.1 |