@@ -51,150 +51,4 @@ sourceSets {
5151 srcDirs = []
5252 }
5353 }
54- }
55-
56- // Put licenser here otherwise it tries to license all source sets including decompiled MC sources
57- license {
58- header = file(' codeformat/HEADER.txt' )
59- skipExistingHeaders = true
60- tasks {
61- neoforge {
62- // Add all NeoForge sources
63- files. from rootProject. fileTree(" src" , {
64- include " **/*.java"
65- })
66- }
67- }
68- }
69-
70- // Put spotless here because it wants the files to live inside the project root
71- immaculate {
72- workflows. named(" java" ) {
73- files. from rootProject. fileTree(" buildSrc/src" , {
74- include " **/*.java"
75- })
76- files. from rootProject. fileTree(" src" , {
77- include " **/*.java"
78- })
79- }
80- workflows. register(" patches" ) {
81- files. from(rootProject. fileTree(" patches" ))
82-
83- custom ' noImportChanges' , { String fileContents ->
84- if (fileContents. contains(' +import' ) || fileContents. contains(' -import' )) {
85- throw new GradleException (" Import changes are not allowed in patches!" )
86- }
87- return fileContents
88- }
89-
90- def interfaceChange = Pattern . compile(' [-+].*(implements|(interface.*extends))(.*)\\ {' )
91- custom ' noInterfaceModifications' , { String fileContents ->
92- // FIXME: remove when handling of Holder is resolved
93- // Special case: removal of sealed and permits incorrectly triggers interface change detection
94- if (fileContents. startsWith(" --- a/net/minecraft/core/Holder.java" )) {
95- return fileContents
96- }
97-
98- def interfaceChanges = fileContents. lines(). filter { it. matches(interfaceChange) }. toList()
99- if (interfaceChanges. isEmpty()) return fileContents
100- String oldInterfaces = " "
101- // we expect interface additions/removals in pairs of - and then +
102- interfaceChanges. each { String change ->
103- final match = change =~ interfaceChange
104- match. find()
105- final values = match. group(3 ). trim()
106- if (change. startsWith(' -' )) {
107- oldInterfaces = values
108- } else if (oldInterfaces != values) {
109- throw new GradleException (" Modification of interfaces via patches is not allowed!" )
110- }
111- }
112- return fileContents
113- }
114-
115- // Note: This doesn't detect changing access level to or from package private
116- // TODO: Eventually try and make this support checking package private access level changes?
117- def accessLevelChange = Pattern . compile(' ^[-+]\\ s*(public|private|protected)\\ s.*\$ ' , Pattern . UNIX_LINES | Pattern . MULTILINE )
118- custom ' noAccessChanges' , { String fileContents ->
119- // Special case: we need to make the field private for our coremod
120- if (fileContents. startsWith(" --- a/net/minecraft/world/level/levelgen/structure/Structure.java" )) {
121- return fileContents
122- }
123-
124- // The anvil menu patches a method to be final, which cannot be done with an AT, but trips this check otherwise.
125- if (fileContents. startsWith(" --- a/net/minecraft/world/inventory/AnvilMenu.java" )) {
126- return fileContents
127- }
128-
129- def accessChanges = fileContents. findAll(accessLevelChange)
130- if (accessChanges. isEmpty()) return fileContents
131- Map<String , Set<String > > removals = Map . of(" private" , new HashSet<> (), " protected" , new HashSet<> (), " public" , new HashSet<> ())
132- accessChanges. each { String change ->
133- // Get the type of match
134- String [] data = change. substring(1 ). trim(). split(" " , 2 )
135- String lineStart = data[1 ]. substring(0 , Math . min(30 , data[1 ]. length()))
136- if (change. startsWith(' -' )) {// Removal
137- removals. get(data[0 ]). add(lineStart)
138- } else {// Addition
139- for (var entry : removals. entrySet()) {
140- if (entry. key == data[0 ]) {
141- continue
142- }
143- if (entry. value. remove(lineStart)) {
144- throw new GradleException (" Changing access level via patches is not allowed, use an AT! Changed line: " + change)
145- }
146- }
147- }
148- }
149- // Note: We allow mismatched counts in case we are removing a method entirely for some reason
150- return fileContents
151- }
152-
153- // Trim any trailing whitespace from patch additions
154- def trailingWhitespace = Pattern . compile(' ^\\ +.*[ \t ]+\$ ' , Pattern . UNIX_LINES | Pattern . MULTILINE )
155- custom ' trimTrailingWhitespacePatches' , { String fileContents ->
156- Matcher matcher = trailingWhitespace. matcher(fileContents)
157- StringBuilder sb = new StringBuilder ()
158- while (matcher. find()) {
159- matcher. appendReplacement(sb, matcher. group(). trim())
160- }
161- matcher. appendTail(sb)
162- return sb. toString()
163- }
164-
165- // Disallow explicit not null in patches, it's always implied.
166- custom ' noNotNull' , { String fileContents ->
167- fileContents. eachLine {
168- if (! it. startsWith(" +" )) return
169- if (it. contains(' @NotNull' ) || it. contains(' @Nonnull' )
170- || it. contains(' @org.jetbrains.annotations.NotNull' )
171- || it. contains(' @javax.annotation.Nonnull' )) {
172- throw new GradleException (' @NotNull and @Nonnull are disallowed.' )
173- }
174- }
175- }
176-
177- // Replace any FQN versions of javax/jetbrains @Nullable with the jspecify variant
178- custom ' jetbrainsNullablePatches' , { String fileContents ->
179- fileContents. replace(' @javax.annotation.Nullable' , ' @org.jspecify.annotations.Nullable' )
180- fileContents. replace(' @org.jetbrains.annotations.Nullable' , ' @org.jspecify.annotations.Nullable' )
181- }
182- }
183- }
184-
185- final task = tasks. register(' checkSourcesAreSplit' , CheckSplitSources ) {
186- serverClientFolder = project. provider { project. layout. projectDirectory. dir(' src/main/java/net/neoforged/neoforge/client' ) }
187- .map { it. asFile. exists() ? it : null }
188- clientClientFolder = project. layout. projectDirectory. dir(' src/client/java/net/neoforged/neoforge/client' )
189- }
190-
191- tasks. named(' checkFormatting' ) {
192- dependsOn(task)
193- }
194-
195- tasks. withType(JavaCompile ). configureEach {
196- it. options. release = 25
197- options. encoding = ' UTF-8'
198- options. warnings = false
199- options. compilerArgs << " -Xlint:-removal" << " -Xlint:-deprecation" << " -Xlint:-dep-ann" << " -Xlint:-varargs" << " -Xdiags:verbose"
20054}
0 commit comments