use of com.tobedevoured.naether.api.Naether in project Glowstone by GlowstoneMC.
the class GlowServer method aggregateLibraries.
private Set<Library> aggregateLibraries(String repository, String libraryFolder) {
String bundleString = config.getString(Key.COMPATIBILITY_BUNDLE);
CompatibilityBundle bundle = CompatibilityBundle.fromConfig(bundleString);
if (bundle == null) {
logger.log(Level.SEVERE, "Unrecognized compatibility bundle: \"" + bundleString + "\"");
System.exit(1);
}
Map<LibraryKey, Library> bundleLibs = bundle.libraries;
ListMultimap<LibraryKey, Library> configLibs = config.getMapList(Key.LIBRARIES_LIST).stream().map(Library::fromConfigMap).filter(library -> {
if (bundleLibs.containsKey(library.getLibraryKey())) {
logger.log(Level.WARNING, String.format("Library '%s' is already defined as part of bundle '%s'. This entry within" + " the 'libraries' config section will be ignored.", library.getLibraryKey().toString(), bundleString));
return false;
}
return true;
}).collect(Multimaps.toMultimap(Library::getLibraryKey, Function.identity(), MultimapBuilder.hashKeys().arrayListValues()::build));
Set<String> conflicts = new HashSet<>();
Set<String> duplicateLibs = new HashSet<>();
Map<String, Naether> clients = new HashMap<>();
clients.put(null, createNaetherWithRepository(repository, libraryFolder));
for (Map.Entry<LibraryKey, List<Library>> entry : Multimaps.asMap(configLibs).entrySet()) {
if (entry.getValue().size() > 1) {
duplicateLibs.add(entry.getKey().toString());
} else {
Library library = entry.getValue().get(0);
if (serverContainsLibrary(library)) {
conflicts.add(entry.getKey().toString());
} else if (!library.isExcludeDependencies()) {
Naether naether = clients.computeIfAbsent(library.getRepository(), k -> createNaetherWithRepository(k, libraryFolder));
if (naether != null) {
naether.addDependency(String.format(// NON-NLS
"%s:%s:jar:%s", library.getGroupId(), library.getArtifactId(), library.getVersion()));
}
}
}
}
if (!conflicts.isEmpty() || !duplicateLibs.isEmpty()) {
if (!conflicts.isEmpty()) {
String joinedConflicts = conflicts.stream().collect(Collectors.joining("', '", "['", "']"));
logger.log(Level.SEVERE, String.format("Libraries %s conflict with libraries built into this JAR file. Please fix" + " this issue and restart the server.", joinedConflicts));
}
if (!duplicateLibs.isEmpty()) {
String joinedDuplicates = duplicateLibs.stream().collect(Collectors.joining("', '", "['", "']"));
logger.log(Level.SEVERE, String.format("Libraries %s are defined multiple times in the 'libraries' config section.", joinedDuplicates));
}
System.exit(1);
}
Map<LibraryKey, Library> dependencyLibs = clients.entrySet().stream().filter(Objects::nonNull).flatMap(entry -> {
try {
entry.getValue().resolveDependencies(false);
return entry.getValue().getDependenciesNotation().stream().map(dependency -> {
// same format as above, {groupId}:{artifactId}:jar:{version}
String[] expanded = dependency.split(":");
// TODO: populate the checksum fields if possible
return new Library(expanded[0], expanded[1], expanded[3], entry.getKey());
});
} catch (NaetherException e) {
logger.log(Level.WARNING, "Unable to resolve library dependencies. Falling" + " back to explicitly defined dependencies only.", e);
return Stream.empty();
}
}).filter(library -> !configLibs.containsKey(library.getLibraryKey()) && !serverContainsLibrary(library) && !blacklistedRuntimeLibs.contains(library.getLibraryKey())).collect(Collectors.toMap(Library::getLibraryKey, Function.identity(), (library1, library2) -> library1.compareTo(library2) > 0 ? library1 : library2));
Set<Library> libraries = new HashSet<>(bundleLibs.size() + configLibs.size() + dependencyLibs.size());
libraries.addAll(bundleLibs.values());
libraries.addAll(configLibs.values());
libraries.addAll(dependencyLibs.values());
return libraries;
}
use of com.tobedevoured.naether.api.Naether in project Glowstone by GlowstoneMC.
the class GlowServer method createNaetherWithRepository.
private Naether createNaetherWithRepository(String repository, String libraryFolder) {
Naether naether = new NaetherImpl();
naether.setLocalRepoPath(new File(libraryFolder).getAbsolutePath());
try {
// Must overwrite the collection here in order to remove Maven Central from it.
naether.setRemoteRepositories(Sets.newHashSet(RepoBuilder.remoteRepositoryFromUrl(repository)));
} catch (MalformedURLException e) {
logger.log(Level.WARNING, "Unable to resolve library dependencies. Falling back to " + "explicitly defined dependencies only.", e);
return null;
}
return naether;
}
Aggregations