jaulib v1.3.0
Jau Support Library (C++, Java, ..)
TempJarSHASum.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 * Copyright (c) 2019 Gothel Software e.K.
5 * Copyright (c) 2019 JogAmp Community.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26package org.jau.pkg;
27
28import java.io.IOException;
29import java.net.URISyntaxException;
30import java.security.MessageDigest;
31import java.util.Arrays;
32import java.util.List;
33import java.util.regex.Pattern;
34
35import org.jau.io.IOUtil;
36import org.jau.pkg.cache.TempJarCache;
37import org.jau.sec.SHASum;
38
39/**
40 * {@link SHASum} specialization utilizing {@link TempJarCache} to access jar file content for SHA computation
41 */
42public class TempJarSHASum extends SHASum {
43 /**
44 * Instance to ensure proper {@link #compute(boolean)} of identical SHA sums over same contents within given paths across machines.
45 * <p>
46 * Instantiation of this class is lightweight, {@link #compute(boolean)} performs all operations.
47 * </p>
48 * <p>
49 * {@link TempJarCache#getTempFileCache()}'s {@link TempFileCache#getTempDir()} is used as origin for {@link IOUtil#filesOf(List, List, List)}
50 * </p>
51 *
52 * @param digest the SHA algorithm
53 * @param jarclazz a class from the desired classpath jar file used for {@link TempJarCache#addAll(Class, com.jogamp.common.net.Uri)}
54 * @param excludes the optional exclude patterns to be used for {@link IOUtil#filesOf(List, List, List)}
55 * @param includes the optional include patterns to be used for {@link IOUtil#filesOf(List, List, List)}
56 * @throws SecurityException
57 * @throws IllegalArgumentException
58 * @throws IOException
59 * @throws URISyntaxException
60 */
61 public TempJarSHASum(final MessageDigest digest, final Class<?> jarclazz, final List<Pattern> excludes, final List<Pattern> includes)
62 throws SecurityException, IllegalArgumentException, IOException, URISyntaxException
63 {
64 super(digest, Arrays.asList(IOUtil.slashify(TempJarCache.getTempFileCache().getTempDir().getAbsolutePath(), false, false)),
65 excludes, includes);
66 TempJarCache.addAll(jarclazz, JarUtil.getJarFileUri(jarclazz.getName(), jarclazz.getClassLoader()));
67 }
68
69 public final String getOrigin() { return getOrigins().get(0); }
70}
static String slashify(final String path, final boolean startWithSlash, final boolean endWithSlash)
Definition: IOUtil.java:327
static Uri getJarFileUri(final String clazzBinName, final ClassLoader cl)
The Class's "com.jogamp.common.GlueGenVersion" Uri jar:sub_protocol:/some/path/gluegen-rt....
Definition: JarUtil.java:304
SHASum specialization utilizing TempJarCache to access jar file content for SHA computation
TempJarSHASum(final MessageDigest digest, final Class<?> jarclazz, final List< Pattern > excludes, final List< Pattern > includes)
Instance to ensure proper compute(boolean) of identical SHA sums over same contents within given path...
File getTempDir()
Temporary directory for individual files (eg.
Static Jar file cache handler using an underlying instance of TempFileCache, see getTempFileCache().
static synchronized final void addAll(final Class<?> certClass, final Uri jarUri)
Adds all types, native libraries, class files and other files (resources) if not yet added.
static TempFileCache getTempFileCache()
Utility class to produce secure hash (SHA) sums over diverse input sources.
Definition: SHASum.java:69
final List< String > getOrigins()
Definition: SHASum.java:202