Search in sources :

Example 1 with CompileResult

use of meghanada.analyze.CompileResult in project meghanada-server by mopemope.

the class GradleProjectTest method testCompile01.

@Test
public void testCompile01() throws Exception {
    final CompileResult compileResult = timeIt(() -> {
        project.parseProject();
        return this.project.compileJava();
    });
    log.info("compile message {}", compileResult.getDiagnosticsSummary());
    assertTrue(compileResult.isSuccess());
    Thread.sleep(3000);
}
Also used : CompileResult(meghanada.analyze.CompileResult) Test(org.junit.Test)

Example 2 with CompileResult

use of meghanada.analyze.CompileResult 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 3 with CompileResult

use of meghanada.analyze.CompileResult in project meghanada-server by mopemope.

the class CommandHandler method compile.

public void compile(final long id, final String path) {
    try {
        final String canonicalPath = new File(path).getCanonicalPath();
        final CompileResult compileResult = session.compileFile(canonicalPath);
        final String out = outputFormatter.compile(id, compileResult, canonicalPath);
        writer.write(out);
        writer.newLine();
    } catch (Throwable t) {
        writeError(id, t);
    }
}
Also used : CompileResult(meghanada.analyze.CompileResult) File(java.io.File)

Example 4 with CompileResult

use of meghanada.analyze.CompileResult in project meghanada-server by mopemope.

the class CommandHandler method compileProject.

public void compileProject(final long id, String path) {
    try {
        final CompileResult compileResult = session.compileProject(path, true);
        final String out = outputFormatter.compileProject(id, compileResult);
        writer.write(out);
        writer.newLine();
    } catch (Throwable t) {
        writeError(id, t);
    }
}
Also used : CompileResult(meghanada.analyze.CompileResult)

Example 5 with CompileResult

use of meghanada.analyze.CompileResult in project meghanada-server by mopemope.

the class CommandHandler method diagnostics.

public void diagnostics(final long id, final String sourceFile, final String sourceCodeFile) {
    File f = new File(sourceCodeFile);
    f.deleteOnExit();
    try {
        String contents = org.apache.commons.io.FileUtils.readFileToString(new File(sourceCodeFile));
        final CompileResult compileResult = session.diagnosticString(sourceFile, contents);
        final String out = outputFormatter.diagnostics(id, compileResult, sourceFile);
        writer.write(out);
        writer.newLine();
    } catch (Throwable t) {
        writeError(id, t);
    } finally {
        if (f.exists()) {
            f.delete();
        }
    }
}
Also used : CompileResult(meghanada.analyze.CompileResult) File(java.io.File)

Aggregations

CompileResult (meghanada.analyze.CompileResult)15 File (java.io.File)9 Stopwatch (com.google.common.base.Stopwatch)6 Diagnostic (javax.tools.Diagnostic)3 JavaFileObject (javax.tools.JavaFileObject)3 Collection (java.util.Collection)2 Config (meghanada.config.Config)2 Project (meghanada.project.Project)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 Test (org.junit.Test)2 Subscribe (com.google.common.eventbus.Subscribe)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1