Skip to content

Commit

Permalink
[FEAT] Allow adding additional files with a custom Display Name and C…
Browse files Browse the repository at this point in the history
…hangelog. Implements #5
  • Loading branch information
hypherionmc committed Jan 22, 2024
1 parent 5d2c9ec commit 546f517
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 17 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version_base=2.0
version_patch=2
version_patch=3

# Dependencies
curse4j=1.0.9
curse4j=1.0.10
modrinth4j=2.2.0
github=1.318
mavenart=4.0.0-alpha-8
Expand Down
24 changes: 24 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,24 @@ publisher {
// Disable the built in Fractureizer scanner
setDisableMalwareScanner(true)
// Add supported java versions. Currently only used by CurseForge
setJavaVersions("Java 8", "Java 11")
// Safety check to check if the artifact contains a valid mod metadata entry,
// which could possibly mean that the jar is empty
setDisableEmptyJarCheck(true)
// Additional files to upload. Same as artifact, this can be a task, file or string
addAdditionalFile(jar, secondJar)
// Additional files to upload with a custom display name and changelog.
// Currently only supported on Curseforge
addAdditionalFile {
// File, Task or String
artifact jar
displayName "Some Name"
changelog "Hello Changelog"
}
}
```

Expand Down Expand Up @@ -268,9 +280,21 @@ publisher {
// Safety check to check if the artifact contains a valid mod metadata entry,
// which could possibly mean that the jar is empty
disableEmptyJarCheck.set(true)

// Add supported java versions. Currently only used by CurseForge
setJavaVersions("Java 8", "Java 11")

// Additional files to upload. Same as artifact, this can be a task, file or string
additionalFiles.set(listOf(tasks.jar))

// Additional files to upload with a custom display name and changelog.
// Currently supports CurseForge only
addAdditionalFile {
// File, Task or String
artifact(tasks.jar)
displayName("Test Name")
changelog("Some Changelog")
}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;

import java.util.ArrayList;
import java.util.HashMap;

/**
Expand Down Expand Up @@ -85,7 +84,7 @@ public class ModPublisherGradleExtension {
@Getter private final Property<Boolean> useModrinthStaging;

// Allow uploading additional files
@Getter private final ListProperty<Object> additionalFiles;
@Getter private final ListProperty<AdditionalFile> additionalFiles;

@Getter private final ListProperty<String> javaVersions;

Expand Down Expand Up @@ -125,7 +124,7 @@ public ModPublisherGradleExtension(Project project) {
this.disableMalwareScanner = project.getObjects().property(Boolean.class).convention(false);
this.disableEmptyJarCheck = project.getObjects().property(Boolean.class).convention(false);
this.useModrinthStaging = project.getObjects().property(Boolean.class).convention(false);
this.additionalFiles = project.getObjects().listProperty(Object.class).empty();
this.additionalFiles = project.getObjects().listProperty(AdditionalFile.class).empty();
}

/**
Expand Down Expand Up @@ -265,15 +264,31 @@ public void setReleaseType(ReleaseType type) {
* @param file The file
*/
public void addAdditionalFile(Object file) {
this.additionalFiles.add(file);
AdditionalFile additionalFile = new AdditionalFile();
additionalFile.artifact = file;
this.additionalFiles.add(additionalFile);
}

/**
* Allow adding multiple additional files to be uploaded along with the main artifact
* @param file The files
*/
public void addAdditionalFile(Object... file) {
this.additionalFiles.addAll(file);
for (Object f : file) {
AdditionalFile additionalFile = new AdditionalFile();
additionalFile.artifact = f;
this.additionalFiles.add(additionalFile);
}
}

/**
* DSL support for adding a file with a custom display name and changelog
* @param file The DSL object containing the file data
*/
public void addAdditionalFile(Action<AdditionalFile> file) {
AdditionalFile additionalFile = new AdditionalFile();
file.execute(additionalFile);
this.additionalFiles.add(additionalFile);
}

@Getter
Expand Down Expand Up @@ -407,5 +422,43 @@ public void embedded(String... deps) {
embedded.addAll(deps);
}
}

/**
* Helper Class to add additional files with a custom Changelog and Display name
*/
@Getter
public static class AdditionalFile {
private Object artifact;
private String displayName;
private String changelog;

public void configure(Action<AdditionalFile> action) {
action.execute(this);
}

/**
* Set the artifact
* @param file The File, Task or String
*/
public void artifact(Object file) {
this.artifact = file;
}

/**
* Set the artifact Display Name
* @param displayName The display name
*/
public void displayName(String displayName) {
this.displayName = displayName;
}

/**
* Set the artifact changelog
* @param changelog The changelog
*/
public void changelog(String changelog) {
this.changelog = changelog;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

import javax.annotation.Nonnull;

import java.io.File;
import java.io.FileNotFoundException;

import static com.hypherionmc.modpublisher.Constants.*;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ public void upload() throws Exception {
}

if (extension.getAdditionalFiles().isPresent()) {
for (Object file : extension.getAdditionalFiles().get()) {
artifact.addAdditionalFile(CommonUtil.resolveFile(project, file));
for (ModPublisherGradleExtension.AdditionalFile file : extension.getAdditionalFiles().get()) {
String changelog = file.getChangelog() == null ? null : CommonUtil.resolveString(file.getChangelog());
artifact.addAdditionalFile(CommonUtil.resolveFile(project, file.getArtifact()), file.getDisplayName(), changelog);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public void upload() throws Exception {
throw new IOException("Failed to upload release to github. No error found");

if (extension.getAdditionalFiles().isPresent()) {
for (Object file : extension.getAdditionalFiles().get()) {
ghRelease.uploadAsset(CommonUtil.resolveFile(project, file), "application/octet-stream");
for (ModPublisherGradleExtension.AdditionalFile file : extension.getAdditionalFiles().get()) {
ghRelease.uploadAsset(CommonUtil.resolveFile(project, file.getArtifact()), "application/octet-stream");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public void upload() throws Exception {
}

if (extension.getAdditionalFiles().isPresent()) {
for (Object file : extension.getAdditionalFiles().get()) {
uploadFiles.add(CommonUtil.resolveFile(project, file));
for (ModPublisherGradleExtension.AdditionalFile file : extension.getAdditionalFiles().get()) {
uploadFiles.add(CommonUtil.resolveFile(project, file.getArtifact()));
}
}
builder.files(uploadFiles);
Expand Down
7 changes: 7 additions & 0 deletions testprojects/groovytest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ publisher {
setPlatformArtifact(com.hypherionmc.modpublisher.properties.Platform.MODRINTH, createDummyJar)
setDisableEmptyJarCheck(true)
addAdditionalFile(jar)
setJavaVersions("Java 8", "Java 11")

addAdditionalFile {
artifact jar
displayName "Some Name"
changelog "Hello Changelog"
}

modrinthDepends {
required "fabric-api", "craterlib"
Expand Down
8 changes: 7 additions & 1 deletion testprojects/kotlintest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ publisher {
artifact.set(tasks.jar)
setPlatformArtifact("modrinth", dummyTask)
useModrinthStaging.set(false)
additionalFiles.set(listOf(tasks.jar))
addAdditionalFile(tasks.jar)

addAdditionalFile {
artifact(tasks.jar)
displayName("Test Name")
changelog("Some Changelog")
}

curseDepends {
required("fabric-api", "craterlib")
Expand Down

0 comments on commit 546f517

Please sign in to comment.