529 .collect(Collectors.toSet());
530
531 // all packages are exported and open
532 builder.packages(packages);
533
534 // map names of service configuration files to service names
535 Set<String> serviceNames = configFiles.stream()
536 .map(this::toServiceName)
537 .flatMap(Optional::stream)
538 .collect(Collectors.toSet());
539
540 // parse each service configuration file
541 for (String sn : serviceNames) {
542 JarEntry entry = jf.getJarEntry(SERVICES_PREFIX + sn);
543 List<String> providerClasses = new ArrayList<>();
544 try (InputStream in = jf.getInputStream(entry)) {
545 BufferedReader reader
546 = new BufferedReader(new InputStreamReader(in, "UTF-8"));
547 String cn;
548 while ((cn = nextLine(reader)) != null) {
549 if (cn.length() > 0) {
550 String pn = packageName(cn);
551 if (!packages.contains(pn)) {
552 String msg = "Provider class " + cn + " not in module";
553 throw new InvalidModuleDescriptorException(msg);
554 }
555 providerClasses.add(cn);
556 }
557 }
558 }
559 if (!providerClasses.isEmpty())
560 builder.provides(sn, providerClasses);
561 }
562
563 // Main-Class attribute if it exists
564 if (attrs != null) {
565 String mainClass = attrs.getValue(Attributes.Name.MAIN_CLASS);
566 if (mainClass != null) {
567 mainClass = mainClass.replace("/", ".");
568 if (Checks.isClassName(mainClass)) {
569 String pn = packageName(mainClass);
582 */
583 private static class Patterns {
584 static final Pattern DASH_VERSION = Pattern.compile("-(\\d+(\\.|$))");
585 static final Pattern NON_ALPHANUM = Pattern.compile("[^A-Za-z0-9]");
586 static final Pattern REPEATING_DOTS = Pattern.compile("(\\.)(\\1)+");
587 static final Pattern LEADING_DOTS = Pattern.compile("^\\.");
588 static final Pattern TRAILING_DOTS = Pattern.compile("\\.$");
589 }
590
591 /**
592 * Clean up candidate module name derived from a JAR file name.
593 */
594 private static String cleanModuleName(String mn) {
595 // replace non-alphanumeric
596 mn = Patterns.NON_ALPHANUM.matcher(mn).replaceAll(".");
597
598 // collapse repeating dots
599 mn = Patterns.REPEATING_DOTS.matcher(mn).replaceAll(".");
600
601 // drop leading dots
602 if (mn.length() > 0 && mn.charAt(0) == '.')
603 mn = Patterns.LEADING_DOTS.matcher(mn).replaceAll("");
604
605 // drop trailing dots
606 int len = mn.length();
607 if (len > 0 && mn.charAt(len-1) == '.')
608 mn = Patterns.TRAILING_DOTS.matcher(mn).replaceAll("");
609
610 return mn;
611 }
612
613 private Set<String> jarPackages(JarFile jf) {
614 return jf.versionedStream()
615 .filter(e -> !e.isDirectory())
616 .map(JarEntry::getName)
617 .map(this::toPackageName)
618 .flatMap(Optional::stream)
619 .collect(Collectors.toSet());
620 }
621
622 /**
|
529 .collect(Collectors.toSet());
530
531 // all packages are exported and open
532 builder.packages(packages);
533
534 // map names of service configuration files to service names
535 Set<String> serviceNames = configFiles.stream()
536 .map(this::toServiceName)
537 .flatMap(Optional::stream)
538 .collect(Collectors.toSet());
539
540 // parse each service configuration file
541 for (String sn : serviceNames) {
542 JarEntry entry = jf.getJarEntry(SERVICES_PREFIX + sn);
543 List<String> providerClasses = new ArrayList<>();
544 try (InputStream in = jf.getInputStream(entry)) {
545 BufferedReader reader
546 = new BufferedReader(new InputStreamReader(in, "UTF-8"));
547 String cn;
548 while ((cn = nextLine(reader)) != null) {
549 if (!cn.isEmpty()) {
550 String pn = packageName(cn);
551 if (!packages.contains(pn)) {
552 String msg = "Provider class " + cn + " not in module";
553 throw new InvalidModuleDescriptorException(msg);
554 }
555 providerClasses.add(cn);
556 }
557 }
558 }
559 if (!providerClasses.isEmpty())
560 builder.provides(sn, providerClasses);
561 }
562
563 // Main-Class attribute if it exists
564 if (attrs != null) {
565 String mainClass = attrs.getValue(Attributes.Name.MAIN_CLASS);
566 if (mainClass != null) {
567 mainClass = mainClass.replace("/", ".");
568 if (Checks.isClassName(mainClass)) {
569 String pn = packageName(mainClass);
582 */
583 private static class Patterns {
584 static final Pattern DASH_VERSION = Pattern.compile("-(\\d+(\\.|$))");
585 static final Pattern NON_ALPHANUM = Pattern.compile("[^A-Za-z0-9]");
586 static final Pattern REPEATING_DOTS = Pattern.compile("(\\.)(\\1)+");
587 static final Pattern LEADING_DOTS = Pattern.compile("^\\.");
588 static final Pattern TRAILING_DOTS = Pattern.compile("\\.$");
589 }
590
591 /**
592 * Clean up candidate module name derived from a JAR file name.
593 */
594 private static String cleanModuleName(String mn) {
595 // replace non-alphanumeric
596 mn = Patterns.NON_ALPHANUM.matcher(mn).replaceAll(".");
597
598 // collapse repeating dots
599 mn = Patterns.REPEATING_DOTS.matcher(mn).replaceAll(".");
600
601 // drop leading dots
602 if (!mn.isEmpty() && mn.charAt(0) == '.')
603 mn = Patterns.LEADING_DOTS.matcher(mn).replaceAll("");
604
605 // drop trailing dots
606 int len = mn.length();
607 if (len > 0 && mn.charAt(len-1) == '.')
608 mn = Patterns.TRAILING_DOTS.matcher(mn).replaceAll("");
609
610 return mn;
611 }
612
613 private Set<String> jarPackages(JarFile jf) {
614 return jf.versionedStream()
615 .filter(e -> !e.isDirectory())
616 .map(JarEntry::getName)
617 .map(this::toPackageName)
618 .flatMap(Optional::stream)
619 .collect(Collectors.toSet());
620 }
621
622 /**
|