Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ protected final void writeSemverCache() {
}

/**
* Loads versions using given executor if they were not already loaded. Executor must be not <c>null</c>.
* @return A map containing all available versions, keyed by a unique name (see {@linkplain VersionInfo#id()}).
*/
@Override
Expand All @@ -101,12 +102,28 @@ public final Map<String, OrderedVersion> getVersions(Executor executor) throws I
return Collections.unmodifiableMap(this.versionsById);
}

/**
* When calling the versions must be already loaded. Crashes if not.
* @return A map containing all available versions, keyed by a unique name (see {@linkplain VersionInfo#id()}).
*/
@Override
public final Map<String, OrderedVersion> getVersionsAssumeLoaded() {
if (!this.versionsLoaded) {
MiscHelper.panic("getVersionsAssumeLoaded() called but the versions are not loaded");
}
return Collections.unmodifiableMap(this.versionsById);
}

public final void initializeAndLoadVersions(Executor executor) throws IOException {
synchronized (this) {
if (!this.versionsLoaded) {
if (executor == null) {
MiscHelper.panic("Cannot load versions because provided executor is null");
}
this.loadVersions(executor);
this.postLoadVersions();
this.writeSemverCache();
this.versionsLoaded = true;
}
}
}
Expand Down Expand Up @@ -163,7 +180,6 @@ protected void loadVersions(Executor executor) throws IOException {
}
});
}
this.versionsLoaded = true;
}

