use of meghanada.project.Project in project meghanada-server by mopemope.
the class GradleProjectTest method testParse01.
@Test
public void testParse01() throws Exception {
Project parsed = this.project.parseProject();
final File outputDirectory = parsed.getOutput();
assertNotNull(outputDirectory);
System.out.println(outputDirectory);
}
use of meghanada.project.Project 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);
}
use of meghanada.project.Project 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);
}
}
use of meghanada.project.Project in project meghanada-server by mopemope.
the class Session method formatCode.
public void formatCode(final String path) throws IOException {
boolean b = this.changeProject(path);
final Project project = currentProject;
final Optional<Properties> formatProperties = project.getFormatProperties();
if (!formatProperties.isPresent()) {
FileUtils.formatJavaFile(path);
} else {
FileUtils.formatJavaFile(formatProperties.get(), path);
}
}
use of meghanada.project.Project in project meghanada-server by mopemope.
the class FileWatchEventSubscriber method on.
@Subscribe
public void on(final FileSystemWatcher.DeleteEvent event) {
final File file = event.getFile();
try {
String filePath = file.getCanonicalPath();
GlobalCache globalCache = GlobalCache.getInstance();
Project project = sessionEventBus.getSession().getCurrentProject();
globalCache.invalidateSource(project, file);
ProjectDatabaseHelper.deleteSource(filePath);
FileUtils.getClassFile(filePath, project.getSources(), project.getOutput()).ifPresent(File::delete);
FileUtils.getClassFile(filePath, project.getTestSources(), project.getTestOutput()).ifPresent(File::delete);
} catch (Throwable e) {
log.catching(e);
}
}
Aggregations