• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/exist-core/src/main/java/org/exist/webstart/JnlpJarFiles.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 *
24
 * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
25
 *       The original license header is included below.
26
 *
27
 * =====================================================================
28
 *
29
 * eXist-db Open Source Native XML Database
30
 * Copyright (C) 2001 The eXist-db Authors
31
 *
32
 * info@exist-db.org
33
 * http://www.exist-db.org
34
 *
35
 * This library is free software; you can redistribute it and/or
36
 * modify it under the terms of the GNU Lesser General Public
37
 * License as published by the Free Software Foundation; either
38
 * version 2.1 of the License, or (at your option) any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43
 * Lesser General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU Lesser General Public
46
 * License along with this library; if not, write to the Free Software
47
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
48
 */
49
package org.exist.webstart;
50

51
import java.io.IOException;
52
import java.nio.file.Files;
53
import java.nio.file.Path;
54
import java.nio.file.Paths;
55
import java.util.Comparator;
56
import java.util.HashMap;
57
import java.util.List;
58
import java.util.Map;
59
import java.util.stream.Collectors;
60

61
import org.apache.logging.log4j.LogManager;
62
import org.apache.logging.log4j.Logger;
63
import org.exist.start.LatestFileResolver;
64
import org.exist.util.FileUtils;
65

66
/**
67
 * Class for managing webstart jar files.
68
 *
69
 * @author Dannes Wessels
70
 */
71
public class JnlpJarFiles {
72

73
    private static final Logger LOGGER = LogManager.getLogger(JnlpJarFiles.class);
×
74

75
    private final Map<String, Path> allFiles = new HashMap<>();
×
76
    private final Path mainJar;
77

78
    // Names of core jar files sans ".jar" extension.
79
    // Use %latest% token in place of a version string.
80
    private final String allJarNames[] = new String[]{
×
81
            "antlr-%latest%",
×
82
            "cglib-nodep-%latest%",
×
83
            "clj-ds-%latest%",
×
84
            "commons-codec-%latest%",
×
85
            "commons-collections-%latest%",
×
86
            "commons-io-%latest%",
×
87
            "commons-logging-%latest%",
×
88
            "commons-pool-%latest%",
×
89
            "jargo-%latest%",
×
90
            "bcprov-jdk18on-%latest%",
×
91
            "fastutil-%latest%-min",
×
92
            "j8fu-%latest%",
×
93
            "jackson-core-%latest%",
×
94
            "jcip-annotations-%latest%",
×
95
            "jline-%latest%",
×
96
            "jansi-%latest%",
×
97
            "jta-%latest%",
×
98
            "log4j-api-%latest%",
×
99
            "log4j-core-%latest%",
×
100
            "log4j-jul-%latest%",
×
101
            "log4j-slf4j-impl-%latest%",
×
102
            "pkg-java-%latest%",
×
103
            "quartz-%latest%",
×
104
            "rsyntaxtextarea-%latest%",
×
105
            "slf4j-api-%latest%",
×
106
            "ws-commons-util-%latest%",
×
107
            "xmldb-api-%latest%",
×
108
            "xmlrpc-client-%latest%",
×
109
            "xmlrpc-common-%latest%"
×
110
    };
111

112
    // Resolves jar file patterns from jars[].
113
    private final LatestFileResolver jarFileResolver = new LatestFileResolver();
×
114

115
    /**
116
     * Get jar file specified by file pattern.
117
     *
118
     * @param folder          Directory containing the jars.
119
     * @param jarFileBaseName Name of jar file, including %latest% token if
120
     *                        necessary sans .jar file extension.
121
     * @return File object of jar file, null if not found.
122
     */
123
    private Path getJarFromLocation(final Path folder, final String jarFileBaseName) {
124
        final String fileToFind = folder.normalize().toAbsolutePath().toString() + java.io.File.separatorChar + jarFileBaseName + ".jar";
×
125
        final String resolvedFile = jarFileResolver.getResolvedFileName(fileToFind);
×
126
        final Path jar = Paths.get(resolvedFile).normalize();
×
127
        if (Files.exists(jar)) {
×
128
            LOGGER.debug("Found match: {} for file pattern: {}", resolvedFile, fileToFind);
×
129
            return jar;
×
130

131
        } else {
132
            LOGGER.error("Could not resolve file pattern: {}", fileToFind);
×
133
            return null;
×
134
        }
135
    }
136

137
    // Copy jars from map to list
138
    private void addToJars(final Path jar) {
139
        if (jar != null && FileUtils.fileName(jar).endsWith(".jar")) {
×
140
            allFiles.put(FileUtils.fileName(jar), jar);
×
141

142
            // Add jar.pack.gz if existent
143
            final Path pkgz = getJarPackGz(jar);
×
144
            if (pkgz != null) {
×
145
                allFiles.put(FileUtils.fileName(pkgz), pkgz);
×
146
            }
147
        }
148
    }
×
149

150
    /**
151
     * Creates a new instance of JnlpJarFiles
152
     *
153
     * @param libDir the lib folder.
154
     */
155
    public JnlpJarFiles(final Path libDir) {
×
156
        LOGGER.info("Initializing jar files Webstart");
×
157

158
        LOGGER.debug("Number of webstart jars={}", allJarNames.length);
×
159

160
        // Setup jars
161
        for (final String jarname : allJarNames) {
×
162
            final Path location = getJarFromLocation(libDir, jarname);
×
163
            addToJars(location);
×
164
        }
165

166
        // Setup exist-core-x.y.z.jar
167
        mainJar = getJarFromLocation(libDir, "exist-core-%latest%");
×
168
        addToJars(mainJar);
×
169
    }
×
170

171
    /**
172
     * Get All jar file as list.
173
     *
174
     * @return list of jar files.
175
     */
176
    public List<Path> getAllWebstartJars() {
177
        final List<Path> allWebstartJars = allFiles.values().stream().filter((file) -> (FileUtils.fileName(file).endsWith(".jar"))).collect(Collectors.toList());
×
178
        allWebstartJars.sort(Comparator.comparing(p -> p.toAbsolutePath().toString()));
×
179
        return allWebstartJars;
×
180
    }
181

182
    /**
183
     * Get file reference for JAR file.
184
     *
185
     * @param key the key for the JAR file.
186
     *
187
     * @return Reference to the jar file, NULL if not existent.
188
     */
189
    public Path getJarFile(final String key) {
190
        return allFiles.get(key);
×
191
    }
192

193
    private Path getJarPackGz(final Path jarName) {
194
        final String path = jarName.toAbsolutePath().toString() + ".pack.gz";
×
195
        final Path pkgz = Paths.get(path);
×
196

197
        if (Files.exists(pkgz)) {
×
198
            return pkgz;
×
199
        }
200

201
        return null;
×
202
    }
203

204
    /**
205
     * Get last modified of main JAR file.
206
     *
207
     * @return the last modified time, or -1 if unknown.
208
     *
209
     * @throws IOException if the last modified time cannot be retrieved.
210
     */
211
    public long getLastModified() throws IOException {
212
        return (mainJar == null) ? -1 : Files.getLastModifiedTime(mainJar).toMillis();
×
213
    }
214
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc