128778: Permit AntLogger impls to inspect the value of references, not just properties. Since loggers cannot "see" Ant classes directly, these are just returned as strings. diff --git a/o.apache.tools.ant.module/apichanges.xml b/o.apache.tools.ant.module/apichanges.xml --- a/o.apache.tools.ant.module/apichanges.xml +++ b/o.apache.tools.ant.module/apichanges.xml @@ -106,6 +106,35 @@ is the proper place. + + + + Ant loggers can now inspect Ant reference objects + + + + +

+ Properties of the same name take precedence over references, + so only code which relied on a property name not + being set would see different behavior. +

+
+ +

+ The AntEvent methods getProperty and + getPropertyNames can now work with Ant references + as well as plain properties. This is critical for loggers which + wish to inspect e.g. the runtime value of a classpath given as: +

+
<classpath refid="my.cp"/>
+

+ which otherwise would be inaccessible. +

+
+ + +
diff --git a/o.apache.tools.ant.module/nbproject/project.properties b/o.apache.tools.ant.module/nbproject/project.properties --- a/o.apache.tools.ant.module/nbproject/project.properties +++ b/o.apache.tools.ant.module/nbproject/project.properties @@ -39,7 +39,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.5 -spec.version.base=3.28.0 +spec.version.base=3.29.0 compile.ant.jar=${ant.core.lib} src-bridge.cp.extra=build/classes:${compile.ant.jar} extra.module.files=\ diff --git a/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java b/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java --- a/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java +++ b/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java @@ -52,6 +52,7 @@ import java.util.Comparator; import java.util.Comparator; import java.util.Enumeration; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; @@ -1163,7 +1164,12 @@ final class NbBuildLogger implements Bui if (o instanceof String) { return (String) o; } else { - return null; + o = project.getReference(name); + if (o != null) { + return o.toString(); + } else { + return null; + } } } else { return null; @@ -1174,7 +1180,10 @@ final class NbBuildLogger implements Bui verifyRunning(); Project project = getProjectIfPropertiesDefined(); if (project != null) { - return NbCollections.checkedSetByFilter(project.getProperties().keySet(), String.class, true); + Set s = new HashSet(); + s.addAll(NbCollections.checkedSetByFilter(project.getProperties().keySet(), String.class, true)); + s.addAll(NbCollections.checkedSetByFilter(project.getReferences().keySet(), String.class, true)); + return s; } else { return Collections.emptySet(); } diff --git a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/spi/AntEvent.java b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/spi/AntEvent.java --- a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/spi/AntEvent.java +++ b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/spi/AntEvent.java @@ -206,6 +206,7 @@ public final class AntEvent { /** * Get a property set on the current Ant project. + * Also can retrieve references using their string values since org.apache.tools.ant.module/3 3.29. * @param name the property name * @return its value, or null */ @@ -215,6 +216,7 @@ public final class AntEvent { /** * Get a set of property names defined on the current Ant project. + * Also includes reference names since org.apache.tools.ant.module/3 3.29. * @return a set of property names; may be empty but not null */ public Set getPropertyNames() { diff --git a/o.apache.tools.ant.module/test/unit/data/antlogger/reference.xml b/o.apache.tools.ant.module/test/unit/data/antlogger/reference.xml new file mode 100644 --- /dev/null +++ b/o.apache.tools.ant.module/test/unit/data/antlogger/reference.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/o.apache.tools.ant.module/test/unit/src/org/apache/tools/ant/module/spi/AntLoggerTest.java b/o.apache.tools.ant.module/test/unit/src/org/apache/tools/ant/module/spi/AntLoggerTest.java --- a/o.apache.tools.ant.module/test/unit/src/org/apache/tools/ant/module/spi/AntLoggerTest.java +++ b/o.apache.tools.ant.module/test/unit/src/org/apache/tools/ant/module/spi/AntLoggerTest.java @@ -192,6 +192,15 @@ public class AntLoggerTest extends NbTes run(testdirFO.getFileObject("trivial.xml"), null, AntEvent.LOG_VERBOSE); // see TestLogger.taskStarted for details } + + public void testReferences() throws Exception { + LOGGER.interestedInSessionFlag = true; + LOGGER.interestedInAllScriptsFlag = true; + LOGGER.interestingTargets = AntLogger.ALL_TARGETS; + FileObject rxml = testdirFO.getFileObject("reference.xml"); + run(rxml); + assertEquals(FileUtil.toFile(rxml).getAbsolutePath(), LOGGER.referenceValue); + } /** * Sample logger which collects results. @@ -211,6 +220,7 @@ public class AntLoggerTest extends NbTes /** Format of each: "taskname:level:message" */ private List messages; private boolean antEventDetailsOK; + private String referenceValue; public TestLogger() {} @@ -226,6 +236,7 @@ public class AntLoggerTest extends NbTes targetsStarted = new ArrayList(); messages = new ArrayList(); antEventDetailsOK = false; + referenceValue = null; halt = false; } @@ -276,6 +287,11 @@ public class AntLoggerTest extends NbTes } @Override + public void targetFinished(AntEvent event) { + referenceValue = event.getProperty("p"); + } + + @Override public synchronized void messageLogged(AntEvent event) { String toadd = "" + event.getLogLevel() + ":" + event.getMessage(); String taskname = event.getTaskName(); @@ -304,7 +320,7 @@ public class AntLoggerTest extends NbTes if (halt && event.getTaskName().equals("touch")) { try { Thread t = new Thread() { - public void run() { + public @Override void run() { synchronized (TestLogger.this) { assertEquals("${foobie}", event.evaluate("${foobie}")); TestLogger.this.notify();