Skip to content

Commit

Permalink
chore(build): Some more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Mar 15, 2024
1 parent 9e1bf91 commit 06d1176
Show file tree
Hide file tree
Showing 58 changed files with 152 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id("fr.xpdustry.toxopid")
}

val extension = project.extensions.findOrCreateExtension<DistributorModuleExtension>("module")
val extension = project.extensions.findOrCreateExtension<DistributorModuleExtension>(DistributorModuleExtension.EXTENSION_NAME)

toxopid {
compileVersion.set(libs.versions.mindustry)
Expand All @@ -18,17 +18,27 @@ dependencies {
mindustryDependencies()
}

afterEvaluate {
dependencies {
for (dependency in extension.dependencies.get()) {
compileOnly(dependency)
}
}
}

tasks.runMindustryClient {
mods.setFrom()
}

tasks.runMindustryServer {
mods.from(tasks.shadowJar)
mods.from(extension.dependencies.map { projects -> projects.map { it.tasks.shadowJar } })
}

tasks.register("getArtifactPath") {
doLast { println(tasks.shadowJar.get().archiveFile.get().toString()) }
// Cursed way to collect dependent distributor modules
gradle.projectsEvaluated {
tasks.runMindustryServer {
mods.from(collectAllPluginDependencies())
}
}

tasks.shadowJar {
Expand All @@ -47,7 +57,7 @@ tasks.shadowJar {
hidden = true,
dependencies =
extension.dependencies.get()
.map { it.extensions.getByType<DistributorModuleExtension>().identifier.get() }
.map { it.dependencyProject.extensions.getByType<DistributorModuleExtension>().identifier.get() }
.toMutableList(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tasks.dependencyUpdates {
}
}

tasks.register<Copy>("dist") {
tasks.register<Copy>("release") {
dependsOn(tasks.build)
from(rootProject.subprojects.filter { it.plugins.hasPlugin(ShadowJavaPlugin::class) }.map { it.tasks.named<ShadowJar>("shadowJar") })
into(temporaryDir)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin

plugins {
id("net.kyori.indra.publishing")
}
Expand Down Expand Up @@ -36,3 +38,11 @@ indra {
}
}
}

plugins.withType<ShadowJavaPlugin> {
components.withType<AdhocComponentWithVariants>().forEach {
it.withVariantsFromConfiguration(project.configurations.named("shadowRuntimeElements").get()) {
skip()
}
}
}
32 changes: 24 additions & 8 deletions distributor-build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.kyori.mammoth.Extensions
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.plugins.ExtensionContainer
import org.gradle.api.provider.Property
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.property
import org.gradle.kotlin.dsl.setProperty
import org.gradle.kotlin.dsl.the

internal val Project.libs: LibrariesForLibs get() = the()

inline fun <reified T : Any> ExtensionContainer.findOrCreateExtension(name: String): T = Extensions.findOrCreate(this, name, T::class.java)

open class DistributorModuleExtension(project: Project) {
val identifier: Property<String> = project.objects.property(String::class.java)
val display: Property<String> = project.objects.property(String::class.java)
val main: Property<String> = project.objects.property(String::class.java)
val description: Property<String> = project.objects.property(String::class.java)
val identifier = project.objects.property<String>()
val display = project.objects.property<String>()
val main = project.objects.property<String>()
val description = project.objects.property<String>()
val dependencies = project.objects.setProperty<ProjectDependency>()

// TODO Does not handle transitive dependencies, FIX IT
val dependencies: SetProperty<Project> = project.objects.setProperty(Project::class.java)
companion object {
const val EXTENSION_NAME = "distributorModule"
}
}

fun Project.collectAllPluginDependencies(): Set<TaskProvider<out ShadowJar>> {
val dependencies = mutableSetOf<TaskProvider<out ShadowJar>>()
val extension = extensions.findOrCreateExtension<DistributorModuleExtension>(DistributorModuleExtension.EXTENSION_NAME)
for (dependency in extension.dependencies.get()) {
dependencies += dependency.dependencyProject.tasks.named<ShadowJar>("shadowJar")
dependencies += dependency.dependencyProject.collectAllPluginDependencies()
}
return dependencies
}
18 changes: 2 additions & 16 deletions distributor-command-cloud/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
plugins {
id("distributor.base-conventions")
id("distributor.mindustry-conventions")
id("distributor.publish-conventions")
}

repositories {
maven("https://oss.sonatype.org/content/repositories/snapshots/") {
name = "sonatype-oss-snapshots"
mavenContent { snapshotsOnly() }
}
}

module {
identifier = "distributor-command-cloud"
display = "DistributorLoggerSimple"
main = "com.xpdustry.distributor.logger.simple.DistributorLoggerPlugin"
description = "Simple slf4j logger implementation for plugins."
}

dependencies {
compileOnly(projects.distributorCore)
api(libs.cloud.core)
compileOnly(project(":distributor-common"))
compileOnly(libs.bundles.mindustry)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import com.xpdustry.distributor.command.cloud.parser.content.UnitParser;
import com.xpdustry.distributor.command.cloud.parser.content.WeatherParser;
import com.xpdustry.distributor.command.cloud.specifier.AllTeams;
import com.xpdustry.distributor.common.DistributorProvider;
import com.xpdustry.distributor.common.command.CommandSender;
import com.xpdustry.distributor.common.plugin.MindustryPlugin;
import com.xpdustry.distributor.common.plugin.PluginAware;
import com.xpdustry.distributor.core.DistributorProvider;
import com.xpdustry.distributor.core.command.CommandSender;
import com.xpdustry.distributor.core.plugin.MindustryPlugin;
import com.xpdustry.distributor.core.plugin.PluginAware;
import io.leangen.geantyref.TypeToken;
import java.text.MessageFormat;
import mindustry.game.Team;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import arc.struct.ObjectMap;
import arc.util.CommandHandler;
import com.xpdustry.distributor.common.collection.ArcCollections;
import com.xpdustry.distributor.core.collection.ArcCollections;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
package com.xpdustry.distributor.command.cloud;

import arc.util.CommandHandler;
import com.xpdustry.distributor.common.command.CommandDescription;
import com.xpdustry.distributor.common.command.CommandElement;
import com.xpdustry.distributor.common.command.CommandFacade;
import com.xpdustry.distributor.common.command.CommandHelp;
import com.xpdustry.distributor.common.command.CommandSender;
import com.xpdustry.distributor.common.plugin.MindustryPlugin;
import com.xpdustry.distributor.core.command.CommandDescription;
import com.xpdustry.distributor.core.command.CommandElement;
import com.xpdustry.distributor.core.command.CommandFacade;
import com.xpdustry.distributor.core.command.CommandHelp;
import com.xpdustry.distributor.core.command.CommandSender;
import com.xpdustry.distributor.core.plugin.MindustryPlugin;
import java.util.ArrayList;
import java.util.List;
import mindustry.gen.Player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package com.xpdustry.distributor.command.cloud.parser;

import arc.util.Strings;
import com.xpdustry.distributor.common.collection.ArcCollections;
import com.xpdustry.distributor.common.player.MUUID;
import com.xpdustry.distributor.core.collection.ArcCollections;
import com.xpdustry.distributor.core.player.MUUID;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import arc.Core;
import com.xpdustry.distributor.command.cloud.ArcCommandContextKeys;
import com.xpdustry.distributor.common.collection.ArcCollections;
import com.xpdustry.distributor.core.collection.ArcCollections;
import java.util.concurrent.CompletableFuture;
import mindustry.gen.Groups;
import mindustry.gen.Player;
Expand All @@ -39,7 +39,7 @@ public final class PlayerParser<C> implements ArgumentParser<C, Player> {
static SuggestionProvider<?> SUGGESTION_PROVIDER = (ctx, input) -> CompletableFuture.supplyAsync(
() -> ArcCollections.immutableList(Groups.player).stream()
.map(Player::plainName)
.map(Suggestion::simple)
.map(Suggestion::suggestion)
.toList(),
Core.app::post);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ plugins {
id("distributor.publish-conventions")
}

module {
distributorModule {
identifier = "distributor-core"
display = "DistributorCore"
main = "com.xpdustry.distributor.core.DistributorCorePlugin"
description = "Core classes of distributor."
dependencies = setOf(project(":distributor-logging-simple"))
dependencies = setOf(projects.distributorLoggingSimple)
}

dependencies {
compileOnlyApi(libs.immutables)
annotationProcessor(libs.immutables)
compileOnlyApi(libs.immutables.annotations)
annotationProcessor(libs.immutables.processor)
compileOnlyApi(libs.slf4j.api)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common;
package com.xpdustry.distributor.core;

import com.xpdustry.distributor.common.command.CommandFacade;
import com.xpdustry.distributor.common.permission.PermissionManager;
import com.xpdustry.distributor.common.service.ServiceManager;
import com.xpdustry.distributor.core.command.CommandFacade;
import com.xpdustry.distributor.core.permission.PermissionManager;
import com.xpdustry.distributor.core.service.ServiceManager;

public interface Distributor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common;
package com.xpdustry.distributor.core;

import com.xpdustry.distributor.common.command.CommandFacade;
import com.xpdustry.distributor.common.permission.PermissionManager;
import com.xpdustry.distributor.common.plugin.AbstractMindustryPlugin;
import com.xpdustry.distributor.common.service.ServiceManager;
import com.xpdustry.distributor.common.util.Priority;
import com.xpdustry.distributor.core.command.CommandFacade;
import com.xpdustry.distributor.core.permission.PermissionManager;
import com.xpdustry.distributor.core.plugin.AbstractMindustryPlugin;
import com.xpdustry.distributor.core.service.ServiceManager;
import com.xpdustry.distributor.core.util.Priority;
import java.util.Objects;
import org.jspecify.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common;
package com.xpdustry.distributor.core;

/**
* This exception is thrown when the distributor fails to initialize.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common;
package com.xpdustry.distributor.core;

import org.jspecify.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common.collection;
package com.xpdustry.distributor.core.collection;

import arc.struct.ObjectMap;
import arc.struct.ObjectSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common.collection;
package com.xpdustry.distributor.core.collection;

import arc.struct.Seq;
import java.io.Serial;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common.collection;
package com.xpdustry.distributor.core.collection;

import arc.struct.ObjectMap;
import java.io.Serial;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common.collection;
package com.xpdustry.distributor.core.collection;

import arc.struct.ObjectSet;
import java.io.Serial;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@NullMarked
package com.xpdustry.distributor.common.collection;
package com.xpdustry.distributor.core.collection;

import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common.command;
package com.xpdustry.distributor.core.command;

import arc.util.CommandHandler;
import com.xpdustry.distributor.common.plugin.MindustryPlugin;
import com.xpdustry.distributor.core.plugin.MindustryPlugin;
import java.util.List;
import org.jspecify.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common.command;
package com.xpdustry.distributor.core.command;

public interface CommandDescription {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common.command;
package com.xpdustry.distributor.core.command;

import com.xpdustry.distributor.common.internal.GeneratedDataClass;
import com.xpdustry.distributor.core.internal.GeneratedDataClass;
import java.util.Collection;
import org.immutables.value.Value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common.command;
package com.xpdustry.distributor.core.command;

import arc.util.CommandHandler;
import com.xpdustry.distributor.common.plugin.MindustryPlugin;
import com.xpdustry.distributor.core.plugin.MindustryPlugin;
import org.jspecify.annotations.Nullable;

public interface CommandFacade {
Expand Down
Loading

0 comments on commit 06d1176

Please sign in to comment.