Skip to content

Commit

Permalink
[#60feature/#60-restlib] sonar issues fixed
Browse files Browse the repository at this point in the history
Signed-off-by: huluvu424242 <huluvu424242@gmail.com>
  • Loading branch information
Huluvu424242 committed Jan 25, 2023
1 parent 00b6ae8 commit 7c1c285
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,24 @@
* #L%
*/

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.util.ContextInitializer;
import ch.qos.logback.core.joran.spi.JoranException;
import com.github.funthomas424242.jenkinsmonitor.etc.JavaSystemWrapper;
import com.github.funthomas424242.jenkinsmonitor.etc.NetworkHelper;
import com.github.funthomas424242.jenkinsmonitor.jenkins.BasicAuthDaten;
import com.github.funthomas424242.jenkinsmonitor.jenkins.JobAbfragedaten;
import com.github.funthomas424242.jenkinsmonitor.jenkins.JobBeschreibung;
import com.github.funthomas424242.jenkinsmonitor.jenkins.JobBeschreibungen;
import com.github.funthomas424242.jenkinsmonitor.logstash.LogStashConfigManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.github.funthomas424242.jenkinsmonitor.logstash.LogStashConfigManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -117,27 +112,19 @@ protected Jenkinszugangskonfiguration[] getAllJenkinszugangskonfigurationen() {
configurationProperties
.stringPropertyNames()
.stream()
.filter((key) -> key.startsWith(KEY_JENKINSAUTH))
.forEach(key -> {
zugangsdatensammler.addZugangsdatum(key, configurationProperties.getProperty(key));
});
.filter(key -> key.startsWith(KEY_JENKINSAUTH))
.forEach(key -> zugangsdatensammler.addZugangsdatum(key, configurationProperties.getProperty(key)));
return zugangsdatensammler.getJenkinsZugangsdaten();
}

protected JobAbfragedaten getAbfragedatenOf(final URL jobUrl) {
loadPropertiesFromFile(configurationFile);
final Jenkinszugangskonfiguration[] alleJenkinsZugaenge = getAllJenkinszugangskonfigurationen();
final Optional<BasicAuthDaten> jenkinsZugangsdaten = Arrays.stream(alleJenkinsZugaenge)
.filter((zugang) -> {
return jobUrl.toExternalForm().startsWith(zugang.getJenkinsUrl().toExternalForm());
})
.map((zugang) -> zugang.getAuthDaten())
.findFirst();
if (jenkinsZugangsdaten.isPresent()) {
return new JobAbfragedaten(jobUrl, jenkinsZugangsdaten.get());
} else {
return new JobAbfragedaten(jobUrl, null);
}
return Arrays.stream(alleJenkinsZugaenge)
.filter(zugang -> jobUrl.toExternalForm().startsWith(zugang.getJenkinsUrl().toExternalForm()))
.map(Jenkinszugangskonfiguration::getAuthDaten)
.findFirst()
.map(basicAuthDaten -> new JobAbfragedaten(jobUrl, basicAuthDaten)).orElseGet(() -> new JobAbfragedaten(jobUrl, null));
}


Expand All @@ -153,7 +140,7 @@ public Loaded reloadFromFile(final File configFile) {

protected Loaded loadPropertiesFromFile(final File configFile) {
if (this.isInitialisiert) return this;
LOGGER.debug(MessageFormat.format("load properties from file {0}", configFile));
LOGGER.debug("load properties from file {}", configFile);
final Properties properties = new Properties();
try (FileInputStream propStream = new FileInputStream(configFile)) {
properties.load(propStream);
Expand All @@ -174,6 +161,7 @@ public long getPollPeriodInSecond() {
final String propValue = this.configurationProperties.getProperty(JENKINSMONITOR_POLLPERIOD, DEFAULT_POLLPERIOD);
return Long.parseLong(propValue);
}

public Loaded resetLoggerConfiguration() {
final String[] LOG_LEVEL = {"debug", "info", "error", "log"};
final String[] LOG_APPENDER = {"CONSOLE", "FILE"};
Expand All @@ -198,7 +186,7 @@ public Loaded resetLoggerConfiguration() {

// applog.appender
final String rootlogAppender = configurationProperties.getProperty("rootlog.appender");
if (Arrays.stream(LOG_APPENDER).anyMatch(entry -> entry.equals(rootlogAppender))) {
if (Arrays.asList(LOG_APPENDER).contains(rootlogAppender)) {
System.setProperty("rootlog.appender", rootlogAppender);
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
Expand All @@ -29,6 +29,9 @@

public class LogStashConfigManager {

private LogStashConfigManager() {
}

public static void reloadDefaultLoggerConfiguration() throws JoranException {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ContextInitializer ci = new ContextInitializer(loggerContext);
Expand Down

0 comments on commit 7c1c285

Please sign in to comment.