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

jreleaser / jreleaser / #503

20 Jul 2025 10:20AM UTC coverage: 49.347% (-0.02%) from 49.362%
#503

push

github

aalmiray
fix: Configure mising resources in native-image

Fixes #1918

25724 of 52129 relevant lines covered (49.35%)

0.49 hits per line

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

68.46
/core/jreleaser-engine/src/main/java/org/jreleaser/assemblers/JlinkAssemblerProcessor.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 *
4
 * Copyright 2020-2025 The JReleaser authors.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     https://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
package org.jreleaser.assemblers;
19

20
import org.jreleaser.bundle.RB;
21
import org.jreleaser.model.Archive;
22
import org.jreleaser.model.internal.JReleaserContext;
23
import org.jreleaser.model.internal.assemble.JlinkAssembler;
24
import org.jreleaser.model.internal.common.Artifact;
25
import org.jreleaser.model.internal.common.JvmOptions;
26
import org.jreleaser.model.spi.assemble.AssemblerProcessingException;
27
import org.jreleaser.mustache.TemplateContext;
28
import org.jreleaser.sdk.command.Command;
29
import org.jreleaser.util.FileUtils;
30
import org.jreleaser.util.PlatformUtils;
31
import org.jreleaser.util.StringUtils;
32
import org.jreleaser.version.SemanticVersion;
33

34
import java.io.File;
35
import java.io.IOException;
36
import java.nio.file.Files;
37
import java.nio.file.Path;
38
import java.nio.file.Paths;
39
import java.util.Arrays;
40
import java.util.Optional;
41
import java.util.Set;
42
import java.util.TreeSet;
43
import java.util.stream.Stream;
44

45
import static java.lang.String.join;
46
import static java.util.stream.Collectors.joining;
47
import static java.util.stream.Collectors.toSet;
48
import static org.jreleaser.assemblers.AssemblerUtils.copyJars;
49
import static org.jreleaser.assemblers.AssemblerUtils.readJavaVersion;
50
import static org.jreleaser.model.Constants.KEY_ARCHIVE_FORMAT;
51
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_ASSEMBLE_DIRECTORY;
52
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_EXECUTABLE;
53
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_ENVIRONMENT_VARIABLES_LINUX;
54
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_ENVIRONMENT_VARIABLES_OSX;
55
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_ENVIRONMENT_VARIABLES_UNIVERSAL;
56
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_ENVIRONMENT_VARIABLES_UNIX;
57
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_ENVIRONMENT_VARIABLES_WINDOWS;
58
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_JVM_OPTIONS_LINUX;
59
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_JVM_OPTIONS_OSX;
60
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_JVM_OPTIONS_UNIVERSAL;
61
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_JVM_OPTIONS_UNIX;
62
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_JVM_OPTIONS_WINDOWS;
63
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_MAIN_CLASS;
64
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_MAIN_JAR;
65
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_MAIN_MODULE;
66
import static org.jreleaser.mustache.MustacheUtils.passThrough;
67
import static org.jreleaser.mustache.Templates.resolveTemplate;
68
import static org.jreleaser.util.FileType.BAT;
69
import static org.jreleaser.util.FileType.JAR;
70
import static org.jreleaser.util.FileUtils.listFilesAndConsume;
71
import static org.jreleaser.util.FileUtils.listFilesAndProcess;
72
import static org.jreleaser.util.StringUtils.isBlank;
73
import static org.jreleaser.util.StringUtils.isNotBlank;
74

75
/**
76
 * @author Andres Almiray
77
 * @since 0.2.0
78
 */
