Skip to content

Commit

Permalink
[packagers] handle skipSpec property on artifacts. Resolves #574
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Dec 6, 2021
1 parent f909047 commit 2019cfa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
Expand Up @@ -31,6 +31,8 @@
*/
public class Spec extends AbstractRepositoryTool {
public static final String NAME = "spec";
public static final String SKIP_SPEC = "skipSpec";

private final List<String> requires = new ArrayList<>();
private final SpecRepository repository = new SpecRepository();

Expand Down
Expand Up @@ -17,6 +17,9 @@
*/
package org.jreleaser.model.validation;

import org.jreleaser.bundle.RB;
import org.jreleaser.model.Active;
import org.jreleaser.model.Artifact;
import org.jreleaser.model.Distribution;
import org.jreleaser.model.GitService;
import org.jreleaser.model.JReleaserContext;
Expand All @@ -26,11 +29,16 @@
import org.jreleaser.util.Errors;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;
import static org.jreleaser.model.Spec.SKIP_SPEC;
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.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.isTrue;

/**
* @author Andres Almiray
Expand Down Expand Up @@ -85,5 +93,19 @@ public static void validateSpec(JReleaserContext context, Distribution distribut
mergeExtraProperties(tool, parentTool);
validateContinueOnError(tool, parentTool);
validateArtifactPlatforms(context, distribution, tool, errors);

List<Artifact> candidateArtifacts = distribution.getArtifacts().stream()
.filter(Artifact::isActive)
.filter(artifact -> tool.getSupportedExtensions().stream().anyMatch(ext -> artifact.getPath().endsWith(ext)))
.filter(artifact -> !isTrue(artifact.getExtraProperties().get(SKIP_SPEC)))
.collect(toList());

if (candidateArtifacts.size() == 0) {
tool.setActive(Active.NEVER);
tool.disable();
} else if(candidateArtifacts.size()> 1) {
errors.configuration(RB.$("validation_spec_multiple_artifacts", "distribution." + distribution.getName() + ".spec"));
tool.disable();
}
}
}
Expand Up @@ -333,6 +333,7 @@ protected List<Artifact> collectArtifacts(Distribution distribution) {
.filter(Artifact::isActive)
.filter(artifact -> fileExtensions.stream().anyMatch(ext -> artifact.getPath().endsWith(ext)))
.filter(artifact -> tool.supportsPlatform(artifact.getPlatform()))
.filter(artifact -> !isSkipped(artifact))
// sort by platform, then by extension
.sorted(Artifact.comparatorByPlatform().thenComparingInt(artifact -> {
String ext = "." + StringUtils.getFilenameExtension(artifact.getPath());
Expand All @@ -341,6 +342,10 @@ protected List<Artifact> collectArtifacts(Distribution distribution) {
.collect(Collectors.toList());
}

protected boolean isSkipped(Artifact artifact) {
return false;
}

protected void info(ByteArrayOutputStream out) {
log(out, context.getLogger()::info);
}
Expand Down
Expand Up @@ -34,8 +34,10 @@
import java.util.Map;
import java.util.Set;

import static org.jreleaser.model.Spec.SKIP_SPEC;
import static org.jreleaser.templates.TemplateUtils.trimTplExtension;
import static org.jreleaser.util.StringUtils.getFilename;
import static org.jreleaser.util.StringUtils.isTrue;

/**
* @author Andres Almiray
Expand Down Expand Up @@ -79,7 +81,7 @@ private void setupJavaBinary(Distribution distribution, Map<String, Object> prop
files.add(entry.replace(context.getModel().getProject().getResolvedVersion(),
"%{version}")
.replace(context.getModel().getProject().getEffectiveVersion(),
"%{version}"));
"%{version}"));
});

props.put(Constants.KEY_SPEC_DIRECTORIES, directories);
Expand Down Expand Up @@ -117,4 +119,9 @@ protected void writeFile(Project project,

writeFile(content, outputFile);
}

@Override
protected boolean isSkipped(Artifact artifact) {
return isTrue(artifact.getExtraProperties().get(SKIP_SPEC));
}
}
Expand Up @@ -232,6 +232,7 @@ 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: {}
validation_spec_multiple_artifacts = {} has nore than one artifact that may be packaged with spec
validation_discussions_enabled = discussions may only be used when releasing to GitHub
validation_distributions_java = {} is set to {} but neither {} nor {} have been set
validation_distributions_multiple = {} has more than one artifact with {} platform for extension {}
Expand Down

0 comments on commit 2019cfa

Please sign in to comment.