Riverside-Software / pct

Build automation for OpenEdge ABL
Apache License 2.0
96 stars 62 forks source link

Using PCT with Groovy on Windows #416

Closed hutcj closed 4 years ago

hutcj commented 4 years ago

Using PCT with Groovy on Windows

With proant, I don't have to manually specify the path to the PCT.jar in order for the PCT definitions to be loaded. However, when using Groovy, I do have to path it out manually. Is there an environment variable that I'm missing? I compared this setup to my setup on a UNIX machine and didn't find anything different, yet on that machine I can use Groovy without manual pathing.

Your environment

Actual behaviour

Using proant

build.xml:

<?xml version="1.0"?>
<project name="test" default="build" basedir=".">
  <!-- -pct-def: PCT definitions -->
  <target name="-pct-def">
    <!-- PCT Libraries -->
    <taskdef resource="PCT.properties" />
    <typedef resource="types.properties" />
    <!-- Next line only for tasks using OpenEdge parser, see ClassDocumentation task -->
    <!--<typedef resource="extras.properties" />-->
    <PCTVersion />
  </target>

  <target name="build" depends="-pct-def">
    <property environment="env"/>
    <PCTVersion/>
    <ProgressVersion dlcHome="${env.DLC}" fullVersion="dlc.version.full" />
    <echo message="${dlc.version.full}" />
  </target>
</project>

Result:

C:\Users\hutcj\repos\migrator>%DLC%/bin/proant
Buildfile: C:\Users\hutcj\repos\migrator\build.xml

-pct-def:
[PCTVersion] PCT Version : pct-213-master-371bf8991b070175bdc34298b8c6ccb5b3e5a4a1

build:
[PCTVersion] PCT Version : pct-213-master-371bf8991b070175bdc34298b8c6ccb5b3e5a4a1
     [echo] OpenEdge Release 11.7.5 as of Fri Jun  7 09:06:03 EDT 2019

BUILD SUCCESSFUL
Total time: 0 seconds

Using Groovy with manual pathing:

test.groovy:

def AntBuilder ant
def String DLC

def env = System.getenv()

ant = new AntBuilder()
ant.taskdef(resource: 'PCT.properties', classpath: "$env.DLC/ant/lib/PCT.jar")
//ant.typedef(resource: 'types.properties')

ant.PCTVersion()

Result:

C:\Users\hutcj\repos\migrator>groovy test.groovy
[PCTVersion] PCT Version : pct-213-master-371bf8991b070175bdc34298b8c6ccb5b3e5a4a1

Using Groovy without manual pathing:

test.groovy:

def AntBuilder ant
def String DLC

def env = System.getenv()

ant = new AntBuilder()
ant.taskdef(resource: 'PCT.properties')
//ant.typedef(resource: 'types.properties')

ant.PCTVersion()

Result:

C:\Users\hutcj\repos\migrator>groovy test.groovy
  [taskdef] Could not load definitions from resource PCT.properties. It could not be found.
Caught: : Problem: failed to create task or type PCTVersion
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

: Problem: failed to create task or type PCTVersion
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

        at org.apache.tools.ant.UnknownElement.getNotFoundException(UnknownElement.java:499)
        at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:431)
        at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:164)
        at test.run(test.groovy:18)

Expected behaviour

Groovy should not have to manually path to the PCT jar.

Steps to reproduce

Run test.groovy on Windows to execute PCT tasks without specifying the exact location of PCT.jar.

gquerret commented 4 years ago

I don't have the answer for your specific question, that's more on the Groovy side. But I fell into a similar problem, which lead me to create this JAR file: https://github.com/Riverside-Software/groovy-pct Basically Groovy + Ant + PCT in a single JAR file

hutcj commented 4 years ago

Thanks for sharing that. Wouldn't you still need to have a standard Groovy installation available to have access to groovy, groovyc, etc.? Or is this meant more for runtime of precompiled Groovy scripts? But then wouldn't you still need the groovy command to run a compiled Groovy class? How exactly do you use this? Would I throw it into $DLC/ant/lib or $DLC/java somewhere?

gquerret commented 4 years ago

The way I'm using is for deployment (or db upgrade) where there's some logic to be applied. I usually deploy a set of Groovy scripts (in the form of .groovy files), this JAR file, and I use the JRE coming with Progress (or the external one starting from 12.2).

gquerret commented 4 years ago

https://github.com/Riverside-Software/pct/wiki/Using-PCT-with-Groovy

gquerret commented 4 years ago

https://www.pugchallenge.eu/docs/default-source/presentations-2017/groove-is-in-the-ant---querret.pdf

