use of meghanada.analyze.CompileResult in project meghanada-server by mopemope.
the class Project method compileJava.
public CompileResult compileJava(boolean force) throws IOException {
final String origin = Config.getProjectRoot();
try {
Config.setProjectRoot(projectRootPath);
List<File> files = Project.collectJavaFiles(sources);
if (nonNull(files) && !files.isEmpty()) {
if (this.callerMap.size() == 0) {
force = true;
}
if (force) {
this.callerMap.clear();
}
final Stopwatch stopwatch = Stopwatch.createStarted();
files = force ? files : FileUtils.getModifiedSources(this.projectRoot, files, this.getSourcesAndResources(), this.output);
if (!force) {
files = this.getRelatedSources(this.getSourcesAndResources(), files);
}
final String classpath = this.classpath();
this.prepareCompile(files);
final CompiledSourceHandler handler = new CompiledSourceHandler(this);
final CompileResult compileResult = clearMemberCache(getJavaAnalyzer().analyzeAndCompile(files, classpath, output.getCanonicalPath(), true, handler));
log.info("project {} compile and analyze (java) {} files. force:{} problem:{} elapsed:{}", this.name, files.size(), force, compileResult.getDiagnostics().size(), stopwatch.stop());
Config.setProjectRoot(projectRootPath);
return compileResult;
}
return new CompileResult(true);
} catch (Throwable t) {
log.catching(t);
final CompileResult result = new CompileResult(false);
final Diagnostic<? extends JavaFileObject> diagnostic = CompileResult.getDiagnosticFromThrowable(t);
if (diagnostic != null) {
result.getDiagnostics().add(diagnostic);
}
return result;
} finally {
Config.setProjectRoot(origin);
}
}
use of meghanada.analyze.CompileResult in project meghanada-server by mopemope.
the class Project method compileFile.
public CompileResult compileFile(List<File> files, final boolean force) throws IOException {
boolean isTest = false;
// sampling
String filepath = files.get(0).getCanonicalPath();
for (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 Set<File> sources = isTest ? this.getAllSources() : this.getSourcesAndResources();
final Stopwatch stopwatch = Stopwatch.createStarted();
files = force ? files : FileUtils.getModifiedSources(projectRoot, files, sources, new File(output));
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;
}
use of meghanada.analyze.CompileResult in project meghanada-server by mopemope.
the class Project method compileTestJava.
public CompileResult compileTestJava(boolean force) throws IOException {
final String origin = Config.getProjectRoot();
try {
Config.setProjectRoot(projectRootPath);
List<File> files = Project.collectJavaFiles(testSources);
if (files != null && !files.isEmpty()) {
if (this.callerMap.size() == 0) {
force = true;
}
if (force) {
this.callerMap.clear();
}
final Stopwatch stopwatch = Stopwatch.createStarted();
files = force ? files : FileUtils.getModifiedSources(projectRoot, files, this.getTestSourcesAndResources(), this.testOutput);
if (!force) {
files = this.getRelatedSources(this.getTestSourcesAndResources(), files);
}
final String classpath = this.allClasspath();
this.prepareTestCompile(files);
final CompiledSourceHandler handler = new CompiledSourceHandler(this);
final CompileResult compileResult = clearMemberCache(getJavaAnalyzer().analyzeAndCompile(files, classpath, testOutput.getCanonicalPath(), true, handler));
log.info("project {} compile and analyze (test) {} files. force:{} problem:{} elapsed:{}", this.name, files.size(), force, compileResult.getDiagnostics().size(), stopwatch.stop());
Config.setProjectRoot(projectRootPath);
return compileResult;
}
return new CompileResult(true);
} catch (Throwable t) {
log.catching(t);
final CompileResult result = new CompileResult(false);
final Diagnostic<? extends JavaFileObject> diagnostic = CompileResult.getDiagnosticFromThrowable(t);
if (diagnostic != null) {
result.getDiagnostics().add(diagnostic);
}
return result;
} finally {
Config.setProjectRoot(origin);
}
}
use of meghanada.analyze.CompileResult in project meghanada-server by mopemope.
the class SexpOutputFormatter method diagnostics.
@Override
public String diagnostics(final long id, final CompileResult compileResult, final String path) {
if (compileResult.isSuccess() && !compileResult.hasDiagnostics()) {
return success(LPAREN + "success" + RPAREN);
}
final List<Diagnostic<? extends JavaFileObject>> list = compileResult.getDiagnostics();
final StringBuilder sb = new StringBuilder(256);
sb.append(LPAREN);
sb.append("error");
sb.append(LIST_SEP);
final Map<String, Set<Diagnostic<? extends JavaFileObject>>> res = new HashMap<>();
list.forEach(wrapIOConsumer(d -> {
final JavaFileObject fileObject = d.getSource();
String key = path;
if (nonNull(fileObject) && fileObject.getKind().equals(JavaFileObject.Kind.SOURCE)) {
final URI uri = fileObject.toUri();
final File file = new File(uri);
key = file.getCanonicalPath();
}
if (res.containsKey(key)) {
final Set<Diagnostic<? extends JavaFileObject>> set = res.get(key);
set.add(d);
res.put(key, set);
} else {
final Set<Diagnostic<? extends JavaFileObject>> set = new HashSet<>();
set.add(d);
res.put(key, set);
}
}));
sb.append(LPAREN);
res.forEach((k, v) -> {
sb.append(LPAREN);
sb.append(doubleQuote(k));
sb.append(LIST_SEP);
sb.append(LPAREN);
v.forEach(d -> {
sb.append(LPAREN);
sb.append(String.join(LIST_SEP, Long.toString(d.getLineNumber()), Long.toString(d.getColumnNumber()), doubleQuote(d.getKind().toString()), doubleQuote(d.getMessage(null))));
sb.append(RPAREN);
sb.append(LIST_SEP);
});
sb.append(RPAREN);
sb.append(RPAREN);
});
sb.append(RPAREN);
sb.append(RPAREN);
return success(sb.toString());
}
use of meghanada.analyze.CompileResult 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;
}
Aggregations