@@ -25,7 +25,6 @@ import javax.xml.xpath.XPathFactory
25
25
* Would be good to PR some (or all) of these changes upstream at some point.
26
26
*
27
27
* @see net.fabricmc.loom.configuration.ide.idea.IdeaSyncTask
28
- * @see net.minecraftforge.gradle.common.util.runs.IntellijRunGenerator
29
28
*/
30
29
internal class IdeaRunConfigurations (project : Project ) {
31
30
private val rootProject = project.rootProject
@@ -35,33 +34,16 @@ internal class IdeaRunConfigurations(project: Project) {
35
34
private val writer = TransformerFactory .newInstance().newTransformer()
36
35
37
36
private val ideaDir = rootProject.file(" .idea/" )
38
- private val buildDir: Lazy <String ?> = lazy {
39
- val ideaMisc = ideaDir.resolve(" misc.xml" )
40
-
41
- try {
42
- val doc = Files .newBufferedReader(ideaMisc.toPath()).use {
43
- documentBuilder.parse(InputSource (it))
44
- }
45
- val node =
46
- xpath.evaluate(" //component[@name=\" ProjectRootManager\" ]/output" , doc, XPathConstants .NODE ) as Node
47
- val attr = node.attributes.getNamedItem(" url" ) as Attr
48
- attr.value.removePrefix(" file://" )
49
- } catch (e: Exception ) {
50
- LOGGER .error(" Failed to find root directory" , e)
51
- null
52
- }
53
- }
54
37
55
38
fun patch () = synchronized(LOCK ) {
56
39
val runConfigDir = ideaDir.resolve(" runConfigurations" )
57
40
if (! runConfigDir.isDirectory) return
58
41
59
42
Files .list(runConfigDir.toPath()).use {
60
43
for (configuration in it) {
61
- val filename = configuration.fileName.toString();
44
+ val filename = configuration.fileName.toString()
62
45
when {
63
46
filename.endsWith(" _fabric.xml" ) -> patchFabric(configuration)
64
- filename.startsWith(" forge_" ) && filename.endsWith(" .xml" ) -> patchForge(configuration)
65
47
else -> {}
66
48
}
67
49
}
@@ -72,65 +54,6 @@ internal class IdeaRunConfigurations(project: Project) {
72
54
setXml(" //configuration" , " folderName" ) { " Fabric" }
73
55
}
74
56
75
- private fun patchForge (path : Path ) = withXml(path) {
76
- val configId = path.fileName.toString().removePrefix(" forge_" ).removeSuffix(" .xml" )
77
- val sourceSet = forgeConfigs[configId]
78
- if (sourceSet == null ) {
79
- LOGGER .error(" [{}] Cannot map run configuration to a known source set" , path)
80
- return @withXml
81
- }
82
-
83
- setXml(" //configuration" , " folderName" ) { " Forge" }
84
- setXml(" //configuration/module" , " name" ) { " ${rootProject.name} .forge.$sourceSet " }
85
-
86
- if (buildDir.value == null ) return @withXml
87
- setXml(" //configuration/envs/env[@name=\" MOD_CLASSES\" ]" , " value" ) { classpath ->
88
- val classes = classpath!! .split(' :' )
89
- val newClasses = mutableListOf<String >()
90
- fun appendUnique (x : String ) {
91
- if (! newClasses.contains(x)) newClasses.add(x)
92
- }
93
-
94
- for (entry in classes) {
95
- if (! entry.contains(" /out/" )) {
96
- appendUnique(entry)
97
- continue
98
- }
99
-
100
- val match = CLASSPATH_ENTRY .matchEntire(entry)
101
- if (match != null ) {
102
- val modId = match.groups[" modId" ]!! .value
103
- val proj = match.groups[" proj" ]!! .value
104
- var component = match.groups[" component" ]!! .value
105
- if (component == " production" ) component = " main"
106
-
107
- appendUnique(forgeModEntry(modId, proj, component))
108
- } else {
109
- LOGGER .warn(" [{}] Unknown classpath entry {}" , path, entry)
110
- appendUnique(entry)
111
- }
112
- }
113
-
114
- // Ensure common code is on the classpath
115
- for (proj in listOf (" common" , " common-api" )) {
116
- for (component in listOf (" main" , " client" )) {
117
- appendUnique(forgeModEntry(" computercraft" , proj, component))
118
- }
119
- }
120
-
121
- if (newClasses.any { it.startsWith(" cctest%%" ) }) {
122
- appendUnique(forgeModEntry(" cctest" , " core" , " testFixtures" ))
123
- appendUnique(forgeModEntry(" cctest" , " common" , " testFixtures" ))
124
- appendUnique(forgeModEntry(" cctest" , " common" , " testMod" ))
125
- }
126
-
127
- newClasses.joinToString(" :" )
128
- }
129
- }
130
-
131
- private fun forgeModEntry (mod : String , project : String , component : String ) =
132
- " $mod %%${buildDir.value} /production/${rootProject.name} .$project .$component "
133
-
134
57
private fun LocatedDocument.setXml (xpath : String , attribute : String , value : (String? ) -> String ) {
135
58
val node = this @IdeaRunConfigurations.xpath.evaluate(xpath, document, XPathConstants .NODE ) as Node ?
136
59
if (node == null ) {
@@ -159,16 +82,5 @@ internal class IdeaRunConfigurations(project: Project) {
159
82
companion object {
160
83
private val LOGGER = Logging .getLogger(IdeaRunConfigurations ::class .java)
161
84
private val LOCK = Any ()
162
-
163
- private val CLASSPATH_ENTRY =
164
- Regex (" (?<modId>[a-z]+)%%\\ \$ PROJECT_DIR\\ \$ /projects/(?<proj>[a-z-]+)/out/(?<component>\\ w+)/(?<type>[a-z]+)\$ " )
165
-
166
- private val forgeConfigs = mapOf (
167
- " runClient" to " client" ,
168
- " runData" to " main" ,
169
- " runGameTestServer" to " testMod" ,
170
- " runServer" to " main" ,
171
- " runTestClient" to " testMod" ,
172
- )
173
85
}
174
86
}
0 commit comments