From a3b3fe2edef2ab049339efd8e1209a84e1c33dcc Mon Sep 17 00:00:00 2001 From: Emma Triphora Date: Fri, 10 Feb 2023 17:50:00 -0500 Subject: [PATCH 1/2] Convert everything to tabs --- .editorconfig | 3 +- build.gradle | 68 +- fg/build.gradle | 56 +- loom/build.gradle | 42 +- loom/src/main/resources/fabric.mod.json | 8 +- settings.gradle | 20 +- .../java/com/modrinth/minotaur/Minotaur.java | 139 ++-- .../modrinth/minotaur/ModrinthExtension.java | 350 ++++++----- .../minotaur/TaskModrinthSyncBody.java | 78 +-- .../modrinth/minotaur/TaskModrinthUpload.java | 365 +++++------ src/main/java/com/modrinth/minotaur/Util.java | 158 ++--- .../minotaur/dependencies/Dependency.java | 184 +++--- .../minotaur/dependencies/DependencyType.java | 68 +- .../minotaur/dependencies/ModDependency.java | 64 +- .../dependencies/VersionDependency.java | 140 ++--- .../dependencies/container/DependencyDSL.java | 124 ++-- .../container/NamedDependency.java | 104 +-- .../container/NamedDependencyContainer.java | 188 +++--- .../minotaur/request/VersionType.java | 31 +- .../minotaur/responses/ResponseUpload.java | 594 +++++++++--------- 20 files changed, 1396 insertions(+), 1388 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0716f14..855005d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,8 +4,9 @@ root = true end_of_line = lf insert_final_newline = true charset = utf-8 -indent_style = space +indent_style = tab indent_size = 4 [*.yml] indent_size = 2 +indent_style = space diff --git a/build.gradle b/build.gradle index 03d270b..0dfca3d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.gradle.plugin-publish' version '1.1.0' + id 'com.gradle.plugin-publish' version '1.1.0' } version = '2.7.0-beta.3' @@ -13,55 +13,55 @@ sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 repositories { - mavenCentral() + mavenCentral() } dependencies { - compileOnly gradleApi() - compileOnly group: 'org.jetbrains', name: 'annotations', version: '+' - //noinspection VulnerableLibrariesLocal - api group: 'dev.masecla', name: 'Modrinth4J', version: '2.0.0' + compileOnly gradleApi() + compileOnly group: 'org.jetbrains', name: 'annotations', version: '+' + //noinspection VulnerableLibrariesLocal + api group: 'dev.masecla', name: 'Modrinth4J', version: '2.0.0' } gradlePlugin { - plugins { - minotaur { - id = 'com.modrinth.minotaur' - implementationClass = 'com.modrinth.minotaur.Minotaur' - displayName = 'Minotaur' - } - } + plugins { + minotaur { + id = 'com.modrinth.minotaur' + implementationClass = 'com.modrinth.minotaur.Minotaur' + displayName = 'Minotaur' + } + } } pluginBundle { - website = 'https://modrinth.com' - vcsUrl = 'https://github.com/modrinth/minotaur' - description = 'Modrinth plugin for publishing builds to the website!' - tags = ['modrinth', 'publish', 'mods', 'minecraft'] + website = 'https://modrinth.com' + vcsUrl = 'https://github.com/modrinth/minotaur' + description = 'Modrinth plugin for publishing builds to the website!' + tags = ['modrinth', 'publish', 'mods', 'minecraft'] } jar { - manifest { - attributes([ - 'Timestamp' : System.currentTimeMillis(), - 'Specification-Title' : project.archivesBaseName, - 'Specification-Vendor' : vendor, - 'Specification-Version' : project.version, - 'Implementation-Title' : project.archivesBaseName, - 'Implementation-Version' : project.version, - 'Implementation-Vendor' : vendor, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})" - ]) - } + manifest { + attributes([ + 'Timestamp' : System.currentTimeMillis(), + 'Specification-Title' : project.archivesBaseName, + 'Specification-Vendor' : vendor, + 'Specification-Version' : project.version, + 'Implementation-Title' : project.archivesBaseName, + 'Implementation-Version' : project.version, + 'Implementation-Vendor' : vendor, + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})" + ]) + } } java { - withSourcesJar() - withJavadocJar() + withSourcesJar() + withJavadocJar() } tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" - it.options.release.set(8) + it.options.encoding = "UTF-8" + it.options.release.set(8) } diff --git a/fg/build.gradle b/fg/build.gradle index e29ce9e..8570399 100644 --- a/fg/build.gradle +++ b/fg/build.gradle @@ -1,16 +1,16 @@ buildscript { - repositories { - maven { url = 'https://files.minecraftforge.net/maven' } - } - dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.+', changing: true - } + repositories { + maven { url = 'https://files.minecraftforge.net/maven' } + } + dependencies { + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.+', changing: true + } } plugins { - id "com.modrinth.minotaur" version "2.+" - id "java" - id "idea" + id "com.modrinth.minotaur" version "2.+" + id "java" + id "idea" } apply plugin: 'net.minecraftforge.gradle' @@ -19,11 +19,11 @@ version = "1.0.371" group = "com.modrinth.minotaur" minecraft { - mappings channel: "official", version: "1.18.1" + mappings channel: "official", version: "1.18.1" } dependencies { - minecraft "net.minecraftforge:forge:1.18.1-39.0.9" + minecraft "net.minecraftforge:forge:1.18.1-39.0.9" } java.withSourcesJar() @@ -33,24 +33,24 @@ import com.modrinth.minotaur.dependencies.ModDependency import com.modrinth.minotaur.dependencies.VersionDependency modrinth { - apiUrl = STAGING_API_URL - projectId = "fred-3" - uploadFile = jar - additionalFiles = [project.file("build/libs/fg-$version-sources.jar")] - versionType = "beta" - dependencies = [ - new ModDependency("test-project", "optional"), - new VersionDependency("CE5sWFeF", DependencyType.INCOMPATIBLE) - ] - dependencies { - required.project "corrupted" - optional.version "UakHulqw" - incompatible.version "kdIr8lsr", "b1.2+mod" - embedded.project "sbbGxWge" - } - debugMode = true + apiUrl = STAGING_API_URL + projectId = "fred-3" + uploadFile = jar + additionalFiles = [project.file("build/libs/fg-$version-sources.jar")] + versionType = "beta" + dependencies = [ + new ModDependency("test-project", "optional"), + new VersionDependency("CE5sWFeF", DependencyType.INCOMPATIBLE) + ] + dependencies { + required.project "corrupted" + optional.version "UakHulqw" + incompatible.version "kdIr8lsr", "b1.2+mod" + embedded.project "sbbGxWge" + } + debugMode = true } tasks.modrinth.doLast { - if (!modrinth.debugMode && tasks.modrinth.wasUploadSuccessful()) println tasks.modrinth.uploadInfo.id + if (!modrinth.debugMode && tasks.modrinth.wasUploadSuccessful()) println tasks.modrinth.uploadInfo.id } diff --git a/loom/build.gradle b/loom/build.gradle index baa5af8..6ef5887 100644 --- a/loom/build.gradle +++ b/loom/build.gradle @@ -1,15 +1,15 @@ plugins { - id "fabric-loom" version "1.0.+" - id "com.modrinth.minotaur" version "2.+" + id "fabric-loom" version "1.0.+" + id "com.modrinth.minotaur" version "2.+" } version = "2.7.0.3" group = "com.modrinth.minotaur" dependencies { - minecraft "com.mojang:minecraft:1.17.1" - mappings "net.fabricmc:yarn:1.17.1+build.65:v2" - modImplementation "net.fabricmc:fabric-loader:0.12.12" + minecraft "com.mojang:minecraft:1.17.1" + mappings "net.fabricmc:yarn:1.17.1+build.65:v2" + modImplementation "net.fabricmc:fabric-loader:0.12.12" } java.withSourcesJar() @@ -19,20 +19,20 @@ import com.modrinth.minotaur.dependencies.ModDependency import com.modrinth.minotaur.dependencies.VersionDependency modrinth { - apiUrl = STAGING_API_URL - projectId = "fred-3" - uploadFile = remapJar - additionalFiles = [project.file("build/libs/loom-$version-sources.jar")] - versionType = "alpha" - dependencies = [ - new ModDependency("test-project", "optional"), - new VersionDependency("CE5sWFeF", DependencyType.INCOMPATIBLE) - ] - dependencies { - required.project "corrupted" - optional.version "UakHulqw" - incompatible.version "kdIr8lsr", "b1.2+mod" - embedded.project "sbbGxWge" - } - debugMode = true + apiUrl = STAGING_API_URL + projectId = "fred-3" + uploadFile = remapJar + additionalFiles = [project.file("build/libs/loom-$version-sources.jar")] + versionType = "alpha" + dependencies = [ + new ModDependency("test-project", "optional"), + new VersionDependency("CE5sWFeF", DependencyType.INCOMPATIBLE) + ] + dependencies { + required.project "corrupted" + optional.version "UakHulqw" + incompatible.version "kdIr8lsr", "b1.2+mod" + embedded.project "sbbGxWge" + } + debugMode = true } diff --git a/loom/src/main/resources/fabric.mod.json b/loom/src/main/resources/fabric.mod.json index c350a77..76b0bcb 100644 --- a/loom/src/main/resources/fabric.mod.json +++ b/loom/src/main/resources/fabric.mod.json @@ -1,5 +1,5 @@ { - "schemaVersion": 1, - "id": "test", - "version": "" -} \ No newline at end of file + "schemaVersion": 1, + "id": "test", + "version": "" +} diff --git a/settings.gradle b/settings.gradle index 503d629..0c794d6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,15 +1,15 @@ pluginManagement { - repositories { - mavenLocal() - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - gradlePluginPortal() - mavenCentral() - } + repositories { + mavenLocal() + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + mavenCentral() + } } rootProject.name = 'Minotaur' if (!System.getenv().EXCLUDE_SUBPROJECTS) { - include 'fg', 'loom' + include 'fg', 'loom' } diff --git a/src/main/java/com/modrinth/minotaur/Minotaur.java b/src/main/java/com/modrinth/minotaur/Minotaur.java index cff0978..c696684 100644 --- a/src/main/java/com/modrinth/minotaur/Minotaur.java +++ b/src/main/java/com/modrinth/minotaur/Minotaur.java @@ -21,84 +21,85 @@ * The main class for Minotaur. */ public class Minotaur implements Plugin { - /** - * Creates the {@link ModrinthExtension} for the project and registers the {@code modrinth} and - * {@code modrinthSyncBody} tasks. - * @param project The Gradle project which Minotaur is applied to - */ - @Override - public void apply(final Project project) { - Path path = project.getRootProject().getProjectDir().toPath().resolve(".gradle").resolve("minotaur"); - if (Files.notExists(path)) { - try { - Files.createDirectories(path); - } catch (IOException e) { - throw new UncheckedIOException("Could not create path at " + path.toAbsolutePath(), e); - } - } - File warningFile = path.resolve("2.7.0-warning-shown").toFile(); - if (!warningFile.exists()) { - project.getLogger().warn("\n[Minotaur Warning] You are running a version of Minotaur that may contain " + - "unintentional breaking changes.\n[Minotaur Warning] If a build of yours worked in v2.6.0 but broke in " + - "v2.7.0, PLEASE report this immediately either via emailing support@modrinth.com or by opening a GitHub " + - "issue on https://github.com/modrinth/minotaur/issues.\n[Minotaur Warning] This warning will not be " + - "shown again.\n"); - try { - //noinspection ResultOfMethodCallIgnored - warningFile.createNewFile(); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } + /** + * Creates the {@link ModrinthExtension} for the project and registers the {@code modrinth} and + * {@code modrinthSyncBody} tasks. + * + * @param project The Gradle project which Minotaur is applied to + */ + @Override + public void apply(final Project project) { + Path path = project.getRootProject().getProjectDir().toPath().resolve(".gradle").resolve("minotaur"); + if (Files.notExists(path)) { + try { + Files.createDirectories(path); + } catch (IOException e) { + throw new UncheckedIOException("Could not create path at " + path.toAbsolutePath(), e); + } + } + File warningFile = path.resolve("2.7.0-warning-shown").toFile(); + if (!warningFile.exists()) { + project.getLogger().warn("\n[Minotaur Warning] You are running a version of Minotaur that may contain " + + "unintentional breaking changes.\n[Minotaur Warning] If a build of yours worked in v2.6.0 but broke in " + + "v2.7.0, PLEASE report this immediately either via emailing support@modrinth.com or by opening a GitHub " + + "issue on https://github.com/modrinth/minotaur/issues.\n[Minotaur Warning] This warning will not be " + + "shown again.\n"); + try { + //noinspection ResultOfMethodCallIgnored + warningFile.createNewFile(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } - project.getExtensions().create("modrinth", ModrinthExtension.class, project); - project.getLogger().debug("Created the `modrinth` extension."); + project.getExtensions().create("modrinth", ModrinthExtension.class, project); + project.getLogger().debug("Created the `modrinth` extension."); - TaskContainer tasks = project.getTasks(); - tasks.register("modrinth", TaskModrinthUpload.class, task -> { - task.setGroup("publishing"); - task.setDescription("Upload project to Modrinth"); - task.dependsOn(tasks.named("assemble")); - task.mustRunAfter(tasks.named("build")); - }); - project.getLogger().debug("Registered the `modrinth` task."); + TaskContainer tasks = project.getTasks(); + tasks.register("modrinth", TaskModrinthUpload.class, task -> { + task.setGroup("publishing"); + task.setDescription("Upload project to Modrinth"); + task.dependsOn(tasks.named("assemble")); + task.mustRunAfter(tasks.named("build")); + }); + project.getLogger().debug("Registered the `modrinth` task."); - tasks.register("modrinthSyncBody", TaskModrinthSyncBody.class, task -> { - task.setGroup("publishing"); - task.setDescription("Sync project description to Modrinth"); - }); - project.getLogger().debug("Registered the `modrinthSyncBody` task."); + tasks.register("modrinthSyncBody", TaskModrinthSyncBody.class, task -> { + task.setGroup("publishing"); + task.setDescription("Sync project description to Modrinth"); + }); + project.getLogger().debug("Registered the `modrinthSyncBody` task."); - project.afterEvaluate(evaluatedProject -> { - ModrinthExtension ext = ext(evaluatedProject); + project.afterEvaluate(evaluatedProject -> { + ModrinthExtension ext = ext(evaluatedProject); - if (!ext.getAutoAddDependsOn().getOrElse(true)) { - return; - } + if (!ext.getAutoAddDependsOn().getOrElse(true)) { + return; + } - Task task = evaluatedProject.getTasks().getByName("modrinth"); - List candidateAATs = new ArrayList<>(); + Task task = evaluatedProject.getTasks().getByName("modrinth"); + List candidateAATs = new ArrayList<>(); - candidateAATs.add(ext.getUploadFile().getOrNull()); - candidateAATs.addAll(ext.getAdditionalFiles().get()); + candidateAATs.add(ext.getUploadFile().getOrNull()); + candidateAATs.addAll(ext.getAdditionalFiles().get()); - candidateAATs.forEach(file -> { - if (file == null) { - return; - } + candidateAATs.forEach(file -> { + if (file == null) { + return; + } - // Try to get an AbstractArchiveTask from the input file by whatever means possible. - if (file instanceof AbstractArchiveTask) { - task.dependsOn(file); - } else if (file instanceof TaskProvider && - ((TaskProvider) file).get() instanceof AbstractArchiveTask) { - task.dependsOn(((TaskProvider) file).get()); - } - }); + // Try to get an AbstractArchiveTask from the input file by whatever means possible. + if (file instanceof AbstractArchiveTask) { + task.dependsOn(file); + } else if (file instanceof TaskProvider && + ((TaskProvider) file).get() instanceof AbstractArchiveTask) { + task.dependsOn(((TaskProvider) file).get()); + } + }); - evaluatedProject.getLogger().debug("Made the `modrinth` task depend on the upload file and additional files."); - }); + evaluatedProject.getLogger().debug("Made the `modrinth` task depend on the upload file and additional files."); + }); - project.getLogger().debug("Successfully applied the Modrinth plugin!"); - } + project.getLogger().debug("Successfully applied the Modrinth plugin!"); + } } diff --git a/src/main/java/com/modrinth/minotaur/ModrinthExtension.java b/src/main/java/com/modrinth/minotaur/ModrinthExtension.java index 00d8b68..df11447 100644 --- a/src/main/java/com/modrinth/minotaur/ModrinthExtension.java +++ b/src/main/java/com/modrinth/minotaur/ModrinthExtension.java @@ -12,178 +12,180 @@ * {...}} block in the buildscript. */ public class ModrinthExtension extends DependencyDSL { - private final Property apiUrl, token, projectId, versionNumber, versionName, changelog, versionType, syncBodyFrom; - private final Property uploadFile; - private final ListProperty additionalFiles; - private final ListProperty gameVersions, loaders; - private final ListProperty dependencies; - private final Property failSilently, detectLoaders, debugMode, autoAddDependsOn; - - /** - * The default API URL in use for uploading. Exposed as a fallback utility. - */ - public static final String DEFAULT_API_URL = "https://api.modrinth.com/v2"; - /** - * The staging API URL if desired for testing. - */ - public static final String STAGING_API_URL = "https://staging-api.modrinth.com/v2"; - /** - * The default token in use for uploading. Exposed as a fallback utility. - */ - public static final String DEFAULT_TOKEN = System.getenv("MODRINTH_TOKEN"); - /** - * The default changelog if one was not provided. Exposed as a fallback utility. - */ - public static final String DEFAULT_CHANGELOG = "No changelog was specified."; - /** - * The default release type if one was not provided. Exposed as a fallback utility. - */ - public static final String DEFAULT_VERSION_TYPE = "release"; - - /** - * @param project The Gradle project that the extension is applied to - */ - public ModrinthExtension(Project project) { - super(project.getObjects()); - apiUrl = project.getObjects().property(String.class).convention(DEFAULT_API_URL); - token = project.getObjects().property(String.class).convention(DEFAULT_TOKEN); - projectId = project.getObjects().property(String.class); - versionNumber = project.getObjects().property(String.class); - versionName = project.getObjects().property(String.class); - changelog = project.getObjects().property(String.class).convention(DEFAULT_CHANGELOG); - uploadFile = project.getObjects().property(Object.class); - additionalFiles = project.getObjects().listProperty(Object.class).empty(); - versionType = project.getObjects().property(String.class).convention(DEFAULT_VERSION_TYPE); - gameVersions = project.getObjects().listProperty(String.class).empty(); - loaders = project.getObjects().listProperty(String.class).empty(); - dependencies = project.getObjects().listProperty(Dependency.class).empty(); - failSilently = project.getObjects().property(Boolean.class).convention(false); - detectLoaders = project.getObjects().property(Boolean.class).convention(true); - debugMode = project.getObjects().property(Boolean.class).convention(false); - syncBodyFrom = project.getObjects().property(String.class); - autoAddDependsOn = project.getObjects().property(Boolean.class).convention(true); - } - - /** - * This should not be changed unless you know what you're doing. Its main use case is for debug, development, or - * advanced user configurations. - * @return The URL used for communicating with Modrinth. - */ - public Property getApiUrl() { - return this.apiUrl; - } - - /** - * Make sure you keep this private! - * @return The API token used to communicate with Modrinth. - */ - public Property getToken() { - return this.token; - } - - /** - * @return The ID of the project to upload the file to. - */ - public Property getProjectId() { - return this.projectId; - } - - /** - * @return The version number of the project being uploaded. - */ - public Property getVersionNumber() { - return this.versionNumber; - } - - /** - * @return The version name of the project being uploaded. Defaults to the version number. - */ - public Property getVersionName() { - return this.versionName; - } - - /** - * @return A list or summary of each of the changes made to the project since the last update. - */ - public Property getChangelog() { - return this.changelog; - } - - /** - * @return The upload artifact file. This can be any object type that is resolvable by - * {@link Util#resolveFile(Project, Object)}. - */ - public Property getUploadFile() { - return this.uploadFile; - } - - /** - * @return Any additional files to be uploaded to the new version. - */ - public ListProperty getAdditionalFiles() { - return this.additionalFiles; - } - - /** - * @return The version type for the project. See {@link VersionType}. - */ - public Property getVersionType() { - return this.versionType; - } - - /** - * @return The game versions of the game the version supports. - */ - public ListProperty getGameVersions() { - return this.gameVersions; - } - - /** - * @return The mod loaders of the game the version supports. - */ - public ListProperty getLoaders() { - return this.loaders; - } - - /** - * @return The dependencies of the version. - */ - public ListProperty getDependencies() { - return this.dependencies; - } - - /** - * @return Whether the build should continue even if the upload failed. - */ - public Property getFailSilently() { - return this.failSilently; - } - - /** - * @return Whether the plugin will try to define loaders based on other plugins in the project environment. - */ - public Property getDetectLoaders() { - return this.detectLoaders; - } - - /** - * @return Whether the plugin is in debug mode. Debug mode does not actually upload any files. - */ - public Property getDebugMode() { - return this.debugMode; - } - - /** - * @return The file to sync the project's body description from - */ - public Property getSyncBodyFrom() { - return this.syncBodyFrom; - } - - /** - * @return Whether to automatically add the `dependsOn` information for upload files - */ - public Property getAutoAddDependsOn() { - return autoAddDependsOn; - } + private final Property apiUrl, token, projectId, versionNumber, versionName, changelog, versionType, syncBodyFrom; + private final Property uploadFile; + private final ListProperty additionalFiles; + private final ListProperty gameVersions, loaders; + private final ListProperty dependencies; + private final Property failSilently, detectLoaders, debugMode, autoAddDependsOn; + + /** + * The default API URL in use for uploading. Exposed as a fallback utility. + */ + public static final String DEFAULT_API_URL = "https://api.modrinth.com/v2"; + /** + * The staging API URL if desired for testing. + */ + public static final String STAGING_API_URL = "https://staging-api.modrinth.com/v2"; + /** + * The default token in use for uploading. Exposed as a fallback utility. + */ + public static final String DEFAULT_TOKEN = System.getenv("MODRINTH_TOKEN"); + /** + * The default changelog if one was not provided. Exposed as a fallback utility. + */ + public static final String DEFAULT_CHANGELOG = "No changelog was specified."; + /** + * The default release type if one was not provided. Exposed as a fallback utility. + */ + public static final String DEFAULT_VERSION_TYPE = "release"; + + /** + * @param project The Gradle project that the extension is applied to + */ + public ModrinthExtension(Project project) { + super(project.getObjects()); + apiUrl = project.getObjects().property(String.class).convention(DEFAULT_API_URL); + token = project.getObjects().property(String.class).convention(DEFAULT_TOKEN); + projectId = project.getObjects().property(String.class); + versionNumber = project.getObjects().property(String.class); + versionName = project.getObjects().property(String.class); + changelog = project.getObjects().property(String.class).convention(DEFAULT_CHANGELOG); + uploadFile = project.getObjects().property(Object.class); + additionalFiles = project.getObjects().listProperty(Object.class).empty(); + versionType = project.getObjects().property(String.class).convention(DEFAULT_VERSION_TYPE); + gameVersions = project.getObjects().listProperty(String.class).empty(); + loaders = project.getObjects().listProperty(String.class).empty(); + dependencies = project.getObjects().listProperty(Dependency.class).empty(); + failSilently = project.getObjects().property(Boolean.class).convention(false); + detectLoaders = project.getObjects().property(Boolean.class).convention(true); + debugMode = project.getObjects().property(Boolean.class).convention(false); + syncBodyFrom = project.getObjects().property(String.class); + autoAddDependsOn = project.getObjects().property(Boolean.class).convention(true); + } + + /** + * This should not be changed unless you know what you're doing. Its main use case is for debug, development, or + * advanced user configurations. + * + * @return The URL used for communicating with Modrinth. + */ + public Property getApiUrl() { + return this.apiUrl; + } + + /** + * Make sure you keep this private! + * + * @return The API token used to communicate with Modrinth. + */ + public Property getToken() { + return this.token; + } + + /** + * @return The ID of the project to upload the file to. + */ + public Property getProjectId() { + return this.projectId; + } + + /** + * @return The version number of the project being uploaded. + */ + public Property getVersionNumber() { + return this.versionNumber; + } + + /** + * @return The version name of the project being uploaded. Defaults to the version number. + */ + public Property getVersionName() { + return this.versionName; + } + + /** + * @return A list or summary of each of the changes made to the project since the last update. + */ + public Property getChangelog() { + return this.changelog; + } + + /** + * @return The upload artifact file. This can be any object type that is resolvable by + * {@link Util#resolveFile(Project, Object)}. + */ + public Property getUploadFile() { + return this.uploadFile; + } + + /** + * @return Any additional files to be uploaded to the new version. + */ + public ListProperty getAdditionalFiles() { + return this.additionalFiles; + } + + /** + * @return The version type for the project. See {@link VersionType}. + */ + public Property getVersionType() { + return this.versionType; + } + + /** + * @return The game versions of the game the version supports. + */ + public ListProperty getGameVersions() { + return this.gameVersions; + } + + /** + * @return The mod loaders of the game the version supports. + */ + public ListProperty getLoaders() { + return this.loaders; + } + + /** + * @return The dependencies of the version. + */ + public ListProperty getDependencies() { + return this.dependencies; + } + + /** + * @return Whether the build should continue even if the upload failed. + */ + public Property getFailSilently() { + return this.failSilently; + } + + /** + * @return Whether the plugin will try to define loaders based on other plugins in the project environment. + */ + public Property getDetectLoaders() { + return this.detectLoaders; + } + + /** + * @return Whether the plugin is in debug mode. Debug mode does not actually upload any files. + */ + public Property getDebugMode() { + return this.debugMode; + } + + /** + * @return The file to sync the project's body description from + */ + public Property getSyncBodyFrom() { + return this.syncBodyFrom; + } + + /** + * @return Whether to automatically add the `dependsOn` information for upload files + */ + public Property getAutoAddDependsOn() { + return autoAddDependsOn; + } } diff --git a/src/main/java/com/modrinth/minotaur/TaskModrinthSyncBody.java b/src/main/java/com/modrinth/minotaur/TaskModrinthSyncBody.java index 4e69991..fd73d8f 100644 --- a/src/main/java/com/modrinth/minotaur/TaskModrinthSyncBody.java +++ b/src/main/java/com/modrinth/minotaur/TaskModrinthSyncBody.java @@ -17,48 +17,48 @@ * A task used to communicate with Modrinth for the purpose of syncing project body with, for example, a README. */ public class TaskModrinthSyncBody extends DefaultTask { - /** - * Uploads a body to a project, both of which are specified in {@link ModrinthExtension}. - */ - @TaskAction - public void apply() { - getLogger().lifecycle("Minotaur: {}", getClass().getPackage().getImplementationVersion()); - ModrinthExtension ext = ext(getProject()); - try { - if (ext.getSyncBodyFrom() == null) { - throw new GradleException("Sync project body task was called, but `syncBodyFrom` was null!"); - } + /** + * Uploads a body to a project, both of which are specified in {@link ModrinthExtension}. + */ + @TaskAction + public void apply() { + getLogger().lifecycle("Minotaur: {}", getClass().getPackage().getImplementationVersion()); + ModrinthExtension ext = ext(getProject()); + try { + if (ext.getSyncBodyFrom() == null) { + throw new GradleException("Sync project body task was called, but `syncBodyFrom` was null!"); + } - ModrinthAPI api = api(getProject()); + ModrinthAPI api = api(getProject()); - // This isn't used until later, but resolve it early anyway to throw invalid IDs early - String id = Objects.requireNonNull( - api.projects().getProjectIdBySlug(ext.getProjectId().get()).join(), - "Failed to resolve project ID: " + ext.getProjectId().get() - ); - getLogger().debug("Syncing body to project {}", id); + // This isn't used until later, but resolve it early anyway to throw invalid IDs early + String id = Objects.requireNonNull( + api.projects().getProjectIdBySlug(ext.getProjectId().get()).join(), + "Failed to resolve project ID: " + ext.getProjectId().get() + ); + getLogger().debug("Syncing body to project {}", id); - Pattern excludeRegex = Pattern.compile(".*?", Pattern.DOTALL); - String body = ext.getSyncBodyFrom().get().replaceAll("\r\n", "\n"); - body = excludeRegex.matcher(body).replaceAll(""); + Pattern excludeRegex = Pattern.compile(".*?", Pattern.DOTALL); + String body = ext.getSyncBodyFrom().get().replaceAll("\r\n", "\n"); + body = excludeRegex.matcher(body).replaceAll(""); - if (ext.getDebugMode().get()) { - JsonObject data = new JsonObject(); - data.addProperty("body", body); - getLogger().lifecycle("Full data to be sent for upload: {}", data); - getLogger().lifecycle("Minotaur debug mode is enabled. Not going to upload the body."); - return; - } + if (ext.getDebugMode().get()) { + JsonObject data = new JsonObject(); + data.addProperty("body", body); + getLogger().lifecycle("Full data to be sent for upload: {}", data); + getLogger().lifecycle("Minotaur debug mode is enabled. Not going to upload the body."); + return; + } - api.projects().modify(id, ProjectModifications.builder().body(body).build()).join(); - getLogger().lifecycle("Successfully synced body to project {}.", ext.getProjectId().get()); - } catch (Exception e) { - if (ext.getFailSilently().get()) { - getLogger().info("Failed to sync body to Modrinth. Check logs for more info."); - getLogger().error("Modrinth body sync failed silently.", e); - } else { - throw new GradleException("Failed to sync project body! " + e.getMessage(), e); - } - } - } + api.projects().modify(id, ProjectModifications.builder().body(body).build()).join(); + getLogger().lifecycle("Successfully synced body to project {}.", ext.getProjectId().get()); + } catch (Exception e) { + if (ext.getFailSilently().get()) { + getLogger().info("Failed to sync body to Modrinth. Check logs for more info."); + getLogger().error("Modrinth body sync failed silently.", e); + } else { + throw new GradleException("Failed to sync project body! " + e.getMessage(), e); + } + } + } } diff --git a/src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java b/src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java index e4c37cd..7265025 100644 --- a/src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java +++ b/src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java @@ -25,186 +25,187 @@ * A task used to communicate with Modrinth for the purpose of uploading build artifacts. */ public class TaskModrinthUpload extends DefaultTask { - /** - * The response from the API when the file was uploaded successfully. - */ - @Nullable - public ProjectVersion newVersion = null; - - /** - * The response from the API when the file was uploaded successfully. - * @deprecated Please use {@link #newVersion} instead - */ - @SuppressWarnings("DeprecatedIsStillUsed") - @Nullable - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "3.0.0") - public ResponseUpload uploadInfo = null; - - /** - * Checks if the upload was successful or not. - * - * @return Whether the file was successfully uploaded. - * @deprecated This check should be done manually - */ - @SuppressWarnings("unused") - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "3.0.0") - public boolean wasUploadSuccessful() { - return newVersion != null; - } - - /** - * Defines what to do when the Modrinth upload task is invoked. - *
    - *
  1. Attempts to automatically resolve various metadata items if not specified, throwing an exception if some - * things still don't have anything set
  2. - *
  3. Resolves each file or task to be uploaded, ensuring they're all valid
  4. - *
  5. Uploads these files to the Modrinth API under a new version
  6. - *
