Skip to content

Commit f2f5b41

Browse files
committed
chore: restore old groovy commands
1 parent 2fdfe67 commit f2f5b41

File tree

8 files changed

+1501
-0
lines changed

8 files changed

+1501
-0
lines changed

config/groovy/common.groovy

Lines changed: 591 additions & 0 deletions
Large diffs are not rendered by default.

config/groovy/facade.groovy

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
class facade {
3+
4+
def excludedItems = ["PC", "TeraEd"]
5+
6+
def getGithubDefaultHome(Properties properties) {
7+
return properties.alternativeGithubHome ?: "MovingBlocks"
8+
}
9+
10+
File targetDirectory = new File("facades")
11+
def itemType = "facade"
12+
13+
// Facades currently do not care about dependencies
14+
String[] findDependencies(File targetDir) {
15+
return []
16+
}
17+
18+
def copyInTemplateFiles(File targetDir) {
19+
println "In copyInTemplateFiles for facade $targetDir.name - reviewing Gradle needs"
20+
File targetBuildGradle = new File(targetDir, 'build.gradle')
21+
if (!targetBuildGradle.exists()) {
22+
targetBuildGradle << new File('templates/facades.gradle').text
23+
}
24+
}
25+
26+
/**
27+
* Filters the given items based on this item type's preferences
28+
* @param possibleItems A map of repos (possible items) and their descriptions (potential filter data)
29+
* @return A list containing only the items this type cares about
30+
*/
31+
List filterItemsFromApi(Map possibleItems) {
32+
List itemList = []
33+
34+
// Facades only includes repos found to have a particular string snippet in their description
35+
itemList = possibleItems.findAll {
36+
it.value?.contains("Automation category: Terasology Facade")
37+
}.collect {it.key}
38+
39+
return itemList
40+
}
41+
42+
def refreshGradle(File targetDir) {
43+
// Copy in the template build.gradle for facades
44+
println "In refreshGradle for facade $targetDir - copying in a fresh build.gradle"
45+
File targetBuildGradle = new File(targetDir, 'build.gradle')
46+
targetBuildGradle.delete()
47+
targetBuildGradle << new File('templates/facades.gradle').text
48+
}
49+
}

config/groovy/lib.groovy

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
class lib {
3+
4+
def excludedItems = []
5+
6+
def getGithubDefaultHome(Properties properties) {
7+
return properties.alternativeGithubHome ?: "MovingBlocks"
8+
}
9+
10+
File targetDirectory = new File("libs")
11+
def itemType = "library"
12+
13+
// Libs currently do not care about dependencies
14+
String[] findDependencies(File targetDir) {
15+
return []
16+
}
17+
18+
// TODO: Libs don't copy anything in yet .. they might be too unique. Some may Gradle stuff but not all (like the Index)
19+
def copyInTemplateFiles(File targetDir) {
20+
21+
}
22+
23+
/**
24+
* Filters the given items based on this item type's preferences
25+
* @param possibleItems A map of repos (possible items) and their descriptions (potential filter data)
26+
* @return A list containing only the items this type cares about
27+
*/
28+
List filterItemsFromApi(Map possibleItems) {
29+
List itemList = []
30+
31+
// Libs only includes repos found to have a particular string snippet in their description
32+
// TODO: Consideration for libraries - generic vs project specific? TeraMath could be used in DestSol etc ...
33+
itemList = possibleItems.findAll {
34+
it.value?.contains("Automation category: Terasology Library")
35+
}.collect {it.key}
36+
37+
return itemList
38+
}
39+
40+
def refreshGradle(File targetDir) {
41+
println "Skipping refreshGradle for lib $targetDir- they vary too much to use any Gradle templates"
42+
}
43+
}

config/groovy/meta.groovy

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
class meta {
3+
4+
def excludedItems = ["metaterasology.github.io"]
5+
6+
def getGithubDefaultHome(Properties properties) {
7+
// Note how metas use a different override property - since same name as the paired module they cannot live in same org
8+
return properties.alternativeGithubMetaHome ?: "MetaTerasology"
9+
}
10+
11+
File targetDirectory = new File("metas")
12+
def itemType = "meta"
13+
14+
// Meta modules currently do not care about dependencies
15+
String[] findDependencies(File targetDir) {
16+
return []
17+
}
18+
19+
def copyInTemplateFiles(File targetDir) {
20+
println "In copyInTemplateFiles for meta $targetDir.name - reviewing readme template"
21+
File targetReadme = new File(targetDir, 'README.md')
22+
if (!targetReadme.exists()) {
23+
def readmeText = new File('templates/metaREADME.markdown').text
24+
targetReadme << readmeText.replaceAll('MODULENAME', targetDir.name)
25+
}
26+
}
27+
28+
/**
29+
* Filters the given items based on this item type's preferences
30+
* @param possibleItems A map of repos (possible items) and their descriptions (potential filter data)
31+
* @return A list containing only the items this type cares about
32+
*/
33+
List filterItemsFromApi(Map possibleItems) {
34+
List itemList = []
35+
36+
// Meta modules just consider the item name and excludes those in a specific list
37+
itemList = possibleItems.findAll {
38+
!excludedItems.contains (it.key)
39+
}.collect {it.key}
40+
41+
return itemList
42+
}
43+
44+
def refreshGradle(File targetDir) {
45+
println "Skipping refreshGradle for meta module $targetDir - they don't Gradle"
46+
}
47+
}

