Skip to content

Commit

Permalink
refactor: delombok plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Misat11 committed Dec 20, 2024
1 parent c3e4709 commit 2125c71
Show file tree
Hide file tree
Showing 20 changed files with 391 additions and 122 deletions.
5 changes: 0 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ subprojects {

dependencies {
"compileOnly"(rootProject.libs.jetbrains.annotations)

if (project.name != "builder") { // Lombok is not required in builder. TODO: delombok slib and run
"compileOnly"(rootProject.libs.projectlombok)
"annotationProcessor"(rootProject.libs.projectlombok)
}
}

extensions.configure<PublishingExtension> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void configureSourceJarTasks(@NotNull Project project) {
}

public static void configureSourceJarTasks(@NotNull Project project, @Nullable Predicate<@NotNull SourceSet> sourceSetSelector) {
project.getTasks().create("sourceJar", Jar.class, it -> {
project.getTasks().register("sourceJar", Jar.class, it -> {
it.getArchiveClassifier().set("sources");
var sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
if (sourceSetSelector != null) {
Expand Down
4 changes: 1 addition & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
shadow = "8.3.5"
gson = "2.11.0"
licenser = "0.6.1"
jetbrains-annotations = "26.0.1"

# compile only
projectlombok = "1.18.36"
jetbrains-annotations = "26.0.1"
kotlin = "2.1.0"

[libraries]
shadow = { group = "com.gradleup.shadow", name = "com.gradleup.shadow.gradle.plugin", version.ref = "shadow" }
licenser = { group = "gradle.plugin.org.cadixdev.gradle", name = "licenser", version.ref = "licenser" }
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
jetbrains-annotations = { group = "org.jetbrains", name = "annotations", version.ref = "jetbrains-annotations" }
projectlombok = { group = "org.projectlombok", name = "lombok", version.ref = "projectlombok" }
kotlin-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-sam = { group = "org.jetbrains.kotlin", name = "kotlin-sam-with-receiver", version.ref = "kotlin" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public void apply(@NotNull Project project) {
if (!extension.getVersions().isEmpty()) {
extension.getVersions().forEach(version -> {
String serverName = version.getPlatform().name().charAt(0) + version.getPlatform().name().substring(1).toLowerCase(Locale.ROOT) + "Server" + version.getVersion();
project.getTasks().create("update" + serverName, UpdateVersionTask.class, it -> {
project.getTasks().register("update" + serverName, UpdateVersionTask.class, it -> {
it.setDescription("Updates " + version.getPlatform().name().toLowerCase(Locale.ROOT) + " server version " + version.getVersion() + " to the latest build.");
it.getPlatform().set(version.getPlatform());
it.getVersion().set(version.getVersion());
it.getSubDirectory().set(extension.getTestingDirectory() + "/" + version.getSubDirectory());
});
project.getTasks().create("run" + serverName, RunServerTask.class, it -> {
project.getTasks().register("run" + serverName, RunServerTask.class, it -> {
it.setDescription("Runs a " + version.getPlatform().name().toLowerCase(Locale.ROOT) + " server version " + version.getVersion() + " with newly compiled plugin jar artifact.");

it.getPlatform().set(version.getPlatform());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

package org.screamingsandals.gradle.run;

import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.gradle.api.Action;
import org.gradle.api.file.RegularFile;
import org.gradle.api.provider.Provider;
Expand All @@ -37,15 +33,17 @@
import java.util.List;
import java.util.Locale;

@Data
@RequiredArgsConstructor(onConstructor_ = {@Inject})
public class RunTestServerExtension {
@Getter(AccessLevel.NONE)
private final @NotNull ProviderFactory providers;
private @NotNull List<@NotNull Version> versions = new ArrayList<>();
private @Nullable Provider<RegularFile> pluginJar;
private @NotNull String testingDirectory = "test-environment";

@Inject
public RunTestServerExtension(@NotNull ProviderFactory providers) {
this.providers = providers;
}

public @NotNull Version version(@NotNull Version version) {
this.versions.add(version);
return version;
Expand All @@ -67,7 +65,7 @@ public class RunTestServerExtension {
return server;
}

public @NotNull MultipleVersions versions(@NotNull Platform platform, @NotNull String @NotNull... versions) {
public @NotNull MultipleVersions versions(@NotNull Platform platform, @NotNull String @NotNull ... versions) {
var list = new ArrayList<Version>();
for (var version : versions) {
list.add(version(platform, version));
Expand Down Expand Up @@ -97,7 +95,7 @@ public class RunTestServerExtension {
return version(Platform.PAPER, version, callback);
}

public @NotNull MultipleVersions paperVersions(@NotNull String @NotNull... versions) {
public @NotNull MultipleVersions paperVersions(@NotNull String @NotNull ... versions) {
return versions(Platform.PAPER, versions);
}

Expand All @@ -121,4 +119,35 @@ public void pluginJar(@NotNull File pluginJar) {
public void testingDirectory(@NotNull String testingDirectory) {
this.testingDirectory = testingDirectory;
}

public @NotNull List<@NotNull Version> getVersions() {
return this.versions;
}

public @Nullable Provider<RegularFile> getPluginJar() {
return this.pluginJar;
}

public @NotNull String getTestingDirectory() {
return this.testingDirectory;
}

public void setVersions(@NotNull List<@NotNull Version> versions) {
this.versions = versions;
}

public void setPluginJar(@Nullable Provider<RegularFile> pluginJar) {
this.pluginJar = pluginJar;
}

public void setTestingDirectory(@NotNull String testingDirectory) {
this.testingDirectory = testingDirectory;
}

public @NotNull String toString() {
return "RunTestServerExtension(providers=" + this.providers
+ ", versions=" + this.versions
+ ", pluginJar=" + this.pluginJar
+ ", testingDirectory=" + this.testingDirectory + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.screamingsandals.gradle.run.api;

import com.google.gson.Gson;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
Expand All @@ -30,14 +29,17 @@
import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
public class Bibliothek {
private final @NotNull String baseUrl;
private final @NotNull HttpClient httpClient = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.NORMAL)
.build();
private final @NotNull Gson gson = new Gson();

public Bibliothek(@NotNull String baseUrl) {
this.baseUrl = baseUrl;
}

public int getLatestBuild(@NotNull String project, @NotNull String version) throws URISyntaxException {
var request = HttpRequest.newBuilder()
.uri(new URI(this.baseUrl + "/v2/projects/" + project + "/versions/" + version))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@

package org.screamingsandals.gradle.run.config;

import lombok.Data;
import org.jetbrains.annotations.NotNull;

import java.util.List;

@Data
public class MultipleServerProperties implements ServerProperties {
private final @NotNull List<@NotNull Version> versions;

public MultipleServerProperties(@NotNull List<@NotNull Version> versions) {
this.versions = versions;
}

public void property(@NotNull String key, @NotNull String value) {
for (var version : versions) {
version.getServerProperties().property(key, value);
Expand All @@ -42,4 +44,8 @@ public void onlineMode(boolean onlineMode) {
version.getServerProperties().onlineMode(onlineMode);
}
}

public @NotNull String toString() {
return "MultipleServerProperties(versions=" + this.versions + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@

package org.screamingsandals.gradle.run.config;

import lombok.RequiredArgsConstructor;
import org.gradle.api.Action;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

@RequiredArgsConstructor
public class MultipleVersions implements Iterable<@NotNull Version> {
private final @NotNull List<@NotNull Version> versions;

public void args(@NotNull String @NotNull... args) {
public MultipleVersions(@NotNull List<@NotNull Version> versions) {
this.versions = versions;
}

public void args(@NotNull String @NotNull ... args) {
for (var version : versions) {
version.args(args);
}
Expand All @@ -40,7 +42,7 @@ public void args(@NotNull List<@NotNull String> args) {
}
}

public void jvmArgs(@NotNull String @NotNull... jvmArgs) {
public void jvmArgs(@NotNull String @NotNull ... jvmArgs) {
for (var version : versions) {
version.jvmArgs(jvmArgs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@

package org.screamingsandals.gradle.run.config;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;
import org.screamingsandals.gradle.run.installer.Installer;
import org.screamingsandals.gradle.run.installer.BibliothekInstaller;

@RequiredArgsConstructor
@Getter
@Accessors(fluent = true)
public enum Platform {
PAPER(true, true, "plugins", true) {
@Override
Expand All @@ -45,5 +39,28 @@ public enum Platform {
private final @NotNull String pluginDirName;
private final boolean supportsPluginAsParameter;

Platform(boolean supportsServerProperties, boolean hasEula, @NotNull String pluginDirName, boolean supportsPluginAsParameter) {
this.supportsServerProperties = supportsServerProperties;
this.hasEula = hasEula;
this.pluginDirName = pluginDirName;
this.supportsPluginAsParameter = supportsPluginAsParameter;
}

public abstract @NotNull Installer obtainInstaller();

public boolean supportsServerProperties() {
return this.supportsServerProperties;
}

public boolean hasEula() {
return this.hasEula;
}

public @NotNull String pluginDirName() {
return this.pluginDirName;
}

public boolean supportsPluginAsParameter() {
return this.supportsPluginAsParameter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

package org.screamingsandals.gradle.run.config;

import lombok.Getter;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

@Getter
@ApiStatus.Internal
public class SingleServerProperties implements ServerProperties {
private final @NotNull Map<@NotNull String, String> serverProperties = new HashMap<>();
Expand All @@ -39,4 +37,8 @@ public void port(int port) {
public void onlineMode(boolean onlineMode) {
serverProperties.put("online-mode", Boolean.toString(onlineMode));
}

public @NotNull Map<@NotNull String, String> getServerProperties() {
return this.serverProperties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.screamingsandals.gradle.run.config;

import lombok.Data;
import org.gradle.api.Action;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -25,7 +24,6 @@
import java.util.Arrays;
import java.util.List;

@Data
public class Version {
private final @NotNull Platform platform;
private final @NotNull String version;
Expand Down Expand Up @@ -59,19 +57,60 @@ public void serverProperties(@NotNull Action<@NotNull ServerProperties> callback
callback.execute(serverProperties);
}

public void args(@NotNull String @NotNull... args) {
public void args(@NotNull String @NotNull ... args) {
this.args = Arrays.asList(args);
}

public void args(@NotNull List<@NotNull String> args) {
this.args = new ArrayList<>(args);
}

public void jvmArgs(@NotNull String @NotNull... jvmArgs) {
public void jvmArgs(@NotNull String @NotNull ... jvmArgs) {
this.jvmArgs = Arrays.asList(jvmArgs);
}

public void jvmArgs(@NotNull List<@NotNull String> jvmArgs) {
this.jvmArgs = new ArrayList<>(jvmArgs);
}

public @NotNull Platform getPlatform() {
return this.platform;
}

public @NotNull String getVersion() {
return this.version;
}

public @NotNull String getSubDirectory() {
return this.subDirectory;
}

public @NotNull List<@NotNull String> getArgs() {
return this.args;
}

public @NotNull List<@NotNull String> getJvmArgs() {
return this.jvmArgs;
}

public void setSubDirectory(@NotNull String subDirectory) {
this.subDirectory = subDirectory;
}

public void setArgs(@NotNull List<@NotNull String> args) {
this.args = args;
}

public void setJvmArgs(@NotNull List<@NotNull String> jvmArgs) {
this.jvmArgs = jvmArgs;
}

public @NotNull String toString() {
return "Version(platform=" + this.platform
+ ", version=" + this.version
+ ", subDirectory=" + this.subDirectory
+ ", serverProperties=" + this.serverProperties
+ ", args=" + this.args
+ ", jvmArgs=" + this.jvmArgs + ")";
}
}
Loading

0 comments on commit 2125c71

Please sign in to comment.