Skip to content

Commit

Permalink
Merge pull request MovingBlocks#634 from Cervator/groovyRefresh
Browse files Browse the repository at this point in the history
feat: upgrade the groovyw system to be closer in sync with Terasology
  • Loading branch information
BenjaminAmos authored Nov 4, 2021
2 parents b1afc79 + 31d4621 commit 30700e9
Show file tree
Hide file tree
Showing 8 changed files with 508 additions and 161 deletions.
292 changes: 226 additions & 66 deletions config/groovy/common.groovy

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions config/groovy/lib.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

class lib {

def excludedItems = []

def getGithubDefaultHome(Properties properties) {
return properties.alternativeGithubHome ?: "MovingBlocks"
}

File targetDirectory = new File("libs")
def itemType = "library"

// Libs currently do not care about dependencies
String[] findDependencies(File targetDir) {
return []
}

// TODO: Libs don't copy anything in yet .. they might be too unique. Some may Gradle stuff but not all (like the Index)
def copyInTemplateFiles(File targetDir) {

}

/**
* Filters the given items based on this item type's preferences
* @param possibleItems A map of repos (possible items) and their descriptions (potential filter data)
* @return A list containing only the items this type cares about
*/
List filterItemsFromApi(Map possibleItems) {
List itemList = []

// Libs only includes repos found to have a particular string snippet in their description
// TODO: Consideration for libraries - generic vs project specific? TeraMath could be used in DestSol etc ...
itemList = possibleItems.findAll {
it.value?.contains("Automation category: Terasology Library")
}.collect {it.key}

return itemList
}

def refreshGradle(File targetDir) {
println "Skipping refreshGradle for lib $targetDir- they vary too much to use any Gradle templates"
}
}
50 changes: 42 additions & 8 deletions config/groovy/module.groovy
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
/*
* Copyright 2020 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import groovy.json.JsonSlurper

class module {

def excludedItems = ["core", "DestinationSol.github.io"]
def excludedItems = ["engine", "core", "out", "build", "DestinationSol.github.io"]

def getGithubDefaultHome(Properties properties) {
return properties.alternativeGithubHome ?: "DestinationSol"
Expand All @@ -11,19 +26,19 @@ class module {
File targetDirectory = new File("modules")
def itemType = "module"

String[] findDependencies(File targetDir) {
def foundDependencies = readModuleDependencies(new File(targetDir, "module.json"))
String[] findDependencies(File targetDir, boolean respectExcludedItems = true) {
def foundDependencies = readModuleDependencies(new File(targetDir, "module.json"), respectExcludedItems)
println "Looked for dependencies, found: " + foundDependencies
return foundDependencies
}

/**
* Reads a given module info file to figure out which if any dependencies it has. Filters out any already retrieved.
* This method is only for modules.
* @param targetModuleInfo the target file to check (a module.txt file or similar)
* @param targetModuleInfo the target file to check (a module.json file or similar)
* @return a String[] containing the next level of dependencies, if any
*/
String[] readModuleDependencies(File targetModuleInfo) {
String[] readModuleDependencies(File targetModuleInfo, boolean respectExcludedItems = true) {
def qualifiedDependencies = []
if (!targetModuleInfo.exists()) {
println "The module info file did not appear to exist - can't calculate dependencies"
Expand All @@ -32,7 +47,7 @@ class module {
def slurper = new JsonSlurper()
def moduleConfig = slurper.parseText(targetModuleInfo.text)
for (dependency in moduleConfig.dependencies) {
if (excludedItems.contains(dependency.id)) {
if (respectExcludedItems && excludedItems.contains(dependency.id)) {
println "Skipping listed dependency $dependency.id as it is in the exclude list (shipped with primary project)"
} else {
println "Accepting listed dependency $dependency.id"
Expand All @@ -43,12 +58,19 @@ class module {
}

def copyInTemplateFiles(File targetDir) {
// Copy in the template build.gradle for modules
println "In copyInTemplateFiles for module $targetDir.name - copying in a build.gradle then next checking for module.json"
File targetBuildGradle = new File(targetDir, 'build.gradle')
targetBuildGradle.delete()
targetBuildGradle << new File('templates/build.gradle').text

// Copy in the template module.json for modules (if one doesn't exist yet)
File moduleManifest = new File(targetDir, 'module.json')
if (!moduleManifest.exists()) {
def moduleText = new File("templates/module.json").text

moduleManifest << moduleText.replaceAll('MODULENAME', targetDir.name)
println "WARNING: Module ${targetDir.name} did not have a module.json! One was created, please review and submit to GitHub"
println "WARNING: the module ${targetDir.name} did not have a module.json! One was created, please review and submit to GitHub"
}

// Always use the latest build.gradle
Expand Down Expand Up @@ -90,4 +112,16 @@ class module {

return itemList
}

def refreshGradle(File targetDir) {
// Copy in the template build.gradle for modules
if (!new File(targetDir, "module.json").exists()) {
println "$targetDir has no module.json, it must not want a fresh build.gradle"
return
}
println "In refreshGradle for module $targetDir - copying in a fresh build.gradle"
File targetBuildGradle = new File(targetDir, 'build.gradle')
targetBuildGradle.delete()
targetBuildGradle << new File('templates/build.gradle').text
}
}
Loading

0 comments on commit 30700e9

Please sign in to comment.