Skip to content

Commit 2b0914a

Browse files
authored
Add defaultLineFeed option (#34)
- Add build.gradle option defaultLineFeed - Renamed `SocketLock` to `PortLock` to match documentation - Removed excessive javadoc warnings from console when publishing - Removed Triple class - Lots of renames - More documentation - Fix workflow - Renamed package `extension` to `config`
2 parents 843be6b + d61ff5c commit 2b0914a

19 files changed

+314
-135
lines changed

.github/workflows/publish-main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ jobs:
2222
with:
2323
gradle-version: 8.13
2424
- name: Publish
25-
run: gradle publishAllPublicationsToMinecrafttasMainRepository -PminecrafttasMainUsername=${{ secrets.MAVEN_NAME }} -PminecrafttasMainPassword=${{ secrets.MAVEN_SECRET }}
25+
run: gradle publishAllPublicationsToMinecrafttasMainRepository -Prelease=true -PminecrafttasMainUsername=${{ secrets.MAVEN_NAME }} -PminecrafttasMainPassword=${{ secrets.MAVEN_SECRET }}

Test/Test1.12.2/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ dependencies {
1515
minecraft "com.mojang:minecraft:1.12.2"
1616
mappings "net.legacyfabric:yarn:1.12.2+build.mcp"
1717
modImplementation "net.fabricmc:fabric-loader:0.16.9"
18-
}
18+
}

Test/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ discombobulator {
1010

1111
ignoredFileFormats = ["*.png"]
1212

13+
defaultLineFeed = "\n"
14+
1315
disableAnsi = false
14-
}
16+
}

