Search in sources :

Example 1 with Session

use of meghanada.session.Session in project meghanada-server by mopemope.

the class CacheEventSubscriber method analyze.

private void analyze() {
    final Stopwatch stopwatch = Stopwatch.createStarted();
    final Session session = super.sessionEventBus.getSession();
    final Project project = session.getCurrentProject();
    final CachedASMReflector reflector = CachedASMReflector.getInstance();
    reflector.addClasspath(project.getOutput());
    reflector.addClasspath(project.getTestOutput());
    project.getDependencies().stream().filter(pd -> pd.getType().equals(ProjectDependency.Type.PROJECT)).forEach(pd -> {
        final File df = new File(pd.getDependencyFilePath());
        if (df.exists() && df.isDirectory()) {
            reflector.addClasspath(df);
        }
    });
    final Collection<File> dependentJars = session.getDependentJars();
    final int size = dependentJars.size();
    timeItF("create class index ... read " + size + " jars. elapsed:{}", () -> {
        reflector.addClasspath(dependentJars);
        reflector.createClassIndexes();
    });
    if (cleanUnusedSource(project)) {
        project.resetCallerMap();
    }
    log.info("start analyze sources ...");
    timeItF("analyzed and compiled. elapsed:{}", () -> {
        try {
            final CompileResult compileResult = project.compileJava();
            if (compileResult.isSuccess()) {
                if (compileResult.hasDiagnostics()) {
                    log.warn("compile message: {}", compileResult.getDiagnosticsSummary());
                }
                final CompileResult testCompileResult = project.compileTestJava();
                if (testCompileResult.isSuccess()) {
                    if (testCompileResult.hasDiagnostics()) {
                        log.warn("compile(test) message: {}", testCompileResult.getDiagnosticsSummary());
                    }
                } else {
                    log.warn("compile(test) error: {}", testCompileResult.getDiagnosticsSummary());
                }
            } else {
                log.warn("compile message  {}", compileResult.getDiagnosticsSummary());
            }
        } catch (Exception e) {
            log.catching(e);
        }
    });
    final Runtime runtime = Runtime.getRuntime();
    final float maxMemory = runtime.maxMemory() / 1024 / 1024;
    final float totalMemory = runtime.totalMemory() / 1024 / 1024;
    final float usedMemory = (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024;
    log.info("class index size:{} total elapsed:{}", reflector.getGlobalClassIndex().size(), stopwatch.stop());
    Config.showMemory();
    log.info("Ready");
}
Also used : SessionEventBus(meghanada.session.SessionEventBus) Stopwatch(com.google.common.base.Stopwatch) Collection(java.util.Collection) CompileResult(meghanada.analyze.CompileResult) Config.timeItF(meghanada.config.Config.timeItF) ProjectDatabaseHelper(meghanada.store.ProjectDatabaseHelper) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) File(java.io.File) Session(meghanada.session.Session) Logger(org.apache.logging.log4j.Logger) Project(meghanada.project.Project) Subscribe(com.google.common.eventbus.Subscribe) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) LogManager(org.apache.logging.log4j.LogManager) Project(meghanada.project.Project) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) Stopwatch(com.google.common.base.Stopwatch) CompileResult(meghanada.analyze.CompileResult) File(java.io.File) Session(meghanada.session.Session)

Example 2 with Session

use of meghanada.session.Session in project meghanada-server by mopemope.

the class ParseEventSubscriber method on.

@Subscribe
public synchronized void on(final SessionEventBus.ParseRequest request) {
    final Session session = super.sessionEventBus.getSession();
    final File file = request.getFile();
    if (!FileUtils.isJavaFile(file)) {
        return;
    }
    try {
        ParseEventSubscriber.parseFile(session, file);
    } catch (Exception e) {
        log.warn("parse error {}", e.getMessage());
    }
}
Also used : File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) IOException(java.io.IOException) Session(meghanada.session.Session) Subscribe(com.google.common.eventbus.Subscribe)

Example 3 with Session

use of meghanada.session.Session in project meghanada-server by mopemope.

