diff --git a/pom.xml b/pom.xml index 5eb4bbe..463bfb3 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 @@ -83,10 +84,6 @@ maven-assembly-plugin 2.5.5 - - src/main/assembly/assembly-standalone.xml - false - single @@ -94,6 +91,25 @@ single + + src/main/assembly/assembly-standalone.xml + false + + + + fat-jar + package + + single + + + + jar-with-dependencies + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + @@ -158,16 +174,6 @@ airline ${version.airline} - - org.slf4j - slf4j-simple - ${version.slf4j} - - - org.slf4j - jul-to-slf4j - ${version.slf4j} - diff --git a/src/main/java/jabsc/Compiler.java b/src/main/java/jabsc/Compiler.java index 5ad89bd..bc89913 100644 --- a/src/main/java/jabsc/Compiler.java +++ b/src/main/java/jabsc/Compiler.java @@ -14,10 +14,7 @@ import java.util.List; import java.util.Optional; import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.bridge.SLF4JBridgeHandler; +import java.util.logging.Logger; import bnfc.abs.Yylex; import bnfc.abs.parser; @@ -33,15 +30,18 @@ public class Compiler implements Runnable { public static final String DEFAULT_OUTPUT_DIRECTORY_NAME = "generated-sources/jabsc"; + private final Logger logger = Logger.getLogger(getClass().getName()); + /** * The version of JABSC Compiler. */ private static final String VERSION; static { + // Set j.u.logging format: [LEVEL] MSG [THROWABLE] + System.setProperty("java.util.logging.SimpleFormatter.format", "[%4$s] %5$s%n%6$s"); VERSION = Optional.ofNullable(Compiler.class.getPackage().getImplementationVersion()) .orElse("1.x-SNAPSHOT"); - SLF4JBridgeHandler.install(); } /** @@ -49,8 +49,6 @@ public class Compiler implements Runnable { */ private static final String JAVA_FILE_EXTENSION = ".java"; - private final Logger logger = LoggerFactory.getLogger(getClass()); - private final List sources; private final Path outputDirectory; private boolean debug = false; @@ -67,7 +65,7 @@ public Compiler(List sources, Path outputDirectory) { this.sources = createSources(sources); this.outputDirectory = outputDirectory.normalize().toAbsolutePath(); validate(this.sources, outputDirectory); - logger.info("JABSC Compiler {} initialized", VERSION); + logger.info("jabsc " + VERSION); } /** @@ -75,17 +73,17 @@ public Compiler(List sources, Path outputDirectory) { * @throws Exception */ public List compile() throws Exception { - logger.info("Compiling from {} to {}", sources, outputDirectory); + logger.info("Compiling from " + sources + " to " + outputDirectory); final List compilations = new ArrayList<>(); for (Path source : sources) { if (Files.isDirectory(source) && Files.list(source).count() == 0) { - logger.info("Source directory {} is empty. Skipping.", source); + logger.info("Source directory " + source + " is empty. Skipping."); continue; } Path compilation = compile(source, outputDirectory); compilations.add(compilation); } - logger.info("Compiled {} Java sources to: {}", compilations.size(), outputDirectory); + logger.info("Compiled " + compilations.size() + " Java sources to: " + outputDirectory); return compilations; } @@ -176,7 +174,8 @@ protected Program parseSource(final BufferedReader reader) throws Exception { if (debug) { parser.dump_stack(); } - logger.error("Compile error found at line {} near:\n\t{}", lexer.line_num(), lexer.buff()); + logger.severe( + "Compile error found at line " + lexer.line_num() + " near:\n\t{}" + lexer.buff()); throw e; } } diff --git a/src/main/java/jabsc/Visitor.java b/src/main/java/jabsc/Visitor.java index c1e24a5..25e5a32 100644 --- a/src/main/java/jabsc/Visitor.java +++ b/src/main/java/jabsc/Visitor.java @@ -15,14 +15,12 @@ import java.util.Set; import java.util.Stack; import java.util.concurrent.Callable; +import java.util.logging.Logger; import java.util.stream.Collectors; import javax.lang.model.element.ElementKind; import javax.lang.model.element.Modifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.base.Supplier; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; @@ -54,7 +52,7 @@ class Visitor extends AbstractVisitor { // Internal Fields - private static final Logger LOGGER = LoggerFactory.getLogger(Visitor.class); + private static final Logger LOGGER = Logger.getLogger(Visitor.class.getName()); private final Set moduleNames; private final Prog prog; @@ -101,18 +99,15 @@ public Visitor(String packageName, Prog prog, JavaWriterSupplier javaWriterSuppl @Override public Prog visit(Prog p, JavaWriter w) { - try { - Prog program = (Prog) p; - determineProgramDeclarationTypes(program); - for (Module module : program.listmodule_) { - moduleNames.add(getQTypeName(((Modul) module).qtype_)); - modules.push(module); - module.accept(this, w); - modules.pop(); - w.emitEmptyLine(); - } - } catch (IOException e) { - throw new RuntimeException(e); + // WARNING: `w` should NOT be used in this method; + // otherwise, I/O issues occur during generation. + Prog program = (Prog) p; + determineProgramDeclarationTypes(program); + for (Module module : program.listmodule_) { + moduleNames.add(getQTypeName(((Modul) module).qtype_)); + modules.push(module); + module.accept(this, w); + modules.pop(); } return prog; } @@ -346,7 +341,6 @@ public Prog visit(NoBlock nb, JavaWriter w) { return prog; } - @Override public Prog visit(MethSig ms, JavaWriter w) { try { @@ -451,7 +445,6 @@ public Prog visit(SAwait p, JavaWriter w) { JavaWriter auxjw = new JavaWriter(auxsw); p.guard_.accept(this, auxjw); w.emitStatement("%s.getValue()", auxsw.toString()); - return prog; } catch (IOException e) { throw new RuntimeException(e); @@ -614,7 +607,6 @@ public Prog visit(SDecAss p, JavaWriter w) { } } - @Override public Prog visit(SReturn r, JavaWriter w) { try { @@ -626,8 +618,6 @@ public Prog visit(SReturn r, JavaWriter w) { } catch (IOException e) { throw new RuntimeException(e); } - - } @Override @@ -642,7 +632,7 @@ public Prog visit(SSuspend ss, JavaWriter w) { @Override public Prog visit(SSkip sk, JavaWriter w) { - LOGGER.warn("Not implemented: #visit({})", sk); + logNotImplemented("#visit(%s)", sk); return prog; } @@ -1082,193 +1072,193 @@ public Prog visit(LThis t, JavaWriter w) { @Override public Prog visit(AnyIden p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(AnyTyIden p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(AnyExport p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(AnyFromExport p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(StarExport p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(StarFromExport p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(AnyFromImport p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(StarFromImport p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(ForeignImport p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(NormalImport p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(TUnderscore p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(TSimple p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(TGen p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(QTyp p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(QTypeSegmen p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(TTyp p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(TTypeSegmen p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(TypeDecl p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(TypeParDecl p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(ExceptionDecl p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(DataDecl p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(DataParDecl p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(FunDecl p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(FunParDecl p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(SinglConstrIdent p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(ParamConstrIdent p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(EmptyConstrType p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(RecordConstrType p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(BuiltinFunBody p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(NormalFunBody p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(Par p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(SAssert p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @@ -1287,139 +1277,139 @@ public Prog visit(SPrint p, JavaWriter w) { @Override public Prog visit(AndGuard p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(Let p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(If p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(Case p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(EFunCall p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(EQualFunCall p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(ENaryFunCall p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(ENaryQualFunCall p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(EQualVar p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(ESinglConstr p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(EParamConstr p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(CaseBranc p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(PIdent p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(PLit p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(PSinglConstr p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(PParamConstr p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(PUnderscore p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(LThisDC p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(NewLocal p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(Spawns p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(SimpleAnn p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(AnnDec p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @Override public Prog visit(AnnTyp p, JavaWriter arg) { - LOGGER.warn("Not implemented: #visit({})", p); + logNotImplemented("#visit(%s)", p); return prog; } @@ -1900,4 +1890,8 @@ private String getRefinedClassName(String name) { return classNames.get(name); } + private void logNotImplemented(String format, Object... args) { + LOGGER.warning("Not implemented: " + String.format(format, args)); + } + } diff --git a/src/main/java/jabsc/cli/Bootstrap.java b/src/main/java/jabsc/cli/Bootstrap.java index c8894fd..e477836 100644 --- a/src/main/java/jabsc/cli/Bootstrap.java +++ b/src/main/java/jabsc/cli/Bootstrap.java @@ -1,7 +1,6 @@ package jabsc.cli; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.logging.Logger; import com.google.common.base.Throwables; import com.google.common.collect.Sets; @@ -12,7 +11,7 @@ public class Bootstrap { - private static final Logger LOGGER = LoggerFactory.getLogger(Bootstrap.class); + private static final Logger LOGGER = Logger.getLogger(Bootstrap.class.getName()); public static void main(String[] args) { try { @@ -24,8 +23,8 @@ public static void main(String[] args) { Runnable command = cli.parse(args); command.run(); } catch (Exception e) { - LOGGER.error("Compilation failed: {}", - Throwables.getStackTraceAsString(Throwables.getRootCause(e))); + LOGGER.severe( + "Compilation failed: " + Throwables.getStackTraceAsString(Throwables.getRootCause(e))); } } diff --git a/src/main/java/jabsc/cli/CompilerCommand.java b/src/main/java/jabsc/cli/CompilerCommand.java index b079093..56f6acd 100644 --- a/src/main/java/jabsc/cli/CompilerCommand.java +++ b/src/main/java/jabsc/cli/CompilerCommand.java @@ -1,7 +1,6 @@ package jabsc.cli; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.logging.Logger; import com.google.common.base.Throwables; @@ -12,7 +11,7 @@ @Command(name = "compile", description = "Compile ABS source to Java source") public class CompilerCommand implements Runnable { - private final Logger logger = LoggerFactory.getLogger(getClass()); + private final Logger logger = Logger.getLogger(getClass().getName()); @Option(name = {"-s", "--source"}, title = "ABS-SOURCE", description = "The path to ABS source(s) to compile. Can be a directory.", required = true) @@ -31,8 +30,8 @@ public void run() { new Compiler(source, outputDirectory).compile(); return; } catch (Exception e) { - logger.error("Compliation failed: {}", - Throwables.getStackTraceAsString(Throwables.getRootCause(e))); + logger.severe( + "Compliation failed: " + Throwables.getStackTraceAsString(Throwables.getRootCause(e))); return; } }