Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
316 lines (194 sloc) 10.9 KB

gradle-cobol-plugin

Build Status

This project is part of my master thesis.

You can discover some examples here

Features

  • Compile, assemble and run your cobol code with a single command
  • Simple and adaptable configuration
  • Incremental compilation
  • Create and run cobol-unit-tests and cobol-unit-integration tests
  • Compute code coverage of your tests (generates an cobertura coverage xml file)
  • Expandable with custom plugin extensions
  • Simple and fast continuous integration e.g. with jenkins or travis.

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.42'
}

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)

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:

  • ... is in the classpath of this plugin (via buildscript dependencies)
  • ... is in the package de.*
  • ... implements the interface de.sebastianruziczka.CobolTestFramework
  • ... is annotated with @CobolUnitTestFrameworkProvider or @CobolIntegrationTestFrameworkProvider

Methods of the interface CobolTestFramework:

  • void configure(CobolExtension configuration, Project project): Initial configuration call. Here you can define new gradle tasks, if needed.
  • int prepare(): Initial call for framework initialization. Returns a process return code (default: 0)
  • clean() : Called before all tests are executed
  • TestFile test(CobolSourceFile file): Called for every pair of src<->testfile. Returns an instance of TestFile

Reuse exiting code

ProcessWrapper (de.sebastianruziczka.process.ProcessWrapper)

Wrapps an existing Java ProcessBuilder.

Features:

  • Waits until process is finished
  • Writes process output into file
  • Writes process output into terminal (loglevel: INFO)
  • Throws exception when process returns with statuscode != 0
  • Loggs process output in terminal (loglevel: ERROR) when process returns with statuscode != 0

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.