config/groovy/module.groovy

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright 2020 MovingBlocks
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import groovy.json.JsonSlurper
18+
19+
class module {
20+
def excludedItems = ["engine", "Index", "out", "build"]
21+
22+
def getGithubDefaultHome(Properties properties) {
23+
return properties.alternativeGithubHome ?: "Terasology"
24+
}
25+
26+
File targetDirectory = new File("modules")
27+
def itemType = "module"
28+
29+
String[] findDependencies(File targetDir, boolean respectExcludedItems = true) {
30+
def foundDependencies = readModuleDependencies(new File(targetDir, "module.txt"), respectExcludedItems)
31+
println "Looked for dependencies, found: " + foundDependencies
32+
return foundDependencies
33+
}
34+
35+
/**
36+
* Reads a given module info file to figure out which if any dependencies it has. Filters out any already retrieved.
37+
* This method is only for modules.
38+
* @param targetModuleInfo the target file to check (a module.txt file or similar)
39+
* @return a String[] containing the next level of dependencies, if any
40+
*/
41+
String[] readModuleDependencies(File targetModuleInfo, boolean respectExcludedItems = true) {
42+
def qualifiedDependencies = []
43+
if (!targetModuleInfo.exists()) {
44+
println "The module info file did not appear to exist - can't calculate dependencies"
45+
return qualifiedDependencies
46+
}
47+
def slurper = new JsonSlurper()
48+
def moduleConfig = slurper.parseText(targetModuleInfo.text)
49+
for (dependency in moduleConfig.dependencies) {
50+
if (respectExcludedItems && excludedItems.contains(dependency.id)) {
51+
println "Skipping listed dependency $dependency.id as it is in the exclude list (shipped with primary project)"
52+
} else {
53+
println "Accepting listed dependency $dependency.id"
54+
qualifiedDependencies << dependency.id
55+
}
56+
}
57+
return qualifiedDependencies
58+
}
59+
60+
def copyInTemplateFiles(File targetDir) {
61+
// Copy in the template build.gradle for modules
62+
println "In copyInTemplateFiles for module $targetDir.name - copying in a build.gradle then next checking for module.txt"
63+
File targetBuildGradle = new File(targetDir, 'build.gradle')
64+
targetBuildGradle.delete()
65+
targetBuildGradle << new File('templates/build.gradle').text
66+
67+
// Copy in the template module.txt for modules (if one doesn't exist yet)
68+
File moduleManifest = new File(targetDir, 'module.txt')
69+
if (!moduleManifest.exists()) {
70+
def moduleText = new File("templates/module.txt").text
71+
72+
moduleManifest << moduleText.replaceAll('MODULENAME', targetDir.name)
73+
println "WARNING: the module ${targetDir.name} did not have a module.txt! One was created, please review and submit to GitHub"
74+
}
75+
76+
// TODO: Copy in a module readme template soon
77+
// TODO : Add in the logback.groovy from engine\src\test\resources\logback.groovy ? Local dev only, Jenkins will use the one inside engine-tests.jar. Also add to .gitignore
78+
}
79+
80+
/**
81+
* Filters the given items based on this item type's preferences
82+
* @param possibleItems A map of repos (possible items) and their descriptions (potential filter data)
83+
* @return A list containing only the items this type cares about
84+
*/
85+
List filterItemsFromApi(Map possibleItems) {
86+
List itemList = []
87+
88+
// Modules just consider the item name and excludes those in a specific list
89+
itemList = possibleItems.findAll {
90+
!excludedItems.contains(it.key)
91+
}.collect { it.key }
92+
93+
return itemList
94+
}
95+
96+
def refreshGradle(File targetDir) {
97+
// Copy in the template build.gradle for modules
98+
if (!new File(targetDir, "module.txt").exists()) {
99+
println "$targetDir has no module.txt, it must not want a fresh build.gradle"
100+
return
101+
}
102+
println "In refreshGradle for module $targetDir - copying in a fresh build.gradle"
103+
File targetBuildGradle = new File(targetDir, 'build.gradle')
104+
targetBuildGradle.delete()
105+
targetBuildGradle << new File('templates/build.gradle').text
106+
}
107+
}

0 commit comments

Comments
 (0)