1

I am attempting to convert an ant task which uses fmpp over to gradle. I am unable to get my project to build. I have the following in my build.xml file:

<project name="website">
    <property file="build.properties" />
    <property name="src.dir" location="src" />
    <property name="build.dir" location="build" />
    <taskdef name="fmpp" classname="fmpp.tools.AntTask">
        <classpath>
            <pathelement location="lib/fmpp.jar"/>
        </classpath>
    </taskdef>
    <target name="clean">
        <delete dir="${build.dir}" />
    </target>
    <target name="dist">
        <fmpp sourceRoot="${src.dir}" outputRoot="${build.dir}">
            <data expandProperties="yes">
                base_url: ${base_url}
                google_analytics_number: ${google_analytics_number}
                mail_user: ${mail_user}
                mail_password: ${mail_password}
                mail_recipient: ${mail_recipient}
                upload_folder: ${upload_folder}
                host: ${host}
                port: ${port}
            </data>
        </fmpp>
    </target>
</project>

my build.gradle file looks like this

ant.taskdef(name: 'fmpp', classname:'fmpp.tools.AntTask') {
    classpath {
        fileset(dir: 'lib', includes: '*.jar')
    }
}

ant.fmpp(sourceRoot:"src", outputRoot :"build") {
    data(expandProperties: 'yes'){
        base_url = base_url
        google_analytics_number = google_analytics_number
        mail_user = mail_user
        mail_password = mail_password
        mail_recipient = mail_recipient
        upload_folder = upload_folder
        host = host
        port = port
    }
}

but when I run it I get the following error

FMPP processing session failed. Caused by: freemarker.core.InvalidReferenceException: Expression base_url is undefined on line 15, column 47 in data/header.htm.

So it seems like the template variable in the htm file isn't being properly picked up and implemented in my my build. I am not sure how to get around this. There are a few gradle plugins for fmpp but have very limited documentation and I am having difficulty getting any of them to work. If any one has suggestions or a work around it would be greatly appreciated.

*** Update

