You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/03/12 18:22:11 UTC
[commons-release-plugin] branch master updated: Hack a workaround for https://issues.apache.org/jira/browse/MNG-7316
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-release-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 36b02c2 Hack a workaround for https://issues.apache.org/jira/browse/MNG-7316
36b02c2 is described below
commit 36b02c2cba36637669c6faf680932a23a540fc0a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Mar 12 13:22:09 2022 -0500
Hack a workaround for https://issues.apache.org/jira/browse/MNG-7316
---
.../mojos/CommonsDistributionDetachmentMojo.java | 35 +++++++++++-----------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
index c24e82c..0197f70 100755
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
@@ -32,6 +32,7 @@ import java.util.Set;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.properties.SortedProperties;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.reflect.MethodUtils;
import org.apache.commons.release.plugin.SharedFunctions;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
@@ -134,24 +135,24 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
//
// PROBLEM CODE for Maven >= 3.8.3
// https://issues.apache.org/jira/browse/MNG-7316
- for (final Artifact artifactToRemove : detachedArtifacts) {
- // Maven 3.8.3 throws an exception here because MavenProject.getAttachedArtifacts()
- // returns an IMMUTABLE collection.
- project.getAttachedArtifacts().remove(artifactToRemove);
+ try {
+ // (1) Try the normal way
+ for (final Artifact artifactToRemove : detachedArtifacts) {
+ // Maven 3.8.3 throws an exception here because MavenProject.getAttachedArtifacts()
+ // returns an IMMUTABLE collection.
+ project.getAttachedArtifacts().remove(artifactToRemove);
+ }
+ } catch (UnsupportedOperationException e) {
+ // (2) HACK workaround for https://issues.apache.org/jira/browse/MNG-7316
+ final ArrayList<Artifact> arrayList = new ArrayList<>(project.getAttachedArtifacts());
+ arrayList.removeAll(detachedArtifacts);
+ try {
+ // MavenProject#setAttachedArtifacts(List) is protected
+ MethodUtils.invokeMethod(project, true, "setAttachedArtifacts", arrayList);
+ } catch (ReflectiveOperationException roe) {
+ throw new MojoExecutionException(roe);
+ }
}
- //
- // HACK START to replace the above.
- // https://issues.apache.org/jira/browse/MNG-7316
-// final ArrayList<Artifact> arrayList = new ArrayList<>(project.getAttachedArtifacts());
-// arrayList.removeAll(detachedArtifacts);
-// try {
-// // MavenProject#setAttachedArtifacts(List) is protected
-// MethodUtils.invokeMethod(project, true, "setAttachedArtifacts", arrayList);
-// } catch (ReflectiveOperationException e) {
-// throw new MojoExecutionException(e);
-// }
- // HACK END
- //
if (!workingDirectory.exists()) {
SharedFunctions.initDirectory(getLog(), workingDirectory);
}