dev.jbang.source.generators.BaseCmdGenerator 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.util.*;
import dev.jbang.source.*;
import dev.jbang.util.CommandBuffer;
import dev.jbang.util.Util;
public abstract class BaseCmdGenerator implements CmdGenerator {
protected final BuildContext ctx;
protected List arguments = Collections.emptyList();
protected Map debugString;
protected String flightRecorderString;
protected Util.Shell shell = Util.getShell();
// 8192 character command line length limit imposed by CMD.EXE
protected static final int COMMAND_LINE_LENGTH_LIMIT = 8000;
@SuppressWarnings("unchecked")
public T arguments(List arguments) {
this.arguments = arguments != null ? arguments : Collections.emptyList();
return (T) this;
}
@SuppressWarnings("unchecked")
public T shell(Util.Shell shell) {
this.shell = shell;
return (T) this;
}
@SuppressWarnings("unchecked")
public T debugString(Map debugString) {
this.debugString = debugString != null && !debugString.isEmpty() ? debugString : null;
return (T) this;
}
@SuppressWarnings("unchecked")
public T flightRecorderString(String flightRecorderString) {
this.flightRecorderString = flightRecorderString != null && !flightRecorderString.isEmpty()
? flightRecorderString
: null;
return (T) this;
}
public BaseCmdGenerator(BuildContext ctx) {
this.ctx = ctx;
}
@Override
public String generate() throws IOException {
List fullArgs = generateCommandLineList();
return generateCommandLineString(fullArgs);
}
protected abstract List generateCommandLineList() throws IOException;
protected String generateCommandLineString(List fullArgs) throws IOException {
CommandBuffer cb = CommandBuffer.of(fullArgs);
return cb.asCommandLine(shell);
}
}