[upload] several updates

- 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
This commit is contained in:
Andres Almiray
2021-07-11 00:03:04 +02:00
parent 3c052fe901
commit d37e086392
21 changed files with 258 additions and 154 deletions

View File

@@ -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
@@ -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;
@@ -45,6 +57,8 @@ abstract class AbstractUploader implements 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;
@@ -53,6 +67,20 @@ abstract class AbstractUploader implements 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;
@@ -89,6 +117,26 @@ abstract class AbstractUploader implements Uploader {
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;
@@ -207,6 +255,8 @@ abstract class AbstractUploader implements Uploader {
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());
@@ -221,4 +271,30 @@ abstract class AbstractUploader implements Uploader {
}
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;
}
}

View File

@@ -23,7 +23,6 @@ import java.util.Map;
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;
/**
@@ -31,22 +30,20 @@ import static org.jreleaser.util.StringUtils.isNotBlank;
* @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;
}
@@ -58,12 +55,6 @@ public class Artifactory extends AbstractUploader {
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);
}
@@ -88,12 +79,16 @@ public class Artifactory extends AbstractUploader {
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() {
@@ -110,7 +105,6 @@ public class Artifactory extends AbstractUploader {
@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);

View File

@@ -334,85 +334,85 @@ public abstract class GitService implements Releaser, CommitAuthorAware, OwnerAw
@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;
}

View File

@@ -24,7 +24,6 @@ import java.util.Map;
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;
/**
@@ -32,24 +31,22 @@ import static org.jreleaser.util.StringUtils.isNotBlank;
* @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);
@@ -63,12 +60,6 @@ public class HttpUploader extends AbstractUploader {
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);
}
@@ -93,12 +84,16 @@ public class HttpUploader extends AbstractUploader {
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() {
@@ -139,7 +134,6 @@ public class HttpUploader extends AbstractUploader {
@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);

View File

@@ -153,11 +153,13 @@ public class Project implements Domain, ExtraProperties {
@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);
}

View File

@@ -18,13 +18,14 @@
package org.jreleaser.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.jreleaser.util.StringUtils.capitalize;
import static org.jreleaser.util.StringUtils.getClassNameForLowerCaseHyphenSeparatedName;
import static org.jreleaser.util.StringUtils.isBlank;
/**
@@ -141,21 +142,66 @@ public class Upload implements Domain, EnabledAware {
return map;
}
public <A extends Uploader> Map<String, A> findUploadersByType(String uploaderName) {
switch (uploaderName) {
case Artifactory.NAME:
public <A extends Uploader> Map<String, A> findUploadersByType(String uploaderType) {
switch (uploaderType) {
case Artifactory.TYPE:
return (Map<String, A>) artifactory;
case HttpUploader.NAME:
case HttpUploader.TYPE:
return (Map<String, A>) http;
}
return Collections.emptyMap();
}
public <A extends Uploader> Collection<A> findAllUploaders() {
public <A extends Uploader> List<A> findAllUploaders() {
List<A> uploaders = new ArrayList<>();
uploaders.addAll((List<A>) getActiveArtifactories());
uploaders.addAll((List<A>) getActiveHttps());
return uploaders;
}
public Map<String, String> resolveDownloadUrls(JReleaserContext context, Distribution distribution, Artifact artifact, String prefix) {
Map<String, String> urls = new LinkedHashMap<>();
List<Uploader> uploaders = findAllUploaders();
for (Uploader uploader : uploaders) {
List<String> keys = uploader.resolveSkipKeys();
if (isSkip(distribution.getExtraProperties(), keys) ||
isSkip(artifact.getExtraProperties(), keys)) continue;
String key = prefix +
"Download" +
capitalize(uploader.getType()) +
getClassNameForLowerCaseHyphenSeparatedName(uploader.getName()) +
"Url";
String url = uploader.getResolvedDownloadUrl(context, artifact);
urls.put(key, url);
if (findUploadersByType(uploader.getType()).size() == 1 && !isSkip(distribution.getExtraProperties(), keys) &&
!isSkip(artifact.getExtraProperties(), keys)) {
key = prefix +
"Download" +
capitalize(uploader.getType()) +
"Url";
url = uploader.getResolvedDownloadUrl(context, artifact);
urls.put(key, url);
}
}
if (uploaders.size() == 1) {
Uploader uploader = uploaders.get(0);
List<String> keys = uploader.resolveSkipKeys();
if (!isSkip(distribution.getExtraProperties(), keys) &&
!isSkip(artifact.getExtraProperties(), keys)) {
String key = prefix + "DownloadUrl";
String url = uploader.getResolvedDownloadUrl(context, artifact);
urls.put(key, url);
}
}
return urls;
}
private boolean isSkip(Map<String, Object> props, List<String> keys) {
return props.keySet().stream().anyMatch(keys::contains);
}
}

View File

@@ -17,6 +17,9 @@
*/
package org.jreleaser.model;
import java.util.List;
import java.util.Map;
import static org.jreleaser.util.StringUtils.isBlank;
/**
@@ -30,6 +33,14 @@ public interface Uploader extends Domain, Activatable, TimeoutAware, ExtraProper
void setName(String name);
String getUploadUrl();
void setUploadUrl(String uploadUrl);
String getDownloadUrl();
void setDownloadUrl(String downloadUrl);
boolean isSnapshotSupported();
Boolean isArtifacts();
@@ -50,6 +61,14 @@ public interface Uploader extends Domain, Activatable, TimeoutAware, ExtraProper
boolean isSignaturesSet();
List<String> resolveSkipKeys();
Map<String, Object> artifactProps(JReleaserContext context, Artifact artifact);
String getResolvedUploadUrl(JReleaserContext context, Artifact artifact);
String getResolvedDownloadUrl(JReleaserContext context, Artifact artifact);
enum Method {
PUT,
POST;

View File

@@ -55,8 +55,11 @@ public abstract class ArtifactoryValidator extends Validator {
return;
}
if (isBlank(artifactory.getTarget())) {
errors.configuration("artifactory." + artifactory.getName() + ".target must not be blank.");
if (isBlank(artifactory.getUploadUrl())) {
errors.configuration("artifactory." + artifactory.getName() + ".uploadUrl must not be blank.");
}
if (isBlank(artifactory.getDownloadUrl())) {
artifactory.setDownloadUrl(artifactory.getUploadUrl());
}
switch (artifactory.resolveAuthorization()) {

View File

@@ -59,8 +59,11 @@ public abstract class HttpUploaderValidator extends Validator {
return;
}
if (isBlank(http.getTarget())) {
errors.configuration("http." + http.getName() + ".target must not be blank.");
if (isBlank(http.getUploadUrl())) {
errors.configuration("http." + http.getName() + ".uploadUrl must not be blank.");
}
if (isBlank(http.getDownloadUrl())) {
http.setDownloadUrl(http.getUploadUrl());
}
if (null == http.getMethod()) {

View File

@@ -31,7 +31,6 @@ import static org.jreleaser.model.Project.PROJECT_SNAPSHOT_PATTERN;
import static org.jreleaser.model.Project.PROJECT_VERSION;
import static org.jreleaser.model.Project.PROJECT_VERSION_PATTERN;
import static org.jreleaser.util.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.isNotBlank;
/**
* @author Andres Almiray
@@ -77,10 +76,6 @@ public abstract class ProjectValidator extends Validator {
project.getSnapshot().getLabel(),
DEFAULT_SNAPSHOT_LABEL));
if (isNotBlank(project.getSnapshotPattern())) {
context.nag("0.6.0", "project.snapshotPattern has been deprecated. Use project.snapshot.pattern instead");
}
boolean javaDistributions = context.getModel().getDistributions().values().stream()
.map(Distribution::getType)
.anyMatch(type -> type == Distribution.DistributionType.JAVA_BINARY ||

View File

@@ -321,12 +321,16 @@ abstract class AbstractToolProcessor<T extends Tool> implements ToolProcessor<T>
newProps.put(Constants.KEY_ARTIFACT_FILE_NAME, artifactFileName);
String artifactUrl = applyTemplate(context.getModel().getRelease().getGitService().getDownloadUrl(), newProps, "downloadUrl");
props.put("artifact" + platform + "Url", artifactUrl);
props.putAll(context.getModel().getUpload()
.resolveDownloadUrls(context, distribution, artifact, "artifact" + platform));
if (0 == i) {
props.putAll(context.getModel().getUpload()
.resolveDownloadUrls(context, distribution, artifact, "distribution"));
props.put(Constants.KEY_DISTRIBUTION_URL, artifactUrl);
props.put(Constants.KEY_DISTRIBUTION_SHA_256, artifact.getHash(Algorithm.SHA_256));
for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
props.put("distributionChecksum" + capitalize(algorithm.formatted()), artifact.getHash(algorithm));
props.put("distributionChecksum" + capitalize(algorithm.formatted()), artifact.getHash(algorithm));
}
props.put(Constants.KEY_DISTRIBUTION_ARTIFACT_FILE_NAME, artifactFileName);
props.put(Constants.KEY_DISTRIBUTION_ARTIFACT_NAME, artifactName);

View File

@@ -30,6 +30,10 @@ import org.jreleaser.model.Active
interface Uploader extends ExtraProperties {
Property<Active> getActive()
Property<String> getUploadUrl()
Property<String> getDownloadUrl()
Property<Integer> getConnectTimeout()
Property<Integer> getReadTimeout()

View File

@@ -38,6 +38,8 @@ import static org.jreleaser.util.StringUtils.isNotBlank
@CompileStatic
abstract class AbstractUploader implements Uploader {
final Property<Active> active
final Property<String> uploadUrl
final Property<String> downloadUrl
final Property<Integer> connectTimeout
final Property<Integer> readTimeout
final Property<Boolean> artifacts
@@ -48,6 +50,8 @@ abstract class AbstractUploader implements Uploader {
@Inject
AbstractUploader(ObjectFactory objects) {
active = objects.property(Active).convention(Providers.notDefined())
uploadUrl = objects.property(String).convention(Providers.notDefined())
downloadUrl = objects.property(String).convention(Providers.notDefined())
connectTimeout = objects.property(Integer).convention(Providers.notDefined())
readTimeout = objects.property(Integer).convention(Providers.notDefined())
extraProperties = objects.mapProperty(String, Object).convention(Providers.notDefined())
@@ -59,6 +63,8 @@ abstract class AbstractUploader implements Uploader {
@Internal
boolean isSet() {
active.present ||
uploadUrl.present ||
downloadUrl.present ||
connectTimeout.present ||
readTimeout.present ||
extraProperties.present ||
@@ -76,6 +82,8 @@ abstract class AbstractUploader implements Uploader {
protected <U extends org.jreleaser.model.Uploader> void fillProperties(U uploader) {
if (active.present) uploader.active = active.get()
if (uploadUrl.present) uploader.uploadUrl = uploadUrl.get()
if (downloadUrl.present) uploader.downloadUrl = downloadUrl.get()
if (connectTimeout.present) uploader.connectTimeout = connectTimeout.get()
if (readTimeout.present) uploader.readTimeout = readTimeout.get()
if (extraProperties.present) uploader.extraProperties.putAll(extraProperties.get())

View File

@@ -29,6 +29,8 @@ abstract class AbstractUploader implements Uploader {
protected final String type;
private final Map<String, Object> extraProperties = new LinkedHashMap<>();
protected String name;
protected String uploadUrl;
protected String downloadUrl;
protected boolean enabled;
protected Active active;
private int connectTimeout;
@@ -45,6 +47,8 @@ abstract class AbstractUploader implements 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;
@@ -63,6 +67,26 @@ abstract class AbstractUploader implements Uploader {
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;

View File

@@ -28,6 +28,14 @@ public interface Uploader extends Activatable, TimeoutAware, ExtraProperties {
void setName(String name);
String getUploadUrl();
void setUploadUrl(String uploadUrl);
String getDownloadUrl();
void setDownloadUrl(String downloadUrl);
Boolean isArtifacts();
void setArtifacts(Boolean artifacts);

View File

@@ -345,7 +345,9 @@ public final class JReleaserModelConverter {
if (artifactory.isArtifactsSet()) a.setArtifacts(artifactory.isArtifacts());
if (artifactory.isFilesSet()) a.setFiles(artifactory.isFiles());
if (artifactory.isSignaturesSet()) a.setSignatures(artifactory.isSignatures());
a.setTarget(artifactory.getTarget());
if (isNotBlank(artifactory.getTarget())) a.setTarget(artifactory.getTarget());
a.setUploadUrl(artifactory.getUploadUrl());
a.setDownloadUrl(artifactory.getDownloadUrl());
a.setUsername(artifactory.getUsername());
a.setPassword(artifactory.getPassword());
a.setAuthorization(artifactory.resolveAuthorization().name());
@@ -371,7 +373,9 @@ public final class JReleaserModelConverter {
if (http.isArtifactsSet()) h.setArtifacts(http.isArtifacts());
if (http.isFilesSet()) h.setFiles(http.isFiles());
if (http.isSignaturesSet()) h.setSignatures(http.isSignatures());
h.setTarget(http.getTarget());
if (isNotBlank(http.getTarget())) h.setTarget(http.getTarget());
h.setUploadUrl(http.getUploadUrl());
h.setDownloadUrl(http.getDownloadUrl());
h.setUsername(http.getUsername());
h.setPassword(http.getPassword());
h.setAuthorization(http.resolveAuthorization().name());

View File

@@ -18,6 +18,7 @@
package org.jreleaser.sdk.artifactory;
import feign.form.FormData;
import org.jreleaser.model.Artifact;
import org.jreleaser.model.Artifactory;
import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.uploader.spi.UploadException;
@@ -33,8 +34,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static org.jreleaser.util.StringUtils.isNotBlank;
/**
* @author Andres Almiray
* @since 0.3.0
@@ -58,21 +57,21 @@ public class ArtifactoryArtifactUploader extends AbstractArtifactUploader<Artifa
@Override
public String getType() {
return Artifactory.NAME;
return Artifactory.TYPE;
}
@Override
public void upload(String name) throws UploadException {
List<Path> paths = collectPaths();
if (paths.isEmpty()) {
List<Artifact> artifacts = collectArtifacts();
if (artifacts.isEmpty()) {
context.getLogger().info("No matching artifacts. Skipping");
}
String target = uploader.getResolvedTarget(context);
String username = uploader.getResolvedUsername();
String password = uploader.getResolvedPassword();
for (Path path : paths) {
for (Artifact artifact : artifacts) {
Path path = artifact.getEffectivePath(context);
context.getLogger().info(" - {}", path.getFileName());
if (!context.isDryrun()) {
@@ -98,7 +97,7 @@ public class ArtifactoryArtifactUploader extends AbstractArtifactUploader<Artifa
headers.put("X-Checksum", ChecksumUtils.checksum(Algorithm.MD5, data.getData()));
ClientUtils.putFile(context.getLogger(),
target,
uploader.getResolvedUploadUrl(context, artifact),
uploader.getConnectTimeout(),
uploader.getReadTimeout(),
data,

View File

@@ -30,7 +30,7 @@ import org.kordamp.jipsy.annotations.ServiceProviderFor;
public class ArtifactoryArtifactUploaderFactory implements ArtifactUploaderFactory<Artifactory, ArtifactoryArtifactUploader> {
@Override
public String getName() {
return Artifactory.NAME;
return Artifactory.TYPE;
}
@Override

View File

@@ -25,7 +25,6 @@ import org.jreleaser.model.Uploader;
import org.jreleaser.model.uploader.spi.UploadException;
import org.jreleaser.sdk.commons.AbstractArtifactUploader;
import org.jreleaser.sdk.commons.ClientUtils;
import org.jreleaser.util.Constants;
import java.io.IOException;
import java.nio.file.Path;
@@ -35,7 +34,6 @@ import java.util.List;
import java.util.Map;
import static org.jreleaser.util.MustacheUtils.applyTemplate;
import static org.jreleaser.util.StringUtils.getFilename;
import static org.jreleaser.util.StringUtils.isNotBlank;
/**
@@ -61,7 +59,7 @@ public class HttpArtifactUploader extends AbstractArtifactUploader<HttpUploader>
@Override
public String getType() {
return HttpUploader.NAME;
return HttpUploader.TYPE;
}
@Override
@@ -101,14 +99,14 @@ public class HttpArtifactUploader extends AbstractArtifactUploader<HttpUploader>
if (uploader.getMethod() == Uploader.Method.POST) {
ClientUtils.postFile(context.getLogger(),
resolveUrl(artifact),
uploader.getResolvedUploadUrl(context, artifact),
uploader.getConnectTimeout(),
uploader.getReadTimeout(),
data,
headers);
} else {
ClientUtils.putFile(context.getLogger(),
resolveUrl(artifact),
uploader.getResolvedUploadUrl(context, artifact),
uploader.getConnectTimeout(),
uploader.getReadTimeout(),
data,
@@ -124,31 +122,10 @@ public class HttpArtifactUploader extends AbstractArtifactUploader<HttpUploader>
}
private void resolveHeaders(Artifact artifact, Map<String, String> headers) {
Map<String, Object> props = artifactProps(artifact);
Map<String, Object> props = uploader.artifactProps(context, artifact);
uploader.getHeaders().forEach((k, v) -> {
String value = applyTemplate(v, props);
if (isNotBlank(value)) headers.put(k, value);
});
}
private String resolveUrl(Artifact artifact) {
return uploader.getResolvedTarget(artifactProps(artifact));
}
private Map<String, Object> artifactProps(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;
}
}

View File

@@ -30,7 +30,7 @@ import org.kordamp.jipsy.annotations.ServiceProviderFor;
public class HttpArtifactUploaderFactory implements ArtifactUploaderFactory<HttpUploader, HttpArtifactUploader> {
@Override
public String getName() {
return HttpUploader.NAME;
return HttpUploader.TYPE;
}
@Override

View File

@@ -27,13 +27,9 @@ import org.jreleaser.model.util.Artifacts;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static org.jreleaser.util.StringUtils.capitalize;
import static org.jreleaser.util.StringUtils.getClassNameForLowerCaseHyphenSeparatedName;
/**
* @author Andres Almiray
* @since 0.4.0
@@ -45,55 +41,10 @@ public abstract class AbstractArtifactUploader<U extends Uploader> implements Ar
this.context = context;
}
protected List<Path> collectPaths() {
List<Path> paths = new ArrayList<>();
List<String> keys = resolveSkipKeys();
if (getUploader().isFiles()) {
for (Artifact artifact : Artifacts.resolveFiles(context)) {
if (isSkip(artifact.getExtraProperties(), keys)) continue;
Path path = artifact.getEffectivePath(context);
if (Files.exists(path) && 0 != path.toFile().length()) {
paths.add(path);
}
}
}
if (getUploader().isArtifacts()) {
for (Distribution distribution : context.getModel().getActiveDistributions()) {
if (isSkip(distribution.getExtraProperties(), keys)) continue;
for (Artifact artifact : distribution.getArtifacts()) {
if (isSkip(artifact.getExtraProperties(), keys)) continue;
Path path = artifact.getEffectivePath(context);
if (Files.exists(path) && 0 != path.toFile().length()) {
paths.add(path);
}
}
}
}
if (getUploader().isSignatures() && context.getModel().getSigning().isEnabled()) {
String extension = context.getModel().getSigning().isArmored() ? ".asc" : ".sig";
List<Path> signatures = new ArrayList<>();
for (Path path : paths) {
path = context.getSignaturesDirectory().resolve(path.getFileName() + extension);
if (Files.exists(path) && 0 != path.toFile().length()) {
signatures.add(path);
}
}
paths.addAll(signatures);
}
return paths;
}
protected List<Artifact> collectArtifacts() {
List<Artifact> artifacts = new ArrayList<>();
List<String> keys = resolveSkipKeys();
List<String> keys = getUploader().resolveSkipKeys();
if (getUploader().isFiles()) {
for (Artifact artifact : Artifacts.resolveFiles(context)) {
@@ -136,13 +87,6 @@ public abstract class AbstractArtifactUploader<U extends Uploader> implements Ar
return artifacts;
}
private List<String> resolveSkipKeys() {
String skipUpload = "skipUpload";
String skipUploadByType = skipUpload + capitalize(getType());
String skipUploadByName = skipUploadByType + getClassNameForLowerCaseHyphenSeparatedName(getUploader().getName());
return Arrays.asList(skipUpload, skipUploadByType, skipUploadByName);
}
private boolean isSkip(Map<String, Object> props, List<String> keys) {
return props.keySet().stream().anyMatch(keys::contains);
}