From 7cb7fd2137f2539821d860bab68666512523000d Mon Sep 17 00:00:00 2001 From: Matthew Cain Date: Fri, 2 Apr 2021 19:07:46 +0200 Subject: [PATCH 1/4] Fix incorrect search scope names Resolves: #32 --- setup.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.gradle b/setup.gradle index bbd83b9..cb6ba06 100644 --- a/setup.gradle +++ b/setup.gradle @@ -109,7 +109,7 @@ if (propertiesFile.exists()) // path to Project Zomboid installation directory registerLocalProjectProperty('gameDir', Path.class, 'PZ_DIR_PATH', true) - // path to Project Zomboid installation directory + // path to IntelliJ IDEA installation directory registerLocalProjectProperty('ideaHome', Path.class, 'IDEA_HOME', false) // Github repository token used to generate changelog @@ -182,7 +182,7 @@ tasks.register('createModSearchScopes') { ] def modMediaScope = [ '', - "", + "", '' ] it.doLast { From f3b671b96044fd5feef3f527632136df50071f9a Mon Sep 17 00:00:00 2001 From: Matthew Cain Date: Fri, 9 Apr 2021 08:24:33 +0200 Subject: [PATCH 2/4] Add option to decompile single classes Resolves: #33 --- zomboid.gradle | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/zomboid.gradle b/zomboid.gradle index 341b6b0..c7edd40 100644 --- a/zomboid.gradle +++ b/zomboid.gradle @@ -1,3 +1,5 @@ +import java.nio.file.Paths + // directory containing Project Zomboid classes project.ext.zomboidClassesDir = file("$buildDir/classes/zomboid").absoluteFile @@ -42,8 +44,10 @@ dependencies { * Decompile game classes with FernFlower using default IDEA settings. * Default task behaviour is to decompile all class files found in game root directory. * - * This can be changed by defining specific file to decompile with project property 'src'. - * example: gradle decompileZomboid -Psrc="" + * This can be changed by defining specific files to decompile with project property 'decompileFiles'. + * Each specified file path has to be a package path relative to destination root directory. + * When specifying multiple file paths remember to separate them with comma delimiter. + * example: gradle decompileZomboid -PdecompileFiles=zombie/FileGuidPair.class,zombie/GameTime.class */ tasks.register('decompileZomboid', JavaExec.class) { @@ -70,7 +74,18 @@ tasks.register('decompileZomboid', JavaExec.class) { // decompiler will throw error if destination dir doesn't exist zomboidSourcesDir.mkdirs() - it.args params + zomboidClassesDir.path + zomboidSourcesDir.path + String zomboidClassesDirPath = zomboidClassesDir.path; + List decompileTargets = new ArrayList<>() + + // handle compiling specified individual classes + if (project.ext.has('decompileFiles')) + { + (project.ext.get('decompileFiles') as String).split(',').each { + decompileTargets.add(Paths.get(zomboidClassesDirPath, it).toString()) + } + } + else decompileTargets.add(zomboidClassesDirPath) + it.args params + decompileTargets + zomboidSourcesDir.path it.dependsOn(zomboidClasses) } From 921a3a49cd2230a4bf322cdc445e2839c3f410b4 Mon Sep 17 00:00:00 2001 From: Matthew Cain Date: Fri, 9 Apr 2021 08:48:38 +0200 Subject: [PATCH 3/4] Do major code formatting --- build.gradle | 63 ++++---- dist/distribution.gradle | 203 +++++++++++++------------ distribution.gradle | 165 +++++++++++---------- mod.gradle | 259 ++++++++++++++++---------------- setup.gradle | 309 +++++++++++++++++++-------------------- zdoc.gradle | 270 +++++++++++++++++----------------- zomboid.gradle | 49 +++---- 7 files changed, 652 insertions(+), 666 deletions(-) diff --git a/build.gradle b/build.gradle index 96f8915..778388b 100644 --- a/build.gradle +++ b/build.gradle @@ -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 sourcesList = new HashSet<>(['media/lua']) - Set resourcesList = new HashSet<>() - Set excludeResources = new HashSet<>([ - 'media/lua', 'media/luaexamples', - 'media/newuitests', 'media/launcher', - ]) - def gameDirPath = gameDir as java.nio.file.Path - //@formatter:off + Set sourcesList = new HashSet<>(['media/lua']) + Set resourcesList = new HashSet<>() + Set 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) @@ -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' } diff --git a/dist/distribution.gradle b/dist/distribution.gradle index ed3b78c..c160966 100644 --- a/dist/distribution.gradle +++ b/dist/distribution.gradle @@ -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() - - def srcDirs = srcDirSet.srcDirs.stream().withCloseable { - it.filter({ f -> f.exists() }).collect() - } - for (File srcDir : (srcDirs as List)) - { - 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)) - { - 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() + + def srcDirs = srcDirSet.srcDirs.stream().withCloseable { + it.filter({ f -> f.exists() }).collect() + } + //@formatter:off + for (File srcDir : (srcDirs as List)) { + 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)) { + 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') \ No newline at end of file diff --git a/distribution.gradle b/distribution.gradle index 6f6c8e0..c3aeff1 100644 --- a/distribution.gradle +++ b/distribution.gradle @@ -1,83 +1,82 @@ -import org.gradle.util.GFileUtils - -apply from: 'dist/distribution.gradle' - -def stagePath = file("stage").toPath() -task cleanDistributionStage(type: Delete) { - - description 'Clean distribution stage directory.' - group 'distribution' - - it.onlyIf { - file(stagePath).exists() - } - delete(stagePath) -} -def docsList = [ 'README.md', 'LICENSE.txt', 'CHANGELOG.md' ] -tasks.register('stageDistribution', Copy.class) { - - it.description 'Copy distribution files to stage directory.' - it.group 'distribution' - - it.from projectDir - it.into stagePath - - // files that need to be excluded - it.exclude '**/stage/', '/.gitignore', '.gitignored', 'distribution.sh', 'distribution.gradle', - '.idea/runConfigurations/distribution.xml', 'mod.info', '.idea/scopes/mod_*' - - // dirs that are already excluded but we don't want to spend time on staging - it.exclude '/dist/**', '.gradle/**', 'buildSrc/.gradle/**', '/build/**', - 'buildSrc/build/**', '/lib/**', '/media/**', '/logs/**' - - // include project documentation - it.into('docs/zmod') { - it.from projectDir - it.include docsList + 'images/*' - } - // do additional copy actions we cannot do with this Copy task - it.doLast { - file('dist').listFiles().each { - /* - * copy additional distribution files manually because files - * excluded by task filters cannot be copied with Copy task - */ - if (it.directory) { - GFileUtils.copyDirectory(it, stagePath.resolve(it.getName()).toFile() as File) - } - else GFileUtils.copyFile(it, stagePath.resolve(it.getName()).toFile() as File) - } - // remove duplicate docs in root directory - docsList.forEach({ - GFileUtils.deleteQuietly(stagePath.resolve(it).toFile()) - }) - } - it.dependsOn(cleanDistributionStage) -} - -tasks.register('pruneDistributionStage', Delete.class) { - - it.description 'Selectively delete files from distribution stage.' - it.group 'distribution' - - // duplicate documentation directory - it.delete './stage/images' - - def gitIgnored = file('.gitignored') - if (file(stagePath).exists() && gitIgnored.exists()) - { - def ignoredFiles = GFileUtils.readFile(gitIgnored).split('\r|\n|\r\n') - ignoredFiles.each { s -> - File ignoredFile = file(s) - if (ignoredFile.toPath().toAbsolutePath().startsWith(stagePath.toAbsolutePath())) { - it.delete(ignoredFile) - logger.quiet("Deleting ignored file ${s}") - } - } - } -} - -distributions.main.contents { - it.from stagePath - it.includeEmptyDirs false -} +import org.gradle.util.GFileUtils + +apply from: 'dist/distribution.gradle' + +def stagePath = file("stage").toPath() +task cleanDistributionStage(type: Delete) { + + description 'Clean distribution stage directory.' + group 'distribution' + + it.onlyIf { + file(stagePath).exists() + } + delete(stagePath) +} +def docsList = ['README.md', 'LICENSE.txt', 'CHANGELOG.md'] +tasks.register('stageDistribution', Copy.class) { + + it.description 'Copy distribution files to stage directory.' + it.group 'distribution' + + it.from projectDir + it.into stagePath + + // files that need to be excluded + it.exclude '**/stage/', '/.gitignore', '.gitignored', 'distribution.sh', 'distribution.gradle', + '.idea/runConfigurations/distribution.xml', 'mod.info', '.idea/scopes/mod_*' + + // dirs that are already excluded but we don't want to spend time on staging + it.exclude '/dist/**', '.gradle/**', 'buildSrc/.gradle/**', '/build/**', + 'buildSrc/build/**', '/lib/**', '/media/**', '/logs/**' + + // include project documentation + it.into('docs/zmod') { + it.from projectDir + it.include docsList + 'images/*' + } + // do additional copy actions we cannot do with this Copy task + it.doLast { + file('dist').listFiles().each { + /* + * copy additional distribution files manually because files + * excluded by task filters cannot be copied with Copy task + */ + if (it.directory) { + GFileUtils.copyDirectory(it, stagePath.resolve(it.getName()).toFile() as File) + } + else GFileUtils.copyFile(it, stagePath.resolve(it.getName()).toFile() as File) + } + // remove duplicate docs in root directory + docsList.forEach({ + GFileUtils.deleteQuietly(stagePath.resolve(it).toFile()) + }) + } + it.dependsOn(cleanDistributionStage) +} + +tasks.register('pruneDistributionStage', Delete.class) { + + it.description 'Selectively delete files from distribution stage.' + it.group 'distribution' + + // duplicate documentation directory + it.delete './stage/images' + + def gitIgnored = file('.gitignored') + if (file(stagePath).exists() && gitIgnored.exists()) { + def ignoredFiles = GFileUtils.readFile(gitIgnored).split('\r|\n|\r\n') + ignoredFiles.each { s -> + File ignoredFile = file(s) + if (ignoredFile.toPath().toAbsolutePath().startsWith(stagePath.toAbsolutePath())) { + it.delete(ignoredFile) + logger.quiet("Deleting ignored file ${s}") + } + } + } +} + +distributions.main.contents { + it.from stagePath + it.includeEmptyDirs false +} diff --git a/mod.gradle b/mod.gradle index 5abb2c2..083891e 100644 --- a/mod.gradle +++ b/mod.gradle @@ -11,16 +11,16 @@ project.ext.semVersion = Pattern.compile('\\d+\\.\\d+\\.\\d+') void validateModInfo() { - // map of all available mod properties - def propertiesMap = [ - 'url': false, - 'description': false, - 'name': true, - 'modversion': true - //game version is checked in zdoc.gradle - //mod.pzversion: String.class, - ] - //@formatter:off + // map of all available mod properties + def propertiesMap = [ + 'url' : false, + 'description': false, + 'name' : true, + 'modversion' : true + //game version is checked in zdoc.gradle + //mod.pzversion: String.class, + ] + //@formatter:off propertiesMap.entrySet().forEach( { def key = it.key @@ -56,100 +56,97 @@ void validateModInfo() { def saveModInfo = tasks.register('saveModInfo') { - it.description 'Save mod metadata to file.' - it.group 'mod' - - it.doLast { - // validate properties before saving them - validateModInfo() - - // game version is not set via user input - def sGameVersion = (project.ext.get('mod.pzversion') as String).replaceAll('\\r\\n?', '') - modInfoProperties.setProperty('pzversion', sGameVersion) - - // trim all mod property values - modInfoProperties.entrySet().forEach({ - modInfoProperties.setProperty(it.key as String, (it.value as String).trim()) - }) - // ensure that mod.info file exists before writing to it - if (!modInfoFile.exists()) - { - if (!modInfoFile.createNewFile()) { - throw new IOException('Unable to create mod.info file') - } - } - // save mod properties to mod.info file - modInfoFile.withWriter('utf-8') { writer -> - def modUrl = modInfoProperties.get('url') as String - Arrays.asList([ - "name=${modInfoProperties.get('name')}", - "poster=poster.png", - "description=${modInfoProperties.get('description')}", - "id=$rootProject.name", - // remove backslash used to escape key/value separators - "url=${modUrl != null ? modUrl.replaceAll('\\\\\\\\:', ':') : ''}", - "modversion=" + modInfoProperties.get('modversion'), - "pzversion=${modInfoProperties.get('pzversion')}", - ] as String[]).forEach({ l -> writer.writeLine(l) }) - } - } - it.dependsOn(tasks.named('zomboidVersion'), loadModInfo) + it.description 'Save mod metadata to file.' + it.group 'mod' + + it.doLast { + // validate properties before saving them + validateModInfo() + + // game version is not set via user input + def sGameVersion = (project.ext.get('mod.pzversion') as String).replaceAll('\\r\\n?', '') + modInfoProperties.setProperty('pzversion', sGameVersion) + + // trim all mod property values + modInfoProperties.entrySet().forEach({ + modInfoProperties.setProperty(it.key as String, (it.value as String).trim()) + }) + // ensure that mod.info file exists before writing to it + if (!modInfoFile.exists()) { + if (!modInfoFile.createNewFile()) { + throw new IOException('Unable to create mod.info file') + } + } + // save mod properties to mod.info file + modInfoFile.withWriter('utf-8') { writer -> + def modUrl = modInfoProperties.get('url') as String + Arrays.asList([ + "name=${modInfoProperties.get('name')}", + "poster=poster.png", + "description=${modInfoProperties.get('description')}", + "id=$rootProject.name", + // remove backslash used to escape key/value separators + "url=${modUrl != null ? modUrl.replaceAll('\\\\\\\\:', ':') : ''}", + "modversion=" + modInfoProperties.get('modversion'), + "pzversion=${modInfoProperties.get('pzversion')}", + ] as String[]).forEach({ l -> writer.writeLine(l) }) + } + } + it.dependsOn(tasks.named('zomboidVersion'), loadModInfo) } tasks.register('initModInfo') { - it.description 'Initialize mod metadata information.' - it.group 'mod' + it.description 'Initialize mod metadata information.' + it.group 'mod' - it.onlyIf { - !modInfoFile.exists() - } - it.doLast { - ant.input(message: 'Enter mod name: \n', addproperty: 'mod.name') - modInfoProperties.setProperty('name', ant.properties.get('mod.name') as String) + it.onlyIf { + !modInfoFile.exists() + } + it.doLast { + ant.input(message: 'Enter mod name: \n', addproperty: 'mod.name') + modInfoProperties.setProperty('name', ant.properties.get('mod.name') as String) - ant.input(message: 'Enter mod description: \n', addproperty: 'mod.description') - modInfoProperties.setProperty('description', ant.properties.get('mod.description') as String) + ant.input(message: 'Enter mod description: \n', addproperty: 'mod.description') + modInfoProperties.setProperty('description', ant.properties.get('mod.description') as String) - ant.input(message: 'Enter github repository URL: \n', addproperty: 'mod.url') - modInfoProperties.setProperty('url', ant.properties.get('mod.url') as String) + ant.input(message: 'Enter github repository URL: \n', addproperty: 'mod.url') + modInfoProperties.setProperty('url', ant.properties.get('mod.url') as String) - // starting mod version is 0.1.0 (sem-ver) - modInfoProperties.setProperty('modversion', '0.1.0') - } - it.finalizedBy(saveModInfo) + // starting mod version is 0.1.0 (sem-ver) + modInfoProperties.setProperty('modversion', '0.1.0') + } + it.finalizedBy(saveModInfo) } task loadModInfo { - description 'Load mod metadata information.' - group 'mod' - - if (modInfoFile.exists()) - { - // load properties from properties file - modInfoFile.withInputStream { - modInfoProperties.load(it) - } - // load mod properties as project extra properties - modInfoProperties.entrySet().forEach({ - logger.info("Loading property ${it.key}:${it.value}") - project.ext.set("mod.${(it.key as String)}", it.value as String) - }) - def sUrl = modInfoProperties.getProperty('url') - if (sUrl && !sUrl.isBlank()) - { - def url = new URL(sUrl) - def urlPath = url.path.startsWith('/') ? url.path.substring(1) : url.path - def pathElements = urlPath.split('/') - if (pathElements.length != 2) { - throw new InvalidUserDataException("Unexpected mod url format '${urlPath}'") - } - project.ext.set('repo.owner', pathElements[0]) - project.ext.set('repo.name', pathElements[1]) - } - } - else logger.warn('WARN: Unable to find mod.info file') + description 'Load mod metadata information.' + group 'mod' + + if (modInfoFile.exists()) { + // load properties from properties file + modInfoFile.withInputStream { + modInfoProperties.load(it) + } + // load mod properties as project extra properties + modInfoProperties.entrySet().forEach({ + logger.info("Loading property ${it.key}:${it.value}") + project.ext.set("mod.${(it.key as String)}", it.value as String) + }) + def sUrl = modInfoProperties.getProperty('url') + if (sUrl && !sUrl.isBlank()) { + def url = new URL(sUrl) + def urlPath = url.path.startsWith('/') ? url.path.substring(1) : url.path + def pathElements = urlPath.split('/') + if (pathElements.length != 2) { + throw new InvalidUserDataException("Unexpected mod url format '${urlPath}'") + } + project.ext.set('repo.owner', pathElements[0]) + project.ext.set('repo.name', pathElements[1]) + } + } + else logger.warn('WARN: Unable to find mod.info file') } /** @@ -158,56 +155,56 @@ task loadModInfo { */ String getDisplayProperty(String name) { - String property = project.ext.get(name) - return property.empty ? '' : property + String property = project.ext.get(name) + return property.empty ? '' : property } task showModInfo { - description 'Print mod metadata information.' - group 'mod' - - onlyIf { - modInfoFile.exists() - } - doLast { - [ 'mod.pzversion', 'mod.name' ].forEach({ - if (!project.ext.has(it)) { - throw new InvalidUserDataException("Missing mod property ${it}, " + - "please (re)initialize mod properties.") - } - }) - logger.lifecycle("This is a mod for Project Zomboid (${getDisplayProperty('mod.pzversion')})") - logger.lifecycle('------------------------------------------------') - logger.lifecycle("Name: ${getDisplayProperty('mod.name')}") - logger.lifecycle("Description: ${getDisplayProperty('mod.description')}") - logger.lifecycle("URL: ${getDisplayProperty('mod.url')}") - logger.lifecycle("ID: ${rootProject.name}") - logger.lifecycle("Version: ${project.version}") - } + description 'Print mod metadata information.' + group 'mod' + + onlyIf { + modInfoFile.exists() + } + doLast { + ['mod.pzversion', 'mod.name'].forEach({ + if (!project.ext.has(it)) { + throw new InvalidUserDataException("Missing mod property ${it}, " + + "please (re)initialize mod properties.") + } + }) + logger.lifecycle("This is a mod for Project Zomboid (${getDisplayProperty('mod.pzversion')})") + logger.lifecycle('------------------------------------------------') + logger.lifecycle("Name: ${getDisplayProperty('mod.name')}") + logger.lifecycle("Description: ${getDisplayProperty('mod.description')}") + logger.lifecycle("URL: ${getDisplayProperty('mod.url')}") + logger.lifecycle("ID: ${rootProject.name}") + logger.lifecycle("Version: ${project.version}") + } } task createModStructure { - description 'Create default mod directory structure.' - group 'mod' - - doLast { - def media = sourceSets.named('media').get() - media.java.getSrcDirs().forEach({ - project.mkdir(it) - }) - media.resources.srcDirs.forEach({ - project.mkdir(it) - }) - } + description 'Create default mod directory structure.' + group 'mod' + + doLast { + def media = sourceSets.named('media').get() + media.java.getSrcDirs().forEach({ + project.mkdir(it) + }) + media.resources.srcDirs.forEach({ + project.mkdir(it) + }) + } } tasks.register('applyModTemplate', Copy.class) { - it.description 'Apply Project Zomboid mod template.' - it.group 'mod' + it.description 'Apply Project Zomboid mod template.' + it.group 'mod' - it.into projectDir - it.from 'docs/template' + it.into projectDir + it.from 'docs/template' } diff --git a/setup.gradle b/setup.gradle index cb6ba06..35c8e5e 100644 --- a/setup.gradle +++ b/setup.gradle @@ -1,19 +1,19 @@ import org.gradle.util.GFileUtils -import java.nio.file.Paths import java.nio.file.Path +import java.nio.file.Paths // write operating system platform name to project property switch (org.gradle.internal.os.OperatingSystem.current()) { - case org.gradle.internal.os.OperatingSystem.LINUX: - project.ext.osName = "Linux" - break - case org.gradle.internal.os.OperatingSystem.MAC_OS: - project.ext.osName = "macOS" - break - case org.gradle.internal.os.OperatingSystem.WINDOWS: - project.ext.osName = "Windows" - break + case org.gradle.internal.os.OperatingSystem.LINUX: + project.ext.osName = "Linux" + break + case org.gradle.internal.os.OperatingSystem.MAC_OS: + project.ext.osName = "macOS" + break + case org.gradle.internal.os.OperatingSystem.WINDOWS: + project.ext.osName = "Windows" + break } // This is where local project properties are stored def propertiesFile = rootDir.toPath().resolve('local.properties').toFile() @@ -31,29 +31,27 @@ project.ext.localProperties = new Properties() */ def T getLocalProjectProperty(String name, Class type, String env, boolean required, T defaultValue) { - Properties localProperties = project.ext.localProperties - String property = localProperties.getProperty(name, '') - if (property.isEmpty()) - { - if (!System.hasProperty(name)) - { - // when env parameter is not defined search for env variable with property name - def sEnv = env != null && !env.isEmpty() ? env : name - def envVariable = providers.environmentVariable(sEnv).forUseAtConfigurationTime() - if (envVariable.present) { - property = envVariable.get() - } - else if (required && defaultValue == null) { - throw new InvalidUserDataException("Unable to find local project property ${name}") - } - else return defaultValue - } - else property = System.getProperty(name) - } - if (type == Path) { - return Paths.get(property) as T - } - else return property as T + Properties localProperties = project.ext.localProperties + String property = localProperties.getProperty(name, '') + if (property.isEmpty()) { + if (!System.hasProperty(name)) { + // when env parameter is not defined search for env variable with property name + def sEnv = env != null && !env.isEmpty() ? env : name + def envVariable = providers.environmentVariable(sEnv).forUseAtConfigurationTime() + if (envVariable.present) { + property = envVariable.get() + } + else if (required && defaultValue == null) { + throw new InvalidUserDataException("Unable to find local project property ${name}") + } + else return defaultValue + } + else property = System.getProperty(name) + } + if (type == Path) { + return Paths.get(property) as T + } + else return property as T } /** * Initialize and register project property from {@code local.properties} file. @@ -65,55 +63,54 @@ def T getLocalProjectProperty(String name, Class type, String env, boolea * @return found project property or {@code null} if no property found. */ def registerLocalProjectProperty(String name, Class type, String env, boolean required) { - project.ext.set(name, getLocalProjectProperty(name, type, env, required, null)) + project.ext.set(name, getLocalProjectProperty(name, type, env, required, null)) } tasks.register('initLocalProperties') { - it.description 'Initialize local project properties.' - it.group 'build setup' - - it.onlyIf { - !propertiesFile.exists() - } - it.doLast { - ArrayList content = new ArrayList() - content.add('# This file contains local properties used to configure project build.') - content.add('# Note: paths need to be Unix-style where segments need to be separated with forward-slashes (/)') - content.add('# this is for compatibility and stability purposes as backslashes don\'t play well.\n') - - content.add('# Path to game installation directory') - ant.input(message: 'Enter path to game installation directory: ', addproperty: 'gameDir') - content.add("gameDir=${ant.properties.gameDir.toString().replace('\\', '/')}") - - content.add('\n# Path to IntelliJ IDEA installation directory') - ant.input(message: '\nEnter path to IntelliJ IDEA installation directory: ', addproperty: 'ideaHome') - content.add("ideaHome=${ant.properties.ideaHome.toString().replace('\\', '/')}") - - logger.info('Creating local.properties file...') - if (!propertiesFile.createNewFile()) { - throw new IOException('Unable to create local.properties file') - } - // noinspection GroovyAssignabilityCheck - GFileUtils.writeFile(content.join(System.lineSeparator()), propertiesFile) - } + it.description 'Initialize local project properties.' + it.group 'build setup' + + it.onlyIf { + !propertiesFile.exists() + } + it.doLast { + ArrayList content = new ArrayList() + content.add('# This file contains local properties used to configure project build.') + content.add('# Note: paths need to be Unix-style where segments need to be separated with forward-slashes (/)') + content.add('# this is for compatibility and stability purposes as backslashes don\'t play well.\n') + + content.add('# Path to game installation directory') + ant.input(message: 'Enter path to game installation directory: ', addproperty: 'gameDir') + content.add("gameDir=${ant.properties.gameDir.toString().replace('\\', '/')}") + + content.add('\n# Path to IntelliJ IDEA installation directory') + ant.input(message: '\nEnter path to IntelliJ IDEA installation directory: ', addproperty: 'ideaHome') + content.add("ideaHome=${ant.properties.ideaHome.toString().replace('\\', '/')}") + + logger.info('Creating local.properties file...') + if (!propertiesFile.createNewFile()) { + throw new IOException('Unable to create local.properties file') + } + // noinspection GroovyAssignabilityCheck + GFileUtils.writeFile(content.join(System.lineSeparator()), propertiesFile) + } } // load and register all local properties -if (propertiesFile.exists()) -{ - // load properties from properties file - logger.info('Loading local properties...') - propertiesFile.withInputStream { - localProperties.load(it) - } - // path to Project Zomboid installation directory - registerLocalProjectProperty('gameDir', Path.class, 'PZ_DIR_PATH', true) - - // path to IntelliJ IDEA installation directory - registerLocalProjectProperty('ideaHome', Path.class, 'IDEA_HOME', false) - - // Github repository token used to generate changelog - registerLocalProjectProperty('cg.token', String.class, 'CHANGELOG_GITHUB_TOKEN', false) +if (propertiesFile.exists()) { + // load properties from properties file + logger.info('Loading local properties...') + propertiesFile.withInputStream { + localProperties.load(it) + } + // path to Project Zomboid installation directory + registerLocalProjectProperty('gameDir', Path.class, 'PZ_DIR_PATH', true) + + // path to IntelliJ IDEA installation directory + registerLocalProjectProperty('ideaHome', Path.class, 'IDEA_HOME', false) + + // Github repository token used to generate changelog + registerLocalProjectProperty('cg.token', String.class, 'CHANGELOG_GITHUB_TOKEN', false) } else logger.warn('WARN: Unable to find local.properties file') @@ -126,96 +123,96 @@ else logger.warn('WARN: Unable to find local.properties file') */ void createRunConfig(String name, boolean debug, boolean steam) { - def runConfigFormat = [ - '', - " ", - ' ', - '', - ] - // translate config name to filename (similar to what IDEA is doing) - def filename = name.replaceAll('\\s', '_').replaceAll('[^\\w_]', '').replaceAll("__", '_') - - // write xml configuration to file - file("./.idea/runConfigurations/${filename}.xml").withWriter { - runConfigFormat.each { l -> it.writeLine(l) } - } + def runConfigFormat = [ + '', + " ", + ' ', + '', + ] + // translate config name to filename (similar to what IDEA is doing) + def filename = name.replaceAll('\\s', '_').replaceAll('[^\\w_]', '').replaceAll("__", '_') + + // write xml configuration to file + file("./.idea/runConfigurations/${filename}.xml").withWriter { + runConfigFormat.each { l -> it.writeLine(l) } + } } tasks.register('createLaunchRunConfigs') { - it.description 'Create game launch run configurations.' - it.group 'build setup' - - it.onlyIf { - project.ext.has('gameDir') - } - it.doLast { - // debug configurations - createRunConfig('Debug Zomboid', true, true) - createRunConfig('Debug Zomboid (local)', true, false) - - // run configurations - createRunConfig('Run Zomboid', false, true) - createRunConfig('Run Zomboid (local)', false, false) - } + it.description 'Create game launch run configurations.' + it.group 'build setup' + + it.onlyIf { + project.ext.has('gameDir') + } + it.doLast { + // debug configurations + createRunConfig('Debug Zomboid', true, true) + createRunConfig('Debug Zomboid (local)', true, false) + + // run configurations + createRunConfig('Run Zomboid', false, true) + createRunConfig('Run Zomboid (local)', false, false) + } } tasks.register('createModSearchScopes') { - it.description 'Create IDEA search scopes for mod files.' - it.group 'build setup' - - def modLuaScope = [ - '', - "", - '' - ] - def modMediaScope = [ - '', - "", - '' - ] - it.doLast { - file('./.idea/scopes/mod_lua.xml').withWriter { - modLuaScope.each { l -> it.writeLine(l) } - } - file('./.idea/scopes/mod_media.xml').withWriter { - modMediaScope.each { l -> it.writeLine(l) } - } - } + it.description 'Create IDEA search scopes for mod files.' + it.group 'build setup' + + def modLuaScope = [ + '', + "", + '' + ] + def modMediaScope = [ + '', + "", + '' + ] + it.doLast { + file('./.idea/scopes/mod_lua.xml').withWriter { + modLuaScope.each { l -> it.writeLine(l) } + } + file('./.idea/scopes/mod_media.xml').withWriter { + modMediaScope.each { l -> it.writeLine(l) } + } + } } tasks.register('createDiscordIntegration') { - it.description 'Show IDEA project in Discord via rich presence.' - it.group 'build setup' - - it.doLast { - def projectName = project.findProperty('mod.name') ?: 'PZ Mod' - def projectDescription = project.findProperty('mod.description') ?: 'Project Zomboid mod.' - def discordXmlFormat = [ - '', - '', - ' ', - ' ', - '', - ] - file('./.idea/discord.xml').withWriter { - discordXmlFormat.each { l -> it.writeLine(l) } - } - } + it.description 'Show IDEA project in Discord via rich presence.' + it.group 'build setup' + + it.doLast { + def projectName = project.findProperty('mod.name') ?: 'PZ Mod' + def projectDescription = project.findProperty('mod.description') ?: 'Project Zomboid mod.' + def discordXmlFormat = [ + '', + '', + ' ', + ' ', + '', + ] + file('./.idea/discord.xml').withWriter { + discordXmlFormat.each { l -> it.writeLine(l) } + } + } } \ No newline at end of file diff --git a/zdoc.gradle b/zdoc.gradle index 44a3863..980e91a 100644 --- a/zdoc.gradle +++ b/zdoc.gradle @@ -4,62 +4,62 @@ import java.nio.charset.StandardCharsets project.ext.zDocLuaDir = file("$buildDir/generated/sources/zdoc/").absoluteFile repositories { - // try to find dependencies locally first - mavenLocal() + // try to find dependencies locally first + mavenLocal() } configurations { - zomboidDoc.extendsFrom zomboidRuntimeOnly + zomboidDoc.extendsFrom zomboidRuntimeOnly } dependencies { - // https://search.maven.org/artifact/io.github.cocolabs/pz-zdoc - zomboidDoc 'io.github.cocolabs:pz-zdoc:3.+' - - // ZomboidDoc compiled Lua library - if (project.ext.has('mod.pzversion')) { - compileOnly files("lib/zdoc-lua-${project.ext.get('mod.pzversion')}" + '.jar') - } - else if (file('mod.info').exists()) { - logger.warn('WARN: Unable to find mod.pzversion property') - } - // Project Zomboid classes - zomboidDoc files(zomboidClassesDir) + // https://search.maven.org/artifact/io.github.cocolabs/pz-zdoc + zomboidDoc 'io.github.cocolabs:pz-zdoc:3.+' + + // ZomboidDoc compiled Lua library + if (project.ext.has('mod.pzversion')) { + compileOnly files("lib/zdoc-lua-${project.ext.get('mod.pzversion')}" + '.jar') + } + else if (file('mod.info').exists()) { + logger.warn('WARN: Unable to find mod.pzversion property') + } + // Project Zomboid classes + zomboidDoc files(zomboidClassesDir) } tasks.register('zomboidLuaJar', ZDocJar.class) { - it.archiveBaseName.set('zdoc-lua') - it.description 'Assembles a jar containing compiled Lua classes.' + it.archiveBaseName.set('zdoc-lua') + it.description 'Assembles a jar containing compiled Lua classes.' - it.from zDocLuaDir - it.destinationDir file('lib') + it.from zDocLuaDir + it.destinationDir file('lib') } tasks.register('zomboidVersion', JavaExec.class) { - it.description 'Read Project Zomboid game version.' - it.group 'zomboid' + it.description 'Read Project Zomboid game version.' + it.group 'zomboid' - it.main = 'io.cocolabs.pz.zdoc.Main' - it.classpath = configurations.zomboidDoc - it.args 'version' + it.main = 'io.cocolabs.pz.zdoc.Main' + it.classpath = configurations.zomboidDoc + it.args 'version' - OutputStream oStream = new ByteArrayOutputStream() - it.setStandardOutput(oStream) + OutputStream oStream = new ByteArrayOutputStream() + it.setStandardOutput(oStream) - it.doLast { - // get command output from stream - def versionText = oStream.toString(StandardCharsets.UTF_8.name()).split('\r\n|\r|\n') + it.doLast { + // get command output from stream + def versionText = oStream.toString(StandardCharsets.UTF_8.name()).split('\r\n|\r|\n') - // ZomboidDoc version - logger.lifecycle(versionText[0]) + // ZomboidDoc version + logger.lifecycle(versionText[0]) - // get version number and classifier (ex. 41.50-IWBUMS) - project.ext.set('mod.pzversion', versionText[1].substring(12).replaceAll(" ", "").trim()) - logger.lifecycle("game version ${project.ext.get('mod.pzversion')}") - } - it.dependsOn(tasks.getByName('zomboidClasses')) - it.finalizedBy(tasks.getByName('saveModInfo')) + // get version number and classifier (ex. 41.50-IWBUMS) + project.ext.set('mod.pzversion', versionText[1].substring(12).replaceAll(" ", "").trim()) + logger.lifecycle("game version ${project.ext.get('mod.pzversion')}") + } + it.dependsOn(tasks.getByName('zomboidClasses')) + it.finalizedBy(tasks.getByName('saveModInfo')) } /** @@ -68,11 +68,11 @@ tasks.register('zomboidVersion', JavaExec.class) { */ File getZDocVersionFile() { - def file = file('zdoc.version') - if (!file.exists() && !file.createNewFile()) { - throw new IOException("Unable to create zdoc.version file") - } - return file + def file = file('zdoc.version') + if (!file.exists() && !file.createNewFile()) { + throw new IOException("Unable to create zdoc.version file") + } + return file } /** @@ -85,22 +85,21 @@ File getZDocVersionFile() { */ static int compareSemanticVersions(Integer[] versionA, Integer[] versionB) { - if (versionA.length != 3 || versionB.length != 3) { - throw new GradleException("Not valid semantic versions [${versionA}, ${versionB}]") - } - for (int i = 0; i < 3; i++) - { - // first version is higher then second - if (versionA[i] > versionB[i]) { - return 1 - } - // second version is higher then first - else if (versionA[i] < versionB[i]) { - return -1 - } - } - // semantic versions are equal - return 0 + if (versionA.length != 3 || versionB.length != 3) { + throw new GradleException("Not valid semantic versions [${versionA}, ${versionB}]") + } + for (int i = 0; i < 3; i++) { + // first version is higher then second + if (versionA[i] > versionB[i]) { + return 1 + } + // second version is higher then first + else if (versionA[i] < versionB[i]) { + return -1 + } + } + // semantic versions are equal + return 0 } /** @@ -109,23 +108,22 @@ static int compareSemanticVersions(Integer[] versionA, Integer[] versionB) { @SuppressWarnings('UnnecessaryQualifiedReference') Integer[] getZDocDependencyVersion() { - def pattern = java.util.regex.Pattern.compile('[\\w\\-]+(\\d+)\\.(\\d+)\\.(\\d+)') - def dependency = configurations.zomboidDoc.files.stream() - .filter({it.name.startsWith('pz-zdoc')}).findFirst() - if (!dependency.present) { - throw new RuntimeException('Unable to find ZomboidDoc dependency in configuration') - } - def filename = dependency.get().name - java.util.regex.Matcher matcher = pattern.matcher(filename) - if (matcher.find()) - { - def result = new Integer[3] - for (int i = 0; i < 3; i++) { - result[i] = Integer.valueOf(matcher.group(i + 1)) - } - return result - } - else throw new RuntimeException("Malformed zdoc dependency name ${filename}") + def pattern = java.util.regex.Pattern.compile('[\\w\\-]+(\\d+)\\.(\\d+)\\.(\\d+)') + def dependency = configurations.zomboidDoc.files.stream() + .filter({ it.name.startsWith('pz-zdoc') }).findFirst() + if (!dependency.present) { + throw new RuntimeException('Unable to find ZomboidDoc dependency in configuration') + } + def filename = dependency.get().name + java.util.regex.Matcher matcher = pattern.matcher(filename) + if (matcher.find()) { + def result = new Integer[3] + for (int i = 0; i < 3; i++) { + result[i] = Integer.valueOf(matcher.group(i + 1)) + } + return result + } + else throw new RuntimeException("Malformed zdoc dependency name ${filename}") } /** @@ -133,83 +131,81 @@ Integer[] getZDocDependencyVersion() { * * @param versionFile {@code file} to read the version information from. * @param currentVersion series of integers representing current {@code ZomboidDoc} version. - * @return last {@code ZomboidDoc} dependency version or {@code null} if no version found. + * @return last{@code ZomboidDoc} dependency version or {@code null} if no version found. */ Integer[] getZDocLastVersion(versionFile, currentVersion) { - def content = versionFile.readLines() - if (!content.empty) - { - String[] elements = content.get(0).split('\\.') - if (elements.length == 3) - { - Integer[] result = new Integer[elements.length] - for (int i = 0; i < elements.length; i++) { - result[i] = Integer.valueOf(elements[i]) - } - return result - } - else logger.warn("WARN: Malformed semantic version found '${elements}'") - } - versionFile.text = currentVersion.join('.') - return null + def content = versionFile.readLines() + if (!content.empty) { + String[] elements = content.get(0).split('\\.') + if (elements.length == 3) { + Integer[] result = new Integer[elements.length] + for (int i = 0; i < elements.length; i++) { + result[i] = Integer.valueOf(elements[i]) + } + return result + } + else logger.warn("WARN: Malformed semantic version found '${elements}'") + } + versionFile.text = currentVersion.join('.') + return null } def annotateZomboidLua = tasks.register('annotateZomboidLua', JavaExec.class) { - it.description 'Annotate vanilla Lua with EmmyLua.' - it.group 'zomboid' - - it.main = 'io.cocolabs.pz.zdoc.Main' - it.classpath = configurations.zomboidDoc - it.args('annotate', '-i', "${project.ext.gameDir}/media/lua", '-o', "$zDocLuaDir/media/lua") - it.dependsOn(tasks.getByName('zomboidClasses')) - it.doLast { - def versionFile = getZDocVersionFile() - versionFile.text = getZDocDependencyVersion().join('.') - } + it.description 'Annotate vanilla Lua with EmmyLua.' + it.group 'zomboid' + + it.main = 'io.cocolabs.pz.zdoc.Main' + it.classpath = configurations.zomboidDoc + it.args('annotate', '-i', "${project.ext.gameDir}/media/lua", '-o', "$zDocLuaDir/media/lua") + it.dependsOn(tasks.getByName('zomboidClasses')) + it.doLast { + def versionFile = getZDocVersionFile() + versionFile.text = getZDocDependencyVersion().join('.') + } } def compileZomboidLua = tasks.register('compileZomboidLua', JavaExec.class) { - it.description 'Compile Lua library from modding API.' - it.group 'zomboid' - - //noinspection GroovyAssignabilityCheck,GroovyAccessibility - it.javaLauncher = javaToolchains.launcherFor { - languageVersion = JavaLanguageVersion.of(8) - } - it.main = 'io.cocolabs.pz.zdoc.Main' - it.classpath = configurations.zomboidDoc - it.args('compile', '-i', "$gameDir", '-o', "$zDocLuaDir/media/lua/shared/Library") - it.dependsOn(tasks.getByName('zomboidClasses')) - it.shouldRunAfter(annotateZomboidLua) - it.doLast { - def versionFile = getZDocVersionFile() - versionFile.text = getZDocDependencyVersion().join('.') - } + it.description 'Compile Lua library from modding API.' + it.group 'zomboid' + + //noinspection GroovyAssignabilityCheck,GroovyAccessibility + it.javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(8) + } + it.main = 'io.cocolabs.pz.zdoc.Main' + it.classpath = configurations.zomboidDoc + it.args('compile', '-i', "$gameDir", '-o', "$zDocLuaDir/media/lua/shared/Library") + it.dependsOn(tasks.getByName('zomboidClasses')) + it.shouldRunAfter(annotateZomboidLua) + it.doLast { + def versionFile = getZDocVersionFile() + versionFile.text = getZDocDependencyVersion().join('.') + } } def updateZomboidLua = tasks.register('updateZomboidLua') { - it.description 'Run ZomboidDoc to update compiled Lua library.' - it.group 'zomboid' - - def versionFile = getZDocVersionFile() - def currentVersion = getZDocDependencyVersion() - def lastVersion = getZDocLastVersion(versionFile, currentVersion) - def compareResult = lastVersion != null ? compareSemanticVersions(lastVersion, currentVersion) : -1 - it.onlyIf { - compareResult == -1 - } - // current version is higher then last version - if (compareResult == -1) { - it.dependsOn(annotateZomboidLua, compileZomboidLua) - } - it.doLast { - // update zdoc.version data - versionFile.text = currentVersion.join('.') - } + it.description 'Run ZomboidDoc to update compiled Lua library.' + it.group 'zomboid' + + def versionFile = getZDocVersionFile() + def currentVersion = getZDocDependencyVersion() + def lastVersion = getZDocLastVersion(versionFile, currentVersion) + def compareResult = lastVersion != null ? compareSemanticVersions(lastVersion, currentVersion) : -1 + it.onlyIf { + compareResult == -1 + } + // current version is higher then last version + if (compareResult == -1) { + it.dependsOn(annotateZomboidLua, compileZomboidLua) + } + it.doLast { + // update zdoc.version data + versionFile.text = currentVersion.join('.') + } } classes.dependsOn(updateZomboidLua) diff --git a/zomboid.gradle b/zomboid.gradle index c7edd40..2eb5443 100644 --- a/zomboid.gradle +++ b/zomboid.gradle @@ -24,8 +24,8 @@ def zomboidClasses = tasks.register('zomboidClasses', Sync.class) { classes.dependsOn(zomboidClasses) configurations { - runtimeOnly.extendsFrom zomboidRuntimeOnly - implementation.extendsFrom zomboidImplementation + runtimeOnly.extendsFrom zomboidRuntimeOnly + implementation.extendsFrom zomboidImplementation } dependencies { // Project Zomboid libraries @@ -54,9 +54,9 @@ tasks.register('decompileZomboid', JavaExec.class) { it.description 'Decompile Project Zomboid classes.' it.group 'zomboid' - if (project.ext.ideaHome == null) { - throw new InvalidUserDataException('Local property \"ideaHome\" is not defined') - } + if (project.ext.ideaHome == null) { + throw new InvalidUserDataException('Local property \"ideaHome\" is not defined') + } it.onlyIf { def files = zomboidClassesDir.exists() ? zomboidClassesDir.listFiles() : null return files != null && files.size() > 0 @@ -65,38 +65,37 @@ tasks.register('decompileZomboid', JavaExec.class) { it.javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(11) } - it.classpath files("$ideaHome/plugins/java-decompiler/lib/java-decompiler.jar") - it.main 'org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler' + it.classpath files("$ideaHome/plugins/java-decompiler/lib/java-decompiler.jar") + it.main 'org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler' - // default parameters used by IDEA compiler - def params = ['-hdc=0', '-dgs=1', '-rsy=1', '-rbr=1', '-lit=1', '-nls=1', '-mpm=60'] + // default parameters used by IDEA compiler + def params = ['-hdc=0', '-dgs=1', '-rsy=1', '-rbr=1', '-lit=1', '-nls=1', '-mpm=60'] - // decompiler will throw error if destination dir doesn't exist - zomboidSourcesDir.mkdirs() + // decompiler will throw error if destination dir doesn't exist + zomboidSourcesDir.mkdirs() String zomboidClassesDirPath = zomboidClassesDir.path; List decompileTargets = new ArrayList<>() // handle compiling specified individual classes - if (project.ext.has('decompileFiles')) - { + if (project.ext.has('decompileFiles')) { (project.ext.get('decompileFiles') as String).split(',').each { decompileTargets.add(Paths.get(zomboidClassesDirPath, it).toString()) } } else decompileTargets.add(zomboidClassesDirPath) - it.args params + decompileTargets + zomboidSourcesDir.path - it.dependsOn(zomboidClasses) + it.args params + decompileTargets + zomboidSourcesDir.path + it.dependsOn(zomboidClasses) } tasks.register('zomboidJar', ZDocJar.class) { - it.description 'Assembles a jar archive containing game classes.' - it.includeEmptyDirs = false + it.description 'Assembles a jar archive containing game classes.' + it.includeEmptyDirs = false - it.archiveBaseName.set('zomboid') - it.from zomboidClassesDir - it.destinationDir file('lib') + it.archiveBaseName.set('zomboid') + it.from zomboidClassesDir + it.destinationDir file('lib') it.onlyIf { def files = zomboidClassesDir.exists() ? zomboidClassesDir.listFiles() : null return files != null && files.size() > 0 @@ -106,12 +105,12 @@ tasks.register('zomboidJar', ZDocJar.class) { tasks.register("zomboidSourcesJar", ZDocJar.class) { - it.description 'Assembles a jar containing decompiled game sources.' - it.archiveBaseName.set('zomboid') - it.classifier 'sources' + it.description 'Assembles a jar containing decompiled game sources.' + it.archiveBaseName.set('zomboid') + it.classifier 'sources' - it.from zomboidSourcesDir - it.destinationDir file('lib') + it.from zomboidSourcesDir + it.destinationDir file('lib') it.onlyIf { def files = zomboidSourcesDir.exists() ? zomboidSourcesDir.listFiles() : null return files != null && files.size() > 0 From 361b35a354346d862ce931a9a918c8fd2c4abb5e Mon Sep 17 00:00:00 2001 From: Matthew Cain Date: Sun, 11 Apr 2021 10:53:34 +0200 Subject: [PATCH 4/4] Bump project version number --- mod.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod.info b/mod.info index 47f6720..5a2fcad 100644 --- a/mod.info +++ b/mod.info @@ -3,5 +3,5 @@ poster=poster.png description=Compact mod development environment. id=pz-zmod url=https://github.com/cocolabs/pz-zmod -modversion=2.3.0 +modversion=2.4.0 pzversion=41.50-IWBUMS