Skip to content

Commit

Permalink
Release ZomboidMod v2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
matshou committed Apr 11, 2021
2 parents 51ef6ad + 361b35a commit 2791ac8
Show file tree
Hide file tree
Showing 8 changed files with 668 additions and 667 deletions.
63 changes: 31 additions & 32 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the java plugin to add support for Java
id 'java'

// Facilitates building archives that serve as project distributions
id 'distribution'
// Facilitates building archives that serve as project distributions
id 'distribution'
}
repositories {
mavenCentral()
mavenCentral()
}

java {
// ZomboidDoc can only be executed with Java 8
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
// ZomboidDoc can only be executed with Java 8
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
apply from: 'setup.gradle'
if (project.ext.has('gameDir'))
{
Set<String> sourcesList = new HashSet<>(['media/lua'])
Set<String> resourcesList = new HashSet<>()
Set<String> excludeResources = new HashSet<>([
'media/lua', 'media/luaexamples',
'media/newuitests', 'media/launcher',
])
def gameDirPath = gameDir as java.nio.file.Path
//@formatter:off
Set<String> sourcesList = new HashSet<>(['media/lua'])
Set<String> resourcesList = new HashSet<>()
Set<String> excludeResources = new HashSet<>([
'media/lua', 'media/luaexamples',
'media/newuitests', 'media/launcher',
])
def gameDirPath = gameDir as java.nio.file.Path
//@formatter:off
gameDirPath.resolve('media').toFile().listFiles().each
{
if (it.directory)
Expand All @@ -36,21 +36,20 @@ if (project.ext.has('gameDir'))
}
}
}//@formatter:on
sourceSets {
media {
java.srcDirs = sourcesList
resources.srcDirs = resourcesList
}
}
apply from: 'mod.gradle'
apply from: 'zomboid.gradle'
apply from: 'zdoc.gradle'
sourceSets {
media {
java.srcDirs = sourcesList
resources.srcDirs = resourcesList
}
}
apply from: 'mod.gradle'
apply from: 'zomboid.gradle'
apply from: 'zdoc.gradle'

jar.from sourceSets.media.output

jar {
from sourceSets.media.output
}
version modInfoProperties.getProperty('modversion')
apply from: 'distribution.gradle'
version modInfoProperties.getProperty('modversion')
apply from: 'distribution.gradle'

defaultTasks 'showModInfo'
defaultTasks 'showModInfo'
}
203 changes: 101 additions & 102 deletions dist/distribution.gradle
Original file line number Diff line number Diff line change
@@ -1,103 +1,102 @@
import java.nio.file.Files
import java.nio.file.Paths

// changelog.gradle
apply from: 'https://git.io/JqJiC'

def getPathsRelativeToModule(moduleName, srcDirSet) {

def module = rootDir.toPath().resolve(moduleName)
def map = new HashMap<String, String>()

def srcDirs = srcDirSet.srcDirs.stream().withCloseable {
it.filter({ f -> f.exists() }).collect()
}
for (File srcDir : (srcDirs as List<File>))
{
Files.walk(srcDir.toPath()).withCloseable
{
def paths = it.filter({ Files.isRegularFile(it as java.nio.file.Path) }).collect()
for (java.nio.file.Path path : (paths as List<java.nio.file.Path>))
{
def srcDirPath = srcDir.toPath()
def relativePath = srcDirPath.relativize(path)
def srcDirName = module.relativize(srcDirPath)
map.put(relativePath.toString(), srcDirName.toString())
}
}
}
return map
}

static def getRelativeCopyPath(fcd, relativePathMap) {

def path = relativePathMap.get(Paths.get(fcd.path).toString())
if (path != null) {
return fcd.relativePath.prepend(path)
}
else throw new Exception("Unable to relativize copy path: $fcd.path")
}

def mediaClassesDir = "$buildDir/classes/lua/media"
task mediaClasses(type: Copy, overwrite: true) {

into mediaClassesDir
from(sourceSets.media.java.srcDirs) {
def mSources = getPathsRelativeToModule('media', sourceSets.media.java)
eachFile {
def fcd = it as FileCopyDetails
fcd.setRelativePath(getRelativeCopyPath(fcd, mSources))
}
}
includeEmptyDirs = false
}

processMediaResources {

includeEmptyDirs = false
def mResources = getPathsRelativeToModule('media', sourceSets.media.resources)
eachFile {
def fcd = it as FileCopyDetails
fcd.setRelativePath(getRelativeCopyPath(fcd, mResources))
}
}

