< prev index next >

src/java.base/share/classes/jdk/internal/module/ModulePath.java

Print this page
rev 51919 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: dfuchs, alanb


 530                 .collect(Collectors.toSet());
 531 
 532         // all packages are exported and open
 533         builder.packages(packages);
 534 
 535         // map names of service configuration files to service names
 536         Set<String> serviceNames = configFiles.stream()
 537                 .map(this::toServiceName)
 538                 .flatMap(Optional::stream)
 539                 .collect(Collectors.toSet());
 540 
 541         // parse each service configuration file
 542         for (String sn : serviceNames) {
 543             JarEntry entry = jf.getJarEntry(SERVICES_PREFIX + sn);
 544             List<String> providerClasses = new ArrayList<>();
 545             try (InputStream in = jf.getInputStream(entry)) {
 546                 BufferedReader reader
 547                     = new BufferedReader(new InputStreamReader(in, "UTF-8"));
 548                 String cn;
 549                 while ((cn = nextLine(reader)) != null) {
 550                     if (cn.length() > 0) {
 551                         String pn = packageName(cn);
 552                         if (!packages.contains(pn)) {
 553                             String msg = "Provider class " + cn + " not in module";
 554                             throw new InvalidModuleDescriptorException(msg);
 555                         }
 556                         providerClasses.add(cn);
 557                     }
 558                 }
 559             }
 560             if (!providerClasses.isEmpty())
 561                 builder.provides(sn, providerClasses);
 562         }
 563 
 564         // Main-Class attribute if it exists
 565         if (attrs != null) {
 566             String mainClass = attrs.getValue(Attributes.Name.MAIN_CLASS);
 567             if (mainClass != null) {
 568                 mainClass = mainClass.replace("/", ".");
 569                 if (Checks.isClassName(mainClass)) {
 570                     String pn = packageName(mainClass);


 583      */
 584     private static class Patterns {
 585         static final Pattern DASH_VERSION = Pattern.compile("-(\\d+(\\.|$))");
 586         static final Pattern NON_ALPHANUM = Pattern.compile("[^A-Za-z0-9]");
 587         static final Pattern REPEATING_DOTS = Pattern.compile("(\\.)(\\1)+");
 588         static final Pattern LEADING_DOTS = Pattern.compile("^\\.");
 589         static final Pattern TRAILING_DOTS = Pattern.compile("\\.$");
 590     }
 591 
 592     /**
 593      * Clean up candidate module name derived from a JAR file name.
 594      */
 595     private static String cleanModuleName(String mn) {
 596         // replace non-alphanumeric
 597         mn = Patterns.NON_ALPHANUM.matcher(mn).replaceAll(".");
 598 
 599         // collapse repeating dots
 600         mn = Patterns.REPEATING_DOTS.matcher(mn).replaceAll(".");
 601 
 602         // drop leading dots
 603         if (mn.length() > 0 && mn.charAt(0) == '.')
 604             mn = Patterns.LEADING_DOTS.matcher(mn).replaceAll("");
 605 
 606         // drop trailing dots
 607         int len = mn.length();
 608         if (len > 0 && mn.charAt(len-1) == '.')
 609             mn = Patterns.TRAILING_DOTS.matcher(mn).replaceAll("");
 610 
 611         return mn;
 612     }
 613 
 614     private Set<String> jarPackages(JarFile jf) {
 615         return jf.versionedStream()
 616                 .filter(e -> !e.isDirectory())
 617                 .map(JarEntry::getName)
 618                 .map(this::toPackageName)
 619                 .flatMap(Optional::stream)
 620                 .collect(Collectors.toSet());
 621     }
 622 
 623     /**




 530                 .collect(Collectors.toSet());
 531 
 532         // all packages are exported and open
 533         builder.packages(packages);
 534 
 535         // map names of service configuration files to service names
 536         Set<String> serviceNames = configFiles.stream()
 537                 .map(this::toServiceName)
 538                 .flatMap(Optional::stream)
 539                 .collect(Collectors.toSet());
 540 
 541         // parse each service configuration file
 542         for (String sn : serviceNames) {
 543             JarEntry entry = jf.getJarEntry(SERVICES_PREFIX + sn);
 544             List<String> providerClasses = new ArrayList<>();
 545             try (InputStream in = jf.getInputStream(entry)) {
 546                 BufferedReader reader
 547                     = new BufferedReader(new InputStreamReader(in, "UTF-8"));
 548                 String cn;
 549                 while ((cn = nextLine(reader)) != null) {
 550                     if (!cn.isEmpty()) {
 551                         String pn = packageName(cn);
 552                         if (!packages.contains(pn)) {
 553                             String msg = "Provider class " + cn + " not in module";
 554                             throw new InvalidModuleDescriptorException(msg);
 555                         }
 556                         providerClasses.add(cn);
 557                     }
 558                 }
 559             }
 560             if (!providerClasses.isEmpty())
 561                 builder.provides(sn, providerClasses);
 562         }
 563 
 564         // Main-Class attribute if it exists
 565         if (attrs != null) {
 566             String mainClass = attrs.getValue(Attributes.Name.MAIN_CLASS);
 567             if (mainClass != null) {
 568                 mainClass = mainClass.replace("/", ".");
 569                 if (Checks.isClassName(mainClass)) {
 570                     String pn = packageName(mainClass);


 583      */
 584     private static class Patterns {
 585         static final Pattern DASH_VERSION = Pattern.compile("-(\\d+(\\.|$))");
 586         static final Pattern NON_ALPHANUM = Pattern.compile("[^A-Za-z0-9]");
 587         static final Pattern REPEATING_DOTS = Pattern.compile("(\\.)(\\1)+");
 588         static final Pattern LEADING_DOTS = Pattern.compile("^\\.");
 589         static final Pattern TRAILING_DOTS = Pattern.compile("\\.$");
 590     }
 591 
 592     /**
 593      * Clean up candidate module name derived from a JAR file name.
 594      */
 595     private static String cleanModuleName(String mn) {
 596         // replace non-alphanumeric
 597         mn = Patterns.NON_ALPHANUM.matcher(mn).replaceAll(".");
 598 
 599         // collapse repeating dots
 600         mn = Patterns.REPEATING_DOTS.matcher(mn).replaceAll(".");
 601 
 602         // drop leading dots
 603         if (!mn.isEmpty() && mn.charAt(0) == '.')
 604             mn = Patterns.LEADING_DOTS.matcher(mn).replaceAll("");
 605 
 606         // drop trailing dots
 607         int len = mn.length();
 608         if (len > 0 && mn.charAt(len-1) == '.')
 609             mn = Patterns.TRAILING_DOTS.matcher(mn).replaceAll("");
 610 
 611         return mn;
 612     }
 613 
 614     private Set<String> jarPackages(JarFile jf) {
 615         return jf.versionedStream()
 616                 .filter(e -> !e.isDirectory())
 617                 .map(JarEntry::getName)
 618                 .map(this::toPackageName)
 619                 .flatMap(Optional::stream)
 620                 .collect(Collectors.toSet());
 621     }
 622 
 623     /**


< prev index next >