Utils.java
package org.docascode.utils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.FileUtils;
import org.docascode.Main;
import org.fusesource.jansi.Ansi;
import static org.fusesource.jansi.Ansi.Color.*;
public class Utils {
private DocAsCodeRepository repository = null;
private Utils(){}
private static Utils ourInstance = new Utils();
public static void setDirectory(File directory){
ourInstance.repository = new DocAsCodeRepository(directory);
}
public static Utils getInstance() {
return ourInstance;
}
public static DocAsCodeRepository getRepository (){
return getInstance().repository;
}
public static void success(String msg){
System.out.println(Ansi.ansi().fg(GREEN).a(msg).reset());
}
public static void info(String msg){
System.out.println(Ansi.ansi().fg(BLUE).a(msg).reset());
}
public static void warn(String msg){
System.out.println(Ansi.ansi().fg(YELLOW).a(msg).reset());
//Tracer dans un log
}
public static void error(String msg, ExitCode e){
System.out.println(Ansi.ansi().fg(RED).a(msg).reset());
//Tracer dans un log
System.exit(e.toInt());
}
public static String getDocAsCodeVersion(){
return Main.class.getPackage().getImplementationVersion();
}
public static void copyInputStreamToFile(InputStream source, File destination, boolean override) throws IOException {
if ((destination.exists() && override) || !destination.exists()){
FileUtils.copyInputStreamToFile(source,destination);
}
}
}