Search in sources :

Example 11 with CompileResult

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

the class GradleProjectTest method testCompile02.

@Ignore
@Test
public void testCompile02() throws Exception {
    project.parseProject();
    setupReflector(project);
    Thread.sleep(1000 * 3);
    final CompileResult compileResult = this.project.compileJava(true);
    assertTrue(compileResult.isSuccess());
    String fqcn = "meghanada.store.ProjectDatabase";
    Thread.sleep(1000 * 5);
    ProjectDatabaseHelper.getClassIndexLinks(fqcn, "references", entities -> {
        log.info("references {}", entities.size());
    });
    for (int i = 0; i < 5; i++) {
        this.project.compileJava(true);
        Thread.sleep(1000 * 5);
        ProjectDatabaseHelper.getClassIndexLinks(fqcn, "references", entities -> {
            log.info("references {}", entities.size());
        });
    }
}
Also used : CompileResult(meghanada.analyze.CompileResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with CompileResult

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

the class ReferenceSearcherTest method setup.

@BeforeClass
public static void setup() throws Exception {
    GradleTestBase.setupReflector(true);
    CompileResult compileResult1 = project.compileJava();
    CompileResult compileResult2 = project.compileTestJava();
    Thread.sleep(1000 * 4);
}
Also used : CompileResult(meghanada.analyze.CompileResult) BeforeClass(org.junit.BeforeClass)

Example 13 with CompileResult

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

the class JavaSourceLoader method load.

@Override
public Source load(final File file) throws IOException {
    final Config config = Config.load();
    if (!file.exists()) {
        return new Source(file.getPath());
    }
    if (!config.useSourceCache()) {
        final CompileResult compileResult = project.parseFile(file);
        return compileResult.getSources().get(file);
    }
    final String projectRootPath = this.project.getProjectRootPath();
    final Map<String, String> checksumMap = ProjectDatabaseHelper.getChecksumMap(projectRootPath);
    final String path = file.getCanonicalPath();
    final String md5sum = FileUtils.getChecksum(file);
    if (checksumMap.containsKey(path)) {
        // compare checksum
        final String prevSum = checksumMap.get(path);
        if (md5sum.equals(prevSum)) {
            // load from cache
            try {
                final Optional<Source> source = loadSource(file);
                if (source.isPresent()) {
                    log.debug("hit source cache {}", file);
                    return source.get();
                }
            } catch (Exception e) {
                log.catching(e);
            }
        }
    }
    log.warn("source cache miss {}", file);
    final CompileResult compileResult = project.parseFile(file.getCanonicalFile());
    return compileResult.getSources().get(file.getCanonicalFile());
}
Also used : Config(meghanada.config.Config) CompileResult(meghanada.analyze.CompileResult) Source(meghanada.analyze.Source) IOException(java.io.IOException)

Example 14 with CompileResult

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

the class Project method compileFile.

public CompileResult compileFile(final File file, final boolean force, final boolean withRelated) throws IOException {
    boolean isTest = false;
    final String filepath = file.getCanonicalPath();
    for (final File source : this.testSources) {
        String testPath = source.getCanonicalPath();
        if (filepath.startsWith(testPath)) {
            isTest = true;
            break;
        }
    }
    String output;
    if (isTest) {
        output = this.testOutput.getCanonicalPath();
    } else {
        output = this.output.getCanonicalPath();
    }
    final Stopwatch stopwatch = Stopwatch.createStarted();
    List<File> files = new ArrayList<>(8);
    files.add(file);
    final Set<File> sources = isTest ? this.getAllSources() : this.getSourcesAndResources();
    files = force ? files : FileUtils.getModifiedSources(projectRoot, files, sources, new File(output));
    if (withRelated) {
        files = this.getRelatedSources(sources, files);
    }
    if (isTest) {
        this.prepareTestCompile(files);
    } else {
        this.prepareCompile(files);
    }
    final CompiledSourceHandler handler = new CompiledSourceHandler(this);
    final CompileResult compileResult = clearMemberCache(getJavaAnalyzer().analyzeAndCompile(files, this.allClasspath(), output, true, handler));
    log.info("project {} compile and analyze {} files. force:{} problem:{} elapsed:{}", this.name, files.size(), force, compileResult.getDiagnostics().size(), stopwatch.stop());
    return compileResult;
}
Also used : Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) CompileResult(meghanada.analyze.CompileResult) File(java.io.File)

Example 15 with CompileResult

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

the class Project method compileString.

public CompileResult compileString(final String sourceFile, final String sourceCode) throws IOException {
    boolean isTest = false;
    for (final File source : this.testSources) {
        String testPath = source.getCanonicalPath();
        if (sourceFile.startsWith(testPath)) {
            isTest = true;
            break;
        }
    }
    String output;
    if (isTest) {
        output = this.testOutput.getCanonicalPath();
    } else {
        output = this.output.getCanonicalPath();
    }
    final Stopwatch stopwatch = Stopwatch.createStarted();
    CompiledSourceHandler handler = new CompiledSourceHandler(this, true);
    CompileResult compileResult = clearMemberCache(getJavaAnalyzer().runAnalyzeAndCompile(this.allClasspath(), output, sourceFile, sourceCode, true, handler));
    log.info("file {} compile and analyze problem:{} elapsed:{}", sourceFile, compileResult.getDiagnostics().size(), stopwatch.stop());
    return compileResult;
}
Also used : Stopwatch(com.google.common.base.Stopwatch) 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