use of net.glowstone.util.library.Library 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 net.glowstone.util.library.Library in project Glowstone by GlowstoneMC.
the class GlowServer method start.
/**
* Starts this server.
*/
public void start() {
// Determine console mode and start reading input
consoleManager.startConsole(config.getBoolean(Key.USE_JLINE));
consoleManager.startFile(config.getString(Key.LOG_FILE));
if (getProxySupport()) {
if (getOnlineMode()) {
ConsoleMessages.Info.Proxy.ONLINE.log();
} else {
ConsoleMessages.Info.PROXY.log();
}
} else if (!getOnlineMode()) {
ConsoleMessages.Warn.OFFLINE.log();
}
int openClMajor = 1;
int openClMinor = 2;
if (doesUseGraphicsCompute()) {
int maxGpuFlops = 0;
int maxIntelFlops = 0;
int maxCpuFlops = 0;
CLPlatform bestPlatform = null;
CLPlatform bestIntelPlatform = null;
CLPlatform bestCpuPlatform = null;
// gets the max flops device across platforms on the computer
for (CLPlatform platform : CLPlatform.listCLPlatforms()) {
if (platform.isAtLeast(openClMajor, openClMinor) && platform.isExtensionAvailable("cl_khr_fp64")) {
// NON-NLS
for (CLDevice device : platform.listCLDevices()) {
if (device.getType() == CLDevice.Type.GPU) {
int flops = device.getMaxComputeUnits() * device.getMaxClockFrequency();
ConsoleMessages.Info.Opencl.FOUND_DEVICE.log(device, flops);
if (device.getVendor().contains("Intel")) {
// NON-NLS
if (flops > maxIntelFlops) {
maxIntelFlops = flops;
ConsoleMessages.Info.Opencl.BEST.log(platform);
bestIntelPlatform = platform;
} else if (flops == maxIntelFlops) {
if (bestIntelPlatform != null && bestIntelPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
maxIntelFlops = flops;
ConsoleMessages.Info.Opencl.BEST_VERSION_TIEBREAKER.log(platform);
bestIntelPlatform = platform;
}
}
} else {
if (flops > maxGpuFlops) {
maxGpuFlops = flops;
ConsoleMessages.Info.Opencl.BEST.log(platform);
bestPlatform = platform;
} else if (flops == maxGpuFlops) {
if (bestPlatform != null && bestPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
maxGpuFlops = flops;
ConsoleMessages.Info.Opencl.BEST_VERSION_TIEBREAKER.log(platform);
bestPlatform = platform;
}
}
}
} else {
int flops = device.getMaxComputeUnits() * device.getMaxClockFrequency();
ConsoleMessages.Info.Opencl.FOUND_DEVICE.log(device, flops);
if (flops > maxCpuFlops) {
maxCpuFlops = flops;
ConsoleMessages.Info.Opencl.BEST.log(platform);
bestCpuPlatform = platform;
} else if (flops == maxCpuFlops) {
if (bestCpuPlatform != null && bestCpuPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
maxCpuFlops = flops;
ConsoleMessages.Info.Opencl.BEST_VERSION_TIEBREAKER.log(platform);
bestCpuPlatform = platform;
}
}
}
}
}
}
if (config.getBoolean(Key.GRAPHICS_COMPUTE_ANY_DEVICE)) {
if (maxGpuFlops - maxIntelFlops < 0 && maxCpuFlops - maxIntelFlops <= 0) {
bestPlatform = bestIntelPlatform;
} else if (maxGpuFlops - maxCpuFlops < 0 && maxIntelFlops - maxCpuFlops < 0) {
bestPlatform = bestCpuPlatform;
}
} else {
if (maxGpuFlops == 0) {
if (maxIntelFlops == 0) {
ConsoleMessages.Info.Opencl.CPU.log();
bestPlatform = bestCpuPlatform;
} else {
ConsoleMessages.Info.Opencl.INTEL_GPU.log();
bestPlatform = bestIntelPlatform;
}
}
}
if (bestPlatform == null) {
isGraphicsComputeAvailable = false;
ConsoleMessages.Info.Opencl.NO_DEVICE.log();
ConsoleMessages.Info.Opencl.REQUIRED_VERSION.log(openClMajor, openClMinor);
ConsoleMessages.Info.Opencl.REQUIRED_EXTENSIONS.log();
} else {
OpenCompute.initContext(bestPlatform);
}
}
// Load player lists
opsList.load();
whitelist.load();
nameBans.load();
ipBans.load();
setPort(config.getInt(Key.SERVER_PORT));
setIp(config.getString(Key.SERVER_IP));
try {
LootingManager.load();
} catch (Exception e) {
ConsoleMessages.Error.LOOTING_MANAGER.log();
e.printStackTrace();
}
// Start loading plugins
String repository = config.getString(Key.LIBRARY_REPOSITORY_URL);
String libraryFolder = config.getString(Key.LIBRARIES_FOLDER);
Set<Library> libraries = aggregateLibraries(repository, libraryFolder);
new LibraryManager(repository, libraryFolder, config.getBoolean(Key.LIBRARY_CHECKSUM_VALIDATION), config.getInt(Key.LIBRARY_DOWNLOAD_ATTEMPTS), libraries).run();
loadPlugins();
enablePlugins(PluginLoadOrder.STARTUP);
// Create worlds
String seedString = config.getString(Key.LEVEL_SEED);
WorldType type = WorldType.getByName(getWorldType());
if (type == null) {
type = WorldType.NORMAL;
}
long seed = new Random().nextLong();
if (!seedString.isEmpty()) {
try {
long parsed = Long.parseLong(seedString);
if (parsed != 0) {
seed = parsed;
}
} catch (NumberFormatException ex) {
seed = seedString.hashCode();
}
}
if (storageProviderFactory == null) {
storageProviderFactory = (worldName) -> new AnvilWorldStorageProvider(new File(getWorldContainer(), worldName));
}
String name = config.getString(Key.LEVEL_NAME);
boolean structs = getGenerateStructures();
createWorld(WorldCreator.name(name).environment(Environment.NORMAL).seed(seed).type(type).generateStructures(structs));
if (getAllowNether()) {
checkTransfer(name, "_nether", Environment.NETHER);
createWorld(// NON-NLS
WorldCreator.name(name + "_nether").environment(Environment.NETHER).seed(seed).type(type).generateStructures(structs));
}
if (getAllowEnd()) {
checkTransfer(name, "_the_end", Environment.THE_END);
createWorld(// NON-NLS
WorldCreator.name(name + "_the_end").environment(Environment.THE_END).seed(seed).type(type).generateStructures(structs));
}
// Finish loading plugins
enablePlugins(PluginLoadOrder.POSTWORLD);
commandMap.registerServerAliases();
scheduler.start();
}
Aggregations