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

jreleaser / jreleaser / #558

08 Dec 2025 02:56PM UTC coverage: 48.239% (+0.02%) from 48.215%
#558

push

github

aalmiray
feat(core): warn when a name template cannot be resolved

Closes #1960

Closes #1961

299 of 573 new or added lines in 133 files covered. (52.18%)

4 existing lines in 4 files now uncovered.

26047 of 53996 relevant lines covered (48.24%)

0.48 hits per line

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

31.25
/sdks/jreleaser-http-java-sdk/src/main/java/org/jreleaser/sdk/http/HttpArtifactUploader.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 feign.form.FormData;
21
import org.jreleaser.bundle.RB;
22
import org.jreleaser.model.Http;
23
import org.jreleaser.model.internal.JReleaserContext;
24
import org.jreleaser.model.internal.common.Artifact;
25
import org.jreleaser.model.internal.upload.HttpUploader;
26
import org.jreleaser.model.spi.upload.UploadException;
27
import org.jreleaser.mustache.TemplateContext;
28
import org.jreleaser.sdk.commons.AbstractArtifactUploader;
29
import org.jreleaser.sdk.commons.ClientUtils;
30

31
import java.io.IOException;
32
import java.nio.file.Path;
33
import java.util.Base64;
34
import java.util.LinkedHashMap;
35
import java.util.Map;
36
import java.util.Set;
37

38
import static java.nio.charset.StandardCharsets.UTF_8;
39
import static org.jreleaser.mustache.Templates.resolveTemplate;
40
import static org.jreleaser.util.StringUtils.isNotBlank;
41

42
/**
43
 * @author Andres Almiray
44
 * @since 0.4.0
45
 */
46
public class HttpArtifactUploader extends AbstractArtifactUploader<org.jreleaser.model.api.upload.HttpUploader, HttpUploader> {
47
    private HttpUploader uploader;
48

49
    public HttpArtifactUploader(JReleaserContext context) {
50
        super(context);
1✔
51
    }
1✔
52

53
    @Override
54
    public HttpUploader getUploader() {
55
        return uploader;
1✔
56
    }
57

58
    @Override
59
    public void setUploader(HttpUploader uploader) {
60
        this.uploader = uploader;
1✔
61
    }
1✔
62

63
    @Override
64
    public String getType() {
65
        return org.jreleaser.model.api.upload.HttpUploader.TYPE;
×
66
    }
67

68
    @Override
69
    public void upload(String name) throws UploadException {
70
        Set<Artifact> artifacts = collectArtifacts();
1✔
71
        if (artifacts.isEmpty()) {
1✔
72
            context.getLogger().info(RB.$("artifacts.no.match"));
×
73
        }
74

75
        String username = uploader.getUsername();
1✔
76
        String password = uploader.getPassword();
1✔
77

78
        for (Artifact artifact : artifacts) {
1✔
79
            Path path = artifact.getEffectivePath(context);
1✔
80
            context.getLogger().info(" - {}", path.getFileName());
1✔
81

82
            if (!context.isDryrun()) {
1✔
83
                try {
84
                    FormData data = ClientUtils.toFormData(path);
×
85

86
                    Map<String, String> headers = new LinkedHashMap<>();
×
87
                    switch (uploader.resolveAuthorization()) {
×
88
                        case NONE:
89
                            break;
×
90
                        case BASIC:
91
                            String auth = username + ":" + password;
×
92
                            byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(UTF_8));
×
93
                            auth = new String(encodedAuth, UTF_8);
×
94
                            headers.put("Authorization", "Basic " + auth);
×
95
                            break;
×
96
                        case BEARER:
97
                            headers.put("Authorization", "Bearer " + password);
×
98
                            break;
99
                    }
100

101
                    resolveHeaders(artifact, headers);
×
102

103
                    if (uploader.getMethod() == Http.Method.POST) {
×
104
                        ClientUtils.postFile(context.getLogger(),
×
105
                            uploader.getResolvedUploadUrl(context, artifact),
×
106
                            uploader.getConnectTimeout(),
×
107
                            uploader.getReadTimeout(),
×
108
                            data,
109
                            headers);
110
                    } else {
111
                        ClientUtils.putFile(context.getLogger(),
×
112
                            uploader.getResolvedUploadUrl(context, artifact),
×
113
                            uploader.getConnectTimeout(),
×
114
                            uploader.getReadTimeout(),
×
115
                            data,
116
                            headers);
117
                    }
118
                } catch (IOException e) {
×
119
                    context.getLogger().trace(e);
×
120
                    throw new UploadException(RB.$("ERROR_unexpected_upload",
×
121
                        context.getBasedir().relativize(path)), e);
×
122
                }
×
123
            }
124
        }
1✔
125
    }
1✔
126

127
    private void resolveHeaders(Artifact artifact, Map<String, String> headers) {
128
        TemplateContext props = uploader.artifactProps(context, artifact);
×
129
        uploader.getHeaders().forEach((k, v) -> {
×
NEW
130
            String value = resolveTemplate(context.getLogger(), v, props);
×
131
            if (isNotBlank(value)) headers.put(k, value);
×
132
        });
×
133
    }
×
134
}
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