Skip to content

Commit fc504b4

Browse files
authored
Implement file types for additional files (#79)
1 parent 513938d commit fc504b4

File tree

10 files changed

+557
-17
lines changed

10 files changed

+557
-17
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Set up JDK 17
1111
uses: actions/setup-java@v4
1212
with:
13-
java-version: 17 # Use Java 17 here because the Loom test env needs it
13+
java-version: 21 # Use Java 21 here because the Loom test env needs it
1414
distribution: temurin
1515

1616
- name: Cache Gradle files
@@ -37,7 +37,7 @@ jobs:
3737

3838
- name: Test with Gradle
3939
run: |
40-
./gradlew -p fg modrinth
40+
# ./gradlew -p fg modrinth
4141
./gradlew -p loom modrinth
4242
if: ${{ !contains(github.event.head_commit.message, 'skip test') }}
4343
env:

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'com.gradle.plugin-publish' version '1.2.0'
33
}
44

5-
version = '2.8.10'
5+
version = '2.9.0'
66
group = 'com.modrinth.minotaur'
77
base.archivesName = 'Minotaur'
88
description = 'Modrinth plugin for publishing builds to the website!'
@@ -19,6 +19,7 @@ dependencies {
1919
compileOnly group: 'org.jetbrains', name: 'annotations', version: '+'
2020
api group: 'dev.masecla', name: 'Modrinth4J', version: '2.2.0'
2121
compileOnly group: 'io.papermc.paperweight', name: 'paperweight-userdev', version: '1.5.2'
22+
compileOnly annotationProcessor(group: 'org.projectlombok', name: 'lombok', version: '1.18.30')
2223
}
2324

2425
gradlePlugin {

loom/build.gradle

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id "fabric-loom" version "1.3.+"
2+
id "fabric-loom" version "1.12.+"
33
id "com.modrinth.minotaur" version "2.+"
44
}
55

@@ -13,15 +13,21 @@ dependencies {
1313
}
1414

1515
java.withSourcesJar()
16+
java.withJavadocJar()
1617

1718
import com.modrinth.minotaur.dependencies.DependencyType
1819
import com.modrinth.minotaur.dependencies.ModDependency
1920
import com.modrinth.minotaur.dependencies.VersionDependency
2021

