From df2a40508c4caef450a549e94d3a6427d9698986 Mon Sep 17 00:00:00 2001 From: csowada Date: Fri, 25 Dec 2020 19:28:54 +0100 Subject: [PATCH 01/11] Update for next development version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 348e601..33b1b8b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ eBUS core library - This library handles the communication with heating engineering via the BUS specification. This protocol is used by many heating manufacturers in Europe. de.cs-dev.ebus ebus-core - 1.1.3 + 1.1.4-SNAPSHOT https://github.com/csowada/ebus bundle From e19a7fb1e4425b5ffd8c9aee9b7b423ed8fea7e9 Mon Sep 17 00:00:00 2001 From: csowada Date: Sat, 26 Dec 2020 21:58:26 +0100 Subject: [PATCH 02/11] Fix bug in connection status change (regression in v1.0.8) - The new "Change Status" check does not work, since the old status is already set previously --- .../java/de/csdev/ebus/core/EBusControllerBase.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/csdev/ebus/core/EBusControllerBase.java b/src/main/java/de/csdev/ebus/core/EBusControllerBase.java index 53388a1..4f20e53 100644 --- a/src/main/java/de/csdev/ebus/core/EBusControllerBase.java +++ b/src/main/java/de/csdev/ebus/core/EBusControllerBase.java @@ -214,11 +214,6 @@ protected void fireOnEBusConnectionStatusChange(final @NonNull ConnectionStatus return; } - // only run on a real status change - if (getConnectionStatus() == status) { - return; - } - if (threadPool == null || threadPool.isTerminated()) { logger.warn(THREADPOOL_NOT_READY); return; @@ -326,8 +321,12 @@ protected void setConnectionStatus(final @NonNull ConnectionStatus status) { Objects.requireNonNull(status, "status"); - this.connectionStatus = status; - fireOnEBusConnectionStatusChange(status); + + // only run on a real status change + if (this.connectionStatus != status) { + this.connectionStatus = status; + fireOnEBusConnectionStatusChange(status); + } } @Override From 1c647c1f4aec016fb8303cd636f01eab628219da Mon Sep 17 00:00:00 2001 From: csowada Date: Sat, 26 Dec 2020 22:11:58 +0100 Subject: [PATCH 03/11] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87f80e8..438c96b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## Unreleased +### Fixed +- The new "Change Status" check (from v1.0.8) does not work, since the old status is already set previously ## [1.1.3] - 2020-12-25 ### Changed From 10a2580d400805ccaa808d2c27700fe2aa62cbef Mon Sep 17 00:00:00 2001 From: csowada Date: Sun, 27 Dec 2020 13:54:54 +0100 Subject: [PATCH 04/11] Enhance error handling for invalid config files - Add better exception messages for invalid configuration files - Throw ``EBusConfigurationReaderException``, ``IOException`` instead logging as error - Add TestCases for invalid json configuration files - Align ``EBusConfigurationReaderException`` to String.format --- .../cfg/EBusConfigurationReaderException.java | 15 ++- .../ebus/cfg/IEBusConfigurationReader.java | 72 +++++++------- .../ebus/cfg/std/EBusConfigurationReader.java | 94 ++++++++++--------- .../ebus/command/EBusCommandRegistry.java | 22 ++--- .../ebus/cfg/EBusConfigurationBundleTest.java | 3 +- .../csdev/ebus/cfg/EBusConfigurationTest.java | 76 +++++++++++++++ .../wip/EBusConfigurationTemplateTest.java | 4 +- .../csdev/ebus/wip/EBusCustomParserTest.java | 4 +- ...valid-configuration-empty-description.json | 64 +++++++++++++ .../invalid-configuration-empty-id.json | 64 +++++++++++++ .../invalid-configuration-empty-label.json | 64 +++++++++++++ 11 files changed, 380 insertions(+), 102 deletions(-) create mode 100644 src/test/java/de/csdev/ebus/cfg/EBusConfigurationTest.java create mode 100644 src/test/resources/invalid-cfgs/invalid-configuration-empty-description.json create mode 100644 src/test/resources/invalid-cfgs/invalid-configuration-empty-id.json create mode 100644 src/test/resources/invalid-cfgs/invalid-configuration-empty-label.json diff --git a/src/main/java/de/csdev/ebus/cfg/EBusConfigurationReaderException.java b/src/main/java/de/csdev/ebus/cfg/EBusConfigurationReaderException.java index c70abcb..7399114 100644 --- a/src/main/java/de/csdev/ebus/cfg/EBusConfigurationReaderException.java +++ b/src/main/java/de/csdev/ebus/cfg/EBusConfigurationReaderException.java @@ -8,8 +8,6 @@ */ package de.csdev.ebus.cfg; -import java.text.MessageFormat; - /** * @author Christian Sowada - Initial contribution * @@ -18,20 +16,19 @@ public class EBusConfigurationReaderException extends Exception { private static final long serialVersionUID = 1L; - public EBusConfigurationReaderException(final String message, final Throwable cause, final Object... args) { - super(String.format(message, args), cause); + public EBusConfigurationReaderException(final String message) { + super(message); } public EBusConfigurationReaderException(final String message, final Object... args) { - super(MessageFormat.format(message, args)); - } - - public EBusConfigurationReaderException(final String message) { - super(message); + super(String.format(message, args)); } public EBusConfigurationReaderException(final String message, final Throwable cause) { super(message, cause); } + public EBusConfigurationReaderException(final String message, final Throwable cause, final Object... args) { + super(String.format(message, args), cause); + } } diff --git a/src/main/java/de/csdev/ebus/cfg/IEBusConfigurationReader.java b/src/main/java/de/csdev/ebus/cfg/IEBusConfigurationReader.java index 56b8159..6be9250 100644 --- a/src/main/java/de/csdev/ebus/cfg/IEBusConfigurationReader.java +++ b/src/main/java/de/csdev/ebus/cfg/IEBusConfigurationReader.java @@ -25,39 +25,41 @@ @NonNullByDefault public interface IEBusConfigurationReader { - /** - * Loads all build-in command collections implemented by the reader - * - * @return - */ - public List loadBuildInConfigurationCollections(); - - /** - * Loads the configuration from an InputStream and returns a command collection - * - * @param url - * @return - * @throws EBusConfigurationReaderException - * @throws IOException - */ - public @Nullable IEBusCommandCollection loadConfigurationCollection(final URL url) - throws EBusConfigurationReaderException, IOException; - - /** - * @param url - * @return - */ - public List loadConfigurationCollectionBundle(final URL url); - - /** - * Sets the eBUS type registry to use - * - * @param ebusTypes - */ - public void setEBusTypes(final EBusTypeRegistry ebusTypes); - - /** - * Clears all internal states - */ - public void clear(); + /** + * Loads all build-in command collections implemented by the reader + * + * @return + */ + public List loadBuildInConfigurationCollections() + throws EBusConfigurationReaderException, IOException; + + /** + * Loads the configuration from an InputStream and returns a command collection + * + * @param url + * @return + * @throws EBusConfigurationReaderException + * @throws IOException + */ + public @Nullable IEBusCommandCollection loadConfigurationCollection(final URL url) + throws EBusConfigurationReaderException, IOException; + + /** + * @param url + * @return + */ + public List loadConfigurationCollectionBundle(final URL url) + throws EBusConfigurationReaderException, IOException; + + /** + * Sets the eBUS type registry to use + * + * @param ebusTypes + */ + public void setEBusTypes(final EBusTypeRegistry ebusTypes); + + /** + * Clears all internal states + */ + public void clear(); } diff --git a/src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java b/src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java index 4481e77..244b981 100644 --- a/src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java +++ b/src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java @@ -23,18 +23,16 @@ import java.util.Map; import java.util.Objects; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + import org.apache.commons.lang.StringUtils; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonIOException; -import com.google.gson.JsonSyntaxException; -import com.google.gson.reflect.TypeToken; - import de.csdev.ebus.cfg.EBusConfigurationReaderException; import de.csdev.ebus.cfg.IEBusConfigurationReader; import de.csdev.ebus.cfg.std.dto.EBusCollectionDTO; @@ -86,7 +84,8 @@ public EBusConfigurationReader() { * @see de.csdev.ebus.cfg.IEBusConfigurationReader#loadBuildInConfigurations() */ @Override - public @NonNull List<@NonNull IEBusCommandCollection> loadBuildInConfigurationCollections() { + public @NonNull List<@NonNull IEBusCommandCollection> loadBuildInConfigurationCollections() + throws EBusConfigurationReaderException, IOException { URL url = EBusConfigurationReader.class.getResource("/index-configuration.json"); Objects.requireNonNull(url); @@ -97,7 +96,9 @@ public EBusConfigurationReader() { /* * (non-Javadoc) * - * @see de.csdev.ebus.cfg.IEBusConfigurationReader#loadConfigurationCollection(java.io.InputStream) + * @see + * de.csdev.ebus.cfg.IEBusConfigurationReader#loadConfigurationCollection(java. + * io.InputStream) */ @Override public @NonNull IEBusCommandCollection loadConfigurationCollection(@NonNull URL url) @@ -124,12 +125,16 @@ public EBusConfigurationReader() { EBusCollectionDTO collection = Objects .requireNonNull(gson.fromJson(new InputStreamReader(dis), EBusCollectionDTO.class)); - EBusCommandCollection commandCollection = (EBusCommandCollection) loadConfigurationCollection(collection); + try { + EBusCommandCollection commandCollection = (EBusCommandCollection) loadConfigurationCollection(collection); + // add md5 hash + commandCollection.setSourceHash(md.digest()); - // add md5 hash - commandCollection.setSourceHash(md.digest()); + return commandCollection; - return commandCollection; + } catch (EBusConfigurationReaderException e) { + throw new EBusConfigurationReaderException("%s [ URL: %s ]", e.getMessage(), url); + } } public @NonNull IEBusCommandCollection loadConfigurationCollection(@NonNull EBusCollectionDTO collection) @@ -137,6 +142,22 @@ public EBusConfigurationReader() { Objects.requireNonNull(collection, "collection"); + if (StringUtils.isEmpty(collection.getId())) { + throw new EBusConfigurationReaderException("The property 'id' is missing for the configuration!"); + } + + if (StringUtils.isEmpty(collection.getLabel())) { + throw new EBusConfigurationReaderException("The property 'label' is missing for the configuration!"); + } + + if (StringUtils.isEmpty(collection.getDescription())) { + throw new EBusConfigurationReaderException("The property 'description' is missing for the configuration!"); + } + + if (collection.getProperties() == null) { + throw new EBusConfigurationReaderException("The property 'properties' is missing for the configuration!"); + } + EBusCommandCollection commandCollection = new EBusCommandCollection(collection.getId(), collection.getLabel(), collection.getDescription(), collection.getProperties()); @@ -250,7 +271,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection } if (id == null) { - throw new EBusConfigurationReaderException("Property 'id' is missing for command ! {0}", + throw new EBusConfigurationReaderException("Property 'id' is missing for command ! %s", commandElement != null ? commandElement.toString() : ""); } @@ -367,7 +388,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection } if (StringUtils.isEmpty(typeStr)) { - throw new EBusConfigurationReaderException("Property 'type' is missing for command ! {0}", + throw new EBusConfigurationReaderException("Property 'type' is missing for command ! %s", commandMethod != null ? commandMethod.getParent() : ""); } @@ -395,7 +416,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection templateCollection = templateBlockRegistry.get(globalId); if (templateCollection == null) { - throw new EBusConfigurationReaderException("Unable to find a template-block with id {0}!", id); + throw new EBusConfigurationReaderException("Unable to find a template-block with id %s!", id); } } @@ -445,7 +466,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection templateCollection.add(templateMap.get(id)); } else { - throw new EBusConfigurationReaderException("Unable to find a template for id {0}!", id); + throw new EBusConfigurationReaderException("Unable to find a template for id %s!", id); } @@ -556,7 +577,9 @@ private void overwritePropertiesFromTemplate(@NonNull EBusCommandValue clone, @N /* * (non-Javadoc) * - * @see de.csdev.ebus.cfg.IEBusConfigurationReader#setEBusTypes(de.csdev.ebus.command.datatypes.EBusTypeRegistry) + * @see + * de.csdev.ebus.cfg.IEBusConfigurationReader#setEBusTypes(de.csdev.ebus.command + * .datatypes.EBusTypeRegistry) */ @Override public void setEBusTypes(@NonNull EBusTypeRegistry ebusTypes) { @@ -565,7 +588,8 @@ public void setEBusTypes(@NonNull EBusTypeRegistry ebusTypes) { } @Override - public @NonNull List<@NonNull IEBusCommandCollection> loadConfigurationCollectionBundle(@NonNull URL url) { + public @NonNull List<@NonNull IEBusCommandCollection> loadConfigurationCollectionBundle(@NonNull URL url) + throws EBusConfigurationReaderException, IOException { Objects.requireNonNull(url, "url"); @@ -575,36 +599,22 @@ public void setEBusTypes(@NonNull EBusTypeRegistry ebusTypes) { Type type = new TypeToken>() { }.getType(); - try { + Map mapping = gson.fromJson(new InputStreamReader(url.openStream()), type); - Map mapping = gson.fromJson(new InputStreamReader(url.openStream()), type); + if (mapping.containsKey("files")) { - if (mapping.containsKey("files")) { + @SuppressWarnings("unchecked") + List> files = (List>) mapping.get("files"); - @SuppressWarnings("unchecked") - List> files = (List>) mapping.get("files"); + if (files != null && !files.isEmpty()) { + for (Map file : files) { + URL fileUrl = new URL(url, file.get("url")); - if (files != null && !files.isEmpty()) { - for (Map file : files) { - URL fileUrl = new URL(url, file.get("url")); - - try { - logger.debug("Load configuration from url {} ...", fileUrl); - IEBusCommandCollection collection = loadConfigurationCollection(fileUrl); - result.add(collection); - - } catch (EBusConfigurationReaderException e) { - logger.error("{} (url: {})", e.getMessage(), fileUrl); - } catch (IOException e) { - logger.error("error!", e); - } - - } + logger.debug("Load configuration from url {} ...", fileUrl); + IEBusCommandCollection collection = loadConfigurationCollection(fileUrl); + result.add(collection); } } - - } catch (JsonSyntaxException | JsonIOException | IOException e) { - logger.error("error!", e); } return result; diff --git a/src/main/java/de/csdev/ebus/command/EBusCommandRegistry.java b/src/main/java/de/csdev/ebus/command/EBusCommandRegistry.java index 406b863..5983b8a 100644 --- a/src/main/java/de/csdev/ebus/command/EBusCommandRegistry.java +++ b/src/main/java/de/csdev/ebus/command/EBusCommandRegistry.java @@ -74,15 +74,19 @@ public EBusCommandRegistry(Class readerClass loadBuildInCommandCollections(); } - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | EBusTypeException e) { + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | EBusTypeException + | EBusConfigurationReaderException | IOException e) { throw new IllegalStateException(e); } } /** * Loads all build-in command collections + * + * @throws IOException + * @throws EBusConfigurationReaderException */ - public void loadBuildInCommandCollections() { + public void loadBuildInCommandCollections() throws EBusConfigurationReaderException, IOException { List<@NonNull IEBusCommandCollection> loadBuildInConfigurations = reader.loadBuildInConfigurationCollections(); if (!loadBuildInConfigurations.isEmpty()) { @@ -97,23 +101,15 @@ public void loadBuildInCommandCollections() { * * @param url */ - public void loadCommandCollection(@NonNull URL url) { - + public void loadCommandCollection(@NonNull URL url) throws EBusConfigurationReaderException, IOException { Objects.requireNonNull(url); - - try { - addCommandCollection(reader.loadConfigurationCollection(url)); - - } catch (EBusConfigurationReaderException | IOException e) { - logger.error("error!", e); - } - + addCommandCollection(reader.loadConfigurationCollection(url)); } /** * @param url */ - public void loadCommandCollectionBundle(@NonNull URL url) { + public void loadCommandCollectionBundle(@NonNull URL url) throws EBusConfigurationReaderException, IOException { Objects.requireNonNull(url); diff --git a/src/test/java/de/csdev/ebus/cfg/EBusConfigurationBundleTest.java b/src/test/java/de/csdev/ebus/cfg/EBusConfigurationBundleTest.java index cf59bd2..fc4069b 100644 --- a/src/test/java/de/csdev/ebus/cfg/EBusConfigurationBundleTest.java +++ b/src/test/java/de/csdev/ebus/cfg/EBusConfigurationBundleTest.java @@ -10,6 +10,7 @@ import static org.junit.Assert.*; +import java.io.IOException; import java.net.URL; import org.junit.Test; @@ -24,7 +25,7 @@ public class EBusConfigurationBundleTest { @Test - public void test_BuildMasterTelegram() { + public void test_BuildMasterTelegram() throws EBusConfigurationReaderException, IOException { URL url = EBusCommandRegistry.class.getResource("/index-configuration.json"); assertNotNull(url); diff --git a/src/test/java/de/csdev/ebus/cfg/EBusConfigurationTest.java b/src/test/java/de/csdev/ebus/cfg/EBusConfigurationTest.java new file mode 100644 index 0000000..b7dfc4c --- /dev/null +++ b/src/test/java/de/csdev/ebus/cfg/EBusConfigurationTest.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2016-2020 by the respective copyright holders. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package de.csdev.ebus.cfg; + +import static org.junit.Assert.fail; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; + +import de.csdev.ebus.cfg.std.EBusConfigurationReader; +import de.csdev.ebus.command.EBusCommandRegistry; + +/** + * @author Christian Sowada - Initial contribution + * + */ +public class EBusConfigurationTest { + + EBusCommandRegistry commandRegistry; + + @Before + public void before() throws IOException, EBusConfigurationReaderException { + commandRegistry = new EBusCommandRegistry(EBusConfigurationReader.class, true); + } + + private void load(String resourceFile) throws EBusConfigurationReaderException, IOException { + commandRegistry.loadCommandCollection(EBusConfigurationTest.class.getResource(resourceFile)); + } + + @Test + public void testConfigurationWithoutId() { + try { + load("/invalid-cfgs/invalid-configuration-empty-id.json"); + fail("The configuration should fail due to missing property 'id' !"); + } catch (EBusConfigurationReaderException e) { + // expected result + + } catch(Exception e) { + fail("Unexpected exception occured!"); + } + } + + @Test + public void testConfigurationWithoutLabel() { + try { + load("/invalid-cfgs/invalid-configuration-empty-label.json"); + fail("The configuration should fail due to missing property 'label' !"); + } catch (EBusConfigurationReaderException e) { + // expected result + + } catch(Exception e) { + fail("Unexpected exception occured!"); + } + } + + @Test + public void testConfigurationWithoutDescription() { + try { + load("/invalid-cfgs/invalid-configuration-empty-description.json"); + fail("The configuration should fail due to missing property 'description' !"); + } catch (EBusConfigurationReaderException e) { + // expected result + + } catch(Exception e) { + fail("Unexpected exception occured!"); + } + } +} diff --git a/src/test/java/de/csdev/ebus/wip/EBusConfigurationTemplateTest.java b/src/test/java/de/csdev/ebus/wip/EBusConfigurationTemplateTest.java index dc0bde7..1bb2ad4 100644 --- a/src/test/java/de/csdev/ebus/wip/EBusConfigurationTemplateTest.java +++ b/src/test/java/de/csdev/ebus/wip/EBusConfigurationTemplateTest.java @@ -10,10 +10,12 @@ import static org.junit.Assert.*; +import java.io.IOException; import java.util.List; import org.eclipse.jdt.annotation.NonNull; +import de.csdev.ebus.cfg.EBusConfigurationReaderException; import de.csdev.ebus.cfg.std.EBusConfigurationReader; import de.csdev.ebus.command.EBusCommandRegistry; import de.csdev.ebus.command.IEBusCommand; @@ -29,7 +31,7 @@ public class EBusConfigurationTemplateTest { // @Test - public void test_BuildMasterTelegram() { + public void test_BuildMasterTelegram() throws EBusConfigurationReaderException, IOException { EBusCommandRegistry registry = new EBusCommandRegistry(EBusConfigurationReader.class); registry.loadBuildInCommandCollections(); diff --git a/src/test/java/de/csdev/ebus/wip/EBusCustomParserTest.java b/src/test/java/de/csdev/ebus/wip/EBusCustomParserTest.java index 34efdfb..2c1b34a 100644 --- a/src/test/java/de/csdev/ebus/wip/EBusCustomParserTest.java +++ b/src/test/java/de/csdev/ebus/wip/EBusCustomParserTest.java @@ -10,12 +10,14 @@ import static org.junit.Assert.*; +import java.io.IOException; import java.net.URL; import java.nio.ByteBuffer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import de.csdev.ebus.cfg.EBusConfigurationReaderException; import de.csdev.ebus.cfg.std.EBusConfigurationReader; import de.csdev.ebus.command.EBusCommandException; import de.csdev.ebus.command.EBusCommandRegistry; @@ -35,7 +37,7 @@ public void xx() { private final Logger logger = LoggerFactory.getLogger(EBusCustomParserTest.class); // @Test - public void test_BuildMasterTelegram() { + public void test_BuildMasterTelegram() throws EBusConfigurationReaderException, IOException { URL url = EBusConfigurationReader.class.getResource("/custom.json"); assertNotNull(url); diff --git a/src/test/resources/invalid-cfgs/invalid-configuration-empty-description.json b/src/test/resources/invalid-cfgs/invalid-configuration-empty-description.json new file mode 100644 index 0000000..f2448c6 --- /dev/null +++ b/src/test/resources/invalid-cfgs/invalid-configuration-empty-description.json @@ -0,0 +1,64 @@ +{ + "id": "test", + "vendor": "TestCase", + "label": "Test Case", + "x-description":"Test Case commands", + + "authors": ["Christian Sowada, opensource@cs-dev.de"], + + "commands": + [ + + { + "label": "Identification of eBUS devices - Request", + "id": "common.identification", + "command": "99 04", + + "template": [ + {"name": "vendor", "type": "byte", "label": "Vendor"}, + {"name": "device_id", "type": "bytes", "length": 5, "label": "Device ID"}, + {"name": "software_version", "type": "version", "label": "Software Version"}, + {"name": "hardware_version", "type": "version", "label": "Hardware Version"} + ], + + "broadcast": { + "master": [ + {"type": "template-block"} + ] + }, + + "get": { + "slave": [ + {"type": "template-block"} + ] + } + }, + + { + "label": "Inquiry of Existence", + "id": "common.inquiry_of_existence", + "command": "99 FE", + "broadcast":{} + }, + + { + "label": "Sign of Life", + "id": "common.sign_of_life", + "command": "99 FF", + "broadcast":{} + }, + + { + "label": "Error Message", + "id": "common.error", + "command": "FE 99", + + "broadcast": { + "master": [ + {"type": "string", "name":"error", "length": 10} + + ] + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/invalid-cfgs/invalid-configuration-empty-id.json b/src/test/resources/invalid-cfgs/invalid-configuration-empty-id.json new file mode 100644 index 0000000..5a1c218 --- /dev/null +++ b/src/test/resources/invalid-cfgs/invalid-configuration-empty-id.json @@ -0,0 +1,64 @@ +{ + "x-id": "test", + "vendor": "TestCase", + "label": "Test Case", + "description": "Test Case commands", + + "authors": ["Christian Sowada, opensource@cs-dev.de"], + + "commands": + [ + + { + "label": "Identification of eBUS devices - Request", + "id": "common.identification", + "command": "99 04", + + "template": [ + {"name": "vendor", "type": "byte", "label": "Vendor"}, + {"name": "device_id", "type": "bytes", "length": 5, "label": "Device ID"}, + {"name": "software_version", "type": "version", "label": "Software Version"}, + {"name": "hardware_version", "type": "version", "label": "Hardware Version"} + ], + + "broadcast": { + "master": [ + {"type": "template-block"} + ] + }, + + "get": { + "slave": [ + {"type": "template-block"} + ] + } + }, + + { + "label": "Inquiry of Existence", + "id": "common.inquiry_of_existence", + "command": "99 FE", + "broadcast":{} + }, + + { + "label": "Sign of Life", + "id": "common.sign_of_life", + "command": "99 FF", + "broadcast":{} + }, + + { + "label": "Error Message", + "id": "common.error", + "command": "FE 99", + + "broadcast": { + "master": [ + {"type": "string", "name":"error", "length": 10} + + ] + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/invalid-cfgs/invalid-configuration-empty-label.json b/src/test/resources/invalid-cfgs/invalid-configuration-empty-label.json new file mode 100644 index 0000000..e1c3062 --- /dev/null +++ b/src/test/resources/invalid-cfgs/invalid-configuration-empty-label.json @@ -0,0 +1,64 @@ +{ + "id": "test", + "vendor": "TestCase", + "x-label": "Test Case", + "description": "Test Case commands", + + "authors": ["Christian Sowada, opensource@cs-dev.de"], + + "commands": + [ + + { + "label": "Identification of eBUS devices - Request", + "id": "common.identification", + "command": "99 04", + + "template": [ + {"name": "vendor", "type": "byte", "label": "Vendor"}, + {"name": "device_id", "type": "bytes", "length": 5, "label": "Device ID"}, + {"name": "software_version", "type": "version", "label": "Software Version"}, + {"name": "hardware_version", "type": "version", "label": "Hardware Version"} + ], + + "broadcast": { + "master": [ + {"type": "template-block"} + ] + }, + + "get": { + "slave": [ + {"type": "template-block"} + ] + } + }, + + { + "label": "Inquiry of Existence", + "id": "common.inquiry_of_existence", + "command": "99 FE", + "broadcast":{} + }, + + { + "label": "Sign of Life", + "id": "common.sign_of_life", + "command": "99 FF", + "broadcast":{} + }, + + { + "label": "Error Message", + "id": "common.error", + "command": "FE 99", + + "broadcast": { + "master": [ + {"type": "string", "name":"error", "length": 10} + + ] + } + } + ] +} \ No newline at end of file From 84e8fb5b8871dda01b9925574b5301b1fcff3c89 Mon Sep 17 00:00:00 2001 From: csowada Date: Sun, 27 Dec 2020 14:00:36 +0100 Subject: [PATCH 05/11] Remove annotations folder, not used --- annotations/java/lang/Class.eea | 4 ---- annotations/java/lang/String.eea | 4 ---- annotations/java/lang/StringBuilder.eea | 4 ---- annotations/java/lang/reflect/Field.eea | 4 ---- annotations/java/math/BigDecimal.eea | 13 ------------- annotations/java/util/Collections.eea | 10 ---------- annotations/java/util/Objects.eea | 4 ---- annotations/org/slf4j/LoggerFactory.eea | 4 ---- 8 files changed, 47 deletions(-) delete mode 100644 annotations/java/lang/Class.eea delete mode 100644 annotations/java/lang/String.eea delete mode 100644 annotations/java/lang/StringBuilder.eea delete mode 100644 annotations/java/lang/reflect/Field.eea delete mode 100644 annotations/java/math/BigDecimal.eea delete mode 100644 annotations/java/util/Collections.eea delete mode 100644 annotations/java/util/Objects.eea delete mode 100644 annotations/org/slf4j/LoggerFactory.eea diff --git a/annotations/java/lang/Class.eea b/annotations/java/lang/Class.eea deleted file mode 100644 index b39b5e1..0000000 --- a/annotations/java/lang/Class.eea +++ /dev/null @@ -1,4 +0,0 @@ -class java/lang/Class -getResource - (Ljava/lang/String;)Ljava/net/URL; - (Ljava/lang/String;)L0java/net/URL; diff --git a/annotations/java/lang/String.eea b/annotations/java/lang/String.eea deleted file mode 100644 index 50c4bcb..0000000 --- a/annotations/java/lang/String.eea +++ /dev/null @@ -1,4 +0,0 @@ -class java/lang/String -format - (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String; - (Ljava/lang/String;[Ljava/lang/Object;)L1java/lang/String; diff --git a/annotations/java/lang/StringBuilder.eea b/annotations/java/lang/StringBuilder.eea deleted file mode 100644 index 7b45488..0000000 --- a/annotations/java/lang/StringBuilder.eea +++ /dev/null @@ -1,4 +0,0 @@ -class java/lang/StringBuilder -toString - ()Ljava/lang/String; - ()L1java/lang/String; diff --git a/annotations/java/lang/reflect/Field.eea b/annotations/java/lang/reflect/Field.eea deleted file mode 100644 index 44da91c..0000000 --- a/annotations/java/lang/reflect/Field.eea +++ /dev/null @@ -1,4 +0,0 @@ -class java/lang/reflect/Field -getAnnotation - (Ljava/lang/Class;)TT; - (Ljava/lang/Class;)T0T; diff --git a/annotations/java/math/BigDecimal.eea b/annotations/java/math/BigDecimal.eea deleted file mode 100644 index 2eb31be..0000000 --- a/annotations/java/math/BigDecimal.eea +++ /dev/null @@ -1,13 +0,0 @@ -class java/math/BigDecimal -ZERO - Ljava/math/BigDecimal; - L1java/math/BigDecimal; -add - (Ljava/math/BigDecimal;)Ljava/math/BigDecimal; - (Ljava/math/BigDecimal;)L1java/math/BigDecimal; -setScale - (ILjava/math/RoundingMode;)Ljava/math/BigDecimal; - (ILjava/math/RoundingMode;)L1java/math/BigDecimal; -valueOf - (J)Ljava/math/BigDecimal; - (J)L1java/math/BigDecimal; diff --git a/annotations/java/util/Collections.eea b/annotations/java/util/Collections.eea deleted file mode 100644 index 90e6e0c..0000000 --- a/annotations/java/util/Collections.eea +++ /dev/null @@ -1,10 +0,0 @@ -class java/util/Collections -emptyMap - ()Ljava/util/Map; - ()L1java/util/Map; -unmodifiableCollection - (Ljava/util/Collection<+TT;>;)Ljava/util/Collection; - (Ljava/util/Collection<+TT;>;)L1java/util/Collection; -unmodifiableMap - (Ljava/util/Map<+TK;+TV;>;)Ljava/util/Map; - (Ljava/util/Map<+TK;+TV;>;)L1java/util/Map; diff --git a/annotations/java/util/Objects.eea b/annotations/java/util/Objects.eea deleted file mode 100644 index 6631c1a..0000000 --- a/annotations/java/util/Objects.eea +++ /dev/null @@ -1,4 +0,0 @@ -class java/util/Objects -requireNonNull - (TT;)TT; - <1T:Ljava/lang/Object;>(TT;)T1T; diff --git a/annotations/org/slf4j/LoggerFactory.eea b/annotations/org/slf4j/LoggerFactory.eea deleted file mode 100644 index 5676819..0000000 --- a/annotations/org/slf4j/LoggerFactory.eea +++ /dev/null @@ -1,4 +0,0 @@ -class org/slf4j/LoggerFactory -getLogger - (Ljava/lang/Class<*>;)Lorg/slf4j/Logger; - (Ljava/lang/Class<*>;)L1org/slf4j/Logger; From 0f592dfb91bcba53854b3a62ae550784bdddf357 Mon Sep 17 00:00:00 2001 From: csowada Date: Sun, 27 Dec 2020 14:02:45 +0100 Subject: [PATCH 06/11] Add null checks for listener methods --- src/main/java/de/csdev/ebus/client/EBusClient.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/de/csdev/ebus/client/EBusClient.java b/src/main/java/de/csdev/ebus/client/EBusClient.java index b81928f..05f5f1a 100644 --- a/src/main/java/de/csdev/ebus/client/EBusClient.java +++ b/src/main/java/de/csdev/ebus/client/EBusClient.java @@ -82,6 +82,8 @@ public void addEBusDeviceTableListener(final @NonNull IEBusDeviceTableListener l Objects.requireNonNull(listener, LABEL_LISTENER); if (deviceTable != null) { deviceTable.addEBusDeviceTableListener(listener); + } else { + throw new IllegalStateException("Device Table is not initialized!"); } } @@ -95,6 +97,8 @@ public void addEBusEventListener(final @NonNull IEBusConnectorEventListener list Objects.requireNonNull(listener, LABEL_LISTENER); if (controller != null) { controller.addEBusEventListener(listener); + } else { + throw new IllegalStateException("Controller is not initialized!"); } } @@ -108,6 +112,8 @@ public void addEBusParserListener(final @NonNull IEBusParserListener listener) { Objects.requireNonNull(listener, LABEL_LISTENER); if (resolverService != null) { resolverService.addEBusParserListener(listener); + } else { + throw new IllegalStateException("Resolver Service is not initialized!"); } } From 3c76bee5d0f44a48a850b09d276220d1c5c47a5b Mon Sep 17 00:00:00 2001 From: csowada Date: Sun, 27 Dec 2020 14:03:27 +0100 Subject: [PATCH 07/11] Fix parameter name --- .../java/de/csdev/ebus/core/EBusReceiveStateMachine.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/csdev/ebus/core/EBusReceiveStateMachine.java b/src/main/java/de/csdev/ebus/core/EBusReceiveStateMachine.java index 2b3ec3c..49847b1 100644 --- a/src/main/java/de/csdev/ebus/core/EBusReceiveStateMachine.java +++ b/src/main/java/de/csdev/ebus/core/EBusReceiveStateMachine.java @@ -222,12 +222,12 @@ public String toDumpString() { /** * Update the state machine * - * @param data The next byte + * @param dataByte The next byte * @throws EBusDataException throws an exception on any telegram error */ - public void update(final byte data0) throws EBusDataException { + public void update(final byte dataByte) throws EBusDataException { - byte data = data0; + byte data = dataByte; try { From 812ec7526a3dabaf6bf25f104e0011d9fd52151b Mon Sep 17 00:00:00 2001 From: csowada Date: Sun, 27 Dec 2020 14:04:01 +0100 Subject: [PATCH 08/11] Enhance Thread Pool size to 60 --- src/main/java/de/csdev/ebus/core/EBusControllerBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/csdev/ebus/core/EBusControllerBase.java b/src/main/java/de/csdev/ebus/core/EBusControllerBase.java index 4f20e53..7403ec2 100644 --- a/src/main/java/de/csdev/ebus/core/EBusControllerBase.java +++ b/src/main/java/de/csdev/ebus/core/EBusControllerBase.java @@ -236,7 +236,7 @@ protected void fireOnEBusConnectionStatusChange(final @NonNull ConnectionStatus protected void initThreadPool() { // create new thread pool to send received telegrams // limit the number of threads to 30 - threadPool = new ThreadPoolExecutor(0, 30, 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), + threadPool = new ThreadPoolExecutor(5, 60, 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new EBusWorkerThreadFactory("ebus-receiver", true)); // create watch dog thread pool From b267a2c34547ef3c97984d6c2b10665564e8727c Mon Sep 17 00:00:00 2001 From: csowada Date: Sun, 27 Dec 2020 15:27:51 +0100 Subject: [PATCH 09/11] Update GitHub Actions --- .github/workflows/codeql-analysis.yml | 4 ++-- .github/workflows/maven-publish.yml | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9b9378c..8e0ca2b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,10 +13,10 @@ name: "CodeQL" on: push: - branches: [ master ] + branches: [ master, develop ] pull_request: # The branches below must be a subset of the branches above - branches: [ master ] + branches: [ master, develop ] schedule: - cron: '15 0 * * 6' diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 4b1f8a9..18d2beb 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -61,16 +61,15 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Create GitGub Release - id: create_release - uses: actions/create-release@v1 + - name: Create a new GitHub Release + uses: docker://antonyurchenko/git-release:latest env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DRAFT_RELEASE: "true" + PRE_RELEASE: "false" + CHANGELOG_FILE: "CHANGELOG.md" + ALLOW_EMPTY_CHANGELOG: "true" + ALLOW_TAG_PREFIX: "true" with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - body: | - Changes in this Release - - draft: true - prerelease: false \ No newline at end of file + args: | + target/*.jar \ No newline at end of file From f87f11a18035a219eb25a8b5c476f9ffeecde832 Mon Sep 17 00:00:00 2001 From: csowada Date: Sun, 27 Dec 2020 15:28:07 +0100 Subject: [PATCH 10/11] Update changelog for the next release --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 438c96b..455248b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. ## Unreleased + +## [1.1.4] - 2020-12-27 +### Changed +- Enhanced the internal ThreadPool from 30 to 60 to prevent issues on startup +- Throw better excepetions if the json configuration file is not valid +- Removed the unsed ``annotation`` folder ### Fixed - The new "Change Status" check (from v1.0.8) does not work, since the old status is already set previously From 01ae006190625b101ef2a113d2be2b53bffa334a Mon Sep 17 00:00:00 2001 From: csowada Date: Sun, 27 Dec 2020 15:28:41 +0100 Subject: [PATCH 11/11] Update versions for release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 33b1b8b..54369ef 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ eBUS core library - This library handles the communication with heating engineering via the BUS specification. This protocol is used by many heating manufacturers in Europe. de.cs-dev.ebus ebus-core - 1.1.4-SNAPSHOT + 1.1.4 https://github.com/csowada/ebus bundle