package pl.touk.sputnik;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Configuration {
    private static final Logger LOG = LoggerFactory.getLogger(Configuration.class);
    private static final Configuration INSTANCE = new Configuration();
    private static final String SPUTNIK_PROPERTIES = "sputnik.properties";
    private static final String SPUTNIK_OPTS = "SPUTNIK_OPTS";
    private Properties properties = new Properties();

    private Configuration() {}

    @NotNull
    public static Configuration instance() {
        return INSTANCE;
    }

    @Nullable
    public String getProperty(@NotNull String key) {
        String value = properties.getProperty(key);
        if (StringUtils.isBlank(value)) {
            value = System.getProperty(key);
        }
        return value;
    }

    public void init() {

        LOG.info("Initializing configuration properties ");
        properties = new Properties();
        InputStream inputStream = null;
        try {
            inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(SPUTNIK_PROPERTIES);
            properties.load(inputStream);
        } catch (IOException e) {
            LOG.error("Configuration initialization failed", e);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }

    @Nullable
    private String getPropertiesFilename() {
        String filename = System.getProperty(SPUTNIK_PROPERTIES);
        if (StringUtils.isBlank(filename)) {
            LOG.warn("Didn't read any properties file - system property {} is missing.", SPUTNIK_PROPERTIES);
            LOG.warn("If you want to provide proprties file in future you can to this with specyfing -D{}=\"/home/user/review.pproperties\" option.", SPUTNIK_PROPERTIES);
            LOG.warn("You can also set up {} variable, so they will be passed to JVM.", SPUTNIK_OPTS);
        }
    }

}

@@ -1100,17 +1100,16 @@
 nit() %7B%0A
-%0A
         
@@ -1159,13 +1159,146 @@
 ties
- 
 %22);%0A
+        String propertiesFilename = getPropertiesFilename();%0A        if (propertiesFilename == null) %7B%0A            return;%0A        %7D%0A%0A
     
@@ -2280,26 +2280,128 @@
 OPTS);%0A        %7D
+ else %7B%0A            LOG.info(%22Using properties file %7B%7D%22, filename);%0A        %7D%0A        return filename;
 %0A    %7D%0A%0A%7D%0A

Fix compilation error