|
7 | 7 | import java.util.concurrent.ConcurrentHashMap; |
8 | 8 | import java.util.stream.Collectors; |
9 | 9 | import java.util.stream.Stream; |
| 10 | +import java.util.zip.ZipEntry; |
| 11 | +import java.util.zip.ZipInputStream; |
| 12 | + |
10 | 13 | import org.apache.log4j.Logger; |
11 | 14 | import org.clyze.doop.util.filter.ClassFilter; |
12 | 15 | import org.clyze.doop.util.filter.GlobClassFilter; |
13 | 16 | import org.clyze.utils.ContainerUtils; |
14 | 17 | import org.clyze.utils.JHelper; |
| 18 | +import org.zeroturnaround.zip.ZipUtil; |
| 19 | + |
| 20 | +import static org.clyze.utils.ContainerUtils.createTmpDir; |
15 | 21 |
|
16 | 22 | /** |
17 | 23 | * This class handles common parameters for Doop Java front-ends. |
@@ -314,4 +320,67 @@ public void processFatArchives(Set<String> tmpDirs) { |
314 | 320 | System.out.println("inputs = " + getInputs()); |
315 | 321 | System.out.println("libraries = " + getDependencies()); |
316 | 322 | } |
| 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 | + } |
317 | 386 | } |
0 commit comments