• 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-http-java-sdk/src/main/java/org/jreleaser/sdk/http/HttpArtifactDownloader.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.http;
19

20
import org.jreleaser.bundle.RB;
21
import org.jreleaser.model.internal.JReleaserContext;
22
import org.jreleaser.model.internal.download.Downloader;
23
import org.jreleaser.model.internal.download.HttpDownloader;
24
import org.jreleaser.model.spi.download.DownloadException;
25
import org.jreleaser.sdk.commons.AbstractArtifactDownloader;
26

27
import java.io.IOException;
28
import java.net.URI;
29
import java.net.URISyntaxException;
30
import java.nio.file.Path;
31

32
import static org.jreleaser.util.StringUtils.isBlank;
33

34
/**
35
 * @author Andres Almiray
36
 * @since 1.1.0
37
 */
38
public class HttpArtifactDownloader extends AbstractArtifactDownloader<org.jreleaser.model.api.download.HttpDownloader, HttpDownloader> {
39
    private HttpDownloader downloader;
40

41
    public HttpArtifactDownloader(JReleaserContext context) {
42
        super(context);
×
43
    }
×
44

45
    @Override
46
    public HttpDownloader getDownloader() {
47
        return downloader;
×
48
    }
49

50
    @Override
51
    public void setDownloader(HttpDownloader downloader) {
52
        this.downloader = downloader;
×
53
    }
×
54

55
    @Override
56
    public String getType() {
57
        return org.jreleaser.model.api.download.HttpDownloader.TYPE;
×
58
    }
59

60
    @Override
61
    public void download(String name) throws DownloadException {
62
        for (Downloader.Asset asset : downloader.getAssets()) {
×
63
            downloadAsset(name, asset);
×
64
        }
×
65
    }
×
66

67
    private void downloadAsset(String name, Downloader.Asset asset) throws DownloadException {
68
        String input = asset.getResolvedInput(context, downloader);
×
69
        String output = asset.getResolvedOutput(context, downloader, getFilename(input));
×
70

71
        if (isBlank(output)) {
×
72
            output = getFilename(input);
×
73
        }
74

75
        Path outputPath = context.getDownloadDirectory().resolve(name).resolve(output);
×
76
        context.getLogger().info("{} -> {}", input, context.relativizeToBasedir(outputPath));
×
77

78
        if (!context.isDryrun()) {
×
79
            try {
80
                org.apache.commons.io.FileUtils.copyURLToFile(
×
81
                    new URI(input).toURL(),
×
82
                    outputPath.toFile(),
×
83
                    downloader.getConnectTimeout() * 1000,
×
84
                    downloader.getReadTimeout() * 1000);
×
85
            } catch (URISyntaxException | IOException e) {
×
86
                throw new DownloadException(RB.$("ERROR_unexpected_download", input), e);
×
87
            }
×
88
        }
89

90
        unpack(asset.getUnpack(), outputPath);
×
91
    }
×
92

93
    private String getFilename(String name) {
94
        return name.substring(name.lastIndexOf('/') + 1);
×
95
    }
96
}
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