Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust to core changes (addon.xml) #444

Merged
merged 3 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected void checkConfigFile(final FileText xmlFileText) throws CheckstyleExce
}

@Override
protected void checkBindingFile(final FileText xmlFileText) throws CheckstyleException {
protected void checkAddonFile(final FileText xmlFileText) throws CheckstyleException {
// No labels in binding files.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ protected void checkConfigFile(final FileText xmlFileText) throws CheckstyleExce
}

@Override
protected void checkBindingFile(final FileText xmlFileText) throws CheckstyleException {
// The allowed values are described in the binding XSD
protected void checkAddonFile(final FileText xmlFileText) throws CheckstyleException {
// The allowed values are described in the addon XSD
allConfigDescriptionRefs.putAll(evaluateExpressionOnFile(xmlFileText, CONFIG_DESCRIPTION_REF_EXPRESSION));
allConfigDescriptions.putAll(evaluateExpressionOnFile(xmlFileText, CONFIG_DESCRIPTION_EXPRESSION));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public class OhInfXmlValidationCheck extends AbstractOhInfXmlCheck {
private Map<Path, File> ohInfFiles = new HashMap<>();

private String thingSchema;
private String bindingSchema;
private String addonSchema;
private String configSchema;

private static Schema thingSchemaFile;
private static Schema bindingSchemaFile;
private static Schema addonSchemaFile;
private static Schema configSchemaFile;

/**
Expand All @@ -73,10 +73,10 @@ public void setThingSchema(String thingSchema) {
/**
* Sets the configuration property for the binding schema file.
*
* @param bindingSchema URL of the binding schema file
* @param addonSchema URL of the binding schema file
*/
public void setBindingSchema(String bindingSchema) {
this.bindingSchema = bindingSchema;
public void setAddonSchema(String addonSchema) {
this.addonSchema = addonSchema;
}

/**
Expand Down Expand Up @@ -111,7 +111,7 @@ public Schema transform(byte[] content) {

CachingHttpClient<Schema> cachingClient = new CachingHttpClient<>(callback);

bindingSchemaFile = getXSD(bindingSchema, cachingClient);
addonSchemaFile = getXSD(addonSchema, cachingClient);
thingSchemaFile = getXSD(thingSchema, cachingClient);
configSchemaFile = getXSD(configSchema, cachingClient);

Expand All @@ -126,10 +126,10 @@ protected void checkConfigFile(FileText xmlFileText) throws CheckstyleException
}

@Override
protected void checkBindingFile(FileText xmlFileText) throws CheckstyleException {
protected void checkAddonFile(FileText xmlFileText) throws CheckstyleException {
File xmlFile = xmlFileText.getFile();
addToOhFiles(xmlFile);
validateXmlAgainstSchema(xmlFile, bindingSchemaFile);
validateXmlAgainstSchema(xmlFile, addonSchemaFile);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
public abstract class AbstractOhInfXmlCheck extends AbstractStaticCheck {
public static final String THING_DIRECTORY = "thing";
public static final String BINDING_DIRECTORY = "binding";
public static final String ADDON_DIRECTORY = "addon";
public static final String CONFIGURATION_DIRECTORY = "config";

private static final String MESSAGE_EMPTY_FILE = "The file {0} should not be empty.";
Expand Down Expand Up @@ -77,8 +77,8 @@ private void processXmlFile(final FileText xmlFileText) throws CheckstyleExcepti
checkThingTypeFile(xmlFileText);
break;
}
case BINDING_DIRECTORY: {
checkBindingFile(xmlFileText);
case ADDON_DIRECTORY: {
checkAddonFile(xmlFileText);
break;
}
case CONFIGURATION_DIRECTORY: {
Expand Down Expand Up @@ -108,7 +108,7 @@ private void processXmlFile(final FileText xmlFileText) throws CheckstyleExcepti
* @param xmlFileText Represents the text contents of the xml file
* @throws CheckstyleException when exception occurred during XML processing
*/
protected abstract void checkBindingFile(FileText xmlFileText) throws CheckstyleException;
protected abstract void checkAddonFile(FileText xmlFileText) throws CheckstyleException;

/**
* Validate a .xml file located in the OH-INF/thing directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public class OhInfXmlValidationCheckTest extends AbstractStaticCheckTest {

private static final String RELATIVE_PATH_TO_THING = File.separator + OH_INF_PATH + File.separator
+ OhInfXmlValidationCheck.THING_DIRECTORY + File.separator + "thing-types.xml";
private static final String RELATIVE_PATH_TO_BINDING = File.separator + OH_INF_PATH + File.separator
+ OhInfXmlValidationCheck.BINDING_DIRECTORY + File.separator + "bind.xml";
private static final String RELATIVE_PATH_TO_ADDON = File.separator + OH_INF_PATH + File.separator
+ OhInfXmlValidationCheck.ADDON_DIRECTORY + File.separator + "addon.xml";
private static final String RELATIVE_PATH_TO_CONFIG = File.separator + OH_INF_PATH + File.separator
+ OhInfXmlValidationCheck.CONFIGURATION_DIRECTORY + File.separator + "conf.xml";

private static final String SCHEMA_ROOT_URL = "https://openhab.org/schemas/";
private static final String THING_SCHEMA_URL = SCHEMA_ROOT_URL + "thing-description-1.0.0.xsd";
private static final String BINDING_SCHEMA_URL = SCHEMA_ROOT_URL + "binding-1.0.0.xsd";
private static final String ADDON_SCHEMA_URL = SCHEMA_ROOT_URL + "addon-1.0.0.xsd";
private static final String CONFIG_SCHEMA_URL = SCHEMA_ROOT_URL + "config-description-1.0.0.xsd";

private static final String MESSAGE_EMPTY_FILE = "The file {0} should not be empty.";
Expand All @@ -59,7 +59,7 @@ public class OhInfXmlValidationCheckTest extends AbstractStaticCheckTest {
@BeforeAll
public static void createConfiguration() {
CONFIGURATION.addProperty("thingSchema", THING_SCHEMA_URL);
CONFIGURATION.addProperty("bindingSchema", BINDING_SCHEMA_URL);
CONFIGURATION.addProperty("addonSchema", ADDON_SCHEMA_URL);
CONFIGURATION.addProperty("configSchema", CONFIG_SCHEMA_URL);
}

Expand Down Expand Up @@ -157,13 +157,13 @@ public void testValidBridgeType() throws Exception {
}

@Test
public void testInvalidBinding() throws Exception {
public void testInvalidAddon() throws Exception {
assumeTrue(isResourceAvailable);

int lineNumber = 7;
String[] expectedMessages = generateExpectedMessages(lineNumber,
"The content of element binding:binding is not complete. One of {name} is expected.");
verifyWithPath("invalidBinding", RELATIVE_PATH_TO_BINDING, expectedMessages);
"The content of element addon:addon is not complete. One of {type} is expected.");
verifyWithPath("invalidAddon", RELATIVE_PATH_TO_ADDON, expectedMessages);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void testXmlWithMultipleLinesWithSpacesEmptyLinesAndComments() throws Exc

@Test
public void testXmlWithOnlyTabsForIndentation() throws Exception {
String fileName = "binding.xml";
String fileName = "addon.xml";
verifyTabIdentation(fileName, noMessagesExpected(), false);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon:addon id="bindingID" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:addon="https://openhab.org/schemas/addon/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/addon/v1.0.0
https://openhab.org/schemas/addon-1.0.0.xsd">


</addon:addon>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<binding:binding id="bindingID" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:binding="https://openhab.org/schemas/binding/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0
https://openhab.org/schemas/binding-1.0.0.xsd">
<addon:addon id="bindingID" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:addon="https://openhab.org/schemas/addon/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/addon/v1.0.0
https://openhab.org/schemas/addon-1.0.0.xsd">

<type>binding</type>
<name>String</name>
<description>String</description>
<author>String</author>

<config-description-ref uri="binding:bindingID:bind" />

</binding:binding>
</addon:addon>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon:addon id="onewiregpio" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:addon="https://openhab.org/schemas/addon/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/addon/v1.0.0 https://openhab.org/schemas/addon-1.0.0.xsd">
<type>binding</type>
<name>OneWireGPIO Binding</name>
<description>Use GPIO in various devices like RaspberryPi to communicate the OneWire protocol</description>
<author>Anatol Ogorek</author>
</addon:addon>

This file was deleted.

6 changes: 3 additions & 3 deletions docs/maven-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ An example configuration may look like this;
<groupId>org.openhab.tools.sat</groupId>
<artifactId>sat-plugin</artifactId>
<configuration>
<checkstyleRuleset>build-tools/checkstyle/binding.xml</checkstyleRuleset>
<checkstyleRuleset>build-tools/checkstyle/addon.xml</checkstyleRuleset>
<checkstyleFilter>build-tools/checkstyle/suppressions.xml</checkstyleFilter>
<pmdRuleset>build-tools/pmd/binding.xml</pmdRuleset>
<pmdRuleset>build-tools/pmd/addon.xml</pmdRuleset>
<pmdFilter>build-tools/pmd/suppressions.properties</pmdFilter>
<spotbugsInclude>build-tools/spotbugs/binding.xml</spotbugsInclude>
<spotbugsInclude>build-tools/spotbugs/addon.xml</spotbugsInclude>
<spotbugsExclude>build-tools/spotbugs/exclude.xml</spotbugsExclude>
<spotbugsRuleset>build-tools/spotbugs/visitors.xml</spotbugsRuleset>
</configuration>
Expand Down