build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ plugins {
77
// Change java compatibility level to 23
88
sourceCompatibility = targetCompatibility = 23
99

10+
def snapshot = project.release ? "" : "-SNAPSHOT"
11+
version = project.version+snapshot
1012
// Name, version and group for the project
1113
version = "1.3"
1214
group = "com.minecrafttas"
@@ -46,12 +48,16 @@ java {
4648

4749
javadoc {
4850
options.locale = "en_US"
51+
options.addBooleanOption('Xdoclint:none', true)
52+
}
53+
54+
publishToMavenLocal {
55+
version = version + "-SNAPSHOT"
4956
}
5057

5158
publishing {
5259
repositories {
5360
maven {
54-
version = version + "-SNAPSHOT"
5561
name = "minecrafttasSnapshots"
5662
url = "https://maven.minecrafttas.com/snapshots"
5763
credentials(PasswordCredentials)

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version=1.3
2+
release=false

src/main/java/com/minecrafttas/discombobulator/Discombobulator.java

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.gradle.api.artifacts.Configuration;
2727
import org.gradle.api.artifacts.ModuleVersionIdentifier;
2828

29-
import com.minecrafttas.discombobulator.extensions.PreprocessingConfiguration;
29+
import com.minecrafttas.discombobulator.config.PreprocessingConfiguration;
3030
import com.minecrafttas.discombobulator.processor.FilePreprocessor;
3131
import com.minecrafttas.discombobulator.processor.LinePreprocessor;
3232
import com.minecrafttas.discombobulator.tasks.TaskCollectBuilds;
@@ -40,16 +40,21 @@
4040
/**
4141
* Gradle plugin main class
4242
*
43-
* @author Pancake
43+
* @author Pancake, Scribble
4444
*/
4545
public class Discombobulator implements Plugin<Project> {
4646

47+
/**
48+
* Which port to lock
49+
*/
4750
public static int PORT_LOCK = 8762;
4851

4952
public static PreprocessingConfiguration config;
5053

5154
public static boolean DISABLE_ANSI = false;
5255

56+
public static String DEFAULT_LINE_FEED = System.lineSeparator();
57+
5358
public static FilePreprocessor fileProcessor;
5459

5560
public static PathLock pathLock;
@@ -98,6 +103,7 @@ public void apply(Project project) {
98103
boolean inverted = config.getInverted().getOrElse(false);
99104
PORT_LOCK = config.getPort().getOrElse(8762);
100105
DISABLE_ANSI = config.getDisableAnsi().getOrElse(false);
106+
DEFAULT_LINE_FEED = config.getDefaultLineFeed().getOrElse(System.lineSeparator());
101107

102108
Map<String, Path> versionPairs = null;
103109
Path projectDir = _project.getProjectDir().toPath();
@@ -157,11 +163,26 @@ public static LinkedHashMap<String, Path> getVersionPairs(Path baseProjectDir) t
157163
return versions;
158164
}
159165

166+
/**
167+
* Centers any given text
168+
* @param text The text to print
169+
* @return The centered text
170+
*/
160171
private static String getCenterText(String text) {
161172
int length = text.length();
162173
return getCenterText(text, length);
163174
}
164175

176+
/**
177+
* Centers any given text
178+
*
179+
* This method is used if ANSI colors are in the text which are not rendered,<br>
180+
* but are still counted in String.length();
181+
*
182+
* @param text The text to print
183+
* @param length The length of the text
184+
* @return The centered text
185+
*/
165186
private static String getCenterText(String text, int length) {
166187
int total = 31;
167188
if (length % 2 == 0) {
@@ -170,14 +191,26 @@ private static String getCenterText(String text, int length) {
170191
return String.format("%s%s", " ".repeat(total - length / 2), text);
171192
}
172193

173-
public static void printError(String line) {
174-
System.err.println(Colors.RED + line + Colors.WHITE);
194+
/**
195+
* Prints an error in red to the console
196+
* @param msg The error message to print
197+
*/
198+
public static void printError(String msg) {
199+
System.err.println(Colors.RED + msg + Colors.WHITE);
175200
}
176201

177-
public static void printError(String line, String filename) {
178-
printError(String.format("[%s] %s", filename, line));
202+
/**
203+
* Print an error to the console in red together with the file where this error occured in
204+
* @param msg The error message to print
205+
* @param filename The filename of the file where this error occured
206+
*/
207+
public static void printError(String msg, String filename) {
208+
printError(String.format("[%s] %s", filename, msg));
179209
}
180210

211+
/**
212+
* @return The splash with ANSI colors
213+
*/
181214
private static String getColoredSplash() {
182215
return " (\n"
183216
+ " )\\ ) ) ) ( )\n"
@@ -189,6 +222,9 @@ private static String getColoredSplash() {
189222
+ " |___/|_/__|__\\___/_|_|_| |_.__/\\___/_.__/\\_,_|_\\__,_|\\__\\___/_|\n";
190223
}
191224

225+
/**
226+
* @return The splash without ANSI colors
227+
*/
192228
private static String getColorLessSplash() {
193229
return " ( \n"
194230
+ " )\\ ) ) ) ( ) \n"
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package com.minecrafttas.discombobulator.config;
2+
3+
import java.util.Map;
4+
5+
import org.gradle.api.provider.ListProperty;
6+
import org.gradle.api.provider.MapProperty;
7+
import org.gradle.api.provider.Property;
8+
9+
import com.minecrafttas.discombobulator.utils.PortLock;
10+
11+
/**
12+
* Configuration for preprocessing
13+
* @author Pancake
14+
*/
15+
public abstract class PreprocessingConfiguration {
16+
17+
/**
18+
* All versions for the project
19+
* <pre>
20+
* versions = [
21+
* "1.14.4":"",
22+
* "1.12.2":"",
23+
* "1.8.9": "AlternateFolderName1.8.9"
24+
* ]
25+
* </pre>
26+
*
27+
* <p>A subproject will be created, only if a version is present in the list.
28+
*
29+
* <p>Defaults to []
30+
* @return Ordered list of versions
31+
*/
32+
public abstract MapProperty<String, String> getVersions();
33+
34+
/**
35+
* All patterns for the project.
36+
* <pre>
37+
* patterns = [
38+
* GetMinecraft: [
39+
* "1.14.4": "Minecraft.getMinecraft().getPlayer()",
40+
* "1.12.2": "Minecraft.getMinecraft().player",
41+
* "def": "Minecraft.getMinecraft().thePlayer"
42+
* ]
43+
* ]
44+
* </pre>
45+
* <p>Anything annotated by @key will be adjusted according to the version where "1.14.4" would refer to any version above or equal to 1.14.4<br>
46+
* {@code Minecraft.getMinecraft().getPlayer(); // @GetMinecraft} would be adjusted to {@code Minecraft.getMinecraft().thePlayer} in versions below 1.12.2
47+
*
48+
* <p>Defaults to []
49+
*
50+
* @return Map of patterns
51+
*/
52+
public abstract MapProperty<String, Map<String, String>> getPatterns();
53+
54+
/**
55+
* <p>If the default version should be inverted
56+
*
57+
* <p>This makes it, so the highest version is considered the default version
58+
* <pre>
59+
* versions = [
60+
* "1.12.2":"", &lt;- Default version if inverted is true
61+
* "1.11.2":"",
62+
* "1.10.2":"",
63+
* "1.9.4":"",
64+
* "1.8.9": "" &lt;- Default version if inverted is false
65+
* ]
66+
* </pre>
67+
*
68+
* <pre>
69+
* inverted = false
70+
* </pre>
71+
*
72+
* <p>Defaults to false
73+
*
74+
* @return True if inverted
75+
*/
76+
public abstract Property<Boolean> getInverted();
77+
78+
/**
79+
* If true, disables ANSI colors
80+
*
81+
* <pre>
82+
* disableAnsi = false
83+
* </pre>
84+
*
85+
* <p>Defaults to false
86+
*
87+
* @return True if disabled
88+
*/
89+
public abstract Property<Boolean> getDisableAnsi();
90+
91+
/**
92+
* The port for the {@link PortLock}
93+
*
94+
* <pre>
95+
* port = 8762
96+
* </pre>
97+
*
98+
* <p>Defaults to 8762
99+
*
100+
* @return The port number
101+
*/
102+
public abstract Property<Integer> getPort();
103+
104+
/**
105+
* <p>Filetypes which should be ignored by the preprocessor and just copied.<br>
106+
* Usually binary file formats should be excluded in this list
107+
*
108+
* <pre>
109+
* ignoredFileFormats = ["*.png"]
110+
* </pre>
111+
*
112+
* <p>Defaults to []
113+
* @return A string array of file filter wildcards
114+
*/
115+
public abstract ListProperty<String> getIgnoredFileFormats();
116+
117+
/**
118+
* <p>Set's the default line feed character
119+
*
120+
* <p>If this option is not set, the {@link System#lineSeparator()} is used instead.
121+
* <p>This option can also be overwritten by the system property "line.seperator"
122+
* <pre>
123+
* defaultLineFeed = "\n"
124+
* </pre>
125+
* @return The line feed string
126+
*/
127+
public abstract Property<String> getDefaultLineFeed();
128+
}

src/main/java/com/minecrafttas/discombobulator/extensions/PreprocessingConfiguration.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)