use of org.jreleaser.model.Artifact 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.Artifact in project jreleaser by jreleaser.
the class SdkmanHelper method collectArtifacts.
public static void collectArtifacts(JReleaserContext context, Distribution distribution, Map<String, String> platforms) {
for (Artifact artifact : distribution.getArtifacts()) {
if (!artifact.isActive())
continue;
// only zips are supported
if (!artifact.getPath().endsWith(ZIP.extension())) {
context.getLogger().debug(RB.$("sdkman.no.artifacts.match"), artifact.getEffectivePath(context, distribution).getFileName());
continue;
}
if (isTrue(artifact.getExtraProperties().get(Sdkman.SKIP_SDKMAN))) {
context.getLogger().debug(RB.$("sdkman.artifact.explicit.skip"), artifact.getEffectivePath(context, distribution).getFileName());
continue;
}
String platform = mapPlatform(artifact.getPlatform());
if (isBlank(platform)) {
context.getLogger().warn(RB.$("sdkman.platform.unsupported"), artifact.getPlatform());
continue;
}
String url = artifactUrl(context, distribution, artifact);
if (platforms.containsKey(platform)) {
context.getLogger().warn(RB.$("sdkman.platform.replacement"), platform, url, platforms.get(platform));
}
platforms.put(platform, url);
}
}
use of org.jreleaser.model.Artifact in project jreleaser by jreleaser.
the class ArchiveResolver method resolveArchiveOutputs.
private static void resolveArchiveOutputs(JReleaserContext context, Archive archive, Errors errors) {
if (archive.isAttachPlatform() && !context.isPlatformSelected(PlatformUtils.getCurrentFull()))
return;
Path baseOutputDirectory = context.getAssembleDirectory().resolve(archive.getName()).resolve(archive.getType());
String archiveName = archive.getResolvedArchiveName(context);
for (Archive.Format format : archive.getFormats()) {
Path path = baseOutputDirectory.resolve(archiveName + "." + format.extension()).toAbsolutePath();
if (!Files.exists(path)) {
errors.assembly(RB.$("validation_missing_assembly", archive.getType(), archive.getName(), archive.getName()));
} else {
Artifact artifact = Artifact.of(path, archive.isAttachPlatform() ? PlatformUtils.getCurrentFull() : "");
artifact.setExtraProperties(archive.getExtraProperties());
artifact.activate();
archive.addOutput(artifact);
}
}
}
use of org.jreleaser.model.Artifact in project jreleaser by jreleaser.
the class BrewValidator method validateBrew.
public static void validateBrew(JReleaserContext context, Distribution distribution, Brew packager, Errors errors) {
JReleaserModel model = context.getModel();
Brew parentPackager = model.getPackagers().getBrew();
if (!packager.isActiveSet() && parentPackager.isActiveSet()) {
packager.setActive(parentPackager.getActive());
}
if (!packager.resolveEnabled(context.getModel().getProject(), distribution)) {
packager.disable();
packager.getCask().disable();
return;
}
GitService service = model.getRelease().getGitService();
if (!service.isReleaseSupported()) {
packager.disable();
packager.getCask().disable();
return;
}
context.getLogger().debug("distribution.{}.brew", distribution.getName());
Brew.Cask cask = preValidateCask(distribution, packager, parentPackager);
if (!packager.isMultiPlatformSet() && parentPackager.isMultiPlatformSet()) {
packager.setMultiPlatform(parentPackager.isMultiPlatform());
}
if (packager.isMultiPlatform() && (distribution.getType() == Distribution.DistributionType.SINGLE_JAR || distribution.getType() == Distribution.DistributionType.JAVA_BINARY || distribution.getType() == Distribution.DistributionType.NATIVE_PACKAGE)) {
packager.setMultiPlatform(false);
}
if (packager.isMultiPlatform()) {
packager.getCask().disable();
}
validateCask(context, distribution, packager, cask, errors);
List<Artifact> candidateArtifacts = packager.resolveCandidateArtifacts(context, distribution);
if (candidateArtifacts.size() == 0) {
packager.setActive(Active.NEVER);
packager.disable();
return;
}
validateCommitAuthor(packager, parentPackager);
Brew.HomebrewTap tap = packager.getTap();
tap.resolveEnabled(model.getProject());
validateTap(context, distribution, tap, parentPackager.getTap(), "brew.tap");
validateTemplate(context, distribution, packager, parentPackager, errors);
mergeExtraProperties(packager, parentPackager);
validateContinueOnError(packager, parentPackager);
if (isBlank(packager.getDownloadUrl())) {
packager.setDownloadUrl(parentPackager.getDownloadUrl());
}
List<Brew.Dependency> dependencies = new ArrayList<>(parentPackager.getDependenciesAsList());
dependencies.addAll(packager.getDependenciesAsList());
packager.setDependenciesAsList(dependencies);
if (isBlank(packager.getFormulaName())) {
packager.setFormulaName(distribution.getName());
}
if (!cask.isEnabled()) {
validateArtifactPlatforms(context, distribution, packager, candidateArtifacts, errors);
}
}
use of org.jreleaser.model.Artifact in project jreleaser by jreleaser.
the class BrewValidator method validateCask.
private static void validateCask(JReleaserContext context, Distribution distribution, Brew packager, Brew.Cask cask, Errors errors) {
if (cask == null || (cask.isEnabledSet() && !cask.isEnabled())) {
return;
}
context.getLogger().debug("distribution.{}.brew.cask", distribution.getName());
// look for a .dmg, .pkg. or .zip
int dmgFound = 0;
int pkgFound = 0;
int zipFound = 0;
String pkgName = "";
for (Artifact artifact : distribution.getArtifacts()) {
if (!artifact.isActive() || !PlatformUtils.isMac(artifact.getPlatform()))
continue;
if (artifact.getPath().endsWith(".dmg") && !isTrue(artifact.getExtraProperties().get(SKIP_BREW))) {
dmgFound++;
} else if (artifact.getPath().endsWith(".pkg") && !isTrue(artifact.getExtraProperties().get(SKIP_BREW))) {
pkgFound++;
pkgName = artifact.getEffectivePath(context).getFileName().toString();
} else if (artifact.getPath().endsWith(".zip") && !isTrue(artifact.getExtraProperties().get(SKIP_BREW))) {
zipFound++;
}
}
if (dmgFound == 0 && pkgFound == 0 && zipFound == 0) {
// no artifacts found, disable cask
cask.disable();
return;
} else if (dmgFound > 1) {
errors.configuration(RB.$("validation_brew_multiple_artifact", "distribution." + distribution.getName() + ".brew", ".dmg"));
cask.disable();
return;
} else if (pkgFound > 1) {
errors.configuration(RB.$("validation_brew_multiple_artifact", "distribution." + distribution.getName() + ".brew", ".pkg"));
cask.disable();
return;
} else if (zipFound > 1) {
errors.configuration(RB.$("validation_brew_multiple_artifact", "distribution." + distribution.getName() + ".brew", ".zip"));
cask.disable();
return;
} else if (dmgFound + pkgFound + zipFound > 1) {
errors.configuration(RB.$("validation_brew_single_artifact", "distribution." + distribution.getName() + ".brew"));
cask.disable();
return;
}
if (zipFound == 1 && !cask.isEnabled()) {
// https://github.com/jreleaser/jreleaser/issues/337
return;
}
cask.enable();
if (isBlank(cask.getPkgName()) && isNotBlank(pkgName)) {
cask.setPkgName(pkgName);
}
if (isNotBlank(cask.getPkgName())) {
if (!cask.getPkgName().endsWith(".pkg")) {
cask.setPkgName(cask.getPkgName() + ".pkg");
}
} else if (isBlank(cask.getAppName())) {
cask.setAppName(packager.getResolvedFormulaName(context) + ".app");
} else if (!cask.getAppName().endsWith(".app")) {
cask.setAppName(cask.getAppName() + ".app");
}
if (zipFound > 0) {
cask.setAppName("");
cask.setPkgName("");
}
if (isBlank(cask.getName())) {
cask.setName(packager.getResolvedFormulaName(context).toLowerCase());
}
if (isBlank(cask.getDisplayName())) {
cask.setDisplayName(packager.getResolvedFormulaName(context));
}
}
Aggregations