Skip to content

Commit 955d9ef

Browse files
committed
add springboot support
1 parent ac22631 commit 955d9ef

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/main/java/org/clyze/doop/common/BasicJavaSupport.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private void preprocessInput(Database db, Set<String> tmpDirs,
7272
boolean isZip = filenameL.endsWith(".zip");
7373
boolean isClass = filenameL.endsWith(".class");
7474
boolean isApk = filenameL.endsWith(".apk");
75+
boolean isSpringBoot = parameters.isSpringBootJar(filenameL);
7576

7677
ArtifactScanner.EntryProcessor gProc = (jarFile, entry, entryName) -> {
7778
if (entryName.endsWith(".properties"))
@@ -90,6 +91,12 @@ else if ((isJar || isAar || isZip || isWar) && entryName.endsWith(".xml")) {
9091
// Process WAR inputs.
9192
parameters.processFatArchives(tmpDirs);
9293
}
94+
95+
if (isSpringBoot) {
96+
System.out.println("Processing springBoot: " + filename);
97+
parameters.processSpringBootArchives(tmpDirs, filename);
98+
}
99+
93100
if (isJar || isApk || isZip || isWar)
94101
artScanner.processArchive(filename, classSet::add, gProc);
95102
else if (isClass) {

src/main/java/org/clyze/doop/common/Parameters.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
import java.util.concurrent.ConcurrentHashMap;
88
import java.util.stream.Collectors;
99
import java.util.stream.Stream;
10+
import java.util.zip.ZipEntry;
11+
import java.util.zip.ZipInputStream;
12+
1013
import org.apache.log4j.Logger;
1114
import org.clyze.doop.util.filter.ClassFilter;
1215
import org.clyze.doop.util.filter.GlobClassFilter;
1316
import org.clyze.utils.ContainerUtils;
1417
import org.clyze.utils.JHelper;
18+
import org.zeroturnaround.zip.ZipUtil;
19+
20+
import static org.clyze.utils.ContainerUtils.createTmpDir;
1521

1622
/**
1723
* This class handles common parameters for Doop Java front-ends.
@@ -314,4 +320,67 @@ public void processFatArchives(Set<String> tmpDirs) {
314320
System.out.println("inputs = " + getInputs());
315321
System.out.println("libraries = " + getDependencies());
316322
}
323+
324+
public boolean isSpringBootJar(String jarFile){
325+
try{
326+
ZipInputStream in = new ZipInputStream(new FileInputStream(jarFile));
327+
328+
ZipEntry entry = null;
329+
330+
while((entry = in.getNextEntry()) != null){
331+
if (entry.isDirectory() && entry.getName().equals("org/springframework/boot/")){
332+
return true;
333+
}
334+
}
335+
}catch (Exception e){
336+
e.printStackTrace();
337+
}
338+
return false;
339+
}
340+
341+
public void processSpringBootArchives(Set<String> tmpDirs, String springBootJar){
342+
try{
343+
String tmpDirPath = createTmpDir(tmpDirs);
344+
Set<String> jarLibs = ConcurrentHashMap.newKeySet();
345+
346+
if (tmpDirPath == null) {
347+
System.out.println("ERROR: null temporary directory path");
348+
return;
349+
}
350+
File tmpDir = new File(tmpDirPath);
351+
File springBootJarFile = new File(springBootJar);
352+
ZipUtil.unpack(springBootJarFile, tmpDir);
353+
// zip BOOT-INF/classes
354+
String jar = tmpDir + "/" + springBootJarFile.getName();
355+
File webInfClasses = new File(tmpDir,"BOOT-INF/classes/");
356+
if (webInfClasses.exists()) {
357+
File zipTarget = new File(jar);
358+
ZipUtil.pack(webInfClasses, zipTarget);
359+
jarLibs.add(zipTarget.getCanonicalPath());
360+
}
361+
// collect libs in BOOT-INF/lib
362+
File bootInfLibs = new File(tmpDir, "BOOT-INF/lib");
363+
if (bootInfLibs.exists()) {
364+
File[] files = bootInfLibs.listFiles();
365+
if (files != null) {
366+
for (File file : files) {
367+
if (file.getName().endsWith(".jar")) {
368+
jarLibs.add(file.getCanonicalPath());
369+
}
370+
}
371+
}
372+
}
373+
374+
jarLibs.addAll(getInputs());
375+
jarLibs.remove(springBootJar);
376+
setInputs(new ArrayList<String>(jarLibs));
377+
// jarLibs.addAll(getDependencies());
378+
// setDependencies(new ArrayList<>(jarLibs));
379+
System.out.println("inputs = " + getInputs());
380+
System.out.println("libraries = " + getDependencies());
381+
}catch (Exception e){
382+
e.printStackTrace();
383+
}
384+
385+
}
317386
}

0 commit comments

Comments
 (0)