
org.fugerit.java.tool.Launcher Maven / Gradle / Ivy
package org.fugerit.java.tool;
import java.util.Iterator;
import java.util.Properties;
import org.fugerit.java.core.cli.ArgUtils;
import org.fugerit.java.core.lang.helpers.ClassHelper;
import org.fugerit.java.core.util.PropsIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The launcher for all the tools.
*
* @author Fugerit
*
*/
public class Launcher {
protected static final Logger logger = LoggerFactory.getLogger(Launcher.class);
/**
* Argument for the tool handler to use
*/
public static final String ARG_TOOL = "tool";
/**
* Argument for the the verbose version
*/
public static final String ARG_VERBOSE = "verbose";
/**
* Argumento for the help
*/
public static final String ARG_HELP = "help";
private final static Properties HANDLER_LIST = loadSafe();
private static Properties loadSafe() {
Properties props = new Properties();
try {
props = PropsIO.loadFromClassLoader( "tool/config/handler-list.properties" );
} catch (Exception e) {
logger.error( "init error", e );
}
return props;
}
private static int handle( Properties params ) throws Exception {
int exit = ToolHandlerHelper.EXIT_OK;
String toolName = params.getProperty( ARG_TOOL );
String help = params.getProperty( ARG_HELP );
String verbose = params.getProperty( ARG_VERBOSE );
if ( verbose != null ) {
logger.info( "Setting to verbose output..." );
}
ToolHandler handler = null;
if ( toolName != null ) {
String toolType = HANDLER_LIST.getProperty( toolName );
handler = (ToolHandler)ClassHelper.newInstance( toolType );
}
if ( toolName == null || help != null ) {
printHelp();
if ( handler instanceof ToolHandlerHelper ) {
logger.info( "Handler help : \n"+((ToolHandlerHelper)handler).getHelp() );
}
} else {
exit = handler.handle( params );
}
return exit;
}
private static void printHelp() {
logger.info( "fj-tool launcher v 0.0.1 [2017-05-04] quickstart : " );
logger.info( " --tool tool name [run the named tool]" );
logger.info( " --help [print this help]" );
logger.info( " --verbose [verbose output]" );
logger.info( " tool valid options : " );
Iterator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy