diff --git a/engine-tests/src/test/java/org/terasology/documentation/ApiScraper.java b/engine-tests/src/test/java/org/terasology/documentation/ApiScraper.java index 29b5ebe9fcb..85bd2e74f43 100644 --- a/engine-tests/src/test/java/org/terasology/documentation/ApiScraper.java +++ b/engine-tests/src/test/java/org/terasology/documentation/ApiScraper.java @@ -4,6 +4,8 @@ import com.google.common.collect.Multimaps; import com.google.common.collect.SortedSetMultimap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.terasology.engine.core.module.ExternalApiWhitelist; import org.terasology.engine.core.module.ModuleManager; import org.terasology.engine.testUtil.ModuleManagerFactory; @@ -18,7 +20,10 @@ /** * Enumerates all classes and packages that are annotated with {@link API}. */ +@SuppressWarnings("PMD.SystemPrintln") // main entrypoint used to generate documentation public final class ApiScraper { + private static final Logger LOGGER = LoggerFactory.getLogger(ApiScraper.class); + private ApiScraper() { // Private constructor, utility class } @@ -35,7 +40,7 @@ public static void main(String[] args) throws Exception { SortedSetMultimap sortedApi = Multimaps.newSortedSetMultimap(new HashMap<>(), TreeSet::new); for (Class apiClass : environment.getTypesAnnotatedWith(API.class)) { - //System.out.println("Processing: " + apiClass); + LOGGER.debug("Processing: {}", apiClass); boolean isPackage = apiClass.isSynthetic(); URL location; String category; @@ -49,7 +54,7 @@ public static void main(String[] args) throws Exception { } if (location == null) { - System.out.println("Failed to get a class/package location, skipping " + apiClass); + LOGGER.info("Failed to get a class/package location, skipping {}", apiClass); continue; } @@ -91,7 +96,7 @@ public static void main(String[] args) throws Exception { break; default : - System.out.println("Unknown protocol for: " + apiClass + ", came from " + location); + LOGGER.info("Unknown protocol for: {}, came from {}", apiClass, location); } } sortedApi.putAll("external", ExternalApiWhitelist.CLASSES.stream() diff --git a/engine-tests/src/test/java/org/terasology/documentation/BindingScraper.java b/engine-tests/src/test/java/org/terasology/documentation/BindingScraper.java index fe67aaac9a0..e9b016fee4e 100644 --- a/engine-tests/src/test/java/org/terasology/documentation/BindingScraper.java +++ b/engine-tests/src/test/java/org/terasology/documentation/BindingScraper.java @@ -4,6 +4,8 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.terasology.engine.core.module.ModuleManager; import org.terasology.engine.input.DefaultBinding; import org.terasology.engine.input.DefaultBindings; @@ -18,7 +20,9 @@ /** * Enumerates all default key bindings and writes them sorted by ID to the console */ +@SuppressWarnings("PMD.SystemPrintln") // main entrypoint used to generate documentation public final class BindingScraper { + private static final Logger LOGGER = LoggerFactory.getLogger(BindingScraper.class); private BindingScraper() { // Utility class, no instances @@ -55,14 +59,14 @@ public static void main(String[] args) throws Exception { if (cat.isEmpty()) { InputCategory inputCategory = findEntry(categories, id); if (inputCategory == null) { - System.out.println("Invalid category for: " + info.id()); + LOGGER.info("Invalid category for: {}", info.id()); } } else { InputCategory inputCategory = findCategory(categories, cat); if (inputCategory != null) { categories.put(inputCategory, id); } else { - System.out.println("Invalid category for: " + info.id()); + LOGGER.info("Invalid category for: {}", info.id()); } } diff --git a/engine-tests/src/test/java/org/terasology/documentation/apiScraper/ApiComparator.java b/engine-tests/src/test/java/org/terasology/documentation/apiScraper/ApiComparator.java index d1f531c98ee..a78f0a54e4b 100644 --- a/engine-tests/src/test/java/org/terasology/documentation/apiScraper/ApiComparator.java +++ b/engine-tests/src/test/java/org/terasology/documentation/apiScraper/ApiComparator.java @@ -3,6 +3,8 @@ package org.terasology.documentation.apiScraper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.terasology.documentation.apiScraper.util.ApiMethod; import java.io.BufferedReader; @@ -20,7 +22,7 @@ * Detects API changes between two instances of a scanned code base. */ public final class ApiComparator { - + private static final Logger LOGGER = LoggerFactory.getLogger(ApiComparator.class); private static final String ORIGINAL_API_FILE = "API_file.txt"; private static final String NEW_API_FILE = "New_API_file.txt"; @@ -54,10 +56,10 @@ public static void main(String[] args) throws Exception { br2.close(); //Begins comparison and increases report - System.out.println("================================================================="); + LOGGER.info("================================================================="); checkClassAdditionAndDeletion(originalApi, newApi); checkMethodChanges(originalApi, newApi); - System.out.println("REPORT FINISHED"); + LOGGER.info("REPORT FINISHED"); } } @@ -113,16 +115,16 @@ private static Map> getApi(BufferedReader br) thro } private static void checkClassAdditionAndDeletion(Map> originalApi, Map> newApi) { - System.out.println("Checking Class Addition and Deletion"); + LOGGER.info("Checking Class Addition and Deletion"); for (String className : originalApi.keySet()) { if (!newApi.containsKey(className)) { - System.out.println("MAJOR INCREASE, DELETION OF " + className); + LOGGER.info("MAJOR INCREASE, DELETION OF {}", className); } } for (String className : newApi.keySet()) { if (!originalApi.containsKey(className)) { - System.out.println("MINOR INCREASE, ADDITION OF " + className); + LOGGER.info("MINOR INCREASE, ADDITION OF {}", className); } } } @@ -134,7 +136,7 @@ private static void checkClassAdditionAndDeletion(Map> originalApi, Map> newApi) { - System.out.println("Checking Method Changes"); + LOGGER.info("Checking Method Changes"); Collection originalMethods; Collection newMethods; for (String className : originalApi.keySet()) { @@ -158,9 +160,9 @@ private static void checkMethodChanges(Map> origin if (auxMethod2.getName().equals("")) { checkMethodIncrease(method1, method2); } else if (isInterfaceOrAbstract(method2.getClassName())) { - System.out.println("MINOR INCREASE, NEW OVERLOADED METHOD " + method2.getName() + - " ON " + method2.getClassName() + "\nNEW PARAMETERS: " + method2.getParametersType()); - System.out.println("================================================================="); + LOGGER.info("MINOR INCREASE, NEW OVERLOADED METHOD {} ON {}\nNEW PARAMETERS: {}", + method2.getName(), method2.getClassName(), method2.getParametersType()); + LOGGER.info("================================================================="); } } else { @@ -173,7 +175,7 @@ private static void checkMethodChanges(Map> origin if (!found) { if (isInterfaceOrAbstract(method2.getClassName())) { if (method2.getName().endsWith("(ABSTRACT METHOD)")) { - System.out.println("MAJOR INCREASE, NEW ABSTRACT METHOD " + method2.getName() + " ON " + method2.getClassName()); + LOGGER.info("MAJOR INCREASE, NEW ABSTRACT METHOD {} ON {}", method2.getName(), method2.getClassName()); } else { String minorOrMajor; if (method2.getClassName().endsWith("(INTERFACE)")) { @@ -185,12 +187,12 @@ private static void checkMethodChanges(Map> origin } else { minorOrMajor = "MINOR"; } - System.out.println(minorOrMajor + " INCREASE, NEW METHOD " + method2.getName() + " ON " + method2.getClassName()); + LOGGER.info(minorOrMajor + " INCREASE, NEW METHOD " + method2.getName() + " ON " + method2.getClassName()); } } else { - System.out.println("MINOR INCREASE, NEW METHOD " + method2.getName() + " ON " + method2.getClassName()); + LOGGER.info("MINOR INCREASE, NEW METHOD {} ON {}", method2.getName(), method2.getClassName()); } - System.out.println("================================================================="); + LOGGER.info("================================================================="); } } } @@ -222,7 +224,7 @@ private static void checkMethodDeletion(Collection originalMethods, C ApiMethod result = getMethodWithSameNameAndParameters(method, newMethodsWithSameName); if (result.getName().equals("")) { checkedMethods.add(method.getName()); - System.out.println("MAJOR INCREASE, OVERLOADED METHOD DELETION: " + method.getName() + LOGGER.info("MAJOR INCREASE, OVERLOADED METHOD DELETION: " + method.getName() + " ON " + method.getClassName() + "\nPARAMETERS: " + method.getParametersType()); } @@ -230,7 +232,7 @@ private static void checkMethodDeletion(Collection originalMethods, C } } if (!found) { - System.out.println("MAJOR INCREASE, METHOD DELETION: " + method1.getName() + " ON " + method1.getClassName()); + LOGGER.info("MAJOR INCREASE, METHOD DELETION: " + method1.getName() + " ON " + method1.getClassName()); } } } @@ -260,10 +262,10 @@ private static void checkMethodIncrease(ApiMethod method1, ApiMethod method2) { */ private static void check(String s1, String s2, String methodName, String className) { if (!s1.equals(s2)) { - System.out.println("MAJOR INCREASE ON : " + methodName + " " + className); - System.out.println("ORIGINAL: " + s1); - System.out.println("NEW: " + s2); - System.out.println("================================================================="); + LOGGER.info("MAJOR INCREASE ON : " + methodName + " " + className); + LOGGER.info("ORIGINAL: " + s1); + LOGGER.info("NEW: " + s2); + LOGGER.info("================================================================="); } } diff --git a/engine-tests/src/test/java/org/terasology/documentation/apiScraper/ApiSaver.java b/engine-tests/src/test/java/org/terasology/documentation/apiScraper/ApiSaver.java index 16f6cfe54d2..20befde42fb 100644 --- a/engine-tests/src/test/java/org/terasology/documentation/apiScraper/ApiSaver.java +++ b/engine-tests/src/test/java/org/terasology/documentation/apiScraper/ApiSaver.java @@ -2,6 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 package org.terasology.documentation.apiScraper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -10,6 +13,7 @@ * Saves the API generated by CompleteApiScraper in a txt file. */ public final class ApiSaver { + private static final Logger LOGGER = LoggerFactory.getLogger(ApiSaver.class); private ApiSaver() { @@ -21,6 +25,6 @@ public static void main(String[] args) throws Exception { writer.write(api.toString()); writer.flush(); writer.close(); - System.out.println("API file is ready!"); + LOGGER.info("API file is ready!"); } } diff --git a/engine-tests/src/test/java/org/terasology/math/IntMathTest.java b/engine-tests/src/test/java/org/terasology/math/IntMathTest.java index cc768355c1c..8735f8381eb 100644 --- a/engine-tests/src/test/java/org/terasology/math/IntMathTest.java +++ b/engine-tests/src/test/java/org/terasology/math/IntMathTest.java @@ -7,6 +7,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.terasology.engine.config.Config; import org.terasology.engine.context.internal.ContextImpl; import org.terasology.engine.context.internal.MockContext; @@ -19,6 +21,7 @@ public class IntMathTest { + private static final Logger LOGGER = LoggerFactory.getLogger(IntMathTest.class); public IntMathTest() { } @@ -128,7 +131,7 @@ private static List generateAllPowersOfTwo() { value <<= 1; } - System.out.println(powersOfTwo.get(powersOfTwo.size() - 1)); + LOGGER.info(String.valueOf(powersOfTwo.get(powersOfTwo.size() - 1))); return powersOfTwo; } diff --git a/engine/src/main/java/org/terasology/engine/core/PathManager.java b/engine/src/main/java/org/terasology/engine/core/PathManager.java index ef2c8ebc679..1c233d09b71 100644 --- a/engine/src/main/java/org/terasology/engine/core/PathManager.java +++ b/engine/src/main/java/org/terasology/engine/core/PathManager.java @@ -6,6 +6,8 @@ import com.google.common.collect.ImmutableList; import com.sun.jna.platform.win32.KnownFolders; import com.sun.jna.platform.win32.Shell32Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.terasology.engine.context.Context; import org.terasology.engine.core.subsystem.DisplayDevice; import org.terasology.engine.utilities.OS; @@ -30,6 +32,7 @@ * Manager class that keeps track of the game's various paths and save directories. */ public final class PathManager { + private static final Logger LOGGER = LoggerFactory.getLogger(PathManager.class); private static final String TERASOLOGY_FOLDER_NAME = "Terasology"; private static final Path LINUX_HOME_SUBPATH = Paths.get(".local", "share", "terasology"); @@ -75,11 +78,9 @@ private static Path findInstallPath() { URI urlToSource = PathManager.class.getProtectionDomain().getCodeSource().getLocation().toURI(); Path codeLocation = Paths.get(urlToSource); installationSearchPaths.add(codeLocation); - // Not using logger because it's usually initialized after PathManager. - System.out.println("PathManager: Initial code location is " + codeLocation.toAbsolutePath()); + LOGGER.info("PathManager: Initial code location is " + codeLocation.toAbsolutePath()); } catch (URISyntaxException e) { - System.err.println("PathManager: Failed to convert code location to path."); - e.printStackTrace(); + LOGGER.error("PathManager: Failed to convert code location to path.", e); } // But that's not always true. This jar may be loaded from somewhere else on the classpath. @@ -89,7 +90,7 @@ private static Path findInstallPath() { // Use the current directory as a fallback. Path currentDirectory = Paths.get("").toAbsolutePath(); installationSearchPaths.add(currentDirectory); - System.out.println("PathManager: Working directory is " + currentDirectory); + LOGGER.info("PathManager: Working directory is " + currentDirectory); for (Path startPath : installationSearchPaths) { Path installationPath = findNativesHome(startPath, 5); diff --git a/engine/src/main/java/org/terasology/engine/logic/players/PlayerSystem.java b/engine/src/main/java/org/terasology/engine/logic/players/PlayerSystem.java index d7ec534e526..c8f958c9340 100644 --- a/engine/src/main/java/org/terasology/engine/logic/players/PlayerSystem.java +++ b/engine/src/main/java/org/terasology/engine/logic/players/PlayerSystem.java @@ -46,8 +46,7 @@ @RegisterSystem(RegisterMode.AUTHORITY) public class PlayerSystem extends BaseComponentSystem implements UpdateSubscriberSystem { - - private static final Logger logger = LoggerFactory.getLogger(PlayerSystem.class); + private static final Logger LOGGER = LoggerFactory.getLogger(PlayerSystem.class); @In private EntityManager entityManager; @In @@ -156,7 +155,7 @@ public void onConnect(ConnectedEvent connected, EntityRef entity) { private void restoreCharacter(EntityRef entity, EntityRef character) { Client clientListener = networkSystem.getOwner(entity); - System.out.println(clientListener); + LOGGER.info(clientListener.toString()); updateRelevanceEntity(entity, clientListener.getViewDistance().getChunkDistance()); ClientComponent client = entity.getComponent(ClientComponent.class); @@ -247,7 +246,7 @@ private void respawnPlayer(EntityRef clientEntity) { playerCharacter.addComponent(new AliveCharacterComponent()); playerCharacter.send(new CharacterTeleportEvent(spawnPosition)); - logger.debug("Re-spawing player at: {}", spawnPosition); + LOGGER.debug("Re-spawing player at: {}", spawnPosition); Client clientListener = networkSystem.getOwner(clientEntity); Vector3ic distance = clientListener.getViewDistance().getChunkDistance();