Skip to content

Commit 171cca6

Browse files
committed
Allow MavenTask to output a repo with only pom/module
Experimental. MCPConfig only for now.
1 parent 7b1880b commit 171cca6

File tree

6 files changed

+68
-60
lines changed

6 files changed

+68
-60
lines changed

src/main/java/net/minecraftforge/mcmaven/cli/MCPDataTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ else if (options.has(parchmentO))
124124
return -3;
125125
}
126126

127-
var repo = new MCPConfigRepo(new Cache(cacheRoot, jdkCacheRoot));
127+
var repo = new MCPConfigRepo(new Cache(cacheRoot, jdkCacheRoot), false);
128128
LOGGER.info(" Output: " + output.getAbsolutePath());
129129
LOGGER.info(" Cache: " + cacheRoot.getAbsolutePath());
130130
LOGGER.info(" JDK Cache: " + jdkCacheRoot.getAbsolutePath());

src/main/java/net/minecraftforge/mcmaven/cli/MCPTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static void run(String[] args) throws Exception {
129129
return;
130130
}
131131

132-
var repo = new MCPConfigRepo(new Cache(cacheRoot, jdkCacheRoot));
132+
var repo = new MCPConfigRepo(new Cache(cacheRoot, jdkCacheRoot), false);
133133
LOGGER.info(" Output: " + output.getAbsolutePath());
134134
LOGGER.info(" Cache: " + cacheRoot.getAbsolutePath());
135135
LOGGER.info(" JDK Cache: " + jdkCacheRoot.getAbsolutePath());

src/main/java/net/minecraftforge/mcmaven/cli/MavenTask.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ static void run(String[] args) throws Exception {
5959
"Root directory to generate the maven repository")
6060
.withRequiredArg().ofType(File.class).defaultsTo(new File("output"));
6161

62+
// dependencies only
63+
var dependenciesOnlyO = parser.accepts("dependencies-only",
64+
"Outputs the maven containing only the Gradle Module and POM for the artifact's dependencies without outputting the artifact itself");
65+
6266
// offline mode, fail on downloads
6367
var offlineO = parser.accepts("offline",
6468
"Do not attempt to download anything (allows offline operations, if possible)")
@@ -154,7 +158,7 @@ static void run(String[] args) throws Exception {
154158
foreignRepositories.put(split[0], split[1]);
155159
}
156160

157-
var mcmaven = new MinecraftMaven(output, cache, jdkCache, mappings, foreignRepositories, options.has(globalAuxiliaryVariantsO));
161+
var mcmaven = new MinecraftMaven(output, options.has(dependenciesOnlyO), cache, jdkCache, mappings, foreignRepositories, options.has(globalAuxiliaryVariantsO));
158162
mcmaven.run(artifact);
159163
}
160164
}

