use of org.jreleaser.model.assembler.spi.AssemblerProcessingException in project jreleaser by jreleaser.
the class NativeImageAssemblerProcessor method upx.
private void upx(Path image) throws AssemblerProcessingException {
Upx upx = new Upx(context, assembler.getUpx().getVersion());
try {
if (!upx.setup()) {
context.getLogger().warn(RB.$("tool_unavailable", "upx"));
return;
}
} catch (ToolException e) {
throw new AssemblerProcessingException(e.getMessage(), e);
}
List<String> args = new ArrayList<>(assembler.getUpx().getArgs());
args.add(image.getFileName().toString());
context.getLogger().info("upx {}", image.getFileName().toString());
try {
upx.compress(image.getParent(), args);
} catch (CommandException e) {
throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error"), e);
}
}
use of org.jreleaser.model.assembler.spi.AssemblerProcessingException in project jreleaser by jreleaser.
the class NativeImageAssemblerProcessor method nativeImage.
private Artifact nativeImage(Path assembleDirectory, Path graalPath, Set<Path> jars, String imageName) throws AssemblerProcessingException {
String platform = assembler.getGraal().getPlatform();
String platformReplaced = assembler.getPlatform().applyReplacements(platform);
String finalImageName = imageName + "-" + platformReplaced;
String executable = assembler.getExecutable();
if (PlatformUtils.isWindows()) {
executable += ".exe";
}
context.getLogger().info("- {}", finalImageName);
Path image = assembleDirectory.resolve(executable).toAbsolutePath();
try {
if (Files.exists(image)) {
Files.deleteIfExists(image);
}
} catch (IOException e) {
throw new AssemblerProcessingException(RB.$("ERROR_assembler_delete_image", executable), e);
}
assembler.getArgs().stream().filter(arg -> arg.startsWith("-H:Name")).findFirst().ifPresent(assembler.getArgs()::remove);
Path nativeImageExecutable = graalPath.resolve("bin").resolve(PlatformUtils.isWindows() ? "native-image.cmd" : "native-image").toAbsolutePath();
Command cmd = new Command(nativeImageExecutable.toString(), true).args(assembler.getArgs());
NativeImage.PlatformCustomizer customizer = assembler.getResolvedPlatformCustomizer();
cmd.args(customizer.getArgs());
cmd.arg("-jar").arg(maybeQuote(assembler.getMainJar().getEffectivePath(context, assembler).toAbsolutePath().toString()));
if (!jars.isEmpty()) {
cmd.arg("-cp").arg(jars.stream().map(Path::toAbsolutePath).map(Path::toString).map(this::maybeQuote).collect(Collectors.joining(File.pathSeparator)));
}
cmd.arg("-H:Name=" + assembler.getExecutable());
context.getLogger().debug(String.join(" ", cmd.getArgs()));
executeCommand(image.getParent(), cmd);
if (assembler.getUpx().isEnabled()) {
upx(image);
}
try {
Path tempDirectory = Files.createTempDirectory("jreleaser");
Path distDirectory = tempDirectory.resolve(finalImageName);
Files.createDirectories(distDirectory);
Path binDirectory = distDirectory.resolve("bin");
Files.createDirectories(binDirectory);
Files.copy(image, binDirectory.resolve(image.getFileName()));
FileUtils.copyFiles(context.getLogger(), context.getBasedir(), distDirectory, path -> path.getFileName().startsWith("LICENSE"));
copyFiles(context, distDirectory);
copyFileSets(context, distDirectory);
Path imageArchive = assembleDirectory.resolve(finalImageName + "." + assembler.getArchiveFormat().extension());
switch(assembler.getArchiveFormat()) {
case ZIP:
FileUtils.zip(tempDirectory, imageArchive);
break;
case TAR:
FileUtils.tar(tempDirectory, imageArchive);
break;
case TGZ:
case TAR_GZ:
FileUtils.tgz(tempDirectory, imageArchive);
break;
case TXZ:
case TAR_XZ:
FileUtils.xz(tempDirectory, imageArchive);
break;
case TBZ2:
case TAR_BZ2:
FileUtils.bz2(tempDirectory, imageArchive);
}
context.getLogger().debug("- {}", imageArchive.getFileName());
return Artifact.of(imageArchive, platform);
} catch (IOException e) {
throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error"), e);
}
}
use of org.jreleaser.model.assembler.spi.AssemblerProcessingException in project jreleaser by jreleaser.
the class AbstractAssemblerProcessor method writeFile.
protected void writeFile(byte[] content, Path outputFile) throws AssemblerProcessingException {
try {
createDirectoriesWithFullAccess(outputFile.getParent());
Files.write(outputFile, content, CREATE, WRITE, TRUNCATE_EXISTING);
grantFullAccess(outputFile);
} catch (IOException e) {
throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error_writing_file", outputFile.toAbsolutePath()), e);
}
}
Aggregations