Skip to content

Commit

Permalink
Move project info variables to top-level build file
Browse files Browse the repository at this point in the history
  • Loading branch information
scroix committed Mar 30, 2024
1 parent 0cfb6fd commit 9018716
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 77 deletions.
32 changes: 31 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
import org.joda.time.DateTime

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'joda-time:joda-time:2.10.10'
}
}

ext {
getGitInfo = {
return [
branch : 'git rev-parse --abbrev-ref HEAD'.execute().text.trim(),
id : 'git rev-parse HEAD'.execute().text.trim(),
rev : 'git rev-list --count HEAD'.execute().text.trim(),
origin : 'git config --get remote.origin.url'.execute().text.trim()
]
}

gitInfo = getGitInfo()
buildSummary = gitInfo.id
hostname = InetAddress.getLocalHost().getHostName().toUpperCase()
now = DateTime.now().toString()
rev = gitInfo.rev.replaceAll(/[^a-zA-Z0-9]/, '')
branch = gitInfo.branch
version = gitInfo.branch != 'stable' ? "${project.version}-${branch}_r${rev}" : project.version
}

subprojects {
apply plugin: 'java'
group = 'org.nodel'
version = '2.2.1'
repositories {
mavenCentral()
}
}
}
36 changes: 2 additions & 34 deletions nodel-framework/build.gradle
Original file line number Diff line number Diff line change
@@ -1,50 +1,18 @@
import org.apache.tools.ant.filters.ReplaceTokens
import org.joda.time.DateTime;

apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'eclipse'

buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'joda-time:joda-time:2.6'
}
}

// some extended unicode is used in SimpleName
compileJava.options.encoding = 'utf-8'

def hostname = InetAddress.getLocalHost().getHostName().toUpperCase();

def now = DateTime.now().toString();

def gitBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
def gitId = 'git rev-parse HEAD'.execute().text.trim()
def gitRev = 'git rev-list --count HEAD'.execute().text.trim()

def branch = gitBranch
if (branch.equals("master"))
branch = "dev"

def rev = gitRev
// strip out non-alphanumeric (e.g. the '+' in '1234+')
rev = rev.replaceAll(/[^a-zA-Z0-9]/, '')

def buildSummary = gitId

if (!branch.equals("stable"))
version = version + "-" + branch + "_r" + rev
version = rootProject.ext.gitInfo.branch != 'stable' ? "${project.version}-${rootProject.ext.branch}_r${rootProject.ext.rev}" : project.version

jar {
from "$buildDir/output"
archiveBaseName = 'nodel-framework'
manifest {
attributes 'Implementation-Title': 'Nodel framework for Java',
'Implementation-Version': version
'Implementation-Version': rootProject.ext.version
}
}

Expand Down
18 changes: 2 additions & 16 deletions nodel-jyhost/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@ repositories {
mavenCentral()
}

def gitBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
def gitId = 'git rev-parse HEAD'.execute().text.trim()
def gitRev = 'git rev-list --count HEAD'.execute().text.trim()

def branch = gitBranch
if (branch.equals("master"))
branch = "dev"

def rev = gitRev
// strip out non-alphanumeric (e.g. the '+' in '1234+')
rev = rev.replaceAll(/[^a-zA-Z0-9]/, '')

def buildSummary = gitId

application {
mainClass = 'org.nodel.jyhost.Launch'
}
Expand All @@ -42,9 +28,9 @@ tasks.register('fatJar', Jar) {
'Implementation-Version': archiveVersion,
'Main-Class': application.mainClassName
}
archiveAppendix = branch
archiveAppendix = rootProject.ext.branch
archiveBaseName = 'nodelhost'
archiveClassifier = 'rev' + rev
archiveClassifier = 'rev' + rootProject.ext.rev
destinationDirectory = new File(buildDir, 'distributions/standalone')
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
Expand Down
34 changes: 8 additions & 26 deletions nodel-webui-js/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import org.apache.tools.ant.filters.ReplaceTokens
import org.joda.time.DateTime

buildscript {
repositories {
Expand Down Expand Up @@ -27,23 +26,6 @@ dependencies {
implementation 'org.joda:joda-convert:2.2.1'
}

static def getGitInfo() {
return [
branch : 'git rev-parse --abbrev-ref HEAD'.execute().text.trim(),
id : 'git rev-parse HEAD'.execute().text.trim(),
rev : 'git rev-list --count HEAD'.execute().text.trim(),
origin : 'git config --get remote.origin.url'.execute().text.trim()
]
}

def buildSummary = gitInfo.id
def hostname = InetAddress.getLocalHost().getHostName().toUpperCase()
def now = DateTime.now().toString()
def rev = gitInfo.rev.replaceAll(/[^a-zA-Z0-9]/, '')
def branch = gitInfo.branch

version = gitInfo.branch != 'stable' ? "${project.version}-${branch}_r${rev}" : project.version

node {
version = '12.19.0'
download = true
Expand Down Expand Up @@ -126,15 +108,15 @@ tasks.register('filterContentTemplates', Copy) {
into file("${project.buildDir}/www-content_stage")
include 'build.json'
filter(ReplaceTokens, tokens: [
buildSummary: (project.name + "-" + project.version + " " + buildSummary + " (" + hostname + ") " + now).toString(),
buildOrigin : gitInfo.origin.toString(),
buildSummary: (project.name + "-" + project.version + " " + rootProject.ext.buildSummary + " (" + rootProject.ext.hostname + ") " + rootProject.ext.now).toString(),
buildOrigin : rootProject.ext.gitInfo.origin.toString(),
buildProject: project.name.toString(),
buildBranch : branch.toString(),
buildVersion: project.version.toString(),
buildId : buildSummary.toString(),
buildRev : rev.toString(),
buildHost : hostname.toString(),
buildDate : now.toString()
buildBranch : rootProject.ext.branch.toString(),
buildVersion: rootProject.ext.version.toString(),
buildId : rootProject.ext.buildSummary.toString(),
buildRev : rootProject.ext.rev.toString(),
buildHost : rootProject.ext.hostname.toString(),
buildDate : rootProject.ext.now.toString()
])
}

Expand Down

0 comments on commit 9018716

Please sign in to comment.