Skip to content

Commit

Permalink
[upload] Add uploader specific skip keys. Resolves #278
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 10, 2021
1 parent 073a233 commit e814fe9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private Map<String, Object> artifactProps(Artifact artifact) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
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
Expand All @@ -43,8 +48,11 @@ protected AbstractArtifactUploader(JReleaserContext 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);
Expand All @@ -54,10 +62,9 @@ protected List<Path> collectPaths() {

if (getUploader().isArtifacts()) {
for (Distribution distribution : context.getModel().getActiveDistributions()) {
if (distribution.getExtraProperties().containsKey("skipUpload")) {
continue;
}
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);
Expand Down Expand Up @@ -86,8 +93,11 @@ protected List<Path> collectPaths() {
protected List<Artifact> collectArtifacts() {
List<Artifact> artifacts = 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()) {
artifacts.add(artifact);
Expand All @@ -97,10 +107,9 @@ protected List<Artifact> collectArtifacts() {

if (getUploader().isArtifacts()) {
for (Distribution distribution : context.getModel().getActiveDistributions()) {
if (distribution.getExtraProperties().containsKey("skipUpload")) {
continue;
}
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()) {
artifacts.add(artifact);
Expand All @@ -126,4 +135,15 @@ protected List<Artifact> collectArtifacts() {

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);
}
}

0 comments on commit e814fe9

Please sign in to comment.