Here is an example of the htm file that's trying to be applied

  <head>
    <?php
        error_reporting(E_ALL);
        ini_set('display_errors', 1);
        $page = basename($_SERVER['PHP_SELF']);
        require_once($_SERVER['DOCUMENT_ROOT'] . '/js/functions.php');
    ?>
    <title>
        <#if title??> ${title}
            <#else> CompSci Resources, LLC | The Complete EDGAR and XBRL Filing Platform, and more!
        </#if>
    </title>

    <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
    <script type='text/javascript' src='${base_url}/js/bootstrap-filestyle.min.js'> </script>
    <script type='text/javascript' src='${base_url}/js/bootstrap.min.js'></script>  
    <script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jcarousel/0.3.4/jquery.jcarousel.js'></script>
    <script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jcarousel/0.3.4/jquery.jcarousel-autoscroll.min.js'></script>
    <script type='text/javascript' src='${base_url}/js/compsci.js'></script>
    <script type='text/javascript' src='${base_url}/js/carousel.js'></script>
    <script type='text/javascript' src='${base_url}/js/readmore.js'></script>

    <link rel='shortcut icon' href='${base_url}/images/littlelogo.png' >
    <link rel='stylesheet' type='text/css' href='${base_url}/css/jcarousel.css' >
    <link rel='stylesheet' type='text/css' href='${base_url}/css/bootstrap.css'>
    <link rel='stylesheet' type='text/css' media='screen, projection' href='${base_url}/css/compsci.css'>

    <style type='text/css'>
        @media screen and (-webkit-min-device-pixel-ratio:0) { 
            h2 { font-weight: normal; }
            .csr-services-popper-left { margin-top:11px; }
        }
    </style>

    <!-- Google Analytics   -->

    <script type='text/javascript'>
        //Google Analytics
                    var _gaq = _gaq || [];
        _gaq.push(['_setAccount', '${google_analytics_number}']);
        _gaq.push(['_trackPageview']);

        (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();
    </script>

    <meta charset="UTF-8">
    <meta name="language" content="en">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
Opal
  • 81,889
  • 28
  • 189
  • 210
Ed Dunn
  • 1,152
  • 3
  • 11
  • 27
  • Try colon `:` instead of equals sign `=` in closure passed to `data`, so, e.g.: `base_url: base_url`. – Opal Oct 11 '18 at 14:58
  • I tried that but it gives me the following error Statement labels may not be used in build scripts. In case you tried to configure a property named 'base_url', replace ':' with '=' or ' ', otherwise it will not have the desired effect. @ line 24, column 19. base_url: base_url – Ed Dunn Oct 11 '18 at 15:01
  • I need to have a quick look into my old project which used ant in a similar way. Will keep you poster.. – Opal Oct 11 '18 at 15:24
  • `base_url` is a property set in Ant, right? If so, you'll need to pull it from the Ant project, as Gradle doesn't have direct access to it. Try `base_url = ant.base_url`. – CAustin Oct 11 '18 at 16:39
  • doing that gives me the following error --- A problem occurred evaluating root project 'csWebsite'. > No such property: base_url for class: org.gradle.api.internal.project.DefaultAntBuilder – Ed Dunn Oct 11 '18 at 16:44
  • I have a properties.gradle file where I pull my variables (much like the build.properties in ant). I load it with -- apply from: 'properties.gradle' – Ed Dunn Oct 11 '18 at 16:49
  • The `apply from:` function loads build scripts, not properties files. Why not just put this property in the default file "gradle.properties"? That way it will be read automatically. – CAustin Oct 11 '18 at 16:59
  • gives me the same error when put in gradle.properties – Ed Dunn Oct 11 '18 at 17:02
  • Did you remove the part where it applies the original properties file? I'm trying it myself right now and it seems to work fine. – CAustin Oct 11 '18 at 17:37
  • yep, I removed that part – Ed Dunn Oct 11 '18 at 17:38
  • What do you see in the console if you comment out the whole ant.fmpp task and add `println base_url`? – CAustin Oct 11 '18 at 17:39
  • I see my variable data as expected – Ed Dunn Oct 11 '18 at 17:41
  • Very strange. Only thing I can help you with at this point is sharing the pared down version of the script that I'm running. https://gist.github.com/CAustin582/da589cf2347958b90bc9b914a4a31467 – CAustin Oct 11 '18 at 17:44
  • looks like what I have. I posted the html that's bombing out if it helps – Ed Dunn Oct 11 '18 at 17:50
  • @EdDunn, please have a look at my answer and let me know if it has helped you. – Opal Oct 11 '18 at 18:17

1 Answers1

1

The problem lies in the fact that both properties read from gradle.properties and data properties are named exactly the same. To fix it you need to refer to value hidden under property with project instance, e.g.:

base_url = project.base_url

Have a look at the demo I've just prepared. It runs without any errors. If you rename properties in gradle.properties you may skip project, this is the case for port2 property - renamed on purpose.

Opal
  • 81,889
  • 28
  • 189
  • 210
  • I get the following error when running the above --- [ant:fmpp] Error [ant:fmpp] Task aborted: FMPP processing session failed. Caused by: freemarker.core.InvalidReferenceException: Expression base_url is undefined on line 15, column 47 in data/header.htm. – Ed Dunn Oct 11 '18 at 18:23
  • I posted the htm file in my main question – Ed Dunn Oct 11 '18 at 18:23
  • @EdDunn, see the updated repo. [This](http://fmpp.sourceforge.net/api/fmpp/tools/AntTask.html#setData-java.lang.String-) method from API inspired me to try this way. – Opal Oct 11 '18 at 19:03
  • It just represents template DATA in TDD (textual data definition) format. Could you please accept my answer? – Opal Oct 11 '18 at 19:24
  • No problem. Thank again – Ed Dunn Oct 11 '18 at 19:25