Skip to content

Commit 91d6291

Browse files
exceptionfactorypvillard31
authored andcommitted
NIFI-14374 Set Deterministic Order for Manifest Documentation
- Sorted Relationship documentation elements based on name field - Sorted Resource Type documentation elements based on enumeration name method - Sorted Property Dependencies based on dependent Property Name - Sorted Dependent Values based on natural String ordering Signed-off-by: Pierre Villard <[email protected]> This closes #4.
1 parent 1d6fafb commit 91d6291

File tree

2 files changed

+398
-17
lines changed

2 files changed

+398
-17
lines changed

src/main/java/org/apache/nifi/documentation/xml/XmlDocumentationWriter.java

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
import java.util.Arrays;
2222
import java.util.Collection;
2323
import java.util.Collections;
24+
import java.util.Comparator;
2425
import java.util.LinkedHashSet;
2526
import java.util.List;
2627
import java.util.Map;
2728
import java.util.Set;
29+
import java.util.TreeSet;
2830
import java.util.function.Function;
2931
import javax.xml.stream.XMLOutputFactory;
3032
import javax.xml.stream.XMLStreamException;
@@ -65,13 +67,11 @@
6567
import org.apache.nifi.processor.Relationship;
6668

6769
/**
68-
* XML-based implementation of DocumentationWriter
69-
*
70+
* XML-based implementation of DocumentationWriter.
7071
* Please note that while this class lives within the nifi-api, it is provided primarily as a means for documentation components within
7172
* the NiFi NAR Maven Plugin. Its home is the nifi-api, however, because the API is needed in order to extract the relevant information and
7273
* the NAR Maven Plugin cannot have a direct dependency on nifi-api (doing so would cause a circular dependency). By having this homed within
7374
* the nifi-api, the Maven plugin is able to discover the class dynamically and invoke the one or two methods necessary to create the documentation.
74-
*
7575
* This is a new capability in 1.9.0 in preparation for the Extension Registry and therefore, you should
7676
* <b>NOTE WELL:</b> At this time, while this class is part of nifi-api, it is still evolving and may change in a non-backward-compatible manner or even be
7777
* removed from one incremental release to the next. Use at your own risk!
@@ -108,19 +108,15 @@ protected void writeDeprecationNotice(final DeprecationNotice deprecationNotice)
108108
return;
109109
}
110110

111-
final Class[] classes = deprecationNotice.alternatives();
111+
final Class<?>[] classes = deprecationNotice.alternatives();
112112
final String[] classNames = deprecationNotice.classNames();
113113

114114
final Set<String> alternatives = new LinkedHashSet<>();
115-
if (classes != null) {
116-
for (final Class alternativeClass : classes) {
117-
alternatives.add(alternativeClass.getName());
118-
}
115+
for (final Class<?> alternativeClass : classes) {
116+
alternatives.add(alternativeClass.getName());
119117
}
120118

121-
if (classNames != null) {
122-
Collections.addAll(alternatives, classNames);
123-
}
119+
Collections.addAll(alternatives, classNames);
124120

125121
writeDeprecationNotice(deprecationNotice.reason(), alternatives);
126122
}
@@ -218,7 +214,16 @@ private void writeResourceDefinition(final ResourceDefinition resourceDefinition
218214

219215
writeStartElement("resourceDefinition");
220216
writeTextElement("cardinality", resourceDefinition.getCardinality().name());
221-
writeArray("resourceTypes", resourceDefinition.getResourceTypes(), this::writeResourceType);
217+
218+
final Set<ResourceType> resourceTypes = resourceDefinition.getResourceTypes();
219+
if (resourceTypes == null) {
220+
writeArray("resourceTypes", null, this::writeResourceType);
221+
} else {
222+
final Set<ResourceType> orderedResourceTypes = new TreeSet<>(Comparator.comparing(ResourceType::name));
223+
orderedResourceTypes.addAll(resourceTypes);
224+
writeArray("resourceTypes", orderedResourceTypes, this::writeResourceType);
225+
}
226+
222227
writeEndElement();
223228
}
224229

@@ -242,15 +247,18 @@ private void writeDependencies(final PropertyDescriptor propertyDescriptor) thro
242247

243248
writeStartElement("dependencies");
244249

245-
for (final PropertyDependency dependency : dependencies) {
250+
final Set<PropertyDependency> orderedDependencies = new TreeSet<>(Comparator.comparing(PropertyDependency::getPropertyName));
251+
orderedDependencies.addAll(dependencies);
252+
for (final PropertyDependency dependency : orderedDependencies) {
246253
writeStartElement("dependency");
247254
writeTextElement("propertyName", dependency.getPropertyName());
248255
writeTextElement("propertyDisplayName", dependency.getPropertyDisplayName());
249256

250257
final Set<String> dependentValues = dependency.getDependentValues();
251258
if (dependentValues != null) {
252259
writeStartElement("dependentValues");
253-
for (final String dependentValue : dependentValues) {
260+
final Collection<String> orderedDependentValues = new TreeSet<>(dependentValues);
261+
for (final String dependentValue : orderedDependentValues) {
254262
writeTextElement("dependentValue", dependentValue);
255263
}
256264
writeEndElement();
@@ -355,12 +363,12 @@ protected void writeSeeAlso(final SeeAlso seeAlso) throws IOException {
355363
return;
356364
}
357365

358-
final Class[] classes = seeAlso.value();
366+
final Class<?>[] classes = seeAlso.value();
359367
final String[] classNames = seeAlso.classNames();
360368

361369
final Set<String> toSee = new LinkedHashSet<>();
362370
if (classes != null) {
363-
for (final Class classToSee : classes) {
371+
for (final Class<?> classToSee : classes) {
364372
toSee.add(classToSee.getName());
365373
}
366374
}
@@ -434,7 +442,9 @@ protected void writeRelationships(final Set<Relationship> relationships) throws
434442
return;
435443
}
436444

437-
writeArray("relationships", relationships, rel -> {
445+
final Set<Relationship> ordered = new TreeSet<>(Comparator.comparing(Relationship::getName));
446+
ordered.addAll(relationships);
447+
writeArray("relationships", ordered, rel -> {
438448
writeStartElement("relationship");
439449

440450
writeTextElement("name", rel.getName());

0 commit comments

Comments
 (0)