use of meghanada.server.Server in project meghanada-server by mopemope.
the class Main method main.
public static void main(String[] args) throws ParseException, IOException {
final String version = getVersion();
System.setProperty("meghanada-server.version", version);
final Options options = buildOptions();
final CommandLineParser parser = new DefaultParser();
final CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("h")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("meghanada server : " + version, options);
return;
}
if (cmd.hasOption("version")) {
System.out.println(version);
return;
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
log.info("shutdown server");
Config.showMemory();
}));
System.setProperty("home", Config.getInstalledPath().getParentFile().getCanonicalPath());
addFileAppender();
if (cmd.hasOption("v")) {
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = context.getConfiguration();
final LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(Level.DEBUG);
context.updateLoggers();
System.setProperty("log-level", "DEBUG");
log.debug("set verbose flag(DEBUG)");
}
if (cmd.hasOption("vv")) {
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = context.getConfiguration();
final LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(Level.TRACE);
context.updateLoggers();
System.setProperty("log-level", "TRACE");
log.debug("set verbose flag(TRACE)");
}
if (cmd.hasOption("clear-cache")) {
System.setProperty("clear-cache-on-start", "true");
}
if (cmd.hasOption("gradle-version")) {
final String gradleVersion = cmd.getOptionValue("gradle-version", "");
if (!version.isEmpty()) {
System.setProperty("meghanada.gradle-version", gradleVersion);
}
}
String port = "55555";
String projectRoot = "./";
String fmt = "sexp";
if (cmd.hasOption("p")) {
port = cmd.getOptionValue("p", port);
}
if (cmd.hasOption("r")) {
projectRoot = cmd.getOptionValue("r", projectRoot);
}
if (cmd.hasOption("output")) {
fmt = cmd.getOptionValue("output", fmt);
}
log.debug("set port:{}, projectRoot:{}, output:{}", port, projectRoot, fmt);
final int portInt = Integer.parseInt(port);
log.info("Meghanada-Server Version:{}", version);
final Server server = createServer("localhost", portInt, projectRoot, fmt);
server.startServer();
}
Aggregations