MavenArtifact implements Serializable { public static File getSourceJarFile(URL classesJarFileUrl) throws IOException { final String file = classesJarFileUrl.getFile(); if (file.endsWith(".jar")) { final File sources = new File(file.replace(".jar", "-sources.jar")); if (sources.exists()) { return sources; } } final byte[] pomProperties = readMavenFileFromJarFile(classesJarFileUrl, "pom.properties"); if (pomProperties == null) { final Map<String, String> sourceFilePaths = getSourceFilePathsByJarFileNames(); String jarFileName = file; if (jarFileName.endsWith("!/")) { jarFileName = jarFileName.substring(0, jarFileName.length() - "!/".length()); } jarFileName = jarFileName.substring(jarFileName.lastIndexOf('/') + 1); final String sourceFilePath = sourceFilePaths.get(jarFileName); if (sourceFilePath != null) { return getMavenArtifact(sourceFilePath); } return null; } final Properties properties = new Properties(); properties.load(new ByteArrayInputStream(pomProperties)); final MavenArtifact mavenArtifact = new MavenArtifact(); mavenArtifact.groupId = properties.getProperty("groupId"); mavenArtifact.artifactId = properties.getProperty("artifactId"); mavenArtifact.version = properties.getProperty("version"); final String filePath = mavenArtifact.getPath("-sources.jar"); return getMavenArtifact(filePath); } private  MavenArtifact(); String getGroupId(); String getArtifactId(); String getVersion(); String getName(); String getUrl(); Map<String, String> getLicenseUrlsByName(); static Map<String, MavenArtifact> getWebappDependencies(); static InputStream getWebappPomXmlAsStream(); static synchronized String getWebappVersion(); static File getSourceJarFile(URL classesJarFileUrl); static File getTomcatSrcZipFile(); @Override String toString();  }
@Test public void testGetSourceJarFile() throws ClassNotFoundException, IOException { final File storageDirectory = Parameters .getStorageDirectory(Parameters.getCurrentApplication()); rmdir(new File(storageDirectory, "poms")); rmdir(new File(storageDirectory, "sources")); final Class<?> clazz = Class.forName("org.apache.commons.dbcp2.BasicDataSource"); final URL location = clazz.getProtectionDomain().getCodeSource().getLocation(); assertNotNull("getSourceJarFile", MavenArtifact.getSourceJarFile(location)); Utils.setProperty(Parameter.MAVEN_REPOSITORIES, LOCAL_REPO.getPath() + ',' + MAVEN_CENTRAL); assertNotNull("getSourceJarFile", MavenArtifact.getSourceJarFile(location)); }