Skip to content

Commit

Permalink
A few small fixes (#14)
Browse files Browse the repository at this point in the history
* Add TaskProvider support for file uploads in Kotlin DSL

* More fixes

- Fix primary files (fixes #4)
- Fix version name being overridden no matter what
- Change version to prepare for release

Co-authored-by: KJP12 <[email protected]>
  • Loading branch information
triphora and Ampflower authored Feb 27, 2022
1 parent a28279c commit 49186c1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'maven-publish'
}

version = '2.0.0-SNAPSHOT'
version = '2.0.0'
group = 'com.modrinth.minotaur'
archivesBaseName = 'Minotaur'
description = 'Modrinth plugin for publishing builds to the website!'
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/modrinth/minotaur/Minotaur.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public void apply(final Project project) {
if (extension.getVersionNumber().getOrNull() == null) {
extension.getVersionNumber().set(evaluatedProject.getVersion().toString());
}
extension.getVersionName().set(extension.getVersionNumber().get());
if (extension.getVersionName().getOrNull() == null) {
extension.getVersionName().set(extension.getVersionNumber().get());
}
});

project.getLogger().debug("Successfully applied the Modrinth plugin!");
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.gradle.api.plugins.AppliedPlugin;
import org.gradle.api.plugins.ExtraPropertiesExtension;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.gradle.jvm.tasks.Jar;

import javax.annotation.Nullable;
import java.io.File;
Expand Down Expand Up @@ -182,6 +182,7 @@ public void upload(URI endpoint, List<File> files) throws IOException {
data.setLoaders(extension.getLoaders().get());
data.setDependencies(extension.getDependencies().get());
data.setFileParts(fileParts);
data.setPrimaryFile("0"); // The primary file will always be of the first index in the list

form.addTextBody("data", GSON.toJson(data), ContentType.APPLICATION_JSON);

Expand Down Expand Up @@ -246,6 +247,17 @@ else if (in instanceof AbstractArchiveTask) {
return ((AbstractArchiveTask) in).getArchiveFile().get().getAsFile();
}

// 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.
else if (in instanceof TaskProvider<?>) {
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();
}
}

// Fallback to Gradle's built-in file resolution mechanics.
return project.file(in);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/modrinth/minotaur/request/VersionData.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public class VersionData {
@SerializedName("featured")
private boolean featured = false;

@Expose
@SerializedName("primary_file")
private String primaryFile;

/**
* @param id Value to set {@link #projectId} to
*/
Expand Down Expand Up @@ -144,4 +148,11 @@ public void setFileParts(List<String> fileParts) {
public void setDependencies(Collection<Dependency> dependencies) {
this.dependencies = dependencies;
}

/**
* @param primaryFile Value to set {@link #primaryFile} to
*/
public void setPrimaryFile(String primaryFile) {
this.primaryFile = primaryFile;
}
}

0 comments on commit 49186c1

Please sign in to comment.