Skip to content

Commit

Permalink
Easier deploy!
Browse files Browse the repository at this point in the history
- Added version in jar manifest
- Cobol Check now reads version from manifest
- build.gradle now clears jar in extension
- build.gradle now copies jar to extension
- build.gradle now copies and sets version of run scripts
- Run scripts now has a tag, for version, to be swapped

Signed-off-by: David Kaan <dak@bankdata.dk>
  • Loading branch information
David Kaan committed Sep 20, 2022
1 parent 1a55bf5 commit cecec6c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 24 deletions.
60 changes: 45 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,35 +127,65 @@ task fatJar(type: Jar) {
description 'Create executable jar'
dependsOn integrationTest
manifest {
attributes 'Main-Class': "${mainClassName}"
attributes 'Main-Class': "${mainClassName}",
'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': productVersion
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}

task copyJar(type: Copy) {
task clearJar(type: Delete) {
delete(files("${project.buildDir}/vs code extension/Cobol-check/bin/"))
}

task copyJarToBin(type: Copy) {
description 'Copy executable jar to bin directory prior to distribution'
dependsOn fatJar
from('build/libs/')
include '**/*.jar'
include '**/*.jar'
into 'bin/'
}

task copyJarToExtension(type: Copy) {
description 'Copy executable jar to bin and VS Code extension bin directories prior to distribution'
dependsOn clearJar, fatJar
from('build/libs/')
include '**/*.jar'
into 'vs code extension/Cobol-check/bin/'
}


task copyRunScripts(type: Copy) {
description 'Makes copies of run scripts'
from "${projectDir}/cobolcheck.cmd"
into "${projectDir}/GradleTemp"
filter { line -> line.replaceAll('@VERSION@', productVersion) }
from "${projectDir}/cobolcheck"
into "${projectDir}/GradleTemp"
filter { line -> line.replaceAll('@VERSION@', productVersion) }
}

task prepareDistribution(type: Zip) {
archiveName "${productName}-${productVersion}.zip"
description 'Prepare distribution archive'
dependsOn copyJar
from "${projectDir}"
include([ "config.properties",
"scripts/*",
"bin/${productName}-${productVersion}.jar",
"src/main/cobol/ALPHA.CBL",
"src/main/cobol/NUMBERS.CBL",
"src/test/cobol/ALPHA/*",
"src/test/cobol/NUMBERS/*",
"cobolcheck",
"cobolcheck.cmd" ])
rename("build/libs/(.*)", "\$1")
dependsOn copyJarToBin, copyJarToExtension, copyRunScripts
from ("${projectDir}"){
include([ "config.properties",
"scripts/*",
"bin/${productName}-${productVersion}.jar",
"src/main/cobol/ALPHA.CBL",
"src/main/cobol/NUMBERS.CBL",
"src/test/cobol/ALPHA/*",
"src/test/cobol/NUMBERS/*" ])
rename("build/libs/(.*)", "\$1")
}

from ("${projectDir}/GradleTemp")

doLast {
delete "GradleTemp"
}
}

def approvalTest = tasks.register("approvalTest", Test) {
Expand Down
2 changes: 1 addition & 1 deletion cobolcheck
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
java -jar bin/cobol-check-0.2.1.jar $@
java -jar bin/cobol-check-@VERSION@.jar1 $@
2 changes: 1 addition & 1 deletion cobolcheck.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@echo off
java -jar bin\cobol-check-0.2.1.jar %*
java -jar bin\cobol-check-@VERSION@.jar %*
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void emitHelp(){
* Emmits a message to the console showing the current version
*/
void emitVersion(){
System.out.println(Version.current());
System.out.println("Version: " + Version.current());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* @since 1.8
*/
public class Version {
private static final Integer MAJOR = 0;
private static final Integer MINOR = 2;
private static final String PATCH = "1";

public static String current() {
return String.format("Version: %s.%s.%s", MAJOR.toString(), MINOR.toString(), PATCH);
String version = Version.class.getPackage().getImplementationVersion();
if (version != null)
return version;
else
return "1.0.DEV";
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package org.openmainframeproject.cobolcheck;

import org.junit.jupiter.api.BeforeAll;
import org.openmainframeproject.cobolcheck.services.Config;
import org.openmainframeproject.cobolcheck.services.Version;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;


public class VersionTest {

@BeforeAll
static void oneTimeSetup() {
Config.load("testconfig.properties");
}

@Test
public void it_returns_the_current_version_string() {
assertTrue(Version.current().matches("^Version: \\d\\.\\d\\..*$"));
assertTrue(Version.current().matches("^\\d\\.\\d\\..*$"));
}
}

0 comments on commit cecec6c

Please sign in to comment.