src/main/java/net/minecraftforge/mcmaven/impl/MinecraftMaven.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,23 @@
2929
// TODO [MCMavenizer][Deobf] ADD DEOBF
3030
// use single detached configuration to resolve individual configurations
3131
// pass in downloaded files to mcmaven (absolute path)
32-
public record MinecraftMaven(File output, Cache cache, Mappings mappings, Map<String, String> foreignRepositories, boolean globalAuxiliaryVariants) {
32+
public record MinecraftMaven(
33+
File output,
34+
boolean dependenciesOnly,
35+
Cache cache,
36+
Mappings mappings,
37+
Map<String, String> foreignRepositories,
38+
boolean globalAuxiliaryVariants
39+
) {
3340
private static final ComparableVersion MIN_SUPPORTED_FORGE = new ComparableVersion("1.14.4"); // Only 1.14.4+ has official mappings, we can support more when we add more mappings
3441

35-
public MinecraftMaven(File output, File cacheRoot, File jdkCacheRoot, Mappings mappings, Map<String, String> foreignRepositories, boolean globalAuxiliaryVariants) {
36-
this(output, new Cache(cacheRoot, jdkCacheRoot, foreignRepositories), mappings, foreignRepositories, globalAuxiliaryVariants);
42+
public MinecraftMaven(File output, boolean dependenciesOnly, File cacheRoot, File jdkCacheRoot, Mappings mappings, Map<String, String> foreignRepositories, boolean globalAuxiliaryVariants) {
43+
this(output, dependenciesOnly, new Cache(cacheRoot, jdkCacheRoot, foreignRepositories), mappings, foreignRepositories, globalAuxiliaryVariants);
3744
}
3845

3946
public MinecraftMaven {
4047
LOGGER.info(" Output: " + output.getAbsolutePath());
48+
LOGGER.info(" Dependencies Only: " + dependenciesOnly);
4149
LOGGER.info(" Cache: " + cache.root().getAbsolutePath());
4250
LOGGER.info(" JDK Cache: " + cache.jdks().root().getAbsolutePath());
4351
LOGGER.info(" Offline: " + Mavenizer.isOffline());
@@ -53,9 +61,12 @@ public void run(Artifact artifact) {
5361
var module = artifact.getGroup() + ':' + artifact.getName();
5462
var version = artifact.getVersion();
5563
LOGGER.info("Processing Minecraft dependency: %s:%s".formatted(module, version));
56-
var mcprepo = new MCPConfigRepo(this.cache);
64+
var mcprepo = new MCPConfigRepo(this.cache, dependenciesOnly);
5765

5866
if (Constants.FORGE_GROUP.equals(artifact.getGroup()) && Constants.FORGE_NAME.equals(artifact.getName())) {
67+
if (dependenciesOnly)
68+
throw new IllegalArgumentException("ForgeRepo doesn't currently support dependenciesOnly");
69+
5970
var repo = new ForgeRepo(this.cache, mcprepo);
6071
if (artifact.getVersion() == null)
6172
throw new IllegalArgumentException("No version specified for Forge");
@@ -125,9 +136,9 @@ private void finalize(Artifact module, Mappings mappings, List<Repo.PendingArtif
125136
// Basically, I want to support multiple variants of a Forge dep.
126137
// Simplest case would be different mapping channels.
127138
// I haven't added an opt-in for making artifacts that use mappings, so just assume any artifact with variants
128-
var artifact = pending.getArtifact();
139+
var artifact = pending.artifact();
129140
String suffix = null;
130-
if (pending.getVariants() != null && !mappings.isPrimary()) {
141+
if (pending.variants() != null && !mappings.isPrimary()) {
131142
suffix = mappings.channel() + '-' + mappings.version();
132143
if (artifact.getClassifier() == null)
133144
artifact = artifact.withClassifier(suffix);
@@ -143,7 +154,7 @@ private void finalize(Artifact module, Mappings mappings, List<Repo.PendingArtif
143154
.add("source", source);
144155

145156
boolean write;
146-
if ("pom".equals(pending.getArtifact().getExtension())) {
157+
if ("pom".equals(pending.artifact().getExtension())) {
147158
// Write the pom for non-primary mappings if we haven't generated primary mappings yet
148159
write = !target.exists() || (mappings.isPrimary() && !cache.isSame());
149160
} else {
@@ -162,20 +173,22 @@ private void finalize(Artifact module, Mappings mappings, List<Repo.PendingArtif
162173
}
163174
}
164175

165-
if (pending.getVariants() != null) {
166-
var source = pending.getVariants().execute();
176+
if (pending.variants() != null) {
177+
var source = pending.variants().execute();
167178
var cache = HashStore.fromFile(varTarget)
168179
.add("source", source);
169180

170181
if (!varTarget.exists() || !cache.isSame()) {
171182
variants.add(Artifact.from(artifact.getGroup(), artifact.getName(), artifact.getVersion()));
172183
try {
173184
var data = JsonData.fromJson(source, GradleModule.Variant[].class);
174-
var file = new GradleModule.Variant.File(target);
175-
for (var variant : data) {
176-
variant.file(file);
177-
if (suffix != null && !(pending.isAuxiliary() && this.globalAuxiliaryVariants))
178-
variant.name = variant.name + '-' + suffix;
185+
if (!dependenciesOnly) {
186+
var file = new GradleModule.Variant.File(target);
187+
for (var variant : data) {
188+
variant.file(file);
189+
if (suffix != null && !(pending.auxiliary() && this.globalAuxiliaryVariants))
190+
variant.name = variant.name + '-' + suffix;
191+
}
179192
}
180193
JsonData.toJson(data, varTarget);
181194
cache.save();

src/main/java/net/minecraftforge/mcmaven/impl/repo/Repo.java

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import net.minecraftforge.util.data.json.JsonData;
1818
import net.minecraftforge.util.file.FileUtils;
1919
import net.minecraftforge.util.hash.HashStore;
20+
2021
import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER;
2122

2223
import java.io.File;
@@ -27,12 +28,9 @@
2728
import java.util.Collection;
2829
import java.util.EnumSet;
2930
import java.util.HashMap;
30-
import java.util.HashSet;
3131
import java.util.List;
32-
import java.util.Objects;
3332
import java.util.function.Consumer;
3433
import java.util.function.Supplier;
35-
import java.util.stream.Collectors;
3634

3735
import org.jetbrains.annotations.Nullable;
3836

@@ -53,7 +51,7 @@ public final Cache getCache() {
5351
public abstract List<PendingArtifact> process(Artifact artifact, Mappings mappings);
5452

5553
protected static PendingArtifact pending(String message, Task task, Artifact artifact, boolean auxiliary) {
56-
return pending(message, task, artifact, auxiliary, (Task)null);
54+
return pending(message, task, artifact, auxiliary, (Task) null);
5755
}
5856

5957
protected static PendingArtifact pending(String message, Task task, Artifact artifact, boolean auxiliary, Supplier<GradleModule.Variant[]> variants) {
@@ -68,12 +66,12 @@ protected static PendingArtifact pending(String message, Task task, Artifact art
6866
protected Supplier<GradleModule.Variant[]> sourceVariant(Mappings mappings) {
6967
return () -> new GradleModule.Variant[] {
7068
GradleModule.Variant.of("sources")
71-
.attribute("org.gradle.usage", "java-runtime")
72-
.attribute("org.gradle.category", "documentation")
73-
.attribute("org.gradle.dependency.bundling", "external")
74-
.attribute("org.gradle.docstype", "sources")
75-
.attribute("org.gradle.libraryelements", "jar")
76-
.attribute(Mappings.CHANNEL_ATTR, mappings.channel())
69+
.attribute("org.gradle.usage", "java-runtime")
70+
.attribute("org.gradle.category", "documentation")
71+
.attribute("org.gradle.dependency.bundling", "external")
72+
.attribute("org.gradle.docstype", "sources")
73+
.attribute("org.gradle.libraryelements", "jar")
74+
.attribute(Mappings.CHANNEL_ATTR, mappings.channel())
7775
.attribute(Mappings.VERSION_ATTR, mappings.version())
7876
};
7977
}
@@ -151,12 +149,12 @@ protected GradleModule.Variant[] classVariants(Mappings mappings, MCPSide side,
151149

152150
Consumer<GradleModule.Variant> common = v -> {
153151
v.attribute("org.gradle.usage", "java-runtime")
154-
.attribute("org.gradle.category", "library")
155-
.attribute("org.gradle.dependency.bundling", "external")
156-
.attribute("org.gradle.libraryelements", "jar")
157-
.attribute("org.gradle.jvm.environment", "standard-jvm")
158-
.attribute(Mappings.CHANNEL_ATTR, mappings.channel())
159-
.attribute(Mappings.VERSION_ATTR, mappings.version())
152+
.attribute("org.gradle.category", "library")
153+
.attribute("org.gradle.dependency.bundling", "external")
154+
.attribute("org.gradle.libraryelements", "jar")
155+
.attribute("org.gradle.jvm.environment", "standard-jvm")
156+
.attribute(Mappings.CHANNEL_ATTR, mappings.channel())
157+
.attribute(Mappings.VERSION_ATTR, mappings.version())
160158
;
161159

162160
if (java != null)
@@ -208,20 +206,13 @@ protected static Task simplePom(File build, Artifact artifact) {
208206
});
209207
}
210208

211-
public static final class PendingArtifact implements Supplier<File> {
212-
private final String message;
213-
private final Task task;
214-
private final Artifact artifact;
215-
private final boolean auxiliary;
216-
private final @Nullable Task variants;
217-
218-
private PendingArtifact(String message, Task task, Artifact artifact, boolean auxiliary, @Nullable Task variants) {
219-
this.message = message;
220-
this.task = task;
221-
this.artifact = artifact;
222-
this.auxiliary = auxiliary;
223-
this.variants = variants;
224-
}
209+
public record PendingArtifact(
210+
String message,
211+
Task task,
212+
Artifact artifact,
213+
boolean auxiliary,
214+
@Nullable Task variants
215+
) implements Supplier<File> {
225216

226217
@Override
227218
public File get() {
@@ -244,16 +235,8 @@ public Task getAsTask() {
244235
return task;
245236
}
246237

247-
public Artifact getArtifact() {
248-
return artifact;
249-
}
250-
251-
public boolean isAuxiliary() {
252-
return auxiliary;
253-
}
254-
255-
public @Nullable Task getVariants() {
256-
return variants;
238+
public PendingArtifact withVariants(Supplier<GradleModule.Variant[]> variants) {
239+
return new PendingArtifact(message, task, artifact, auxiliary, variantTask(task, variants));
257240
}
258241
}
259242
}

src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPConfigRepo.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@
6363
public final class MCPConfigRepo extends Repo {
6464
private final Map<Artifact, MCP> versions = new HashMap<>();
6565
private final Map<String, MinecraftTasks> mcTasks = new HashMap<>();
66+
private final boolean dependenciesOnly;
6667

67-
public MCPConfigRepo(Cache cache) {
68+
public MCPConfigRepo(Cache cache, boolean dependenciesOnly) {
69+
this.dependenciesOnly = dependenciesOnly;
6870
super(cache);
6971
}
7072

@@ -103,12 +105,20 @@ public List<PendingArtifact> process(Artifact artifact, Mappings mappings) {
103105
var build = mcpSide.getBuildFolder();
104106
var name = Artifact.from("net.minecraft", side, version);
105107

108+
var pom = pending("Maven POM", pom(build, side, mcpSide, version), name.withExtension("pom"), false);
109+
var metadata = pending("Metadata", metadata(build, mcpSide), name.withClassifier("metadata").withExtension("zip"), false, metadataVariant());
110+
106111
if (isMappings) {
107112
name = mappings.getArtifact(mcpSide);
108113
return List.of(
109114
pending("Mappings", mappings.getCsvZip(mcpSide), name, false),
110115
pending("Mappings POM", simplePom(build, name), name.withExtension("pom"), false)
111116
);
117+
} else if (dependenciesOnly) {
118+
return List.of(
119+
pom.withVariants(() -> classVariants(mappings, mcpSide)),
120+
metadata
121+
);
112122
}
113123

114124
return switch (mappings.channel()) {
@@ -123,8 +133,6 @@ public List<PendingArtifact> process(Artifact artifact, Mappings mappings) {
123133

124134
var sources = pending("Sources", sourcesTask, name.withClassifier("sources"), true, sourceVariant(mappings));
125135
var classes = pending("Classes", classesTask, name, false, () -> classVariants(mappings, mcpSide));
126-
var metadata = pending("Metadata", metadata(build, mcpSide), name.withClassifier("metadata").withExtension("zip"), false, metadataVariant());
127-
var pom = pending("Maven POM", pom(build, side, mcpSide, version), name.withExtension("pom"), false);
128136

129137
pending.addAll(List.of(
130138
sources, classes, metadata, pom

0 commit comments

Comments
 (0)