From c6cb79c8d71061ec7ed48231734c1c681db32c47 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 27 Jul 2023 07:34:47 +0200 Subject: [PATCH] [DEV] rework to Maven --- .classpath | 21 ++- ...clipsecs.core.CheckstyleBuilder (2).launch | 7 + .project | 13 +- pom.xml | 129 ++++++++++++++++++ src/org/atriasoft/ejson/Ejson.java | 8 +- src/org/atriasoft/ejson/JsonMapper.java | 8 +- .../ejson/builder/BuilderIntrospection.java | 47 ++++--- .../ejson/builder/IntrospectionObject.java | 23 ++-- src/org/atriasoft/ejson/internal/Log.java | 81 ----------- src/org/atriasoft/ejson/model/JsonArray.java | 9 +- src/org/atriasoft/ejson/model/JsonObject.java | 7 +- src/org/atriasoft/ejson/parser/ParseJson.java | 7 +- .../ejson/parser/ParsingProperty.java | 7 +- test/resources/simplelogger.properties | 35 +++++ .../atriasoft/ejson/generic/EjsonLocal.java | 7 +- .../atriasoft/ejson/generic/EjsonTestAll.java | 6 +- .../ejson/generic/EjsonTestBoolean.java | 6 +- .../ejson/generic/EjsonTestNull.java | 6 +- .../ejson/generic/EjsonTestNumber.java | 6 +- .../test/atriasoft/ejson/internal/Log.java | 82 ----------- .../introspection/EjsonTestIntrospection.java | 6 +- 21 files changed, 286 insertions(+), 235 deletions(-) create mode 100644 .externalToolBuilders/net.sf.eclipsecs.core.CheckstyleBuilder (2).launch create mode 100644 pom.xml delete mode 100644 src/org/atriasoft/ejson/internal/Log.java create mode 100644 test/resources/simplelogger.properties delete mode 100644 test/src/test/atriasoft/ejson/internal/Log.java diff --git a/.classpath b/.classpath index 6c4f306..bd326c0 100644 --- a/.classpath +++ b/.classpath @@ -1,19 +1,21 @@ - + + - + + - + - + @@ -21,15 +23,10 @@ - + - + - - - - - - + diff --git a/.externalToolBuilders/net.sf.eclipsecs.core.CheckstyleBuilder (2).launch b/.externalToolBuilders/net.sf.eclipsecs.core.CheckstyleBuilder (2).launch new file mode 100644 index 0000000..1ee8204 --- /dev/null +++ b/.externalToolBuilders/net.sf.eclipsecs.core.CheckstyleBuilder (2).launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.project b/.project index 42c4cb7..efaf6cf 100644 --- a/.project +++ b/.project @@ -17,12 +17,23 @@ - net.sf.eclipsecs.core.CheckstyleBuilder + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/net.sf.eclipsecs.core.CheckstyleBuilder (2).launch + + + + + org.eclipse.m2e.core.maven2Builder + org.eclipse.m2e.core.maven2Nature org.eclipse.jdt.core.javanature net.sf.eclipsecs.core.CheckstyleNature org.python.pydev.pythonNature diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..bcc1acb --- /dev/null +++ b/pom.xml @@ -0,0 +1,129 @@ + + 4.0.0 + jatria-soft + ejson + 0.1.0 + + 3.1 + 17 + 17 + + 3.1.1 + + + + + gitea + https://gitea.atria-soft.org/api/packages/jatria-soft/maven + + + + + gitea + https://gitea.atria-soft.org/api/packages/jatria-soft/maven + + + gitea + https://gitea.atria-soft.org/api/packages/jatria-soft/maven + + + + + + jatria-soft + etk + 0.1.0 + + + jatria-soft + aknot + 0.1.0 + + + org.junit.jupiter + junit-jupiter-api + 5.9.3 + test + + + org.slf4j + slf4j-simple + 2.0.7 + test + + + + + src + test/src + ${project.basedir}/out/maven/ + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M5 + + + maven-assembly-plugin + + + + fully.qualified.MainClass + + + + jar-with-dependencies + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + private + true + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + public + + + + + + diff --git a/src/org/atriasoft/ejson/Ejson.java b/src/org/atriasoft/ejson/Ejson.java index ed4b0b7..a2b32ce 100644 --- a/src/org/atriasoft/ejson/Ejson.java +++ b/src/org/atriasoft/ejson/Ejson.java @@ -11,20 +11,22 @@ import org.atriasoft.ejson.builder.BuilderGeneric; import org.atriasoft.ejson.exception.EjsonBuilderException; import org.atriasoft.ejson.exception.EjsonParserErrorMulti; import org.atriasoft.ejson.generator.GeneratorGeneric; -import org.atriasoft.ejson.internal.Log; import org.atriasoft.ejson.model.JsonNode; import org.atriasoft.ejson.parser.ParseJson; import org.atriasoft.ejson.parser.ParsingProperty; import org.atriasoft.etk.Uri; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class Ejson { + final static Logger LOGGER = LoggerFactory.getLogger(Ejson.class); /** * Display the Document on console */ public static void display(final JsonNode root) { final StringBuilder tmpp = new StringBuilder(); GeneratorGeneric.serialize(root, tmpp, 0); - Log.info("Generated JSON : \n{}", tmpp.toString()); + LOGGER.info("Generated JSON : \n{}", tmpp.toString()); } /** @@ -51,7 +53,7 @@ public class Ejson { property.setDisplayError(true); final byte[] elemData = Uri.getAllData(data); if (elemData == null) { - Log.error("Can not read the Stream : {}", data); + LOGGER.error("Can not read the Stream : {}", data); return null; } final String dataToParse = new String(elemData); diff --git a/src/org/atriasoft/ejson/JsonMapper.java b/src/org/atriasoft/ejson/JsonMapper.java index 2a5aa52..53cb8b3 100644 --- a/src/org/atriasoft/ejson/JsonMapper.java +++ b/src/org/atriasoft/ejson/JsonMapper.java @@ -13,12 +13,14 @@ import org.atriasoft.ejson.builder.BuilderIntrospection; import org.atriasoft.ejson.builder.IntrospectionObject; import org.atriasoft.ejson.exception.EjsonException; import org.atriasoft.ejson.exception.EjsonNodeDoesNotExist; -import org.atriasoft.ejson.internal.Log; import org.atriasoft.ejson.parser.ParseJson; import org.atriasoft.ejson.parser.ParsingProperty; import org.atriasoft.etk.Uri; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class JsonMapper { + final static Logger LOGGER = LoggerFactory.getLogger(JsonMapper.class); private static String readFile(final Path path, final Charset encoding) throws IOException { final byte[] encoded = Files.readAllBytes(path); @@ -67,7 +69,7 @@ public class JsonMapper { final IntrospectionObject introspectionObject = (IntrospectionObject) parser.parse(data, property); introspectionObject.generateTheObject(true); final Object listRet = introspectionObject.getData(); - Log.error("elements: {} , {}", listRet.getClass(), classType); + LOGGER.error("elements: {} , {}", listRet.getClass(), classType); if (listRet != null && !listRet.getClass().isArray() && listRet.getClass() == classType) { return (T) listRet; } else if (listRet != null && listRet.getClass().isArray() && listRet.getClass().componentType() == classType) { @@ -97,7 +99,7 @@ public class JsonMapper { final byte[] elemData = Uri.getAllData(uri); if (elemData == null) { - Log.error("Can not read the Stream : " + uri); + LOGGER.error("Can not read the Stream : " + uri); return null; } final String content = new String(elemData); diff --git a/src/org/atriasoft/ejson/builder/BuilderIntrospection.java b/src/org/atriasoft/ejson/builder/BuilderIntrospection.java index 91ff880..5954359 100644 --- a/src/org/atriasoft/ejson/builder/BuilderIntrospection.java +++ b/src/org/atriasoft/ejson/builder/BuilderIntrospection.java @@ -13,12 +13,15 @@ import org.atriasoft.aknot.exception.AknotException; import org.atriasoft.aknot.model.IntrospectionModel; import org.atriasoft.aknot.model.ModelType; import org.atriasoft.aknot.pojo.CacheIntrospectionModel; +import org.atriasoft.aknot.pojo.IntrospectionProperty; import org.atriasoft.ejson.exception.EjsonBuilderException; import org.atriasoft.ejson.exception.EjsonException; import org.atriasoft.ejson.exception.EjsonNodeDoesNotExist; -import org.atriasoft.ejson.internal.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class BuilderIntrospection implements Builder { + final static Logger LOGGER = LoggerFactory.getLogger(BuilderIntrospection.class); // Keep in cach all the object alredy parsed ==> optimize CPU CacheIntrospectionModel cacheModel = new CacheIntrospectionModel(); // The root class (need to keep it if we use 2 time the builder, the root class is no more accessible). @@ -33,7 +36,7 @@ public class BuilderIntrospection implements Builder { @Override public void endParsing(final Object element) throws EjsonBuilderException, AknotException { - Log.verbose("End of Element: {}", element); + LOGGER.trace("End of Element: {}", element); if (element == null) { return; } @@ -63,13 +66,13 @@ public class BuilderIntrospection implements Builder { if (parent == null) { return null; } - Log.verbose("new element on NodeName=" + nodeName); + LOGGER.trace("new element on NodeName=" + nodeName); final IntrospectionObject introspectionObject = (IntrospectionObject) parent; final IntrospectionModel model = introspectionObject.getModelIntrospection(); Class typeClass = null; String listTreeName = null; if (!introspectionObject.isSubNodeOrPropertyExist(nodeName) && model.isIgnoreUnknown()) { - Log.debug("Ignore array: '" + nodeName + "', it does not exist."); + LOGGER.debug("Ignore array: '" + nodeName + "', it does not exist."); return null; } try { @@ -86,7 +89,7 @@ public class BuilderIntrospection implements Builder { // specific case for List ==> need to get the subType in introspection ... if (typeClass.isArray()) { final Class subTypeClass = typeClass.getComponentType(); - Log.verbose("Create array new 'SUB' class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); + LOGGER.trace("Create array new 'SUB' class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); IntrospectionModel inferData = null; inferData = this.cacheModel.findOrCreate(ModelType.LIST, listTreeName, subTypeClass); // Create the data when object is ended created... @@ -99,13 +102,13 @@ public class BuilderIntrospection implements Builder { } catch (final AknotException e) { throw new EjsonBuilderException("Node does not exist: " + e.getMessage()); } - Log.verbose("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); + LOGGER.trace("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); IntrospectionModel inferData = null; inferData = this.cacheModel.findOrCreate(ModelType.LIST, listTreeName, subTypeClass); // Create the data when object is ended created... return new IntrospectionObject(inferData); } - Log.verbose("Create new class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); + LOGGER.trace("Create new class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, typeClass); // Create the data when object is ended created... return new IntrospectionObject(inferData); @@ -115,7 +118,7 @@ public class BuilderIntrospection implements Builder { @Override public void newArrayFinished(final Object parent, String tmpName, final Object element) throws EjsonException, AknotException { - Log.error("New element fionished : ==> " + tmpName); + LOGGER.error("New element fionished : ==> " + tmpName); if (parent == null || element == null) { return; } @@ -279,7 +282,7 @@ public class BuilderIntrospection implements Builder { throw new EjsonBuilderException("Object created inside a non list ... ==> impssible case"); } final Class typeClass = model.getClassType(); - Log.verbose("Create new class: '" + typeClass.getCanonicalName() + "'"); + LOGGER.trace("Create new class: '" + typeClass.getCanonicalName() + "'"); final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, typeClass); // Create the data when object is ended created... return new IntrospectionObject(inferData); @@ -289,7 +292,7 @@ public class BuilderIntrospection implements Builder { @Override public Object newObject(final Object parent, final String nodeName) throws EjsonException, AknotException { - Log.verbose("new element on NodeName=" + nodeName); + LOGGER.trace("new element on NodeName=" + nodeName); final IntrospectionObject introspectionObject = (IntrospectionObject) parent; final IntrospectionModel model = introspectionObject.getModelIntrospection(); Class typeClass = null; @@ -298,7 +301,7 @@ public class BuilderIntrospection implements Builder { throw new EjsonBuilderException("Object is not compatible with an requested array: " + nodeName); } else { if (!introspectionObject.isSubNodeOrPropertyExist(nodeName) && model.isIgnoreUnknown()) { - Log.debug("Ignore node: '" + nodeName + "' Does not exist..."); + LOGGER.debug("Ignore node: '" + nodeName + "' Does not exist..."); return null; } try { @@ -312,7 +315,7 @@ public class BuilderIntrospection implements Builder { // specific case for List ==> need to get the subType in introspection ... if (typeClass.isArray()) { final Class subTypeClass = typeClass.getComponentType(); - Log.verbose("Create array new 'SUB' class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); + LOGGER.trace("Create array new 'SUB' class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); IntrospectionModel inferData = null; // when we request a list elements, we need to add the element in a list, then we need the return is LIST and not ARRAY inferData = this.cacheModel.findOrCreate(ModelType.LIST, listTreeName, subTypeClass); @@ -327,13 +330,13 @@ public class BuilderIntrospection implements Builder { } catch (final AknotException e) { throw new EjsonBuilderException("Node does not exist: " + e.getMessage()); } - Log.verbose("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); + LOGGER.trace("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); IntrospectionModel inferData = null; inferData = this.cacheModel.findOrCreate(ModelType.LIST, listTreeName, subTypeClass); // Create the data when object is ended created... return new IntrospectionObject(inferData); } - Log.verbose("Create new class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); + LOGGER.trace("Create new class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, listTreeName, typeClass); // Create the data when object is ended created... return new IntrospectionObject(inferData); @@ -361,7 +364,7 @@ public class BuilderIntrospection implements Builder { final String beanName = model.getTextBeanName(); if (beanName == null) { if (model.isIgnoreUnknown()) { - Log.debug("Ignore node : **TEXT**"); + LOGGER.debug("Ignore node : **TEXT**"); return; } throw new EjsonBuilderException("The node **TEXT** Does not exist..."); @@ -373,7 +376,7 @@ public class BuilderIntrospection implements Builder { final Object out = StringSerializer.valueOf(typeClass, value); introspectionObject.putProperty(beanName, out); } else if (typeClass.isArray()) { - Log.error("Not managed !!! "); + LOGGER.error("Not managed !!! "); /* final String[] elems = propertyValue.split(";"); final Class subTypeClass = typeClass.getComponentType(); @@ -386,11 +389,11 @@ public class BuilderIntrospection implements Builder { introspectionObject.putProperty(propertyName, out); */ } else if (List.class.isAssignableFrom(typeClass)) { - Log.error("Not managed !!! "); + LOGGER.error("Not managed !!! "); /* final String[] elems = propertyValue.split(";"); final Class subTypeClass = introspectionObject.getTypeOfSubProperty(propertyName); - Log.verbose("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + propertyName + "'"); + LOGGER.trace("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + propertyName + "'"); final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass); final List out = new ArrayList<>(); for (int iii = 0; iii < elems.length; iii++) { @@ -400,7 +403,7 @@ public class BuilderIntrospection implements Builder { introspectionObject.putProperty(propertyName, out); */ } else { - //Log.error("Not managed !!! "); + //LOGGER.error("Not managed !!! "); final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, typeClass); final Object out = inferData.getValueFromText(value); introspectionObject.putProperty(IntrospectionObject.PUBLIC_TEXT_NAME, out); @@ -426,7 +429,7 @@ public class BuilderIntrospection implements Builder { } else if (List.class.isAssignableFrom(typeClass)) { final String[] elems = value.split(";"); final Class subTypeClass = introspectionObject.getTypeOfSubNode(value, true); - Log.verbose("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + value + "'"); + LOGGER.trace("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + value + "'"); final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass); final List out = new ArrayList<>(); for (int iii = 0; iii < elems.length; iii++) { @@ -459,7 +462,7 @@ public class BuilderIntrospection implements Builder { final String beanName = model.getBeanName(nodeName); if (beanName == null) { if (model.isIgnoreUnknown()) { - Log.debug("Ignore node : '" + nodeName + "'"); + LOGGER.debug("Ignore node : '" + nodeName + "'"); return; } throw new EjsonBuilderException("The node '" + nodeName + "' Does not exist..."); @@ -484,7 +487,7 @@ public class BuilderIntrospection implements Builder { } else if (List.class.isAssignableFrom(typeClass)) { final String[] elems = value.split(";"); final Class subTypeClass = introspectionObject.getTypeOfSubNode(value, true); - Log.verbose("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + value + "'"); + LOGGER.trace("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + value + "'"); final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass); final List out = new ArrayList<>(); for (int iii = 0; iii < elems.length; iii++) { diff --git a/src/org/atriasoft/ejson/builder/IntrospectionObject.java b/src/org/atriasoft/ejson/builder/IntrospectionObject.java index ffd23ff..e4595e9 100644 --- a/src/org/atriasoft/ejson/builder/IntrospectionObject.java +++ b/src/org/atriasoft/ejson/builder/IntrospectionObject.java @@ -7,11 +7,14 @@ import java.util.Map; import org.atriasoft.aknot.exception.AknotException; import org.atriasoft.aknot.model.IntrospectionModel; +import org.atriasoft.aknot.pojo.IntrospectionProperty; import org.atriasoft.ejson.exception.EjsonException; import org.atriasoft.ejson.exception.EjsonNodeDoesNotExist; -import org.atriasoft.ejson.internal.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class IntrospectionObject { + final static Logger LOGGER = LoggerFactory.getLogger(IntrospectionObject.class); public static final String PUBLIC_TEXT_NAME = "##<< ** TEXT-ZONE ** >>##"; private final IntrospectionModel modelInterface; private Object data = null; @@ -23,19 +26,19 @@ public class IntrospectionObject { } public void addData(final Object value) throws AknotException, EjsonException { - Log.warning("Add Object in list {}", value); + LOGGER.warn("Add Object in list {}", value); final Object value2 = this.modelInterface.getValueConverted(value, this.modelInterface.getClassType()); final String uniqueName = this.modelInterface.getTokenBasicList(); if (!this.nodes.containsKey(uniqueName)) { final List tmp = new ArrayList<>(); tmp.add(value2); - Log.warning(" ==> new list"); + LOGGER.warn(" ==> new list"); this.nodes.put(uniqueName, tmp); } else { - Log.warning(" ==> previous list"); + LOGGER.warn(" ==> previous list"); this.nodes.get(uniqueName).add(value2); - Log.warning(" >> {}", this.nodes.get(uniqueName)); + LOGGER.warn(" >> {}", this.nodes.get(uniqueName)); } } @@ -60,14 +63,14 @@ public class IntrospectionObject { if (List.class.isAssignableFrom(value.getClass())) { node = (List) value; } else if (value.getClass().isArray()) { - Log.error("this is a big problem ..."); + LOGGER.error("this is a big problem ..."); } else { node = new ArrayList<>(); node.add(value); } this.nodes.put(beanName, node); } else if (value.getClass().isArray()) { - Log.error("this is a big problem ..."); + LOGGER.error("this is a big problem ..."); } else if (List.class.isAssignableFrom(value.getClass())) { final List nodeIn = (List) value; node.addAll(nodeIn); @@ -81,10 +84,10 @@ public class IntrospectionObject { // nothing to do ... ==> element already created return; } - Log.warning("Create the element for the Specific node ... type = " + this.modelInterface.getClassType().getCanonicalName() + (this.modelInterface.isArray() ? "[array]" : "") + LOGGER.warn("Create the element for the Specific node ... type = " + this.modelInterface.getClassType().getCanonicalName() + (this.modelInterface.isArray() ? "[array]" : "") + (this.modelInterface.isList() ? "[List]" : "")); - Log.warning(" Properties : " + this.properties.keySet()); - Log.warning(" Nodes : " + this.nodes.keySet()); + LOGGER.warn(" Properties : " + this.properties.keySet()); + LOGGER.warn(" Nodes : " + this.nodes.keySet()); this.data = this.modelInterface.createObject(this.properties, this.nodes, attributeIndependent); } diff --git a/src/org/atriasoft/ejson/internal/Log.java b/src/org/atriasoft/ejson/internal/Log.java deleted file mode 100644 index 1eefc2a..0000000 --- a/src/org/atriasoft/ejson/internal/Log.java +++ /dev/null @@ -1,81 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2021, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ -package org.atriasoft.ejson.internal; - -import org.atriasoft.reggol.LogLevel; -import org.atriasoft.reggol.Logger; - -public class Log { - private static final boolean FORCE_ALL = false; - private static final String LIB_NAME = "ejson"; - private static final String LIB_NAME_DRAW = Logger.getDrawableName(Log.LIB_NAME); - private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.CRITICAL); - private static final boolean PRINT_DEBUG = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.DEBUG); - private static final boolean PRINT_ERROR = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.ERROR); - private static final boolean PRINT_INFO = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.INFO); - private static final boolean PRINT_PRINT = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.PRINT); - private static final boolean PRINT_TODO = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.TODO); - private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.VERBOSE); - private static final boolean PRINT_WARNING = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.WARNING); - - public static void critical(final Exception e, final String data) { - e.printStackTrace(); - if (PRINT_CRITICAL || FORCE_ALL) { - Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage()); - } - } - - public static void critical(final String data, final Object... objects) { - if (PRINT_CRITICAL || FORCE_ALL) { - Logger.critical(LIB_NAME_DRAW, data, objects); - } - } - - public static void debug(final String data, final Object... objects) { - if (PRINT_DEBUG || FORCE_ALL) { - Logger.debug(LIB_NAME_DRAW, data, objects); - } - } - - public static void error(final String data, final Object... objects) { - if (PRINT_ERROR || FORCE_ALL) { - Logger.error(LIB_NAME_DRAW, data, objects); - } - } - - public static void info(final String data, final Object... objects) { - if (PRINT_INFO || FORCE_ALL) { - Logger.info(LIB_NAME_DRAW, data, objects); - } - } - - public static void print(final String data, final Object... objects) { - if (PRINT_PRINT || FORCE_ALL) { - Logger.print(LIB_NAME_DRAW, data, objects); - } - } - - public static void todo(final String data, final Object... objects) { - if (PRINT_TODO || FORCE_ALL) { - Logger.todo(LIB_NAME_DRAW, data, objects); - } - } - - public static void verbose(final String data, final Object... objects) { - if (PRINT_VERBOSE || FORCE_ALL) { - Logger.verbose(LIB_NAME_DRAW, data, objects); - } - } - - public static void warning(final String data, final Object... objects) { - if (PRINT_WARNING || FORCE_ALL) { - Logger.warning(LIB_NAME_DRAW, data, objects); - } - } - - private Log() {} - -} diff --git a/src/org/atriasoft/ejson/model/JsonArray.java b/src/org/atriasoft/ejson/model/JsonArray.java index 02810fa..661dd48 100644 --- a/src/org/atriasoft/ejson/model/JsonArray.java +++ b/src/org/atriasoft/ejson/model/JsonArray.java @@ -9,13 +9,16 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.atriasoft.aknot.pojo.IntrospectionProperty; import org.atriasoft.ejson.exception.EjsonNodeDoesNotExist; -import org.atriasoft.ejson.internal.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Basic element Node of an XML document lt;YYYYYgt; */ public class JsonArray extends JsonNode { + final static Logger LOGGER = LoggerFactory.getLogger(JsonArray.class); protected List listSub = new ArrayList<>(); //!< List of subNodes; /** @@ -30,12 +33,12 @@ public class JsonArray extends JsonNode { */ public void add(final JsonNode node) { if (node == null) { - Log.error("Try to set an empty node"); + LOGGER.error("Try to set an empty node"); return; } for (final JsonNode jsonNode : this.listSub) { if (jsonNode == node) { - Log.error("Try to add a node that is already added before !!!"); + LOGGER.error("Try to add a node that is already added before !!!"); return; } } diff --git a/src/org/atriasoft/ejson/model/JsonObject.java b/src/org/atriasoft/ejson/model/JsonObject.java index aabd970..1d25f4c 100644 --- a/src/org/atriasoft/ejson/model/JsonObject.java +++ b/src/org/atriasoft/ejson/model/JsonObject.java @@ -9,8 +9,10 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; +import org.atriasoft.aknot.pojo.IntrospectionProperty; import org.atriasoft.ejson.exception.EjsonNodeDoesNotExist; -import org.atriasoft.ejson.internal.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @file * @author Edouard DUPIN @@ -21,6 +23,7 @@ import org.atriasoft.ejson.internal.Log; * Basic element Node of an JSON document <> */ public class JsonObject extends JsonNode { + final static Logger LOGGER = LoggerFactory.getLogger(JsonObject.class); protected Map listSub = new LinkedHashMap<>(); // !< List of subNodes; /** @@ -93,7 +96,7 @@ public class JsonObject extends JsonNode { */ public void put(final String nodeName, final JsonNode node) { if (node == null) { - Log.error("Try to set an empty node"); + LOGGER.error("Try to set an empty node"); return; } this.listSub.put(nodeName, node); diff --git a/src/org/atriasoft/ejson/parser/ParseJson.java b/src/org/atriasoft/ejson/parser/ParseJson.java index 78e4978..70158e3 100644 --- a/src/org/atriasoft/ejson/parser/ParseJson.java +++ b/src/org/atriasoft/ejson/parser/ParseJson.java @@ -1,16 +1,19 @@ package org.atriasoft.ejson.parser; import org.atriasoft.aknot.exception.AknotException; +import org.atriasoft.aknot.pojo.IntrospectionProperty; import org.atriasoft.ejson.builder.Builder; import org.atriasoft.ejson.exception.EjsonBuilderException; import org.atriasoft.ejson.exception.EjsonException; import org.atriasoft.ejson.exception.EjsonParserError; import org.atriasoft.ejson.exception.EjsonParserErrorMulti; -import org.atriasoft.ejson.internal.Log; import org.atriasoft.etk.Tools; import org.atriasoft.etk.util.FilePos; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ParseJson { + final static Logger LOGGER = LoggerFactory.getLogger(ParseJson.class); // global builder that is generate the final Tree private final Builder builder; @@ -244,7 +247,7 @@ public class ParseJson { } public Object parse(final String data, final ParsingProperty property) throws EjsonException, AknotException { - Log.verbose("Start parsing document (type: string) size={}", data.length()); + //LOGGER.trace("Start parsing document (type: string) size={}", data.length()); // came from char == > force in utf8 ... final FilePos pos = new FilePos(1, 0); final PositionParsing parsePos = new PositionParsing(); diff --git a/src/org/atriasoft/ejson/parser/ParsingProperty.java b/src/org/atriasoft/ejson/parser/ParsingProperty.java index 628845e..287531d 100644 --- a/src/org/atriasoft/ejson/parser/ParsingProperty.java +++ b/src/org/atriasoft/ejson/parser/ParsingProperty.java @@ -4,11 +4,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.atriasoft.aknot.pojo.IntrospectionProperty; import org.atriasoft.ejson.exception.EjsonParserError; -import org.atriasoft.ejson.internal.Log; import org.atriasoft.etk.Tools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ParsingProperty { + final static Logger LOGGER = LoggerFactory.getLogger(ParsingProperty.class); /// check the case sensitive of the nodes (end marker) and attribute (duplicates) private boolean caseSensitive = true; // List of all error detected @@ -71,7 +74,7 @@ public class ParsingProperty { * @param error The error to display. */ public void displayError(final EjsonParserError error) { - Log.error("{} {}\n{}\n", error.getFilePos(), error.getMessage(), error.getDataLine(), Tools.createPosPointer(error.getDataLine(), error.getFilePos().getCol())); + LOGGER.error("{} {}\n{}\n", error.getFilePos(), error.getMessage(), error.getDataLine(), Tools.createPosPointer(error.getDataLine(), error.getFilePos().getCol())); } /** diff --git a/test/resources/simplelogger.properties b/test/resources/simplelogger.properties new file mode 100644 index 0000000..4314b58 --- /dev/null +++ b/test/resources/simplelogger.properties @@ -0,0 +1,35 @@ +# SLF4J's SimpleLogger configuration file +# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. +# Default logging detail level for all instances of SimpleLogger. +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, defaults to "info". +org.slf4j.simpleLogger.defaultLogLevel=trace + +# Logging detail level for a SimpleLogger instance named "xxxxx". +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, the default logging detail level is used. +#org.slf4j.simpleLogger.log.xxxxx= + +# Set to true if you want the current date and time to be included in output messages. +# Default is false, and will output the number of milliseconds elapsed since startup. +#org.slf4j.simpleLogger.showDateTime=false + +# The date and time format to be used in the output messages. +# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat. +# If the format is not specified or is invalid, the default format is used. +# The default format is yyyy-MM-dd HH:mm:ss:SSS Z. +#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z + +# Set to true if you want to output the current thread name. +# Defaults to true. +org.slf4j.simpleLogger.showThreadName=true + +# Set to true if you want the Logger instance name to be included in output messages. +# Defaults to true. +#org.slf4j.simpleLogger.showLogName=true + +# Set to true if you want the last component of the name to be included in output messages. +# Defaults to false. +#org.slf4j.simpleLogger.showShortLogName=false + + diff --git a/test/src/test/atriasoft/ejson/generic/EjsonLocal.java b/test/src/test/atriasoft/ejson/generic/EjsonLocal.java index c422d84..c513d1b 100644 --- a/test/src/test/atriasoft/ejson/generic/EjsonLocal.java +++ b/test/src/test/atriasoft/ejson/generic/EjsonLocal.java @@ -7,15 +7,18 @@ package test.atriasoft.ejson.generic; import org.atriasoft.ejson.Ejson; import org.atriasoft.ejson.model.JsonNode; +import org.atriasoft.ejson.parser.ParsingProperty; import org.junit.jupiter.api.Assertions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import test.atriasoft.ejson.internal.Log; class EjsonLocal { + final static Logger LOGGER = LoggerFactory.getLogger(ParsingProperty.class); // errorPos : -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ???? public static void test(final String ref, final String input, final int errorPos) { //doc.setCaseSensitive(!caseInSensitive); - Log.verbose("parse : \n{}", input); + LOGGER.trace("parse : \n{}", input); JsonNode root = null; try { root = Ejson.parse(input); diff --git a/test/src/test/atriasoft/ejson/generic/EjsonTestAll.java b/test/src/test/atriasoft/ejson/generic/EjsonTestAll.java index ed7244e..a77f4cb 100644 --- a/test/src/test/atriasoft/ejson/generic/EjsonTestAll.java +++ b/test/src/test/atriasoft/ejson/generic/EjsonTestAll.java @@ -7,10 +7,12 @@ package test.atriasoft.ejson.generic; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import test.atriasoft.ejson.internal.Log; public class EjsonTestAll { + final static Logger LOGGER = LoggerFactory.getLogger(EjsonTestAll.class); //@formatter:off private static String refOutputAll = """ { @@ -31,7 +33,7 @@ public class EjsonTestAll { @BeforeAll public static void beforeClass() { - Log.verbose("----------------------------------------------------------------"); + LOGGER.trace("----------------------------------------------------------------"); } @Test diff --git a/test/src/test/atriasoft/ejson/generic/EjsonTestBoolean.java b/test/src/test/atriasoft/ejson/generic/EjsonTestBoolean.java index c0da106..dfdc68e 100644 --- a/test/src/test/atriasoft/ejson/generic/EjsonTestBoolean.java +++ b/test/src/test/atriasoft/ejson/generic/EjsonTestBoolean.java @@ -8,17 +8,19 @@ package test.atriasoft.ejson.generic; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import test.atriasoft.ejson.internal.Log; public class EjsonTestBoolean { + final static Logger LOGGER = LoggerFactory.getLogger(EjsonTestBoolean.class); private static String refOutputBoolean1 = "{\n\t\"tmpElement\": true\n}"; private static String refOutputBoolean2 = "{\n\t\"tmpElement\": false\n}"; @BeforeAll public static void beforeClass() { - Log.verbose("----------------------------------------------------------------"); + LOGGER.trace("----------------------------------------------------------------"); } @Test diff --git a/test/src/test/atriasoft/ejson/generic/EjsonTestNull.java b/test/src/test/atriasoft/ejson/generic/EjsonTestNull.java index 7f32d74..8ad732f 100644 --- a/test/src/test/atriasoft/ejson/generic/EjsonTestNull.java +++ b/test/src/test/atriasoft/ejson/generic/EjsonTestNull.java @@ -8,15 +8,17 @@ package test.atriasoft.ejson.generic; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import test.atriasoft.ejson.internal.Log; public class EjsonTestNull { + final static Logger LOGGER = LoggerFactory.getLogger(EjsonTestNull.class); private static final String REF_OUTPUT_NULL = "{\n\t\"tmpElement\": null\n}"; @BeforeAll public static void beforeClass() { - Log.verbose("----------------------------------------------------------------"); + LOGGER.trace("----------------------------------------------------------------"); } @Test diff --git a/test/src/test/atriasoft/ejson/generic/EjsonTestNumber.java b/test/src/test/atriasoft/ejson/generic/EjsonTestNumber.java index dcfbf40..edec8a7 100644 --- a/test/src/test/atriasoft/ejson/generic/EjsonTestNumber.java +++ b/test/src/test/atriasoft/ejson/generic/EjsonTestNumber.java @@ -8,15 +8,17 @@ package test.atriasoft.ejson.generic; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import test.atriasoft.ejson.internal.Log; public class EjsonTestNumber { + final static Logger LOGGER = LoggerFactory.getLogger(EjsonTestNumber.class); private static final String REF_OUTPUT_NUMBER = "{\n\t\"tmpElement\": 956256\n}"; @BeforeAll public static void beforeClass() { - Log.verbose("----------------------------------------------------------------"); + LOGGER.trace("----------------------------------------------------------------"); } @Test diff --git a/test/src/test/atriasoft/ejson/internal/Log.java b/test/src/test/atriasoft/ejson/internal/Log.java deleted file mode 100644 index b9a5587..0000000 --- a/test/src/test/atriasoft/ejson/internal/Log.java +++ /dev/null @@ -1,82 +0,0 @@ -package test.atriasoft.ejson.internal; - -/** @file - * @author Edouard DUPIN - * @copyright 2021, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - -import org.atriasoft.reggol.LogLevel; -import org.atriasoft.reggol.Logger; - -public class Log { - private static final boolean FORCE_ALL = false; - private static final String LIB_NAME = "ejson-test"; - private static final String LIB_NAME_DRAW = Logger.getDrawableName(Log.LIB_NAME); - private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.CRITICAL); - private static final boolean PRINT_DEBUG = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.DEBUG); - private static final boolean PRINT_ERROR = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.ERROR); - private static final boolean PRINT_INFO = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.INFO); - private static final boolean PRINT_PRINT = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.PRINT); - private static final boolean PRINT_TODO = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.TODO); - private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.VERBOSE); - private static final boolean PRINT_WARNING = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.WARNING); - - public static void critical(final Exception e, final String data) { - e.printStackTrace(); - if (PRINT_CRITICAL || FORCE_ALL) { - Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage()); - } - } - - public static void critical(final String data, final Object... objects) { - if (PRINT_CRITICAL || FORCE_ALL) { - Logger.critical(LIB_NAME_DRAW, data, objects); - } - } - - public static void debug(final String data, final Object... objects) { - if (PRINT_DEBUG || FORCE_ALL) { - Logger.debug(LIB_NAME_DRAW, data, objects); - } - } - - public static void error(final String data, final Object... objects) { - if (PRINT_ERROR || FORCE_ALL) { - Logger.error(LIB_NAME_DRAW, data, objects); - } - } - - public static void info(final String data, final Object... objects) { - if (PRINT_INFO || FORCE_ALL) { - Logger.info(LIB_NAME_DRAW, data, objects); - } - } - - public static void print(final String data, final Object... objects) { - if (PRINT_PRINT || FORCE_ALL) { - Logger.print(LIB_NAME_DRAW, data, objects); - } - } - - public static void todo(final String data, final Object... objects) { - if (PRINT_TODO || FORCE_ALL) { - Logger.todo(LIB_NAME_DRAW, data, objects); - } - } - - public static void verbose(final String data, final Object... objects) { - if (PRINT_VERBOSE || FORCE_ALL) { - Logger.verbose(LIB_NAME_DRAW, data, objects); - } - } - - public static void warning(final String data, final Object... objects) { - if (PRINT_WARNING || FORCE_ALL) { - Logger.warning(LIB_NAME_DRAW, data, objects); - } - } - - private Log() {} - -} diff --git a/test/src/test/atriasoft/ejson/introspection/EjsonTestIntrospection.java b/test/src/test/atriasoft/ejson/introspection/EjsonTestIntrospection.java index 5c616dd..3599e7b 100644 --- a/test/src/test/atriasoft/ejson/introspection/EjsonTestIntrospection.java +++ b/test/src/test/atriasoft/ejson/introspection/EjsonTestIntrospection.java @@ -15,8 +15,9 @@ import org.atriasoft.ejson.exception.EjsonParserErrorMulti; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import test.atriasoft.ejson.internal.Log; import test.atriasoft.ejson.introspection.model.ClassMethodEnum; import test.atriasoft.ejson.introspection.model.ClassPublicChild; import test.atriasoft.ejson.introspection.model.ClassPublicMemberOnly; @@ -26,9 +27,10 @@ import test.atriasoft.ejson.introspection.model.ClassPublicMethodeStructured; import test.atriasoft.ejson.introspection.model.SimpleEnum; public class EjsonTestIntrospection { + final static Logger LOGGER = LoggerFactory.getLogger(EjsonTestIntrospection.class); @BeforeAll public static void beforeClass() { - Log.verbose("----------------------------------------------------------------"); + LOGGER.trace("----------------------------------------------------------------"); } @Test