Search in sources :

Example 1 with MavenProject

use of meghanada.project.maven.MavenProject in project meghanada-server by mopemope.

the class Session method searchAndChangeProject.

private boolean searchAndChangeProject(final File base) throws IOException {
    final File projectRoot = Session.findProjectRoot(base);
    if (isNull(projectRoot) || this.currentProject.getProjectRoot().equals(projectRoot)) {
        // not change
        return false;
    }
    if (this.projects.containsKey(projectRoot)) {
        // loaded project
        this.currentProject = this.projects.get(projectRoot);
        log.info("change project {}", this.currentProject.getName());
        String projectRootPath = this.currentProject.getProjectRootPath();
        Config.setProjectRoot(projectRootPath);
        this.getLocationSearcher().setProject(currentProject);
        this.getDeclarationSearcher().setProject(this.currentProject);
        this.getVariableCompletion().setProject(this.currentProject);
        this.getCompletion().setProject(this.currentProject);
        return true;
    }
    if (currentProject instanceof GradleProject) {
        return loadProject(projectRoot, Project.GRADLE_PROJECT_FILE).map(project -> setProject(projectRoot, project)).orElse(false);
    } else if (currentProject instanceof MavenProject) {
        return loadProject(projectRoot, Project.MVN_PROJECT_FILE).map(project -> setProject(projectRoot, project)).orElse(false);
    }
    return loadProject(projectRoot, Config.MEGHANADA_CONF_FILE).map(project -> setProject(projectRoot, project)).orElse(false);
}
Also used : MavenProject(meghanada.project.maven.MavenProject) Matcher(java.util.regex.Matcher) Diagnostic(javax.tools.Diagnostic) Map(java.util.Map) CandidateUnit(meghanada.reflect.CandidateUnit) Objects.isNull(java.util.Objects.isNull) Path(java.nio.file.Path) GlobalCache(meghanada.cache.GlobalCache) TypeInfoSearcher(meghanada.typeinfo.TypeInfoSearcher) Collection(java.util.Collection) CompileResult(meghanada.analyze.CompileResult) StandardOpenOption(java.nio.file.StandardOpenOption) GradleProject(meghanada.project.gradle.GradleProject) Set(java.util.Set) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) JavaFileObject(javax.tools.JavaFileObject) List(java.util.List) Declaration(meghanada.docs.declaration.Declaration) Stream(java.util.stream.Stream) TypeInfo(meghanada.typeinfo.TypeInfo) Logger(org.apache.logging.log4j.Logger) Optional(java.util.Optional) Project(meghanada.project.Project) Pattern(java.util.regex.Pattern) Objects.nonNull(java.util.Objects.nonNull) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) Joiner(com.google.common.base.Joiner) Location(meghanada.location.Location) Stopwatch(com.google.common.base.Stopwatch) HashMap(java.util.HashMap) JavaCompletion(meghanada.completion.JavaCompletion) Deque(java.util.Deque) ArrayList(java.util.ArrayList) JavaVariableCompletion(meghanada.completion.JavaVariableCompletion) HashSet(java.util.HashSet) Reference(meghanada.reference.Reference) ReferenceSearcher(meghanada.reference.ReferenceSearcher) LocationSearcher(meghanada.location.LocationSearcher) LocalVariable(meghanada.completion.LocalVariable) Properties(java.util.Properties) Files(java.nio.file.Files) IOException(java.io.IOException) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) FileUtils(meghanada.utils.FileUtils) EntryMessage(org.apache.logging.log4j.message.EntryMessage) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) MeghanadaProject(meghanada.project.meghanada.MeghanadaProject) Paths(java.nio.file.Paths) ModuleHelper(meghanada.module.ModuleHelper) Source(meghanada.analyze.Source) DeclarationSearcher(meghanada.docs.declaration.DeclarationSearcher) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) MavenProject(meghanada.project.maven.MavenProject) GradleProject(meghanada.project.gradle.GradleProject) File(java.io.File)

Example 2 with MavenProject

use of meghanada.project.maven.MavenProject in project meghanada-server by mopemope.

the class Session method loadProject.

private static Optional<Project> loadProject(final File projectRoot, final String targetFile) throws IOException {
    final EntryMessage entryMessage = log.traceEntry("projectRoot={} targetFile={}", projectRoot, targetFile);
    final String projectRootPath = projectRoot.getCanonicalPath();
    Config.setProjectRoot(projectRootPath);
    try {
        final Config config = Config.load();
        final String id = FileUtils.findProjectID(projectRoot, targetFile);
        if (Project.loadedProject.containsKey(id)) {
            // loaded skip
            final Project project = Project.loadedProject.get(id);
            log.traceExit(entryMessage);
            Config.setProjectRoot(projectRootPath);
            return Optional.of(project);
        }
        log.trace("project projectID={} projectRoot={}", id, projectRoot);
        if (config.useFastBoot()) {
            try {
                final Project tempProject = Project.loadProject(projectRootPath);
                if (nonNull(tempProject) && tempProject.getId().equals(id)) {
                    tempProject.setId(id);
                    log.debug("load from cache project={}", tempProject);
                    log.info("load project from cache. projectRoot:{}", tempProject.getProjectRoot());
                    log.traceExit(entryMessage);
                    return Optional.of(tempProject.mergeFromProjectConfig());
                }
            } catch (Exception ex) {
                log.catching(ex);
            }
        }
        Project project;
        switch(targetFile) {
            case Project.GRADLE_PROJECT_FILE:
                project = new GradleProject(projectRoot);
                break;
            case Project.MVN_PROJECT_FILE:
                project = new MavenProject(projectRoot);
                break;
            default:
                project = new MeghanadaProject(projectRoot);
                break;
        }
        project.setId(id);
        final Stopwatch stopwatch = Stopwatch.createStarted();
        final Project parsed = project.parseProject();
        if (config.useFastBoot()) {
            parsed.saveProject();
        }
        log.info("loaded project:{} elapsed:{}", project.getProjectRoot(), stopwatch.stop());
        log.traceExit(entryMessage);
        return Optional.of(parsed.mergeFromProjectConfig());
    } finally {
        Config.setProjectRoot(projectRootPath);
    }
}
Also used : MavenProject(meghanada.project.maven.MavenProject) GradleProject(meghanada.project.gradle.GradleProject) Project(meghanada.project.Project) MeghanadaProject(meghanada.project.meghanada.MeghanadaProject) MavenProject(meghanada.project.maven.MavenProject) MeghanadaProject(meghanada.project.meghanada.MeghanadaProject) Config(meghanada.config.Config) Stopwatch(com.google.common.base.Stopwatch) GradleProject(meghanada.project.gradle.GradleProject) EntryMessage(org.apache.logging.log4j.message.EntryMessage) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with MavenProject

