Skip to content

Commit 3baaf3f

Browse files
committed
Initial git info work
Add Jenkinsfile and use Gradle 7.0.2 Licenser currently doesn't have a functional release for Gradle 7.1
1 parent f070717 commit 3baaf3f

File tree

11 files changed

+579
-0
lines changed

11 files changed

+579
-0
lines changed

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# gradle
2+
.gradle
3+
build
4+
repo
5+
6+
# eclipse
7+
.settings
8+
.metadata
9+
.classpath
10+
.project
11+
bin
12+
13+
# intellij
14+
out
15+
*.idea
16+
*.iml
17+
18+
# src
19+
src/main/groovy/**/*.groovy

HEADER

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
${name}
2+
Copyright (C) ${year} ${fullname}
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17+
USA

Jenkinsfile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
@Library('forge-shared-library')_
2+
3+
pipeline {
4+
agent {
5+
docker {
6+
image 'gradle:jdk8'
7+
args '-v forgespigc:/home/gradle/.gradle/'
8+
}
9+
}
10+
environment {
11+
GRADLE_ARGS = '-Dorg.gradle.daemon.idletimeout=5000'
12+
DISCORD_WEBHOOK = credentials('forge-discord-jenkins-webhook')
13+
DISCORD_PREFIX = "Job: GradleUtils Branch: ${BRANCH_NAME} Build: #${BUILD_NUMBER}"
14+
JENKINS_HEAD = 'https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png'
15+
}
16+
17+
stages {
18+
stage('notify_start') {
19+
when {
20+
not {
21+
changeRequest()
22+
}
23+
}
24+
steps {
25+
discordSend(
26+
title: "${DISCORD_PREFIX} Started",
27+
successful: true,
28+
result: 'ABORTED', //White border
29+
thumbnail: JENKINS_HEAD,
30+
webhookURL: DISCORD_WEBHOOK
31+
)
32+
}
33+
}
34+
stage('buildandtest') {
35+
steps {
36+
sh './gradlew ${GRADLE_ARGS} --refresh-dependencies --continue build test'
37+
script {
38+
gradleVersion(this)
39+
}
40+
}
41+
}
42+
stage('publish') {
43+
when {
44+
not {
45+
changeRequest()
46+
}
47+
}
48+
steps {
49+
withCredentials([usernamePassword(credentialsId: 'maven-forge-user', usernameVariable: 'MAVEN_USER', passwordVariable: 'MAVEN_PASSWORD')]) {
50+
withGradle {
51+
sh './gradlew ${GRADLE_ARGS} publish'
52+
}
53+
}
54+
}
55+
post {
56+
success {
57+
build job: 'filegenerator', parameters: [string(name: 'COMMAND', value: "promote ${env.MYGROUP}:${env.MYARTIFACT} ${env.MYVERSION} latest")], propagate: false, wait: false
58+
}
59+
}
60+
}
61+
}
62+
post {
63+
always {
64+
script {
65+
if (env.CHANGE_ID == null) { // This is unset for non-PRs
66+
discordSend(
67+
title: "${DISCORD_PREFIX} Finished ${currentBuild.currentResult}",
68+
description: '```\n' + getChanges(currentBuild) + '\n```',
69+
successful: currentBuild.resultIsBetterOrEqualTo("SUCCESS"),
70+
result: currentBuild.currentResult,
71+
thumbnail: JENKINS_HEAD,
72+
webhookURL: DISCORD_WEBHOOK
73+
)
74+
}
75+
}
76+
}
77+
}
78+
}

