Skip to content

Commit

Permalink
[model] distributions should have deterministic artifact order. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 27, 2021
1 parent 84efb9e commit 1bacb20
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jreleaser.util.PlatformUtils;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -196,10 +197,11 @@ public boolean supportsPlatform(String platform) {

@Override
public Set<String> getSupportedExtensions() {
Set<String> extensions = super.getSupportedExtensions();
extensions.add(".jar");
Set<String> extensions = new LinkedHashSet<>();
extensions.add(".dmg");
extensions.add(".pkg");
extensions.add(".zip");
extensions.add(".jar");
return extensions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@
import org.jreleaser.util.Algorithm;
import org.jreleaser.util.Constants;
import org.jreleaser.util.FileUtils;
import org.jreleaser.util.StringUtils;
import org.zeroturnaround.exec.ProcessExecutor;
import org.zeroturnaround.exec.ProcessInitException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -290,11 +291,17 @@ protected boolean verifyAndAddArtifacts(Map<String, Object> props,
}

protected List<Artifact> collectArtifacts(Distribution distribution) {
Set<String> fileExtensions = tool.getSupportedExtensions();
List<String> fileExtensions = new ArrayList<>(tool.getSupportedExtensions());

return distribution.getArtifacts().stream()
.filter(Artifact::isActive)
.filter(artifact -> fileExtensions.stream().anyMatch(ext -> artifact.getPath().endsWith(ext)))
.filter(artifact -> tool.supportsPlatform(artifact.getPlatform()))
// sort by platform, then by extension
.sorted(Artifact.comparatorByPlatform().thenComparingInt(artifact -> {
String ext = "." + StringUtils.getFilenameExtension(artifact.getPath());
return fileExtensions.indexOf(ext);
}))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,18 @@ protected void fillToolProperties(Map<String, Object> props, Distribution distri

Cask cask = tool.getCask();
if (cask.isEnabled()) {
boolean hasPkg = isNotBlank(cask.getPkgName());
boolean hasApp = isNotBlank(cask.getAppName());

props.put(Constants.KEY_BREW_CASK_NAME, cask.getResolvedCaskName(props));
props.put(Constants.KEY_BREW_CASK_DISPLAY_NAME, cask.getResolvedDisplayName(props));
props.put(Constants.KEY_BREW_CASK_HAS_UNINSTALL, !cask.getUninstallItems().isEmpty());
props.put(Constants.KEY_BREW_CASK_HAS_PKG, isNotBlank(cask.getPkgName()));
if (isNotBlank(cask.getPkgName())) {
props.put(Constants.KEY_BREW_CASK_HAS_PKG, hasPkg);
if (hasPkg) {
props.put(Constants.KEY_BREW_CASK_PKG, cask.getResolvedPkgName(props));
}
props.put(Constants.KEY_BREW_CASK_HAS_APP, isNotBlank(cask.getAppName()));
if (isNotBlank(cask.getAppName())) {
props.put(Constants.KEY_BREW_CASK_HAS_APP, hasApp);
if (hasApp) {
props.put(Constants.KEY_BREW_CASK_APP, cask.getResolvedAppName(props));
}
props.put(Constants.KEY_BREW_CASK_UNINSTALL, cask.getUninstallItems());
Expand All @@ -114,12 +117,14 @@ protected void fillToolProperties(Map<String, Object> props, Distribution distri
props.put(Constants.KEY_BREW_CASK_HAS_APPCAST, isNotBlank(appcast));
props.put(Constants.KEY_BREW_CASK_APPCAST, appcast);

for (Artifact artifact : distribution.getArtifacts()) {
if (!artifact.isActive()) continue;
if (artifact.getPath().endsWith(".zip") && !isTrue(artifact.getExtraProperties().get("skipBrew"))) {
props.put(Constants.KEY_DISTRIBUTION_URL, resolveArtifactUrl(props, artifact));
props.put(Constants.KEY_BREW_CASK_HAS_BINARY, true);
break;
if (!hasApp && !hasPkg) {
for (Artifact artifact : distribution.getArtifacts()) {
if (!artifact.isActive()) continue;
if (artifact.getPath().endsWith(".zip") && !isTrue(artifact.getExtraProperties().get("skipBrew"))) {
props.put(Constants.KEY_DISTRIBUTION_URL, resolveArtifactUrl(props, artifact));
props.put(Constants.KEY_BREW_CASK_HAS_BINARY, true);
break;
}
}
}
} else if (tool.isMultiPlatform()) {
Expand Down Expand Up @@ -153,7 +158,7 @@ protected void fillToolProperties(Map<String, Object> props, Distribution distri
if (multiPlatforms.isEmpty()) {
throw new ToolProcessingException("There are no matching multi-platform binaries.");
}
props.put(Constants.KEY_BREW_MULTIPLATFORM, passThrough(String.join(System.lineSeparator()+" ", multiPlatforms)));
props.put(Constants.KEY_BREW_MULTIPLATFORM, passThrough(String.join(System.lineSeparator() + " ", multiPlatforms)));
} else if ((distribution.getType() == Distribution.DistributionType.JAVA_BINARY ||
distribution.getType() == Distribution.DistributionType.SINGLE_JAR) &&
!isTrue(tool.getExtraProperties().get("javaSkip")) &&
Expand Down

0 comments on commit 1bacb20

Please sign in to comment.