use of org.jreleaser.util.command.Command in project jreleaser by jreleaser.
the class ChocolateyPackagerProcessor method publishChocolateyPackage.
private void publishChocolateyPackage(Distribution distribution, Map<String, Object> props) throws PackagerProcessingException {
Path packageDirectory = (Path) props.get(KEY_DISTRIBUTION_PACKAGE_DIRECTORY);
Path execDirectory = packageDirectory.resolve(distribution.getName());
Command cmd = new Command("choco").arg("apikey").arg("-k").arg(packager.getResolvedApiKey()).arg("-source").arg(packager.getSource());
executeCommand(execDirectory, cmd);
try {
Optional<String> nuget = listFilesAndProcess(execDirectory, files -> files.map(Path::getFileName).map(Path::toString).filter(s -> s.endsWith(".nupkg")).findFirst());
if (nuget.isPresent()) {
cmd = new Command("choco").arg("push").arg(nuget.get()).arg("-s").arg(packager.getSource());
context.getLogger().debug(String.join(" ", cmd.getArgs()));
executeCommand(execDirectory, cmd);
} else {
throw new PackagerProcessingException(RB.$("ERROR_chocolatey_nuget_not_found", context.relativizeToBasedir(execDirectory)));
}
} catch (IOException e) {
throw new PackagerProcessingException(RB.$("ERROR_unexpected_error"), e);
}
}
use of org.jreleaser.util.command.Command in project jreleaser by jreleaser.
the class DockerPackagerProcessor method login.
private void login(Registry registry) throws PackagerProcessingException {
Command cmd = createCommand("login");
if (isNotBlank(registry.getServer())) {
cmd.arg(registry.getServer());
}
cmd.arg("-u");
cmd.arg(registry.getResolvedUsername());
cmd.arg("-p");
cmd.arg(registry.getResolvedPassword());
ByteArrayInputStream in = new ByteArrayInputStream((registry.getResolvedPassword() + System.lineSeparator()).getBytes());
context.getLogger().debug(RB.$("docker.login"), registry.getServerName(), (isNotBlank(registry.getServer()) ? " (" + registry.getServer() + ")" : ""));
if (!context.isDryrun())
executeCommandWithInput(cmd, in);
}
use of org.jreleaser.util.command.Command in project jreleaser by jreleaser.
the class DockerPackagerProcessor method packageDocker.
protected void packageDocker(Distribution distribution, Map<String, Object> props, Path packageDirectory, DockerConfiguration docker, List<Artifact> artifacts) throws PackagerProcessingException {
super.doPackageDistribution(distribution, props, packageDirectory);
try {
// copy files
Path workingDirectory = prepareAssembly(distribution, props, packageDirectory, artifacts);
for (String imageName : docker.getImageNames()) {
imageName = resolveTemplate(imageName, props);
// command line
Command cmd = createBuildCommand(props, docker);
if (!cmd.hasArg("-q") && !cmd.hasArg("--quiet")) {
cmd.arg("-q");
}
cmd.arg("-f");
cmd.arg(workingDirectory.resolve("Dockerfile").toAbsolutePath().toString());
cmd.arg("-t");
cmd.arg(imageName);
cmd.arg(workingDirectory.toAbsolutePath().toString());
context.getLogger().debug(String.join(" ", cmd.getArgs()));
context.getLogger().info(" - {}", imageName);
// execute
executeCommand(cmd);
}
} catch (IOException e) {
throw new PackagerProcessingException(e);
}
}
use of org.jreleaser.util.command.Command in project jreleaser by jreleaser.
the class SnapPackagerProcessor method push.
private void push(Distribution distribution, Map<String, Object> props) throws PackagerProcessingException {
Path packageDirectory = (Path) props.get(KEY_DISTRIBUTION_PACKAGE_DIRECTORY);
String version = (String) props.get(KEY_PROJECT_EFFECTIVE_VERSION);
String snapName = packager.getPackageName() + "-" + version + ".snap";
Command cmd = new Command("snapcraft").arg("push").arg(snapName);
executeCommand(packageDirectory, cmd);
}
use of org.jreleaser.util.command.Command in project jreleaser by jreleaser.
the class JlinkAssemblerProcessor method jlink.
private Artifact jlink(Path assembleDirectory, Path jdkPath, Artifact targetJdk, Set<String> moduleNames, String imageName, Archive.Format archiveFormat) throws AssemblerProcessingException {
String platform = targetJdk.getPlatform();
String platformReplaced = assembler.getPlatform().applyReplacements(platform);
String finalImageName = imageName + "-" + platformReplaced;
context.getLogger().info("- {}", finalImageName);
Path inputsDirectory = assembleDirectory.resolve("inputs");
Path jarsDirectory = inputsDirectory.resolve("jars");
Path workDirectory = assembleDirectory.resolve("work-" + platform);
Path imageDirectory = workDirectory.resolve(finalImageName).toAbsolutePath();
try {
FileUtils.deleteFiles(imageDirectory);
} catch (IOException e) {
throw new AssemblerProcessingException(RB.$("ERROR_assembler_delete_image", finalImageName), e);
}
// jlink it
String moduleName = assembler.getJava().getMainModule();
String modulePath = maybeQuote(targetJdk.getEffectivePath(context, assembler).resolve("jmods").toAbsolutePath().toString());
if (isNotBlank(moduleName) || assembler.isCopyJars()) {
modulePath += File.pathSeparator + maybeQuote(jarsDirectory.resolve("universal").toAbsolutePath().toString());
try {
Path platformJarsDirectory = jarsDirectory.resolve(platform).toAbsolutePath();
if (listFilesAndProcess(platformJarsDirectory, Stream::count) > 1) {
modulePath += File.pathSeparator + maybeQuote(platformJarsDirectory.toString());
}
} catch (IOException e) {
throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error", e));
}
}
Path jlinkExecutable = jdkPath.resolve("bin").resolve(PlatformUtils.isWindows() ? "jlink.exe" : "jlink").toAbsolutePath();
Command cmd = new Command(jlinkExecutable.toString(), true).args(assembler.getArgs()).arg("--module-path").arg(modulePath).arg("--add-modules").arg(String.join(",", moduleNames));
if (isNotBlank(moduleName)) {
cmd.arg("--launcher").arg(assembler.getExecutable() + "=" + moduleName + "/" + assembler.getJava().getMainClass());
}
cmd.arg("--output").arg(maybeQuote(imageDirectory.toString()));
context.getLogger().debug(String.join(" ", cmd.getArgs()));
ByteArrayOutputStream out = new ByteArrayOutputStream();
executeCommandCapturing(cmd, out);
if (isBlank(moduleName)) {
if (assembler.isCopyJars()) {
Path outputJarsDirectory = imageDirectory.resolve("jars");
try {
Files.createDirectory(outputJarsDirectory);
FileUtils.copyFiles(context.getLogger(), jarsDirectory.resolve("universal"), outputJarsDirectory);
FileUtils.copyFiles(context.getLogger(), jarsDirectory.resolve(platform), outputJarsDirectory);
} catch (IOException e) {
throw new AssemblerProcessingException(RB.$("ERROR_assembler_copy_jars", context.relativizeToBasedir(outputJarsDirectory)), e);
}
}
try {
if (PlatformUtils.isWindows(platform)) {
Files.copy(inputsDirectory.resolve(assembler.getExecutable().concat(".bat")), imageDirectory.resolve("bin").resolve(assembler.getExecutable().concat(".bat")));
} else {
Path launcher = imageDirectory.resolve("bin").resolve(assembler.getExecutable());
Files.copy(inputsDirectory.resolve(assembler.getExecutable()), launcher);
FileUtils.grantExecutableAccess(launcher);
}
} catch (IOException e) {
throw new AssemblerProcessingException(RB.$("ERROR_assembler_copy_launcher", context.relativizeToBasedir(imageDirectory.resolve("bin"))), e);
}
}
try {
Path imageArchive = assembleDirectory.resolve(finalImageName + "." + archiveFormat.extension());
FileUtils.copyFiles(context.getLogger(), context.getBasedir(), imageDirectory, path -> path.getFileName().startsWith("LICENSE"));
copyFiles(context, imageDirectory);
copyFileSets(context, imageDirectory);
switch(archiveFormat) {
case ZIP:
FileUtils.zip(workDirectory, imageArchive);
break;
case TAR:
FileUtils.tar(workDirectory, imageArchive);
break;
case TGZ:
case TAR_GZ:
FileUtils.tgz(workDirectory, imageArchive);
break;
case TXZ:
case TAR_XZ:
FileUtils.xz(workDirectory, imageArchive);
break;
case TBZ2:
case TAR_BZ2:
FileUtils.bz2(workDirectory, imageArchive);
}
context.getLogger().debug("- {}", imageArchive.getFileName());
return Artifact.of(imageArchive, platform);
} catch (IOException e) {
throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error"), e);
}
}
Aggregations