build.gradle

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import net.minecraftforge.gradleutils.GradleUtils
2+
3+
plugins {
4+
id 'groovy'
5+
id 'maven-publish'
6+
}
7+
8+
ext {
9+
GIT_INFO = GradleUtils.gitInfo(file('.'))
10+
}
11+
12+
group 'net.minecraftforge'
13+
version GradleUtils.getSimpleVersion(GIT_INFO)
14+
15+
repositories {
16+
mavenCentral()
17+
}
18+
19+
dependencies {
20+
implementation 'org.codehaus.groovy:groovy-all:3.0.5'
21+
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r'
22+
}
23+
24+
task copyGradleUtils(type: Sync) {
25+
outputs.upToDateWhen { false }
26+
into 'src/main/groovy'
27+
from('buildSrc/src/main/groovy') {
28+
include '**/*.groovy'
29+
}
30+
}
31+
32+
compileGroovy.dependsOn(copyGradleUtils)
33+
34+
publishing {
35+
publications {
36+
mavenJava(MavenPublication) {
37+
from components.java
38+
39+
pom {
40+
name = 'Gradle Utils'
41+
description = 'Used by MinecraftForge projects as a util library for Gradle buildscripts'
42+
url = 'https://github.com/MinecraftForge/GradleUtils'
43+
scm {
44+
url = 'https://github.com/MinecraftForge/GradleUtils'
45+
connection = 'scm:git:git://github.com/MinecraftForge/GradleUtils.git'
46+
developerConnection = 'scm:git:[email protected]:MinecraftForge/GradleUtils.git'
47+
}
48+
issueManagement {
49+
system = 'github'
50+
url = 'https://github.com/MinecraftForge/GradleUtils/issues'
51+
}
52+
53+
licenses {
54+
license {
55+
name = 'LGPLv2.1'
56+
url = 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt'
57+
}
58+
}
59+
60+
developers {
61+
developer {
62+
id = 'LexManos'
63+
name = 'Lex Manos'
64+
}
65+
developer {
66+
id = 'SizableShrimp'
67+
name = 'SizableShrimp'
68+
}
69+
}
70+
}
71+
}
72+
}
73+
repositories {
74+
maven {
75+
if (System.env.MAVEN_USER) {
76+
url 'https://maven.minecraftforge.net/'
77+
authentication {
78+
basic(BasicAuthentication)
79+
}
80+
credentials {
81+
username = System.env.MAVEN_USER ?: 'not'
82+
password = System.env.MAVEN_PASSWORD ?: 'set'
83+
}
84+
} else {
85+
url 'file://' + rootProject.file('repo').getAbsolutePath()
86+
}
87+
}
88+
}
89+
}

buildSrc/build.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
plugins {
2+
id 'org.cadixdev.licenser' version '0.5.0'
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r'
11+
}
12+
13+
license {
14+
header = new File(projectDir.parentFile, 'HEADER')
15+
ext {
16+
name = 'GradleUtils'
17+
year = 2021
18+
fullname = 'Forge Development LLC'
19+
}
20+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* GradleUtils
3+
* Copyright (C) 2021 Forge Development LLC
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18+
* USA
19+
*/
20+
21+
package net.minecraftforge.gradleutils
22+
23+
import org.eclipse.jgit.api.Git
24+
import org.eclipse.jgit.errors.RepositoryNotFoundException
25+
import org.eclipse.jgit.lib.ObjectId
26+
import org.eclipse.jgit.lib.Repository
27+
28+
class GradleUtils {
29+
static {
30+
String.metaClass.rsplit = { String del, int limit = -1 ->
31+
def lst = new ArrayList()
32+
def x = 0, idx
33+
def tmp = delegate
34+
while ((idx = tmp.lastIndexOf(del)) != -1 && (limit == -1 || x++ < limit)) {
35+
lst.add(0, tmp.substring(idx + del.length(), tmp.length()))
36+
tmp = tmp.substring(0, idx)
37+
}
38+
lst.add(0, tmp)
39+
return lst
40+
}
41+
}
42+
43+
static gitInfo(dir) {
44+
def git = null
45+
try {
46+
git = Git.open(dir)
47+
} catch (RepositoryNotFoundException e) {
48+
return [
49+
tag: '0.0',
50+
offset: '0',
51+
hash: '00000000',
52+
branch: 'master',
53+
commit: '0000000000000000000000',
54+
abbreviatedId: '00000000'
55+
]
56+
}
57+
def desc = git.describe().setLong(true).setTags(true).call().rsplit('-', 2)
58+
def head = git.repository.exactRef('HEAD')
59+
def longBranch = head.symbolic ? head?.target?.name : null // matches Repository.getFullBranch() but returning null when on a detached HEAD
60+
61+
def ret = [:]
62+
ret.tag = desc[0]
63+
ret.offset = desc[1]
64+
ret.hash = desc[2]
65+
ret.branch = longBranch != null ? Repository.shortenRefName(longBranch) : null
66+
ret.commit = ObjectId.toString(head.objectId)
67+
ret.abbreviatedId = head.objectId.abbreviate(8).name()
68+
69+
return ret
70+
}
71+
72+
static String getSimpleVersion(info) {
73+
return "${info.tag}.${info.offset}"
74+
}
75+
}

gradle/wrapper/gradle-wrapper.jar

57.8 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)