Skip to content

Commit

Permalink
[snap] support the architectures block. Resolves #592
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Dec 12, 2021
1 parent 4572016 commit e3503ed
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 121 deletions.
121 changes: 119 additions & 2 deletions core/jreleaser-model/src/main/java/org/jreleaser/model/Snap.java
Expand Up @@ -42,7 +42,9 @@ public class Snap extends AbstractRepositoryTool {
private final Set<String> localSlots = new LinkedHashSet<>();
private final List<Plug> plugs = new ArrayList<>();
private final List<Slot> slots = new ArrayList<>();
private final List<Architecture> architectures = new ArrayList<>();
private final SnapTap snap = new SnapTap();

private String packageName;
private String base = "core20";
private String grade = "stable";
Expand Down Expand Up @@ -76,6 +78,7 @@ void setAll(Snap snap) {
setLocalSlots(snap.localSlots);
setPlugs(snap.plugs);
setSlots(snap.slots);
setArchitectures(snap.architectures);
setSnap(snap.snap);
}

Expand Down Expand Up @@ -211,6 +214,31 @@ public void removeSlot(Slot slot) {
}
}

public List<Architecture> getArchitectures() {
return architectures;
}

public void setArchitectures(List<Architecture> architectures) {
this.architectures.clear();
this.architectures.addAll(architectures);
}

public void addArchitecture(List<Architecture> architectures) {
this.architectures.addAll(architectures);
}

public void addArchitecture(Architecture architecture) {
if (null != architecture) {
this.architectures.add(architecture);
}
}

public void removeArchitecture(Architecture architecture) {
if (null != architecture) {
this.architectures.remove(architecture);
}
}

public String getExportedLogin() {
return exportedLogin;
}
Expand Down Expand Up @@ -251,8 +279,24 @@ protected void asMap(boolean full, Map<String, Object> props) {
props.put("snap", snap.asMap(full));
props.put("localPlugs", localPlugs);
props.put("localSlots", localSlots);
props.put("plugs", plugs);
props.put("slots", slots);

Map<String, Map<String, Object>> mapped = new LinkedHashMap<>();
for (int i = 0; i < plugs.size(); i++) {
mapped.put("plug " + i, plugs.get(i).asMap(full));
}
props.put("plugs", mapped);

mapped = new LinkedHashMap<>();
for (int i = 0; i < slots.size(); i++) {
mapped.put("slot " + i, slots.get(i).asMap(full));
}
props.put("slots", mapped);

mapped = new LinkedHashMap<>();
for (int i = 0; i < architectures.size(); i++) {
mapped.put("architecture " + i, architectures.get(i).asMap(full));
}
props.put("architectures", mapped);
}

@Override
Expand Down Expand Up @@ -422,4 +466,77 @@ public SnapTap() {
super("snap", "snap");
}
}

public static class Architecture implements Domain {
private final List<String> buildOn = new ArrayList<>();
private final List<String> runOn = new ArrayList<>();
private Boolean ignoreError;

public List<String> getBuildOn() {
return buildOn;
}

public void setBuildOn(List<String> buildOn) {
this.buildOn.clear();
this.buildOn.addAll(buildOn);
}

public void addBuildOn(List<String> buildOn) {
this.buildOn.addAll(buildOn);
}

public void addBuildOn(String str) {
if (isNotBlank(str)) {
this.buildOn.add(str.trim());
}
}

public List<String> getRunOn() {
return runOn;
}

public void setRunOn(List<String> runOn) {
this.runOn.clear();
this.runOn.addAll(runOn);
}

public void addRunOn(List<String> runOn) {
this.runOn.addAll(runOn);
}

public void addRunOn(String str) {
if (isNotBlank(str)) {
this.runOn.add(str.trim());
}
}

public boolean hasBuildOn() {
return !buildOn.isEmpty();
}

public boolean hasRunOn() {
return !runOn.isEmpty();
}

public boolean isIgnoreError() {
return ignoreError != null && ignoreError;
}

public void setIgnoreError(Boolean ignoreError) {
this.ignoreError = ignoreError;
}

public boolean isIgnoreErrorSet() {
return ignoreError != null;
}

@Override
public Map<String, Object> asMap(boolean full) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("buildOn", buildOn);
map.put("runOn", runOn);
map.put("ignoreError", isIgnoreError());
return map;
}
}
}
Expand Up @@ -256,7 +256,7 @@ private static void validateChangelog(JReleaserContext context, GitService servi
errors.configuration(RB.$("validation_is_missing", service.getServiceName() + ".changelog.categories[" + i + "].title"));
}
if (category.getLabels().isEmpty()) {
errors.configuration(RB.$("validation_ares_missing", service.getServiceName() + ".changelog.categories[" + i + "].labels"));
errors.configuration(RB.$("validation_are_missing", service.getServiceName() + ".changelog.categories[" + i + "].labels"));
}

