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

jreleaser / jreleaser / #539

25 Sep 2025 06:51PM UTC coverage: 48.269% (+0.7%) from 47.589%
#539

push

github

web-flow
feat(release): Add support for github immutable releases

Closes #1978

2 of 14 new or added lines in 4 files covered. (14.29%)

10 existing lines in 5 files now uncovered.

25820 of 53492 relevant lines covered (48.27%)

0.48 hits per line

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

68.21
/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 configuredPath = assembler.getJavaArchive().getPath();
×
159
            String archiveFile = resolveTemplate(configuredPath, props);
×
160
            Path archivePath = context.getBasedir().resolve(Paths.get(archiveFile));
×
161
            if (!Files.exists(archivePath)) {
×
162
                throw new AssemblerProcessingException(RB.$("ERROR_path_does_not_exist_2", configuredPath, archivePath));
×
163
            }
164

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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