// Path: src/main/java/com/github/davidmoten/logan/util/PropertyReplacer.java
// public class PropertyReplacer {
// 
// 	private PropertyReplacer() {
// 		// prevent instantiation
// 	}
// 
// 	public static InputStream replaceSystemProperties(InputStream is) {
// 		try {
// 			List<String> lines = IOUtils.readLines(is, StandardCharsets.UTF_8);
// 			ByteArrayOutputStream bytes = new ByteArrayOutputStream();
// 			PrintWriter out = new PrintWriter(bytes);
// 			Pattern p = Pattern.compile("\\$\\{[^\\$]*\\}");
// 			boolean firstLine = true;
// 			for (String line : lines) {
// 				if (!firstLine)
// 					out.println();
// 				Matcher m = p.matcher(line);
// 				while (m.find()) {
// 					String name = m.group()
// 							.substring(2, m.group().length() - 1);
// 					String property = System.getProperty(name);
// 					if (property != null)
// 						line = line.replace(m.group(), property);
// 				}
// 				out.print(line);
// 				firstLine = false;
// 			}
// 			out.close();
// 			return new ByteArrayInputStream(bytes.toByteArray());
// 		} catch (IOException e) {
// 			throw new RuntimeException(e);
// 		}
// 	}
// }
// 
// Path: src/main/java/com/github/davidmoten/logan/watcher/Main.java
// public class Main {
// 
//     private static Logger log = Logger.getLogger(Main.class.getName());
// 
//     /**
//      * Main method to start the persister.
//      * 
//      * @param args
//      *            args
//      * @throws IOException
//      *             exception
//      */
//     public static void main(String[] args) throws IOException {
// 
//         Configuration configuration = Configuration.getConfiguration();
//         setupLogging();
// 
//         Watcher w = new Watcher(new DataMemory(), configuration);
//         log.info("starting watcher");
//         w.start();
//         log.info("started");
//     }
// 
//     private static void setupLogging() throws IOException {
//         LogManager.getLogManager()
//                 .readConfiguration(Main.class.getResourceAsStream("/my-logging.properties"));
//     }
// 
// }


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;
import java.util.logging.Logger;
import javax.xml.bind.annotation.XmlElement;
import com.github.davidmoten.logan.util.PropertyReplacer;
import com.github.davidmoten.logan.watcher.Main;
import com.google.common.collect.Lists;
     * <code>logan.config</code>. The classpath is checked first then the
     * filesystem. If the file is not found in neither path then a
     * {@link RuntimeException} is thrown.
     * </p>
     * 
     * <p>
     * Any properties specified in the configuration.xml file in the format
     * <code>${property.name}</code> will be replaced with system properties if
     * set.
     * </p>
     * 
     * @return loaded configuration
     */

    public static synchronized Configuration getConfiguration() {
        String configLocation = System.getProperty("logan.config", DEFAULT_CONFIGURATION_LOCATION);
        log.info("config=" + configLocation);
        InputStream is = Main.class.getResourceAsStream(configLocation);
        if (is == null) {
            File file = new File(configLocation);
            if (file.exists())
                try {
                    is = new FileInputStream(configLocation);
                } catch (FileNotFoundException e) {
                    throw new RuntimeException(e);
                }
            else
                throw new RuntimeException(
                        "configuration xml not found. Set property logan.config to a file on classpath or filesystem.");
        }
// Path: src/main/java/com/github/davidmoten/logan/util/PropertyReplacer.java
// public class PropertyReplacer {
// 
// 	private PropertyReplacer() {
// 		// prevent instantiation
// 	}
// 
// 	public static InputStream replaceSystemProperties(InputStream is) {
// 		try {
// 			List<String> lines = IOUtils.readLines(is, StandardCharsets.UTF_8);
// 			ByteArrayOutputStream bytes = new ByteArrayOutputStream();
// 			PrintWriter out = new PrintWriter(bytes);
// 			Pattern p = Pattern.compile("\\$\\{[^\\$]*\\}");
// 			boolean firstLine = true;
// 			for (String line : lines) {
// 				if (!firstLine)
// 					out.println();
// 				Matcher m = p.matcher(line);
// 				while (m.find()) {
// 					String name = m.group()
// 							.substring(2, m.group().length() - 1);
// 					String property = System.getProperty(name);
// 					if (property != null)
// 						line = line.replace(m.group(), property);
// 				}
// 				out.print(line);
// 				firstLine = false;
// 			}
// 			out.close();
// 			return new ByteArrayInputStream(bytes.toByteArray());
// 		} catch (IOException e) {
// 			throw new RuntimeException(e);
// 		}
// 	}
// }
// 
// Path: src/main/java/com/github/davidmoten/logan/watcher/Main.java
// public class Main {
// 
//     private static Logger log = Logger.getLogger(Main.class.getName());
// 
//     /**
//      * Main method to start the persister.
//      * 
//      * @param args
//      *            args
//      * @throws IOException
//      *             exception
//      */
//     public static void main(String[] args) throws IOException {
// 
//         Configuration configuration = Configuration.getConfiguration();
//         setupLogging();
// 
//         Watcher w = new Watcher(new DataMemory(), configuration);
//         log.info("starting watcher");
//         w.start();
//         log.info("started");
//     }
// 
//     private static void setupLogging() throws IOException {
//         LogManager.getLogManager()
//                 .readConfiguration(Main.class.getResourceAsStream("/my-logging.properties"));
//     }
// 
// }


// Path: src/main/java/com/github/davidmoten/logan/config/Configuration.java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;
import java.util.logging.Logger;
import javax.xml.bind.annotation.XmlElement;
import com.github.davidmoten.logan.util.PropertyReplacer;
import com.github.davidmoten.logan.watcher.Main;
import com.google.common.collect.Lists;

     * <code>logan.config</code>. The classpath is checked first then the
     * filesystem. If the file is not found in neither path then a
     * {@link RuntimeException} is thrown.
     * </p>
     * 
     * <p>
     * Any properties specified in the configuration.xml file in the format
     * <code>${property.name}</code> will be replaced with system properties if
     * set.
     * </p>
     * 
     * @return loaded configuration
     */

    public static synchronized Configuration getConfiguration() {
        String configLocation = System.getProperty("logan.config", DEFAULT_CONFIGURATION_LOCATION);
        log.info("config=" + configLocation);
        InputStream is = Main.class.getResourceAsStream(configLocation);
        if (is == null) {
            File file = new File(configLocation);
            if (file.exists())
                try {
                    is = new FileInputStream(configLocation);
                } catch (FileNotFoundException e) {
                    throw new RuntimeException(e);
                }
            else
                throw new RuntimeException(
                        "configuration xml not found. Set property logan.config to a file on classpath or filesystem.");
        }
        InputStream is2 = PropertyReplacer.replaceSystemProperties(is);