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

[BUG] Custom POM configuration for ZIP publication produces duplicit tags (url, scm) #3656

Merged
merged 3 commits into from
Jun 23, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.github.jengelman.gradle.plugins.shadow.ShadowExtension;
import groovy.util.Node;
import groovy.util.NodeList;
import groovy.xml.QName;

import org.opensearch.gradle.info.BuildParams;
import org.opensearch.gradle.precommit.PomValidationPrecommitPlugin;
Expand All @@ -57,6 +56,9 @@
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.language.base.plugins.LifecycleBasePlugin;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.concurrent.Callable;

import static org.opensearch.gradle.util.GradleUtils.maybeConfigure;
Expand Down Expand Up @@ -153,16 +155,29 @@ private static void addScmInfo(XmlProvider xml) {
for (final Object child : root.children()) {
saratvemulapalli marked this conversation as resolved.
Show resolved Hide resolved
if (child instanceof Node) {
final Node node = (Node) child;
if (node.name() instanceof QName) {
final QName qname = (QName) node.name();
if (qname.matches("url")) {
url = node;
} else if (qname.matches("scm")) {
scm = node;
final Object name = node.name();

try {
// For Gradle 6.8 and below, the class is groovy.xml.QName
// For Gradle 7.4 and above, the class is groovy.namespace.QName
if (name != null && name.getClass().getSimpleName().equals("QName")) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we still have to support Gradle 6.x ? Do you still see value?
I believe all our components moved to Gradle 7+.

Copy link
Collaborator Author

@reta reta Jun 23, 2022

Choose a reason for hiding this comment

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

Yes, that's basically on plugin authors ... We support it since we don't have control over external community plugins

final MethodHandle handle = MethodHandles.publicLookup()
.findVirtual(name.getClass(), "matches", MethodType.methodType(boolean.class, Object.class))
.bindTo(name);

if ((boolean) handle.invoke("url")) {
url = node;
} else if ((boolean) handle.invoke("scm")) {
scm = node;
}
}
} else if ("url".equals(node.name())) {
} catch (final Throwable ex) {
// Not a suitable QName type we could use ...
}

if ("url".equals(name)) {
url = node;
} else if ("scm".equals(node.name())) {
} else if ("scm".equals(name)) {
scm = node;
}
}
Expand Down