io.github.rmuhamedgaliev.config.ConfigLoader Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2015 Rinat Muhamedgaliev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.rmuhamedgaliev.config;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
/**
* Config loader class for work with config of JPS
*
* @author Rinat Muhamedgaliev
*/
public class ConfigLoader {
// Follow directory contain all config files
private final static File CONFIG_DIRECTORY = new File("config");
/**
* Follow void method check {@link ConfigLoader#CONFIG_DIRECTORY} exists.
* If directory not exists, method create itself.
*
* Follow method must call only before read all plugins
*/
public void prepareConfig() {
if (!CONFIG_DIRECTORY.exists()) {
CONFIG_DIRECTORY.mkdir();
}
copyLogBackConfig();
}
/**
* Copy file {@link logback} from resource directory to configure logback
*/
private void copyLogBackConfig() {
File logbackConfigFile = new File("config/logback.xml");
if (!logbackConfigFile.exists() && !logbackConfigFile.canRead()) {
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("logback");
try {
Files.copy(stream, Paths.get("config/logback.xml"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy