-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] handle WAR file and EAR file #107
Comments
Hi @chingchichuang, thanks for reaching out. I've implemented a way for DepClean to decompress and analyze the bytecode in Please clone and install DepClean from source, then try it in your codebase and let me know if it works for you. Question: Do you know about any open-source Maven project that uses a |
Hi @cesarsotovalero, thank you for the help^______^ I am testing this new feature and find out that this function needs to update too. For the question about EAR and WAR file, I can't find other open-source Maven project that uses EAR or WAR. The Maven project I use is a proprietary project in my internship company. I have checked with my supervisors and they also don't know about this. If I have more information about this, I will let you know! Thank you!! |
Hi @chingchichuang, Thanks for pointing at this. Would you like to contribute by making a pull request with the working changes as in the Otherwise, I will try to implement this solution. |
Hi @cesarsotovalero, Sure, I am glad to implement this solution. |
Hi @cesarsotovalero, I follow the probable solution mentioned previously, but it does not detect dependencies inside the war file. Since WAR files's dependencies are all included under the folder WEB-INF/lib/, I try to decompress WAR file and use classAnalyzer to analyze individual jar file (WEB-INF/lib/*.jar). This step works fine. However, after getting classes by classAnalyzer, I need to put classes and artifact into artifactClassMap. I try to create an artifact by using DefaultArtifact. I am still testing now, and I will update the result later. P.S. Currently, I use a workaround. I go to the repository of each WAR file and manually copy their dependencies (in pom.xml) to the pom.xml analyzed by DepClean. } else if (file != null && file.getName().endsWith(".war")) {
URL url = file.toURI().toURL();
acceptWar(url, artifactClassMap, artifact.getGroupId());
} private void acceptWar(URL url, Map<Artifact, Set<String>> artifactClassMap, String wid) throws URISyntaxException {
File file = new File(new URI(url.toString()));
decompressDependencyFiles(file.getAbsolutePath());
try (ZipFile zip = new ZipFile(file)) {
Enumeration<? extends ZipEntry> zipFileEntries = zip.entries();
while (zipFileEntries.hasMoreElements()) {
ZipEntry entry = zipFileEntries.nextElement();
String currentEntry = entry.getName();
if (currentEntry.matches("^WEB-INF/lib/.*-.*\\.jar$")) {
String name = currentEntry.substring(currentEntry.lastIndexOf("/") + 1);
String artifactId = name.substring(0, name.lastIndexOf("-"));
String version = name.substring(name.lastIndexOf("-") + 1, name.lastIndexOf("."));
String jarPath = url.toString().substring(0, url.toString().length() - 4) + "/WEB-INF/lib/" + name;
Set<String> classes = classAnalyzer.analyze(new URL(jarPath));
Artifact artifact = new DefaultArtifact(wid, artifactId, version, "runtime", "jar", "jdk8", null);
artifactClassMap.put(artifact, classes);
}
}
} catch (IOException e) {
log.info(e.toString());
}
} P.S. for the method decompressDependencyFiles, I reuse your method as below. private void decompressDependencyFiles(String zipFile) {
File file = new File(zipFile);
try (ZipFile zip = new ZipFile(file)) {
String newPath = zipFile.substring(0, zipFile.length() - 4);
new File(newPath).mkdir();
Enumeration<? extends ZipEntry> zipFileEntries = zip.entries();
// Process each entry
while (zipFileEntries.hasMoreElements()) {
// grab a zip file entry
ZipEntry entry = zipFileEntries.nextElement();
String currentEntry = entry.getName();
File destFile = new File(newPath, currentEntry);
File destinationParent = destFile.getParentFile();
// create the parent directory structure if needed
destinationParent.mkdirs();
if (!entry.isDirectory()) {
BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
int currentByte;
// establish buffer for writing file
byte[] data = new byte[BUFFER_SIZE];
// write the current file to disk
FileOutputStream fos = new FileOutputStream(destFile);
try (BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
// read and write until last byte is encountered
while ((currentByte = is.read(data, 0, BUFFER_SIZE)) != -1) {
dest.write(data, 0, currentByte);
}
dest.flush();
is.close();
}
}
}
} catch (IOException e) {
log.info(e.toString());
}
} |
Hi @chingchichuang, |
Hi @cesarsotovalero, |
Hi @cesarsotovalero, I finally have time to test the new version. Currently, I have one month left before my contract with my internship company ends. |
Hi @chingchichuang, |
Hi,
I would like to ask if DepClean has plan to implement how to handle WAR file and EAR file?
An enterprise archive (EAR) is a wrapper for a Java EE application, which consists of web archive (WAR) and Java archive (JAR) files.
Thank you!
Best regards,
Ching-Chi
The text was updated successfully, but these errors were encountered: