Skip to content
This repository has been archived by the owner on Dec 4, 2021. It is now read-only.

Commit

Permalink
Update Gradle buildscript
Browse files Browse the repository at this point in the history
* Add changelog support in prep for further Ore deploy and CI integration
* Convert static functions to use tasks
  • Loading branch information
dualspiral committed Mar 25, 2018
1 parent 9e515be commit d8d817f
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 38 deletions.
129 changes: 101 additions & 28 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,31 @@ plugins {
id 'com.github.johnrengelman.shadow' version '1.2.3'
id 'java'
// id 'org.spongepowered.plugin' version '0.8.2-SNAPSHOT'
// id "com.qixalite.spongestart" version "1.4.3"
}

allprojects {
apply plugin: 'java'

task gitCommitHash(type: Exec) {
ignoreExitValue=true
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = new ByteArrayOutputStream()
ext.hash = {
if (getExecResult().failure == null) {
return standardOutput.toString().replace('\n', '')
} else {
return "unknown"
}
}
}

task gitCommitMessage(type: Exec) {
commandLine 'git', 'log', '-1', '--format=%B'
standardOutput = new ByteArrayOutputStream()
ext.message = {
standardOutput.toString().replaceAll('[\\r?\\n]+$', '')
}
}
}

project.ext.versionno = '1.3.5'
Expand All @@ -29,16 +53,18 @@ project.ext.spongeapiversion = '7.0'
project.ext.suffix = '-SNAPSHOT'
project.ext.hash = ''

// Add Git hash for unique version numbers, but only for non-snapshot versions
// Yes, I'm being lazy.
if (project.ext.suffix != '') {
project.ext.hash = '-' + getGitHash()
}
String docVer
boolean isSnapshot