protected void postLoadVersions() {
Expand Down Expand Up @@ -281,12 +297,7 @@ protected final boolean isExistingVersionMetadataValid(String id, String url, St

@Override
public final OrderedVersion getVersionByVersionID(String versionId) {
try {
return this.getVersions(null).get(versionId);
} catch (Exception e) {
MiscHelper.panicBecause(e, "Could not fetch version information by id '%s'", versionId);
return null;
}
return this.getVersionsAssumeLoaded().get(versionId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ public interface MetadataProvider<E extends AbstractVersion<E>> {
String getInternalName();

/**
* Loads versions using given executor if they were not already loaded. Executor must be not <c>null</c>.
* @return A map containing all available versions, keyed by a unique name (see {@linkplain VersionInfo#id VersionInfo.id}).
*/
Map<String, E> getVersions(Executor executor) throws IOException;

/**
* When calling the versions must be already loaded. Crashes if not.
* @return A map containing all available versions, keyed by a unique name (see {@linkplain VersionInfo#id VersionInfo.id}).
*/
Map<String, E> getVersionsAssumeLoaded();

/**
* Finds parent nodes to the provided version. Used to construct the {@link com.github.winplay02.gitcraft.graph.AbstractVersionGraph}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,8 @@ private CompletableFuture<OrderedVersion> constructMostHistoricallyTruthfulVersi
@Override
protected void loadVersions(Executor executor) throws IOException {
this.versionsById.clear();
this.mojangLauncherMetadataProvider.initializeAndLoadVersions(executor);
this.skyrisingMetadataProvider.initializeAndLoadVersions(executor);
Set<String> mojangVersionIds = this.mojangLauncherMetadataProvider.getVersions(null).keySet();
Set<String> skyrisingVersionIds = this.skyrisingMetadataProvider.getVersions(null).keySet();
Set<String> mojangVersionIds = this.mojangLauncherMetadataProvider.getVersions(executor).keySet();
Set<String> skyrisingVersionIds = this.skyrisingMetadataProvider.getVersions(executor).keySet();
Set<String> transformedSkyrisingVersionIds = MiscHelper.concatStreams(
skyrisingVersionIds.stream().filter(SKYRISING_MOJANG_VERSION_ID_MAPPING::containsKey).map(SKYRISING_MOJANG_VERSION_ID_MAPPING::get),
skyrisingVersionIds.stream().filter(Predicate.not(SKYRISING_MOJANG_VERSION_ID_MAPPING::containsKey))
Expand Down Expand Up @@ -232,7 +230,6 @@ protected void loadVersions(Executor executor) throws IOException {
for (Map.Entry<String, CompletableFuture<OrderedVersion>> futureEntry : futureVersionsMap.entrySet()) {
this.versionsById.put(futureEntry.getKey(), futureEntry.getValue().join());
}
this.versionsLoaded = true;
}

@Override
Expand Down
86 changes: 74 additions & 12 deletions src/test/groovy/com/github/winplay02/gitcraft/GitCraftTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.winplay02.gitcraft;

import com.github.winplay02.gitcraft.config.ApplicationConfiguration;
import com.github.winplay02.gitcraft.config.Configuration;
import com.github.winplay02.gitcraft.exceptions.ExceptionsFlavour;
import com.github.winplay02.gitcraft.manifest.ManifestSource;
import com.github.winplay02.gitcraft.manifest.skyrising.SkyrisingMetadataProvider;
import com.github.winplay02.gitcraft.manifest.vanilla.MojangLauncherMetadataProvider;
import com.github.winplay02.gitcraft.mappings.MappingFlavour;
Expand Down Expand Up @@ -122,12 +124,32 @@ public void mappingsMojang() throws IOException, URISyntaxException, Interrupted

@Test
public void mappingsParchment() throws IOException, URISyntaxException, InterruptedException {
MojangLauncherMetadataProvider metadataBootstrap = new MojangLauncherMetadataProvider();
Files.copy(LibraryPaths.lookupCurrentWorkingDirectory().resolve(String.format("semver-cache-%s.json", metadataBootstrap.getInternalName())), LibraryPaths.CURRENT_WORKING_DIRECTORY.resolve(String.format("semver-cache-%s.json", metadataBootstrap.getInternalName())), StandardCopyOption.REPLACE_EXISTING);
metadataBootstrap = new MojangLauncherMetadataProvider();
MojangLauncherMetadataProvider metadataBootstrap1 = new MojangLauncherMetadataProvider();
Files.copy(LibraryPaths.lookupCurrentWorkingDirectory().resolve(String.format("semver-cache-%s.json", metadataBootstrap1.getInternalName())), LibraryPaths.CURRENT_WORKING_DIRECTORY.resolve(String.format("semver-cache-%s.json", metadataBootstrap1.getInternalName())), StandardCopyOption.REPLACE_EXISTING);
Configuration.editConfiguration(ApplicationConfiguration.class, (original) -> new ApplicationConfiguration(
ManifestSource.MOJANG,
original.usedMapping(),
original.fallbackMappings(),
original.usedUnpickFlavour(),
original.fallbackUnpickFlavours(),
original.singleSideVersionsOnMainBranch(),
original.onlyStableReleases(),
original.onlySnapshots(),
original.skipNonLinear(),
original.onlyVersion(),
original.minVersion(),
original.maxVersion(),
original.excludedVersion(),
original.ornitheIntermediaryGeneration(),
original.patchLvt(),
original.usedExceptions(),
original.usedSignatures(),
original.usedNests(),
original.enablePreening()
));
MinecraftVersionGraph versionGraph;
try (ExecutorService executor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().name("Testing-Executor").factory())) {
versionGraph = MinecraftVersionGraph.createFromMetadata(executor, metadataBootstrap);
versionGraph = MinecraftVersionGraph.createFromMetadata(executor, GitCraftApplication.getApplicationConfiguration().manifestSource().getMetadataProvider());
//
Path mappingsPath = MappingFlavour.MOJMAP_PARCHMENT.getPath(versionGraph.getMinecraftVersionByName("1.20.1"), MinecraftJar.MERGED).orElse(null);
assertNotNull(mappingsPath);
Expand All @@ -148,12 +170,32 @@ public void mappingsParchment() throws IOException, URISyntaxException, Interrup

@Test
public void mappingsFabricIntermediary() throws IOException, URISyntaxException, InterruptedException {
MojangLauncherMetadataProvider metadataBootstrap = new MojangLauncherMetadataProvider();
Files.copy(LibraryPaths.lookupCurrentWorkingDirectory().resolve(String.format("semver-cache-%s.json", metadataBootstrap.getInternalName())), LibraryPaths.CURRENT_WORKING_DIRECTORY.resolve(String.format("semver-cache-%s.json", metadataBootstrap.getInternalName())), StandardCopyOption.REPLACE_EXISTING);
metadataBootstrap = new MojangLauncherMetadataProvider();
MojangLauncherMetadataProvider metadataBootstrap1 = new MojangLauncherMetadataProvider();
Files.copy(LibraryPaths.lookupCurrentWorkingDirectory().resolve(String.format("semver-cache-%s.json", metadataBootstrap1.getInternalName())), LibraryPaths.CURRENT_WORKING_DIRECTORY.resolve(String.format("semver-cache-%s.json", metadataBootstrap1.getInternalName())), StandardCopyOption.REPLACE_EXISTING);
Configuration.editConfiguration(ApplicationConfiguration.class, (original) -> new ApplicationConfiguration(
ManifestSource.MOJANG,
original.usedMapping(),
original.fallbackMappings(),
original.usedUnpickFlavour(),
original.fallbackUnpickFlavours(),
original.singleSideVersionsOnMainBranch(),
original.onlyStableReleases(),
original.onlySnapshots(),
original.skipNonLinear(),
original.onlyVersion(),
original.minVersion(),
original.maxVersion(),
original.excludedVersion(),
original.ornitheIntermediaryGeneration(),
original.patchLvt(),
original.usedExceptions(),
original.usedSignatures(),
original.usedNests(),
original.enablePreening()
));
MinecraftVersionGraph versionGraph;
try (ExecutorService executor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().name("Testing-Executor").factory())) {
versionGraph = MinecraftVersionGraph.createFromMetadata(executor, metadataBootstrap);
versionGraph = MinecraftVersionGraph.createFromMetadata(executor, GitCraftApplication.getApplicationConfiguration().manifestSource().getMetadataProvider());
//
Path mappingsPath = MappingFlavour.FABRIC_INTERMEDIARY.getPath(versionGraph.getMinecraftVersionByName("1.20"), MinecraftJar.MERGED).orElse(null);
assertNotNull(mappingsPath);
Expand All @@ -174,12 +216,32 @@ public void mappingsFabricIntermediary() throws IOException, URISyntaxException,

@Test
public void mappingsYarn() throws IOException, URISyntaxException, InterruptedException {
MojangLauncherMetadataProvider metadataBootstrap = new MojangLauncherMetadataProvider();
Files.copy(LibraryPaths.lookupCurrentWorkingDirectory().resolve(String.format("semver-cache-%s.json", metadataBootstrap.getInternalName())), LibraryPaths.CURRENT_WORKING_DIRECTORY.resolve(String.format("semver-cache-%s.json", metadataBootstrap.getInternalName())), StandardCopyOption.REPLACE_EXISTING);
metadataBootstrap = new MojangLauncherMetadataProvider();
MojangLauncherMetadataProvider metadataBootstrap1 = new MojangLauncherMetadataProvider();
Files.copy(LibraryPaths.lookupCurrentWorkingDirectory().resolve(String.format("semver-cache-%s.json", metadataBootstrap1.getInternalName())), LibraryPaths.CURRENT_WORKING_DIRECTORY.resolve(String.format("semver-cache-%s.json", metadataBootstrap1.getInternalName())), StandardCopyOption.REPLACE_EXISTING);
Configuration.editConfiguration(ApplicationConfiguration.class, (original) -> new ApplicationConfiguration(
ManifestSource.MOJANG,
original.usedMapping(),
original.fallbackMappings(),
original.usedUnpickFlavour(),
original.fallbackUnpickFlavours(),
original.singleSideVersionsOnMainBranch(),
original.onlyStableReleases(),
original.onlySnapshots(),
original.skipNonLinear(),
original.onlyVersion(),
original.minVersion(),
original.maxVersion(),
original.excludedVersion(),
original.ornitheIntermediaryGeneration(),
original.patchLvt(),
original.usedExceptions(),
original.usedSignatures(),
original.usedNests(),
original.enablePreening()
));
MinecraftVersionGraph versionGraph;
try (ExecutorService executor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().name("Testing-Executor").factory())) {
versionGraph = MinecraftVersionGraph.createFromMetadata(executor, metadataBootstrap);
versionGraph = MinecraftVersionGraph.createFromMetadata(executor, GitCraftApplication.getApplicationConfiguration().manifestSource().getMetadataProvider());
//
Path mappingsPath = MappingFlavour.YARN.getPath(versionGraph.getMinecraftVersionByName("1.20"), MinecraftJar.MERGED).orElse(null);
assertNotNull(mappingsPath);
Expand Down