Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Fran committed Mar 28, 2023
1 parent 43f8f8b commit fbcc9fe
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 37 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/gradle-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: "Test"
# Only execute this workflow when a PR is opened or when something is pushed to the master branch
on: [pull_request]
on:
pull_request:
branches: [ master ]
jobs:
testBuilds:
strategy:
Expand Down
18 changes: 9 additions & 9 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val env = project.rootProject.file(".env").let { file ->
if(file.exists()) file.readLines().filter { it.isNotBlank() && !it.startsWith("#") && it.split("=").size == 2 }.associate { it.split("=")[0] to it.split("=")[1] } else emptyMap()
}.toMutableMap().apply { putAll(System.getenv()) }

val projectVersion = env["VERSION"] ?: "0.6.2-SNAPSHOT"
val projectVersion = env["VERSION"] ?: "0.6.3.11-SNAPSHOT"

group = "xyz.theprogramsrc"
version = projectVersion.replaceFirst("v", "").replace("/", "")
Expand Down Expand Up @@ -183,14 +183,16 @@ publishing {
}
}

nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
if(env["ENV"] == "prod") {
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))

username.set(env["SONATYPE_USERNAME"])
password.set(env["SONATYPE_PASSWORD"])
username.set(env["SONATYPE_USERNAME"])
password.set(env["SONATYPE_PASSWORD"])
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,26 @@ object ModuleHelper {
* @return List of the sorted modules to load
*/
fun sortModuleDependencies(dependencies: Map<String, Collection<String>>): List<String> {
val sorted = mutableListOf<String>()
// First add the modules that don't have dependencies
sorted.addAll(dependencies.filter { it.value.isEmpty() }.keys)
val visited = mutableSetOf<String>()
val result = mutableListOf<String>()

// Now add the modules that have dependencies
dependencies.filter { !sorted.contains(it.key) }.forEach { (moduleName, moduleDepends) ->
moduleDepends.forEach { dependency ->
if(sorted.contains(dependency) && sorted.indexOf(moduleName) > sorted.indexOf(dependency)) {
sorted.remove(dependency)
sorted.add(sorted.indexOf(moduleName), dependency)
}else if(!sorted.contains(dependency)){
sorted.add(dependency)
fun dfs(node: String) {
visited.add(node)
for (neighbor in dependencies[node] ?: emptySet()) {
if (!visited.contains(neighbor)) {
dfs(neighbor)
}
}
if(!sorted.contains(moduleName)) sorted.add(moduleName)
result.add(node)
}
return sorted.filter { it.isNotBlank() && it.isNotEmpty() }

for (node in dependencies.keys) {
if (!visited.contains(node)) {
dfs(node)
}
}

return result
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.FileInputStream
import java.io.IOException
import java.net.URLClassLoader
import java.util.*
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarInputStream

Expand Down Expand Up @@ -99,7 +100,7 @@ class ModuleManager(private val logger: ILogger) {

// Now we load and save all the module descriptions from the available modules
val updatedModules = mutableListOf<String>()
files.map { file ->
files.mapNotNull { file ->
try {
// Validate that this file is a module
val props = loadDescription(file) ?: throw InvalidModuleDescriptionException("Failed to load module description for " + file!!.name)
Expand Down Expand Up @@ -131,7 +132,7 @@ class ModuleManager(private val logger: ILogger) {
e.printStackTrace()
null
}
}.filterNotNull().filter { !(it.second.disableStandalone && StandaloneLoader.isRunning) }.forEach { // Filter not null descriptions and filter to only run available modules
}.filter { !(it.second.disableStandalone && StandaloneLoader.isRunning) }.forEach { // Filter not null descriptions and filter to only run available modules
val file = it.first
val description = it.second

Expand Down Expand Up @@ -255,6 +256,19 @@ class ModuleManager(private val logger: ILogger) {
private fun loadIntoClasspath(loader: URLClassLoader, file: File, description: ModuleDescription) {
try {
JarInputStream(FileInputStream(file)).use {
logger.info("Loading classes for module ${description.name} v${description.version}")
var entry: JarEntry? = it.nextJarEntry
while (entry != null) {
if (!entry.isDirectory && !entry.name.startsWith("META-INF") && entry.name.endsWith(".class")) {
val name = entry.name.replace('/', '.').replace('\\', '.').substring(0, entry.name.length - 6)
if (name != description.mainClass) {
loader.loadClass(name)
logger.info("Loaded class $name")
}
}
entry = it.nextJarEntry
}

val mainClass = loader.loadClass(description.mainClass)
if(!Module::class.java.isAssignableFrom(mainClass)){
throw InvalidModuleException("The class ${description.mainClass} must be extended to the Module class!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ internal class ModuleHelperTest {
)

val expectedOrder = listOf(
// First modules without dependencies (in order of appearance)
"filesmodule",
"tasksmodule",
// Then modules with dependencies (in order so other modules can depend on them)
"configmodule",
"loggingmodule",
"translationsmodule",
"tasksmodule",
"uismodule",
)

Expand Down

0 comments on commit fbcc9fe

Please sign in to comment.