gradle-cobol-plugin

Gradle plugin for the cobol language. Compile - Run - Unittest - Testcoverage

View the Project on GitHub RosesTheN00b/gradle-cobol-plugin

gradle-cobol-plugin

Build Status

This project is part of my master thesis.

You can discover some examples here

Features

Gradle-cobol environment

Further Reading:

Compatibility

Fixed file format

Compiler Code format compile/run executable compile/run debug unit test (plugin) unit testcoverage (plugin) integration test (plugin) integration testcoverage (plugin)
GnuCobol / Open Cobol 1.1 fixed full support full support full support full support
GnuCobol 2 recommended fixed full support full support full support full support full support full support
GnuCobol 3rc fixed full support full support full support full support full support full support

Free file format

Compiler Code format compile/run executable compile/run debug unit test (plugin) unit testcoverage (plugin) integration test (plugin) integration testcoverage (plugin)
GnuCobol / Open Cobol 1.1 free full support full support not tested not tested
GnuCobol 2 free full support full support not tested not tested not tested not tested
GnuCobol 3rc free not tested not tested not tested not tested not tested not tested

3-Steps Quickstart

1. Install

To use the plugin, you need GNUCobol and Gradle.

On Ubuntu (18.10 and higher):

sudo apt install gradle gnucobol

On Arch (via yaourt):

yaourt gnu-cobol gradle

2. Configure your project

Initial project structure:

.
├── build.gradle  (empty)
└── settings.gradle  (empty)

Import the plugin from the provided repo (in your settings.gradle):

mvn: https://sebastianruziczka.de/repo/mvn
ivy: https://sebastianruziczka.de/repo/ivy

E.g. settings.gradle :

pluginManagement {
	repositories {
		maven {
			url 'https://sebastianruziczka.de/repo/mvn/'
		}
	}
}

or build your your own versioned jar with the command

gradle publish

use the parameter -PgenerateLatest for publishing a jar with the version latest:

gradle publish -PgenerateLatest

Add to your build.gradle the last version of the plugin (preferred):

plugins {
     id 'de.sebastianruziczka.Cobol' version 'latest'
}

Or hardcode a specific version:

plugins {
     id 'de.sebastianruziczka.Cobol' version '0.0.41'
}

3. Run HELLOWORLD.cbl

Insert HelloWorld in src/main/cobol and run it with the single command:

gradle helloWorld

Running

Run your application with

gradle runDebug

or build an complete executable and run it with:

gradle runExecutable

Additional configuration

A minimal configuration for more than one cobol source file:

cobol {
     srcMain = 'HelloWorld' // Path to your main file in src/main/cobol without the file extension .cbl
}

Testing (Unit + Integration)

Add this lines at the top of your build.gradle to enable unittests (more information: gradle-cobol-plugin-unittest-extension):

 buildscript {
 	 dependencies {
 		classpath group: 'de.sebastianruziczka', name: 'gradle-cobol-plugin-unittest-extension', version: 'latest'
 	}
 }

Or hardcode with specific version (not preferred):

 buildscript {
 	 dependencies {
 		classpath group: 'de.sebastianruziczka', name: 'gradle-cobol-plugin-unittest-extension', version: '0.0.30'
 	}
 }

Unit testing

To run your unit-tests enter:

gradle testUnit

The additional parameter ‘showResults’ prints out all results (successfull + failing)

gradle testUnit -PshowResults

Integration testing

To run your unit-tests enter:

gradle testIntegration

The additional parameter ‘showResults’ prints out all results (successfull + failing)

gradle testIntegration -PshowResults

Deep documentation

Configuration of the plugin

Following properties can be modified in the cobol block in your build.gradle :

Compile

name default other
srcFileType ‘.cbl’ e.g. ‘.CBL’
srcMain ’’  
srcMainPath ‘src/main/cobol’  
binMainPath ‘build/bin/main/cobol’  
resMainPath ‘res/main/cobol’  
multiCompileTargets [] other files to be compiled
fileFormat ‘fixed’ ‘free’
compiler instance of GnuCobol  
compilerLogLevel ‘FINE’ ‘FINER’, ‘FINEST’

Run

name default other
terminal ‘current’ ‘gnome-terminal’ or ‘xterm’
terminalRows 43  
terminalColumns 80  
customTerminal ’’  
additionalRuntimeEnvironmentVariables [] e.g. [MY_KEY:’MY_VALUE’]

Test

name default other
srcTestPath ‘src/test/cobol’  
unittestPostfix ‘UT’ e.g. ‘UNIT’, ‘TEST’ …
unittestCodeCoverage false true
integratinotestPostfix ‘IT’ e.g. ‘INTEGRATION’, ‘INTEGRATIONTEST’ …
integrationtestCodeCoverage false true
resIntegrationTest ‘res/integrationtest/cobol’  
additionalRuntimeEnvironmentVariables [] e.g. [MY_KEY:’MY_VALUE’]

Terminal configuration

preconfigured terminals

Set the parameter terminal in the cobol block in your build gradle, to use one of the preconfigured terminals.

terminal value default
gnome-terminal ‘gnome-terminal’  
xterm ‘xterm’  
current terminal ‘current’ yes

configure own terminal

Set the parameter customTerminal in the cobol block in your build.gradle to use a custom terminal commands.

Insert the full qualified terminal command string. Use {path} as placeholder for the absolute path to the executable (runExecutable) or the terminal command (runDebug).

tasks

Cobol compile executable

name input output dependsOn
compileExecutable srcMain executable in build  
cobolCopyRessources resMain ressources in build directory  
build   runnable programm in build directory compile, cobolCopyRessources
runExecutable everything in build directory terminal process build
compileMultiTarget defined main files in multiCompileTargets executables in build directory  

Cobol development

name input output dependsOn
helloWorld   HELLOWORLD.cbl + executable runDebug
compileDebug changed files since last build in srcMain gcc modules for each cobol file ion build  
buildDebug   compiled cobol files in build directory witrh ressources compileDebug, cobolCopyRessources
runDebug everything in build directory terminal process buildDebug
testUnit srcTest result of tests  
testIntegration srcTest result of tests  
check everything check result testUnit, compile, cobolConfiguration

Develop own testing plugin

Basics how to extend this project.

Example: Build Status gradle-cobol-plugin-unittest-extension Adds unittests to the base plugin

Basics

At first, add the gradleAPI and gradle-cobol-plugin as dependency:

repositories {
	mavenCentral()
	jcenter()
	maven {
		url 'https://sebastianruziczka.de/repo/mvn'
	}
}

dependencies {
	compileOnly gradleApi()
	compileOnly group: 'de.sebastianruziczka', name: 'gradle-cobol-plugin', version: 'latest'
}

To use your own testing groovy/java/kotlin … -code, several conditions must be met.

Make sure your main framework class:

Methods of the interface CobolTestFramework:

Reuse exiting code

ProcessWrapper (de.sebastianruziczka.process.ProcessWrapper)

Wrapps an existing Java ProcessBuilder.

Features:

CompilerBuilder (de.sebastianruziczka.compiler.api.CompilerBuilder)

Interface to the configured compiler. An instance is located in CobolExtension.compiler

This builder enables executable files and modules to be compiled.