def stagePath = "$buildDir/tmp/distribution/stage"
task cleanModDistributionStage(type: Delete) {

description 'Clean distribution stage directory.'
group 'distribution'

it.onlyIf {
file(stagePath).exists()
}
delete(stagePath)
}
tasks.register('stageModDistribution', Copy.class) {

it.description 'Copy mod distribution files to stage directory.'
it.group 'distribution'

it.from mediaClassesDir, "$buildDir/resources/media"
it.into stagePath

it.dependsOn(cleanModDistributionStage)
it.mustRunAfter('processMediaResources', 'mediaClasses')
}

distributions {
mod.contents {
it.from stagePath
it.into 'media'
}
}
installModDist {
def parentDir = destinationDir.parentFile.toPath()
destinationDir = parentDir.resolve(rootProject.name).toFile()
}
[ 'modDistTar', 'modDistZip' ].forEach({
def task = tasks.named(it).get() as AbstractArchiveTask
task.archiveBaseName.set(rootProject.name)
task.mustRunAfter('stageModDistribution')
})
import java.nio.file.Files
import java.nio.file.Paths

// changelog.gradle
apply from: 'https://git.io/JqJiC'

def getPathsRelativeToModule(moduleName, srcDirSet) {

def module = rootDir.toPath().resolve(moduleName)
def map = new HashMap<String, String>()

def srcDirs = srcDirSet.srcDirs.stream().withCloseable {
it.filter({ f -> f.exists() }).collect()
}
//@formatter:off
for (File srcDir : (srcDirs as List<File>)) {
Files.walk(srcDir.toPath()).withCloseable
{
def paths = it.filter({ Files.isRegularFile(it as java.nio.file.Path) }).collect()
for (java.nio.file.Path path : (paths as List<java.nio.file.Path>)) {
def srcDirPath = srcDir.toPath()
def relativePath = srcDirPath.relativize(path)
def srcDirName = module.relativize(srcDirPath)
map.put(relativePath.toString(), srcDirName.toString())
}
}
}//@formatter:on
return map
}

static def getRelativeCopyPath(fcd, relativePathMap) {

def path = relativePathMap.get(Paths.get(fcd.path).toString())
if (path != null) {
return fcd.relativePath.prepend(path)
}
else throw new Exception("Unable to relativize copy path: $fcd.path")
}

def mediaClassesDir = "$buildDir/classes/lua/media"
task mediaClasses(type: Copy, overwrite: true) {

into mediaClassesDir
from(sourceSets.media.java.srcDirs) {
def mSources = getPathsRelativeToModule('media', sourceSets.media.java)
eachFile {
def fcd = it as FileCopyDetails
fcd.setRelativePath(getRelativeCopyPath(fcd, mSources))
}
}
includeEmptyDirs = false
}

processMediaResources {

includeEmptyDirs = false
def mResources = getPathsRelativeToModule('media', sourceSets.media.resources)
eachFile {
def fcd = it as FileCopyDetails
fcd.setRelativePath(getRelativeCopyPath(fcd, mResources))
}
}

def stagePath = "$buildDir/tmp/distribution/stage"
task cleanModDistributionStage(type: Delete) {

description 'Clean distribution stage directory.'
group 'distribution'

it.onlyIf {
file(stagePath).exists()
}
delete(stagePath)
}
tasks.register('stageModDistribution', Copy.class) {

it.description 'Copy mod distribution files to stage directory.'
it.group 'distribution'

it.from mediaClassesDir, "$buildDir/resources/media"
it.into stagePath

it.dependsOn(cleanModDistributionStage)
it.mustRunAfter('processMediaResources', 'mediaClasses')
}

distributions {
mod.contents {
it.from stagePath
it.into 'media'
}
}
installModDist {
def parentDir = destinationDir.parentFile.toPath()
destinationDir = parentDir.resolve(rootProject.name).toFile()
}
['modDistTar', 'modDistZip'].forEach({
def task = tasks.named(it).get() as AbstractArchiveTask
task.archiveBaseName.set(rootProject.name)
task.mustRunAfter('stageModDistribution')
})
assembleModDist.dependsOn('processMediaResources', 'mediaClasses', 'stageModDistribution')
Loading

0 comments on commit 2791ac8

Please sign in to comment.