Skip to content

Commit

Permalink
Version output and command line arg parsing (#23)
Browse files Browse the repository at this point in the history
* Setup gradle to dynamically set the version in code at build time
* Add Version class for dynamically holding the version of muddler. Adjust App to print version at beginning of build, and add cli arguments for printing help/version and exiting
* Adjust dockerfile to properly consume command line arguments
* prep new release
* make default shell wrapper for the docker image always pull latest.
  • Loading branch information
demonnic committed Oct 14, 2021
1 parent 1c4a714 commit 63678a1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM adoptopenjdk/openjdk8:alpine-slim
COPY ./build/libs/muddle*-all.jar /app
ENTRYPOINT sh -c 'java -jar /app'
ENTRYPOINT ["java", "-jar", "/app"]
18 changes: 15 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,29 @@ plugins {
id 'com.github.johnrengelman.shadow' version '5.0.0'

}
version = '0.9'

mainClassName = "muddler.App"

repositories {
jcenter()
jcenter()
}

dependencies {
implementation 'org.codehaus.groovy:groovy-all:3.0.3'
}

// this feels like a lot to not repeat the version, but by Jove I'm doing it anyway!
task generateGroovy(type: Copy) {
def templateContext = [version: project.version]
inputs.properties templateContext // for gradle up-to-date check
from "src/template/groovy/"
into "$buildDir/generated/groovy"
expand templateContext
}
// add the generated files to the srcDir and ensure they're generated before compileGroovy
sourceSets.main.groovy.srcDir "$buildDir/generated/groovy"
compileGroovy.dependsOn generateGroovy

task dockerImage(type:Exec, dependsOn: ['clean', 'shadowJar']) {
commandLine 'docker', 'build', '-t', "demonnic/muddler:$version", '.'
}
Expand All @@ -51,7 +63,7 @@ task createPom {
project {
groupId 'muddler'
artifactId 'muddler'
version "$version"
version project.version
inceptionYear '2019'
}
}.writeTo("pom.xml")
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = 0.10
2 changes: 1 addition & 1 deletion muddle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker run --rm -it -u $(id -u):$(id -g) -v $PWD:/$PWD -w /$PWD demonnic/muddler
docker run --pull always --rm -it -u $(id -u):$(id -g) -v $PWD:/$PWD -w /$PWD demonnic/muddler
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>muddler</groupId>
<artifactId>muddler</artifactId>
<version>0.9</version>
<version>0.10</version>
<inceptionYear>2019</inceptionYear>
<dependencies>
<dependency>
Expand Down
25 changes: 23 additions & 2 deletions src/main/groovy/muddler/App.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,39 @@ package muddler
import groovy.json.JsonSlurper
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.XmlUtil
import groovy.cli.picocli.CliBuilder
import static groovy.io.FileType.File
import muddler.mudlet.packages.*
import java.util.regex.Pattern
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import muddler.Echo

import muddler.Version

class App {
static void main(String[] args) {
def e = new Echo()
e.echo "Beginning build"
def cli = new CliBuilder(usage: 'muddler [-v|--version] [-h|--help]')
cli.with {
h longOpt: 'help', 'Show usage information'
v longOpt: 'version', 'Print version information and exit'
}
def options = cli.parse(args)
if (!options) {
return
}
// print usage information and exit
if (options.h) {
cli.usage()
return
}

// print version and exit
if (options.v) {
println "muddler version: " + Version.version
return
}
e.echo "Beginning build. Using muddler version ${Version.version}"
def mfile = new File('./mfile')
def readme = new File('./README.md')
def packageName = ""
Expand Down
5 changes: 5 additions & 0 deletions src/template/groovy/muddler/Version.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package muddler

class Version {
static final version = "${version}"
}

0 comments on commit 63678a1

Please sign in to comment.