Skip to content

Commit

Permalink
[core] Add a platform property to Glob. Resolves #565
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Dec 3, 2021
1 parent a843131 commit 4177b29
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ public static Comparator<Artifact> comparatorByPlatform() {
};
}

public static Artifact of(Path resolvedPath, String platform, Map<String, Object> props) {
Artifact artifact = new Artifact();
artifact.path = resolvedPath.toAbsolutePath().toString();
artifact.platform = platform;
artifact.resolvedPath = resolvedPath;
artifact.setExtraProperties(props);
return artifact;
}

public static Artifact of(Path resolvedPath, Map<String, Object> props) {
Artifact artifact = new Artifact();
artifact.path = resolvedPath.toAbsolutePath().toString();
Expand Down
14 changes: 13 additions & 1 deletion core/jreleaser-model/src/main/java/org/jreleaser/model/Glob.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Glob implements Domain, ExtraProperties {
private final Map<String, Object> extraProperties = new LinkedHashMap<>();

private String pattern;
private String platform;
private Set<Artifact> artifacts;

private String directory;
Expand All @@ -62,6 +63,7 @@ public class Glob implements Domain, ExtraProperties {

void setAll(Glob glob) {
this.pattern = glob.pattern;
this.platform = glob.platform;
setExtraProperties(glob.extraProperties);
}

Expand Down Expand Up @@ -96,6 +98,7 @@ public Set<Artifact> getResolvedArtifactsPattern(JReleaserContext context) {
normalizePattern();
artifacts = Artifacts.resolveFiles(context, resolveDirectory(context), Collections.singletonList(pattern));
artifacts.forEach(artifact -> {
artifact.setPlatform(platform);
if (context.isPlatformSelected(artifact)) artifact.activate();
artifact.setExtraProperties(getExtraProperties());
});
Expand Down Expand Up @@ -143,7 +146,7 @@ public Set<Artifact> getResolvedArtifactsLegacy(JReleaserContext context) {
}

artifacts = fileCollector.getFiles().stream()
.map(p -> Artifact.of(p, getExtraProperties()))
.map(p -> Artifact.of(p, platform, getExtraProperties()))
.peek(a -> {
if (context.isPlatformSelected(a)) a.activate();
})
Expand Down Expand Up @@ -180,6 +183,14 @@ private void normalizePattern() {
}
}

public String getPlatform() {
return platform;
}

public void setPlatform(String platform) {
this.platform = platform;
}

public String getDirectory() {
return directory;
}
Expand Down Expand Up @@ -226,6 +237,7 @@ public boolean isRecursiveSet() {
public Map<String, Object> asMap(boolean full) {
Map<String, Object> props = new LinkedHashMap<>();
props.put("pattern", pattern);
props.put("platform", platform);
props.put("extraProperties", getResolvedExtraProperties());
props.put("directory", directory);
props.put("include", include);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import org.gradle.api.provider.Property
interface Glob {
Property<String> getPattern()

Property<String> getPlatform()

DirectoryProperty getDirectory()

Property<String> getInclude()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import javax.inject.Inject
class GlobImpl implements Glob {
String name
final Property<String> pattern
final Property<String> platform
final DirectoryProperty directory
final Property<String> include
final Property<String> exclude
Expand All @@ -43,6 +44,7 @@ class GlobImpl implements Glob {
@Inject
GlobImpl(ObjectFactory objects) {
pattern = objects.property(String).convention(Providers.notDefined())
platform = objects.property(String).convention(Providers.notDefined())
directory = objects.directoryProperty().convention(Providers.notDefined())
include = objects.property(String).convention(Providers.notDefined())
exclude = objects.property(String).convention(Providers.notDefined())
Expand All @@ -56,6 +58,7 @@ class GlobImpl implements Glob {
org.jreleaser.model.Glob toModel() {
org.jreleaser.model.Glob glob = new org.jreleaser.model.Glob()
if (pattern.present) glob.pattern = pattern.get()
if (platform.present) glob.platform = platform.get()
if (directory.present) {
glob.directory = directory.asFile.get().absolutePath
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
public class Glob {
private String pattern;
private String platform;
private String directory;
private String include;
private String exclude;
Expand All @@ -36,6 +37,14 @@ public void setPattern(String pattern) {
this.pattern = pattern;
}

public String getPlatform() {
return platform;
}

public void setPlatform(String platform) {
this.platform = platform;
}

public String getDirectory() {
return directory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ private static List<org.jreleaser.model.Glob> convertGlobs(List<Glob> globs) {
private static org.jreleaser.model.Glob convertGlob(Glob glob) {
org.jreleaser.model.Glob g = new org.jreleaser.model.Glob();
g.setPattern(tr(glob.getPattern()));
g.setPlatform(tr(glob.getPlatform()));
if (isNotBlank(glob.getDirectory())) g.setDirectory(tr(glob.getDirectory()));
if (isNotBlank(glob.getInclude())) g.setInclude(glob.getInclude());
if (isNotBlank(glob.getExclude())) g.setExclude(glob.getExclude());
Expand Down

0 comments on commit 4177b29

Please sign in to comment.