use of meghanada.project.maven.MavenProject in project meghanada-server by mopemope.

the class Session method reloadProject.

public void reloadProject() throws IOException {
    final Project currentProject = this.currentProject;
    final File projectRoot = currentProject.getProjectRoot();
    this.projects.clear();
    if (currentProject instanceof GradleProject) {
        loadProject(projectRoot, Project.GRADLE_PROJECT_FILE).ifPresent(project -> {
            boolean ret = setProject(projectRoot, project);
        });
    } else if (currentProject instanceof MavenProject) {
        loadProject(projectRoot, Project.MVN_PROJECT_FILE).ifPresent(project -> {
            boolean ret = setProject(projectRoot, project);
        });
    } else {
        loadProject(projectRoot, Config.MEGHANADA_CONF_FILE).ifPresent(project -> {
            boolean ret = setProject(projectRoot, project);
        });
    }
    final Set<File> temp = new HashSet<>(this.currentProject.getSources());
    temp.addAll(this.currentProject.getTestSources());
    this.sessionEventBus.requestWatchFiles(new ArrayList<>(temp));
    final CachedASMReflector reflector = CachedASMReflector.getInstance();
    reflector.addClasspath(Session.getSystemJars());
    this.sessionEventBus.requestCreateCache();
    this.projects.values().forEach(project -> this.sessionEventBus.requestWatchFile(project.getProjectRoot()));
}
Also used : MavenProject(meghanada.project.maven.MavenProject) Matcher(java.util.regex.Matcher) Diagnostic(javax.tools.Diagnostic) Map(java.util.Map) CandidateUnit(meghanada.reflect.CandidateUnit) Objects.isNull(java.util.Objects.isNull) Path(java.nio.file.Path) GlobalCache(meghanada.cache.GlobalCache) TypeInfoSearcher(meghanada.typeinfo.TypeInfoSearcher) Collection(java.util.Collection) CompileResult(meghanada.analyze.CompileResult) StandardOpenOption(java.nio.file.StandardOpenOption) GradleProject(meghanada.project.gradle.GradleProject) Set(java.util.Set) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) JavaFileObject(javax.tools.JavaFileObject) List(java.util.List) Declaration(meghanada.docs.declaration.Declaration) Stream(java.util.stream.Stream) TypeInfo(meghanada.typeinfo.TypeInfo) Logger(org.apache.logging.log4j.Logger) Optional(java.util.Optional) Project(meghanada.project.Project) Pattern(java.util.regex.Pattern) Objects.nonNull(java.util.Objects.nonNull) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) Joiner(com.google.common.base.Joiner) Location(meghanada.location.Location) Stopwatch(com.google.common.base.Stopwatch) HashMap(java.util.HashMap) JavaCompletion(meghanada.completion.JavaCompletion) Deque(java.util.Deque) ArrayList(java.util.ArrayList) JavaVariableCompletion(meghanada.completion.JavaVariableCompletion) HashSet(java.util.HashSet) Reference(meghanada.reference.Reference) ReferenceSearcher(meghanada.reference.ReferenceSearcher) LocationSearcher(meghanada.location.LocationSearcher) LocalVariable(meghanada.completion.LocalVariable) Properties(java.util.Properties) Files(java.nio.file.Files) IOException(java.io.IOException) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) FileUtils(meghanada.utils.FileUtils) EntryMessage(org.apache.logging.log4j.message.EntryMessage) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) MeghanadaProject(meghanada.project.meghanada.MeghanadaProject) Paths(java.nio.file.Paths) ModuleHelper(meghanada.module.ModuleHelper) Source(meghanada.analyze.Source) DeclarationSearcher(meghanada.docs.declaration.DeclarationSearcher) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) MavenProject(meghanada.project.maven.MavenProject) GradleProject(meghanada.project.gradle.GradleProject) Project(meghanada.project.Project) MeghanadaProject(meghanada.project.meghanada.MeghanadaProject) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) MavenProject(meghanada.project.maven.MavenProject) GradleProject(meghanada.project.gradle.GradleProject) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)3 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 Config (meghanada.config.Config)3 Joiner (com.google.common.base.Joiner)2 File (java.io.File)2 InputStream (java.io.InputStream)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2 StandardOpenOption (java.nio.file.StandardOpenOption)2 ArrayDeque (java.util.ArrayDeque)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 Deque (java.util.Deque)2 HashMap (java.util.HashMap)2