use of org.jreleaser.model.Jlink in project jreleaser by jreleaser.
the class JpackageValidator method validateJpackage.
private static void validateJpackage(JReleaserContext context, JReleaserContext.Mode mode, Jpackage jpackage, Errors errors) {
context.getLogger().debug("jpackage.{}", jpackage.getName());
if (!jpackage.isActiveSet()) {
jpackage.setActive(Active.NEVER);
}
Project project = context.getModel().getProject();
if (!jpackage.resolveEnabled(project))
return;
Jpackage.PlatformPackager packager = jpackage.getResolvedPlatformPackager();
Jpackage.ApplicationPackage applicationPackage = jpackage.getApplicationPackage();
packager.enable();
if (isNotBlank(jpackage.getJlink())) {
Jlink jlink = context.getModel().getAssemble().findJlink(jpackage.getJlink());
Path baseOutputDirectory = context.getAssembleDirectory().resolve(jlink.getName()).resolve(jlink.getType());
String imageName = jlink.getResolvedImageName(context);
List<Artifact> candidateRuntimeImages = new ArrayList<>();
for (Artifact targetJdk : jlink.getTargetJdks()) {
if (!context.isPlatformSelected(targetJdk))
continue;
String platform = targetJdk.getPlatform();
Path path = baseOutputDirectory.resolve("work-" + platform).resolve(imageName + "-" + platform).toAbsolutePath();
candidateRuntimeImages.add(Artifact.of(path, platform));
}
if (jpackage.getRuntimeImages().size() > 0 && jpackage.getRuntimeImages().size() != candidateRuntimeImages.size()) {
errors.configuration(RB.$("validation_jpackage_jlink_application", jpackage.getName()));
}
int count = 0;
for (Artifact runtimeImage : jpackage.getRuntimeImages()) {
Path rp = runtimeImage.getResolvedPath(context, jpackage);
Path tp = runtimeImage.getResolvedTransform(context, jpackage);
Path path = tp != null ? tp : rp;
if (candidateRuntimeImages.stream().anyMatch(a -> a.getPath().equals(path.toString()))) {
count++;
}
}
if (jpackage.getRuntimeImages().size() > 0 && count != candidateRuntimeImages.size()) {
errors.configuration(RB.$("validation_jpackage_jlink_application", jpackage.getName()));
}
jpackage.setJava(jlink.getJava());
jpackage.setMainJar(jlink.getMainJar());
jpackage.setJars(jlink.getJars());
packager.setJdk(jlink.getJdk());
if (isBlank(jpackage.getExecutable())) {
jpackage.setExecutable(jlink.getExecutable());
}
for (Artifact runtimeImage : candidateRuntimeImages) {
runtimeImage.activate();
jpackage.addRuntimeImage(runtimeImage);
}
}
context.getLogger().debug("jpackage.{}.java", jpackage.getName());
if (!validateJava(context, jpackage, errors)) {
return;
}
if (isBlank(jpackage.getExecutable())) {
jpackage.setExecutable(jpackage.getName());
}
if (jpackage.getRuntimeImages().size() == 0) {
errors.configuration(RB.$("validation_jpackage_runtime_images_missing", jpackage.getName()));
return;
}
int i = 0;
for (Artifact runtimeImage : jpackage.getRuntimeImages()) {
validateRuntimeImage(context, mode, jpackage, runtimeImage, i++, errors);
}
// validate jdks.platform is unique
Map<String, List<Artifact>> byPlatform = jpackage.getRuntimeImages().stream().collect(groupingBy(ri -> isBlank(ri.getPlatform()) ? "<nil>" : ri.getPlatform()));
if (byPlatform.containsKey("<nil>")) {
errors.configuration(RB.$("validation_jpackage_runtime_image_platform", jpackage.getName()));
}
// check platforms
byPlatform.forEach((p, jdks) -> {
if (jdks.size() > 1) {
errors.configuration(RB.$("validation_jpackage_runtime_image_multiple_platforms", jpackage.getName(), p));
}
});
if (isBlank(packager.getJdk().getPath())) {
String javaHome = System.getProperty("java.home");
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;
}
packager.getJdk().setPath(javaHome);
packager.getJdk().setPlatform(PlatformUtils.getCurrentFull());
}
if (packager.getTypes().isEmpty()) {
packager.setTypes(singletonList(packager.getValidTypes().get(0)));
}
if (isBlank(applicationPackage.getAppName())) {
applicationPackage.setAppName(jpackage.getName());
}
if (isBlank(applicationPackage.getAppVersion())) {
applicationPackage.setAppVersion(project.getResolvedVersion());
}
// validate appVersion
String appVersion = applicationPackage.getResolvedAppVersion(context, jpackage);
try {
SemVer v = SemVer.of(appVersion);
if (isNotBlank(v.getBuild()) && isNotBlank(v.getTag()) && v.getMajor() <= 0) {
errors.configuration(RB.$("validation_jpackage_invalid_appversion", appVersion));
}
} catch (IllegalArgumentException e) {
// can't use this value
errors.configuration(RB.$("validation_jpackage_invalid_appversion", appVersion));
}
if (isBlank(applicationPackage.getVendor())) {
applicationPackage.setVendor(project.getVendor());
}
if (isBlank(applicationPackage.getVendor())) {
errors.configuration(RB.$("validation_jpackage_missing_vendor", jpackage.getName()));
}
if (isBlank(applicationPackage.getCopyright())) {
applicationPackage.setCopyright(project.getCopyright());
}
if (mode == JReleaserContext.Mode.ASSEMBLE) {
validateTemplate(context, jpackage, errors);
}
if (isBlank(packager.getAppName())) {
packager.setAppName(jpackage.getApplicationPackage().getAppName());
}
if (packager instanceof Jpackage.Linux) {
validateLinux(context, jpackage, (Jpackage.Linux) packager, errors);
}
if (packager instanceof Jpackage.Osx) {
validateOsx(context, jpackage, (Jpackage.Osx) packager, errors);
}
if (packager instanceof Jpackage.Windows) {
validateWindows(context, jpackage, (Jpackage.Windows) packager, errors);
}
}
use of org.jreleaser.model.Jlink 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);
}
}
}
use of org.jreleaser.model.Jlink in project jreleaser by jreleaser.
the class AssemblersValidator method validateAssemblers.
public static void validateAssemblers(JReleaserContext context, JReleaserContext.Mode mode, Errors errors) {
if (mode == JReleaserContext.Mode.CHANGELOG) {
return;
}
context.getLogger().debug("assemble");
Assemble assemble = context.getModel().getAssemble();
validateArchive(context, mode, errors);
validateJlink(context, mode, errors);
validateJpackage(context, mode, errors);
validateNativeImage(context, mode, errors);
// validate unique distribution names between exported assemblers
Map<String, List<String>> byDistributionName = new LinkedHashMap<>();
for (Archive archive : assemble.getActiveArchives()) {
List<String> types = byDistributionName.computeIfAbsent(archive.getName(), k -> new ArrayList<>());
types.add(archive.getType());
}
for (Jlink jlink : assemble.getActiveJlinks()) {
List<String> types = byDistributionName.computeIfAbsent(jlink.getName(), k -> new ArrayList<>());
if (jlink.isExported())
types.add(jlink.getType());
}
for (Jpackage jpackage : assemble.getActiveJpackages()) {
List<String> types = byDistributionName.computeIfAbsent(jpackage.getName(), k -> new ArrayList<>());
if (jpackage.isExported())
types.add(jpackage.getType());
}
for (NativeImage nativeImage : assemble.getActiveNativeImages()) {
List<String> types = byDistributionName.computeIfAbsent(nativeImage.getName(), k -> new ArrayList<>());
if (nativeImage.isExported())
types.add(nativeImage.getType());
}
byDistributionName.forEach((name, types) -> {
if (types.size() > 1) {
errors.configuration(RB.$("validation_multiple_assemblers", "distribution." + name, types));
assemble.setEnabled(false);
}
});
if (!assemble.isEnabledSet()) {
assemble.setEnabled(!assemble.getActiveArchives().isEmpty() || !assemble.getActiveJlinks().isEmpty() || !assemble.getActiveJpackages().isEmpty() || !assemble.getActiveNativeImages().isEmpty());
}
}
Aggregations