the class EmacsServer method acceptConnection.

private Future<?> acceptConnection(final Socket conn) {
    return this.executorService.submit(() -> {
        try (final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), UTF_8));
            final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(), UTF_8))) {
            final CommandHandler handler = new CommandHandler(session, writer, getOutputFormatter());
            boolean start = true;
            final SExprParser parser = new SExprParser();
            while (start) {
                final String line = reader.readLine();
                if (isNull(line) || line.isEmpty()) {
                    log.info("close from client ...");
                    break;
                }
                final SExprParser.SExpr expr = parser.parse(line);
                final List<SExprParser.SExpr> lst = expr.value();
                final List<String> args = lst.stream().map(sExpr -> sExpr.value().toString()).collect(Collectors.toList());
                log.debug("receive command line:{} expr:{} args:{}", line, expr, args);
                start = dispatch(args, handler);
                if (!start) {
                    log.info("stop client ... args:{}", args);
                }
                if (this.outputEOT) {
                    writer.write(EmacsServer.EOT);
                    writer.newLine();
                }
                writer.flush();
            }
            log.info("close client ...");
        } catch (Throwable e) {
            log.catching(e);
        } finally {
            try {
                conn.close();
            } catch (IOException e) {
                log.catching(e);
            }
            log.info("client disconnect");
        }
    });
}
Also used : Socket(java.net.Socket) Stopwatch(com.google.common.base.Stopwatch) ListConsCases.headNil(com.leacox.motif.cases.ListConsCases.headNil) MatchesExact.eq(com.leacox.motif.MatchesExact.eq) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) ServerSocket(java.net.ServerSocket) Future(java.util.concurrent.Future) Server(meghanada.server.Server) OutputFormatter(meghanada.server.OutputFormatter) OutputStreamWriter(java.io.OutputStreamWriter) Objects.isNull(java.util.Objects.isNull) ExecutorService(java.util.concurrent.ExecutorService) SexpOutputFormatter(meghanada.server.formatter.SexpOutputFormatter) UTF_8(java.nio.charset.StandardCharsets.UTF_8) BufferedWriter(java.io.BufferedWriter) ListConsCases.headTail(com.leacox.motif.cases.ListConsCases.headTail) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Session(meghanada.session.Session) Logger(org.apache.logging.log4j.Logger) Motif.match(com.leacox.motif.Motif.match) MatchesAny.any(com.leacox.motif.MatchesAny.any) BufferedReader(java.io.BufferedReader) Objects.nonNull(java.util.Objects.nonNull) CommandHandler(meghanada.server.CommandHandler) LogManager(org.apache.logging.log4j.LogManager) InputStreamReader(java.io.InputStreamReader) CommandHandler(meghanada.server.CommandHandler) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter)

Example 4 with Session

use of meghanada.session.Session in project meghanada-server by mopemope.

the class ParseEventSubscriber method on.

@Subscribe
public synchronized void on(SessionEventBus.ParseFilesRequest request) {
    final Session session = super.sessionEventBus.getSession();
    final List<File> files = request.getFiles();
    for (final File file : files) {
        if (!FileUtils.isJavaFile(file)) {
            continue;
        }
        try {
            ParseEventSubscriber.parseFile(session, file);
        } catch (Exception e) {
            log.warn("parse error {}", e.getMessage());
        }
    }
}
Also used : File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) IOException(java.io.IOException) Session(meghanada.session.Session) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Session (meghanada.session.Session)4 Subscribe (com.google.common.eventbus.Subscribe)3 File (java.io.File)3 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 Stopwatch (com.google.common.base.Stopwatch)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 MatchesAny.any (com.leacox.motif.MatchesAny.any)1 MatchesExact.eq (com.leacox.motif.MatchesExact.eq)1 Motif.match (com.leacox.motif.Motif.match)1 ListConsCases.headNil (com.leacox.motif.cases.ListConsCases.headNil)1 ListConsCases.headTail (com.leacox.motif.cases.ListConsCases.headTail)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 InetAddress (java.net.InetAddress)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1