Skip to content

Commit

Permalink
Merge pull request MegaMek#1567 from rjhancock/utilities-to-gradle
Browse files Browse the repository at this point in the history
Updated Gradle
  • Loading branch information
HammerGS authored Jul 21, 2024
2 parents 8109232 + ac19834 commit 5d36273
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 178 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
/megameklab/mmconf/*.preferences
/megameklab/out/
/megameklab/.classpath
/megameklab/.project
/megameklab/.project
/megameklab/sheets

/megameklab/docs/mml-revision.txt
/megameklab/MegaMekLab.l4j.ini
17 changes: 0 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
plugins {
id 'org.ajoberstar.grgit' version '5.2.2'
id 'java'
}

Expand All @@ -19,22 +18,6 @@ subprojects {
version = '0.50.0-SNAPSHOT'
}

ext {
mmGitRoot = 'https://github.com/MegaMek/megamek.git'
mmlGitRoot = 'https://github.com/MegaMek/megameklab.git'
// Work on MML or MHQ sometimes requires changes in MM as well. The maven publishing tasks use
// these properties to append the branch name to the artifact id if the repo is not in the master
// branch, making it available separately to the child project.
mmlBranch = grgit.branch.current().name
mmlBranchTag = mmlBranch.equals('master') ? '' : '-' + mmlBranch

// Allows setting a dependency on a different MM branch.
mmBranch = 'master'
mmBranchTag = mmBranch.equals('master') ? '' : '-' + mmBranch

mmDir = "${rootDir}/../megamek"
}

// A properties_local.gradle file can be used to override any of the above options. For instance,
// rootProject.ext.mmlGitRoot = 'file:///path/to/local/repo' will cause the release target to clone a
// local copy of the repository rather than downloading it.
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
175 changes: 51 additions & 124 deletions megameklab/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import java.time.LocalDateTime

plugins {
id 'application'
id 'edu.sc.seis.launch4j' version '3.0.5'
id 'edu.sc.seis.launch4j' version '3.0.6'
id 'jacoco'
id 'java'
id "io.sentry.jvm.gradle" version "4.9.0"
id "io.sentry.jvm.gradle" version "4.10.0"
id 'com.palantir.git-version' version '3.1.0'
}

java {
Expand All @@ -32,6 +33,27 @@ sourceSets {
}
}

ext {
mmlJvmOptions = ['-Xmx1024m']
data = 'data'
unitFiles = "${data}/mechfiles"
docs = 'docs'
lib = 'lib'
log = 'logs'
mmconf = 'mmconf'
userdata = 'userdata'
distributionDir = "${buildDir}/distributions"
fileStagingDir = "${buildDir}/files"
scriptsDir = "${projectDir}/scripts"
scriptTemplate = "${scriptsDir}/startScriptTemplate.txt"

// Allows setting a dependency on a different MM branch.
mmBranch = 'master'
mmBranchTag = mmBranch.equals('master') ? '' : '-' + mmBranch

mmDir = "${rootDir}/../megamek"
}

dependencies {
implementation "org.megamek:megamek${mmBranchTag}:${version}"

Expand Down Expand Up @@ -64,82 +86,58 @@ dependencies {

//Required for printing scaled vector graphics (SVG) - EclipseIDE Comipatability.
runtimeOnly 'xml-apis:xml-apis-ext:1.3.04'

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

application {
mainClass = 'megameklab.MegaMekLab'
}

ext {
mmlJvmOptions = ['-Xmx1024m']
data = 'data'
unitFiles = "${data}/mechfiles"
docs = 'docs'
lib = 'lib'
log = 'logs'
mmconf = 'mmconf'
userdata = 'userdata'
distributionDir = "${buildDir}/distributions"
fileStagingDir = "${buildDir}/files"
mmRepoDir = "${buildDir}/repo/megamek"
mmlRepoDir = "${buildDir}/repo/megameklab"
scriptsDir = "${projectDir}/scripts"
scriptTemplate = "${scriptsDir}/startScriptTemplate.txt"
}

task mmJar (type: Jar) {
description = 'Builds a MegaMek jar from the current source'

dependsOn gradle.includedBuild('megamek').task(':megamek:compileTestJava')

archiveFileName = "MegaMek.jar"
from "${mmDir}/megamek/build/classes/java/main"
from "${mmDir}/megamek/build/resources/main"
manifest {
attributes "Main-Class" : 'megamek.MegaMek'
attributes "Class-Path" : project.sourceSets.main.runtimeClasspath.files
.findAll { it.name.endsWith(".jar") }
.collect { "${lib}/${it.name}" }.join(' ')
attributes "Add-Opens" : 'java.base/java.util java.base/java.util.concurrent'
attributes "Build-Date" : LocalDateTime.now()
}
ext.jarLocation = "${buildDir}/libs/${archiveFileName.get()}"
inputs.dir "${mmDir}/megamek/build/classes/java/main"
inputs.dir "${mmDir}/megamek/build/resources/main"
outputs.file jarLocation
}

jar {
archiveFileName = "MegaMekLab.jar"
manifest {
attributes "Main-Class" : application.mainClass
attributes "Class-Path" : "${lib}/${mmJar.archiveFileName.get()} " + (project.sourceSets.main.runtimeClasspath.files
attributes "Class-Path" : "${lib}/MegaMek.jar " + (project.sourceSets.main.runtimeClasspath.files
.findAll { it.name.endsWith(".jar") && !it.name.toLowerCase().startsWith("megamek") }
.collect { "${lib}/${it.name}" }.join(' '))
attributes "Add-Opens" : 'java.base/java.util java.base/java.util.concurrent'
attributes "Build-Date" : LocalDateTime.now()
}
}

task generateDynamicFiles() {
doLast {
new File("${projectDir}/docs/mml-revision.txt").text = versionDetails().gitHashFull
new File("${projectDir}/MegaMekLab.l4j.ini").text = """# Launch4j runtime config
# you can add arguments here that will be processed by the JVM at runtime
${project.ext.mmlJvmOptions.join('\n')}
"""
}
}

task stageFiles(type: Copy) {
description = 'Stages files that are to be copied into the distribution.'

dependsOn gradle.includedBuild('megamek').task(':megamek:compileJava')
dependsOn generateDynamicFiles

from projectDir
include "${mmconf}/**"
include "${data}/**"
include "${docs}/**"
include 'license.txt'
include 'SubmitBug.html'
include "sentry.properties"
include "mml-revision.txt"
include "MegaMekLab.l4j.ini"
exclude "**/*.psd"

