Skip to content

Commit 7cdd63c

Browse files
committed
Merge branch 'fixScanDependencyTwist' into develop
2 parents 33cca96 + 89a2f49 commit 7cdd63c

17 files changed

Lines changed: 315 additions & 109 deletions

File tree

serverpackcreator-api/src/main/kotlin/de/griefed/serverpackcreator/api/modscanning/FabricScanner.kt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import java.util.*
3737
class FabricScanner(
3838
private val objectMapper: ObjectMapper,
3939
private val utilities: Utilities
40-
) : JsonBasedScanner(), Scanner<Pair<Collection<File>, Collection<Pair<String,String>>>, Collection<File>> {
40+
) : JsonBasedScanner(), Scanner<ScanResult, Collection<File>> {
4141
private val log by lazy { cachedLoggerOf(this.javaClass) }
4242
private val jar = "jar"
4343
private val fabricModJson = "fabric.mod.json"
@@ -59,11 +59,11 @@ class FabricScanner(
5959
* @return List of mods not to include in server pack based on fabric.mod.json-content.
6060
* @author Griefed
6161
*/
62-
override fun scan(jarFiles: Collection<File>): Pair<Collection<File>, Collection<Pair<String,String>>> {
62+
override fun scan(jarFiles: Collection<File>): ScanResult {
6363
log.info("Scanning Fabric mods for sideness...")
6464
val modDependencies = ArrayList<Pair<String, Pair<String, String>>>()
6565
val clientMods = TreeSet<String>()
66-
66+
val scanResult = ScanResult()
6767
/*
6868
* Go through all mods in our list and acquire a list of clientside-only mods as well as any
6969
* dependencies of the mods.
@@ -78,14 +78,10 @@ class FabricScanner(
7878
* any of the remaining clientmods is available in our list of files. The resulting set is the
7979
* set of mods we can safely exclude from our server pack.
8080
*/
81-
return Pair(
81+
return ScanResult(
8282
getModsDelta(jarFiles, clientMods),
83-
modDependencies.map { entry ->
84-
Pair(
85-
entry.first,
86-
"${entry.second.first} (${entry.second.second})"
87-
)
88-
})
83+
modDependencies.map { entry -> Dependency(entry.first, entry.second.first, entry.second.second)}
84+
)
8985
}
9086

9187
override fun checkForClientModsAndDeps(
@@ -143,8 +139,9 @@ class FabricScanner(
143139
}
144140
}
145141

146-
override fun getModsDelta(filesInModsDir: Collection<File>, clientMods: TreeSet<String>): TreeSet<File> {
142+
override fun getModsDelta(filesInModsDir: Collection<File>, clientMods: TreeSet<String>): List<Exclusion> {
147143
val modsDelta = TreeSet<File>()
144+
val exclusions = ArrayList<Exclusion>()
148145
for (mod in filesInModsDir) {
149146
var modIdToCheck: String
150147
var addToDelta = false
@@ -172,6 +169,15 @@ class FabricScanner(
172169
// delta rather than aborting the scan of the remaining mods.
173170
}
174171
}
175-
return modsDelta
172+
for (mod in modsDelta) {
173+
var modID: String
174+
val modJson: JsonNode = getJarJson(mod, fabricModJson, objectMapper)
175+
176+
// Get the modId
177+
modID = utilities.jsonUtilities.getNestedText(modJson, id)
178+
179+
exclusions.add(Exclusion(modID, mod))
180+
}
181+
return exclusions
176182
}
177183
}

serverpackcreator-api/src/main/kotlin/de/griefed/serverpackcreator/api/modscanning/ForgeAnnotationScanner.kt

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import java.util.*
3939
class ForgeAnnotationScanner(
4040
private val objectMapper: ObjectMapper,
4141
private val utilities: Utilities
42-
) : JsonBasedScanner(), Scanner<Pair<Collection<File>, Collection<Pair<String,String>>>, Collection<File>> {
42+
) : JsonBasedScanner(), Scanner<ScanResult, Collection<File>> {
4343
private val log by lazy { cachedLoggerOf(this.javaClass) }
4444
private val additionalDependencyRegex = "(@.*|\\[.*)".toRegex()
4545
private val caches = "META-INF/fml_cache_annotation.json"
@@ -66,7 +66,7 @@ class ForgeAnnotationScanner(
6666
* @return List of mods not to include in server pack based on fml-cache-annotation.json-content.
6767
* @author Griefed
6868
*/
69-
override fun scan(jarFiles: Collection<File>): Pair<Collection<File>, Collection<Pair<String,String>>> {
69+
override fun scan(jarFiles: Collection<File>): ScanResult {
7070
log.info("Scanning Minecraft 1.12.x and older mods for sideness...")
7171
val modDependencies = ArrayList<Pair<String, Pair<String, String>>>()
7272
val clientMods = TreeSet<String>()
@@ -85,14 +85,10 @@ class ForgeAnnotationScanner(
8585
* any of the remaining clientmods is available in our list of files. The resulting set is the
8686
* set of mods we can safely exclude from our server pack.
8787
*/
88-
return Pair(
88+
return ScanResult(
8989
getModsDelta(jarFiles, clientMods),
90-
modDependencies.map { entry ->
91-
Pair(
92-
entry.first,
93-
"${entry.second.first} (${entry.second.second})"
94-
)
95-
})
90+
modDependencies.map { entry -> Dependency(entry.first, entry.second.first, entry.second.second)}
91+
)
9692
}
9793

9894
override fun checkForClientModsAndDeps(
@@ -560,8 +556,9 @@ class ForgeAnnotationScanner(
560556
return clientSide
561557
}
562558

563-
override fun getModsDelta(filesInModsDir: Collection<File>, clientMods: TreeSet<String>): TreeSet<File> {
559+
override fun getModsDelta(filesInModsDir: Collection<File>, clientMods: TreeSet<String>): List<Exclusion> {
564560
val modsDelta = TreeSet<File>()
561+
val exclusions = ArrayList<Exclusion>()
565562
for (mod in filesInModsDir) {
566563
try {
567564
if (addToDelta(mod, clientMods)) {
@@ -572,6 +569,32 @@ class ForgeAnnotationScanner(
572569
// delta, so it is skipped rather than aborting the scan of the remaining mods.
573570
}
574571
}
575-
return modsDelta
572+
for (mod in modsDelta) {
573+
var modID: String? = null
574+
val modJson: JsonNode = getJarJson(mod, caches, objectMapper)
575+
for (node in modJson) {
576+
try {
577+
// iterate though annotations
578+
val cacheAnnotations = node.get(annotations)
579+
for (child in cacheAnnotations) {
580+
581+
// Get the modId
582+
try {
583+
modID = getModId(child)
584+
} catch (ignored: NullPointerException) {
585+
// This child has no modId / no clientSideOnly flag -> it can't mark the mod
586+
// for the delta, so skip it.
587+
} catch (ignored: JsonException) {
588+
// Malformed annotation entry -> skip it.
589+
}
590+
}
591+
} catch (ignored: NullPointerException) {
592+
// This node has no "annotations" array -> skip it and continue with the next node.
593+
}
594+
}
595+
596+
exclusions.add(Exclusion(modID?: "N/A", mod))
597+
}
598+
return exclusions
576599
}
577600
}

serverpackcreator-api/src/main/kotlin/de/griefed/serverpackcreator/api/modscanning/ForgeTomlScanner.kt

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import java.util.jar.JarFile
3535
* @Griefed
3636
*/
3737
open class ForgeTomlScanner(private val tomlParser: TomlParser) :
38-
Scanner<Pair<Collection<File>, Collection<Pair<String,String>>>, Collection<File>> {
38+
Scanner<ScanResult, Collection<File>> {
3939
private val log by lazy { cachedLoggerOf(this.javaClass) }
4040
private val mods = "mods"
4141
private val modId = "modId"
@@ -67,19 +67,19 @@ open class ForgeTomlScanner(private val tomlParser: TomlParser) :
6767
* @return Mods not to include in server pack based on mods.toml-configuration.
6868
* @author Griefed
6969
*/
70-
override fun scan(jarFiles: Collection<File>): Pair<Collection<File>, Collection<Pair<String,String>>> {
70+
override fun scan(jarFiles: Collection<File>): ScanResult {
7171
val serverMods = TreeSet<File>()
72-
val dependencies = ArrayList<Pair<String,String>>()
7372
var modConfig: CommentedConfig
73+
val scanResult = ScanResult()
7474
for (modJar in jarFiles) {
7575
try {
7676
modConfig = getConfig(modJar)
7777

7878
// get all [[dependencies.n]] which are minecraft|forge, to determine the sideness of the mod itself
79-
dependencies.addAll(getModDependencyIdsRequiredOnServer(modConfig, modJar.name))
79+
scanResult.dependencies.addAll(getModDependencyIdsRequiredOnServer(modConfig, modJar.name))
8080

8181
// get all mods required on the server
82-
dependencies.addAll(getModIdsRequiredOnServer(modConfig, modJar.name))
82+
scanResult.dependencies.addAll(getModIdsRequiredOnServer(modConfig, modJar.name))
8383
} catch (e: Exception) {
8484
log.error("Could not scan ${modJar.name}. Consider reporting this: ${e.cause}: ${e.message}")
8585
serverMods.add(modJar)
@@ -90,7 +90,7 @@ open class ForgeTomlScanner(private val tomlParser: TomlParser) :
9090
modConfig = getConfig(modJar)
9191
val idsInMod = getModIdsInJar(modConfig)
9292
for (id in idsInMod) {
93-
if (dependencies.map{ it.first }.contains(id)) {
93+
if (scanResult.dependencies.map{ it.dependencyID }.contains(id)) {
9494
serverMods.add(modJar)
9595
}
9696
}
@@ -101,7 +101,13 @@ open class ForgeTomlScanner(private val tomlParser: TomlParser) :
101101
}
102102
val excluded = TreeSet(jarFiles)
103103
excluded.removeAll(serverMods)
104-
return Pair(excluded,dependencies)
104+
for (exclusion in excluded) {
105+
modConfig = getConfig(exclusion)
106+
val modId = getModId(modConfig)
107+
scanResult.exclusions.add(Exclusion(modId, exclusion))
108+
}
109+
return scanResult
110+
//return Pair(excluded,dependencies)
105111
}
106112

107113
/**
@@ -112,9 +118,9 @@ open class ForgeTomlScanner(private val tomlParser: TomlParser) :
112118
* @throws ScanningException if the mod specifies no mods.
113119
*/
114120
@Throws(ScanningException::class)
115-
private fun getModIdsRequiredOnServer(modConfig: CommentedConfig, fileName: String): ArrayList<Pair<String,String>> {
121+
private fun getModIdsRequiredOnServer(modConfig: CommentedConfig, fileName: String): ArrayList<Dependency> {
116122
val modConfigs = ArrayList<Map<String, Any>>(100)
117-
val entries = ArrayList<Pair<String, String>>()
123+
val entries = ArrayList<Dependency>()
118124
if (modConfig.valueMap()[mods] == null) {
119125
throw ScanningException("No mods specified.")
120126
} else {
@@ -139,25 +145,25 @@ open class ForgeTomlScanner(private val tomlParser: TomlParser) :
139145
try {
140146
val side = getSide(dependency)
141147
if (side.matches(bothServer)) {
142-
entries.add(Pair(modId, fileName))
148+
entries.add(Dependency(modId, fileName))
143149
}
144150
} catch (_: NullPointerException) {
145151
// no side specified....assuming both|server
146-
entries.add(Pair(modId, fileName))
152+
entries.add(Dependency(modId, fileName))
147153
}
148154
}
149155
} catch (_: NullPointerException) {
150156
// no modId specified in dependency...assuming forge|minecraft and both|server
151157
containedForgeOrMinecraft = true
152-
entries.add(Pair(modId,"$fileName ($modId)"))
158+
entries.add(Dependency(modId,fileName, modId))
153159
}
154160
}
155161
} else {
156162
// contains no self referencing dependency...
157-
entries.add(Pair(modId, fileName))
163+
entries.add(Dependency(modId, fileName))
158164
}
159165
if (!containedForgeOrMinecraft) {
160-
entries.add(Pair(modId, fileName))
166+
entries.add(Dependency(modId, fileName))
161167
}
162168
}
163169
return entries
@@ -175,10 +181,10 @@ open class ForgeTomlScanner(private val tomlParser: TomlParser) :
175181
* @throws ScanningException if the mod has invalid dependency declarations or specifies no mods.
176182
*/
177183
@Throws(ScanningException::class)
178-
private fun getModDependencyIdsRequiredOnServer(modConfig: CommentedConfig, fileName: String): ArrayList<Pair<String,String>> {
184+
private fun getModDependencyIdsRequiredOnServer(modConfig: CommentedConfig, fileName: String): ArrayList<Dependency> {
179185
val dependencies: Map<String, ArrayList<CommentedConfig>> = getMapOfDependencyLists(modConfig)
180186
val idsInMod = getModIdsInJar(modConfig)
181-
val entries = ArrayList<Pair<String, String>>()
187+
val entries = ArrayList<Dependency>()
182188
try {
183189
var confidentOnClientSide = true
184190
for (modId in idsInMod) {
@@ -220,13 +226,13 @@ open class ForgeTomlScanner(private val tomlParser: TomlParser) :
220226
val required = getRequired(commentedConfig)
221227
if (side.matches(bothServer) && required.equals(requiredAsDep,true)) {
222228
for (modID in idsInMod) {
223-
entries.add(Pair(dependencyID,"$fileName ($modID)"))
229+
entries.add(Dependency(dependencyID, fileName, modId))
224230
}
225231
}
226232
} catch (_: NullPointerException) {
227233
// dependency specifies no side
228234
for (modID in idsInMod) {
229-
entries.add(Pair(dependencyID,"$fileName ($modID)"))
235+
entries.add(Dependency(dependencyID, fileName, modId))
230236
}
231237
}
232238
}
@@ -235,7 +241,7 @@ open class ForgeTomlScanner(private val tomlParser: TomlParser) :
235241
val lowerKey = key.lowercase()
236242
if (!lowerKey.matches(neoForgeMinecraft)) {
237243
for (modID in idsInMod) {
238-
entries.add(Pair(key,"$fileName ($modID)"))
244+
entries.add(Dependency(key, fileName, modId))
239245
}
240246
}
241247
}

serverpackcreator-api/src/main/kotlin/de/griefed/serverpackcreator/api/modscanning/JsonBasedScanner.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,5 @@ abstract class JsonBasedScanner {
107107
* server pack.
108108
* @author Griefed
109109
*/
110-
abstract fun getModsDelta(filesInModsDir: Collection<File>, clientMods: TreeSet<String>): TreeSet<File>
110+
abstract fun getModsDelta(filesInModsDir: Collection<File>, clientMods: TreeSet<String>): List<Exclusion>
111111
}

serverpackcreator-api/src/main/kotlin/de/griefed/serverpackcreator/api/modscanning/QuiltScanner.kt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import java.util.*
3737
class QuiltScanner(
3838
private val objectMapper: ObjectMapper,
3939
private val utilities: Utilities
40-
) : JsonBasedScanner(), Scanner<Pair<Collection<File>, Collection<Pair<String,String>>>, Collection<File>> {
40+
) : JsonBasedScanner(), Scanner<ScanResult, Collection<File>> {
4141
private val log by lazy { cachedLoggerOf(this.javaClass) }
4242
private val quiltModJson = "quilt.mod.json"
4343
private val quiltLoader = "quilt_loader"
@@ -61,7 +61,7 @@ class QuiltScanner(
6161
* @return List of mods not to include in server pack based on fabric.mod.json-content.
6262
* @author Griefed
6363
*/
64-
override fun scan(jarFiles: Collection<File>): Pair<Collection<File>, Collection<Pair<String,String>>> {
64+
override fun scan(jarFiles: Collection<File>): ScanResult {
6565
log.info("Scanning Quilt mods for sideness...")
6666
val modDependencies = ArrayList<Pair<String, Pair<String, String>>>()
6767
val clientMods = TreeSet<String>()
@@ -80,14 +80,10 @@ class QuiltScanner(
8080
* any of the remaining clientmods is available in our list of files. The resulting set is the
8181
* set of mods we can safely exclude from our server pack.
8282
*/
83-
return Pair(
83+
return ScanResult(
8484
getModsDelta(jarFiles, clientMods),
85-
modDependencies.map { entry ->
86-
Pair(
87-
entry.first,
88-
"${entry.second.first} (${entry.second.second})"
89-
)
90-
})
85+
modDependencies.map { entry -> Dependency(entry.first, entry.second.first, entry.second.second)}
86+
)
9187
}
9288

9389
override fun checkForClientModsAndDeps(
@@ -152,8 +148,9 @@ class QuiltScanner(
152148
}
153149
}
154150

155-
override fun getModsDelta(filesInModsDir: Collection<File>, clientMods: TreeSet<String>): TreeSet<File> {
151+
override fun getModsDelta(filesInModsDir: Collection<File>, clientMods: TreeSet<String>): List<Exclusion> {
156152
val modsDelta = TreeSet<File>()
153+
val exclusions = ArrayList<Exclusion>()
157154
// After removing dependencies from the list of potential clientside mods, we can remove any mod
158155
// that says it is clientside-only.
159156
for (mod in filesInModsDir) {
@@ -187,6 +184,15 @@ class QuiltScanner(
187184
// delta rather than aborting the scan of the remaining mods.
188185
}
189186
}
190-
return modsDelta
187+
for (mod in modsDelta) {
188+
var modID: String
189+
val modJson: JsonNode = getJarJson(mod, quiltModJson, objectMapper)
190+
191+
// Get the modId
192+
modID = utilities.jsonUtilities.getNestedText(modJson, quiltLoader, id)
193+
194+
exclusions.add(Exclusion(modID, mod))
195+
}
196+
return exclusions
191197
}
192198
}

0 commit comments

Comments
 (0)