You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Alexander (JIRA)" <ji...@apache.org> on 2018/09/11 12:51:00 UTC

[jira] [Commented] (MANTRUN-207) scriptdef ignores CDATA when there is also an element

    [ https://issues.apache.org/jira/browse/MANTRUN-207?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16610543#comment-16610543 ] 

Alexander commented on MANTRUN-207:
-----------------------------------

Hello [~stmsat],

I have implemented a workaround using the <script> task. The drawback is that one must put it to each target. It would be ugly, but it will work.

Here is my code snippet. It does a simple task that is to count the number of files matched by a fileset and fail the execution if it is not equal to the desired value.
{code:java}
<configuration>
    <target>

        <!-- The script for counting of files within fileset -->
        <!-- There is no way to use the scriptdef due to the Maven bug https://issues.apache.org/jira/browse/MANTRUN-207-->
        <property name="fSet.dir" value="${binary.path}"/> <!-- Directory -->
        <property name="fSet.includes" value="icu*.dat"/>  <!-- File Pattern -->
        <property name="fSet.expectedSize" value="1"/>     <!-- Validating condition (number of files) -->

        <script language="javascript">
            <![CDATA[
            importClass(java.io.File);
            // Access to Ant-Properties by their names
            fSetDir      = project.getProperty("fSet.dir");
            fSetIncludes = project.getProperty("fSet.includes");
            // Create a <fileset dir="" includes=""/>
            fSet = project.createDataType("fileset");
            fSet.setDir(new File(fSetDir));
            fSet.setIncludes(fSetIncludes);
            // Get the files (array) of that fileset
            ds = fSet.getDirectoryScanner(project);
            srcFiles = ds.getIncludedFiles();
            java.lang.System.out.println("     [custom script] " + srcFiles.length + " files from " +  fSetDir + " will be included to the JAR:");
            for (i = 0; i < srcFiles.length; i++) { // Print file names to console
                java.lang.System.out.println("     [custom script] " + srcFiles[i]);
            }
            // "return" the number of files as a new property with the name "fSet.Size"
            project.setNewProperty("fSet.Size", srcFiles.length);
            ]]>
        </script>

        <fail message="Exactly ${fSet.expectedSize} files were expected, but ${fSet.Size} found in the directory '${fSet.dir}':">
            <condition>
                <not>
                    <equals arg1="${fSet.Size}" arg2="${fSet.expectedSize}"/>
                </not>
            </condition>
        </fail>

    </target>
</configuration>{code}
I have upvoted the ticket and would be happy to replace this code with well-working <scriptdef> as well.

> scriptdef ignores CDATA when there is also an element
> -----------------------------------------------------
>
>                 Key: MANTRUN-207
>                 URL: https://issues.apache.org/jira/browse/MANTRUN-207
>             Project: Maven Antrun Plugin
>          Issue Type: Bug
>    Affects Versions: 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8
>         Environment: Windows 10 64bit, java 1.8.0_151, maven 3.5.0
>            Reporter: Matteo Steccolini
>            Priority: Major
>         Attachments: build-main.xml, pom.xml
>
>
> When I put a CDATA node inside a scriptdef which has also an element node, the cdata is ignored. You can see it in the attached build-main.xml that is generated from the attached pom.xml (mvn antrun:run@hello).
> When I though I might be doing something wrong I wrote this question on stackoverflow: [https://stackoverflow.com/questions/47796805/maven-antrun-plugin-scriptdef-ignores-cdata-when-i-add-an-element]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)