use of org.jreleaser.model.Platform in project jreleaser by jreleaser.
the class ArchiveValidator method validateArchive.
private static void validateArchive(JReleaserContext context, JReleaserContext.Mode mode, Archive archive, Errors errors) {
context.getLogger().debug("archive.{}", archive.getName());
if (!archive.isActiveSet()) {
archive.setActive(Active.NEVER);
}
if (!archive.resolveEnabled(context.getModel().getProject()))
return;
if (isBlank(archive.getName())) {
errors.configuration(RB.$("validation_must_not_be_blank", "archive.name"));
return;
}
Platform platform = archive.getPlatform().merge(context.getModel().getPlatform());
archive.setPlatform(platform);
if (null == archive.getDistributionType()) {
archive.setDistributionType(Distribution.DistributionType.BINARY);
}
if (isBlank(archive.getArchiveName())) {
archive.setArchiveName("{{distributionName}}-{{projectVersion}}");
}
if (archive.getFormats().isEmpty()) {
archive.addFormat(Archive.Format.ZIP);
}
if (archive.getFileSets().isEmpty()) {
errors.configuration(RB.$("validation_archive_empty_fileset", archive.getName()));
} else {
int i = 0;
for (FileSet fileSet : archive.getFileSets()) {
validateFileSet(context, mode, archive, fileSet, i++, errors);
}
}
}
use of org.jreleaser.model.Platform in project jreleaser by jreleaser.
the class NativeImageValidator method validateNativeImage.
private static void validateNativeImage(JReleaserContext context, JReleaserContext.Mode mode, NativeImage nativeImage, Errors errors) {
context.getLogger().debug("nativeImage.{}", nativeImage.getName());
if (!nativeImage.isActiveSet()) {
nativeImage.setActive(Active.NEVER);
}
if (!nativeImage.resolveEnabled(context.getModel().getProject()))
return;
if (isBlank(nativeImage.getName())) {
errors.configuration(RB.$("validation_must_not_be_blank", "nativeImage.name"));
return;
}
if (null == nativeImage.getMainJar()) {
errors.configuration(RB.$("validation_is_null", "nativeImage." + nativeImage.getName() + ".mainJar"));
return;
}
Platform platform = nativeImage.getPlatform().merge(context.getModel().getPlatform());
nativeImage.setPlatform(platform);
if (isBlank(nativeImage.getExecutable())) {
nativeImage.setExecutable(nativeImage.getName());
}
if (isBlank(nativeImage.getImageName())) {
nativeImage.setImageName(nativeImage.getExecutable() + "-" + context.getModel().getProject().getResolvedVersion());
}
int i = 0;
for (Artifact graalJdk : nativeImage.getGraalJdks()) {
validateJdk(context, mode, nativeImage, graalJdk, i++, errors);
}
// validate jdks.platform is unique
Map<String, List<Artifact>> byPlatform = nativeImage.getGraalJdks().stream().collect(groupingBy(jdk -> isBlank(jdk.getPlatform()) ? "<nil>" : jdk.getPlatform()));
if (byPlatform.containsKey("<nil>")) {
errors.configuration(RB.$("validation_nativeimage_jdk_platform", nativeImage.getName()));
}
// check platforms
byPlatform.forEach((p, jdks) -> {
if (jdks.size() > 1) {
errors.configuration(RB.$("validation_nativeimage_jdk_multiple_platforms", nativeImage.getName(), p));
}
});
if (isBlank(nativeImage.getGraal().getPath())) {
String currentPlatform = PlatformUtils.getCurrentFull();
String javaHome = System.getProperty("java.home");
if (nativeImage.getGraalJdks().isEmpty()) {
if (isBlank(javaHome)) {
// Can only happen when running as native-image, fail for now
// TODO: native-image
errors.configuration(RB.$("validation_java_home_missing"));
return;
}
// Use current
nativeImage.getGraal().setPath(javaHome);
nativeImage.getGraal().setPlatform(currentPlatform);
} else {
// find a compatible JDK in targets
Optional<Artifact> jdk = nativeImage.getGraalJdks().stream().filter(j -> PlatformUtils.isCompatible(currentPlatform, j.getPlatform())).findFirst();
if (jdk.isPresent()) {
nativeImage.setGraal(jdk.get());
} else {
if (isBlank(javaHome)) {
// Can only happen when running as native-image, fail for now
// TODO: native-image
errors.configuration(RB.$("validation_java_home_missing"));
return;
}
// Can't tell if the current JDK will work but might as well use it
nativeImage.getGraal().setPath(javaHome);
nativeImage.getGraal().setPlatform(currentPlatform);
}
}
}
if (isBlank(nativeImage.getMainJar().getPath())) {
errors.configuration(RB.$("validation_must_not_be_null", "nativeImage." + nativeImage.getName() + ".mainJar.path"));
}
if (null == nativeImage.getArchiveFormat()) {
nativeImage.setArchiveFormat(Archive.Format.ZIP);
}
validateGlobs(context, nativeImage.getJars(), "nativeImage." + nativeImage.getName() + ".jars", errors);
if (mode == JReleaserContext.Mode.ASSEMBLE) {
validateTemplate(context, nativeImage, errors);
}
if (!nativeImage.getFileSets().isEmpty()) {
i = 0;
for (FileSet fileSet : nativeImage.getFileSets()) {
validateFileSet(context, mode, nativeImage, fileSet, i++, errors);
}
}
NativeImage.Upx upx = nativeImage.getUpx();
if (!upx.isActiveSet()) {
upx.setActive(Active.NEVER);
}
if (!upx.resolveEnabled(context.getModel().getProject()))
return;
if (isBlank(upx.getVersion())) {
errors.configuration(RB.$("validation_is_missing", "nativeImage." + nativeImage.getName() + ".upx.version"));
}
}
use of org.jreleaser.model.Platform in project jreleaser by jreleaser.
the class JlinkValidator method validateJlink.
private static void validateJlink(JReleaserContext context, JReleaserContext.Mode mode, Jlink jlink, Errors errors) {
context.getLogger().debug("jlink.{}", jlink.getName());
if (!jlink.isActiveSet()) {
jlink.setActive(Active.NEVER);
}
if (!jlink.resolveEnabled(context.getModel().getProject()))
return;
if (isBlank(jlink.getName())) {
errors.configuration(RB.$("validation_must_not_be_blank", "jlink.name"));
return;
}
context.getLogger().debug("jlink.{}.java", jlink.getName());
if (!validateJava(context, jlink, errors)) {
return;
}
Platform platform = jlink.getPlatform().merge(context.getModel().getPlatform());
jlink.setPlatform(platform);
if (isBlank(jlink.getImageName())) {
jlink.setImageName(jlink.getJava().getGroupId() + "." + jlink.getJava().getArtifactId() + "-" + context.getModel().getProject().getResolvedVersion());
}
if (isBlank(jlink.getExecutable())) {
jlink.setExecutable(jlink.getName());
}
int i = 0;
for (Artifact targetJdk : jlink.getTargetJdks()) {
validateJdk(context, mode, jlink, targetJdk, i++, errors);
}
// validate jdks.platform is unique
Map<String, List<Artifact>> byPlatform = jlink.getTargetJdks().stream().collect(groupingBy(jdk -> isBlank(jdk.getPlatform()) ? "<nil>" : jdk.getPlatform()));
if (byPlatform.containsKey("<nil>")) {
errors.configuration(RB.$("validation_jlink_jdk_platform", jlink.getName()));
}
// check platforms
byPlatform.forEach((p, jdks) -> {
if (jdks.size() > 1) {
errors.configuration(RB.$("validation_jlink_jdk_multiple_platforms", jlink.getName(), p));
}
});
if (isBlank(jlink.getJdk().getPath())) {
String currentPlatform = PlatformUtils.getCurrentFull();
String javaHome = System.getProperty("java.home");
if (jlink.getTargetJdks().isEmpty()) {
if (isBlank(javaHome)) {
// Can only happen when running as native-image, fail for now
// TODO: native-image
errors.configuration(RB.$("validation_java_home_missing"));
return;
}
// Use current
jlink.getJdk().setPath(javaHome);
jlink.getJdk().setPlatform(currentPlatform);
jlink.addTargetJdk(jlink.getJdk());
} else {
// find a compatible JDK in targets
Optional<Artifact> jdk = jlink.getTargetJdks().stream().filter(j -> PlatformUtils.isCompatible(currentPlatform, j.getPlatform())).findFirst();
if (jdk.isPresent()) {
jlink.setJdk(jdk.get());
} else {
if (isBlank(javaHome)) {
// Can only happen when running as native-image, fail for now
// TODO: native-image
errors.configuration(RB.$("validation_java_home_missing"));
return;
}
// Can't tell if the current JDK will work but might as well use it
jlink.getJdk().setPath(javaHome);
jlink.getJdk().setPlatform(currentPlatform);
}
}
}
if (jlink.getArgs().isEmpty()) {
jlink.getArgs().add("--no-header-files");
jlink.getArgs().add("--no-man-pages");
jlink.getArgs().add("--compress=2");
jlink.getArgs().add("--strip-debug");
}
if (null == jlink.getMainJar()) {
errors.configuration(RB.$("validation_is_null", "jlink." + jlink.getName() + ".mainJar"));
return;
}
if (isBlank(jlink.getMainJar().getPath())) {
errors.configuration(RB.$("validation_must_not_be_null", "jlink." + jlink.getName() + ".mainJar.path"));
}
validateGlobs(context, jlink.getJars(), "jlink." + jlink.getName() + ".jars", errors);
if (mode == JReleaserContext.Mode.ASSEMBLE) {
validateTemplate(context, jlink, errors);
}
if (!jlink.getFileSets().isEmpty()) {
i = 0;
for (FileSet fileSet : jlink.getFileSets()) {
validateFileSet(context, mode, jlink, fileSet, i++, errors);
}
}
}
Aggregations