| 437 | | String path = jarUrl.getPath(); |
| 438 | | int ind = path.indexOf('!'); |
| 439 | | path = path.substring(0, ind); |
| 440 | | ind = path.lastIndexOf('/'); |
| 441 | | path = path.substring(ind + 1); |
| 442 | | ind = path.lastIndexOf('.'); |
| 443 | | path = path.substring(0, ind); |
| 444 | | // look for entry by jar file name |
| 445 | | Entry entry = jarEntries.get(path); |
| 446 | | if (entry != null) { |
| 447 | | for (File dir : entry.directories) { |
| 448 | | if (dir.getName().equals("resources")) { |
| 449 | | if (LOG.isDebugEnabled()) { |
| 450 | | LOG.debug("Found live location by jar file name: " + path); |
| 451 | | } |
| 452 | | rootToLocation.put(jarUrl.toString(), dir); |
| 453 | | return dir; |
| 454 | | } |
| 455 | | } |
| 456 | | } |
| 457 | | // look for entry by artifact name and MANIFEST attributes |
| 458 | | try { |
| 459 | | URL manifestUrl = new URL(jarUrl, "/META-INF/MANIFEST.MF"); |
| 460 | | URLConnection con = manifestUrl.openConnection(); |
| 461 | | if (con != null) { |
| 462 | | InputStream in = con.getInputStream(); |
| 463 | | if (in != null) { |
| 464 | | Manifest manifest = new Manifest(in); |
| 465 | | Attributes attrs = manifest.getMainAttributes(); |
| 466 | | String groupId = attrs.getValue("Implementation-Vendor-Id"); |
| 467 | | String version = attrs.getValue("Implementation-Version"); |
| 468 | | if (groupId != null && version != null) { |
| 469 | | int endInd = path.indexOf(version); |
| 470 | | if (endInd > 2) { |
| 471 | | String artifactId = path.substring(0, endInd - 1); |
| 472 | | String entryKey = groupId + "+" + artifactId + "+" + version; |
| 473 | | entry = jarEntries.get(entryKey); |
| 474 | | if (entry != null) { |
| 475 | | for (File dir : entry.directories) { |
| 476 | | // if (dir.getName().equals("resources")) { |
| 477 | | if (LOG.isDebugEnabled()) { |
| 478 | | LOG.debug("Found live location by artifact name and MANIFEST attributes: " |
| 479 | | + entryKey); |
| | 439 | if (url.getProtocol().equals("jar")) { |
| | 440 | String jarFileName = url.getPath(); |
| | 441 | int ind = jarFileName.indexOf('!'); |
| | 442 | jarFileName = jarFileName.substring(0, ind); |
| | 443 | ind = jarFileName.lastIndexOf('/'); |
| | 444 | jarFileName = jarFileName.substring(ind + 1); |
| | 445 | ind = jarFileName.lastIndexOf('.'); |
| | 446 | jarFileName = jarFileName.substring(0, ind); |
| | 447 | // look for entry by jar file name |
| | 448 | Entry entry = jarEntries.get(jarFileName); |
| | 449 | if (entry != null) { |
| | 450 | for (File dir : entry.directories) { |
| | 451 | if (dir.getName().equals("resources")) { |
| | 452 | if (LOG.isDebugEnabled()) { |
| | 453 | LOG.debug("Found live module location by jar file name: " + jarFileName); |
| | 454 | } |
| | 455 | rootToLocation.put(url.toString(), dir); |
| | 456 | return dir; |
| | 457 | } |
| | 458 | } |
| | 459 | } |
| | 460 | // look for entry by artifact name and MANIFEST attributes |
| | 461 | try { |
| | 462 | URL manifestUrl = new URL(url, "/META-INF/MANIFEST.MF"); |
| | 463 | URLConnection con = manifestUrl.openConnection(); |
| | 464 | if (con != null) { |
| | 465 | InputStream in = con.getInputStream(); |
| | 466 | if (in != null) { |
| | 467 | Manifest manifest = new Manifest(in); |
| | 468 | Attributes attrs = manifest.getMainAttributes(); |
| | 469 | String groupId = attrs.getValue("Implementation-Vendor-Id"); |
| | 470 | String version = attrs.getValue("Implementation-Version"); |
| | 471 | if (groupId != null && version != null) { |
| | 472 | int endInd = jarFileName.indexOf(version); |
| | 473 | if (endInd > 2) { |
| | 474 | String artifactId = jarFileName.substring(0, endInd - 1); |
| | 475 | String entryKey = groupId + "+" + artifactId + "+" + version; |
| | 476 | entry = jarEntries.get(entryKey); |
| | 477 | if (entry != null) { |
| | 478 | for (File dir : entry.directories) { |
| | 479 | if (LOG.isDebugEnabled()) { |
| | 480 | LOG.debug("Found live module location by artifact name and MANIFEST attributes: " |
| | 481 | + entryKey); |
| | 482 | } |
| | 483 | rootToLocation.put(url.toString(), dir); |
| | 484 | return dir; |
| 489 | | } |
| 490 | | } catch (FileNotFoundException x) { |
| 491 | | LOG.warn("Module contains no MANIFEST.MF: " + jarUrl.toString()); |
| 492 | | } catch (MalformedURLException x) { |
| 493 | | LOG.warn("Illegal module URL: " + jarUrl.toString(), x); |
| 494 | | } catch (IOException x) { |
| 495 | | LOG.warn("IO error reading module data: " + jarUrl.toString(), x); |
| 496 | | } |
| | 491 | } catch (FileNotFoundException x) { |
| | 492 | LOG.warn("Module contains no MANIFEST.MF: " + url.toString()); |
| | 493 | } catch (MalformedURLException x) { |
| | 494 | LOG.warn("Illegal module URL: " + url.toString(), x); |
| | 495 | } catch (IOException x) { |
| | 496 | LOG.warn("IO error reading module data: " + url.toString(), x); |
| | 497 | } |
| | 498 | } else if (url.getProtocol().equals("file")) { |
| | 499 | // find pom.xml, retrieve groupId, artifactId, version from pom.xml |
| | 500 | try { |
| | 501 | File pomFile = guessPom(url.getFile()); |
| | 502 | if (pomFile != null) { |
| | 503 | if (LOG.isDebugEnabled()) { |
| | 504 | LOG.debug("Found pom.xml: " + pomFile); |
| | 505 | } |
| | 506 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| | 507 | factory.setNamespaceAware(true); |
| | 508 | DocumentBuilder builder = factory.newDocumentBuilder(); |
| | 509 | Document document = builder.parse(pomFile); |
| | 510 | Element root = document.getDocumentElement(); |
| | 511 | Element groupElem = getSingleChildElement(root, "groupId", true); |
| | 512 | String groupId = groupElem.getTextContent().trim(); |
| | 513 | Element artifactElem = getSingleChildElement(root, "artifactId", true); |
| | 514 | String artifactId = artifactElem.getTextContent().trim(); |
| | 515 | Element versionElem = getSingleChildElement(root, "version", true); |
| | 516 | String version = versionElem.getTextContent().trim(); |
| | 517 | String entryKey = groupId + "+" + artifactId + "+" + version; |
| | 518 | |
| | 519 | Entry jarEntry = jarEntries.get(entryKey); |
| | 520 | if (jarEntry != null) { |
| | 521 | for (File dir : jarEntry.directories) { |
| | 522 | if (LOG.isDebugEnabled()) { |
| | 523 | LOG.debug("Found live module location by pom.xml: " + entryKey); |
| | 524 | } |
| | 525 | rootToLocation.put(url.toString(), dir); |
| | 526 | return dir; |
| | 527 | } |
| | 528 | } |
| | 529 | } |
| | 530 | } catch (Exception e) { |
| | 531 | LOG.warn("Exceptions reading module live POM: " + url.toString(), e); |
| | 532 | } |
| | 533 | } |
| | 534 | |