Skip to content

Commit

Permalink
[upload] several updates
Browse files Browse the repository at this point in the history
- Generate download URLs for matching uploaders. Resolves #279
- Configure uploadUrl/downladUrl properties in uploaders. Resolves #282
- UploadURLs should have explicit artifact file name. Resolves #283
  • Loading branch information
aalmiray committed Jul 10, 2021
1 parent 3c052fe commit d37e086
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@
*/
package org.jreleaser.model;

import org.jreleaser.util.Constants;

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static org.jreleaser.util.MustacheUtils.applyTemplate;
import static org.jreleaser.util.StringUtils.capitalize;
import static org.jreleaser.util.StringUtils.getClassNameForLowerCaseHyphenSeparatedName;
import static org.jreleaser.util.StringUtils.getFilename;
import static org.jreleaser.util.StringUtils.isNotBlank;

/**
* @author Andres Almiray
* @since 0.3.0
Expand All @@ -31,6 +41,8 @@ abstract class AbstractUploader implements Uploader {
protected String name;
protected boolean enabled;
protected Active active;
private String uploadUrl;
private String downloadUrl;
private int connectTimeout;
private int readTimeout;
private Boolean artifacts;
Expand All @@ -45,6 +57,8 @@ void setAll(AbstractUploader uploader) {
this.active = uploader.active;
this.enabled = uploader.enabled;
this.name = uploader.name;
this.uploadUrl = uploader.uploadUrl;
this.downloadUrl = uploader.downloadUrl;
this.connectTimeout = uploader.connectTimeout;
this.readTimeout = uploader.readTimeout;
this.artifacts = uploader.artifacts;
Expand All @@ -53,6 +67,20 @@ void setAll(AbstractUploader uploader) {
setExtraProperties(uploader.extraProperties);
}

@Override
public String getResolvedUploadUrl(JReleaserContext context, Artifact artifact) {
Map<String, Object> p = new LinkedHashMap<>(artifactProps(context, artifact));
p.putAll(getResolvedExtraProperties());
return applyTemplate(uploadUrl, p);
}

@Override
public String getResolvedDownloadUrl(JReleaserContext context, Artifact artifact) {
Map<String, Object> p = new LinkedHashMap<>(artifactProps(context, artifact));
p.putAll(getResolvedExtraProperties());
return applyTemplate(downloadUrl, p);
}

@Override
public String getPrefix() {
return name;
Expand Down Expand Up @@ -89,6 +117,26 @@ public void setName(String name) {
this.name = name;
}

@Override
public String getUploadUrl() {
return uploadUrl;
}

@Override
public void setUploadUrl(String uploadUrl) {
this.uploadUrl = uploadUrl;
}

@Override
public String getDownloadUrl() {
return downloadUrl;
}

@Override
public void setDownloadUrl(String downloadUrl) {
this.downloadUrl = downloadUrl;
}

@Override
public Active getActive() {
return active;
Expand Down Expand Up @@ -207,6 +255,8 @@ public Map<String, Object> asMap(boolean full) {
Map<String, Object> props = new LinkedHashMap<>();
props.put("enabled", isEnabled());
props.put("active", active);
props.put("uploadUrl", uploadUrl);
props.put("downloadUrl", downloadUrl);
props.put("connectTimeout", connectTimeout);
props.put("readTimeout", readTimeout);
props.put("artifacts", isArtifacts());
Expand All @@ -221,4 +271,30 @@ public Map<String, Object> asMap(boolean full) {
}

protected abstract void asMap(Map<String, Object> props, boolean full);

@Override
public List<String> resolveSkipKeys() {
String skipUpload = "skipUpload";
String skipUploadByType = skipUpload + capitalize(type);
String skipUploadByName = skipUploadByType + getClassNameForLowerCaseHyphenSeparatedName(name);
return Arrays.asList(skipUpload, skipUploadByType, skipUploadByName);
}

@Override
public Map<String, Object> artifactProps(JReleaserContext context, Artifact artifact) {
Map<String, Object> props = context.props();

String platform = isNotBlank(artifact.getPlatform()) ? artifact.getPlatform() : "";
// add extra properties without clobbering existing keys
Map<String, Object> artifactProps = artifact.getResolvedExtraProperties("artifact");
artifactProps.keySet().stream()
.filter(k -> !props.containsKey(k))
.filter(k -> !k.startsWith("artifactSkip"))
.forEach(k -> props.put(k, artifactProps.get(k)));
String artifactFileName = artifact.getEffectivePath(context).getFileName().toString();
props.put(Constants.KEY_ARTIFACT_PLATFORM, platform);
props.put(Constants.KEY_ARTIFACT_FILE_NAME, artifactFileName);
props.put(Constants.KEY_ARTIFACT_NAME, getFilename(artifactFileName));
return props;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,27 @@

import static org.jreleaser.util.Constants.HIDE;
import static org.jreleaser.util.Constants.UNSET;
import static org.jreleaser.util.MustacheUtils.applyTemplate;
import static org.jreleaser.util.StringUtils.isNotBlank;

/**
* @author Andres Almiray
* @since 0.3.0
*/
public class Artifactory extends AbstractUploader {
public static final String NAME = "artifactory";
public static final String TYPE = "artifactory";

private String target;
private String username;
private String password;
private Authorization authorization;

public Artifactory() {
super(NAME);
super(TYPE);
}

void setAll(Artifactory artifactory) {
super.setAll(artifactory);
this.username = artifactory.username;
this.password = artifactory.password;
this.target = artifactory.target;
this.authorization = artifactory.authorization;
}

Expand All @@ -58,12 +55,6 @@ public Authorization resolveAuthorization() {
return authorization;
}

public String getResolvedTarget(JReleaserContext context) {
Map<String, Object> props = context.props();
props.putAll(getResolvedExtraProperties());
return applyTemplate(target, props);
}

public String getResolvedUsername() {
return Env.resolve("ARTIFACTORY_" + Env.toVar(name) + "_USERNAME", username);
}
Expand All @@ -88,12 +79,16 @@ public void setPassword(String password) {
this.password = password;
}

@Deprecated
public String getTarget() {
return target;
System.out.println("artifactory.target has been deprecated since 0.6.0 and will be removed in the future. Use artifactory.uploadUrl instead");
return getUploadUrl();
}

@Deprecated
public void setTarget(String target) {
this.target = target;
System.out.println("artifactory.target has been deprecated since 0.6.0 and will be removed in the future. Use artifactory.uploadUrl instead");
setUploadUrl(target);
}

public Authorization getAuthorization() {
Expand All @@ -110,7 +105,6 @@ public void setAuthorization(String authorization) {

@Override
protected void asMap(Map<String, Object> props, boolean full) {
props.put("target", target);
props.put("authorization", authorization);
props.put("username", isNotBlank(getResolvedUsername()) ? HIDE : UNSET);
props.put("password", isNotBlank(getResolvedPassword()) ? HIDE : UNSET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,85 +334,85 @@ public void setIssueTrackerUrl(String issueTrackerUrl) {

@Deprecated
public String getRepoUrlFormat() {
System.out.println("getRepoUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use getRepoUrl() instead");
System.out.println("getRepoUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use getRepoUrl() instead");
return repoUrl;
}

@Deprecated
public void setRepoUrlFormat(String repoUrl) {
System.out.println("setRepoUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use setRepoUrl() instead");
System.out.println("setRepoUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use setRepoUrl() instead");
this.repoUrl = repoUrl;
}

@Deprecated
public String getRepoCloneUrlFormat() {
System.out.println("getRepoCloneUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use getRepoCloneUrl() instead");
System.out.println("getRepoCloneUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use getRepoCloneUrl() instead");
return repoCloneUrl;
}

@Deprecated
public void setRepoCloneUrlFormat(String repoCloneUrl) {
System.out.println("setRepoCloneUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use setRepoCloneUrl() instead");
System.out.println("setRepoCloneUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use setRepoCloneUrl() instead");
this.repoCloneUrl = repoCloneUrl;
}

@Deprecated
public String getCommitUrlFormat() {
System.out.println("getCommitUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use getCommitUrl() instead");
System.out.println("getCommitUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use getCommitUrl() instead");
return commitUrl;
}

@Deprecated
public void setCommitUrlFormat(String commitUrl) {
System.out.println("setCommitUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use setCommitUrl() instead");
System.out.println("setCommitUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use setCommitUrl() instead");
this.commitUrl = commitUrl;
}

@Deprecated
public String getDownloadUrlFormat() {
System.out.println("getDownloadUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use getDownloadUrl() instead");
System.out.println("getDownloadUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use getDownloadUrl() instead");
return downloadUrl;
}

@Deprecated
public void setDownloadUrlFormat(String downloadUrl) {
System.out.println("setDownloadUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use setDownloadUrl() instead");
System.out.println("setDownloadUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use setDownloadUrl() instead");
this.downloadUrl = downloadUrl;
}

@Deprecated
public String getReleaseNotesUrlFormat() {
System.out.println("getReleaseNotesUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use getReleaseNotesUrl() instead");
System.out.println("getReleaseNotesUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use getReleaseNotesUrl() instead");
return releaseNotesUrl;
}

@Deprecated
public void setReleaseNotesUrlFormat(String releaseNotesUrl) {
System.out.println("setReleaseNotesUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use setReleaseNotesUrl() instead");
System.out.println("setReleaseNotesUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use setReleaseNotesUrl() instead");
this.releaseNotesUrl = releaseNotesUrl;
}

@Deprecated
public String getLatestReleaseUrlFormat() {
System.out.println("getLatestReleaseUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use getLatestReleaseUrl() instead");
System.out.println("getLatestReleaseUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use getLatestReleaseUrl() instead");
return latestReleaseUrl;
}

@Deprecated
public void setLatestReleaseUrlFormat(String latestReleaseUrl) {
System.out.println("setLatestReleaseUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use setLatestReleaseUrl() instead");
System.out.println("setLatestReleaseUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use setLatestReleaseUrl() instead");
this.latestReleaseUrl = latestReleaseUrl;
}

@Deprecated
public String getIssueTrackerUrlFormat() {
System.out.println("getIssueTrackerUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use getIssueTrackerUrl() instead");
System.out.println("getIssueTrackerUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use getIssueTrackerUrl() instead");
return issueTrackerUrl;
}

@Deprecated
public void setIssueTrackerUrlFormat(String issueTrackerUrl) {
System.out.println("setIssueTrackerUrlFormat() has been deprecated since 0.5.0 wan will be removed in the future. Use setIssueTrackerUrl() instead");
System.out.println("setIssueTrackerUrlFormat() has been deprecated since 0.5.0 and will be removed in the future. Use setIssueTrackerUrl() instead");
this.issueTrackerUrl = issueTrackerUrl;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,29 @@

import static org.jreleaser.util.Constants.HIDE;
import static org.jreleaser.util.Constants.UNSET;
import static org.jreleaser.util.MustacheUtils.applyTemplate;
import static org.jreleaser.util.StringUtils.isNotBlank;

/**
* @author Andres Almiray
* @since 0.4.0
*/
public class HttpUploader extends AbstractUploader {
public static final String NAME = "http";
public static final String TYPE = "http";

private final Map<String, String> headers = new LinkedHashMap<>();
private String target;
private String username;
private String password;
private Authorization authorization;
private Method method;

public HttpUploader() {
super(NAME);
super(TYPE);
}

void setAll(HttpUploader http) {
super.setAll(http);
this.username = http.username;
this.password = http.password;
this.target = http.target;
this.authorization = http.authorization;
this.method = http.method;
setHeaders(http.headers);
Expand All @@ -63,12 +60,6 @@ public Authorization resolveAuthorization() {
return authorization;
}

public String getResolvedTarget(Map<String, Object> props) {
Map<String, Object> p = new LinkedHashMap<>(props);
p.putAll(getResolvedExtraProperties());
return applyTemplate(target, p);
}

public String getResolvedUsername() {
return Env.resolve("HTTP_" + Env.toVar(name) + "_USERNAME", username);
}
Expand All @@ -93,12 +84,16 @@ public void setPassword(String password) {
this.password = password;
}

@Deprecated
public String getTarget() {
return target;
System.out.println("http.target has been deprecated since 0.6.0 and will be removed in the future. Use http.uploadUrl instead");
return getUploadUrl();
}

@Deprecated
public void setTarget(String target) {
this.target = target;
System.out.println("http.target has been deprecated since 0.6.0 and will be removed in the future. Use http.uploadUrl instead");
setUploadUrl(target);
}

public Authorization getAuthorization() {
Expand Down Expand Up @@ -139,7 +134,6 @@ public void addHeaders(Map<String, String> headers) {

@Override
protected void asMap(Map<String, Object> props, boolean full) {
props.put("target", target);
props.put("authorization", authorization);
props.put("method", method);
props.put("username", isNotBlank(getResolvedUsername()) ? HIDE : UNSET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ public void setSnapshot(Snapshot snapshot) {

@Deprecated
public String getSnapshotPattern() {
System.out.println("project.snapshotPattern has been deprecated since 0.6.0 and will be removed in the future. Use project.snapshot.pattern instead");
return snapshotPattern;
}

@Deprecated
public void setSnapshotPattern(String snapshotPattern) {
System.out.println("project.snapshotPattern has been deprecated since 0.6.0 and will be removed in the future. Use project.snapshot.pattern instead");
this.snapshotPattern = snapshotPattern;
this.snapshot.setPattern(snapshotPattern);
}
Expand Down

0 comments on commit d37e086

Please sign in to comment.