- * This is all in a try/catch block so that, if {@link ModrinthExtension#getFailSilently()} is enabled, it won't - * fail the build if it fails to upload the version to Modrinth. - */ - @TaskAction - public void apply() { - getLogger().lifecycle("Minotaur: {}", getClass().getPackage().getImplementationVersion()); - ModrinthExtension ext = ext(getProject()); - PluginManager pluginManager = getProject().getPluginManager(); - try { - ModrinthAPI api = api(getProject()); - - String id = Objects.requireNonNull(api.projects().getProjectIdBySlug(ext.getProjectId().get()).join()); - getLogger().debug("Uploading version to project {}", id); - - // Add version name if it's null - String versionNumber = resolveVersionNumber(getProject()); - if (ext.getVersionName().getOrNull() == null) { - ext.getVersionName().set(versionNumber); - } - - // Attempt to automatically resolve the loader if none were specified. - if (ext.getLoaders().get().isEmpty() && ext.getDetectLoaders().get()) { - Map pluginLoaderMap = new HashMap<>(); - pluginLoaderMap.put("net.minecraftforge.gradle", "forge"); - pluginLoaderMap.put("fabric-loom", "fabric"); - pluginLoaderMap.put("org.quiltmc.loom", "quilt"); - pluginLoaderMap.put("org.spongepowered.gradle.plugin", "sponge"); - pluginLoaderMap.put("io.papermc.paperweight.userdev", "paper"); - - pluginLoaderMap.forEach((plugin, loader) -> { - if (pluginManager.hasPlugin(plugin)) { - getLogger().debug("Adding loader {} because plugin {} was found.", loader, plugin); - ext.getLoaders().add(loader); - } - }); - } - - if (ext.getLoaders().get().isEmpty()) { - throw new GradleException("Cannot upload to Modrinth: no loaders specified!"); - } - - // Attempt to automatically resolve the game version if none were specified. - if (ext.getGameVersions().get().isEmpty()) { - if (ext.getLoaders().get().contains("forge")) { - if (pluginManager.hasPlugin("net.minecraftforge.gradle")) { - // ForgeGradle will store the game version here. - // https://github.com/MinecraftForge/ForgeGradle/blob/FG_5.0/src/userdev/java/net/minecraftforge/gradle/userdev/MinecraftUserRepo.java#L199 - String version = (String) getProject().getExtensions().getExtraProperties().get("MC_VERSION"); - assert version != null; - - getLogger().debug("Adding fallback game version {} from ForgeGradle.", version); - ext.getGameVersions().add(version); - } - } - - if (ext.getLoaders().get().contains("fabric") || ext.getLoaders().get().contains("quilt")) { - if (pluginManager.hasPlugin("fabric-loom") || pluginManager.hasPlugin("org.quiltmc.loom")) { - // Use the same method Loom uses to get the version. - // https://github.com/FabricMC/fabric-loom/blob/97f594da8e132c3d33cf39fe8d7cc0e76d84aeb6/src/main/java/net/fabricmc/loom/configuration/DependencyInfo.java#LL60C26-L60C56 - String version = getProject().getConfigurations().getByName("minecraft") - .getDependencies().iterator().next().getVersion(); - assert version != null; - - getLogger().debug("Adding fallback game version {} from Loom.", version); - ext.getGameVersions().add(version); - } - } - } - - if (ext.getGameVersions().get().isEmpty()) { - throw new GradleException("Cannot upload to Modrinth: no game versions specified!"); - } - - // Convert each of our proto-dependencies to a proper Modrinth4J ProjectDependency - List protoDependencies = new ArrayList<>(); - List dependencies = new ArrayList<>(); - protoDependencies.addAll(ext.getNamedDependenciesAsList()); - protoDependencies.addAll(ext.getDependencies().get()); - protoDependencies.stream().map(dependency -> dependency.toNew(api, ext)).forEach(dependencies::add); - - // Get each of the files, starting with the primary file - List files = new ArrayList<>(); - files.add(resolveFile(getProject(), ext.getUploadFile().get())); - - // Convert each of the Object files from the extension to a proper File - ext.getAdditionalFiles().get().forEach(file -> { - File resolvedFile = resolveFile(getProject(), file); - - // Ensure the file actually exists before trying to upload it. - if (resolvedFile == null || !resolvedFile.exists()) { - throw new GradleException("The upload file is missing or null. " + file); - } - - files.add(resolvedFile); - }); - - // Start construction of the actual request! - CreateVersionRequest data = CreateVersionRequest.builder() - .projectId(id) - .versionNumber(versionNumber) - .name(ext.getVersionName().get()) - .changelog(ext.getChangelog().get().replaceAll("\r\n", "\n")) - .versionType(VersionType.valueOf(ext.getVersionType().get().toUpperCase(Locale.ROOT))) - .gameVersions(ext.getGameVersions().get()) - .loaders(ext.getLoaders().get()) - .dependencies(dependencies) - .files(files) - .build(); - - // Return early in debug mode - if (ext.getDebugMode().get()) { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - getLogger().lifecycle("Full data to be sent for upload: {}", gson.toJson(data)); - getLogger().lifecycle("Minotaur debug mode is enabled. Not going to upload this version."); - return; - } - - // Execute the request - ProjectVersion version = api.versions().createProjectVersion(data).join(); - newVersion = version; - //noinspection deprecation - uploadInfo = new ResponseUpload(version); - - getLogger().lifecycle( - "Successfully uploaded version {} to {} ({}) as version ID {}. {}", - newVersion.getVersionNumber(), - ext.getProjectId().get(), - id, - newVersion.getId(), - String.format( - "%s/project/%s/version/%s", - ext.getApiUrl().get().replaceFirst("-?api", "").replaceFirst("/?v2/?", "").replaceFirst("//\\.", "//"), - id, - newVersion.getId() - ) - ); - } catch (Exception e) { - if (ext.getFailSilently().get()) { - getLogger().info("Failed to upload to Modrinth. Check logs for more info."); - getLogger().error("Modrinth upload failed silently.", e); - } else { - throw new GradleException("Failed to upload file to Modrinth! " + e.getMessage(), e); - } - } - } + /** + * The response from the API when the file was uploaded successfully. + */ + @Nullable + public ProjectVersion newVersion = null; + + /** + * The response from the API when the file was uploaded successfully. + * + * @deprecated Please use {@link #newVersion} instead + */ + @SuppressWarnings("DeprecatedIsStillUsed") + @Nullable + @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "3.0.0") + public ResponseUpload uploadInfo = null; + + /** + * Checks if the upload was successful or not. + * + * @return Whether the file was successfully uploaded. + * @deprecated This check should be done manually + */ + @SuppressWarnings("unused") + @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "3.0.0") + public boolean wasUploadSuccessful() { + return newVersion != null; + } + + /** + * Defines what to do when the Modrinth upload task is invoked. + *
    + *
  1. Attempts to automatically resolve various metadata items if not specified, throwing an exception if some + * things still don't have anything set
  2. + *
  3. Resolves each file or task to be uploaded, ensuring they're all valid
  4. + *
  5. Uploads these files to the Modrinth API under a new version
  6. + *
+ * This is all in a try/catch block so that, if {@link ModrinthExtension#getFailSilently()} is enabled, it won't + * fail the build if it fails to upload the version to Modrinth. + */ + @TaskAction + public void apply() { + getLogger().lifecycle("Minotaur: {}", getClass().getPackage().getImplementationVersion()); + ModrinthExtension ext = ext(getProject()); + PluginManager pluginManager = getProject().getPluginManager(); + try { + ModrinthAPI api = api(getProject()); + + String id = Objects.requireNonNull(api.projects().getProjectIdBySlug(ext.getProjectId().get()).join()); + getLogger().debug("Uploading version to project {}", id); + + // Add version name if it's null + String versionNumber = resolveVersionNumber(getProject()); + if (ext.getVersionName().getOrNull() == null) { + ext.getVersionName().set(versionNumber); + } + + // Attempt to automatically resolve the loader if none were specified. + if (ext.getLoaders().get().isEmpty() && ext.getDetectLoaders().get()) { + Map pluginLoaderMap = new HashMap<>(); + pluginLoaderMap.put("net.minecraftforge.gradle", "forge"); + pluginLoaderMap.put("fabric-loom", "fabric"); + pluginLoaderMap.put("org.quiltmc.loom", "quilt"); + pluginLoaderMap.put("org.spongepowered.gradle.plugin", "sponge"); + pluginLoaderMap.put("io.papermc.paperweight.userdev", "paper"); + + pluginLoaderMap.forEach((plugin, loader) -> { + if (pluginManager.hasPlugin(plugin)) { + getLogger().debug("Adding loader {} because plugin {} was found.", loader, plugin); + ext.getLoaders().add(loader); + } + }); + } + + if (ext.getLoaders().get().isEmpty()) { + throw new GradleException("Cannot upload to Modrinth: no loaders specified!"); + } + + // Attempt to automatically resolve the game version if none were specified. + if (ext.getGameVersions().get().isEmpty()) { + if (ext.getLoaders().get().contains("forge")) { + if (pluginManager.hasPlugin("net.minecraftforge.gradle")) { + // ForgeGradle will store the game version here. + // https://github.com/MinecraftForge/ForgeGradle/blob/FG_5.0/src/userdev/java/net/minecraftforge/gradle/userdev/MinecraftUserRepo.java#L199 + String version = (String) getProject().getExtensions().getExtraProperties().get("MC_VERSION"); + assert version != null; + + getLogger().debug("Adding fallback game version {} from ForgeGradle.", version); + ext.getGameVersions().add(version); + } + } + + if (ext.getLoaders().get().contains("fabric") || ext.getLoaders().get().contains("quilt")) { + if (pluginManager.hasPlugin("fabric-loom") || pluginManager.hasPlugin("org.quiltmc.loom")) { + // Use the same method Loom uses to get the version. + // https://github.com/FabricMC/fabric-loom/blob/97f594da8e132c3d33cf39fe8d7cc0e76d84aeb6/src/main/java/net/fabricmc/loom/configuration/DependencyInfo.java#LL60C26-L60C56 + String version = getProject().getConfigurations().getByName("minecraft") + .getDependencies().iterator().next().getVersion(); + assert version != null; + + getLogger().debug("Adding fallback game version {} from Loom.", version); + ext.getGameVersions().add(version); + } + } + } + + if (ext.getGameVersions().get().isEmpty()) { + throw new GradleException("Cannot upload to Modrinth: no game versions specified!"); + } + + // Convert each of our proto-dependencies to a proper Modrinth4J ProjectDependency + List protoDependencies = new ArrayList<>(); + List dependencies = new ArrayList<>(); + protoDependencies.addAll(ext.getNamedDependenciesAsList()); + protoDependencies.addAll(ext.getDependencies().get()); + protoDependencies.stream().map(dependency -> dependency.toNew(api, ext)).forEach(dependencies::add); + + // Get each of the files, starting with the primary file + List files = new ArrayList<>(); + files.add(resolveFile(getProject(), ext.getUploadFile().get())); + + // Convert each of the Object files from the extension to a proper File + ext.getAdditionalFiles().get().forEach(file -> { + File resolvedFile = resolveFile(getProject(), file); + + // Ensure the file actually exists before trying to upload it. + if (resolvedFile == null || !resolvedFile.exists()) { + throw new GradleException("The upload file is missing or null. " + file); + } + + files.add(resolvedFile); + }); + + // Start construction of the actual request! + CreateVersionRequest data = CreateVersionRequest.builder() + .projectId(id) + .versionNumber(versionNumber) + .name(ext.getVersionName().get()) + .changelog(ext.getChangelog().get().replaceAll("\r\n", "\n")) + .versionType(VersionType.valueOf(ext.getVersionType().get().toUpperCase(Locale.ROOT))) + .gameVersions(ext.getGameVersions().get()) + .loaders(ext.getLoaders().get()) + .dependencies(dependencies) + .files(files) + .build(); + + // Return early in debug mode + if (ext.getDebugMode().get()) { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + getLogger().lifecycle("Full data to be sent for upload: {}", gson.toJson(data)); + getLogger().lifecycle("Minotaur debug mode is enabled. Not going to upload this version."); + return; + } + + // Execute the request + ProjectVersion version = api.versions().createProjectVersion(data).join(); + newVersion = version; + //noinspection deprecation + uploadInfo = new ResponseUpload(version); + + getLogger().lifecycle( + "Successfully uploaded version {} to {} ({}) as version ID {}. {}", + newVersion.getVersionNumber(), + ext.getProjectId().get(), + id, + newVersion.getId(), + String.format( + "%s/project/%s/version/%s", + ext.getApiUrl().get().replaceFirst("-?api", "").replaceFirst("/?v2/?", "").replaceFirst("//\\.", "//"), + id, + newVersion.getId() + ) + ); + } catch (Exception e) { + if (ext.getFailSilently().get()) { + getLogger().info("Failed to upload to Modrinth. Check logs for more info."); + getLogger().error("Modrinth upload failed silently.", e); + } else { + throw new GradleException("Failed to upload file to Modrinth! " + e.getMessage(), e); + } + } + } } diff --git a/src/main/java/com/modrinth/minotaur/Util.java b/src/main/java/com/modrinth/minotaur/Util.java index 42be336..5c07b4e 100644 --- a/src/main/java/com/modrinth/minotaur/Util.java +++ b/src/main/java/com/modrinth/minotaur/Util.java @@ -18,92 +18,92 @@ */ @ApiStatus.Internal class Util { - /** - * @param project Gradle project for getting various info from - * @return A valid {@link ModrinthAPI} instance - * @throws EndpointException when the request to validate the token fails - */ - static ModrinthAPI api(Project project) throws EndpointException, NullPointerException { - ModrinthExtension ext = ext(project); - String url = ext.getApiUrl().get(); - if (url.endsWith("/")) { - url = url.substring(0, url.length() - 1); - } + /** + * @param project Gradle project for getting various info from + * @return A valid {@link ModrinthAPI} instance + * @throws EndpointException when the request to validate the token fails + */ + static ModrinthAPI api(Project project) throws EndpointException, NullPointerException { + ModrinthExtension ext = ext(project); + String url = ext.getApiUrl().get(); + if (url.endsWith("/")) { + url = url.substring(0, url.length() - 1); + } - UserAgent agent = UserAgent.builder() - .authorUsername("modrinth") - .projectName("minotaur") - .projectVersion(Util.class.getPackage().getImplementationVersion()) - .contact(ext.getProjectId().get() + "/" + resolveVersionNumber(project)) - .build(); + UserAgent agent = UserAgent.builder() + .authorUsername("modrinth") + .projectName("minotaur") + .projectVersion(Util.class.getPackage().getImplementationVersion()) + .contact(ext.getProjectId().get() + "/" + resolveVersionNumber(project)) + .build(); - String token = ext(project).getToken().get(); - ModrinthAPI api = ModrinthAPI.rateLimited(agent, url, token); + String token = ext(project).getToken().get(); + ModrinthAPI api = ModrinthAPI.rateLimited(agent, url, token); - // Ensure validity of token unless in Minotaur CI - if (token.equals("dummy_token_for_CI")) { - project.getLogger().info("Skipping token validation (GitHub repo {})", System.getenv("GITHUB_REPOSITORY")); - } else { - ModrinthUser user = api.users().getSelf().join(); - String username = Objects.requireNonNull(user.getUsername(), "Failed to resolve username from token"); - project.getLogger().debug("Signed in as user {}", username); - } + // Ensure validity of token unless in Minotaur CI + if (token.equals("dummy_token_for_CI")) { + project.getLogger().info("Skipping token validation (GitHub repo {})", System.getenv("GITHUB_REPOSITORY")); + } else { + ModrinthUser user = api.users().getSelf().join(); + String username = Objects.requireNonNull(user.getUsername(), "Failed to resolve username from token"); + project.getLogger().debug("Signed in as user {}", username); + } - return api; - } + return api; + } - /** - * @param project Gradle project for getting various info from - * @return The {@link ModrinthExtension} for the project - */ - static ModrinthExtension ext(Project project) { - return project.getExtensions().getByType(ModrinthExtension.class); - } + /** + * @param project Gradle project for getting various info from + * @return The {@link ModrinthExtension} for the project + */ + static ModrinthExtension ext(Project project) { + return project.getExtensions().getByType(ModrinthExtension.class); + } - /** - * Safely resolves the version number. - * - * @param project The Gradle project to resolve the extension and version from - * @return The extension version number if set; otherwise, the Gradle project version. - */ - static String resolveVersionNumber(Project project) { - ModrinthExtension ext = ext(project); - if (ext.getVersionNumber().getOrNull() == null) { - ext.getVersionNumber().set(project.getVersion().toString()); - } - return ext.getVersionNumber().get(); - } + /** + * Safely resolves the version number. + * + * @param project The Gradle project to resolve the extension and version from + * @return The extension version number if set; otherwise, the Gradle project version. + */ + static String resolveVersionNumber(Project project) { + ModrinthExtension ext = ext(project); + if (ext.getVersionNumber().getOrNull() == null) { + ext.getVersionNumber().set(project.getVersion().toString()); + } + return ext.getVersionNumber().get(); + } - /** - * Attempts to resolve a file using an arbitrary object provided by a user defined gradle - * task. - * - * @param in The arbitrary input object from the user. - * @return A file handle for the resolved input. If the input can not be resolved this will be null or the fallback. - */ - @Nullable - static File resolveFile(Project project, Object in) { - if (in == null) { - // If input is null we can't really do anything... - return null; - } else if (in instanceof File) { - // If the file is a Java file handle no additional handling is needed. - return (File) in; - } else if (in instanceof AbstractArchiveTask) { - // Grabs the file from an archive task. Allows build scripts to do things like the jar task directly. - return ((AbstractArchiveTask) in).getArchiveFile().get().getAsFile(); - } else if (in instanceof TaskProvider) { - // Grabs the file from an archive task wrapped in a provider. Allows Kotlin DSL buildscripts to also specify - // the jar task directly, rather than having to call #get() before running. - Object provided = ((TaskProvider) in).get(); + /** + * Attempts to resolve a file using an arbitrary object provided by a user defined gradle + * task. + * + * @param in The arbitrary input object from the user. + * @return A file handle for the resolved input. If the input can not be resolved this will be null or the fallback. + */ + @Nullable + static File resolveFile(Project project, Object in) { + if (in == null) { + // If input is null we can't really do anything... + return null; + } else if (in instanceof File) { + // If the file is a Java file handle no additional handling is needed. + return (File) in; + } else if (in instanceof AbstractArchiveTask) { + // Grabs the file from an archive task. Allows build scripts to do things like the jar task directly. + return ((AbstractArchiveTask) in).getArchiveFile().get().getAsFile(); + } else if (in instanceof TaskProvider) { + // Grabs the file from an archive task wrapped in a provider. Allows Kotlin DSL buildscripts to also specify + // the jar task directly, rather than having to call #get() before running. + Object provided = ((TaskProvider) in).get(); - // Check to see if the task provided is actually an AbstractArchiveTask. - if (provided instanceof AbstractArchiveTask) { - return ((AbstractArchiveTask) provided).getArchiveFile().get().getAsFile(); - } - } + // Check to see if the task provided is actually an AbstractArchiveTask. + if (provided instanceof AbstractArchiveTask) { + return ((AbstractArchiveTask) provided).getArchiveFile().get().getAsFile(); + } + } - // None of the previous checks worked. Fall back to Gradle's built-in file resolution mechanics. - return project.file(in); - } + // None of the previous checks worked. Fall back to Gradle's built-in file resolution mechanics. + return project.file(in); + } } diff --git a/src/main/java/com/modrinth/minotaur/dependencies/Dependency.java b/src/main/java/com/modrinth/minotaur/dependencies/Dependency.java index ebe8db1..c058f8d 100644 --- a/src/main/java/com/modrinth/minotaur/dependencies/Dependency.java +++ b/src/main/java/com/modrinth/minotaur/dependencies/Dependency.java @@ -20,104 +20,104 @@ */ public class Dependency { - /** - * The {@link ProjectDependencyType} of the dependency. - */ - @Expose - @SerializedName("dependency_type") - private final ProjectDependencyType dependencyType; + /** + * The {@link ProjectDependencyType} of the dependency. + */ + @Expose + @SerializedName("dependency_type") + private final ProjectDependencyType dependencyType; - /** - * Creates a new dependency relationship. - * - * @param type The type of dependency being created. - */ - @ApiStatus.Internal - Dependency(DependencyType type) { - this.dependencyType = type.toNew(); - } + /** + * Creates a new dependency relationship. + * + * @param type The type of dependency being created. + */ + @ApiStatus.Internal + Dependency(DependencyType type) { + this.dependencyType = type.toNew(); + } - /** - * Creates a new dependency relationship. - * - * @param type The type of dependency being created. - */ - @ApiStatus.Internal - Dependency(String type) { - this.dependencyType = ProjectDependencyType.valueOf(type.toUpperCase(Locale.ROOT)); - } + /** + * Creates a new dependency relationship. + * + * @param type The type of dependency being created. + */ + @ApiStatus.Internal + Dependency(String type) { + this.dependencyType = ProjectDependencyType.valueOf(type.toUpperCase(Locale.ROOT)); + } - /** - * @return {@link #dependencyType} - */ - ProjectDependencyType getDependencyType() { - return this.dependencyType; - } + /** + * @return {@link #dependencyType} + */ + ProjectDependencyType getDependencyType() { + return this.dependencyType; + } - /** - * @param api {@link ModrinthAPI} instance - * @param ext {@link ModrinthExtension} instance - * @return a {@link ProjectDependency} instance from a {@link Dependency} - */ - public ProjectDependency toNew(ModrinthAPI api, ModrinthExtension ext) { - if (this instanceof ModDependency) { - ModDependency dep = (ModDependency) this; - String id = Objects.requireNonNull( - api.projects().getProjectIdBySlug(dep.getProjectId()).join(), - "Failed to resolve dependency project ID: " + dep.getProjectId() - ); - return new ProjectDependency(null, id, null, dep.getDependencyType()); - } else if (this instanceof VersionDependency) { - VersionDependency dep = (VersionDependency) this; - String versionId = resolveVersionId(dep.getProjectId(), dep.getVersionId(), api, ext); - return new ProjectDependency(versionId, dep.getProjectId(), null, dep.getDependencyType()); - } else { - throw new GradleException("Dependency was not an instance of ModDependency or VersionDependency!"); - } - } + /** + * @param api {@link ModrinthAPI} instance + * @param ext {@link ModrinthExtension} instance + * @return a {@link ProjectDependency} instance from a {@link Dependency} + */ + public ProjectDependency toNew(ModrinthAPI api, ModrinthExtension ext) { + if (this instanceof ModDependency) { + ModDependency dep = (ModDependency) this; + String id = Objects.requireNonNull( + api.projects().getProjectIdBySlug(dep.getProjectId()).join(), + "Failed to resolve dependency project ID: " + dep.getProjectId() + ); + return new ProjectDependency(null, id, null, dep.getDependencyType()); + } else if (this instanceof VersionDependency) { + VersionDependency dep = (VersionDependency) this; + String versionId = resolveVersionId(dep.getProjectId(), dep.getVersionId(), api, ext); + return new ProjectDependency(versionId, dep.getProjectId(), null, dep.getDependencyType()); + } else { + throw new GradleException("Dependency was not an instance of ModDependency or VersionDependency!"); + } + } - /** - * @param newDep the {@link ProjectDependency} to convert to a {@link Dependency} - * @return a converted {@link Dependency} - */ - public static Dependency fromNew(ProjectDependency newDep) { - if (newDep.getVersionId() != null) { - return new VersionDependency(newDep.getProjectId(), newDep.getVersionId(), newDep.getDependencyType().name()); - } else { - return new ModDependency(newDep.getProjectId(), newDep.getDependencyType().name()); - } - } + /** + * @param newDep the {@link ProjectDependency} to convert to a {@link Dependency} + * @return a converted {@link Dependency} + */ + public static Dependency fromNew(ProjectDependency newDep) { + if (newDep.getVersionId() != null) { + return new VersionDependency(newDep.getProjectId(), newDep.getVersionId(), newDep.getDependencyType().name()); + } else { + return new ModDependency(newDep.getProjectId(), newDep.getDependencyType().name()); + } + } - /** - * Returns a project ID from a project ID or slug - * - * @param versionId ID or version number of the project to resolve - * @return ID of the resolved project - */ - private String resolveVersionId(String projectId, String versionId, ModrinthAPI api, ModrinthExtension ext) { - attempt: try { - // First check to see if the version is simply a version ID. Return it if so. - ProjectVersion version = api.versions().getVersion(versionId).join(); - return version.getId(); - } catch (Exception ignored) { - // Seems it wasn't a version ID. Try to extract a version number. - if (projectId == null) { - break attempt; - } - GetProjectVersionsRequest filter = GetProjectVersionsRequest.builder() - .loaders(ext.getLoaders().get()) - .gameVersions(ext.getGameVersions().get()) - .build(); - List versions = api.versions().getProjectVersions(projectId, filter).join(); + /** + * Returns a project ID from a project ID or slug + * + * @param versionId ID or version number of the project to resolve + * @return ID of the resolved project + */ + private String resolveVersionId(String projectId, String versionId, ModrinthAPI api, ModrinthExtension ext) { + attempt: try { + // First check to see if the version is simply a version ID. Return it if so. + ProjectVersion version = api.versions().getVersion(versionId).join(); + return version.getId(); + } catch (Exception ignored) { + // Seems it wasn't a version ID. Try to extract a version number. + if (projectId == null) { + break attempt; + } + GetProjectVersionsRequest filter = GetProjectVersionsRequest.builder() + .loaders(ext.getLoaders().get()) + .gameVersions(ext.getGameVersions().get()) + .build(); + List versions = api.versions().getProjectVersions(projectId, filter).join(); - for (ProjectVersion version : versions) { - if (version.getVersionNumber().equals(versionId)) { - return version.getId(); - } - } - } + for (ProjectVersion version : versions) { + if (version.getVersionNumber().equals(versionId)) { + return version.getId(); + } + } + } - // Input wasn't a version ID or a version number - throw new GradleException("Failed to resolve version \"" + versionId + "\"!"); - } + // Input wasn't a version ID or a version number + throw new GradleException("Failed to resolve version \"" + versionId + "\"!"); + } } diff --git a/src/main/java/com/modrinth/minotaur/dependencies/DependencyType.java b/src/main/java/com/modrinth/minotaur/dependencies/DependencyType.java index 52178c4..f35b096 100644 --- a/src/main/java/com/modrinth/minotaur/dependencies/DependencyType.java +++ b/src/main/java/com/modrinth/minotaur/dependencies/DependencyType.java @@ -9,38 +9,38 @@ * The enum representing the three types of dependencies supported by Modrinth. */ public enum DependencyType { - /** - * The version requires an instance of the project/version to work. - */ - @SerializedName("required") - REQUIRED, - - /** - * The version has additional functionality when the project/version is present. - */ - @SerializedName("optional") - OPTIONAL, - - /** - * The version is not compatible with the project/version and will not work when both are used. - */ - @SerializedName("incompatible") - INCOMPATIBLE, - - /** - * The version contains this other project/version within it. - */ - @SerializedName("embedded") - EMBEDDED; - - public String toString() { - return this.name().toLowerCase(Locale.ROOT); - } - - /** - * @return a converted {@link ProjectDependencyType} - */ - ProjectDependencyType toNew() { - return ProjectDependencyType.valueOf(this.name().toUpperCase(Locale.ROOT)); - } + /** + * The version requires an instance of the project/version to work. + */ + @SerializedName("required") + REQUIRED, + + /** + * The version has additional functionality when the project/version is present. + */ + @SerializedName("optional") + OPTIONAL, + + /** + * The version is not compatible with the project/version and will not work when both are used. + */ + @SerializedName("incompatible") + INCOMPATIBLE, + + /** + * The version contains this other project/version within it. + */ + @SerializedName("embedded") + EMBEDDED; + + public String toString() { + return this.name().toLowerCase(Locale.ROOT); + } + + /** + * @return a converted {@link ProjectDependencyType} + */ + ProjectDependencyType toNew() { + return ProjectDependencyType.valueOf(this.name().toUpperCase(Locale.ROOT)); + } } diff --git a/src/main/java/com/modrinth/minotaur/dependencies/ModDependency.java b/src/main/java/com/modrinth/minotaur/dependencies/ModDependency.java index e9d22ae..cf47dbe 100644 --- a/src/main/java/com/modrinth/minotaur/dependencies/ModDependency.java +++ b/src/main/java/com/modrinth/minotaur/dependencies/ModDependency.java @@ -11,39 +11,39 @@ @SuppressWarnings("unused") public class ModDependency extends Dependency { - /** - * The ID of the project to create a dependency with. - */ - @Expose - @SerializedName("project_id") - private final String projectId; + /** + * The ID of the project to create a dependency with. + */ + @Expose + @SerializedName("project_id") + private final String projectId; - /** - * Creates a new project relationship. - * - * @param id The ID of the project to create a dependency with. - * @param type The type of dependency being created. - */ - public ModDependency(String id, DependencyType type) { - super(type.toString().toLowerCase(Locale.ROOT)); - this.projectId = id; - } + /** + * Creates a new project relationship. + * + * @param id The ID of the project to create a dependency with. + * @param type The type of dependency being created. + */ + public ModDependency(String id, DependencyType type) { + super(type.toString().toLowerCase(Locale.ROOT)); + this.projectId = id; + } - /** - * Creates a new project relationship. - * - * @param id The ID of the project to create a dependency with. - * @param type The type of dependency being created. - */ - public ModDependency(String id, String type) { - super(type); - this.projectId = id; - } + /** + * Creates a new project relationship. + * + * @param id The ID of the project to create a dependency with. + * @param type The type of dependency being created. + */ + public ModDependency(String id, String type) { + super(type); + this.projectId = id; + } - /** - * @return {@link #projectId} - */ - public String getProjectId() { - return this.projectId; - } + /** + * @return {@link #projectId} + */ + public String getProjectId() { + return this.projectId; + } } diff --git a/src/main/java/com/modrinth/minotaur/dependencies/VersionDependency.java b/src/main/java/com/modrinth/minotaur/dependencies/VersionDependency.java index 4656c0a..08d46bb 100644 --- a/src/main/java/com/modrinth/minotaur/dependencies/VersionDependency.java +++ b/src/main/java/com/modrinth/minotaur/dependencies/VersionDependency.java @@ -8,81 +8,81 @@ */ @SuppressWarnings("unused") public class VersionDependency extends Dependency { - /** - * The ID of the version to create a dependency with. - */ - @Expose - @SerializedName("project_id") - private final String projectId; + /** + * The ID of the version to create a dependency with. + */ + @Expose + @SerializedName("project_id") + private final String projectId; - /** - * The ID of the version to create a dependency with. - */ - @Expose - @SerializedName("version_id") - private final String versionId; + /** + * The ID of the version to create a dependency with. + */ + @Expose + @SerializedName("version_id") + private final String versionId; - /** - * Creates a new version relationship. - * - * @param id The ID of the version to create a dependency with. - * @param type The type of dependency being created. - */ - public VersionDependency(String id, DependencyType type) { - super(type); - this.projectId = null; - this.versionId = id; - } + /** + * Creates a new version relationship. + * + * @param id The ID of the version to create a dependency with. + * @param type The type of dependency being created. + */ + public VersionDependency(String id, DependencyType type) { + super(type); + this.projectId = null; + this.versionId = id; + } - /** - * Creates a new version relationship. - * - * @param id The ID of the version to create a dependency with. - * @param type The type of dependency being created. - */ - public VersionDependency(String id, String type) { - super(type); - this.projectId = null; - this.versionId = id; - } + /** + * Creates a new version relationship. + * + * @param id The ID of the version to create a dependency with. + * @param type The type of dependency being created. + */ + public VersionDependency(String id, String type) { + super(type); + this.projectId = null; + this.versionId = id; + } - /** - * Creates a new version relationship. - * - * @param projectId The ID of the project to create a dependency with. - * @param versionId The ID of the version to create a dependency with. - * @param type The type of dependency being created. - */ - public VersionDependency(String projectId, String versionId, DependencyType type) { - super(type); - this.projectId = projectId; - this.versionId = versionId; - } + /** + * Creates a new version relationship. + * + * @param projectId The ID of the project to create a dependency with. + * @param versionId The ID of the version to create a dependency with. + * @param type The type of dependency being created. + */ + public VersionDependency(String projectId, String versionId, DependencyType type) { + super(type); + this.projectId = projectId; + this.versionId = versionId; + } - /** - * Creates a new version relationship. - * - * @param projectId The ID of the project to create a dependency with. - * @param versionId The ID of the version to create a dependency with. - * @param type The type of dependency being created. - */ - public VersionDependency(String projectId, String versionId, String type) { - super(type); - this.projectId = projectId; - this.versionId = versionId; - } + /** + * Creates a new version relationship. + * + * @param projectId The ID of the project to create a dependency with. + * @param versionId The ID of the version to create a dependency with. + * @param type The type of dependency being created. + */ + public VersionDependency(String projectId, String versionId, String type) { + super(type); + this.projectId = projectId; + this.versionId = versionId; + } - /** - * @return {@link #projectId} - */ - public String getProjectId() { - return this.projectId; - } + /** + * @return {@link #projectId} + */ + public String getProjectId() { + return this.projectId; + } - /** - * @return {@link #versionId} - */ - public String getVersionId() { - return this.versionId; - } + /** + * @return {@link #versionId} + */ + public String getVersionId() { + return this.versionId; + } } diff --git a/src/main/java/com/modrinth/minotaur/dependencies/container/DependencyDSL.java b/src/main/java/com/modrinth/minotaur/dependencies/container/DependencyDSL.java index bb1d665..551d780 100644 --- a/src/main/java/com/modrinth/minotaur/dependencies/container/DependencyDSL.java +++ b/src/main/java/com/modrinth/minotaur/dependencies/container/DependencyDSL.java @@ -12,72 +12,72 @@ * the Nested Dependencies configuration */ public class DependencyDSL { - private final NamedDomainObjectContainer dependencies; - private final NamedDependencyContainer.Incompatible incompatible; - private final NamedDependencyContainer.Optional optional; - private final NamedDependencyContainer.Required required; - private final NamedDependencyContainer.Embedded embedded; + private final NamedDomainObjectContainer dependencies; + private final NamedDependencyContainer.Incompatible incompatible; + private final NamedDependencyContainer.Optional optional; + private final NamedDependencyContainer.Required required; + private final NamedDependencyContainer.Embedded embedded; - /** - * Instantiates a new dependencies configuration. - * - * @param objects ObjectFactory - */ - @Inject - protected DependencyDSL(final ObjectFactory objects) { - this.dependencies = objects.domainObjectContainer(NamedDependency.class); - this.incompatible = objects.newInstance(NamedDependencyContainer.Incompatible.class, dependencies); - this.optional = objects.newInstance(NamedDependencyContainer.Optional.class, dependencies); - this.required = objects.newInstance(NamedDependencyContainer.Required.class, dependencies); - this.embedded = objects.newInstance(NamedDependencyContainer.Embedded.class, dependencies); - } + /** + * Instantiates a new dependencies configuration. + * + * @param objects ObjectFactory + */ + @Inject + protected DependencyDSL(final ObjectFactory objects) { + this.dependencies = objects.domainObjectContainer(NamedDependency.class); + this.incompatible = objects.newInstance(NamedDependencyContainer.Incompatible.class, dependencies); + this.optional = objects.newInstance(NamedDependencyContainer.Optional.class, dependencies); + this.required = objects.newInstance(NamedDependencyContainer.Required.class, dependencies); + this.embedded = objects.newInstance(NamedDependencyContainer.Embedded.class, dependencies); + } - /** - * Returns the complete NamedDependency container set mapped and collected as a {@literal List} - * - * @return {@literal List} - */ - public List getNamedDependenciesAsList() { - return this.dependencies.stream().map(NamedDependency::getDependency).collect(Collectors.toList()); - } + /** + * Returns the complete NamedDependency container set mapped and collected as a {@literal List} + * + * @return {@literal List} + */ + public List getNamedDependenciesAsList() { + return this.dependencies.stream().map(NamedDependency::getDependency).collect(Collectors.toList()); + } - /** - * Retrieve the reference to an {@link NamedDependencyContainer.Incompatible} instance. - * Provided as a utility method for external uses. - * - * @return incompatible {@link NamedDependencyContainer.Incompatible} - */ - public NamedDependencyContainer.Incompatible getIncompatible() { - return this.incompatible; - } + /** + * Retrieve the reference to an {@link NamedDependencyContainer.Incompatible} instance. + * Provided as a utility method for external uses. + * + * @return incompatible {@link NamedDependencyContainer.Incompatible} + */ + public NamedDependencyContainer.Incompatible getIncompatible() { + return this.incompatible; + } - /** - * Retrieve the reference to an {@link NamedDependencyContainer.Optional} instance. - * Provided as a utility method for external uses. - * - * @return optional {@link NamedDependencyContainer.Optional} - */ - public NamedDependencyContainer.Optional getOptional() { - return this.optional; - } + /** + * Retrieve the reference to an {@link NamedDependencyContainer.Optional} instance. + * Provided as a utility method for external uses. + * + * @return optional {@link NamedDependencyContainer.Optional} + */ + public NamedDependencyContainer.Optional getOptional() { + return this.optional; + } - /** - * Retrieve the reference to an {@link NamedDependencyContainer.Required} instance. - * Provided as a utility method for external uses. - * - * @return required {@link NamedDependencyContainer.Required} - */ - public NamedDependencyContainer.Required getRequired() { - return this.required; - } + /** + * Retrieve the reference to an {@link NamedDependencyContainer.Required} instance. + * Provided as a utility method for external uses. + * + * @return required {@link NamedDependencyContainer.Required} + */ + public NamedDependencyContainer.Required getRequired() { + return this.required; + } - /** - * Retrieve the reference to an {@link NamedDependencyContainer.Embedded} instance. - * Provided as a utility method for external uses. - * - * @return embedded {@link NamedDependencyContainer.Embedded} - */ - public NamedDependencyContainer.Embedded getEmbedded() { - return this.embedded; - } + /** + * Retrieve the reference to an {@link NamedDependencyContainer.Embedded} instance. + * Provided as a utility method for external uses. + * + * @return embedded {@link NamedDependencyContainer.Embedded} + */ + public NamedDependencyContainer.Embedded getEmbedded() { + return this.embedded; + } } diff --git a/src/main/java/com/modrinth/minotaur/dependencies/container/NamedDependency.java b/src/main/java/com/modrinth/minotaur/dependencies/container/NamedDependency.java index 217eb6a..3298cc2 100644 --- a/src/main/java/com/modrinth/minotaur/dependencies/container/NamedDependency.java +++ b/src/main/java/com/modrinth/minotaur/dependencies/container/NamedDependency.java @@ -13,61 +13,61 @@ * Defines a Named Dependency for our NamedDependencyContainer. */ public class NamedDependency implements Named { - private final String id; - private final String projectId; - private final String versionId; - private final DependencyType dependencyType; + private final String id; + private final String projectId; + private final String versionId; + private final DependencyType dependencyType; - /** - * Instantiates a new NamedDependency. - * - * @param projectId the projectId if not-null - * @param versionId the versionId if not-null - * @param dependencyType the DependencyType - */ - protected NamedDependency(@Nullable String projectId, @Nullable String versionId, DependencyType dependencyType) { - this.checkAll(projectId, versionId); - this.id = projectId == null ? versionId : projectId; - this.dependencyType = dependencyType; - this.projectId = projectId; - this.versionId = versionId; - } + /** + * Instantiates a new NamedDependency. + * + * @param projectId the projectId if not-null + * @param versionId the versionId if not-null + * @param dependencyType the DependencyType + */ + protected NamedDependency(@Nullable String projectId, @Nullable String versionId, DependencyType dependencyType) { + this.checkAll(projectId, versionId); + this.id = projectId == null ? versionId : projectId; + this.dependencyType = dependencyType; + this.projectId = projectId; + this.versionId = versionId; + } - /** - * @return the container id, is only of either projectId or versionId - */ - @NotNull - @Override - public String getName() { - return this.id; - } + /** + * @return the container id, is only of either projectId or versionId + */ + @NotNull + @Override + public String getName() { + return this.id; + } - /** - * Gets the DependencyType as String. - * - * @return the type - */ - public DependencyType getDependencyType() { - return this.dependencyType; - } + /** + * Gets the DependencyType as String. + * + * @return the type + */ + public DependencyType getDependencyType() { + return this.dependencyType; + } - /** - * Return this as a never null {@link VersionDependency} or {@link ModDependency} depending on - * which id is set. - * - * @return {@link Dependency} dynamically created Dependency - */ - @NotNull - public Dependency getDependency() { - if (this.versionId == null) { - return new ModDependency(this.projectId, this.dependencyType); - } - return new VersionDependency(this.projectId, this.versionId, this.dependencyType); - } + /** + * Return this as a never null {@link VersionDependency} or {@link ModDependency} depending on + * which id is set. + * + * @return {@link Dependency} dynamically created Dependency + */ + @NotNull + public Dependency getDependency() { + if (this.versionId == null) { + return new ModDependency(this.projectId, this.dependencyType); + } + return new VersionDependency(this.projectId, this.versionId, this.dependencyType); + } - private void checkAll(@Nullable Object obj1, @Nullable Object obj2) { - if (obj1 == null && obj2 == null) { - throw new GradleException("Both 'projectId' & 'versionId' cannot be null. At least 1 must be defined"); - } - } + private void checkAll(@Nullable Object obj1, @Nullable Object obj2) { + if (obj1 == null && obj2 == null) { + throw new GradleException("Both 'projectId' & 'versionId' cannot be null. At least 1 must be defined"); + } + } } diff --git a/src/main/java/com/modrinth/minotaur/dependencies/container/NamedDependencyContainer.java b/src/main/java/com/modrinth/minotaur/dependencies/container/NamedDependencyContainer.java index e52b6af..ef833a4 100644 --- a/src/main/java/com/modrinth/minotaur/dependencies/container/NamedDependencyContainer.java +++ b/src/main/java/com/modrinth/minotaur/dependencies/container/NamedDependencyContainer.java @@ -9,106 +9,106 @@ * The root NamedDependencyContainer class */ public class NamedDependencyContainer { - private final NamedDomainObjectContainer dependencyContainer; - private final DependencyType dependencyType; + private final NamedDomainObjectContainer dependencyContainer; + private final DependencyType dependencyType; - /** - * Instantiates a new Dependency object. - * - * @param container {@literal NamedDomainObjectContainer} - * @param dependencyType {@link DependencyType} - */ - @Inject - protected NamedDependencyContainer(NamedDomainObjectContainer container, DependencyType dependencyType) { - this.dependencyContainer = container; - this.dependencyType = dependencyType; - } + /** + * Instantiates a new Dependency object. + * + * @param container {@literal NamedDomainObjectContainer} + * @param dependencyType {@link DependencyType} + */ + @Inject + protected NamedDependencyContainer(NamedDomainObjectContainer container, DependencyType dependencyType) { + this.dependencyContainer = container; + this.dependencyType = dependencyType; + } - /** - * Creates an incompatible Dependency Container and applies the projectId property - * - * @param projectId the project id - */ - public void project(final String projectId) { - this.dependencyContainer.add(new NamedDependency(projectId, null, this.dependencyType)); - } + /** + * Creates an incompatible Dependency Container and applies the projectId property + * + * @param projectId the project id + */ + public void project(final String projectId) { + this.dependencyContainer.add(new NamedDependency(projectId, null, this.dependencyType)); + } - /** - * Creates a incompatible Dependency Container and applies the versionId property - * - * @param versionId the version id - */ - public void version(final String versionId) { - this.dependencyContainer.add(new NamedDependency(null, versionId, this.dependencyType)); - } + /** + * Creates a incompatible Dependency Container and applies the versionId property + * + * @param versionId the version id + */ + public void version(final String versionId) { + this.dependencyContainer.add(new NamedDependency(null, versionId, this.dependencyType)); + } - /** - * Creates a incompatible Dependency Container and applies the versionId property - * - * @param projectId the project id - * @param versionId the version number - */ - public void version(final String projectId, final String versionId) { - this.dependencyContainer.add(new NamedDependency(projectId, versionId, this.dependencyType)); - } + /** + * Creates a incompatible Dependency Container and applies the versionId property + * + * @param projectId the project id + * @param versionId the version number + */ + public void version(final String projectId, final String versionId) { + this.dependencyContainer.add(new NamedDependency(projectId, versionId, this.dependencyType)); + } - /** - * Incompatible DependencyType container class - */ - public static class Incompatible extends NamedDependencyContainer { - /** - * Instantiates a new incompatible object. - * - * @param container {@literal NamedDomainObjectContainer} - */ - @Inject - public Incompatible(NamedDomainObjectContainer container) { - super(container, DependencyType.INCOMPATIBLE); - } - } + /** + * Incompatible DependencyType container class + */ + public static class Incompatible extends NamedDependencyContainer { + /** + * Instantiates a new incompatible object. + * + * @param container {@literal NamedDomainObjectContainer} + */ + @Inject + public Incompatible(NamedDomainObjectContainer container) { + super(container, DependencyType.INCOMPATIBLE); + } + } - /** - * Optional DependencyType container class - */ - public static class Optional extends NamedDependencyContainer { - /** - * Instantiates a new optional object. - * - * @param container {@literal NamedDomainObjectContainer} - */ - @Inject - public Optional(NamedDomainObjectContainer container) { - super(container, DependencyType.OPTIONAL); - } - } + /** + * Optional DependencyType container class + */ + public static class Optional extends NamedDependencyContainer { + /** + * Instantiates a new optional object. + * + * @param container {@literal NamedDomainObjectContainer} + */ + @Inject + public Optional(NamedDomainObjectContainer container) { + super(container, DependencyType.OPTIONAL); + } + } - /** - * Required DependencyType container class - */ - public static class Required extends NamedDependencyContainer { - /** - * Instantiates a new required object. - * - * @param container {@literal NamedDomainObjectContainer} - */ - @Inject - public Required(NamedDomainObjectContainer container) { - super(container, DependencyType.REQUIRED); - } - } + /** + * Required DependencyType container class + */ + public static class Required extends NamedDependencyContainer { + /** + * Instantiates a new required object. + * + * @param container {@literal NamedDomainObjectContainer} + */ + @Inject + public Required(NamedDomainObjectContainer container) { + super(container, DependencyType.REQUIRED); + } + } - /** - * Embedded DependencyType container class - */ - public static class Embedded extends NamedDependencyContainer { - /** - * Instantiates a new required object. - * - * @param container {@literal NamedDomainObjectContainer} - */ - @Inject - public Embedded(NamedDomainObjectContainer container) { - super(container, DependencyType.EMBEDDED); - } - } + /** + * Embedded DependencyType container class + */ + public static class Embedded extends NamedDependencyContainer { + /** + * Instantiates a new required object. + * + * @param container {@literal NamedDomainObjectContainer} + */ + @Inject + public Embedded(NamedDomainObjectContainer container) { + super(container, DependencyType.EMBEDDED); + } + } } diff --git a/src/main/java/com/modrinth/minotaur/request/VersionType.java b/src/main/java/com/modrinth/minotaur/request/VersionType.java index c287fce..af59b01 100644 --- a/src/main/java/com/modrinth/minotaur/request/VersionType.java +++ b/src/main/java/com/modrinth/minotaur/request/VersionType.java @@ -4,23 +4,24 @@ /** * The enum representing the three version types available for versions. + * * @deprecated Please use {@link masecla.modrinth4j.model.version.ProjectVersion.VersionType} */ @Deprecated public enum VersionType { - /** - * The version is in a stable state. - */ - @SerializedName("release") - RELEASE, - /** - * The version is in an experimental state which may have bugs. - */ - @SerializedName("beta") - BETA, - /** - * The version is in a volatile state which could result in data loss. - */ - @SerializedName("alpha") - ALPHA + /** + * The version is in a stable state. + */ + @SerializedName("release") + RELEASE, + /** + * The version is in an experimental state which may have bugs. + */ + @SerializedName("beta") + BETA, + /** + * The version is in a volatile state which could result in data loss. + */ + @SerializedName("alpha") + ALPHA } diff --git a/src/main/java/com/modrinth/minotaur/responses/ResponseUpload.java b/src/main/java/com/modrinth/minotaur/responses/ResponseUpload.java index 42e7683..c6ae9aa 100644 --- a/src/main/java/com/modrinth/minotaur/responses/ResponseUpload.java +++ b/src/main/java/com/modrinth/minotaur/responses/ResponseUpload.java @@ -14,305 +14,307 @@ /** * This class defines a POJO that represents the API response for versions that have been successfully uploaded to * Modrinth. + * * @deprecated Please use {@link ProjectVersion} */ @SuppressWarnings("ALL") @Deprecated public class ResponseUpload { - /** - * The ID of the version, encoded as a base62 string. - */ - @Expose - @SerializedName("id") - private String id; - - /** - * The ID of the mod this version is for. - */ - @Expose - @SerializedName("project_id") - private String projectId; - - /** - * The ID of the author who published this version - */ - @Expose - @SerializedName("author_id") - private String authorId; - - /** - * Whether the version is featured or not - */ - @Expose - @SerializedName("featured") - private boolean featured; - - /** - * The name of this version - */ - @Expose - @SerializedName("name") - private String name; - - /** - * The version number. Ideally will follow semantic versioning - */ - @Expose - @SerializedName("version_number") - private String versionNumber; - - /** - * The changelog for this version of the mod. - */ - @Expose - @SerializedName("changelog") - private String changelog; - - /** - * The date that this version was published. - */ - @Expose - @SerializedName("date_published") - private Date datePublished; - - /** - * The number of downloads this specific version has had. - */ - @Expose - @SerializedName("downloads") - private int downloads; - - /** - * The type of the release - `Alpha`, `Beta`, or `Release`. - */ - @Expose - @SerializedName("version_type") - private VersionType versionType; - - /** - * A list of files available for download for this version. - */ - @Expose - @SerializedName("files") - private Collection files = new ArrayList<>(); - - /** - * A list of versions of Minecraft that this version of the mod supports. - */ - @Expose - @SerializedName("game_versions") - private Collection gameVersions = new ArrayList<>(); - - /** - * The loaders that this version works on - */ - @Expose - @SerializedName("loaders") - private Collection loaders = new ArrayList<>(); - - /** - * A list of mods that this version depends on. - */ - @Expose - @SerializedName("dependencies") - private Collection dependencies = new ArrayList<>(); - - /** - * @return {@link #id} - */ - public String getId() { - return this.id; - } - - /** - * @return {@link #projectId} - */ - public String getProjectId() { - return this.projectId; - } - - /** - * @return {@link #authorId} - */ - public String getAuthorId() { - return this.authorId; - } - - /** - * @return {@link #featured} - */ - public boolean isFeatured() { - return this.featured; - } - - /** - * @return {@link #name} - */ - public String getName() { - return this.name; - } - - /** - * @return {@link #versionNumber} - */ - public String getVersionNumber() { - return this.versionNumber; - } - - /** - * @return {@link #changelog} - */ - public String getChangelog() { - return this.changelog; - } - - /** - * @return {@link #datePublished} - */ - public Date getDatePublished() { - return this.datePublished; - } - - /** - * @return {@link #downloads} - */ - public int getDownloads() { - return this.downloads; - } - - /** - * @return {@link #versionType} - */ - public VersionType getVersionType() { - return this.versionType; - } - - /** - * @return {@link #files} - */ - public Collection getFiles() { - return this.files; - } - - /** - * @return {@link #gameVersions} - */ - public Collection getGameVersions() { - return this.gameVersions; - } - - /** - * @return {@link #loaders} - */ - public Collection getLoaders() { - return this.loaders; - } - - /** - * @return {@link #dependencies} - */ - public Collection getDependencies() { - return this.dependencies; - } - - /** - * Constructs a {@link ResponseUpload} from a {@link ProjectVersion} - * @param newVersion {@link ProjectVersion} instance - */ - @ApiStatus.Internal - public ResponseUpload(ProjectVersion newVersion) { - this.name = newVersion.getName(); - this.versionNumber = newVersion.getVersionNumber(); - this.changelog = newVersion.getChangelog(); - this.dependencies = - newVersion.getDependencies().stream().map(Dependency::fromNew).collect(Collectors.toList()); - this.gameVersions = newVersion.getGameVersions(); - this.versionType = VersionType.valueOf(newVersion.getVersionType().name()); - this.loaders = newVersion.getLoaders(); - this.featured = newVersion.isFeatured(); - this.id = newVersion.getId(); - this.projectId = newVersion.getProjectId(); - this.authorId = newVersion.getAuthorId(); - this.datePublished = Date.from(newVersion.getDatePublished()); - this.downloads = newVersion.getDownloads(); - this.files = - newVersion.getFiles().stream().map(VersionFile::fromNew).collect(Collectors.toList()); - } - - /** - * A single version file. - */ - public static class VersionFile { - /** - * A map of hashes of the file. The key is the hashing algorithm and the value is the string version of the - * hash. - */ - @Expose - @SerializedName("hashes") - private Map hashes; - - /** - * A direct link to the file for downloading it. - */ - @Expose - @SerializedName("url") - private String url; - - /** - * The filename of the file. - */ - @Expose - @SerializedName("filename") - private String filename; - - /** - * Whether the file is the primary file of the version. - */ - @Expose - @SerializedName("primary") - private boolean primary; - - /** - * @return {@link #hashes} - */ - public Map getHashes() { - return this.hashes; - } - - /** - * @return {@link #url} - */ - public String getUrl() { - return this.url; - } - - /** - * @return {@link #filename} - */ - public String getFilename() { - return this.filename; - } - - /** - * @return {@link #primary} - */ - public boolean isPrimary() { - return this.primary; - } - - /** - * @param newFile the {@link ProjectFile} to convert to a {@link VersionFile} - * @return a converted {@link VersionFile} - */ - public static VersionFile fromNew(ProjectFile newFile) { - VersionFile file = new VersionFile(); - file.hashes = new HashMap<>(); - file.hashes.put("sha1", newFile.getHashes().getSha1()); - file.hashes.put("sha512", newFile.getHashes().getSha512()); - file.url = newFile.getUrl(); - file.filename = newFile.getFilename(); - file.primary = newFile.isPrimary(); - return file; - } - } + /** + * The ID of the version, encoded as a base62 string. + */ + @Expose + @SerializedName("id") + private String id; + + /** + * The ID of the mod this version is for. + */ + @Expose + @SerializedName("project_id") + private String projectId; + + /** + * The ID of the author who published this version + */ + @Expose + @SerializedName("author_id") + private String authorId; + + /** + * Whether the version is featured or not + */ + @Expose + @SerializedName("featured") + private boolean featured; + + /** + * The name of this version + */ + @Expose + @SerializedName("name") + private String name; + + /** + * The version number. Ideally will follow semantic versioning + */ + @Expose + @SerializedName("version_number") + private String versionNumber; + + /** + * The changelog for this version of the mod. + */ + @Expose + @SerializedName("changelog") + private String changelog; + + /** + * The date that this version was published. + */ + @Expose + @SerializedName("date_published") + private Date datePublished; + + /** + * The number of downloads this specific version has had. + */ + @Expose + @SerializedName("downloads") + private int downloads; + + /** + * The type of the release - `Alpha`, `Beta`, or `Release`. + */ + @Expose + @SerializedName("version_type") + private VersionType versionType; + + /** + * A list of files available for download for this version. + */ + @Expose + @SerializedName("files") + private Collection files = new ArrayList<>(); + + /** + * A list of versions of Minecraft that this version of the mod supports. + */ + @Expose + @SerializedName("game_versions") + private Collection gameVersions = new ArrayList<>(); + + /** + * The loaders that this version works on + */ + @Expose + @SerializedName("loaders") + private Collection loaders = new ArrayList<>(); + + /** + * A list of mods that this version depends on. + */ + @Expose + @SerializedName("dependencies") + private Collection dependencies = new ArrayList<>(); + + /** + * @return {@link #id} + */ + public String getId() { + return this.id; + } + + /** + * @return {@link #projectId} + */ + public String getProjectId() { + return this.projectId; + } + + /** + * @return {@link #authorId} + */ + public String getAuthorId() { + return this.authorId; + } + + /** + * @return {@link #featured} + */ + public boolean isFeatured() { + return this.featured; + } + + /** + * @return {@link #name} + */ + public String getName() { + return this.name; + } + + /** + * @return {@link #versionNumber} + */ + public String getVersionNumber() { + return this.versionNumber; + } + + /** + * @return {@link #changelog} + */ + public String getChangelog() { + return this.changelog; + } + + /** + * @return {@link #datePublished} + */ + public Date getDatePublished() { + return this.datePublished; + } + + /** + * @return {@link #downloads} + */ + public int getDownloads() { + return this.downloads; + } + + /** + * @return {@link #versionType} + */ + public VersionType getVersionType() { + return this.versionType; + } + + /** + * @return {@link #files} + */ + public Collection getFiles() { + return this.files; + } + + /** + * @return {@link #gameVersions} + */ + public Collection getGameVersions() { + return this.gameVersions; + } + + /** + * @return {@link #loaders} + */ + public Collection getLoaders() { + return this.loaders; + } + + /** + * @return {@link #dependencies} + */ + public Collection getDependencies() { + return this.dependencies; + } + + /** + * Constructs a {@link ResponseUpload} from a {@link ProjectVersion} + * + * @param newVersion {@link ProjectVersion} instance + */ + @ApiStatus.Internal + public ResponseUpload(ProjectVersion newVersion) { + this.name = newVersion.getName(); + this.versionNumber = newVersion.getVersionNumber(); + this.changelog = newVersion.getChangelog(); + this.dependencies = + newVersion.getDependencies().stream().map(Dependency::fromNew).collect(Collectors.toList()); + this.gameVersions = newVersion.getGameVersions(); + this.versionType = VersionType.valueOf(newVersion.getVersionType().name()); + this.loaders = newVersion.getLoaders(); + this.featured = newVersion.isFeatured(); + this.id = newVersion.getId(); + this.projectId = newVersion.getProjectId(); + this.authorId = newVersion.getAuthorId(); + this.datePublished = Date.from(newVersion.getDatePublished()); + this.downloads = newVersion.getDownloads(); + this.files = + newVersion.getFiles().stream().map(VersionFile::fromNew).collect(Collectors.toList()); + } + + /** + * A single version file. + */ + public static class VersionFile { + /** + * A map of hashes of the file. The key is the hashing algorithm and the value is the string version of the + * hash. + */ + @Expose + @SerializedName("hashes") + private Map hashes; + + /** + * A direct link to the file for downloading it. + */ + @Expose + @SerializedName("url") + private String url; + + /** + * The filename of the file. + */ + @Expose + @SerializedName("filename") + private String filename; + + /** + * Whether the file is the primary file of the version. + */ + @Expose + @SerializedName("primary") + private boolean primary; + + /** + * @return {@link #hashes} + */ + public Map getHashes() { + return this.hashes; + } + + /** + * @return {@link #url} + */ + public String getUrl() { + return this.url; + } + + /** + * @return {@link #filename} + */ + public String getFilename() { + return this.filename; + } + + /** + * @return {@link #primary} + */ + public boolean isPrimary() { + return this.primary; + } + + /** + * @param newFile the {@link ProjectFile} to convert to a {@link VersionFile} + * @return a converted {@link VersionFile} + */ + public static VersionFile fromNew(ProjectFile newFile) { + VersionFile file = new VersionFile(); + file.hashes = new HashMap<>(); + file.hashes.put("sha1", newFile.getHashes().getSha1()); + file.hashes.put("sha512", newFile.getHashes().getSha512()); + file.url = newFile.getUrl(); + file.filename = newFile.getFilename(); + file.primary = newFile.isPrimary(); + return file; + } + } } From 5f7b0a45ed984f009e3fde136fa805eb1b59343c Mon Sep 17 00:00:00 2001 From: Emma Triphora Date: Fri, 10 Feb 2023 17:53:28 -0500 Subject: [PATCH 2/2] Add git-blame-ignore-revs file for prev commit --- .git-blame-ignore-revs | 2 ++ build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..e1d493a --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Reformatting from spaces -> tabs +a3b3fe2edef2ab049339efd8e1209a84e1c33dcc diff --git a/build.gradle b/build.gradle index 0dfca3d..819df5f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'com.gradle.plugin-publish' version '1.1.0' } -version = '2.7.0-beta.3' +version = '2.7.0' group = 'com.modrinth.minotaur' archivesBaseName = 'Minotaur' description = 'Modrinth plugin for publishing builds to the website!'