diff --git a/WHATSNEW b/WHATSNEW index 6db5548de..9a6d4782a 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -13,6 +13,8 @@ Fixed bugs: Other changes: -------------- + * Hidden resource is published now. It reads the + value of a specified java constant. Changes from Ant 1.9.4 TO Ant 1.9.5 diff --git a/manual/Types/resources.html b/manual/Types/resources.html index ebbeff1e6..58cefde1a 100644 --- a/manual/Types/resources.html +++ b/manual/Types/resources.html @@ -43,6 +43,8 @@ explicit use beginning in Ant 1.7.
  • gzipresource - a GZip compressed resource.
  • javaresource - a resource loadable via a Java classloader.
  • +
  • javaconstant - a constant in a class loadable + via a Java classloader.
  • propertyresource - an Ant property.
  • string - a text string.
  • tarentry - an entry in a tar file.
  • @@ -164,9 +166,49 @@ implementations are also usable as single-element where <classpath> is a path-like structure.

    + +

    javaconstant

    +

    Loads the value of a java constant. As a specialisation of +javaresource all of its attributes and nested elements are +supported. A constant must be specified as public static otherwise it could not be loaded.

    + + + + + + + + + + + + +
    AttributeDescriptionRequired
    nameThe name of the resource. Must be specified as full qualified + field name. + Yes
    +
    Examples
    +This loads the value of the constant VERSION of the org.acme.Main class +into the version-property. The classpath for finding that class is provided via +nested classpath element. +
    <loadresource property="version">
    +   <javaconstant name="org.acme.Main.VERSION">
    +     <classpath>
    +       <pathelement location="${acme.lib.dir}"/>
    +     </classpath>
    +   </javaconstant>
    + </loadresource>
    +
    + +Create a new file c:/temp/org.apache.tools.ant.Main.DEFAULT_BUILD_FILENAME with the content +of that constant (build.xml). +
    <copy todir="c:/temp">
    +  <javaconstant name="org.apache.tools.ant.Main.DEFAULT_BUILD_FILENAME"/>
    +</copy>
    + +

    zipentry

    -

    Represents an entry in a ZIP archive. The archive can be specified +

    Represents an entry in a ZIP archive. The archive can be specified using the archive attribute or a nested single-element resource collection. zipentry only supports file system resources as nested elements.

    diff --git a/src/main/org/apache/tools/ant/types/defaults.properties b/src/main/org/apache/tools/ant/types/defaults.properties index 1837ec7f7..29771dbb9 100644 --- a/src/main/org/apache/tools/ant/types/defaults.properties +++ b/src/main/org/apache/tools/ant/types/defaults.properties @@ -93,6 +93,7 @@ gzipresource=org.apache.tools.ant.types.resources.GZipResource bzip2resource=org.apache.tools.ant.types.resources.BZip2Resource javaresource=org.apache.tools.ant.types.resources.JavaResource multirootfileset=org.apache.tools.ant.types.resources.MultiRootFileSet +javaconstant=org.apache.tools.ant.types.resources.JavaConstantResource #tokenizer implementations linetokenizer=org.apache.tools.ant.util.LineTokenizer diff --git a/src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java b/src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java index fe6ed6945..a947c9a9c 100644 --- a/src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java +++ b/src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java @@ -39,6 +39,9 @@ public class JavaConstantResource extends AbstractClasspathResource { protected InputStream openInputStream(ClassLoader cl) throws IOException { Class clazz; String constant = getName(); + if (constant == null) { + throw new IOException("Attribute 'name' must be set."); + } int index1 = constant.lastIndexOf('.'); if (index1 < 0) { throw new IOException("No class name in " + constant); diff --git a/src/tests/antunit/types/resources/test.xml b/src/tests/antunit/types/resources/test.xml index fca9b56c3..5af37b9ad 100644 --- a/src/tests/antunit/types/resources/test.xml +++ b/src/tests/antunit/types/resources/test.xml @@ -400,4 +400,61 @@ + + + + + public class SomeClass { + public static final String CONSTANT = "constant"; + public final String NOT_STATIC = "not-static"; + private static final String PRIVATE = "private"; + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +