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

Move DOMUtil ConfigNode methods to ConfigNode, with some name changes. #3027

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

dsmiley
Copy link
Contributor

@dsmiley dsmiley commented Jan 12, 2025

ConfigNode.requiredStrAttr -> attrRequired
ConfigNode.child (ex) -> childRequired
ConfigNode.getAll move name to first param; don't use empty set

PluginInfo: don't need the XML Node constructor anymore

A Solr 10-only change

ConfigNode.requiredStrAttr -> attrRequired
ConfigNode.child (ex) -> childRequired
ConfigNode.getAll move name to first param; don't use empty set

PluginInfo: don't need the XML Node constructor anymore
children = loadSubPlugins(node);
isFromSolrConfig = true;
@VisibleForTesting
PluginInfo(Node node, String err, boolean requireName, boolean requireClass) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't truly need this but it's a convenience constructor for one test.
It's crazy PluginInfo had duplicated code for Node vs ConfigNode -- no need.

Map<String, String> attrs;
private Map<String, String> attrs; // lazy populated

public DOMConfigNode(Node node) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constructor was misplaced

@@ -94,9 +94,13 @@ public List<ConfigNode> getAll(String name) {
}

@Override
public List<ConfigNode> getAll(Predicate<ConfigNode> test, Set<String> matchNames) {
public List<ConfigNode> getAll(Set<String> names, Predicate<ConfigNode> test) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name/names should go first in these methods. More logical / good taste.

Comment on lines +98 to +100
if (names == null) {
return ConfigNode.super.getAll(names, test);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually fixes a bug since this overriding code doesn't handle null names, and an empty names was weird so I made that basically disallowed.

Map<String, String> attributes();

/** Mutable copy of {@link #attributes()}, excluding {@code exclusions} keys. */
default Map<String, String> attributesExcept(String... exclusions) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formerly was DOMUtil.toMapExcept. This is a better name and needed documentation. I also added a check for a reasonable number of exclusions, and also pre-initialize the result map size.

Comment on lines -74 to +88
default ConfigNode child(String name, Supplier<RuntimeException> err) {
default ConfigNode childRequired(String name, Supplier<RuntimeException> err) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want "required" in the name to better differentiate the overloads

*/
default List<ConfigNode> getAll(Predicate<ConfigNode> test, String... nodeNames) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't need this one

List<ConfigNode> result = new ArrayList<>();
forEachChild(
it -> {
if (matchNames != null && !matchNames.isEmpty() && !matchNames.contains(it.name()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer using empty as a reasonable param

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense for DOMUtil to refer to ConfigNode; the latter is a higher level concept. The methods in here referring to it were itching to be instance methods on ConfigNode, which is much more natural for callers. I don't see why ConfigNode & implementations are doing in SolrJ; there are too many things in SolrJ that don't belong there.

This is mostly what precipitated the substance of this PR.

I didn't rename methods in DOMUtil based on the naming choices in ConfigNode (e.g. toMap -> attributes, ...) but maybe should be for consistency? I'm more inclined to let it be. DOMUtil doesn't have many callers anymore. The code there is ancient.

Copy link
Contributor

@epugh epugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an area I understand well, but the diff changes did make things more legible, and i apprecaited the additional comments.

@@ -100,39 +100,23 @@ public String toString() {
}
}

/** From XML. */
Copy link
Contributor

@epugh epugh Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extend just a bit? From schema.xml? It made me look for a similar constructor that was /** From JSON. */ further down...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor supports XML config generally; not just a specific file as you wondered. I added it because it may not be obvious to the reader who may be unfamiliar with ConfigNode but who would recognize XML Node type. The other constructors are more general; can't be said to be from any particular format. I could drop this but was trying to be helpful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's fine. Thanks!

@dsmiley dsmiley merged commit ca935b3 into apache:main Jan 15, 2025
4 checks passed
@dsmiley dsmiley deleted the ConfigNode branch January 15, 2025 04:06
@dsmiley
Copy link
Contributor Author

dsmiley commented Jan 17, 2025

In the description, I said Solr 10 only but actually I see no reason why these internal changes couldn't be applied to branch_9x as well so I'll do that too.

dsmiley added a commit that referenced this pull request Jan 17, 2025
#3027)

(internal refactoring)
ConfigNode.requiredStrAttr -> attrRequired
ConfigNode.child (ex) -> childRequired
ConfigNode.getAll move name to first param and don't accept empty set

PluginInfo: don't need the XML Node constructor anymore
(cherry picked from commit ca935b3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants