Search in sources :

Example 1 with Server

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();
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) Configuration(org.apache.logging.log4j.core.config.Configuration) EmacsServer(meghanada.server.emacs.EmacsServer) Server(meghanada.server.Server) CommandLineParser(org.apache.commons.cli.CommandLineParser) LoggerContext(org.apache.logging.log4j.core.LoggerContext) DefaultParser(org.apache.commons.cli.DefaultParser) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Aggregations

Server (meghanada.server.Server)1 EmacsServer (meghanada.server.emacs.EmacsServer)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Options (org.apache.commons.cli.Options)1 LoggerContext (org.apache.logging.log4j.core.LoggerContext)1 Configuration (org.apache.logging.log4j.core.config.Configuration)1 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)1