Repository navigation
Conversation
|
We need to synchronize the implementation in plexus-xml, so we will keep it as a draft for now. |
gnodet
left a comment
There was a problem hiding this comment.
I'm -1 on this.
The role of an API is to decouple the contract from the implementation.
All interfaces in Maven have almost a single implementation, except a couple of interfaces.
The Single Interface Single Implementation is only an anti-pattern in a closed world, but the API is designed to be consumed by all plugins, extensions, etc...
|
And this implementation class changes quite often with bug fixes, so I would not put it in the API. |
|
I’ve almost completed most of the coding work and linked it to a plexus-xml PR. However, this PR seems to have a broader impact than expected. Could you please help evaluate it? |
I’ve placed most of the implementation in the Util class to avoid impacting the API layer. Could you please take another look? |
|
There are still some comment-related tasks remaining, and I will complete them later. |
| * An immutable xml node. | ||
| * | ||
| * @since 4.0.0 | ||
| * NOTE: remove all the util code in here when separated, this class should be pure data. |
There was a problem hiding this comment.
let's do this now, maybe even in a preceding PR
| @Immutable | ||
| public interface XmlNode { | ||
| public class XmlNode implements Serializable { | ||
| private static final long serialVersionUID = 2567894443061173996L; |
| String DEFAULT_SELF_COMBINATION_MODE = SELF_COMBINATION_MERGE; | ||
| public static final String DEFAULT_SELF_COMBINATION_MODE = SELF_COMBINATION_MERGE; | ||
|
|
||
| protected final String prefix; |
There was a problem hiding this comment.
This isn't necessary if using an interface + builder and non public class.
There was a problem hiding this comment.
Yes it is. They'd just be in a different class.
|
|
||
| @Nullable | ||
| String getAttribute(@Nonnull String name); | ||
| public Map<String, String> getAttributes() { |
There was a problem hiding this comment.
needs javadoc, particularly about immutability
| public String toStringObject() { | ||
| StringBuilder sb = new StringBuilder(); | ||
| sb.append("XmlNode["); | ||
| boolean w = false; |
| sb.append("XmlNode["); | ||
| boolean w = false; | ||
| w = addToStringField(sb, prefix, o -> !o.isEmpty(), "prefix", w); | ||
| w = addToStringField(sb, namespaceUri, o -> !o.isEmpty(), "namespaceUri", w); |
There was a problem hiding this comment.
why is this variable reassigned?
| return sb.toString(); | ||
| } | ||
|
|
||
| private static <T> boolean addToStringField(StringBuilder sb, T o, Function<T, Boolean> p, String n, boolean w) { |
There was a problem hiding this comment.
rename w variable and other variables; in general avoid single letter names
| </dependency> | ||
| <dependency> | ||
| <groupId>org.codehaus.plexus</groupId> | ||
| <artifactId>plexus-xml</artifactId> |
There was a problem hiding this comment.
We tried hard to get rid of that dependency, don't add it back.
| <artifactId>maven-api-annotations</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.fasterxml.woodstox</groupId> |
There was a problem hiding this comment.
No external dependencies in the API.
| @ThreadSafe | ||
| @Immutable | ||
| public interface XmlNode { | ||
| public class XmlNode implements Serializable { |
There was a problem hiding this comment.
Use an interface and a builder API, similar to requests / models in other parts of the API.
There was a problem hiding this comment.
This is exactly what I don't what to do. That just makes the API more complex than it needs to be.
| return children.size(); | ||
| } | ||
|
|
||
| XmlNode merge(@Nullable XmlNode source, @Nullable Boolean childMergeOverride); |
There was a problem hiding this comment.
This removes one important piece from the whole API. It suddenly becomes completely unavailable. A service needs to be defined. However, services are currently only available from the Session, but it cannot be used here.
A service locator could be used, but that's really overkill. No better idea at this point though (and don't put the merge code in the API, this really needs to be decoupled).
gnodet
left a comment
There was a problem hiding this comment.
A few points need to be addressed:
- no third party dependency in the API
- no dependency on plexus-xml, this would re-create a cyclic dependency
- use an interface + builder api, similar to other data classes in the API
- the merge code needs to be abstracted and decoupled using a service interface so that it can be used from plugins (they are only provided with the API jars)
For the merge service, maybe using a factory using ServiceLoader if we want to make that generally available. However, if we only target plugins, a service accessible from the Session could actually be used.
But we do have plugins that use Xpp3Dom.mergeXpp3Dom so that feature cannot be removed from the API
| @ThreadSafe | ||
| @Immutable | ||
| public interface XmlNode { | ||
| public class XmlNode implements Serializable { |
There was a problem hiding this comment.
This is exactly what I don't what to do. That just makes the API more complex than it needs to be.
| @ThreadSafe | ||
| @Immutable | ||
| public interface XmlNode { | ||
| public class XmlNode implements Serializable { |
| String DEFAULT_SELF_COMBINATION_MODE = SELF_COMBINATION_MERGE; | ||
| public static final String DEFAULT_SELF_COMBINATION_MODE = SELF_COMBINATION_MERGE; | ||
|
|
||
| protected final String prefix; |
There was a problem hiding this comment.
Yes it is. They'd just be in a different class.
|
|
||
| protected final Object location; | ||
|
|
||
| public XmlNode(String name) { |
| // Name handling | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| public String getPrefix() { |
There was a problem hiding this comment.
Javadoc on all public methods, and thi9s should be more than simply "Returns prefix". It should say what a prefix is.
| public Object getInputLocation() { | ||
| return location; | ||
| } | ||
| public class XmlNodeUtil { |
There was a problem hiding this comment.
I prefer the Guava convention of using plurals for utility classes; e.g. instead of XmlNodeUtil consider XmlNodes
|
Resolve #9946 |
No description provided.