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

jreleaser / jreleaser / #477

04 Apr 2025 05:53PM UTC coverage: 35.124% (-5.1%) from 40.183%
#477

push

github

aalmiray
fix(deploy): Add missing Forgejo messages

Related to #1842

18210 of 51845 relevant lines covered (35.12%)

0.35 hits per line

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

0.0
/sdks/jreleaser-ssh-java-sdk/src/main/java/org/jreleaser/sdk/ssh/SftpArtifactDownloader.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.sdk.ssh;
19

20
import net.schmizz.sshj.SSHClient;
21
import net.schmizz.sshj.sftp.SFTPClient;
22
import org.jreleaser.bundle.RB;
23
import org.jreleaser.model.internal.JReleaserContext;
24
import org.jreleaser.model.internal.download.Downloader;
25
import org.jreleaser.model.internal.download.SftpDownloader;
26
import org.jreleaser.model.spi.download.DownloadException;
27
import org.jreleaser.sdk.commons.AbstractArtifactDownloader;
28

29
import java.io.IOException;
30
import java.nio.file.Files;
31
import java.nio.file.Path;
32
import java.nio.file.Paths;
33

34
import static org.jreleaser.sdk.ssh.SshUtils.close;
35
import static org.jreleaser.sdk.ssh.SshUtils.createSFTPClient;
36
import static org.jreleaser.sdk.ssh.SshUtils.createSSHClient;
37
import static org.jreleaser.sdk.ssh.SshUtils.disconnect;
38
import static org.jreleaser.util.StringUtils.isBlank;
39

40
/**
41
 * @author Andres Almiray
42
 * @since 1.1.0
43
 */
44
public class SftpArtifactDownloader extends AbstractArtifactDownloader<org.jreleaser.model.api.download.SftpDownloader, SftpDownloader> {
45
    private SftpDownloader downloader;
46

47
    public SftpArtifactDownloader(JReleaserContext context) {
48
        super(context);
×
49
    }
×
50

51
    @Override
52
    public SftpDownloader getDownloader() {
53
        return downloader;
×
54
    }
55

56
    @Override
57
    public void setDownloader(SftpDownloader downloader) {
58
        this.downloader = downloader;
×
59
    }
×
60

61
    @Override
62
    public String getType() {
63
        return org.jreleaser.model.api.download.ScpDownloader.TYPE;
×
64
    }
65

66
    @Override
67
    public void download(String name) throws DownloadException {
68
        SSHClient ssh = createSSHClient(context, downloader);
×
69
        SFTPClient sftp = createSFTPClient(downloader, ssh);
×
70

71
        try {
72
            try {
73
                for (Downloader.Asset asset : downloader.getAssets()) {
×
74
                    downloadAsset(name, sftp, asset);
×
75
                }
×
76
            } finally {
77
                close(downloader, sftp);
×
78
            }
79
        } finally {
80
            disconnect(downloader, ssh);
×
81
        }
82
    }
×
83

84
    private void downloadAsset(String name, SFTPClient sftp, Downloader.Asset asset) throws DownloadException {
85
        String input = asset.getResolvedInput(context, downloader);
×
86
        String output = asset.getResolvedOutput(context, downloader, Paths.get(input).getFileName().toString());
×
87

88
        if (isBlank(output)) {
×
89
            output = Paths.get(input).getFileName().toString();
×
90
        }
91

92
        Path outputPath = context.getDownloadDirectory().resolve(name).resolve(output);
×
93
        context.getLogger().info("{} -> {}", input, context.relativizeToBasedir(outputPath));
×
94

95
        if (!context.isDryrun()) {
×
96
            try {
97
                Files.createDirectories(outputPath.toAbsolutePath().getParent());
×
98
                sftp.get(input, outputPath.toAbsolutePath().toString());
×
99
            } catch (IOException e) {
×
100
                throw new DownloadException(RB.$("ERROR_unexpected_download", input), e);
×
101
            }
×
102
        }
103

104
        unpack(asset.getUnpack(), outputPath);
×
105
    }
×
106
}
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