From b143d39467d561004161b3a14977cdc4436f2b86 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Tue, 24 Dec 2024 14:31:38 +0300 Subject: [PATCH] safe read --- src/main/java/com/rultor/Env.java | 2 +- src/main/resources/META-INF/MANIFEST.MF | 1 + src/test/java/com/rultor/EnvTest.java | 4 ++-- src/test/resources/log4j.properties | 11 ++++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/rultor/Env.java b/src/main/java/com/rultor/Env.java index e04db5accb..2860897c57 100644 --- a/src/main/java/com/rultor/Env.java +++ b/src/main/java/com/rultor/Env.java @@ -66,7 +66,7 @@ private Env() { public static String read(final String name) { final String xml = System.getenv(Env.SETTINGS_XML); final String ret; - if (xml == null) { + if (xml == null || Manifests.exists(name) && !Manifests.read(name).startsWith("${")) { ret = Manifests.read(name); } else { final String res = "rultor-mf/MANIFEST.MF"; diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF index b8f9ced743..64e3ac46ec 100644 --- a/src/main/resources/META-INF/MANIFEST.MF +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -25,3 +25,4 @@ Rultor-TwitterTokenSecret: ${twitter.tsecret} Rultor-SentryDsn: ${sentry.dsn} Rultor-GpgPublic: ${gpg.public} Rultor-GpgSecret: ${gpg.secret} +Rultor-Test: ${test} diff --git a/src/test/java/com/rultor/EnvTest.java b/src/test/java/com/rultor/EnvTest.java index 10f7ea1e18..73b0f762af 100644 --- a/src/test/java/com/rultor/EnvTest.java +++ b/src/test/java/com/rultor/EnvTest.java @@ -80,7 +80,7 @@ void readsFromSettingsXml() { String.join( "", "", - "hello", + "hello", "" ) ); @@ -91,7 +91,7 @@ void readsFromSettingsXml() { ); MatcherAssert.assertThat( "takes the right value", - Env.read("Rultor-DynamoKey"), + Env.read("Rultor-Test"), Matchers.equalTo("hello") ); } diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties index 700f9346e4..ea5ce06753 100644 --- a/src/test/resources/log4j.properties +++ b/src/test/resources/log4j.properties @@ -32,9 +32,10 @@ log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=com.jcabi.log.MulticolorLayout log4j.appender.CONSOLE.layout.ConversionPattern=[%color{%p}] %c{1}: %m%n -log4j.logger.com.rultor=INFO -log4j.logger.com.jcabi.dynamo=INFO -log4j.logger.com.jcabi.github=INFO +log4j.logger.com.rultor=WARN +log4j.logger.com.jcabi.dynamo=WARN +log4j.logger.com.jcabi.github=WARN +log4j.logger.com.jcabi.xml.StrictXML=ERROR log4j.logger.com.jcabi.http.wire.VerboseWire=WARN -log4j.logger.com.jcabi.manifests=INFO -log4j.logger.co.stateful.mock=DEBUG +log4j.logger.com.jcabi.manifests=WARN +log4j.logger.co.stateful.mock=WARN