2122
modrinth {
22-
projectId = "mudmod"
23+
projectId = "allergies"
2324
uploadFile = remapJar
24-
additionalFiles = [project.file("build/libs/loom-$version-sources.jar")]
25+
additionalFiles = [project.file("build/devlibs/loom-$version-dev.jar")]
26+
additionalFiles {
27+
sourcesJar sourcesJar
28+
javadocJar javadocJar
29+
other 'build/loom-cache/remapped_working/remapped.net.fabricmc-fabric-loader-2b40239f-0.12.12.jar'
30+
}
2531
versionType = "alpha"
2632
dependencies = [
2733
new ModDependency("test-project", "optional"),
@@ -30,9 +36,17 @@ modrinth {
3036
dependencies {
3137
required.project "corrupted"
3238
optional.version "9MsDOrJE"
33-
incompatible.version "mOgUt4GM", "13.0.0"
39+
incompatible.version "AANobbMI", "mc1.21.11-0.8.2-fabric"
3440
embedded.project "uiW75cBG"
3541
required.version "modmenu", "11.0.2"
3642
}
3743
debugMode = true
3844
}
45+
46+
tasks.withType(Jar) {
47+
manifest {
48+
attributes([
49+
'Timestamp': System.currentTimeMillis(),
50+
])
51+
}
52+
}

src/main/java/com/modrinth/minotaur/ModrinthExtension.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.modrinth.minotaur;
22

3+
import com.modrinth.minotaur.additionalfiles.AdditionalFileDSL;
34
import com.modrinth.minotaur.dependencies.Dependency;
45
import com.modrinth.minotaur.dependencies.container.DependencyDSL;
56
import masecla.modrinth4j.model.version.ProjectVersion.VersionType;
7+
import org.gradle.api.Action;
68
import org.gradle.api.Project;
79
import org.gradle.api.file.RegularFileProperty;
810
import org.gradle.api.provider.ListProperty;
@@ -13,6 +15,7 @@
1315
* {...}} block in the buildscript.
1416
*/
1517
public class ModrinthExtension extends DependencyDSL {
18+
private final AdditionalFileDSL additionalFileDsl;
1619
private final Property<String> apiUrl, token, projectId, versionNumber, versionName, changelog, versionType, syncBodyFrom;
1720
private final Property<Object> legacyUploadFile;
1821
private final RegularFileProperty file;
@@ -48,6 +51,7 @@ public class ModrinthExtension extends DependencyDSL {
4851
*/
4952
public ModrinthExtension(Project project) {
5053
super(project.getObjects());
54+
additionalFileDsl = project.getObjects().newInstance(AdditionalFileDSL.class);
5155
apiUrl = project.getObjects().property(String.class).convention(DEFAULT_API_URL);
5256
token = project.getObjects().property(String.class).convention(project.getProviders().environmentVariable("MODRINTH_TOKEN"));
5357
projectId = project.getObjects().property(String.class);
@@ -68,6 +72,14 @@ public ModrinthExtension(Project project) {
6872
autoAddDependsOn = project.getObjects().property(Boolean.class).convention(true);
6973
}
7074

75+
public void additionalFiles(Action<? super AdditionalFileDSL> action) {
76+
action.execute(additionalFileDsl);
77+
}
78+
79+
public AdditionalFileDSL getAdditionalFileDsl() {
80+
return additionalFileDsl;
81+
}
82+
7183
/**
7284
* This should not be changed unless you know what you're doing. Its main use case is for debug, development, or
7385
* advanced user configurations.

src/main/java/com/modrinth/minotaur/TaskModrinthUpload.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import com.modrinth.minotaur.dependencies.Dependency;
66
import com.modrinth.minotaur.responses.ResponseUpload;
77
import io.papermc.paperweight.userdev.PaperweightUserExtension;
8-
import masecla.modrinth4j.endpoints.version.CreateVersion.CreateVersionRequest;
8+
import com.modrinth.minotaur.masecla.modrinth4j.endpoints.version.TemporaryCreateVersion;
9+
import com.modrinth.minotaur.masecla.modrinth4j.endpoints.version.TemporaryCreateVersion.TemporaryCreateVersionRequest;
910
import masecla.modrinth4j.main.ModrinthAPI;
1011
import masecla.modrinth4j.model.version.ProjectVersion;
1112
import masecla.modrinth4j.model.version.ProjectVersion.ProjectDependency;
@@ -199,8 +200,8 @@ && getProject().getExtensions().findByName("loom") != null) {
199200
protoDependencies.stream().map(dependency -> dependency.toNew(api)).forEach(dependencies::add);
200201

201202
// Get each of the files, starting with the primary file
202-
List<File> files = new ArrayList<>();
203-
files.add(ext.getFile().get().getAsFile());
203+
Map<File, String> files = new LinkedHashMap<>();
204+
files.put(ext.getFile().get().getAsFile(), "primary");
204205

205206
// Convert each of the Object files from the extension to a proper File
206207
ext.getAdditionalFiles().get().forEach(file -> {
@@ -211,11 +212,28 @@ && getProject().getExtensions().findByName("loom") != null) {
211212
throw new GradleException("The upload file is missing or null. " + file);
212213
}
213214

214-
files.add(resolvedFile);
215+
String fileName = resolvedFile.getName();
216+
String fileType = null;
217+
218+
// No switches in Java 8 :(
219+
if (fileName.contains("-dev.jar")) {
220+
fileType = "dev-jar";
221+
} else if (fileName.contains("-sources.jar")) {
222+
fileType = "sources-jar";
223+
} else if (fileName.contains("-javadoc.jar")) {
224+
fileType = "javadoc-jar";
225+
} else if (fileName.contains("asc") || fileName.contains("gpg") || fileName.contains("sig")) {
226+
fileType = "signature";
227+
}
228+
229+
files.put(resolvedFile, fileType);
215230
});
216231

232+
ext.getAdditionalFileDsl().getNamedAdditionalFilesAsList().forEach(file ->
233+
files.put(file.getFile().getAsFile(), file.getAdditionalFileType().toString()));
234+
217235
// Start construction of the actual request!
218-
CreateVersionRequest data = CreateVersionRequest.builder()
236+
TemporaryCreateVersionRequest data = TemporaryCreateVersionRequest.builder()
219237
.projectId(id)
220238
.versionNumber(versionNumber)
221239
.name(ext.getVersionName().get())
@@ -236,7 +254,8 @@ && getProject().getExtensions().findByName("loom") != null) {
236254
}
237255

238256
// Execute the request
239-
ProjectVersion version = api.versions().createProjectVersion(data).join();
257+
ProjectVersion version = new TemporaryCreateVersion(getProject()).sendRequest(data).join();
258+
//ProjectVersion version = api.versions().createProjectVersion(data).join();
240259
newVersion = version;
241260
//noinspection deprecation
242261
uploadInfo = new ResponseUpload(version);

src/main/java/com/modrinth/minotaur/Util.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Internal utility methods to make things easier and deduplicated
1717
*/
1818
@ApiStatus.Internal
19-
class Util {
19+
public class Util {
2020
/**
2121
* @param project Gradle project for getting various info from
2222
* @return A valid {@link ModrinthAPI} instance
@@ -49,7 +49,7 @@ static ModrinthAPI api(Project project) {
4949
* @param project Gradle project for getting various info from
5050
* @return The {@link ModrinthExtension} for the project
5151
*/
52-
static ModrinthExtension ext(Project project) {
52+
public static ModrinthExtension ext(Project project) {
5353
return project.getExtensions().getByType(ModrinthExtension.class);
5454
}
5555

@@ -59,7 +59,7 @@ static ModrinthExtension ext(Project project) {
5959
* @param project The Gradle project to resolve the extension and version from
6060
* @return The extension version number if set; otherwise, the Gradle project version.
6161
*/
62-
static String resolveVersionNumber(Project project) {
62+
public static String resolveVersionNumber(Project project) {
6363
ModrinthExtension ext = ext(project);
6464
if (ext.getVersionNumber().getOrNull() == null) {
6565
ext.getVersionNumber().set(project.getVersion().toString());
@@ -100,7 +100,7 @@ static File resolveFile(Project project, Object in) {
100100
return project.file(in);
101101
}
102102

103-
static Provider<RegularFile> resolveFileProperty(Project project, Object in) {
103+
public static Provider<RegularFile> resolveFileProperty(Project project, Object in) {
104104
if (in == null) {
105105
// If input is null we can't really do anything...
106106
return project.getObjects().fileProperty();
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.modrinth.minotaur.additionalfiles;
2+
3+
import com.modrinth.minotaur.Util;
4+
import org.gradle.api.NamedDomainObjectContainer;
5+
import org.gradle.api.Project;
6+
7+
import javax.inject.Inject;
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
/**
12+
* the Nested AdditionalFiles configuration
13+
*/
14+
public class AdditionalFileDSL {
15+
private final Project project;
16+
private final NamedDomainObjectContainer<NamedAdditionalFile> additionalFiles;
17+
18+
/**
19+
* Instantiates a new additionalFiles configuration.
20+
*
21+
* @param project Project
22+
*/
23+
@Inject
24+
public AdditionalFileDSL(final Project project) {
25+
this.project = project;
26+
this.additionalFiles = project.getObjects().domainObjectContainer(NamedAdditionalFile.class);
27+
}
28+
29+
/**
30+
* Returns the complete NamedAdditionalFile container set mapped and collected as a {@literal List<AdditionalFile>}
31+
*
32+
* @return {@literal List<AdditionalFile>}
33+
*/
34+
public List<NamedAdditionalFile> getNamedAdditionalFilesAsList() {
35+
return new ArrayList<>(this.additionalFiles);
36+
}
37+
38+
/**
39+
* Creates a required resource pack AdditionalFile Container
40+
*
41+
* @param file the file
42+
*/
43+
public void requiredResourcePack(final Object file) {
44+
this.additionalFiles.add(new NamedAdditionalFile(AdditionalFileType.REQUIRED_RESOURCE_PACK, Util.resolveFileProperty(project, file).get()));
45+
}
46+
47+
/**
48+
* Creates an optional resource pack AdditionalFile Container
49+
*
50+
* @param file the file
51+
*/
52+
public void optionalResourcePack(final Object file) {
53+
this.additionalFiles.add(new NamedAdditionalFile(AdditionalFileType.OPTIONAL_RESOURCE_PACK, Util.resolveFileProperty(project, file).get()));
54+
}
55+
56+
/**
57+
* Creates a sources JAR AdditionalFile Container
58+
*
59+
* @param file the file
60+
*/
61+
public void sourcesJar(final Object file) {
62+
this.additionalFiles.add(new NamedAdditionalFile(AdditionalFileType.SOURCES_JAR, Util.resolveFileProperty(project, file).get()));
63+
}
64+
65+
/**
66+
* Creates a dev JAR AdditionalFile Container
67+
*
68+
* @param file the file
69+
*/
70+
public void devJar(final Object file) {
71+
this.additionalFiles.add(new NamedAdditionalFile(AdditionalFileType.DEV_JAR, Util.resolveFileProperty(project, file).get()));
72+
}
73+
74+
/**
75+
* Creates a Javadoc JAR AdditionalFile Container
76+
*
77+
* @param file the file
78+
*/
79+
public void javadocJar(final Object file) {
80+
this.additionalFiles.add(new NamedAdditionalFile(AdditionalFileType.JAVADOC_JAR, Util.resolveFileProperty(project, file).get()));
81+
}
82+
83+
/**
84+
* Creates a signature AdditionalFile Container
85+
*
86+
* @param file the file
87+
*/
88+
public void signature(final Object file) {
89+
this.additionalFiles.add(new NamedAdditionalFile(AdditionalFileType.SIGNATURE, Util.resolveFileProperty(project, file).get()));
90+
}
91+
92+
/**
93+
* Creates another AdditionalFile Container
94+
*
95+
* @param file the file
96+
*/
97+
public void other(final Object file) {
98+
this.additionalFiles.add(new NamedAdditionalFile(AdditionalFileType.OTHER, Util.resolveFileProperty(project, file).get()));
99+
}
100+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.modrinth.minotaur.additionalfiles;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
import java.util.Locale;
6+
7+
/**
8+
* The enum representing the additional file types supported by Modrinth.
9+
*/
10+
public enum AdditionalFileType {
11+
/**
12+
* The file is a resource pack file that must be used alongside the file. Primarily meant for data
13+
* pack projects.
14+
*/
15+
@SerializedName("required-resource-pack")
16+
REQUIRED_RESOURCE_PACK,
17+
18+
/**
19+
* The file is a resource pack file that can be used alongside the file. Primarily meant for data
20+
* pack projects.
21+
*/
22+
@SerializedName("optional-resource-pack")
23+
OPTIONAL_RESOURCE_PACK,
24+
25+
/**
26+
* The file is a JAR containing source code.
27+
*/
28+
@SerializedName("sources-jar")
29+
SOURCES_JAR,
30+
31+
/**
32+
* The file is a JAR containing unmapped or development code.
33+
*/
34+
@SerializedName("dev-jar")
35+
DEV_JAR,
36+
37+
/**
38+
* The file is a JAR containing Javadoc documentation.
39+
*/
40+
@SerializedName("javadoc-jar")
41+
JAVADOC_JAR,
42+
43+
/**
44+
* The file is a signature file (asc, gpg, or sig).
45+
*/
46+
@SerializedName("signature")
47+
SIGNATURE,
48+
49+
/**
50+
* The file is a different type of additional file.
51+
*/
52+
@SerializedName("")
53+
OTHER;
54+
55+
public String toString() {
56+
if (this == OTHER) {
57+
return null;
58+
} else {
59+
return this.name().toLowerCase(Locale.ROOT).replace('_', '-');
60+
}
61+
}
62+
63+
}

0 commit comments

Comments
 (0)