use of org.jreleaser.model.Distribution in project jreleaser by jreleaser.
the class Signer method collectArtifacts.
private static List<FilePair> collectArtifacts(JReleaserContext context, boolean forceSign, Function<FilePair, Boolean> validator) {
List<FilePair> files = new ArrayList<>();
Signing signing = context.getModel().getSigning();
Path signaturesDirectory = context.getSignaturesDirectory();
String extension = ".sig";
if (signing.getMode() != Signing.Mode.COSIGN) {
extension = signing.isArmored() ? ".asc" : ".sig";
}
if (signing.isFiles()) {
for (Artifact artifact : Artifacts.resolveFiles(context)) {
if (!artifact.isActive() || artifact.extraPropertyIsTrue(KEY_SKIP_SIGNING))
continue;
Path input = artifact.getEffectivePath(context);
Path output = signaturesDirectory.resolve(input.getFileName().toString().concat(extension));
FilePair pair = new FilePair(input, output);
if (!forceSign)
pair.setValid(validator.apply(pair));
files.add(pair);
}
}
if (signing.isArtifacts()) {
for (Distribution distribution : context.getModel().getActiveDistributions()) {
if (distribution.extraPropertyIsTrue(KEY_SKIP_SIGNING))
continue;
for (Artifact artifact : distribution.getArtifacts()) {
if (!artifact.isActive() || artifact.extraPropertyIsTrue(KEY_SKIP_SIGNING))
continue;
Path input = artifact.getEffectivePath(context, distribution);
Path output = signaturesDirectory.resolve(input.getFileName().toString().concat(extension));
FilePair pair = new FilePair(input, output);
if (!forceSign)
pair.setValid(validator.apply(pair));
files.add(pair);
}
}
}
if (signing.isChecksums()) {
for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
Path checksums = context.getChecksumsDirectory().resolve(context.getModel().getChecksum().getResolvedName(context, algorithm));
if (Files.exists(checksums)) {
Path output = signaturesDirectory.resolve(checksums.getFileName().toString().concat(extension));
FilePair pair = new FilePair(checksums, output);
if (!forceSign)
pair.setValid(validator.apply(pair));
files.add(pair);
}
}
}
return files;
}
use of org.jreleaser.model.Distribution in project jreleaser by jreleaser.
the class Distributions method process.
public static void process(JReleaserContext context, String action, PackagerProcessingFunction function) {
List<Distribution> activeDistributions = context.getModel().getActiveDistributions();
if (activeDistributions.isEmpty()) {
context.getLogger().debug(RB.$("distributions.not.enabled"), action.toLowerCase());
return;
}
if (!context.getIncludedDistributions().isEmpty()) {
for (String distributionName : context.getIncludedDistributions()) {
Distribution distribution = activeDistributions.stream().filter(d -> distributionName.equals(d.getName())).findFirst().orElse(null);
if (null == distribution) {
context.getLogger().error(RB.$("distributions.no.match"), distributionName);
return;
}
if (!context.getIncludedPackagers().isEmpty()) {
for (String packagerName : context.getIncludedPackagers()) {
if (!Distribution.supportedPackagers().contains(packagerName)) {
context.getLogger().warn(RB.$("ERROR_unsupported_packager", packagerName));
continue;
}
context.getLogger().info(RB.$("distributions.apply.action"), action);
processDistribution(context, action, distribution, packagerName, function);
}
} else {
processDistribution(context, action, distribution, function);
}
}
} else if (!context.getIncludedPackagers().isEmpty()) {
for (String packagerName : context.getIncludedPackagers()) {
if (!Distribution.supportedPackagers().contains(packagerName)) {
context.getLogger().warn(RB.$("ERROR_unsupported_packager", packagerName));
continue;
}
context.getLogger().info(RB.$("distributions.apply.action"), action);
for (Distribution distribution : activeDistributions) {
processDistribution(context, action, distribution, packagerName, function);
}
}
} else {
// process all
context.getLogger().info(RB.$("distributions.apply.action"), action);
for (Distribution distribution : activeDistributions) {
if (context.getExcludedDistributions().contains(distribution.getName())) {
context.getLogger().info(RB.$("distributions.distribution.excluded"), distribution.getName());
continue;
}
processDistribution(context, action, distribution, function);
}
}
}
use of org.jreleaser.model.Distribution in project jreleaser by jreleaser.
the class DockerValidator method validateDocker.
public static void validateDocker(JReleaserContext context, Distribution distribution, Docker packager, Errors errors) {
JReleaserModel model = context.getModel();
Project project = model.getProject();
Docker parentPackager = model.getPackagers().getDocker();
if (!packager.isActiveSet() && parentPackager.isActiveSet()) {
packager.setActive(parentPackager.getActive());
}
if (!packager.resolveEnabled(context.getModel().getProject(), distribution))
return;
String element = "distribution." + distribution.getName() + ".docker";
context.getLogger().debug(element);
List<Artifact> candidateArtifacts = packager.resolveCandidateArtifacts(context, distribution);
if (candidateArtifacts.size() == 0) {
packager.setActive(Active.NEVER);
packager.disable();
return;
}
// check specs for active status
for (DockerSpec spec : packager.getSpecs().values()) {
if (!spec.isActiveSet() && packager.isActiveSet()) {
spec.setActive(packager.getActive());
}
spec.resolveEnabled(context.getModel().getProject(), distribution);
}
validateTemplate(context, distribution, packager, parentPackager, errors);
validateCommitAuthor(packager, parentPackager);
Docker.DockerRepository repository = packager.getRepository();
repository.resolveEnabled(model.getProject());
if (!repository.isVersionedSubfoldersSet()) {
repository.setVersionedSubfolders(parentPackager.getRepository().isVersionedSubfolders());
}
if (isBlank(repository.getName())) {
repository.setName(project.getName() + "-docker");
}
validateTap(context, distribution, repository, parentPackager.getRepository(), "docker.repository");
mergeExtraProperties(packager, parentPackager);
validateContinueOnError(packager, parentPackager);
if (isBlank(packager.getDownloadUrl())) {
packager.setDownloadUrl(parentPackager.getDownloadUrl());
}
if (isBlank(packager.getBaseImage())) {
packager.setBaseImage(parentPackager.getBaseImage());
}
validateBaseImage(distribution, packager);
if (packager.getImageNames().isEmpty()) {
packager.setImageNames(parentPackager.getImageNames());
}
if (packager.getImageNames().isEmpty()) {
packager.addImageName("{{repoOwner}}/{{distributionName}}:{{tagName}}");
}
if (context.getModel().getProject().isSnapshot()) {
// find the 1st image that ends with :{{tagName}}
Optional<String> imageName = packager.getImageNames().stream().filter(n -> n.endsWith(":{{tagName}}") || n.endsWith(":{{ tagName }}")).findFirst();
packager.setImageNames(singleton(imageName.orElse("{{repoOwner}}/{{distributionName}}:{{tagName}}")));
}
validateCommands(packager, parentPackager);
Map<String, String> labels = new LinkedHashMap<>();
labels.putAll(parentPackager.getLabels());
labels.putAll(packager.getLabels());
packager.setLabels(labels);
if (!packager.getLabels().containsKey(LABEL_OCI_IMAGE_TITLE)) {
packager.getLabels().put(LABEL_OCI_IMAGE_TITLE, "{{distributionName}}");
}
validateLabels(packager);
validateArtifactPlatforms(context, distribution, packager, candidateArtifacts, errors);
validateRegistries(context, packager, parentPackager, errors, element);
if (!packager.isUseLocalArtifactSet() && parentPackager.isUseLocalArtifactSet()) {
packager.setUseLocalArtifact(parentPackager.isUseLocalArtifact());
}
if (distribution.getType() == Distribution.DistributionType.SINGLE_JAR) {
packager.setUseLocalArtifact(true);
}
for (Map.Entry<String, DockerSpec> e : packager.getSpecs().entrySet()) {
DockerSpec spec = e.getValue();
if (isBlank(spec.getName())) {
spec.setName(e.getKey());
}
validateDockerSpec(context, distribution, spec, packager, errors);
}
}
use of org.jreleaser.model.Distribution in project jreleaser by jreleaser.
the class DistributionsValidator method validateDistribution.
private static void validateDistribution(JReleaserContext context, Distribution distribution, Errors errors) {
context.getLogger().debug("distribution.{}", distribution.getName());
if (!distribution.isActiveSet()) {
distribution.setActive(Active.ALWAYS);
}
if (!distribution.resolveEnabled(context.getModel().getProject()))
return;
if (!selectArtifactsByPlatform(context, distribution)) {
distribution.setActive(Active.NEVER);
distribution.disable();
return;
}
if (isBlank(distribution.getName())) {
errors.configuration(RB.$("validation_must_not_be_blank", "distribution.name"));
return;
}
if (null == distribution.getType()) {
errors.configuration(RB.$("validation_must_not_be_null", "distribution." + distribution.getName() + ".type"));
return;
}
if (isBlank(distribution.getExecutable().getName())) {
distribution.getExecutable().setName(distribution.getName());
}
if (isBlank(distribution.getExecutable().getWindowsExtension())) {
switch(distribution.getType()) {
case BINARY:
case NATIVE_IMAGE:
distribution.getExecutable().setWindowsExtension("exe");
break;
default:
distribution.getExecutable().setWindowsExtension("bat");
}
}
if (Distribution.JAVA_DISTRIBUTION_TYPES.contains(distribution.getType())) {
context.getLogger().debug("distribution.{}.java", distribution.getName());
if (!validateJava(context, distribution, errors)) {
return;
}
}
// validate distribution type
if (!distribution.getJava().isEnabled() && Distribution.JAVA_DISTRIBUTION_TYPES.contains(distribution.getType())) {
errors.configuration(RB.$("validation_distributions_java", "distribution." + distribution.getName() + ".type", distribution.getType(), "distribution." + distribution.getName() + ".java", "project.java"));
return;
}
if (null == distribution.getArtifacts() || distribution.getArtifacts().isEmpty()) {
errors.configuration(RB.$("validation_is_empty", "distribution." + distribution.getName() + ".artifacts"));
return;
}
List<String> tags = new ArrayList<>();
tags.addAll(context.getModel().getProject().getTags());
tags.addAll(distribution.getTags());
distribution.setTags(tags);
int i = 0;
for (Artifact artifact : distribution.getArtifacts()) {
if (artifact.isActive()) {
validateArtifact(context, distribution, artifact, i++, errors);
if (distribution.getExtraProperties().containsKey(KEY_SKIP_RELEASE_SIGNATURES) && !artifact.getExtraProperties().containsKey(KEY_SKIP_RELEASE_SIGNATURES)) {
artifact.getExtraProperties().put(KEY_SKIP_RELEASE_SIGNATURES, distribution.getExtraProperties().get(KEY_SKIP_RELEASE_SIGNATURES));
}
}
}
// validate artifact.platform is unique
Map<String, List<Artifact>> byPlatform = distribution.getArtifacts().stream().filter(Artifact::isActive).collect(groupingBy(artifact -> isBlank(artifact.getPlatform()) ? "<nil>" : artifact.getPlatform()));
// check platforms by extension
byPlatform.forEach((p, artifacts) -> {
String platform = "<nil>".equals(p) ? "no" : p;
artifacts.stream().collect(groupingBy(artifact -> FileType.getFileType(artifact.getPath()))).forEach((ext, matches) -> {
if (matches.size() > 1) {
errors.configuration(RB.$("validation_distributions_multiple", "distribution." + distribution.getName(), platform, ext));
}
});
});
validateBrew(context, distribution, distribution.getBrew(), errors);
validateChocolatey(context, distribution, distribution.getChocolatey(), errors);
validateDocker(context, distribution, distribution.getDocker(), errors);
validateGofish(context, distribution, distribution.getGofish(), errors);
validateJbang(context, distribution, distribution.getJbang(), errors);
validateMacports(context, distribution, distribution.getMacports(), errors);
validateScoop(context, distribution, distribution.getScoop(), errors);
validateSdkman(context, distribution, distribution.getSdkman(), errors);
validateSnap(context, distribution, distribution.getSnap(), errors);
validateSpec(context, distribution, distribution.getSpec(), errors);
}
use of org.jreleaser.model.Distribution in project jreleaser by jreleaser.
the class DistributionsValidator method postValidateDistributions.
public static void postValidateDistributions(JReleaserContext context, JReleaserContext.Mode mode, Errors errors) {
if (!mode.validateConfig()) {
return;
}
context.getLogger().debug("distributions");
Map<String, Distribution> distributions = context.getModel().getDistributions();
for (Map.Entry<String, Distribution> e : distributions.entrySet()) {
Distribution distribution = e.getValue();
if (distribution.isEnabled()) {
postValidateDistribution(context, distribution, errors);
}
}
}
Aggregations