Skip to content

Commit 6ad9559

Browse files
committed
WIP Replace arch-loom with ForgeGradle
1 parent efb1b64 commit 6ad9559

File tree

15 files changed

+426
-176
lines changed

15 files changed

+426
-176
lines changed

bootstrap-dev/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies {
2+
api(libs.bootstrap.api)
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module org.spongepowered.boostrap.dev {
2+
requires net.minecraftforge.bootstrap.api;
3+
exports org.spongepowered.bootstrap.dev;
4+
5+
provides net.minecraftforge.bootstrap.api.BootstrapClasspathModifier with org.spongepowered.bootstrap.dev.SpongeDevClasspathFixer;
6+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This file is part of Sponge, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.bootstrap.dev;
26+
27+
import java.util.HashMap;
28+
import java.util.LinkedList;
29+
import java.util.List;
30+
31+
public class Multimap<K, V> extends HashMap<K, List<V>> {
32+
33+
public void add(K key, V value) {
34+
this.computeIfAbsent(key, k -> new LinkedList<>()).add(value);
35+
}
36+
}

vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java renamed to bootstrap-dev/src/main/java/org/spongepowered/bootstrap/dev/SourceSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
package org.spongepowered.vanilla.devlaunch;
25+
package org.spongepowered.bootstrap.dev;
2626

2727
import java.nio.file.Files;
2828
import java.nio.file.Path;

vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java renamed to bootstrap-dev/src/main/java/org/spongepowered/bootstrap/dev/SpongeDevClasspathFixer.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
package org.spongepowered.vanilla.devlaunch;
25+
package org.spongepowered.bootstrap.dev;
2626

2727
import net.minecraftforge.bootstrap.api.BootstrapClasspathModifier;
2828

29+
import java.io.File;
2930
import java.nio.file.Files;
3031
import java.nio.file.Path;
3132
import java.util.ArrayList;
32-
import java.util.HashMap;
33-
import java.util.LinkedList;
3433
import java.util.List;
35-
import java.util.Map;
3634
import java.util.Set;
3735
import java.util.concurrent.atomic.AtomicBoolean;
3836

@@ -51,11 +49,12 @@ public String name() {
5149
*/
5250
@Override
5351
public boolean process(final List<Path[]> classpath) {
54-
final Set<String> bootLibs = Set.of(System.getProperty("sponge.dev.boot").split(";"));
55-
final Set<String> gameShadedLibs = Set.of(System.getProperty("sponge.dev.gameShaded").split(";"));
52+
final Set<String> ignoredLibs = Set.of("bootstrap-dev.jar");
53+
final Set<String> bootLibs = Set.of(System.getProperty("sponge.dev.boot").split(File.pathSeparator));
54+
final Set<String> gameShadedLibs = Set.of(System.getProperty("sponge.dev.gameShaded").split(File.pathSeparator));
5655

57-
final Map<String, List<Path>> bootSourceSets = new HashMap<>();
58-
final Map<String, List<Path>> unknownProjects = new HashMap<>();
56+
final Multimap<String, Path> bootSourceSets = new Multimap<>();
57+
final Multimap<String, Path> unknownProjects = new Multimap<>();
5958

6059
final List<Path> spongeImplUnion = new ArrayList<>();
6160
final List<Path> gameLibs = new ArrayList<>();
@@ -75,8 +74,11 @@ public boolean process(final List<Path[]> classpath) {
7574
}
7675

7776
switch (sourceSet.project()) {
78-
case "modlauncher-transformers":
79-
bootSourceSets.computeIfAbsent("transformers", k -> new LinkedList<>()).add(path);
77+
case "bootstrap-dev":
78+
// ignore
79+
break;
80+
case "modlauncher-transformers", "library-manager":
81+
bootSourceSets.add(sourceSet.project(), path);
8082
break;
8183
case "SpongeAPI":
8284
switch (sourceSet.name()) {
@@ -91,28 +93,29 @@ public boolean process(final List<Path[]> classpath) {
9193
break;
9294
}
9395
break;
94-
case "Sponge", "vanilla":
95-
switch (sourceSet.name()) {
96-
case "devlaunch":
97-
// ignore
98-
break;
99-
case "applaunch":
100-
bootSourceSets.computeIfAbsent("applaunch", k -> new LinkedList<>()).add(path);
101-
break;
102-
default:
103-
spongeImplUnion.add(path);
104-
break;
96+
case "Sponge", "vanilla", "forge":
97+
if (sourceSet.name().equals("applaunch")) {
98+
bootSourceSets.add("applaunch", path);
99+
} else {
100+
spongeImplUnion.add(path);
105101
}
106102
break;
107103
default:
108-
unknownProjects.computeIfAbsent(sourceSet.project(), k -> new LinkedList<>()).add(path);
104+
unknownProjects.add(sourceSet.project(), path);
109105
break;
110106
}
111107
return true;
112108
}
113109

114110
final String fileName = path.getFileName().toString();
115111

112+
if (ignoredLibs.contains(fileName)) {
113+
if (DEBUG) {
114+
System.out.println("Ignored: " + path);
115+
}
116+
return true;
117+
}
118+
116119
if (bootLibs.contains(fileName)) {
117120
if (DEBUG) {
118121
System.out.println("Boot: " + path);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.spongepowered.bootstrap.dev.SpongeDevClasspathFixer

build-logic/src/main/java/org/spongepowered/gradle/impl/SpongeImplementationExtension.java

Lines changed: 87 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@
3737

3838
import javax.annotation.Nullable;
3939
import javax.inject.Inject;
40+
import java.io.File;
4041
import java.util.Collection;
4142
import java.util.Collections;
4243
import java.util.HashMap;
4344
import java.util.HashSet;
4445
import java.util.Map;
4546
import java.util.Objects;
4647
import java.util.Set;
48+
import java.util.StringJoiner;
49+
import java.util.function.Predicate;
4750
import java.util.stream.Collectors;
4851
import java.util.stream.Stream;
4952

@@ -60,33 +63,100 @@ public SpongeImplementationExtension(final Project project, final Logger logger)
6063
this.logger = logger;
6164
}
6265

63-
public void copyModulesExcludingProvided(final Configuration source, final Configuration provided, final Configuration target) {
64-
final DependencyHandler deps = this.project.getDependencies();
66+
private record Module(ModuleIdentifier id, String classifier) {}
67+
68+
public String buildRuntimeFileNames(final Configuration config) {
69+
final Configuration runtimeConfig = this.project.getConfigurations().getByName("runtimeClasspath");
70+
71+
final Map<Module, String> runtimeFileNames = new HashMap<>();
72+
for (final ResolvedArtifact artifact : runtimeConfig.getResolvedConfiguration().getResolvedArtifacts()) {
73+
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
74+
if (id instanceof ModuleComponentIdentifier moduleId) {
75+
runtimeFileNames.put(new Module(moduleId.getModuleIdentifier(), artifact.getClassifier()), artifact.getFile().getName());
76+
}
77+
}
78+
79+
final StringJoiner joiner = new StringJoiner(File.pathSeparator);
80+
81+
for (final ResolvedArtifact artifact : config.getResolvedConfiguration().getResolvedArtifacts()) {
82+
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
83+
84+
String fileName = null;
85+
if (id instanceof ModuleComponentIdentifier moduleId) {
86+
fileName = runtimeFileNames.get(new Module(moduleId.getModuleIdentifier(), artifact.getClassifier()));
87+
}
88+
89+
if (fileName == null) {
90+
fileName = artifact.getFile().getName();
91+
}
92+
93+
joiner.add(fileName);
94+
}
95+
96+
return joiner.toString();
97+
}
6598

99+
private String buildDependencyNotation(final ModuleComponentIdentifier moduleId, final String classifier) {
100+
final ModuleIdentifier module = moduleId.getModuleIdentifier();
101+
String notation = module.getGroup() + ":" + module.getName() + ":" + moduleId.getVersion();
102+
if (classifier != null) {
103+
notation += ":" + classifier;
104+
}
105+
return notation;
106+
}
107+
108+
public void copyModulesExcludingProvided(final Configuration source, final Configuration provided, final Configuration target) {
66109
final Map<ModuleIdentifier, String> providedModuleVersions = new HashMap<>();
67-
for (ResolvedArtifact artifact : provided.getResolvedConfiguration().getResolvedArtifacts()) {
110+
for (final ResolvedArtifact artifact : provided.getResolvedConfiguration().getResolvedArtifacts()) {
68111
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
69-
if (id instanceof ModuleComponentIdentifier) {
70-
final ModuleComponentIdentifier moduleId = (ModuleComponentIdentifier) id;
112+
if (id instanceof ModuleComponentIdentifier moduleId) {
71113
providedModuleVersions.put(moduleId.getModuleIdentifier(), moduleId.getVersion());
72114
}
73115
}
74116

117+
this.copyModulesExcludingPredicate(source, (moduleId) -> {
118+
final ModuleIdentifier module = moduleId.getModuleIdentifier();
119+
final String version = moduleId.getVersion();
120+
121+
final String providedVersion = providedModuleVersions.get(module);
122+
if (providedVersion == null) {
123+
return false;
124+
}
125+
126+
if (!providedVersion.equals(version)) {
127+
this.logger.warn("Version mismatch for module {}. {} expects {} but {} has {}.", module, source.getName(), version, provided.getName(), providedVersion);
128+
}
129+
return true;
130+
}, target);
131+
}
132+
133+
public void copyModulesExcludingPrefix(final Configuration source, final String group, final String namePrefix, final Configuration target) {
134+
this.copyModulesExcludingPredicate(source, (moduleId) -> {
135+
final ModuleIdentifier module = moduleId.getModuleIdentifier();
136+
return module.getGroup().equals(group) && module.getName().startsWith(namePrefix);
137+
}, target);
138+
}
139+
140+
public void copyModulesExcludingExact(final Configuration source, final String group, final String name, final Configuration target) {
141+
this.copyModulesExcludingPredicate(source, (moduleId) -> {
142+
final ModuleIdentifier module = moduleId.getModuleIdentifier();
143+
return module.getGroup().equals(group) && module.getName().equals(name);
144+
}, target);
145+
}
146+
147+
private void copyModulesExcludingPredicate(final Configuration source, final Predicate<ModuleComponentIdentifier> predicate, final Configuration target) {
148+
final DependencyHandler deps = this.project.getDependencies();
149+
75150
for (ResolvedArtifact artifact : source.getResolvedConfiguration().getResolvedArtifacts()) {
76151
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
77-
if (id instanceof ModuleComponentIdentifier) {
78-
final ModuleComponentIdentifier moduleId = (ModuleComponentIdentifier) id;
79-
final ModuleIdentifier module = moduleId.getModuleIdentifier();
80-
final String version = moduleId.getVersion();
81-
82-
final String providedVersion = providedModuleVersions.get(module);
83-
if (providedVersion == null) {
84-
ModuleDependency dep = (ModuleDependency) deps.create(module.getGroup() + ":" + module.getName() + ":" + version);
85-
dep.setTransitive(false);
86-
target.getDependencies().add(dep);
87-
} else if (!providedVersion.equals(version)) {
88-
this.logger.warn("Version mismatch for module {}. {} expects {} but {} has {}.", module, source.getName(), version, provided.getName(), providedVersion);
152+
if (id instanceof ModuleComponentIdentifier moduleId) {
153+
if (predicate.test(moduleId)) {
154+
continue;
89155
}
156+
157+
final ModuleDependency dep = (ModuleDependency) deps.create(this.buildDependencyNotation(moduleId, artifact.getClassifier()));
158+
dep.setTransitive(false);
159+
target.getDependencies().add(dep);
90160
}
91161

92162
// projects are not copied because we cannot always recreate properly a project dependency from the resolved artefact

0 commit comments

Comments
 (0)