Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<MissingLibraryArtifact> filterMissingLibraries(
- Iterator<? extends Library> librariesIterator,
- String nativesKey,
- boolean autoRetrieveHash,
- boolean autoRetrieveSize,
- int asyncPoolSize
- ) {
- List<MissingLibraryArtifact> missingLibraries = new ArrayList<>();
- List<Library> legacyLibraries = new ArrayList<>();
- while (librariesIterator.hasNext()) {
- Library library = librariesIterator.next();
- if (library.isLegacyLibrary()) {
- legacyLibraries.add(library);
- } else {
- String name = library.getName();
- checkMissingLibraryArtifact(missingLibraries::add, name, library.getArtifact());
- checkMissingLibraryArtifact(missingLibraries::add, name, library.getNativesFor(nativesKey));
- }
- }
- if (!legacyLibraries.isEmpty()) {
- ExecutorService asyncPool = Executors.newFixedThreadPool(asyncPoolSize);
- List<LegacyLibraryFutureData> futureData = new ArrayList<>();
- // retrieve hashes and sizes from the remote sources
- for (Library library : legacyLibraries) {
- String downloadUrl = library.constructDownloadUrl();
- Path libraryPath = getLibraryPath(library.constructPathFromCoordinates());
- Supplier<String> hashRetriever = null;
- LongSupplier sizeRetriever = null;
- if (library instanceof ForgeLibrary forgeLibrary && forgeLibrary.hasHashSHA1()) {
- hashRetriever = forgeLibrary::getHashSHA1;
- }
- if (autoRetrieveHash && hashRetriever == null && Files.isRegularFile(libraryPath)) {
- String hashsumUrl = downloadUrl + ".sha1";
- CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> retrieveHash(downloadUrl), asyncPool);
- hashRetriever = future::join;
- }
- if (autoRetrieveSize) {
- CompletableFuture<Long> future = CompletableFuture.supplyAsync(() -> retrieveSize(downloadUrl), asyncPool);
- sizeRetriever = future::join;
- }
- futureData.add(new LegacyLibraryFutureData(library, hashRetriever, sizeRetriever));
- }
- // check libraries for missing
- for (LegacyLibraryFutureData data : futureData) {
- Library library = data.library();
- String name = library.getName();
- String hash = data.hash();
- String downloadUrl = library.constructDownloadUrl();
- Path libraryPath = getLibraryPath(library.constructPathFromCoordinates());
- byte cause = isMissingLibrary(libraryPath, hash);
- if (cause != 0) {
- long size = data.size();
- missingLibraries.add(new MissingLibraryArtifact(name, downloadUrl, libraryPath, size, hash, cause));
- }
- }
- }
- return missingLibraries;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement