You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by gi...@apache.org on 2018/08/04 12:41:48 UTC

[1/2] ant-ivy git commit: Fix IVY-1104 by including extra attribute in XML report

Repository: ant-ivy
Updated Branches:
  refs/heads/master c21193ae1 -> 895834440


Fix IVY-1104 by including extra attribute in XML report


Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/9a9b720d
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/9a9b720d
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/9a9b720d

Branch: refs/heads/master
Commit: 9a9b720db7c282cf1d162ec5f7396f74e0090f62
Parents: c21193a
Author: aprelev <ar...@gmail.com>
Authored: Sat Aug 4 00:06:35 2018 +0300
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Sat Aug 4 14:34:49 2018 +0200

----------------------------------------------------------------------
 .../ivy/plugins/report/XmlReportParser.java     | 13 +---
 .../ivy/plugins/report/XmlReportWriter.java     | 20 ++++--
 .../util/extendable/ExtendableItemHelper.java   | 74 +++++++++++++++++++-
 .../java/org/apache/ivy/ant/IvyResolveTest.java | 18 +++++
 test/java/org/apache/ivy/ant/ivy-1104.xml       | 25 +++++++
 .../ivy/plugins/report/XmlReportWriterTest.java |  4 +-
 6 files changed, 133 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/9a9b720d/src/java/org/apache/ivy/plugins/report/XmlReportParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/report/XmlReportParser.java b/src/java/org/apache/ivy/plugins/report/XmlReportParser.java
index b6f87f7..3f248c2 100644
--- a/src/java/org/apache/ivy/plugins/report/XmlReportParser.java
+++ b/src/java/org/apache/ivy/plugins/report/XmlReportParser.java
@@ -192,17 +192,8 @@ public class XmlReportParser {
                         String name = attributes.getValue("module");
                         String branch = attributes.getValue("branch");
                         String revision = attributes.getValue("revision");
-                        Map<String, String> extraAttributes = new HashMap<>();
-                        for (int i = 0; i < attributes.getLength(); i++) {
-                            String attName = attributes.getQName(i);
-                            if (attName.startsWith("extra-")) {
-                                String extraAttrName = attName.substring("extra-".length());
-                                String extraAttrValue = attributes.getValue(i);
-                                extraAttributes.put(extraAttrName, extraAttrValue);
-                            }
-                        }
-                        mRevisionId = ModuleRevisionId.newInstance(organisation, name, branch,
-                                revision, extraAttributes);
+                        mRevisionId = ModuleRevisionId.newInstance(organisation, name, branch, revision,
+                            ExtendableItemHelper.getExtraAttributes(attributes, "extra-"));
                         break;
                 }
             }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/9a9b720d/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java b/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
index fdee32d..c5c0a8c 100644
--- a/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
+++ b/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
@@ -42,6 +42,7 @@ import org.apache.ivy.core.resolve.IvyNodeCallers.Caller;
 import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData;
 import org.apache.ivy.util.DateUtil;
 import org.apache.ivy.util.XMLHelper;
+import org.apache.ivy.util.extendable.ExtendableItemHelper;
 
 import static org.apache.ivy.util.StringUtils.joinArray;
 
@@ -77,7 +78,7 @@ public class XmlReportWriter {
         if (mrid.getBranch() != null) {
             out.println("\t\tbranch=\"" + XMLHelper.escape(mrid.getBranch()) + "\"");
         }
-        out.println(extraToString(mrid.getExtraAttributes(), "\t\t"));
+        out.println(extraToString(mrid.getQualifiedExtraAttributes(), "\t\t"));
         out.println("\t\tconf=\"" + XMLHelper.escape(report.getConfiguration()) + "\"");
         out.println("\t\tconfs=\"" + XMLHelper.escape(joinArray(confs, ", ")) + "\"");
         out.println("\t\tdate=\"" + DateUtil.format(report.getDate()) + "\"/>");
@@ -139,8 +140,9 @@ public class XmlReportWriter {
         if (md != null && md.getHomePage() != null) {
             details.append(" homepage=\"").append(XMLHelper.escape(md.getHomePage())).append("\"");
         }
-        extraAttributes = (md != null) ? md.getExtraAttributes() : dep.getResolvedId()
-                .getExtraAttributes();
+        extraAttributes = (md != null)
+            ? md.getQualifiedExtraAttributes()
+            : dep.getResolvedId().getQualifiedExtraAttributes();
         details.append(extraToString(extraAttributes, SEPARATOR));
         out.println(String.format("\t\t\t<revision name=\"%s\"%s%s downloaded=\"%s\" searched=\"%s\"%s conf=\"%s\" position=\"%d\">",
                 XMLHelper.escape(dep.getResolvedId().getRevision()),
@@ -172,8 +174,12 @@ public class XmlReportWriter {
             if (sb.length() > 0 && !SEPARATOR.equals(prefix)) {
                 sb.append(System.lineSeparator());
             }
-            sb.append(prefix).append("extra-").append(entry.getKey()).append("=\"")
-                    .append(XMLHelper.escape(entry.getValue())).append("\"");
+
+            sb.append(prefix);
+            sb.append(ExtendableItemHelper.encodeAttribute(entry.getKey(), "extra-"));
+            sb.append("=\"");
+            sb.append(XMLHelper.escape(entry.getValue()));
+            sb.append("\"");
         }
         return sb.toString();
     }
@@ -232,7 +238,7 @@ public class XmlReportWriter {
                     XMLHelper.escape(dependencyDescriptor.getDependencyRevisionId().getRevision()),
                     XMLHelper.escape(dependencyDescriptor.getDynamicConstraintDependencyRevisionId().getRevision()),
                     XMLHelper.escape(caller.getModuleRevisionId().getRevision()),
-                    extraToString(dependencyDescriptor.getExtraAttributes(), SEPARATOR)));
+                    extraToString(dependencyDescriptor.getQualifiedExtraAttributes(), SEPARATOR)));
         }
     }
 
