in hawtio-log/src/main/java/io/hawt/log/log4j/MavenCoordHelper.java [39:95]
public static String getMavenCoordinates(Class cls) throws IOException {
StringBuilder buffer = new StringBuilder();
try {
CodeSource source = cls.getProtectionDomain().getCodeSource();
if (source != null) {
URL locationURL = source.getLocation();
if (locationURL != null) {
// lets try find the pom.properties file...
//
// if a file: URL
//
if ("file".equals(locationURL.getProtocol())) {
String path = locationURL.getPath();
if (path != null) {
File file = new File(path);
if (file.exists() && !file.isDirectory()) {
String coordinates = MavenCoordinates.mavenCoordinatesFromJarFile(file);
if (!Objects.isBlank(coordinates)) {
return coordinates;
}
}
//
// find the last file separator character
//
int lastSlash = path.lastIndexOf('/');
int lastBack = path.lastIndexOf(File.separatorChar);
if (lastBack > lastSlash) {
lastSlash = lastBack;
}
//
// if no separator or ends with separator (a directory)
// then output the URL, otherwise just the file name.
//
if (lastSlash <= 0 || lastSlash == path.length() - 1) {
buffer.append(locationURL);
} else {
buffer.append(path.substring(lastSlash + 1));
}
}
} else {
buffer.append(locationURL);
}
}
}
} catch (SecurityException ex) {
}
buffer.append(':');
Package pkg = cls.getPackage();
if (pkg != null) {
String implVersion = pkg.getImplementationVersion();
if (implVersion != null) {
buffer.append(implVersion);
}
}
return buffer.toString();
}