79
public class JlinkAssemblerProcessor extends AbstractAssemblerProcessor<org.jreleaser.model.api.assemble.JlinkAssembler, JlinkAssembler> {
80
    public JlinkAssemblerProcessor(JReleaserContext context) {
81
        super(context);
1✔
82
    }
1✔
83

84
    @Override
85
    protected void fillAssemblerProperties(TemplateContext props) {
86
        super.fillAssemblerProperties(props);
1✔
87
        if (isNotBlank(assembler.getMainJar().getPath())) {
1✔
88
            props.set(KEY_DISTRIBUTION_JAVA_MAIN_JAR, assembler.getMainJar().getEffectivePath(context, assembler)
1✔
89
                .getFileName());
1✔
90
        } else {
91
            props.set(KEY_DISTRIBUTION_JAVA_MAIN_JAR, "");
×
92
        }
93
        props.set(KEY_DISTRIBUTION_JAVA_MAIN_CLASS, assembler.getJava().getMainClass());
1✔
94
        props.set(KEY_DISTRIBUTION_JAVA_MAIN_MODULE, assembler.getJava().getMainModule());
1✔
95
        JvmOptions jvmOptions = assembler.getJava().getJvmOptions();
1✔
96
        props.set(KEY_DISTRIBUTION_EXECUTABLE, assembler.getExecutable());
1✔
97
        props.set(KEY_DISTRIBUTION_JAVA_JVM_OPTIONS_UNIVERSAL,
1✔
98
            !jvmOptions.getUniversal().isEmpty() ? passThrough(join(" ", jvmOptions.getResolvedUniversal(context))) : "");
1✔
99
        props.set(KEY_DISTRIBUTION_JAVA_JVM_OPTIONS_UNIX,
1✔
100
            !jvmOptions.getUnix().isEmpty() ? passThrough(join(" ", jvmOptions.getResolvedUnix(context))) : "");
1✔
101
        props.set(KEY_DISTRIBUTION_JAVA_JVM_OPTIONS_LINUX,
1✔
102
            !jvmOptions.getLinux().isEmpty() ? passThrough(join(" ", jvmOptions.getResolvedLinux(context))) : "");
1✔
103
        props.set(KEY_DISTRIBUTION_JAVA_JVM_OPTIONS_OSX,
1✔
104
            !jvmOptions.getOsx().isEmpty() ? passThrough(join(" ", jvmOptions.getResolvedOsx(context))) : "");
1✔
105
        props.set(KEY_DISTRIBUTION_JAVA_JVM_OPTIONS_WINDOWS,
1✔
106
            !jvmOptions.getWindows().isEmpty() ? passThrough(join(" ", jvmOptions.getResolvedWindows(context))) : "");
1✔
107
        props.set(KEY_DISTRIBUTION_JAVA_ENVIRONMENT_VARIABLES_UNIVERSAL,
1✔
108
            assembler.getJava().getEnvironmentVariables().getResolvedUniversal(context).entrySet());
1✔
109
        props.set(KEY_DISTRIBUTION_JAVA_ENVIRONMENT_VARIABLES_UNIX,
1✔
110
            assembler.getJava().getEnvironmentVariables().getResolvedUnix(context).entrySet());
1✔
111
        props.set(KEY_DISTRIBUTION_JAVA_ENVIRONMENT_VARIABLES_LINUX,
1✔
112
            assembler.getJava().getEnvironmentVariables().getResolvedLinux(context).entrySet());
1✔
113
        props.set(KEY_DISTRIBUTION_JAVA_ENVIRONMENT_VARIABLES_OSX,
1✔
114
            assembler.getJava().getEnvironmentVariables().getResolvedOsx(context).entrySet());
1✔
115
        props.set(KEY_DISTRIBUTION_JAVA_ENVIRONMENT_VARIABLES_WINDOWS,
1✔
116
            assembler.getJava().getEnvironmentVariables().getResolvedWindows(context).entrySet());
1✔
117
    }
1✔
118

119
    @Override
120
    protected void doAssemble(TemplateContext props) throws AssemblerProcessingException {
121
        // verify jdk
122
        Path jdkPath = assembler.getJdk().getEffectivePath(context, assembler);
1✔
123
        SemanticVersion jdkVersion = SemanticVersion.of(readJavaVersion(jdkPath));
1✔
124
        context.getLogger().debug(RB.$("assembler.jlink.jdk"), jdkVersion, jdkPath.toAbsolutePath().toString());
1✔
125

126
        boolean selectedJdks = false;
1✔
127
        // verify jdks
128
        for (Artifact targetJdk : assembler.getTargetJdks()) {
1✔
129
            if (!targetJdk.isActiveAndSelected()) continue;
1✔
130
            selectedJdks = true;
1✔
131

132
            Path targetJdkPath = targetJdk.getEffectivePath(context, assembler);
1✔
133
            SemanticVersion targetJdkVersion = SemanticVersion.of(readJavaVersion(targetJdkPath));
1✔
134
            context.getLogger().debug(RB.$("assembler.jlink.target"), jdkVersion, targetJdkPath.toAbsolutePath().toString());
1✔
135

136
            if (jdkVersion.getMajor() != targetJdkVersion.getMajor()) {
1✔
137
                throw new AssemblerProcessingException(RB.$("ERROR_jlink_target_not_compatible", targetJdkVersion, jdkVersion));
×
138
            }
139
        }
1✔
140

141
        if (!selectedJdks) return;
1✔
142

143
        Path assembleDirectory = props.get(KEY_DISTRIBUTION_ASSEMBLE_DIRECTORY);
1✔
144
        Path inputsDirectory = assembleDirectory.resolve(INPUTS_DIRECTORY);
1✔
145

146
        // copy templates
147
        copyTemplates(context, props, inputsDirectory);
1✔
148

149
        // run jlink x jdk
150
        String imageName = assembler.getResolvedImageName(context);
1✔
151
        if (isNotBlank(assembler.getImageNameTransform())) {
1✔
152
            imageName = assembler.getResolvedImageNameTransform(context);
×
153
        }
154

155
        boolean hasJavaArchive = assembler.getJavaArchive().isSet();
1✔
156

157
        if (hasJavaArchive) {
1✔
158
            String archiveFile = resolveTemplate(assembler.getJavaArchive().getPath(), props);
×
159
            Path archivePath = context.getBasedir().resolve(Paths.get(archiveFile));
×
160
            if (!Files.exists(archivePath)) {
×
161
                throw new AssemblerProcessingException(RB.$("ERROR_path_does_not_exist", archivePath));
×
162
            }
163

164
            Path archiveDirectory = inputsDirectory.resolve(ARCHIVE_DIRECTORY);
×
165
            try {
166
                FileUtils.unpackArchive(archivePath, archiveDirectory, true);
×
167
            } catch (IOException e) {
×
168
                throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error"), e);
×
169
            }
×
170
        }
171

172
        // copy jars to assembly
173
        Path jarsDirectory = inputsDirectory.resolve(JARS_DIRECTORY);
1✔
174
        Path universalJarsDirectory = jarsDirectory.resolve(UNIVERSAL_DIRECTORY);
1✔
175

176
        if (hasJavaArchive) {
1✔
177
            String libDirectoryName = resolveTemplate(assembler.getJavaArchive().getLibDirectoryName(), props);
×
178
            Path libPath = inputsDirectory.resolve(ARCHIVE_DIRECTORY).resolve(libDirectoryName);
×
179
            try {
180
                FileUtils.copyFiles(context.getLogger(), libPath, universalJarsDirectory);
×
181
            } catch (IOException e) {
×
182
                throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error"), e);
×
183
            }
×
184
        }
185
        context.getLogger().debug(RB.$("assembler.copy.jars"), context.relativizeToBasedir(universalJarsDirectory));
1✔
186
        copyJars(context, assembler, universalJarsDirectory, "");
1✔
187

188
        Optional<String> compress = assembler.getArgs().stream()
1✔
189
            .filter(arg -> arg.contains("--compress") || arg.startsWith("-c=") || arg.startsWith("-c "))
1✔
190
            .findFirst();
1✔
191
        if (!compress.isPresent()) {
1✔
192
            if (jdkVersion.getMajor() >= 21) {
1✔
193
                assembler.getArgs().add("--compress");
×
194
                assembler.getArgs().add("zip-9");
×
195
            } else {
196
                assembler.getArgs().add("--compress=2");
1✔
197
            }
198
        }
199

200
        for (Artifact targetJdk : assembler.getTargetJdks()) {
1✔
201
            if (!targetJdk.isActiveAndSelected()) continue;
1✔
202

203
            String platform = targetJdk.getPlatform();
1✔
204
            Path platformJarsDirectory = jarsDirectory.resolve(platform);
1✔
205
            context.getLogger().debug(RB.$("assembler.copy.jars"), context.relativizeToBasedir(platformJarsDirectory));
1✔
206
            copyJars(context, assembler, platformJarsDirectory, platform);
1✔
207

208
            // resolve module names
209
            Set<String> moduleNames = new TreeSet<>(resolveModuleNames(context, jdkPath, jarsDirectory, platform, props));
1✔
210
            context.getLogger().debug(RB.$("assembler.resolved.module.names"), moduleNames);
1✔
211
            if (moduleNames.isEmpty()) {
1✔
212
                throw new AssemblerProcessingException(RB.$("ERROR_assembler_no_module_names"));
×
213
            }
214
            moduleNames.addAll(assembler.getAdditionalModuleNames());
1✔
215
            if (isNotBlank(assembler.getJava().getMainModule())) {
1✔
216
                moduleNames.add(assembler.getJava().getMainModule());
×
217
            }
218
            context.getLogger().debug(RB.$("assembler.module.names"), moduleNames);
1✔
219

220
            String str = targetJdk.getExtraProperties()
1✔
221
                .getOrDefault(KEY_ARCHIVE_FORMAT, assembler.getArchiveFormat())
1✔
222
                .toString();
1✔
223
            Archive.Format archiveFormat = Archive.Format.of(str);
1✔
224

225
            jlink(props, assembleDirectory, jdkPath, targetJdk, moduleNames, imageName, archiveFormat);
1✔
226
        }
1✔
227
    }
1✔
228

229
    private void jlink(TemplateContext props, Path assembleDirectory, Path jdkPath, Artifact targetJdk, Set<String> moduleNames, String imageName, Archive.Format archiveFormat) throws AssemblerProcessingException {
230
        String platform = targetJdk.getPlatform();
1✔
231
        String platformReplaced = assembler.getPlatform().applyReplacements(platform);
1✔
232
        String finalImageName = imageName + "-" + platformReplaced;
1✔
233
        context.getLogger().info("- {}", finalImageName);
1✔
234

235
        boolean hasJavaArchive = assembler.getJavaArchive().isSet();
1✔
236
        Path inputsDirectory = assembleDirectory.resolve(INPUTS_DIRECTORY);
1✔
237
        Path archiveDirectory = inputsDirectory.resolve(ARCHIVE_DIRECTORY);
1✔
238
        Path jarsDirectory = inputsDirectory.resolve(JARS_DIRECTORY);
1✔
239
        Path workDirectory = assembleDirectory.resolve(WORK_DIRECTORY + "-" + platform);
1✔
240
        Path imageDirectory = workDirectory.resolve(finalImageName).toAbsolutePath();
1✔
241
        try {
242
            FileUtils.deleteFiles(imageDirectory);
1✔
243
        } catch (IOException e) {
×
244
            throw new AssemblerProcessingException(RB.$("ERROR_assembler_delete_image", finalImageName), e);
×
245
        }
1✔
246

247
        // jlink it
248
        String moduleName = assembler.getJava().getMainModule();
1✔
249
        String modulePath = maybeQuote(targetJdk.getEffectivePath(context, assembler).resolve("jmods").toAbsolutePath().toString());
1✔
250
        if (isNotBlank(moduleName) || assembler.isCopyJars()) {
1✔
251
            modulePath += File.pathSeparator + maybeQuote(jarsDirectory
1✔
252
                .resolve(UNIVERSAL_DIRECTORY)
1✔
253
                .toAbsolutePath().toString());
1✔
254

255
            try {
256
                Path platformJarsDirectory = jarsDirectory.resolve(platform).toAbsolutePath();
1✔
257
                if (listFilesAndProcess(platformJarsDirectory, Stream::count).orElse(0L) > 1) {
1✔
258
                    modulePath += File.pathSeparator + maybeQuote(platformJarsDirectory.toString());
×
259
                }
260
            } catch (IOException e) {
×
261
                throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error", e));
×
262
            }
1✔
263
        }
264

265
        Path jlinkExecutable = jdkPath
1✔
266
            .resolve(BIN_DIRECTORY)
1✔
267
            .resolve(PlatformUtils.isWindows() ? "jlink.exe" : "jlink")
1✔
268
            .toAbsolutePath();
1✔
269

270
        Command cmd = new Command(jlinkExecutable.toString(), true)
1✔
271
            .args(assembler.getArgs())
1✔
272
            .arg("--module-path")
1✔
273
            .arg(modulePath)
1✔
274
            .arg("--add-modules")
1✔
275
            .arg(String.join(",", moduleNames));
1✔
276
        if (isNotBlank(moduleName)) {
1✔
277
            cmd.arg("--launcher")
×
278
                .arg(assembler.getExecutable() + "=" + moduleName + "/" + assembler.getJava().getMainClass());
×
279
        }
280
        cmd.arg("--output")
1✔
281
            .arg(maybeQuote(imageDirectory.toString()));
1✔
282

283
        context.getLogger().debug(String.join(" ", cmd.getArgs()));
1✔
284
        executeCommand(cmd);
1✔
285

286
        if (isBlank(moduleName)) {
1✔
287
            // non modular
288
            // copy jars & launcher
289

290
            if (assembler.isCopyJars()) {
1✔
291
                Path outputJarsDirectory = imageDirectory.resolve(JARS_DIRECTORY);
1✔
292

293
                try {
294
                    Files.createDirectory(outputJarsDirectory);
1✔
295
                    FileUtils.copyFiles(context.getLogger(),
1✔
296
                        jarsDirectory.resolve(UNIVERSAL_DIRECTORY),
1✔
297
                        outputJarsDirectory);
298
                    FileUtils.copyFiles(context.getLogger(),
1✔
299
                        jarsDirectory.resolve(platform),
1✔
300
                        outputJarsDirectory);
301
                } catch (IOException e) {
×
302
                    throw new AssemblerProcessingException(RB.$("ERROR_assembler_copy_jars",
×
303
                        context.relativizeToBasedir(outputJarsDirectory)), e);
×
304
                }
1✔
305
            }
306

307
            Path binDirectory = imageDirectory.resolve(BIN_DIRECTORY);
1✔
308
            try {
309
                Files.createDirectories(binDirectory);
1✔
310

311
                Optional<Set<Path>> launchers = listFilesAndProcess(inputsDirectory.resolve(BIN_DIRECTORY), files -> files.collect(toSet()));
1✔
312
                if (launchers.isPresent()) {
1✔
313
                    for (Path srcLauncher : launchers.get()) {
1✔
314
                        Path destLauncher = binDirectory.resolve(srcLauncher.getFileName());
1✔
315
                        Files.copy(srcLauncher, destLauncher);
1✔
316
                        FileUtils.grantExecutableAccess(destLauncher);
1✔
317
                    }
1✔
318
                }
319
            } catch (IOException e) {
×
320
                throw new AssemblerProcessingException(RB.$("ERROR_assembler_copy_launcher",
×
321
                    context.relativizeToBasedir(binDirectory)), e);
×
322
            }
1✔
323
        }
324

325
        try {
326
            Path imageArchive = assembleDirectory.resolve(finalImageName + "." + archiveFormat.extension());
1✔
327
            FileUtils.copyFiles(context.getLogger(),
1✔
328
                context.getBasedir(),
1✔
329
                imageDirectory, path -> path.getFileName().startsWith(LICENSE));
1✔
330
            // copy all templates, filter existing launchers
331
            FileUtils.copyFiles(context.getLogger(), inputsDirectory, imageDirectory, path -> {
1✔
332
                if (!BIN_DIRECTORY.equals(path.getParent().getFileName().toString())) return true;
×
333
                String fileName = path.getFileName().toString();
×
334
                // don't copy jars twice
335
                if (fileName.endsWith(JAR.extension()) && JARS_DIRECTORY.equals(path.getParent().getParent().getFileName().toString())) {
×
336
                    return false;
×
337
                }
338
                Path candidateBinary = imageDirectory.resolve(BIN_DIRECTORY).resolve(fileName);
×
339
                return !Files.exists(candidateBinary);
×
340
            });
341

342
            if (hasJavaArchive) {
1✔
343
                String libDirectory = resolveTemplate(assembler.getJavaArchive().getLibDirectoryName(), props);
×
344
                String archivePathName = archiveDirectory.toString();
×
345
                FileUtils.copyFiles(context.getLogger(),
×
346
                    archiveDirectory,
347
                    imageDirectory, path -> {
348
                        String fileName = path.getFileName().toString();
×
349
                        if (!fileName.endsWith(JAR.extension())) return true;
×
350
                        return !path.getParent().toString()
×
351
                            .substring(archivePathName.length())
×
352
                            .contains(libDirectory);
×
353
                    });
354
            }
355

356
            copyArtifacts(context, imageDirectory, platform, true);
1✔
357
            copyFiles(context, imageDirectory);
1✔
358
            copyFileSets(context, imageDirectory);
1✔
359
            generateSwidTag(context, imageDirectory);
1✔
360

361
            FileUtils.packArchive(workDirectory, imageArchive, assembler.getOptions().toOptions());
1✔
362

363
            context.getLogger().debug("- {}", imageArchive.getFileName());
1✔
364
        } catch (IOException e) {
×
365
            throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error"), e);
×
366
        }
1✔
367
    }
1✔
368

369
    private Set<String> resolveModuleNames(JReleaserContext context, Path jdkPath, Path jarsDirectory, String platform, TemplateContext props) throws AssemblerProcessingException {
370
        if (!assembler.getModuleNames().isEmpty()) {
1✔
371
            return assembler.getModuleNames();
×
372
        }
373

374
        Path jdepsExecutable = jdkPath
1✔
375
            .resolve(BIN_DIRECTORY)
1✔
376
            .resolve(PlatformUtils.isWindows() ? "jdeps.exe" : "jdeps")
1✔
377
            .toAbsolutePath();
1✔
378

379
        Command cmd = new Command(jdepsExecutable.toAbsolutePath().toString());
1✔
380
        String multiRelease = assembler.getJdeps().getMultiRelease();
1✔
381
        if (isNotBlank(multiRelease)) {
1✔
382
            cmd.arg("--multi-release")
1✔
383
                .arg(multiRelease);
1✔
384
        }
385
        if (assembler.getJdeps().isIgnoreMissingDeps()) {
1✔
386
            cmd.arg("--ignore-missing-deps");
1✔
387
        }
388
        cmd.arg("--print-module-deps");
1✔
389

390
        String moduleName = assembler.getJava().getMainModule();
1✔
391
        if (isNotBlank(moduleName)) {
1✔
392
            cmd.arg("--module")
×
393
                .arg(moduleName)
×
394
                .arg("--module-path");
×
395
            calculateJarPath(jarsDirectory, platform, cmd, true);
×
396
        } else if (!assembler.getJdeps().getTargets().isEmpty()) {
1✔
397
            cmd.arg("--class-path");
×
398
            if (assembler.getJdeps().isUseWildcardInPath()) {
×
399
                cmd.arg(UNIVERSAL_DIRECTORY +
×
400
                    File.separator + "*" +
401
                    File.pathSeparator +
402
                    platform +
403
                    File.separator + "*");
404
            } else {
405
                calculateJarPath(jarsDirectory, platform, cmd, true);
×
406
            }
407

408
            assembler.getJdeps().getTargets().stream()
×
409
                .map(target -> resolveTemplate(target, props))
×
410
                .filter(StringUtils::isNotBlank)
×
411
                .map(AssemblerUtils::maybeAdjust)
×
412
                .map(context::relativizeToBasedir)
×
413
                .map(p -> p.toAbsolutePath().normalize().toString())
×
414
                .forEach(cmd::arg);
×
415
        } else {
416
            calculateJarPath(jarsDirectory, platform, cmd, false);
1✔
417
        }
418

419
        context.getLogger().debug(String.join(" ", cmd.getArgs()));
1✔
420
        Command.Result result = executeCommand(jarsDirectory, cmd);
1✔
421

422
        String output = result.getOut();
1✔
423
        long lineCount = Arrays.stream(output.split(System.lineSeparator()))
1✔
424
            .map(String::trim)
1✔
425
            .count();
1✔
426

427
        if (lineCount == 1 && isNotBlank(output)) {
1✔
428
            return Arrays.stream(output.split(",")).collect(toSet());
1✔
429
        }
430

431
        throw new AssemblerProcessingException(RB.$("ERROR_assembler_jdeps_error", output));
×
432
    }
433

434
    private void calculateJarPath(Path jarsDirectory, String platform, Command cmd, boolean join) throws AssemblerProcessingException {
435
        try {
436
            if (join) {
1✔
437
                StringBuilder pathBuilder = new StringBuilder();
×
438

439
                listFilesAndProcess(jarsDirectory.resolve(UNIVERSAL_DIRECTORY), files ->
×
440
                    files.map(Path::toAbsolutePath)
×
441
                        .map(Object::toString)
×
442
                        .collect(joining(File.pathSeparator)))
×
443
                    .ifPresent(pathBuilder::append);
×
444

445
                listFilesAndProcess(jarsDirectory.resolve(platform), files ->
×
446
                    files.map(Path::toAbsolutePath)
×
447
                        .map(Object::toString)
×
448
                        .collect(joining(File.pathSeparator)))
×
449
                    .ifPresent(platformSpecific -> {
×
450
                        if (isNotBlank(platformSpecific)) {
×
451
                            pathBuilder.append(File.pathSeparator)
×
452
                                .append(platformSpecific);
×
453
                        }
454
                    });
×
455

456
                cmd.arg(pathBuilder.toString());
×
457
            } else {
×
458
                listFilesAndConsume(jarsDirectory.resolve(UNIVERSAL_DIRECTORY), files ->
1✔
459
                    files.map(Path::toAbsolutePath)
1✔
460
                        .map(Object::toString)
1✔
461
                        .forEach(cmd::arg));
1✔
462

463
                listFilesAndConsume(jarsDirectory.resolve(platform), files ->
1✔
464
                    files.map(Path::toAbsolutePath)
1✔
465
                        .map(Object::toString)
1✔
466
                        .forEach(cmd::arg));
1✔
467
            }
468
        } catch (IOException e) {
×
469
            throw new AssemblerProcessingException(RB.$("ERROR_assembler_jdeps_error", e.getMessage(), e));
×
470
        }
1✔
471
    }
1✔
472

473
    @Override
474
    protected Path resolveOutputFile(TemplateContext props, Path targetDirectory, String fileName) throws AssemblerProcessingException {
475
        String executableName = assembler.getExecutable();
1✔
476

477
        return "bin/launcher.bat".equals(fileName) ?
1✔
478
            targetDirectory.resolve(BIN_DIRECTORY).resolve(executableName.concat(BAT.extension())) :
1✔
479
            "bin/launcher".equals(fileName) ?
1✔
480
                targetDirectory.resolve(BIN_DIRECTORY).resolve(executableName) :
1✔
481
                targetDirectory.resolve(fileName);
×
482
    }
483
}
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

© 2026 Coveralls, Inc