Skip to content

Commit

Permalink
feat: Add extraProperties support to screenshot. Resolves #900
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Aug 15, 2022
1 parent 0b39476 commit 467f314
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
* @author Andres Almiray
* @since 1.2.0
*/
public class Screenshot extends AbstractModelObject<Screenshot> implements Domain {
public class Screenshot extends AbstractModelObject<Screenshot> implements Domain, ExtraProperties {
protected final Map<String, Object> extraProperties = new LinkedHashMap<>();

private Type type = Type.SOURCE;
private Boolean primary;
private String url;
Expand All @@ -36,14 +38,15 @@ public class Screenshot extends AbstractModelObject<Screenshot> implements Domai
private Integer height;

@Override
public void merge(Screenshot registry) {
public void merge(Screenshot source) {
freezeCheck();
this.type = merge(this.type, registry.type);
this.primary = merge(this.primary, registry.primary);
this.url = merge(this.url, registry.url);
this.caption = merge(this.caption, registry.caption);
this.width = merge(this.width, registry.width);
this.height = merge(this.height, registry.height);
this.type = merge(this.type, source.type);
this.primary = merge(this.primary, source.primary);
this.url = merge(this.url, source.url);
this.caption = merge(this.caption, source.caption);
this.width = merge(this.width, source.width);
this.height = merge(this.height, source.height);
setExtraProperties(merge(this.extraProperties, source.extraProperties));
}

public Type getType() {
Expand Down Expand Up @@ -104,6 +107,29 @@ public void setHeight(Integer height) {
this.height = height;
}

@Override
public String getPrefix() {
return "screenshot";
}

@Override
public Map<String, Object> getExtraProperties() {
return freezeWrap(extraProperties);
}

@Override
public void setExtraProperties(Map<String, Object> extraProperties) {
freezeCheck();
this.extraProperties.clear();
this.extraProperties.putAll(extraProperties);
}

@Override
public void addExtraProperties(Map<String, Object> extraProperties) {
freezeCheck();
this.extraProperties.putAll(extraProperties);
}

@Override
public Map<String, Object> asMap(boolean full) {
Map<String, Object> map = new LinkedHashMap<>();
Expand All @@ -113,6 +139,7 @@ public Map<String, Object> asMap(boolean full) {
map.put("caption", caption);
map.put("width", width);
map.put("height", height);
map.put("extraProperties", getResolvedExtraProperties());
return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@
import org.jreleaser.model.GitService;
import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.JReleaserModel;
import org.jreleaser.model.Screenshot;
import org.jreleaser.model.Stereotype;
import org.jreleaser.util.Errors;

import java.util.ArrayList;
import java.util.List;

import static org.jreleaser.model.AppImage.SKIP_APPIMAGE;
import static org.jreleaser.model.validation.DistributionsValidator.validateArtifactPlatforms;
import static org.jreleaser.model.validation.ExtraPropertiesValidator.mergeExtraProperties;
import static org.jreleaser.model.validation.TemplateValidator.validateTemplate;
import static org.jreleaser.util.CollectionUtils.listOf;
import static org.jreleaser.util.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.isFalse;
import static org.jreleaser.util.StringUtils.isNotBlank;
import static org.jreleaser.util.StringUtils.isTrue;

/**
* @author Andres Almiray
Expand Down Expand Up @@ -101,6 +106,10 @@ public static void validateAppImage(JReleaserContext context, JReleaserContext.M
errors.configuration(RB.$("validation_is_empty", "distribution." + distribution.getName() + ".appImage.screenshots"));
}
validateScreenshots(context, mode, packager.getScreenshots(), errors, "distribution." + distribution.getName() + ".appImage");
packager.getScreenshots().removeIf(screenshot -> isTrue(screenshot.getExtraProperties().get(SKIP_APPIMAGE)));
if (packager.getScreenshots().isEmpty()) {
errors.configuration(RB.$("validation_is_empty", "distribution." + distribution.getName() + ".appImage.screenshots"));
}

if (isBlank(packager.getRepository().getName())) {
packager.getRepository().setName(distribution.getName() + "-appimage");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.gradle.api.provider.Property
* @since 1.2.0
*/
@CompileStatic
interface Screenshot {
interface Screenshot extends ExtraProperties {
void setScreenshotType(String str)

Property<org.jreleaser.model.Screenshot.Type> getScreenshotType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.jreleaser.gradle.plugin.internal.dsl
import groovy.transform.CompileStatic
import org.gradle.api.internal.provider.Providers
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.jreleaser.gradle.plugin.dsl.Screenshot

Expand All @@ -41,6 +42,7 @@ class ScreenshotImpl implements Screenshot {
final Property<String> caption
final Property<Integer> width
final Property<Integer> height
final MapProperty<String, Object> extraProperties

@Inject
ScreenshotImpl(ObjectFactory objects) {
Expand All @@ -51,6 +53,7 @@ class ScreenshotImpl implements Screenshot {
caption = objects.property(String).convention(Providers.notDefined())
width = objects.property(Integer).convention(Providers.notDefined())
height = objects.property(Integer).convention(Providers.notDefined())
extraProperties = objects.mapProperty(String, Object).convention(Providers.notDefined())
}

@Override
Expand All @@ -68,6 +71,7 @@ class ScreenshotImpl implements Screenshot {
if (caption.present) screenshot.caption = caption.get()
if (width.present) screenshot.width = width.get()
if (height.present) screenshot.height = height.get()
if (extraProperties.present) screenshot.extraProperties.putAll(extraProperties.get())
screenshot
}
}

0 comments on commit 467f314

Please sign in to comment.