forked from QuiltMC/quilt-mappings
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace DownloadTargetMetaFileTask with TargetVersionSource
- Loading branch information
1 parent
7ae0d89
commit a347ea9
Showing
4 changed files
with
91 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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
59 changes: 0 additions & 59 deletions
59
buildSrc/src/main/java/quilt/internal/task/diff/DownloadTargetMetaFileTask.java
This file was deleted.
Oops, something went wrong.
This file contains 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
58 changes: 58 additions & 0 deletions
58
buildSrc/src/main/java/quilt/internal/util/TargetVersionSource.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package quilt.internal.util; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParser; | ||
import org.gradle.api.GradleException; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.provider.ValueSource; | ||
import org.gradle.api.provider.ValueSourceParameters; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Comparator; | ||
import java.util.stream.StreamSupport; | ||
|
||
import static quilt.internal.util.DownloadUtil.openAvailableConnection; | ||
|
||
public abstract class TargetVersionSource implements ValueSource<String, TargetVersionSource.Params> { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(TargetVersionSource.class); | ||
|
||
@Override | ||
@Nullable | ||
public String obtain() { | ||
final String url = "https://meta.quiltmc.org/v3/versions/quilt-mappings/" + | ||
this.getParameters().getMinecraftVersion().get(); | ||
|
||
return openAvailableConnection(url) | ||
.flatMap(connection -> { | ||
final JsonElement meta; | ||
try (var in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { | ||
meta = JsonParser.parseReader(in); | ||
} catch (IOException e) { | ||
throw new GradleException("Failed to read meta file from url: " + url, e); | ||
} | ||
|
||
return StreamSupport.stream(meta.getAsJsonArray().spliterator(), false) | ||
.map(JsonElement::getAsJsonObject) | ||
.max(Comparator.comparing( | ||
object -> object.get("build").getAsInt(), | ||
Integer::compare | ||
)) | ||
.map(object -> object.get("version")) | ||
.map(JsonElement::getAsString); | ||
}) | ||
.orElseGet(() -> { | ||
LOGGER.warn(":target version meta unavailable"); | ||
|
||
return null; | ||
}); | ||
} | ||
|
||
public interface Params extends ValueSourceParameters { | ||
Property<String> getMinecraftVersion(); | ||
} | ||
} |
a347ea9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No difference between head and target.