From de0bcaf3e8b2422932e25c6c4d21ab4a8aa3e1b3 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 1 Sep 2020 07:21:06 +0200 Subject: [PATCH] use static instance of slf4j instead of lombok annotation --- .../java/sonia/scm/web/i18n/I18nServlet.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/scm-webapp/src/main/java/sonia/scm/web/i18n/I18nServlet.java b/scm-webapp/src/main/java/sonia/scm/web/i18n/I18nServlet.java index 2748153b7d..903250c68b 100644 --- a/scm-webapp/src/main/java/sonia/scm/web/i18n/I18nServlet.java +++ b/scm-webapp/src/main/java/sonia/scm/web/i18n/I18nServlet.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.web.i18n; @@ -31,14 +31,15 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.github.legman.Subscribe; import com.google.common.annotations.VisibleForTesting; import com.google.inject.Singleton; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import sonia.scm.NotFoundException; import sonia.scm.SCMContext; import sonia.scm.Stage; -import sonia.scm.lifecycle.RestartEvent; import sonia.scm.cache.Cache; import sonia.scm.cache.CacheManager; import sonia.scm.filter.WebElement; +import sonia.scm.lifecycle.RestartEvent; import sonia.scm.plugin.PluginLoader; import javax.inject.Inject; @@ -63,16 +64,17 @@ import static sonia.scm.NotFoundException.notFound; */ @Singleton @WebElement(value = I18nServlet.PATTERN, regex = true) -@Slf4j public class I18nServlet extends HttpServlet { + private static final Logger LOG = LoggerFactory.getLogger(I18nServlet.class); + public static final String PLUGINS_JSON = "plugins.json"; public static final String PATTERN = "/locales/[a-z\\-A-Z]*/" + PLUGINS_JSON; public static final String CACHE_NAME = "sonia.cache.plugins.translations"; private final ClassLoader classLoader; private final Cache cache; - private static ObjectMapper objectMapper = new ObjectMapper(); + private final ObjectMapper objectMapper = new ObjectMapper(); @Inject @@ -83,7 +85,7 @@ public class I18nServlet extends HttpServlet { @Subscribe(async = false) public void handleRestartEvent(RestartEvent event) { - log.debug("Clear cache on restart event with reason {}", event.getReason()); + LOG.debug("Clear cache on restart event with reason {}", event.getReason()); cache.clear(); } @@ -108,21 +110,20 @@ public class I18nServlet extends HttpServlet { try (PrintWriter out = response.getWriter()) { String path = req.getServletPath(); Function> jsonFileProvider = usedPath -> Optional.empty(); - BiConsumer createdJsonFileConsumer = (usedPath, jsonNode) -> log.debug("A json File is created from the path {}", usedPath); + BiConsumer createdJsonFileConsumer = (usedPath, jsonNode) -> LOG.debug("A json File is created from the path {}", usedPath); if (isProductionStage()) { - log.debug("In Production Stage get the plugin translations from the cache"); - jsonFileProvider = usedPath -> Optional.ofNullable( - cache.get(usedPath)); + LOG.debug("In Production Stage get the plugin translations from the cache"); + jsonFileProvider = usedPath -> Optional.ofNullable(cache.get(usedPath)); createdJsonFileConsumer = createdJsonFileConsumer - .andThen((usedPath, jsonNode) -> log.debug("Put the created json File in the cache with the key {}", usedPath)) + .andThen((usedPath, jsonNode) -> LOG.debug("Put the created json File in the cache with the key {}", usedPath)) .andThen(cache::put); } objectMapper.writeValue(out, getCollectedJson(path, jsonFileProvider, createdJsonFileConsumer)); } catch (IOException e) { - log.error("Error on getting the translation of the plugins", e); + LOG.error("Error on getting the translation of the plugins", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (NotFoundException e) { - log.error("Plugin translations are not found", e); + LOG.error("Plugin translations are not found", e); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } @@ -140,7 +141,7 @@ public class I18nServlet extends HttpServlet { */ @VisibleForTesting protected Optional collectJsonFile(String path) { - log.debug("Collect plugin translations from path {} for every plugin", path); + LOG.debug("Collect plugin translations from path {} for every plugin", path); JsonNode mergedJsonNode = null; try { Enumeration resources = classLoader.getResources(path.replaceFirst("/", "")); @@ -154,7 +155,7 @@ public class I18nServlet extends HttpServlet { } } } catch (IOException e) { - log.error("Error on loading sources from {}", path, e); + LOG.error("Error on loading sources from {}", path, e); return Optional.empty(); } return Optional.ofNullable(mergedJsonNode);