com.automationrockstars.bmo.ArtefactsStore Maven / Gradle / Ivy
package com.automationrockstars.bmo;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Callable;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.automationrockstars.base.ConfigLoader;
import com.google.common.collect.Maps;
public class ArtefactsStore {
private static Map stored = Maps.newConcurrentMap();
private static final String destinationFolder = ConfigLoader.config().getString("report.target.data","target/allure-report/data");
public static synchronized void store(String name, String webTag){
stored.put(name, webTag);
}
private static final Logger LOG = LoggerFactory.getLogger(ArtefactsStore.class);
private static void copyFile(File originalLocation){
try {
FileUtils.copyFile(originalLocation, Paths.get(destinationFolder,originalLocation.getName()).toFile());
} catch (IOException e) {
LOG.error("Inculding file {} as publishable artifact failed due to {}",originalLocation,e.getMessage());
}
}
public static void storeTextFile(String name,File text){
copyFile(text);
store(name, String.format(""
+ "",
destinationFolder,text.getName(),name,destinationFolder,text.getName()));
}
public static void storeImage(String name, File image){
copyFile(image);
store(name,String.format("", destinationFolder,image.getName()));
}
public static void storeLink(String name, String url){
store(name, String.format("%s", url,name));
}
public static void storeVideo(String name,Callable video){
try {
storeVideo(name, video.call());
} catch (Exception e) {
LOG.error("Fetching file with {} failed due to {}",video,e);
}
}
public static void storeVideo(String name,File video){
copyFile(video);
store(name,String.format("", destinationFolder,video.getName(),name,destinationFolder,video.getName()));
}
public static void storeText(String name, String text){
store(name, String.format("%s", text));
}
public static Properties populate(Properties initial){
for (Map.Entry prop : stored.entrySet()){
initial.setProperty(prop.getKey(), prop.getValue());
}
return initial;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy