diff --git a/src/main/java/io/kokuwa/edge/esh/constants/maven/plugin/GenerateConstantsMojo.java b/src/main/java/io/kokuwa/edge/esh/constants/maven/plugin/GenerateConstantsMojo.java index da6b6a2..915b799 100644 --- a/src/main/java/io/kokuwa/edge/esh/constants/maven/plugin/GenerateConstantsMojo.java +++ b/src/main/java/io/kokuwa/edge/esh/constants/maven/plugin/GenerateConstantsMojo.java @@ -40,6 +40,24 @@ @Mojo(name = "generate-esh-constants", defaultPhase = LifecyclePhase.GENERATE_SOURCES) public class GenerateConstantsMojo extends AbstractMojo { + /** + * property names which are already defined in org.eclipse.smarthome.core.thing.Thing + */ + private static final Set STANDARD_PROPERTIES = Set.of( + /* the key for the vendor property */ + "vendor", + /* the key for the model ID property */ + "modelId", + /* the key for the serial number property */ + "serialNumber", + /* the key for the hardware version property */ + "hardwareVersion", + /* the key for the firmware version property */ + "firmwareVersion", + /* the key for the MAC address property */ + "macAddress" + ); + @Parameter(property = "esh-constants.inputDirectory", defaultValue = "${project.basedir}/src/main/resources/ESH-INF") private String inputDirectory; @@ -66,7 +84,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { final Map constants = new LinkedHashMap<>(); Set bindingIDs = scanDocuments(inputFiles, "//thing-descriptions/@bindingId"); - Set properties = scanDocuments(inputFiles, "//property/@name"); + Set properties = exclude(STANDARD_PROPERTIES, scanDocuments(inputFiles, "//property/@name")); Set thingTypeIDs = scanDocuments(inputFiles, "//thing-type/@id"); Set bridgeTypeIDs = scanDocuments(inputFiles, "//bridge-type/@id"); Set channelIDs = scanDocuments(inputFiles, "//channel/@id"); @@ -267,4 +285,15 @@ private void writeFile(Path path, String content) throws MojoExecutionException throw new MojoExecutionException("Unable to write file: " + path, e); } } + + /** + * @param exclude the set of values to exclude + * @param candidates the origin value set + * @return a copy of candidates with all values from exclude removed + */ + private static Set exclude(Set exclude, Set candidates) { + return candidates.stream() + .filter(candidate -> !exclude.contains(candidate)) + .collect(Collectors.toSet()); + } } diff --git a/src/test/resources/ESH-INF/thing/thing-types.xml b/src/test/resources/ESH-INF/thing/thing-types.xml index 6e2012e..bbcfaf9 100644 --- a/src/test/resources/ESH-INF/thing/thing-types.xml +++ b/src/test/resources/ESH-INF/thing/thing-types.xml @@ -32,6 +32,17 @@ minutes + + + + N/A + N/A + N/A + N/A + N/A + N/A + + diff --git a/src/test/resources/expected.java b/src/test/resources/expected.java index cff219d..9a5af7b 100644 --- a/src/test/resources/expected.java +++ b/src/test/resources/expected.java @@ -16,8 +16,6 @@ private Constants() { public static final String BINDING_ID = "wmbus"; // Constants - public static final String PROPERTY_VENDOR = "vendor"; - public static final String PROPERTY_MODELID = "modelId"; public static final String PROPERTY_SERIAL = "serial"; public static final String THING_TYPE_ID_ITRON_SMOKE_DETECTOR = "itron_smoke_detector"; public static final String THING_TYPE_ID_TECHEM_HKV45 = "techem_hkv45";