Escape each element of the IntelliJ module name - #354
Open
adityaanikam wants to merge 1 commit into
Open
adityaanikam wants to merge 1 commit into
adityaanikam wants to merge 1 commit into
Conversation
IntelliJ escapes every element of the Gradle path on its own and joins the escaped elements with '.', so an element containing a '.' does not survive. Joining the raw path meant a subproject named "1.21.1-neoforge" produced "root.1.21.1-neoforge.main" where IntelliJ has "root.1_21_1-neoforge.main". That module does not exist, so the generated run configuration was written without one and IntelliJ built the classpath from the whole project. Mirror IntelliJ's escapeModuleNameElement and apply it to the root project name, each path element and the source set name. The comment above this code pointed at an older code path that keeps dots, which is repointed at the current one.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #353
Problem
getIntellijModuleNamebuilds the module name by joining the Gradle path as-is:IntelliJ escapes each element of the path individually and then joins the escaped elements with
., so an element that itself contains a.is not preserved. For a subproject:1.21.1-neoforgeunder rootxaeronav, IntelliJ's module isxaeronav.1_21_1-neoforge.mainwhile the above producesxaeronav.1.21.1-neoforge.main.That name matches no module, so
setModuleName(..)leaves the generated run configuration without one. IntelliJ then builds-classpathfrom the whole project, which in a multi-loader setup pulls in the other loader's Minecraft and dev launch aborts:About the comment above that code
The comment currently points at IntelliJ's
GradleProjectResolverUtil#getInternalModuleName/PathUtilRt#suggestFileNameat a pinned revision. That code does not do this escaping — it splits on:, joins with., and finishes withsuggestFileName(name, /* allowDots = */ true, false), which keeps dots. Read on its own it suggests the current behaviour is correct, which is presumably how this survived.The escaping happens on the newer sync path, which is what recent IDEA uses:
and source set modules are
holderModuleName + "." + escapeModuleNameElement(sourceSetName).So I have repointed the comment at those two methods with a pinned permalink, since the stale link is part of why this looked right.
Fix
Mirror
escapeModuleNameElementand apply it per element — to the root project name, each path element, and the source set name:This is slightly wider than just handling dots: IntelliJ escapes
/and\too, and applies the same escaping to the root name and the source set name, where the current code only replaced spaces in the root name and did not touch the source set name at all.getIntellijModuleNameis now package-private so it can be tested.Testing
IntelliJIntegrationTest— 7 cases: four forescapeModuleNameElement(plain, space, dots, slash) and three building names throughProjectBuilder(root project, a subproject with dots, and a nested subproject).Verified with a negative control. Restoring the old assembly (keeping the new helper so the test still compiles) fails exactly the two name tests, with the broken names from the issue:
Restoring the fix returns all 7 to passing.