@@ -242,7 +248,7 @@ public class XmlReportWriter {
             out.print("\t\t\t\t\t<artifact name=\"" + XMLHelper.escape(adr.getName())
                     + "\" type=\"" + XMLHelper.escape(adr.getType()) + "\" ext=\""
                     + XMLHelper.escape(adr.getExt()) + "\"");
-            out.print(extraToString(adr.getArtifact().getExtraAttributes(), SEPARATOR));
+            out.print(extraToString(adr.getArtifact().getQualifiedExtraAttributes(), SEPARATOR));
             out.print(" status=\"" + XMLHelper.escape(adr.getDownloadStatus().toString()) + "\"");
             out.print(" details=\"" + XMLHelper.escape(adr.getDownloadDetails()) + "\"");
             out.print(" size=\"" + adr.getSize() + "\"");

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/9a9b720d/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java b/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java
index 8dee1ec..d5de2e3 100644
--- a/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java
+++ b/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java
@@ -29,11 +29,83 @@ public final class ExtendableItemHelper {
     private ExtendableItemHelper() {
     }
 
+    private static final char separator = '.';
+
+    /**
+     * Decode qualified attribute name from blob.
+     *
+     * @param blob Encoded attribute name
+     * @param prefix Prefix used during encoding
+     * @return String
+     * @see #encodeAttribute(String, String)
+     */
+    public static String decodeAttribute(String blob, String prefix) {
+        // Decoding <qualifier>:<attribute> from 
+        //   <pre><qlen><sep><qualifier><sep><attribute>
+        // where qualifier (with following separator) is optional.
+        StringBuilder builder = new StringBuilder(blob);
+
+        // Skipping prefix
+        int cur = prefix.length();
+
+        // Resolving length of qualifier
+        int sepi = blob.indexOf(separator, cur);
+        int qlen = Integer.parseInt(blob.substring(cur, sepi));
+
+        // Skipping to attribute and reclaiming ':'
+        cur = sepi + 1;
+        if (qlen > 0)
+            builder.setCharAt(cur + qlen, ':');
+
+        return builder.substring(cur);
+    }
+
+    /**
+     * Encode qualified attribute name into blob
+     * to be used in XML report.
+     *
+     * @param attribute Qualified (or unqualified) attribute name
+     * @param prefix Prefix
+     * @return String
+     * @see #decodeAttribute(String, String)
+     */
+    public static String encodeAttribute(String attribute, String prefix) {
+        StringBuilder builder = new StringBuilder(
+            attribute.length() + prefix.length() + 5
+        );
+
+        // Resolving length of qualifier
+        int coloni = attribute.indexOf(':');
+        int qlen = coloni == -1
+            ? 0
+            : coloni;
+
+        // Encoding <qualifier>:<attribute> as
+        //   <pre><qlen><sep><qualifier><sep><attribute>
+        // where qualifier (with following separator) is optional;
+        // e.g. `extra-3.foo.bar` for `foo:bar`, or `extra-0.foo` for `foo`
+        builder.append(prefix);
+        builder.append(qlen);
+        builder.append(separator);
+        builder.append(attribute);
+
+        // Replacing ':' with '.' in order for report XML to not
+        // deal with all those pesky namespaces (c)
+        if (qlen > 0) {
+            int cur = builder.length() - attribute.length();
+            builder.setCharAt(cur + qlen, separator);
+        }
+
+        return builder.toString();
+    }
+
     public static Map<String, String> getExtraAttributes(Attributes attributes, String prefix) {
         Map<String, String> ret = new HashMap<>();
         for (int i = 0; i < attributes.getLength(); i++) {
             if (attributes.getQName(i).startsWith(prefix)) {
-                ret.put(attributes.getQName(i).substring(prefix.length()), attributes.getValue(i));
+                String name = decodeAttribute(attributes.getQName(i), prefix);
+                String value = attributes.getValue(i);
+                ret.put(name, value);
             }
         }
         return ret;

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/9a9b720d/test/java/org/apache/ivy/ant/IvyResolveTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/ant/IvyResolveTest.java b/test/java/org/apache/ivy/ant/IvyResolveTest.java
index 70dd022..3737d84 100644
--- a/test/java/org/apache/ivy/ant/IvyResolveTest.java
+++ b/test/java/org/apache/ivy/ant/IvyResolveTest.java
@@ -249,6 +249,24 @@ public class IvyResolveTest {
         assertEquals("false", getIvy().getVariable("ivy.deps.changed"));
     }
 
+
+    /**
+     * Test for issue IVY-1104,
+     * which has to do with ${ivy.deps.changed} being always set
+     * dependencies with extra attributes.
+     */
+
+    @Test
+    public void testDepsWithAttributesChanged() {
+        resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-1104.xml"));
+
+        resolve.execute();
+        assertEquals("true", getIvy().getVariable("ivy.deps.changed"));
+
+        resolve.execute();
+        assertEquals("false", getIvy().getVariable("ivy.deps.changed"));
+    }
+
     @Test
     public void testDontCheckIfChanged() {
         resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/9a9b720d/test/java/org/apache/ivy/ant/ivy-1104.xml
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/ant/ivy-1104.xml b/test/java/org/apache/ivy/ant/ivy-1104.xml
new file mode 100644
index 0000000..c2caa0e
--- /dev/null
+++ b/test/java/org/apache/ivy/ant/ivy-1104.xml
@@ -0,0 +1,25 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+     http://www.apache.org/licenses/LICENSE-2.0
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.
+-->
+<ivy-module version="1.0" xmlns:e="http://ant.apache.org/ivy/extra">
+  <info organisation="apache"
+         module="ivy-1104"
+         revision="1.0"
+         status="release"/>
+  <dependencies>
+    <dependency org="org1" name="mod1.2" rev="2.0" e:foo="bar"/>
+  </dependencies>
+</ivy-module>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/9a9b720d/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java b/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java
index 4b36e85..d5c833d 100644
--- a/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java
+++ b/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java
@@ -125,8 +125,8 @@ public class XmlReportWriterTest {
         String orgAttribute = "organisation=\"org1\"";
         String modAttribute = "module=\"mod1\"";
         String revAttribute = "revision=\"1.0\"";
-        String extra1Attribute = "extra-blabla=\"abc\"";
-        String extra2Attribute = "extra-blabla2=\"123\"";
+        String extra1Attribute = "extra-0.blabla=\"abc\"";
+        String extra2Attribute = "extra-0.blabla2=\"123\"";
 
         assertTrue("XML doesn't contain organisation attribute", xml.contains(orgAttribute));
         assertTrue("XML doesn't contain module attribute", xml.contains(modAttribute));


[2/2] ant-ivy git commit: Update the release notes

Posted by gi...@apache.org.
Update the release notes

Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/89583444
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/89583444
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/89583444

Branch: refs/heads/master
Commit: 89583444040dc5423bb143435f23ae0814f24542
Parents: 9a9b720
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Sat Aug 4 14:41:34 2018 +0200
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Sat Aug 4 14:41:34 2018 +0200

----------------------------------------------------------------------
 asciidoc/release-notes.adoc | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/89583444/asciidoc/release-notes.adoc
----------------------------------------------------------------------
diff --git a/asciidoc/release-notes.adoc b/asciidoc/release-notes.adoc
index 17926ab..8a6f1f9 100644
--- a/asciidoc/release-notes.adoc
+++ b/asciidoc/release-notes.adoc
@@ -80,6 +80,7 @@ For details about the following changes, check our JIRA install at link:https://
 - FIX: Fix Maven dependency resolution for dependencies with multiple different classifiers (jira:IVY-1576[])
 - FIX: Correct parent classloader when lauching resolved artifacts from CLI (jira:IVY-1483[]) (Thanks to Stephan Feder)
 - FIX: Make Main.run() public (usable with REPL) (jira:IVY-1321[] jira:IVY-1578[]) (Thanks to Greg Perry)
+- FIX: Make ivy.deps.changed work with extra attributes (jira:IVY-1104[]) (Thanks to Arseny Aprelev)
 
 - IMPROVEMENT: Throw an IllegalStateException when retrieving the resolutionCacheRoot on the DefaultResolutionCacheManager if the basedir (or IvySettings) is not set (jira:IVY-1482[])
 - IMPROVEMENT: Optimization: limit the revision numbers scanned if revision prefix is specified (Thanks to Ernestas Vaiciukevi&ccaron;ius)
@@ -125,6 +126,7 @@ Here is the list of people who have contributed source code and documentation up
 
 * Ingo Adler
 * Mathieu Anquetin
+* Arseny Aprelev
 * Andreas Axelsson
 * St&eacute;phane Bailliez
 * Karl Baum