allprojects {
apply plugin: 'java'
if (project.properties.containsKey('override-doc-ver')) {
docVer = project.properties.get('override-doc-ver')
isSnapshot = false
} else {
docVer = project.ext.versionno + "-S" + project.ext.spongeapiversion
isSnapshot = project.ext.suffix.endsWith('SNAPSHOT')
}


project(":nucleus-api") {
repositories {
jcenter()
Expand All @@ -57,8 +83,6 @@ project(":nucleus-api") {
}
}

version = project.versionno + project.suffix + project.hash + '-S' + project.spongeapiversion

if (!project.hasProperty("nosign")) {
apply plugin: 'signing'
apply plugin: 'org.spongepowered.plugin'
Expand Down Expand Up @@ -136,24 +160,27 @@ license {
}
}

blossom {
def location = 'src/main/java/io/github/nucleuspowered/nucleus/PluginInfo.java'
def getVersion = {
rootProject.version
}

replaceToken '@name@', project.name, location
replaceToken '@version@', project.version, location
replaceToken '@gitHash@', getGitHash(), location
blossom {
replaceTokenIn('src/main/java/io/github/nucleuspowered/nucleus/PluginInfo.java')
replaceToken '@name@', project.name
replaceToken '@version@', getVersion

replaceToken '@description@', project.description, location
replaceToken '@url@', project.url, location
replaceToken '@description@', project.description
replaceToken '@url@', project.url
replaceToken '@gitHash@', gitCommitHash.hash
}

jar {
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Version': version,
'SpongeAPI-Version': project.spongeapi,
'Git-Hash': getGitHash()
'SpongeAPI-Version': project.spongeapi
}

archiveName = getVersion
}

shadowJar {
Expand All @@ -180,9 +207,10 @@ shadowJar {
}

exclude "io/github/nucleuspowered/nucleus/api/NucleusAPIMod.class"
archiveName = "Nucleus-${version}-MC${project.ext.minecraftversion}-plugin.jar"
//shadowJar.archiveName = shadowName
// archiveName = "Nucleus-${version}-MC${project.ext.minecraftversion}-plugin.jar"
}
shadowJar.dependsOn([':nucleus-api:build'])
shadowJar.dependsOn(':nucleus-api:build')

task cleanJars() {
project.file('output').listFiles().each {
Expand All @@ -200,6 +228,54 @@ artifacts {
shadow shadowJar
}

// Git

task relnotes {
doLast {
String complete
if (isSnapshot) {
// read the snapshot.md file
String contents = new File('changelogs/templates/snapshot.md').getText("UTF-8")
complete = contents
.replace('{{hash}}', gitCommitHash.hash())
.replace('{{message}}', gitCommitMessage.message())
.replace('{{sponge}}', project.ext.spongeapiversion)
} else {
String contents = new File('changelogs/templates/release.md').getText("UTF-8")
String notes = new File('changelogs/templates/' + docVer + ".md").getText("UTF-8")
complete = contents
.replace('{{hash}}', gitCommitHash.hash())
.replace('{{info}}', notes)
.replace('{{sponge}}', project.ext.spongeapiversion)
}

ext.notes = complete
}
}

task printRelNotes(dependsOn: relnotes) {
doLast {
println(relnotes.notes)
}
}

task onCommitHashComplete {
doLast {
// Add Git hash for unique version numbers, but only for non-snapshot versions
if (project.ext.suffix != '') {
project.ext.hash = '-' + gitCommitHash.hash()
}

rootProject.version = project.versionno + project.suffix + project.ext.hash + '-S' + project.spongeapiversion
shadowJar.archiveName = "Nucleus-${rootProject.version}-MC${project.ext.minecraftversion}-plugin.jar"
jar.manifest.attributes.put('Implementation-Version', getVersion())
jar.manifest.attributes.put('Git-Hash', gitCommitHash.hash())
}
}


// SIGNING & ORE DEPLOY

if (!project.hasProperty("nosign")) {
signing {
required {
Expand Down Expand Up @@ -240,13 +316,10 @@ if (!project.hasProperty("nosign")) {

}

static String getGitHash() {
def process = 'git rev-parse --short HEAD'.execute()
process.waitFor()
return process.exitValue() ? 'unknown' : process.text.trim()
}

relnotes.dependsOn([gitCommitHash, gitCommitMessage])
compileJava.dependsOn(":nucleus-ap:build")
onCommitHashComplete.dependsOn(gitCommitHash)
blossomSourceReplacementJava.dependsOn(onCommitHashComplete)
clean.dependsOn(cleanJars)
copyJars.mustRunAfter(cleanJars)
build.dependsOn(shadowJar)
Expand Down
13 changes: 13 additions & 0 deletions changelogs/templates/1.3.5-S7.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## New Features

There are no new features in this release

## Bugfixes

* Fixed `/world list` mixing up reporting for `pvp` and `keepSpawnLoaded`
* Fixed `/home limit` not working without a player argument (for self)
* Updated out of date doc strings

## API updates

There are no API updates in this release
13 changes: 13 additions & 0 deletions changelogs/templates/release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This is a bug fix and minor feature release for Nucleus for Sponge API version {{sponge}}

This was built from Nucleus commit: {{hash}}

## Release Notes

If you're having trouble, visit our Discord channel: https://discord.gg/A9QHG5H

{{info}}

## Known Issues

* Sometimes, an incorrect custom prefix might be selected. Nucleus uses whatever the permission plugin hands back, check your inheritance with the permissions plugin.
4 changes: 4 additions & 0 deletions changelogs/templates/snapshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is a snapshot build of Nucleus and should only be used for testing purposes. No support is given for this build.

Git Commit hash: {{hash}}
Last commit: {{message}}
35 changes: 25 additions & 10 deletions nucleus-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,43 @@ task sourcesJar(type: Jar, dependsOn: classes) {
from sourceSets.main.allSource
}

def getRootVersion = {
rootProject.version
}

jar {
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Version': project.getRootProject().version,
'SpongeAPI-Version': project.spongeapi,
'Git-Hash': project.getRootProject().getGitHash()
attributes 'API-Title': project.name,
'Implementation-Title': rootProject.name,
'API-Version': project.version,
'SpongeAPI-Version': project.spongeapi
}

archiveName = "Nucleus-${version}-api.jar"
}

task afterGitHash(dependsOn: gitCommitHash) {
doFirst {
jar.manifest.attributes.put('Implementation-Version', getRootVersion())
jar.manifest.attributes.put('Git-Hash', gitCommitHash.hash())
}
}

compileJava.dependsOn(afterGitHash)

artifacts {
archives javadocJar
archives jar
archives sourcesJar
}

blossom {
def location = 'src/main/java/io/github/nucleuspowered/nucleus/api/NucleusAPITokens.java'
replaceTokenIn('src/main/java/io/github/nucleuspowered/nucleus/api/NucleusAPITokens.java')
replaceToken '@semver@', versionno
replaceToken '@release@', suffix
replaceToken '@version@', version
replaceToken '@description@', description
replaceToken '@gitHash@', gitCommitHash.hash
}

replaceToken '@version@', rootProject.version, location
replaceToken '@semver@', versionno, location
replaceToken '@release@', suffix, location
replaceToken '@description@', description, location
}
blossomSourceReplacementJava.dependsOn(gitCommitHash)
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rootProject.name = 'Nucleus'
include 'nucleus-api'
include 'nucleus-ap'

0 comments on commit d8d817f

Please sign in to comment.