Commit 3f1eb2a9 authored by René Schöne's avatar René Schöne
Browse files

Version 0.3.1

parent 1f7396a9
...@@ -32,7 +32,7 @@ test: ...@@ -32,7 +32,7 @@ test:
image: openjdk:11 image: openjdk:11
stage: test stage: test
services: services:
- name: "eclipse-mosquitto:1.6.9" - name: "eclipse-mosquitto:1.6"
alias: "mqtt" alias: "mqtt"
needs: needs:
- build - build
......
[submodule "relast-preprocessor"] [submodule "relast-preprocessor"]
path = relast-preprocessor path = relast-preprocessor
url = ../relast-preprocessor.git url = ../relast-preprocessor.git
branch = jastadd-fix-inc-param-debug branch = develop
[submodule "ragconnect.base/src/main/jastadd/mustache"]
path = ragconnect.base/src/main/jastadd/mustache
url = ../mustache
# Changelog
## 0.3.1
- Full support for incremental dependency tracking
- Full support for subtree endpoint definitions ([#9](https://git-st.inf.tu-dresden.de/jastadd/ragconnect/-/issues/9))
- Internal: Use updated gradle plugin for tests ([#18](https://git-st.inf.tu-dresden.de/jastadd/ragconnect/-/issues/18))
- Bugfix [#22](https://git-st.inf.tu-dresden.de/jastadd/ragconnect/-/issues/22): Correct handling of malformed URIs passed when connecting an endpoint
- Bugfix [#23](https://git-st.inf.tu-dresden.de/jastadd/ragconnect/-/issues/23): Correct handling of OptComponents as endpoints
- Bugfix [#27](https://git-st.inf.tu-dresden.de/jastadd/ragconnect/-/issues/27): Correctly handle whitespaces in grammars
## 0.3.0
- Added [API documentation](ragdoc/index.html) to documentation
- Add methods to `disconnect` an endpoint
- Internal: PoC for incremental dependency tracking and subtree endpoint definitions ([#14](https://git-st.inf.tu-dresden.de/jastadd/ragconnect/-/issues/14))
- Bugfix [#17](https://git-st.inf.tu-dresden.de/jastadd/ragconnect/-/issues/17): Added missing support for `boolean`
...@@ -5,6 +5,7 @@ nav: ...@@ -5,6 +5,7 @@ nav:
- inner-workings.md - inner-workings.md
- using.md - using.md
- extending.md - extending.md
- changelog.md
- API documentation: ragdoc/index.html - API documentation: ragdoc/index.html
theme: theme:
name: readthedocs name: readthedocs
......
...@@ -27,11 +27,9 @@ repositories { ...@@ -27,11 +27,9 @@ repositories {
dependencies { dependencies {
implementation project(':relast-preprocessor') implementation project(':relast-preprocessor')
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: "${log4j_version}"
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: "${log4j_version}"
implementation group: 'org.apache.logging.log4j', name: 'log4j-jul', version: "${log4j_version}"
implementation group: 'com.github.spullara.mustache.java', name: 'compiler', version: "${mustache_java_version}" implementation group: 'com.github.spullara.mustache.java', name: 'compiler', version: "${mustache_java_version}"
runtimeOnly group: 'org.jastadd', name: 'jastadd', version: '2.3.5' // runtimeOnly group: 'org.jastadd', name: 'jastadd', version: '2.3.5'
runtimeOnly fileTree(include: ['jastadd2.jar'], dir: '../libs')
api group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' api group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
} }
...@@ -67,14 +65,12 @@ idea.module.generatedSourceDirs += genSrc ...@@ -67,14 +65,12 @@ idea.module.generatedSourceDirs += genSrc
jar { jar {
manifest { manifest {
attributes "Main-Class": 'org.jastadd.ragconnect.compiler.Compiler' attributes "Main-Class": 'org.jastadd.ragconnect.compiler.Compiler'
// Log4J + Java 11 compatibility, see https://stackoverflow.com/q/53049346/2493208
attributes "Multi-Release": true
} }
from { from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
} }
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveBaseName = 'ragconnect' archiveBaseName = 'ragconnect'
} }
...@@ -82,7 +78,7 @@ jar { ...@@ -82,7 +78,7 @@ jar {
File preprocessorGrammar = file('../relast-preprocessor/src/main/jastadd/RelAst.relast') File preprocessorGrammar = file('../relast-preprocessor/src/main/jastadd/RelAst.relast')
File ragConnectGrammar = file('./src/main/jastadd/RagConnect.relast') File ragConnectGrammar = file('./src/main/jastadd/RagConnect.relast')
File intermediateGrammar = file('./src/main/jastadd/intermediate/MustacheNodes.relast') File intermediateGrammar = file('./src/main/jastadd/intermediate/MustacheNodes.relast')
File mustacheGrammar = file('./src/main/jastadd/mustache/Mustache.relast') File mustacheGrammar = file('../relast-preprocessor/src/main/jastadd/mustache/Mustache.relast')
task relast(type: JavaExec) { task relast(type: JavaExec) {
group = 'Build' group = 'Build'
main = "-jar" main = "-jar"
...@@ -224,3 +220,4 @@ publishing { ...@@ -224,3 +220,4 @@ publishing {
} }
publish.dependsOn jar publish.dependsOn jar
jar.dependsOn ":relast-preprocessor:jar"
aspect Analysis { aspect Analysis {
// --- lookupTokenEndpointDefinition --- // --- lookupTokenEndpointDefinition ---
inh java.util.List<TokenEndpointDefinition> TokenEndpointDefinition.lookupTokenEndpointDefinitions(TokenComponent token); inh java.util.List<TokenEndpointDefinition> TokenEndpointDefinition.lookupTokenEndpointDefinitions(TokenComponent token);
eq RagConnect.getEndpointDefinition().lookupTokenEndpointDefinitions(TokenComponent token) = lookupTokenEndpointDefinitions(token); eq RagConnect.getConnectSpecificationFile().lookupTokenEndpointDefinitions(TokenComponent token) = lookupTokenEndpointDefinitions(token);
syn java.util.List<TokenEndpointDefinition> RagConnect.lookupTokenEndpointDefinitions(TokenComponent token) { syn java.util.List<TokenEndpointDefinition> RagConnect.lookupTokenEndpointDefinitions(TokenComponent token) {
java.util.List<TokenEndpointDefinition> result = new java.util.ArrayList<>(); java.util.List<TokenEndpointDefinition> result = new java.util.ArrayList<>();
for (EndpointDefinition def : getEndpointDefinitionList()) { for (EndpointDefinition def : allEndpointDefinitionList()) {
if (def.isTokenEndpointDefinition() && def.asTokenEndpointDefinition().getToken().equals(token)) { if (def.isTokenEndpointDefinition() && def.asTokenEndpointDefinition().getToken().equals(token)) {
result.add(def.asTokenEndpointDefinition()); result.add(def.asTokenEndpointDefinition());
} }
...@@ -14,10 +14,10 @@ aspect Analysis { ...@@ -14,10 +14,10 @@ aspect Analysis {
// --- lookupTypeEndpointDefinition --- // --- lookupTypeEndpointDefinition ---
inh java.util.List<TypeEndpointDefinition> TypeEndpointDefinition.lookupTypeEndpointDefinitions(TypeComponent type); inh java.util.List<TypeEndpointDefinition> TypeEndpointDefinition.lookupTypeEndpointDefinitions(TypeComponent type);
eq RagConnect.getEndpointDefinition().lookupTypeEndpointDefinitions(TypeComponent type) = lookupTypeEndpointDefinitions(type); eq RagConnect.getConnectSpecificationFile().lookupTypeEndpointDefinitions(TypeComponent type) = lookupTypeEndpointDefinitions(type);
syn java.util.List<TypeEndpointDefinition> RagConnect.lookupTypeEndpointDefinitions(TypeComponent type) { syn java.util.List<TypeEndpointDefinition> RagConnect.lookupTypeEndpointDefinitions(TypeComponent type) {
java.util.List<TypeEndpointDefinition> result = new java.util.ArrayList<>(); java.util.List<TypeEndpointDefinition> result = new java.util.ArrayList<>();
for (EndpointDefinition def : getEndpointDefinitionList()) { for (EndpointDefinition def : allEndpointDefinitionList()) {
if (def.isTypeEndpointDefinition() && def.asTypeEndpointDefinition().getType().equals(type)) { if (def.isTypeEndpointDefinition() && def.asTypeEndpointDefinition().getType().equals(type)) {
result.add(def.asTypeEndpointDefinition()); result.add(def.asTypeEndpointDefinition());
} }
...@@ -27,8 +27,8 @@ aspect Analysis { ...@@ -27,8 +27,8 @@ aspect Analysis {
// --- lookupDependencyDefinition --- // --- lookupDependencyDefinition ---
inh DependencyDefinition DependencyDefinition.lookupDependencyDefinition(TypeDecl source, String id); inh DependencyDefinition DependencyDefinition.lookupDependencyDefinition(TypeDecl source, String id);
eq RagConnect.getDependencyDefinition().lookupDependencyDefinition(TypeDecl source, String id) { eq RagConnect.getConnectSpecificationFile().lookupDependencyDefinition(TypeDecl source, String id) {
for (DependencyDefinition def : getDependencyDefinitionList()) { for (DependencyDefinition def : allDependencyDefinitionList()) {
if (def.getID().equals(id) && def.getSource().containingTypeDecl().equals(source)) { if (def.getID().equals(id) && def.getSource().containingTypeDecl().equals(source)) {
return def; return def;
} }
......
aspect Configuration { aspect Configuration {
public static boolean ASTNode.loggingEnabledForReads = false; public static boolean ASTNode.loggingEnabledForReads = false;
public static boolean ASTNode.loggingEnabledForWrites = false; public static boolean ASTNode.loggingEnabledForWrites = false;
public static boolean ASTNode.loggingEnabledForIncremental = false;
public static TypeDecl ASTNode.rootNode; public static TypeDecl ASTNode.rootNode;
public static boolean ASTNode.usesMqtt; public static boolean ASTNode.usesMqtt;
public static boolean ASTNode.usesRest; public static boolean ASTNode.usesRest;
public static boolean ASTNode.incrementalOptionActive; public static boolean ASTNode.incrementalOptionActive;
public static boolean ASTNode.experimentalJastAdd329;
} }
...@@ -2,7 +2,7 @@ aspect NameResolution { ...@@ -2,7 +2,7 @@ aspect NameResolution {
refine RefResolverStubs eq EndpointDefinition.resolveMappingByToken(String id, int position) { refine RefResolverStubs eq EndpointDefinition.resolveMappingByToken(String id, int position) {
// return a MappingDefinition // return a MappingDefinition
for (MappingDefinition mappingDefinition : ragconnect().getMappingDefinitionList()) { for (MappingDefinition mappingDefinition : ragconnect().allMappingDefinitionList()) {
if (mappingDefinition.getID().equals(id)) { if (mappingDefinition.getID().equals(id)) {
return mappingDefinition; return mappingDefinition;
} }
......
aspect Navigation { import java.util.List;
import java.util.ArrayList;
aspect RagConnectNavigation {
// --- program --- // --- program ---
eq RagConnect.getChild().program() = getProgram(); eq RagConnect.getChild().program() = getProgram();
...@@ -9,15 +12,54 @@ aspect Navigation { ...@@ -9,15 +12,54 @@ aspect Navigation {
eq RagConnect.getChild().ragconnect() = this; eq RagConnect.getChild().ragconnect() = this;
eq MRagConnect.getChild().ragconnect() = getRagConnect(); eq MRagConnect.getChild().ragconnect() = getRagConnect();
// --- containedConnectSpecification ---
inh ConnectSpecification ASTNode.containedConnectSpecification();
eq RagConnect.getChild().containedConnectSpecification() = null;
eq MRagConnect.getChild().containedConnectSpecification() = null;
eq Document.getChild().containedConnectSpecification() = null;
eq Program.getChild().containedConnectSpecification() = null;
eq ConnectSpecification.getChild().containedConnectSpecification() = this;
// --- containedFile // --- containedFile
eq Grammar.getChild().containedFile() = null;
eq RagConnect.getChild().containedFile() = null; eq RagConnect.getChild().containedFile() = null;
eq MRagConnect.getChild().containedFile() = null; eq MRagConnect.getChild().containedFile() = null;
// --- containedFileName --- // --- containedFileName ---
eq Grammar.getChild().containedFileName() = null; // should be in PP eq ConnectSpecificationFile.containedFileName() = getFileName();
eq RagConnect.getChild().containedFileName() = getFileName(); refine Navigation eq ASTNode.containedFileName() {
eq MRagConnect.getChild().containedFileName() = null; if (containedFile() == null) {
return containedConnectSpecification().containedFileName();
}
return refined();
// return containedFile().getFileName();
}
//--- allEndpointDefinitionList ---
syn List<EndpointDefinition> RagConnect.allEndpointDefinitionList() {
List<EndpointDefinition> result = new ArrayList<>();
for (var spec : getConnectSpecificationFileList()) {
spec.getEndpointDefinitionList().forEach(result::add);
}
return result;
}
//--- allDependencyDefinitionList ---
syn List<DependencyDefinition> RagConnect.allDependencyDefinitionList() {
List<DependencyDefinition> result = new ArrayList<>();
for (var spec : getConnectSpecificationFileList()) {
spec.getDependencyDefinitionList().forEach(result::add);
}
return result;
}
//--- allMappingDefinitionList ---
syn List<MappingDefinition> RagConnect.allMappingDefinitionList() {
List<MappingDefinition> result = new ArrayList<>();
for (var spec : getConnectSpecificationFileList()) {
spec.getMappingDefinitionList().forEach(result::add);
}
return result;
}
// --- isTokenEndpointDefinition --- // --- isTokenEndpointDefinition ---
syn boolean EndpointDefinition.isTokenEndpointDefinition() = false; syn boolean EndpointDefinition.isTokenEndpointDefinition() = false;
...@@ -70,7 +112,7 @@ aspect Navigation { ...@@ -70,7 +112,7 @@ aspect Navigation {
// --- targetEndpointDefinition --- // --- targetEndpointDefinition ---
syn EndpointDefinition DependencyDefinition.targetEndpointDefinition() { syn EndpointDefinition DependencyDefinition.targetEndpointDefinition() {
// resolve definition in here, as we do not need resolveMethod in any other place (yet) // resolve definition in here, as we do not need resolveMethod in any other place (yet)
for (EndpointDefinition endpointDefinition : ragconnect().getEndpointDefinitionList()) { for (EndpointDefinition endpointDefinition : ragconnect().allEndpointDefinitionList()) {
if (endpointDefinition.isSendTokenEndpointDefinition() && if (endpointDefinition.isSendTokenEndpointDefinition() &&
endpointDefinition.asSendTokenEndpointDefinition().getToken().equals(this.getTarget())) { endpointDefinition.asSendTokenEndpointDefinition().getToken().equals(this.getTarget())) {
return endpointDefinition; return endpointDefinition;
...@@ -96,4 +138,7 @@ aspect Navigation { ...@@ -96,4 +138,7 @@ aspect Navigation {
// --- rootTypeComponents --- // --- rootTypeComponents ---
syn JastAddList<MTypeComponent> MHandler.rootTypeComponents() = mragconnect().getRootTypeComponents(); syn JastAddList<MTypeComponent> MHandler.rootTypeComponents() = mragconnect().getRootTypeComponents();
// --- isListComponent --- (defined in PP, but only on TypeComponent)
syn boolean Component.isListComponent() = false;
} }
RagConnect ::= EndpointDefinition* DependencyDefinition* MappingDefinition* Program <FileName> ; RagConnect ::= ConnectSpecificationFile* Program ;
abstract ConnectSpecification ::= EndpointDefinition* DependencyDefinition* MappingDefinition* ;
ConnectSpecificationFile : ConnectSpecification ::= <FileName> ;
abstract EndpointDefinition ::= <AlwaysApply:boolean> ; abstract EndpointDefinition ::= <AlwaysApply:boolean> ;
......
...@@ -62,12 +62,17 @@ aspect AttributesForMustache { ...@@ -62,12 +62,17 @@ aspect AttributesForMustache {
syn String MEndpointDefinition.lastDefinitionToType() = lastDefinition().toType(); syn String MEndpointDefinition.lastDefinitionToType() = lastDefinition().toType();
syn String MEndpointDefinition.lastResult() = lastDefinition().outputVarName(); syn String MEndpointDefinition.lastResult() = lastDefinition().outputVarName();
syn String MEndpointDefinition.condition() { syn String MEndpointDefinition.condition() {
// TODO probably, this has to be structured in a better way
if (lastDefinition().mappingDef().getToType().isArray()) { if (lastDefinition().mappingDef().getToType().isArray()) {
return "java.util.Arrays.equals(" + preemptiveExpectedValue() + ", " + lastResult() + ")"; return "java.util.Arrays.equals(" + preemptiveExpectedValue() + ", " + lastResult() + ")";
} }
if (endpointDef().isTokenEndpointDefinition() && token().isPrimitiveType() && lastDefinition().mappingDef().getToType().isPrimitiveType()) { if (endpointDef().isTokenEndpointDefinition() && token().isPrimitiveType() && lastDefinition().mappingDef().getToType().isPrimitiveType()) {
return preemptiveExpectedValue() + " == " + lastResult(); return preemptiveExpectedValue() + " == " + lastResult();
} }
if (endpointDef().isTypeEndpointDefinition() && type().isOptComponent()) {
// use "hasX()" instead of "getX() != null" for optionals
return "has" + typeName() + "()" + " && " + preemptiveExpectedValue() + ".equals(" + lastResult() + ")";
}
if (lastDefinition().mappingDef().getToType().isPrimitiveType() || lastDefinition().mappingDef().isDefaultMappingDefinition()) { if (lastDefinition().mappingDef().getToType().isPrimitiveType() || lastDefinition().mappingDef().isDefaultMappingDefinition()) {
return preemptiveExpectedValue() + " != null && " + preemptiveExpectedValue() + ".equals(" + lastResult() + ")"; return preemptiveExpectedValue() + " != null && " + preemptiveExpectedValue() + ".equals(" + lastResult() + ")";
} }
...@@ -172,7 +177,7 @@ aspect AttributesForMustache { ...@@ -172,7 +177,7 @@ aspect AttributesForMustache {
syn lazy MRagConnect RagConnect.toMustache() { syn lazy MRagConnect RagConnect.toMustache() {
MRagConnect result = new MRagConnect(); MRagConnect result = new MRagConnect();
result.setRagConnect(this); result.setRagConnect(this);
for (EndpointDefinition def : getEndpointDefinitionList()) { for (EndpointDefinition def : allEndpointDefinitionList()) {
if (def.isReceiveTokenEndpointDefinition()) { if (def.isReceiveTokenEndpointDefinition()) {
result.addTokenReceiveDefinition(def.asReceiveTokenEndpointDefinition().toMustache()); result.addTokenReceiveDefinition(def.asReceiveTokenEndpointDefinition().toMustache());
} else if (def.isSendTokenEndpointDefinition()) { } else if (def.isSendTokenEndpointDefinition()) {
...@@ -188,7 +193,7 @@ aspect AttributesForMustache { ...@@ -188,7 +193,7 @@ aspect AttributesForMustache {
for (MappingDefinition def : allMappingDefinitions()) { for (MappingDefinition def : allMappingDefinitions()) {
result.addMappingDefinition(def.toMustache()); result.addMappingDefinition(def.toMustache());
} }
for (DependencyDefinition def : getDependencyDefinitionList()) { for (DependencyDefinition def : allDependencyDefinitionList()) {
result.addDependencyDefinition(def.toMustache()); result.addDependencyDefinition(def.toMustache());
} }
for (TokenComponent token : getProgram().allTokenComponents()) { for (TokenComponent token : getProgram().allTokenComponents()) {
...@@ -311,7 +316,7 @@ aspect AspectGeneration { ...@@ -311,7 +316,7 @@ aspect AspectGeneration {
aspect RelationGeneration { aspect RelationGeneration {
syn java.util.List<Relation> RagConnect.additionalRelations() { syn java.util.List<Relation> RagConnect.additionalRelations() {
java.util.List<Relation> result = new java.util.ArrayList<>(); java.util.List<Relation> result = new java.util.ArrayList<>();
for (DependencyDefinition dd : getDependencyDefinitionList()) { for (DependencyDefinition dd : allDependencyDefinitionList()) {
result.add(dd.getRelationToCreate()); result.add(dd.getRelationToCreate());
} }
return result; return result;
......
...@@ -298,7 +298,7 @@ aspect Mappings { ...@@ -298,7 +298,7 @@ aspect Mappings {
syn java.util.List<MappingDefinition> RagConnect.allMappingDefinitions() { syn java.util.List<MappingDefinition> RagConnect.allMappingDefinitions() {
java.util.List<MappingDefinition> result = new java.util.ArrayList<>(); java.util.List<MappingDefinition> result = new java.util.ArrayList<>();
// user-defined mappings // user-defined mappings
getMappingDefinitionList().iterator().forEachRemaining(result::add); allMappingDefinitionList().iterator().forEachRemaining(result::add);
// byte[] <-> primitive conversion // byte[] <-> primitive conversion
result.add(defaultBytesToBooleanMapping()); result.add(defaultBytesToBooleanMapping());
result.add(defaultBytesToIntMapping()); result.add(defaultBytesToIntMapping());
......
...@@ -206,5 +206,5 @@ aspect Navigation { ...@@ -206,5 +206,5 @@ aspect Navigation {
eq Document.getChild().program() = null; eq Document.getChild().program() = null;
eq Document.getChild().ragconnect() = null; eq Document.getChild().ragconnect() = null;
eq Document.getChild().containedFile() = null; eq Document.getChild().containedFile() = null;
eq Document.getChild().containedFileName() = getFileName(); eq Document.containedFileName() = getFileName();
} }
Subproject commit c10bed0d03e3fa18b8133ce1de48de7646899615
...@@ -4,4 +4,4 @@ import org.jastadd.ragconnect.ast.*; ...@@ -4,4 +4,4 @@ import org.jastadd.ragconnect.ast.*;
:}; :};
%goal goal; %goal goal;
%goal ragconnect; %goal connect_specification_file;
RagConnect ragconnect ConnectSpecificationFile connect_specification_file
= endpoint_definition.d ragconnect.r {: r.getEndpointDefinitionList().insertChild(d, 0); return r; :} = endpoint_definition.d connect_specification_file.r
| dependency_definition.d ragconnect.r {: r.getDependencyDefinitionList().insertChild(d, 0); return r; :} {:
| mapping_definition.d ragconnect.r {: r.getMappingDefinitionList().insertChild(d, 0); return r; :} r.getEndpointDefinitionList().insertChild(d, 0); return r;
| comment ragconnect.r {: return r; :} :}
| {: return new RagConnect(); :} | dependency_definition.d connect_specification_file.r
{:
r.getDependencyDefinitionList().insertChild(d, 0); return r;
:}
| mapping_definition.d connect_specification_file.r
{:
r.getMappingDefinitionList().insertChild(d, 0); return r;
:}
| comment connect_specification_file.r
{:
return r;
:}
| {: return new ConnectSpecificationFile(); :}
; ;
%embed {: %embed {:
......
...@@ -3,11 +3,11 @@ package org.jastadd.ragconnect.compiler; ...@@ -3,11 +3,11 @@ package org.jastadd.ragconnect.compiler;
import beaver.Parser; import beaver.Parser;
import org.jastadd.option.BooleanOption; import org.jastadd.option.BooleanOption;
import org.jastadd.option.ValueOption; import org.jastadd.option.ValueOption;
import org.jastadd.relast.compiler.AbstractCompiler;
import org.jastadd.relast.compiler.CompilerException;
import org.jastadd.ragconnect.ast.*; import org.jastadd.ragconnect.ast.*;
import org.jastadd.ragconnect.parser.RagConnectParser; import org.jastadd.ragconnect.parser.RagConnectParser;
import org.jastadd.ragconnect.scanner.RagConnectScanner; import org.jastadd.ragconnect.scanner.RagConnectScanner;
import org.jastadd.relast.compiler.AbstractCompiler;
import org.jastadd.relast.compiler.CompilerException;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
...@@ -15,6 +15,8 @@ import java.nio.file.Path; ...@@ -15,6 +15,8 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.*; import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Compiler extends AbstractCompiler { public class Compiler extends AbstractCompiler {
...@@ -25,10 +27,14 @@ public class Compiler extends AbstractCompiler { ...@@ -25,10 +27,14 @@ public class Compiler extends AbstractCompiler {
private BooleanOption optionVerbose; private BooleanOption optionVerbose;
private BooleanOption optionLogReads; private BooleanOption optionLogReads;
private BooleanOption optionLogWrites; private BooleanOption optionLogWrites;
private BooleanOption optionLogIncremental;
private BooleanOption optionExperimentalJastAdd329;
private static final String OPTION_PROTOCOL_MQTT = "mqtt"; private static final String OPTION_PROTOCOL_MQTT = "mqtt";
private static final String OPTION_PROTOCOL_REST = "rest"; private static final String OPTION_PROTOCOL_REST = "rest";
private final static Logger LOGGER = Logger.getLogger(Compiler.class.getName());
public Compiler() { public Compiler() {
super("ragconnect", true); super("ragconnect", true);
} }
...@@ -43,8 +49,11 @@ public class Compiler extends AbstractCompiler { ...@@ -43,8 +49,11 @@ public class Compiler extends AbstractCompiler {
getConfiguration().printHelp(System.out); getConfiguration().printHelp(System.out);
return 0; return 0;
} }
if (optionVerbose.value()) {
LOGGER.setLevel(Level.FINE);
}
printMessage("Running RagConnect " + readVersion()); LOGGER.info(() -> "Running RagConnect " + readVersion());
if (!getConfiguration().outputDir().exists()) { if (!getConfiguration().outputDir().exists()) {
try { try {
...@@ -61,10 +70,11 @@ public class Compiler extends AbstractCompiler { ...@@ -61,10 +70,11 @@ public class Compiler extends AbstractCompiler {
RagConnect ragConnect = parseProgram(getConfiguration().getFiles()); RagConnect ragConnect = parseProgram(getConfiguration().getFiles());
if (!ragConnect.errors().isEmpty()) { if (!ragConnect.errors().isEmpty()) {
System.err.println("Errors:"); StringBuilder sb = new StringBuilder("Errors:\n");
for (ErrorMessage e : ragConnect.errors()) { for (ErrorMessage e : ragConnect.errors()) {
System.err.println(e); sb.append(e).append("\n");
} }
LOGGER.severe(sb::toString);
System.exit(1); System.exit(1);
} }
...@@ -76,7 +86,7 @@ public class Compiler extends AbstractCompiler { ...@@ -76,7 +86,7 @@ public class Compiler extends AbstractCompiler {
return 0; return 0;
} }
printMessage("Writing output files"); LOGGER.fine("Writing output files");
final List<String> handlers = new ArrayList<>(); final List<String> handlers = new ArrayList<>();
if (ASTNode.usesMqtt) { if (ASTNode.usesMqtt) {
handlers.add("MqttHandler.jadd"); handlers.add("MqttHandler.jadd");
...@@ -107,12 +117,11 @@ public class Compiler extends AbstractCompiler { ...@@ -107,12 +117,11 @@ public class Compiler extends AbstractCompiler {
} }
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");
System.setProperty("mustache.debug", "true"); System.setProperty("mustache.debug", "true");
try { try {
new Compiler().run(args); new Compiler().run(args);
} catch (CompilerException e) { } catch (CompilerException e) {
e.printStackTrace(); LOGGER.log(Level.SEVERE, e.getMessage(), e);
System.exit(1); System.exit(1);
} }
} }
...@@ -137,12 +146,6 @@ public class Compiler extends AbstractCompiler { ...@@ -137,12 +146,6 @@ public class Compiler extends AbstractCompiler {
} }
} }
private void printMessage(String message) {
if (optionVerbose.value()) {
System.out.println(message);
}
}
private void writeToFile(Path path, String str) throws CompilerException { private void writeToFile(Path path, String str) throws CompilerException {
try (BufferedWriter writer = Files.newBufferedWriter(path)) { try (BufferedWriter writer = Files.newBufferedWriter(path)) {
writer.append(str); writer.append(str);
...@@ -175,6 +178,12 @@ public class Compiler extends AbstractCompiler { ...@@ -175,6 +178,12 @@ public class Compiler extends AbstractCompiler {