Search in sources :

Example 11 with Project

use of meghanada.project.Project in project meghanada-server by mopemope.

the class Session method compileProject.

public synchronized CompileResult compileProject(final String path, final boolean force) throws IOException {
    final Project project = currentProject;
    final CompileResult result = project.compileJava(force);
    if (result.hasDiagnostics()) {
        log.warn("project {} compile report:{}", project.getName(), result.getDiagnosticsSummary());
    }
    final CompileResult testResult = project.compileTestJava(force);
    if (testResult.hasDiagnostics()) {
        for (final Diagnostic<? extends JavaFileObject> diagnostic : testResult.getDiagnostics()) {
            result.getDiagnostics().add(diagnostic);
        }
        log.warn("peoject {} test compile report:{}", project.getName(), testResult.getDiagnosticsSummary());
    }
    return result;
}
Also used : MavenProject(meghanada.project.maven.MavenProject) GradleProject(meghanada.project.gradle.GradleProject) Project(meghanada.project.Project) MeghanadaProject(meghanada.project.meghanada.MeghanadaProject) CompileResult(meghanada.analyze.CompileResult)

Example 12 with Project

use of meghanada.project.Project in project meghanada-server by mopemope.

the class Session method switchTest.

public Optional<String> switchTest(final String path) throws IOException {
    boolean b = this.changeProject(path);
    Project project = currentProject;
    String root = null;
    Set<File> roots;
    boolean isTest;
    if (path.endsWith("Test.java")) {
        // test -> src
        roots = project.getTestSources();
        isTest = true;
    } else {
        // src -> test
        roots = project.getSources();
        isTest = false;
    }
    for (final File file : roots) {
        final String rootPath = file.getCanonicalPath();
        if (path.startsWith(rootPath)) {
            root = rootPath;
            break;
        }
    }
    if (isNull(root)) {
        return Optional.empty();
    }
    String switchPath = path.substring(root.length());
    if (isTest) {
        switchPath = SWITCH_TEST_RE.matcher(switchPath).replaceAll(Matcher.quoteReplacement(".java"));
        // to src
        for (File srcRoot : project.getSources()) {
            final File srcFile = new File(srcRoot, switchPath);
            if (srcFile.exists()) {
                return Optional.of(srcFile.getCanonicalPath());
            }
        }
    } else {
        switchPath = SWITCH_JAVA_RE.matcher(switchPath).replaceAll(Matcher.quoteReplacement("Test.java"));
        // to test
        for (File srcRoot : project.getTestSources()) {
            final File testFile = new File(srcRoot, switchPath);
            if (testFile.exists()) {
                return Optional.of(testFile.getCanonicalPath());
            }
        }
    }
    return Optional.empty();
}
Also used : MavenProject(meghanada.project.maven.MavenProject) GradleProject(meghanada.project.gradle.GradleProject) Project(meghanada.project.Project) MeghanadaProject(meghanada.project.meghanada.MeghanadaProject) File(java.io.File)

Example 13 with Project

use of meghanada.project.Project 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)

Example 14 with Project

use of meghanada.project.Project in project meghanada-server by mopemope.

the class GradleProjectTest method testLoadProject01.

@Ignore
@Test
public void testLoadProject01() throws Exception {
    Project parsed = project.parseProject();
    String classpath1 = parsed.classpath();
    timeIt(parsed::saveProject);
    Thread.sleep(1000);
    Project load = timeIt(() -> Project.loadProject(this.projectRootPath));
    String classpath2 = load.classpath();
    assertEquals(classpath1, classpath2);
    timeIt(load::saveProject);
}
Also used : Project(meghanada.project.Project) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with Project

use of meghanada.project.Project in project meghanada-server by mopemope.

the class GradleProjectTest method testParse02.

@Test
public void testParse02() throws Exception {
    final Project project = timeIt(() -> this.project.parseProject());
    final String classpath = project.classpath();
    assertNotNull(classpath);
    // for (final String cp : StringUtils.split(classpath, File.pathSeparatorChar)) {
    // System.out.println(cp);
    // }
    final String all = project.classpath();
    assertNotNull(all);
}
Also used : Project(meghanada.project.Project) Test(org.junit.Test)

Aggregations

Project (meghanada.project.Project)18 File (java.io.File)13 Config (meghanada.config.Config)10 IOException (java.io.IOException)8 GradleProject (meghanada.project.gradle.GradleProject)8 LogManager (org.apache.logging.log4j.LogManager)8 Logger (org.apache.logging.log4j.Logger)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)7 ExecutionException (java.util.concurrent.ExecutionException)7 GlobalCache (meghanada.cache.GlobalCache)7 ProjectDependency (meghanada.project.ProjectDependency)7 CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)7 InputStream (java.io.InputStream)6 UncheckedIOException (java.io.UncheckedIOException)6 HashMap (java.util.HashMap)6 Optional (java.util.Optional)6 Stream (java.util.stream.Stream)6 Source (meghanada.analyze.Source)6