Skip to content

Commit

Permalink
Javac print all diagnostic messages at ERROR or INFO.
Browse files Browse the repository at this point in the history
- TODO TreeLogger needs a WARN level
- TODO #615
  TreeLogger.error indent doesnt match logger.info/debug

- Closes #609
- compile task not showing javac errors
  • Loading branch information
mP1 committed Dec 25, 2022
1 parent f29953b commit a3e4a91
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions src/main/java/walkingkooka/j2cl/maven/javac/JavacCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

package walkingkooka.j2cl.maven.javac;

import walkingkooka.NeverError;
import walkingkooka.collect.list.Lists;
import walkingkooka.j2cl.maven.J2clException;
import walkingkooka.j2cl.maven.J2clPath;
import walkingkooka.j2cl.maven.log.TreeFormat;
import walkingkooka.j2cl.maven.log.TreeLogger;
import walkingkooka.util.SystemProperty;

import javax.tools.Diagnostic;
import javax.tools.JavaCompiler;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
Expand All @@ -32,7 +34,9 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -92,10 +96,45 @@ static boolean execute(final Set<J2clPath> bootstrap,
fileManager.setLocation(StandardLocation.CLASS_PATH, J2clPath.toFiles(classpath)); /// Location to search for user class files.
fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(newClassFilesOutput.file())); /// Location of new class files

try(final Writer output = output(logger)) {
try (final Writer output = output(logger)) {
success = compiler.getTask(output,
fileManager,
null,
diagnostic -> {
final Diagnostic.Kind kind = diagnostic.getKind();

Consumer<String> target = null;

switch (kind) {
case ERROR:
target = (line) -> logger.error(line, null);
break;
case WARNING:
case MANDATORY_WARNING:
target = logger::line; // TODO should use WARN not INFO
break;
case NOTE:
case OTHER:
target = logger::line;
break;
default:
NeverError.unhandledCase(
kind,
Diagnostic.Kind.values()
);
}

// /Users/miroslav/repos-github/vertispan-connected-2/src/main/java/com/vertispan/draw/connected/client/FlowChartEntryPoint.java:85:64
//java: not a statement

Lists.of(
diagnostic.getSource().getName() +
":" +
diagnostic.getLineNumber() +
":" +
diagnostic.getColumnNumber(),
diagnostic.getMessage(Locale.getDefault())
).forEach(target);
},
options,
null,
fileManager.getJavaFileObjectsFromFiles(J2clPath.toFiles(newSourceFiles)))
Expand Down

0 comments on commit a3e4a91

Please sign in to comment.