in enricher/fabric8/src/main/java/io/fabric8/maven/enricher/fabric8/IconEnricher.java [254:311]
private String convertIconFileToURL(File iconFile, String iconRef) throws IOException {
long length = iconFile.length();
int sizeK = Math.round(length / 1024);
byte[] bytes = Files.readBytes(iconFile);
byte[] encoded = Base64Encoder.encode(bytes);
int base64SizeK = Math.round(encoded.length / 1024);
if (base64SizeK < Configs.asInt(getConfig(Config.maximumDataUrlSizeK))) {
String mimeType = guessMediaType(iconFile);
return "data:" + mimeType + ";charset=UTF-8;base64," + new String(encoded);
} else {
File iconSourceFile = new File(appConfigDir, iconFile.getName());
if (iconSourceFile.exists()) {
File rootProjectFolder = getRootProjectFolder();
if (rootProjectFolder != null) {
String relativePath = Files.getRelativePath(rootProjectFolder, iconSourceFile);
String relativeParentPath = Files.getRelativePath(rootProjectFolder, getProject().getBasedir());
String urlPrefix = getConfig(Config.urlPrefix);
if (Strings.isNullOrBlank(urlPrefix)) {
Scm scm = getProject().getScm();
if (scm != null) {
String url = scm.getUrl();
if (url != null) {
String[] prefixes = {"http://github.com/", "https://github.com/"};
for (String prefix : prefixes) {
if (url.startsWith(prefix)) {
url = URLUtils.pathJoin("https://cdn.rawgit.com/", url.substring(prefix.length()));
break;
}
}
if (url.endsWith(relativeParentPath)) {
url = url.substring(0, url.length() - relativeParentPath.length());
}
urlPrefix = url;
}
}
}
if (Strings.isNullOrBlank(urlPrefix)) {
log.warn("No iconUrlPrefix defined or could be found via SCM in the pom.xml so cannot add an icon URL!");
} else {
String answer = URLUtils.pathJoin(urlPrefix, getConfig(Config.branch), relativePath);
return answer;
}
}
} else {
String embeddedIcon = embeddedIconsInConsole(iconRef, "img/icons/");
if (embeddedIcon != null) {
return embeddedIcon;
} else {
log.warn("Cannot find url for icon to use %s", iconRef);
}
}
}
return null;
}