Fix dynamic version lookup.

This commit is contained in:
Mark Nellemann 2020-10-07 15:09:59 +02:00
parent c555f91794
commit 8d633cc049
4 changed files with 16 additions and 30 deletions

View File

@ -1,5 +1,4 @@
image: adoptopenjdk:8-openj9 image: openjdk:8
#image: openjdk:8
pipelines: pipelines:
branches: branches:
@ -17,7 +16,7 @@ pipelines:
- gradle - gradle
name: Build and Release name: Build and Release
script: script:
- ./gradlew clean versionFile build shadowJar buildRpm buildDeb - ./gradlew clean build shadowJar buildRpm buildDeb
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/libs/*-all.jar ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done - shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/libs/*-all.jar ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/distributions/*.rpm ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done - shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/distributions/*.rpm ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/distributions/*.deb ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done - shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/distributions/*.deb ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done

View File

@ -8,8 +8,6 @@ plugins {
} }
repositories { repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter() jcenter()
} }
@ -20,13 +18,11 @@ dependencies {
implementation 'org.slf4j:slf4j-api:1.7.+' implementation 'org.slf4j:slf4j-api:1.7.+'
runtimeOnly 'ch.qos.logback:logback-classic:1.+' runtimeOnly 'ch.qos.logback:logback-classic:1.+'
// Use the awesome Spock testing and specification framework
testImplementation('org.spockframework:spock-core:2.0-M3-groovy-3.0') testImplementation('org.spockframework:spock-core:2.0-M3-groovy-3.0')
testImplementation("org.slf4j:slf4j-simple:1.7.+") testImplementation("org.slf4j:slf4j-simple:1.7.+")
} }
application { application {
// Define the main class for the application.
mainClassName = 'biz.nellemann.syslogd.SyslogServer' mainClassName = 'biz.nellemann.syslogd.SyslogServer'
} }
@ -59,7 +55,6 @@ ospackage {
buildRpm { buildRpm {
dependsOn startShadowScripts dependsOn startShadowScripts
//requires('java-1.8.0-openjdk-headless')
os = LINUX os = LINUX
} }
@ -68,21 +63,16 @@ buildDeb {
requires('default-jre-headless') requires('default-jre-headless')
} }
processResources.dependsOn.add("versionFile")
versionFile {
// Path to the file to be written
file = new File(project.buildDir, 'resources/main/version.properties')
}
jar { jar {
manifest { manifest {
attributes( attributes(
'Built-By' : System.properties['user.name'], 'Created-By' : "Gradle ${gradle.gradleVersion}",
'Build-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ").toString(), 'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}",
'Build-Revision' : versioning.info.commit, 'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Created-By' : "Gradle ${gradle.gradleVersion}", 'Build-User' : System.properties['user.name'],
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})", 'Build-Version' : versioning.info.tag ?: (versioning.info.branch + "-" + versioning.info.build),
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}" 'Build-Revision' : versioning.info.commit,
'Build-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ").toString(),
) )
} }
} }

View File

@ -1,3 +1,3 @@
id = syslogd id = syslogd
group = biz.nellemann.syslogd group = biz.nellemann.syslogd
version = 1.0.3 version = 1.0.4

View File

@ -3,20 +3,17 @@ package biz.nellemann.syslogd;
import picocli.CommandLine; import picocli.CommandLine;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.util.jar.Attributes;
import java.util.Properties; import java.util.jar.Manifest;
class VersionProvider implements CommandLine.IVersionProvider { class VersionProvider implements CommandLine.IVersionProvider {
public String[] getVersion() throws IOException { public String[] getVersion() throws IOException {
URL url = getClass().getResource("/version.properties"); Manifest manifest = new Manifest(getClass().getResourceAsStream("/META-INF/MANIFEST.MF"));
if (url == null) { Attributes attrs = manifest.getMainAttributes();
return new String[] { "No version information available." };
} return new String[] { "${COMMAND-FULL-NAME} " + attrs.getValue("Build-Version") };
Properties properties = new Properties();
properties.load(url.openStream());
return new String[] { "${COMMAND-FULL-NAME} " + properties.getProperty("VERSION_GRADLE") + "-" + properties.getProperty("VERSION_BUILD") };
} }
} }