i++;
Expand Down
Expand Up @@ -128,6 +128,14 @@ public static void validateSnap(JReleaserContext context, Distribution distribut
errors.configuration(RB.$("validation_tool_multiple_artifacts", "distribution." + distribution.getName() + ".snap"));
tool.disable();
}

tool.addArchitecture(parentTool.getArchitectures());
for (int i = 0; i < tool.getArchitectures().size(); i++) {
Snap.Architecture arch = tool.getArchitectures().get(i);
if (!arch.hasBuildOn()) {
errors.configuration(RB.$("validation_snap_missing_buildon", "distribution." + distribution.getName() + ".snap.architectures", i));
}
}
}

private static void mergeSnapPlugs(Snap tool, Snap common) {
Expand Down
Expand Up @@ -9,6 +9,14 @@ confinement: {{snapConfinement}}
base: {{snapBase}}
type: app

{{#hasArchitectures}}
architectures:
{{#snapArchitectures}}
- build-on: {{buildOn}}
{{#hasRunOn}}run-on: {{runOn}}{{/hasRunOn}}
{{#ignoreError}}build-error: ignore{{/ignoreError}}
{{/snapArchitectures}}
{{/hasArchitectures}}
apps:
{{distributionExecutable}}:
command: $SNAP/bin/{{distributionExecutable}}
Expand Down
Expand Up @@ -9,6 +9,14 @@ confinement: {{snapConfinement}}
base: {{snapBase}}
type: app

{{#hasArchitectures}}
architectures:
{{#snapArchitectures}}
- build-on: {{buildOn}}
{{#hasRunOn}}run-on: {{runOn}}{{/hasRunOn}}
{{#ignoreError}}build-error: ignore{{/ignoreError}}
{{/snapArchitectures}}
{{/hasArchitectures}}
apps:
{{distributionExecutable}}:
command: $SNAP/bin/{{distributionExecutable}}
Expand Down
Expand Up @@ -9,6 +9,14 @@ confinement: {{snapConfinement}}
base: {{snapBase}}
type: app

{{#hasArchitectures}}
architectures:
{{#snapArchitectures}}
- build-on: {{buildOn}}
{{#hasRunOn}}run-on: {{runOn}}{{/hasRunOn}}
{{#ignoreError}}build-error: ignore{{/ignoreError}}
{{/snapArchitectures}}
{{/hasArchitectures}}
apps:
{{distributionExecutable}}:
command: $SNAP/bin/{{distributionExecutable}}
Expand Down
Expand Up @@ -9,6 +9,14 @@ confinement: {{snapConfinement}}
base: {{snapBase}}
type: app

{{#hasArchitectures}}
architectures:
{{#snapArchitectures}}
- build-on: {{buildOn}}
{{#hasRunOn}}run-on: {{runOn}}{{/hasRunOn}}
{{#ignoreError}}build-error: ignore{{/ignoreError}}
{{/snapArchitectures}}
{{/hasArchitectures}}
apps:
{{distributionExecutable}}:
command: $SNAP/bin/{{distributionExecutable}}
Expand Down
Expand Up @@ -9,6 +9,14 @@ confinement: {{snapConfinement}}
base: {{snapBase}}
type: app

{{#hasArchitectures}}
architectures:
{{#snapArchitectures}}
- build-on: {{buildOn}}
{{#hasRunOn}}run-on: {{runOn}}{{/hasRunOn}}
{{#ignoreError}}build-error: ignore{{/ignoreError}}
{{/snapArchitectures}}
{{/hasArchitectures}}
apps:
{{distributionExecutable}}:
command: ${JAVA_HOME}/bin/java -jar $SNAP/{{distributionArtifactFile}}
Expand Down
Expand Up @@ -39,9 +39,11 @@
import static org.jreleaser.util.Constants.KEY_DISTRIBUTION_PACKAGE_DIRECTORY;
import static org.jreleaser.util.Constants.KEY_PROJECT_EFFECTIVE_VERSION;
import static org.jreleaser.util.Constants.KEY_PROJECT_LONG_DESCRIPTION;
import static org.jreleaser.util.Constants.KEY_SNAP_ARCHITECTURES;
import static org.jreleaser.util.Constants.KEY_SNAP_BASE;
import static org.jreleaser.util.Constants.KEY_SNAP_CONFINEMENT;
import static org.jreleaser.util.Constants.KEY_SNAP_GRADE;
import static org.jreleaser.util.Constants.KEY_SNAP_HAS_ARCHITECTURES;
import static org.jreleaser.util.Constants.KEY_SNAP_HAS_LOCAL_PLUGS;
import static org.jreleaser.util.Constants.KEY_SNAP_HAS_LOCAL_SLOTS;
import static org.jreleaser.util.Constants.KEY_SNAP_HAS_PLUGS;
Expand Down Expand Up @@ -130,6 +132,8 @@ protected void fillToolProperties(Map<String, Object> props, Distribution distri
props.put(KEY_SNAP_LOCAL_PLUGS, tool.getLocalPlugs());
props.put(KEY_SNAP_HAS_LOCAL_SLOTS, !tool.getLocalSlots().isEmpty());
props.put(KEY_SNAP_LOCAL_SLOTS, tool.getLocalSlots());
props.put(KEY_SNAP_HAS_ARCHITECTURES, !tool.getArchitectures().isEmpty());
props.put(KEY_SNAP_ARCHITECTURES, tool.getArchitectures());
}

@Override
Expand Down
Expand Up @@ -240,6 +240,8 @@ public interface Constants {
String KEY_SNAP_LOCAL_PLUGS = "snapLocalPlugs";
String KEY_SNAP_HAS_LOCAL_SLOTS = "snapHasLocalSlots";
String KEY_SNAP_LOCAL_SLOTS = "snapLocalSlots";
String KEY_SNAP_HAS_ARCHITECTURES = "hasArchitectures";
String KEY_SNAP_ARCHITECTURES = "snapArchitectures";
String KEY_SNAP_REPO_URL = "snapRepoUrl";
String KEY_SNAP_REPO_CLONE_URL = "snapRepoCloneUrl";

Expand Down
Expand Up @@ -225,6 +225,7 @@ validation_must_not_be_null = {} must not be null
validation_is_null = {} is null
validation_is_empty = {} is empty
validation_is_missing = {} is missing
validation_are_missing = {} are missing
validation_directory_not_exist = {} does not exist: {}
validation_is_not_a_directory = {} is not a directory: {}
validation_directory_is_empty = {} is empty: {}
Expand All @@ -234,6 +235,8 @@ validation_multiple_assemblers = {} has more than 1 assembler: {}
validation_brew_multiple_artifact = {} has more than one {} artifact
validation_brew_single_artifact = {} can only have a single matching .dmg, .pkg, or .zip artifact
validation_brew_duplicate_definition = {} is defined for more than one distribution: {}
# do not translate .buildOn
validation_snap_missing_buildon = {}[{}].buildOn must define at least one entry
validation_tool_multiple_artifacts = {} has more than one artifact that may be packaged
validation_discussions_enabled = discussions may only be used when releasing to GitHub
validation_distributions_java = {} is set to {} but neither {} nor {} have been set
Expand Down
Expand Up @@ -61,8 +61,12 @@ interface Snap extends RepositoryTool {

void snap(Action<? super Tap> action)

void architecture(Action<? super Architecture> action)

void snap(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Tap) Closure<Void> action)

void architecture(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Architecture) Closure<Void> action)

@CompileStatic
interface Slot {
MapProperty<String, String> getAttributes()
Expand All @@ -84,4 +88,17 @@ interface Snap extends RepositoryTool {

void addAttribute(String key, String value)
}

@CompileStatic
interface Architecture {
ListProperty<String> getBuildOn()

void addBuildOn(String str)

ListProperty<String> getRunOn()

void addRunOn(String str)

Property<String> getIgnoreError()
}
}

0 comments on commit e3503ed

Please sign in to comment.