From bb5a03707b506eacd924fc8b71d8da67e3322fc1 Mon Sep 17 00:00:00 2001 From: Jamie Shiell Date: Sun, 5 Jun 2022 11:41:46 +0100 Subject: [PATCH] Fix serialisation of property values (#573) --- CHANGELOG.md | 1 + .../config/ProjectConfigurationState.java | 68 +++++++++++-------- src/main/resources/META-INF/plugin.xml | 1 + 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd354e43..d3c415d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # CheckStyle-IDEA Changelog * **5.67.1** Fix: Improve serialisation from legacy formats (#574). +* **5.67.1** Fix: Fix serialisation of property values (#573). * **5.67.0** New: Added Checkstyle 10.3. * **5.67.0** Fix: Project paths should now remain relative where possible (#569). * **5.67.0** Fix: Fix NPE in module configuration (#570). diff --git a/src/main/java/org/infernus/idea/checkstyle/config/ProjectConfigurationState.java b/src/main/java/org/infernus/idea/checkstyle/config/ProjectConfigurationState.java index 7cf0a69c..fe98d934 100644 --- a/src/main/java/org/infernus/idea/checkstyle/config/ProjectConfigurationState.java +++ b/src/main/java/org/infernus/idea/checkstyle/config/ProjectConfigurationState.java @@ -105,19 +105,21 @@ static ProjectSettings create(@NotNull final PluginConfiguration currentPluginCo projectSettings.activeLocationIds = new ArrayList<>(currentPluginConfig.getActiveLocationIds()); projectSettings.locations = currentPluginConfig.getLocations().stream() - .map(location -> new ConfigurationLocation( - location.getId(), - location.getType().name(), - location.getRawLocation(), - location.getDescription(), - location.getNamedScope().map(NamedScope::getScopeId).orElse("") - )) - .collect(Collectors.toList()); + .map(location -> new ConfigurationLocation( + location.getId(), + location.getType().name(), + location.getRawLocation(), + location.getDescription(), + location.getNamedScope().map(NamedScope::getScopeId).orElse(""), + location.getProperties() + )) + .collect(Collectors.toList()); return projectSettings; } - @SuppressWarnings("unused") // for serialisation + @SuppressWarnings("unused") + // for serialisation ProjectSettings() { } @@ -168,20 +170,22 @@ private ConfigurationLocationFactory configurationLocationFactory(@NotNull final } @Nullable - private org.infernus.idea.checkstyle.model.ConfigurationLocation deserialiseLocation(@NotNull Project project, - @Nullable ProjectConfigurationState.ConfigurationLocation location) { + private org.infernus.idea.checkstyle.model.ConfigurationLocation deserialiseLocation(@NotNull final Project project, + @Nullable final ProjectConfigurationState.ConfigurationLocation location) { if (location == null) { return null; } try { - return configurationLocationFactory(project).create( + org.infernus.idea.checkstyle.model.ConfigurationLocation configurationLocation = configurationLocationFactory(project).create( project, location.id, ConfigurationType.parse(location.type), - location.location, + Objects.requireNonNullElse(location.location, "").trim(), location.description, NamedScopeHelper.getScopeByIdWithDefaultFallback(project, location.scope)); + configurationLocation.setProperties(Objects.requireNonNullElse(location.properties, new HashMap<>())); + return configurationLocation; } catch (Exception e) { LOG.error("Failed to deserialise " + location, e); return null; @@ -201,32 +205,42 @@ static class ConfigurationLocation { private String description; @Text private String location; + @MapAnnotation + private Map properties; - @SuppressWarnings("unused") // serialisation - public ConfigurationLocation() { + @SuppressWarnings("unused") + // serialisation + ConfigurationLocation() { } - public ConfigurationLocation(String id, - String type, - String location, - String description, - String scope) { + ConfigurationLocation(final String id, + final String type, + final String location, + final String description, + final String scope, + final Map properties) { this.id = id; this.type = type; this.scope = scope; this.description = description; this.location = location; + if (properties != null && !properties.isEmpty()) { + this.properties = properties; + } else { + this.properties = null; + } } @Override public String toString() { - return "ConfigurationLocation{" + - "id='" + id + '\'' + - ", type='" + type + '\'' + - ", scope='" + scope + '\'' + - ", description='" + description + '\'' + - ", location='" + location + '\'' + - '}'; + return "ConfigurationLocation{" + + "id='" + id + '\'' + + ", type='" + type + '\'' + + ", scope='" + scope + '\'' + + ", description='" + description + '\'' + + ", location='" + location + '\'' + + ", properties='" + properties + '\'' + + '}'; } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 26cc09a0..47cdabbb 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -25,6 +25,7 @@
  • 5.67.1: Fix: Improve serialisation from legacy formats (#574).
  • +
  • 5.67.1: Fix: Fix serialisation of property values (#573).
  • 5.67.0: New: Added Checkstyle 10.3.
  • 5.67.0: Fix: Project paths should now remain relative where possible (#569).
  • 5.67.0: Fix: Fix NPE in module configuration (#570).