Skip to content

Commit

Permalink
[core] skip properties should have a defined value. Fixes #292
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 16, 2021
1 parent 81a08ed commit 5f56576
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.jreleaser.util.StringUtils.capitalize;
import static org.jreleaser.util.StringUtils.getClassNameForLowerCaseHyphenSeparatedName;
import static org.jreleaser.util.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.isTrue;

/**
* @author Andres Almiray
Expand Down Expand Up @@ -202,6 +203,11 @@ public Map<String, String> resolveDownloadUrls(JReleaserContext context, Distrib
}

private boolean isSkip(Map<String, Object> props, List<String> keys) {
return props.keySet().stream().anyMatch(keys::contains);
for (String key : keys) {
if (props.containsKey(key) && isTrue(props.get(key))) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static org.jreleaser.model.validation.TemplateValidator.validateTemplate;
import static org.jreleaser.util.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.isNotBlank;
import static org.jreleaser.util.StringUtils.isTrue;

/**
* @author Andres Almiray
Expand Down Expand Up @@ -114,9 +115,9 @@ private static void validateCask(JReleaserContext context, Distribution distribu
int pkgFound = 0;
String pkgName = "";
for (Artifact artifact : distribution.getArtifacts()) {
if (artifact.getPath().endsWith(".dmg") && !artifact.getExtraProperties().containsKey("skipBrew"))
if (artifact.getPath().endsWith(".dmg") && !isTrue(artifact.getExtraProperties().get("skipBrew")))
dmgFound++;
if (artifact.getPath().endsWith(".pkg") && !artifact.getExtraProperties().containsKey("skipBrew")) {
if (artifact.getPath().endsWith(".pkg") && !isTrue(artifact.getExtraProperties().get("skipBrew"))) {
pkgFound++;
pkgName = artifact.getEffectivePath(context).getFileName().toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.jreleaser.util.MustacheUtils.applyTemplate;
import static org.jreleaser.util.MustacheUtils.passThrough;
import static org.jreleaser.util.StringUtils.isNotBlank;
import static org.jreleaser.util.StringUtils.isTrue;

/**
* @author Andres Almiray
Expand Down Expand Up @@ -72,8 +73,8 @@ protected void fillToolProperties(Map<String, Object> props, Distribution distri

if ((distribution.getType() == Distribution.DistributionType.JAVA_BINARY ||
distribution.getType() == Distribution.DistributionType.SINGLE_JAR) &&
!tool.getExtraProperties().containsKey("javaSkip") &&
!tool.getExtraProperties().containsKey("skipJava")) {
!isTrue(tool.getExtraProperties().get("javaSkip")) &&
!isTrue(tool.getExtraProperties().get("skipJava"))) {
tool.addDependency("openjdk@" + props.get(Constants.KEY_DISTRIBUTION_JAVA_VERSION));
} else if (distribution.getType() == Distribution.DistributionType.NATIVE_PACKAGE) {
props.put(Constants.KEY_BREW_CASK_NAME, tool.getCask().getResolvedCaskName(props));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,10 @@ public static String toSafeRegexPattern(String str) {
public static Pattern toSafePattern(String str) {
return Pattern.compile(toSafeRegexPattern(str));
}

public static boolean isTrue(Object o) {
if (o == null) return false;
if (o instanceof Boolean) return (Boolean) o;
return "true".equalsIgnoreCase(String.valueOf(o).trim());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.List;
import java.util.Map;

import static org.jreleaser.util.StringUtils.isTrue;

/**
* @author Andres Almiray
* @since 0.4.0
Expand Down Expand Up @@ -88,6 +90,11 @@ protected List<Artifact> collectArtifacts() {
}

private boolean isSkip(Map<String, Object> props, List<String> keys) {
return props.keySet().stream().anyMatch(keys::contains);
for (String key : keys) {
if (props.containsKey(key) && isTrue(props.get(key))) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.jreleaser.util.MustacheUtils.applyTemplate;
import static org.jreleaser.util.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.isNotBlank;
import static org.jreleaser.util.StringUtils.isTrue;

/**
* @author Andres Almiray
Expand Down Expand Up @@ -68,7 +69,7 @@ public void announce() throws AnnounceException {
continue;
}

if (artifact.getExtraProperties().containsKey("skipSdkman")) {
if (isTrue(artifact.getExtraProperties().get("skipSdkman"))) {
context.getLogger().debug("Artifact {} is explicitly skipped.",
artifact.getEffectivePath(context, distribution).getFileName());
continue;
Expand Down Expand Up @@ -130,8 +131,8 @@ private boolean isDistributionSupported(Distribution distribution) {
return (distribution.getType() == Distribution.DistributionType.JAVA_BINARY ||
distribution.getType() == Distribution.DistributionType.JLINK ||
distribution.getType() == Distribution.DistributionType.NATIVE_IMAGE) &&
!distribution.getExtraProperties().containsKey("sdkmanSkip") &&
!distribution.getExtraProperties().containsKey("skipSdkman");
!isTrue(distribution.getExtraProperties().get("sdkmanSkip")) &&
!isTrue(distribution.getExtraProperties().get("skipSdkman"));
}

private String mapPlatform(String platform) {
Expand Down

0 comments on commit 5f56576

Please sign in to comment.