Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
DirectBTVersion.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25package org.direct_bt;
26
27import java.io.IOException;
28import java.io.PrintStream;
29import java.net.URISyntaxException;
30import java.security.MessageDigest;
31import java.security.NoSuchAlgorithmException;
32import java.util.ArrayList;
33import java.util.Iterator;
34import java.util.List;
35import java.util.Set;
36import java.util.jar.Attributes;
37import java.util.jar.Manifest;
38import java.util.regex.Pattern;
39
40import org.jau.base.JaulibVersion;
41import org.jau.io.PrintUtil;
42import org.jau.pkg.TempJarSHASum;
43import org.jau.sec.SHASum;
44import org.jau.util.JauVersion;
45import org.jau.util.VersionUtil;
46
47/**
48 * This {@code jaulib} derived version info class is only
49 * usable when having {@code jaulib} available, naturally.
50 */
51public class DirectBTVersion extends JauVersion {
52
53 /**
54 * Print full Direct-BT version information.
55 *
56 * {@link BTFactory#initDirectBTLibrary()} is being called.
57 *
58 * @param out the output stream used
59 */
60 public static final void printVersionInfo(final PrintStream out) {
62
63 PrintUtil.println(out, "BTFactory: Jaulib: Available "+BTFactory.JAULIB_AVAILABLE+", JarCache in use "+BTFactory.JAULIB_JARCACHE_USED);
65 out.println(VersionUtil.getPlatformInfo());
66 PrintUtil.println(out, "Version Info:");
68 out.println(v.toString());
69 PrintUtil.println(out, "");
70 PrintUtil.println(out, "Full Manifest:");
71 out.println(v.getFullManifestInfo(null).toString());
72 } else {
73 PrintUtil.println(out, "Full Manifest:");
74 final Manifest manifest = BTFactory.getManifest(BTFactory.class.getClassLoader(), new String[] { "org.direct_bt" } );
75 final Attributes attr = manifest.getMainAttributes();
76 final Set<Object> keys = attr.keySet();
77 final StringBuilder sb = new StringBuilder();
78 for(final Iterator<Object> iter=keys.iterator(); iter.hasNext(); ) {
79 final Attributes.Name key = (Attributes.Name) iter.next();
80 final String val = attr.getValue(key);
81 sb.append(" ");
82 sb.append(key);
83 sb.append(" = ");
84 sb.append(val);
85 sb.append(System.lineSeparator());
86 }
87 out.println(sb.toString());
88 }
89
90 PrintUtil.println(out, "Direct-BT Native Version "+BTFactory.getNativeVersion()+" (API "+BTFactory.getNativeAPIVersion()+")");
91 PrintUtil.println(out, "Direct-BT Java Version "+BTFactory.getImplVersion()+" (API "+BTFactory.getAPIVersion()+")");
92 }
93
94 protected DirectBTVersion(final String packageName, final Manifest mf) {
95 super(packageName, mf);
96 }
97
98 /**
99 * Returns a transient new instance.
100 */
101 public static DirectBTVersion getInstance() {
102 final String packageNameCompileTime = "org.direct_bt";
103 final String packageNameRuntime = "org.direct_bt";
104 Manifest mf = VersionUtil.getManifest(DirectBTVersion.class.getClassLoader(), packageNameRuntime);
105 if(null != mf) {
106 return new DirectBTVersion(packageNameRuntime, mf);
107 } else {
108 mf = VersionUtil.getManifest(DirectBTVersion.class.getClassLoader(), packageNameCompileTime);
109 return new DirectBTVersion(packageNameCompileTime, mf);
110 }
111 }
112
113 /**
114 * Direct-BT definition of {@link TempJarSHASum}'s specialization of {@link SHASum}.
115 * <p>
116 * Implementation uses {@link org.jau.pkg.cache.TempJarCache}.
117 * </p>
118 * <p>
119 * Constructor defines the includes and excludes as used for Direct-BT {@link SHASum} computation.
120 * </p>
121 */
122 static public class JarSHASum extends TempJarSHASum {
123 /**
124 * See {@link DirectBTJarSHASum}
125 * @throws SecurityException
126 * @throws IllegalArgumentException
127 * @throws NoSuchAlgorithmException
128 * @throws IOException
129 * @throws URISyntaxException
130 */
131 public JarSHASum()
132 throws SecurityException, IllegalArgumentException, NoSuchAlgorithmException, IOException, URISyntaxException
133 {
134 super(MessageDigest.getInstance("SHA-256"), JaulibVersion.class, new ArrayList<Pattern>(), new ArrayList<Pattern>());
135 final List<Pattern> includes = getIncludes();
136 final String origin = getOrigin();
137 includes.add(Pattern.compile(origin+"/org/direct_bt/.*"));
138 includes.add(Pattern.compile(origin+"/jau/direct_bt/.*"));
139 }
140 }
141 public static void main(final String args[]) {
142 BTFactory.main(args);
143 }
144}
One stop BTManager API entry point.
Definition: BTFactory.java:52
static native String getNativeVersion()
static void main(final String args[])
Definition: BTFactory.java:532
static final boolean JAULIB_JARCACHE_USED
True if jaulib JAULIB_AVAILABLE and its org.jau.sys.PlatformProps#USE_TEMP_JAR_CACHE is true,...
Definition: BTFactory.java:158
static final String getImplVersion()
Manifest's Attributes.Name#IMPLEMENTATION_VERSION or null if not available.
Definition: BTFactory.java:130
static final String getAPIVersion()
Manifest's Attributes.Name#SPECIFICATION_VERSION or null if not available.
Definition: BTFactory.java:124
static native String getNativeAPIVersion()
static synchronized void initDirectBTLibrary()
Preloads the DirectBT native library w/o instantiating BTManager.
Definition: BTFactory.java:482
static final Manifest getManifest(final ClassLoader cl, final String[] extensions)
Helper function to retrieve a Manifest instance.
Definition: BTFactory.java:489
static final boolean JAULIB_AVAILABLE
True if jaulib org.jau.sys.PlatformProps has been detected.
Definition: BTFactory.java:152
Direct-BT definition of TempJarSHASum's specialization of SHASum.
This jaulib derived version info class is only usable when having jaulib available,...
static final void printVersionInfo(final PrintStream out)
Print full Direct-BT version information.
DirectBTVersion(final String packageName, final Manifest mf)
static void main(final String args[])
static DirectBTVersion getInstance()
Returns a transient new instance.