Skip to content

Commit

Permalink
fix(core): Replace special characters with a post processing step (#78)
Browse files Browse the repository at this point in the history
- toString changes
- Now some classes are havin NonNull and Nullable annotations
- Tests passes again.
  • Loading branch information
nandorholozsnyak committed Sep 9, 2023
1 parent c64e2c9 commit 5de2934
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.rodnansol.core.generator.template.data;

import com.github.jknack.handlebars.internal.lang3.StringUtils;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

import java.util.Objects;
import java.util.StringJoiner;

/**
* Class representing a property.
Expand All @@ -26,18 +27,22 @@ public class Property {
/**
* Property's key.
*/
@Nullable
private String key;
/**
* Property's description if specified.
*/
@Nullable
private String description;
/**
* Property's default value if specified.
*/
@Nullable
private String defaultValue;
/**
* Property's deprecation.
*/
@Nullable
private PropertyDeprecation propertyDeprecation;

public Property(String fqName, String type) {
Expand All @@ -47,10 +52,10 @@ public Property(String fqName, String type) {

public Property(String fqName, String type, String key, String description, String defaultValue, PropertyDeprecation propertyDeprecation) {
this(fqName, type);
this.key = StringUtils.defaultIfBlank(key, "");
this.description = StringUtils.defaultIfBlank(description, "");
this.defaultValue = StringUtils.defaultIfBlank(defaultValue, "");
this.propertyDeprecation = Objects.requireNonNullElse(propertyDeprecation, new PropertyDeprecation());
this.key = key;
this.description = description;
this.defaultValue = defaultValue;
this.propertyDeprecation = propertyDeprecation;
}

/**
Expand All @@ -64,42 +69,47 @@ public static Builder builder(String fqName, String type) {
return new Builder(fqName, type);
}

@Nullable
public String getKey() {
return key;
}

public void setKey(String key) {
public void setKey(@Nullable String key) {
this.key = key;
}

@Nullable
public String getDescription() {
return description;
}

public void setDescription(String description) {
public void setDescription(@Nullable String description) {
this.description = description;
}

@Nullable
public String getDefaultValue() {
return defaultValue;
}

public void setDefaultValue(String defaultValue) {
public void setDefaultValue(@Nullable String defaultValue) {
this.defaultValue = defaultValue;
}

@NonNull
public String getType() {
return type;
}

@Nullable
public PropertyDeprecation getPropertyDeprecation() {
return propertyDeprecation;
}

public void setPropertyDeprecation(PropertyDeprecation propertyDeprecation) {
public void setPropertyDeprecation(@Nullable PropertyDeprecation propertyDeprecation) {
this.propertyDeprecation = propertyDeprecation;
}

@NonNull
public String getFqName() {
return fqName;
}
Expand All @@ -119,14 +129,14 @@ public int hashCode() {

@Override
public String toString() {
return "Property{" +
"fqName='" + fqName + '\'' +
", type='" + type + '\'' +
", key='" + key + '\'' +
", description='" + description + '\'' +
", defaultValue='" + defaultValue + '\'' +
", propertyDeprecation=" + propertyDeprecation +
'}';
return new StringJoiner(",\n\t", Property.class.getSimpleName() + "[", "]")
.add("fqName='" + fqName + "'")
.add("type='" + type + "'")
.add("key='" + key + "'")
.add("description='" + description + "'")
.add("defaultValue='" + defaultValue + "'")
.add("propertyDeprecation=" + propertyDeprecation)
.toString();
}

public static final class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ public class PropertyDeprecation {
@Nullable
private final String replacement;

public PropertyDeprecation() {
reason = null;
replacement = null;
}

public PropertyDeprecation(String reason, String replacement) {
public PropertyDeprecation(@Nullable String reason, @Nullable String replacement) {
this.reason = reason;
this.replacement = replacement;
}

@Nullable
public String getReason() {
return reason;
}

@Nullable
public String getReplacement() {
return replacement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;

import static org.rodnansol.core.generator.template.data.PropertyGroupConstants.UNKNOWN;
import static org.rodnansol.core.generator.template.data.PropertyGroupConstants.UNKNOWN_GROUP;
Expand Down Expand Up @@ -141,15 +142,15 @@ public PropertyGroup addProperty(Property property) {

@Override
public String toString() {
return "PropertyGroup{" +
"groupName='" + groupName + '\'' +
", type='" + type + '\'' +
", sourceType='" + sourceType + '\'' +
", properties=" + properties +
", parentGroup=" + parentGroup +
", nested=" + nested +
", unknownGroup=" + unknownGroup +
'}';
return new StringJoiner(",\n\t", PropertyGroup.class.getSimpleName() + "[", "]")
.add("type='" + type + "'")
.add("sourceType='" + sourceType + "'")
.add("groupName='" + groupName + "'")
.add("properties=" + properties)
.add("parentGroup=" + parentGroup)
.add("nested=" + nested)
.add("unknownGroup=" + unknownGroup)
.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.rodnansol.core.generator.writer;

import java.util.StringJoiner;

/**
* Class representing a customization for the templates.
* <p>
Expand Down Expand Up @@ -46,10 +48,10 @@ public void setCustomFooterTemplate(String customFooterTemplate) {

@Override
public String toString() {
return "CustomTemplate{" +
"customHeaderTemplate='" + customHeaderTemplate + '\'' +
", customContentTemplate='" + customContentTemplate + '\'' +
", customFooterTemplate='" + customFooterTemplate + '\'' +
'}';
return new StringJoiner(",\n\t", CustomTemplate.class.getSimpleName() + "[", "]")
.add("customHeaderTemplate='" + customHeaderTemplate + "'")
.add("customContentTemplate='" + customContentTemplate + "'")
.add("customFooterTemplate='" + customFooterTemplate + "'")
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;

/**
* Class grouping attributes together that helps to post process the property groups and properties.
Expand Down Expand Up @@ -80,13 +81,13 @@ public int hashCode() {

@Override
public String toString() {
return "PostProcessPropertyGroupsCommand{" +
"templateCustomization=" + templateCustomization +
", propertyGroups=" + propertyGroups +
", excludedGroups=" + excludedGroups +
", includedGroups=" + includedGroups +
", excludedProperties=" + excludedProperties +
", includedProperties=" + includedProperties +
'}';
return new StringJoiner(",\n\t", PostProcessPropertyGroupsCommand.class.getSimpleName() + "[", "]")
.add("templateCustomization=" + templateCustomization)
.add("propertyGroups=" + propertyGroups)
.add("excludedGroups=" + excludedGroups)
.add("includedGroups=" + includedGroups)
.add("excludedProperties=" + excludedProperties)
.add("includedProperties=" + includedProperties)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.Objects;

import static java.util.Map.entry;
import static java.util.Map.ofEntries;
Expand Down Expand Up @@ -62,8 +63,10 @@ public void postProcess(PostProcessPropertyGroupsCommand command) {

private void replaceSpecialCharacters(Property property, Map<String, String> specialCharacterMap) {
specialCharacterMap.forEach((character, replacement) -> {
property.setDescription(property.getDescription().replace(character, replacement));
property.setDefaultValue(property.getDefaultValue().replace(character, replacement));
if (Objects.nonNull(property.getDescription()))
property.setDescription(property.getDescription().replace(character, replacement));
if (Objects.nonNull(property.getDefaultValue()))
property.setDefaultValue(property.getDefaultValue().replace(character, replacement));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ProjectType getProjectType() {

@Override
public String toString() {
return new StringJoiner(", ", Project.class.getSimpleName() + "[", "]")
return new StringJoiner(",\n\t", Project.class.getSimpleName() + "[", "]")
.add("basedir=" + basedir)
.add("name='" + name + "'")
.add("projectType=" + projectType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void setIncludedGroups(List<String> includedGroups) {

@Override
public String toString() {
return new StringJoiner(", ", AggregationInput.class.getSimpleName() + "[", "]")
return new StringJoiner(",\n\t", AggregationInput.class.getSimpleName() + "[", "]")
.add("excludedProperties=" + excludedProperties)
.add("includedProperties=" + includedProperties)
.add("excludedGroups=" + excludedGroups)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public void metadata(Closure closure) {

@Override
public String toString() {
return new StringJoiner(", ", GenerateAndAggregateDocumentsTask.class.getSimpleName() + "[", "]")
return new StringJoiner(",\n\t", GenerateAndAggregateDocumentsTask.class.getSimpleName() + "[", "]")
.add("metadataInputs=" + metadataInputs)
.add("documentName='" + documentName + "'")
.add("documentDescription='" + documentDescription + "'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public void setFailOnMissingInput(Boolean failOnMissingInput) {

@Override
public String toString() {
return new StringJoiner(", ", GeneratePropertyDocumentTask.class.getSimpleName() + "[", "]")
return new StringJoiner(",\n\t", GeneratePropertyDocumentTask.class.getSimpleName() + "[", "]")
.add("documentName='" + documentName + "'")
.add("documentDescription='" + documentDescription + "'")
.add("template='" + template + "'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public int hashCode() {

@Override
public String toString() {
return new StringJoiner(", ", AbstractTemplateCustomization.class.getSimpleName() + "[", "]")
return new StringJoiner(",\n\t", AbstractTemplateCustomization.class.getSimpleName() + "[", "]")
.add("tocTitle='" + tocTitle + "'")
.add("headerEnabled=" + headerEnabled)
.add("tableOfContentsEnabled=" + tableOfContentsEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public int hashCode() {

@Override
public String toString() {
return new StringJoiner(", ", AsciiDocTemplateCustomization.class.getSimpleName() + "[", "]")
return new StringJoiner(",\n\t", AsciiDocTemplateCustomization.class.getSimpleName() + "[", "]")
.add("tocPlacement=" + tocPlacement)
.add("tocLevels=" + tocLevels)
.add("tocTitle='" + tocTitle + "'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public int hashCode() {

@Override
public String toString() {
return new StringJoiner(", ", HtmlTemplateCustomization.class.getSimpleName() + "[", "]")
return new StringJoiner(",\n\t", HtmlTemplateCustomization.class.getSimpleName() + "[", "]")
.add("backgroundColor='" + backgroundColor + "'")
.add("linkColor='" + linkColor + "'")
.add("collapsibleHoverColor='" + collapsibleHoverColor + "'")
Expand Down

0 comments on commit 5de2934

Please sign in to comment.