mirror of
https://github.com/jlengrand/jreleaser.git
synced 2026-03-10 08:31:24 +00:00
[core] Fix artifact sorting. Fixes #263
This commit is contained in:
@@ -22,9 +22,9 @@ import org.jreleaser.util.Version;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.jreleaser.util.CollectionUtils.safePut;
|
||||
import static org.jreleaser.util.MustacheUtils.applyTemplates;
|
||||
@@ -35,7 +35,7 @@ import static org.jreleaser.util.StringUtils.isNotBlank;
|
||||
* @since 0.2.0
|
||||
*/
|
||||
abstract class AbstractAssembler implements Assembler {
|
||||
protected final Set<Artifact> outputs = new TreeSet<>();
|
||||
protected final Set<Artifact> outputs = new LinkedHashSet<>();
|
||||
private final Map<String, Object> extraProperties = new LinkedHashMap<>();
|
||||
private final Java java = new Java();
|
||||
private final String type;
|
||||
@@ -176,7 +176,7 @@ abstract class AbstractAssembler implements Assembler {
|
||||
|
||||
@Override
|
||||
public Set<Artifact> getOutputs() {
|
||||
return outputs;
|
||||
return Artifact.sortArtifacts(outputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,9 +23,13 @@ import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.nio.file.Files.exists;
|
||||
import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
|
||||
@@ -38,7 +42,7 @@ import static org.jreleaser.util.StringUtils.isNotBlank;
|
||||
* @author Andres Almiray
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public class Artifact implements Domain, ExtraProperties, Comparable<Artifact> {
|
||||
public class Artifact implements Domain, ExtraProperties {
|
||||
private final Map<String, Object> extraProperties = new LinkedHashMap<>();
|
||||
private final Map<Algorithm, String> hashes = new LinkedHashMap<>();
|
||||
|
||||
@@ -300,8 +304,8 @@ public class Artifact implements Domain, ExtraProperties, Comparable<Artifact> {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Artifact artifact = (Artifact) o;
|
||||
return path.equals(artifact.path);
|
||||
Artifact that = (Artifact) o;
|
||||
return path.equals(that.path);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,13 +313,20 @@ public class Artifact implements Domain, ExtraProperties, Comparable<Artifact> {
|
||||
return Objects.hash(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Artifact that) {
|
||||
String p1 = this.platform;
|
||||
String p2 = that.platform;
|
||||
if (isBlank(p1)) p1 = "";
|
||||
if (isBlank(p2)) p2 = "";
|
||||
return p1.compareTo(p2);
|
||||
public static Set<Artifact> sortArtifacts(Set<Artifact> artifacts) {
|
||||
return artifacts.stream()
|
||||
.sorted(Artifact.comparatorByPlatform())
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
}
|
||||
|
||||
public static Comparator<Artifact> comparatorByPlatform() {
|
||||
return (a1, a2) -> {
|
||||
String p1 = a1.platform;
|
||||
String p2 = a2.platform;
|
||||
if (isBlank(p1)) p1 = "";
|
||||
if (isBlank(p2)) p2 = "";
|
||||
return p1.compareTo(p2);
|
||||
};
|
||||
}
|
||||
|
||||
public static Artifact of(Path resolvedPath) {
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.jreleaser.util.CollectionUtils.safePut;
|
||||
import static org.jreleaser.util.MustacheUtils.applyTemplates;
|
||||
@@ -48,7 +47,7 @@ public class Distribution extends Packagers implements ExtraProperties, Activata
|
||||
|
||||
private final List<String> tags = new ArrayList<>();
|
||||
private final Map<String, Object> extraProperties = new LinkedHashMap<>();
|
||||
private final Set<Artifact> artifacts = new TreeSet<>();
|
||||
private final Set<Artifact> artifacts = new LinkedHashSet<>();
|
||||
private final Java java = new Java();
|
||||
private Active active;
|
||||
private boolean enabled;
|
||||
@@ -171,7 +170,7 @@ public class Distribution extends Packagers implements ExtraProperties, Activata
|
||||
}
|
||||
|
||||
public Set<Artifact> getArtifacts() {
|
||||
return artifacts;
|
||||
return Artifact.sortArtifacts(artifacts);
|
||||
}
|
||||
|
||||
public void setArtifacts(Set<Artifact> artifacts) {
|
||||
@@ -287,7 +286,7 @@ public class Distribution extends Packagers implements ExtraProperties, Activata
|
||||
|
||||
Map<String, Map<String, Object>> mappedArtifacts = new LinkedHashMap<>();
|
||||
int i = 0;
|
||||
for (Artifact artifact : artifacts) {
|
||||
for (Artifact artifact : getArtifacts()) {
|
||||
mappedArtifacts.put("artifact " + (i++), artifact.asMap(full));
|
||||
}
|
||||
props.put("artifacts", mappedArtifacts);
|
||||
|
||||
@@ -18,21 +18,20 @@
|
||||
package org.jreleaser.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* @author Andres Almiray
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public class Files implements Domain {
|
||||
private final Set<Artifact> artifacts = new TreeSet<>();
|
||||
private final Set<Artifact> artifacts = new LinkedHashSet<>();
|
||||
private final List<Glob> globs = new ArrayList<>();
|
||||
private final Set<Artifact> paths = new TreeSet<>();
|
||||
private final Set<Artifact> paths = new LinkedHashSet<>();
|
||||
private boolean resolved;
|
||||
|
||||
public boolean isEmpty() {
|
||||
@@ -44,7 +43,7 @@ public class Files implements Domain {
|
||||
}
|
||||
|
||||
public Set<Artifact> getPaths() {
|
||||
return Collections.unmodifiableSet(paths);
|
||||
return Artifact.sortArtifacts(paths);
|
||||
}
|
||||
|
||||
public void setPaths(Set<Artifact> paths) {
|
||||
@@ -59,7 +58,7 @@ public class Files implements Domain {
|
||||
}
|
||||
|
||||
public Set<Artifact> getArtifacts() {
|
||||
return artifacts;
|
||||
return Artifact.sortArtifacts(artifacts);
|
||||
}
|
||||
|
||||
public void setArtifacts(Set<Artifact> artifacts) {
|
||||
@@ -102,7 +101,7 @@ public class Files implements Domain {
|
||||
|
||||
Map<String, Map<String, Object>> mappedArtifacts = new LinkedHashMap<>();
|
||||
int i = 0;
|
||||
for (Artifact artifact : artifacts) {
|
||||
for (Artifact artifact : getArtifacts()) {
|
||||
mappedArtifacts.put("artifact " + (i++), artifact.asMap(full));
|
||||
}
|
||||
map.put("artifacts", mappedArtifacts);
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.jreleaser.util.MustacheUtils.applyTemplate;
|
||||
import static org.jreleaser.util.StringUtils.isNotBlank;
|
||||
@@ -35,7 +34,7 @@ import static org.jreleaser.util.StringUtils.isNotBlank;
|
||||
public class Jlink extends AbstractAssembler {
|
||||
public static final String NAME = "jlink";
|
||||
|
||||
private final Set<Artifact> targetJdks = new TreeSet<>();
|
||||
private final Set<Artifact> targetJdks = new LinkedHashSet<>();
|
||||
private final Set<String> moduleNames = new LinkedHashSet<>();
|
||||
private final List<String> args = new ArrayList<>();
|
||||
private final Artifact jdk = new Artifact();
|
||||
@@ -105,7 +104,7 @@ public class Jlink extends AbstractAssembler {
|
||||
}
|
||||
|
||||
public Set<Artifact> getTargetJdks() {
|
||||
return targetJdks;
|
||||
return Artifact.sortArtifacts(targetJdks);
|
||||
}
|
||||
|
||||
public void setTargetJdks(Set<Artifact> targetJdks) {
|
||||
@@ -200,7 +199,7 @@ public class Jlink extends AbstractAssembler {
|
||||
props.put("args", args);
|
||||
Map<String, Map<String, Object>> mappedJdks = new LinkedHashMap<>();
|
||||
int i = 0;
|
||||
for (Artifact targetJdk : targetJdks) {
|
||||
for (Artifact targetJdk : getTargetJdks()) {
|
||||
mappedJdks.put("jdk " + (i++), targetJdk.asMap(full));
|
||||
}
|
||||
props.put("jdk", jdk.asMap(full));
|
||||
|
||||
@@ -35,9 +35,9 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static java.nio.file.FileVisitResult.CONTINUE;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Artifacts {
|
||||
return files.getPaths();
|
||||
}
|
||||
|
||||
Set<Artifact> paths = new TreeSet<>();
|
||||
Set<Artifact> paths = new LinkedHashSet<>();
|
||||
|
||||
// resolve artifacts
|
||||
for (Artifact artifact : files.getArtifacts()) {
|
||||
@@ -68,7 +68,7 @@ public class Artifacts {
|
||||
}
|
||||
}
|
||||
|
||||
files.setPaths(paths);
|
||||
files.setPaths(Artifact.sortArtifacts(paths));
|
||||
|
||||
return files.getPaths();
|
||||
}
|
||||
@@ -90,7 +90,8 @@ public class Artifacts {
|
||||
if (resolver.failed) {
|
||||
throw new JReleaserException("Some globs failed to be resolved.");
|
||||
}
|
||||
return resolver.artifacts;
|
||||
|
||||
return Artifact.sortArtifacts(resolver.artifacts);
|
||||
} catch (IOException e) {
|
||||
throw new JReleaserException("Unexpected error when resolving globs", e);
|
||||
}
|
||||
@@ -100,7 +101,7 @@ public class Artifacts {
|
||||
private final JReleaserLogger logger;
|
||||
private final List<PathMatcher> matchers;
|
||||
private final Path basedir;
|
||||
private final Set<Artifact> artifacts = new TreeSet<>();
|
||||
private final Set<Artifact> artifacts = new LinkedHashSet<>();
|
||||
private boolean failed;
|
||||
|
||||
private GlobResolver(JReleaserLogger logger, Path basedir, List<PathMatcher> matchers) {
|
||||
|
||||
Reference in New Issue
Block a user