dev.jbang.source.generators.NativeCmdGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbang-cli Show documentation
Show all versions of jbang-cli Show documentation
JBang Command Line Interface
package dev.jbang.source.generators;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import dev.jbang.source.BuildContext;
import dev.jbang.source.CmdGenerator;
import dev.jbang.util.Util;
public class NativeCmdGenerator extends BaseCmdGenerator {
private final CmdGenerator fallback;
public NativeCmdGenerator(BuildContext ctx, CmdGenerator fallback) {
super(ctx);
this.fallback = fallback;
}
@Override
public String generate() throws IOException {
List fullArgs = new ArrayList<>();
if (ctx.getProject().enablePreview()) {
fullArgs.add("--enable-preview");
}
Path image = ctx.getNativeImageFile();
if (Files.exists(image)) {
fullArgs.add(image.toString());
} else {
Util.warnMsg("native built image not found - running in java mode.");
return fallback.generate();
}
fullArgs.addAll(arguments);
return generateCommandLineString(fullArgs);
}
@Override
protected List generateCommandLineList() throws IOException {
return null;
}
}