Skip to content

Commit

Permalink
Add a propertiesHelp task to print a list of all available properties
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Jun 14, 2024
1 parent 95896f8 commit 3a4d92d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ gtnh.modules.codeStyle = false
gtnh.modules.modernJava = false

```

Run `./gradlew propertiesHelp` to list all the available properties along with their descriptions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.io.PrintStream;
import java.io.Reader;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand Down Expand Up @@ -926,6 +927,48 @@ private static void appendPropertySafeString(StringBuilder sb, String text) {
});
}

/**
* Prints documentation for all the available properties
*
* @param out The stream to write to.
*/
public static void printPropertyDocs(final PrintStream out) {
out.println("GTNHGradle supports various Gradle properties to change its behaviour:");
final Field[] fields = PropertiesConfiguration.class.getDeclaredFields();
final PropertiesConfiguration defaultCfg = new PropertiesConfiguration();
try {
for (final Field field : fields) {
final Prop prop = field.getAnnotation(Prop.class);
if (prop == null) {
continue;
}
final String key = prop.name();
Object defaultValue = field.get(defaultCfg);
if (defaultValue instanceof String) {
defaultValue = '"' + (String) defaultValue + '"';
} else if (defaultValue == null) {
defaultValue = "null";
}
out.println();
out.print("Key: ");
out.println(key);
out.printf(
"Affects settings.gradle: %s Required: %s Default: %s%n",
prop.isSettings(),
prop.required(),
defaultValue);
out.println("Description: ");
String docOut = "\n" + prop.docComment()
.trim();
// indent everything two spaces
docOut = docOut.replace("\n", "\n ");
out.println(docOut);
}
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}

/** Property metadata */
@Documented
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
});
});

tasks.register("propertiesHelp", t -> {
t.setGroup("GTNH Buildscript");
t.setDescription("Prints descriptions for all the settings available in gradle.properties");
t.doLast(inner -> { PropertiesConfiguration.printPropertyDocs(System.out); });
});

tasks.register("deobfParams", t -> {
t.setGroup("GTNH Buildscript");
t.setDescription("Rename all obfuscated parameter names inherited from Minecraft classes");
Expand Down

0 comments on commit 3a4d92d

Please sign in to comment.