public class Sincerity extends Object implements Runnable
While strictly speaking it is a singleton, several Sincerity instances may
coexist via the Bootstrap
mechanism. This is in order to allow
Sincerity to "reboot" itself using a new classpath in case the
Container
is changed. See reboot()
.
The main role of this class is to manage the Container
singleton.
Indeed, Sincerity can run without a container, and this class can be used to
create it.
This is also where you can access the "system" plugins, those that are part
of the Sincerity base installation and are not associated with any container.
See getPlugins()
.
Additionally, this class manages the general runtime environment and interface for all of Sincerity. This includes both the command line interface (CLI) and the graphical user interface (GUI).
Modifier and Type | Field and Description |
---|---|
static String |
CONTAINER_ENV |
static String |
CONTAINER_PROPERTY |
static String |
CONTAINER_ROOT_ATTRIBUTE |
static String |
DEBUG_ENV |
static String |
DEBUG_PROPERTY |
static String |
ERR_ATTRIBUTE |
static String |
OUT_ATTRIBUTE |
static String |
STARTED_ATTRIBUTE |
static String |
VERBOSITY_ATTRIBUTE |
static String |
VERSION_ATTRIBUTE |
Constructor and Description |
---|
Sincerity(String[] arguments)
Constructor.
|
Sincerity(String[] arguments,
Sincerity sincerity)
Cloning constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
captureOutput(Process process)
Captures the standard output and standard error of a process.
|
void |
createContainer(File containerRoot,
File templateDir,
boolean force)
Creates a new container based on a template and sets it as the current
container.
|
void |
dumpStackTrace(Throwable x)
Dumps an exception's stack trace to standard error.
|
<RD extends Module,R extends Repositories> |
getContainer()
The current container.
|
File |
getContainerRoot()
The root directory of the current container.
|
static Sincerity |
getCurrent()
The Sincerity instance running in the current thread.
|
PrintWriter |
getErr() |
Frame |
getFrame() |
File |
getHome()
The Sincerity home directory
|
File |
getHomeFile(String... parts)
Constructs an absolute path from the home directory.
|
PrintWriter |
getOut() |
Plugins |
getPlugins()
The plugins.
|
String |
getRelativeHomePath(File file)
If the file is under to the root directory, returns a relative path.
|
String |
getRelativeHomePath(String path)
If the path is under to the root directory, returns a relative path.
|
List<Template> |
getTemplates()
The available templates (names of directory in the "/templates/"
subdirectory of the Sincerity install).
|
int |
getTerminalHeight()
The terminal height
|
int |
getTerminalWidth()
The terminal width.
|
int |
getVerbosity() |
Map<String,String> |
getVersion()
Sincerity version information (cached as a bootstrap attribute).
|
boolean |
isTerminalAnsi()
Whether the terminal supports ANSI codes.
|
static void |
main(String[] arguments)
Executes a Sincerity command line, defaulting to the "shell:console"
command if no commands are given.
|
void |
reboot()
Reboots Sincerity without forcing a new container bootstrap.
|
void |
reboot(boolean forceNewBootstrap)
Reboots Sincerity, resubmitting the current command queue to the new
instance.
|
protected void |
removeCommand(Command command)
Removes a command from the current command queue.
|
void |
run() |
void |
run(Object... arguments)
Runs a command line with the current set of plugs.
|
void |
setContainerRoot(File containerRoot)
Changes the current container by specifying a new root directory.
|
void |
setErr(Writer err)
The standard error writer.
|
void |
setFrame(Frame frame)
The current open GUI frame.
|
void |
setOut(Writer out)
The standard output writer.
|
void |
setVerbosity(int verbosity)
Verbosity is only used to control messages to standard output and
standard error
|
public static final String CONTAINER_PROPERTY
public static final String CONTAINER_ENV
public static final String DEBUG_PROPERTY
public static final String DEBUG_ENV
public static final String VERSION_ATTRIBUTE
public static final String CONTAINER_ROOT_ATTRIBUTE
public static final String STARTED_ATTRIBUTE
public static final String VERBOSITY_ATTRIBUTE
public static final String OUT_ATTRIBUTE
public static final String ERR_ATTRIBUTE
public Sincerity(String[] arguments) throws SincerityException
arguments
- The command lineSincerityException
- In case of an errorpublic Sincerity(String[] arguments, Sincerity sincerity) throws SincerityException
arguments
- The command linesincerity
- The instance to cloneSincerityException
- In case of an errorpublic static Sincerity getCurrent()
public static void main(String[] arguments)
arguments
- The command linepublic Map<String,String> getVersion()
Taken from the "version.conf" resource.
public File getHome() throws SincerityException
SincerityException
- In case of an errorpublic File getHomeFile(String... parts) throws SincerityException
parts
- The path partsSincerityException
- In case of an errorpublic String getRelativeHomePath(File file) throws SincerityException
file
- The absolute fileSincerityException
- In case of an errorgetRelativeHomePath(File)
public String getRelativeHomePath(String path) throws SincerityException
path
- The absolute pathSincerityException
- In case of an errorgetRelativeHomePath(File)
public int getVerbosity()
setVerbosity(int)
public void setVerbosity(int verbosity)
It is interpreted individually by individual commands, though 0 usually means "silent," 1 means "only important messages" and 2 means "quite chatty." Higher values usually include more minute debugging information.
verbosity
- The verbosity levelgetVerbosity()
public PrintWriter getOut()
setOut(Writer)
public void setOut(Writer out)
Will be wrapped in a PrintWriter
if it's not already one.
out
- The writergetOut()
public PrintWriter getErr()
setErr(Writer)
public void setErr(Writer err)
Will be wrapped in a PrintWriter
if it's not already one.
err
- The writerpublic boolean isTerminalAnsi()
public int getTerminalWidth()
public int getTerminalHeight()
public File getContainerRoot() throws SincerityException
SincerityException
- In case of an errorsetContainerRoot(File)
public void setContainerRoot(File containerRoot) throws SincerityException
Causes a reboot()
if the current container is changed!
containerRoot
- The container rootSincerityException
- In case of an errorgetContainerRoot()
public <RD extends Module,R extends Repositories> Container<RD,R> getContainer() throws SincerityException
Creates a new instance if not previously accessed.
RD
- The resolved dependency classR
- The repositories classSincerityException
- In case of an errorpublic Plugins getPlugins() throws SincerityException
If there is a current container, then we will include its classpath. Otherwise, we will only consider the Sincerity home plugins.
SincerityException
- In case of an errorpublic Frame getFrame()
setFrame(Frame)
public void setFrame(Frame frame)
frame
- The GUI framegetFrame()
public List<Template> getTemplates() throws SincerityException
SincerityException
- In case of an errorpublic void createContainer(File containerRoot, File templateDir, boolean force) throws SincerityException
Unless force is true, will not copy any files if the directory already exists.
containerRoot
- The container root directorytemplateDir
- The template root directoryforce
- True to force overriding of existing filesSincerityException
- In case of an errorpublic void run(Object... arguments) throws SincerityException
arguments
- The command argumentsSincerityException
- In case of an errorgetPlugins()
public void reboot() throws SincerityException
SincerityException
- In case of an errorreboot(boolean)
public void reboot(boolean forceNewBootstrap) throws SincerityException
forceNewBootstrap
- True to force the re-creation of the container's bootstrapSincerityException
- In case of an errorpublic void captureOutput(Process process)
process
- The processsetOut(Writer)
,
setErr(Writer)
public void dumpStackTrace(Throwable x)
x
- The exceptionsetErr(Writer)
protected void removeCommand(Command command)
command
- The commandCopyright © 2011-2016 Three Crickets LLC.