use of org.lanternpowered.server.inject.LanternModule in project LanternServer by LanternPowered.
the class LanternServerLaunch method main.
public void main(String[] args) {
final LanternClassLoader classLoader = LanternClassLoader.get();
// Exclude the ASM library
classLoader.addTransformerExclusion(Exclusion.forPackage("org.objectweb.asm"));
classLoader.addTransformerExclusion(Exclusion.forPackage("org.lanternpowered.server.transformer"));
classLoader.addTransformerExclusion(Exclusion.forClass("org.lanternpowered.server.util.BytecodeUtils"));
classLoader.addTransformer(new FinalFieldClassTransformer());
classLoader.addTransformer(new FastValueContainerClassTransformer());
// Get the default logger
final Logger logger = LoggerFactory.getLogger(InternalPluginsInfo.Implementation.IDENTIFIER);
try {
// Create the shared option parser
final OptionParser optionParser = new OptionParser();
optionParser.allowsUnrecognizedOptions();
final OptionSpec<Void> version = optionParser.acceptsAll(Arrays.asList("version", "v"), "Display the Lantern version");
if (optionParser.parse(args).has(version)) {
final Package pack = Platform.class.getPackage();
logger.info(pack.getImplementationTitle() + ' ' + pack.getImplementationVersion());
logger.info(pack.getSpecificationTitle() + ' ' + pack.getSpecificationVersion());
return;
}
final OptionSpec<Void> help = optionParser.acceptsAll(Arrays.asList("help", "h", "?"), "Show this help text").forHelp();
// Initialize the injector
final LanternModule module = new LanternModule(logger, args, optionParser);
final Injector injector = Guice.createInjector(Stage.DEVELOPMENT, module);
logger.info("Instantiated the Injector in {} mode.", Environment.get().name().toLowerCase());
// Create the server instance
final LanternServer lanternServer = injector.getInstance(LanternServer.class);
// Initialize and start the server
lanternServer.initialize();
try {
final Field field = OptionParser.class.getDeclaredField("allowsUnrecognizedOptions");
field.setAccessible(true);
field.set(optionParser, false);
optionParser.parse(args);
} catch (OptionException e) {
logger.warn("Something went wrong while parsing options", e);
} catch (Exception e) {
logger.error("Unexpected error", e);
}
// annotations will be detected
if (optionParser.parse(args).has(help)) {
if (System.console() != null) {
// Terminal is (very likely) supported, use the terminal width provided by jline
final Terminal terminal = TerminalConsoleAppender.getTerminal();
if (terminal != null) {
optionParser.formatHelpWith(new BuiltinHelpFormatter(terminal.getWidth(), 3));
}
}
optionParser.printHelpOn(System.err);
return;
}
lanternServer.start();
} catch (Throwable t) {
logger.error("Error during server startup.", t);
System.exit(1);
}
}
Aggregations