hutcj commented 4 years ago

Works great!

$ $DLC/jre/bin/java -jar ~/Downloads/groovy-ant.jar test.groovy
[PCTVersion] PCT Version : pct-209-master-260e0a7951e4a94d04f43fc827196578e664bebb

Looks like more recent versions of Groovy like 2.5.12 don't have the embeddable folder or any "groovy-all...jar" file. Would I just have to add a task for each jar in the indy folder instead?

hutcj commented 4 years ago

E.g.

$ ls -al groovy/groovy-2.5.12/
total 48
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:04 ./
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:04 ../
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:04 bin/
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:04 conf/
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:04 grooid/
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:04 indy/
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:04 lib/
-rw-r--r-- 1 hutcj 1049089 14503 May 18 20:18 LICENSE
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:04 licenses/
-rw-r--r-- 1 hutcj 1049089  1308 May 18 20:18 NOTICE
$ ls -al groovy/groovy-2.5.12/indy
total 8588
drwxr-xr-x 1 hutcj 1049089       0 Jun 11 16:04 ./
drwxr-xr-x 1 hutcj 1049089       0 Jun 11 16:04 ../
-rw-r--r-- 1 hutcj 1049089 5626612 May 18 20:21 groovy-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089   69752 May 18 20:20 groovy-ant-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089    7563 May 18 20:19 groovy-bsf-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089   71221 May 18 20:20 groovy-cli-commons-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089   60339 May 18 20:19 groovy-cli-picocli-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089  747418 May 18 20:20 groovy-console-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089   14798 May 18 20:19 groovy-datetime-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089    7413 May 18 20:20 groovy-dateutil-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089  124320 May 18 20:20 groovy-docgenerator-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089  138133 May 18 20:20 groovy-groovydoc-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089  449668 May 18 20:20 groovy-groovysh-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089    3613 May 18 20:20 groovy-jaxb-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089  130249 May 18 20:20 groovy-jmx-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089  128620 May 18 20:20 groovy-json-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089    5149 May 18 20:20 groovy-json-direct-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089   17320 May 18 20:20 groovy-jsr223-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089  234661 May 18 20:20 groovy-macro-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089   15516 May 18 20:20 groovy-nio-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089   22481 May 18 20:20 groovy-servlet-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089   79809 May 18 20:20 groovy-sql-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089  369566 May 18 20:20 groovy-swing-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089   97057 May 18 20:20 groovy-templates-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089   80651 May 18 20:20 groovy-test-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089    9238 May 18 20:20 groovy-test-junit5-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089    5489 May 18 20:20 groovy-testng-2.5.12-indy.jar
-rw-r--r-- 1 hutcj 1049089  218416 May 18 20:20 groovy-xml-2.5.12-indy.jar

Versus the old version:

$ ls -al groovy/groovy-2.4.15/
total 44
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:05 ./
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:05 ../
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:05 bin/
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:05 conf/
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:05 embeddable/
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:05 grooid/
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:05 indy/
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:05 lib/
-rw-r--r-- 1 hutcj 1049089 14338 Mar 23  2018 LICENSE
drwxr-xr-x 1 hutcj 1049089     0 Jun 11 16:05 licenses/
-rw-r--r-- 1 hutcj 1049089  1175 Mar 23  2018 NOTICE
$ ls -al groovy/groovy-2.4.15/embeddable/
total 13808
drwxr-xr-x 1 hutcj 1049089       0 Jun 11 16:05 ./
drwxr-xr-x 1 hutcj 1049089       0 Jun 11 16:05 ../
-rw-r--r-- 1 hutcj 1049089 7164868 Mar 23  2018 groovy-all-2.4.15.jar
-rw-r--r-- 1 hutcj 1049089 6966215 Mar 23  2018 groovy-all-2.4.15-indy.jar
hutcj commented 4 years ago

I guess this was a decision by the Groovy developers. Don't fully understand the reason they no longer include it, but appears to have caused some issues in the past. https://issues.apache.org/jira/browse/GROOVY-8751

I'll have to do some more reading on how to build the jar file myself.

gquerret commented 4 years ago

Looks like more recent versions of Groovy like 2.5.12 don't have the embeddable folder or any "groovy-all...jar" file. Would I just have to add a task for each jar in the indy folder instead?

I'm still using Groovy 2.4 for this reason :-) I never took time to create the fatjar for newer versions of Groovy, but it's on my TODO list. Feel free to open a pull request if you do it before me !

hutcj commented 4 years ago

Gotcha, thanks!