into fileStagingDir

inputs.dir "${mmconf}"
inputs.dir "${data}"
inputs.dir "${docs}"
inputs.files 'license.txt', 'SubmitBug.html', 'sentry.properties', 'mml-revision.txt'
inputs.files 'license.txt', 'SubmitBug.html', 'sentry.properties', 'MegaMekLab.l4j.ini'
outputs.dir fileStagingDir

doLast {
Expand Down Expand Up @@ -183,7 +181,7 @@ distributions {
include 'mml*'
rename 'mml(.*)', 'mml-startup$1'
}
from (mmJar) {
from ("${mmDir}/megamek/build/libs/MegaMek.jar") {
into "${lib}"
}
from (jar)
Expand Down Expand Up @@ -233,6 +231,7 @@ tasks.register("packagePrepWork") {

distZip {
description = 'Creates zip Package'
enabled = false
dependsOn packagePrepWork
}

Expand All @@ -243,52 +242,6 @@ distTar {
compression = Compression.GZIP
}

// The repository can only be cloned into an empty directory so we need to delete anything left over
// from a previous build
task deleteMMRepoDir (type: Delete) {
delete = "${mmRepoDir}"
}

task deleteMMLRepoDir (type: Delete) {
delete = "${mmlRepoDir}"
}

task cloneMMRepo (type: Exec, dependsOn: deleteMMRepoDir) {
description = 'Clones the MegaMek repository to ensure we are working with a clean directory tree'
group = 'distribution'
commandLine "git"
args "clone", "--branch", mmBranch, "--single-branch", mmGitRoot, "${mmRepoDir}"
}

task cloneMMLRepo (type: Exec, dependsOn: deleteMMLRepoDir) {
description = 'Clones the MegaMekLab repository to ensure we are working with a clean directory tree'
group = 'distribution'
commandLine "git"
args "clone", "--branch", mmlBranch, "--single-branch", mmlGitRoot, "${mmlRepoDir}"
}

task sourceZip (type: Zip) {
description 'Creates a zip archive of the source'
group = 'distribution'
from (rootDir) {
exclude "**/build/**"
exclude "**/.*"
}
archiveFileName = "megameklab-${archiveVersion}-source.zip"
destinationDirectory = file(distributionDir)
}

task sourceTar (type: Tar) {
description 'Creates a compressed tar archive of the source'
from (rootDir) {
exclude "**/build/**"
exclude "**/.*"
}
archiveFileName = "megameklab-${archiveVersion}-source.tar.gz"
compression = Compression.GZIP
destinationDirectory = file(distributionDir)
}

// The distribution plugin adds the distro packages to the assemble task, which causes the build task
// to run all the packaging tasks.
task assemble(overwrite: true) {
Expand All @@ -301,39 +254,6 @@ task assembleDist(overwrite: true) {
group = 'distribution'
dependsOn test
dependsOn distTar
dependsOn distZip
}

task buildFromRepo (type: GradleBuild) {
description = 'Assembles the distribution packages in the clean repository copy'
group = 'distribution'
dependsOn cloneMMRepo
dependsOn cloneMMLRepo

buildName = "mml-build-repo"
dir = "${mmlRepoDir}"
tasks = [ 'assembleDist' ]
}

task release (type: Copy) {
description = 'Builds the release packages from the repository and copies them into the project build directory'
group = 'distribution'
dependsOn buildFromRepo

from "${mmlRepoDir}/build/distributions"
into "${distributionDir}"
}

task sourcesJar(type: Jar) {
description = 'Creates a source archive for publication to a maven repository'
from sourceSets.main.allJava
archiveClassifier = 'sources'
}

task javadocJar(type: Jar) {
description = 'Creates a documentation archive for publication to a maven repository'
from javadoc
archiveClassifier = 'javadoc'
}

test {
Expand All @@ -350,3 +270,10 @@ jacocoTestReport {
html.required = true
}
}

task processSystemTest(type: JavaExec, dependsOn: stageFiles) {
description = 'Internal System Test. Dev use only.'
group = 'other'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'megameklab.printing.CGLMassPrinter'
}
12 changes: 7 additions & 5 deletions megameklab/mmconf/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@
</Properties>

<Appenders>
<Console name="Console">
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${layout}" />
</Console>
<File name="MegaMekLabLog" fileName="logs/megameklab.log" append="false">
<PatternLayout pattern="${layout}"/>
<PatternLayout pattern="${layout}" />
</File>
</Appenders>

<Loggers>
<Logger name="megamek" level="info" additivity="false" >
<Logger name="megamek" level="info" additivity="false">
<AppenderRef ref="MegaMekLabLog" />
<AppenderRef ref="Console" />
</Logger>
<Logger name="megameklab" level="info" additivity="false" >
<Logger name="megameklab" level="info" additivity="false">
<AppenderRef ref="MegaMekLabLog" />
<AppenderRef ref="Console" />
</Logger>

<Root level="info">
<AppenderRef ref="MegaMekLabLog" />
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
Loading

0 comments on commit 5d36273

Please sign in to comment.