make/tools/classanalyzer/src/com/sun/classanalyzer/ModuleConfig.java

Print this page




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package com.sun.classanalyzer;
  24 
  25 import java.io.BufferedReader;
  26 import java.io.FileInputStream;
  27 import java.io.IOException;
  28 import java.io.InputStreamReader;
  29 import java.util.ArrayList;
  30 import java.util.Collection;
  31 import java.util.LinkedList;
  32 import java.util.List;
  33 import java.util.Set;
  34 import java.util.TreeSet;
  35 import java.util.regex.Pattern;
  36 
  37 import com.sun.classanalyzer.Module.RequiresModule;
  38 import java.util.LinkedHashMap;
  39 import java.util.Map;

  40 
  41 /**
  42  *
  43  * @author Mandy Chung
  44  */
  45 public class ModuleConfig {
  46 
  47     private final Set<String> roots;
  48     private final Set<String> includes;
  49     private final Set<String> permits;
  50     private final Map<String, RequiresModule> requires;
  51     private final Filter filter;
  52     private List<String> members;
  53     private String mainClass;
  54     final String module;
  55 
  56     ModuleConfig(String name) throws IOException {
  57         this(name, null);
  58     }
  59 
  60     ModuleConfig(String name, String mainClass) throws IOException {
  61         this.module = name;
  62         this.roots = new TreeSet<String>();
  63         this.includes = new TreeSet<String>();
  64         this.permits = new TreeSet<String>();
  65         this.requires = new LinkedHashMap<String, RequiresModule>();
  66         this.filter = new Filter(this);
  67         this.mainClass = mainClass;
  68     }
  69 
  70     List<String> members() {
  71         if (members == null) {
  72             members = new LinkedList<String>();
  73 
  74             for (String s : includes) {
  75                 if (!s.contains("*") && Module.findModule(s) != null) {
  76                     // module member
  77                     members.add(s);
  78                 }
  79             }
  80         }
  81         return members;
  82     }
  83 
  84     Set<String> permits() {
  85         return permits;
  86     }
  87 
  88     Collection<RequiresModule> requires() {
  89         return requires.values();
  90     }
  91 














  92     String mainClass() {
  93         return mainClass;
  94     }
  95 
  96     boolean matchesRoot(String name) {
  97         for (String pattern : roots) {
  98             if (matches(name, pattern)) {
  99                 return true;
 100             }
 101         }
 102         return false;
 103     }
 104 
 105     boolean matchesIncludes(String name) {
 106         for (String pattern : includes) {
 107             if (matches(name, pattern)) {
 108                 return true;
 109             }
 110         }
 111         return false;


 547                         if (inRoots) {
 548                             config.roots.add(s);
 549                         } else if (inIncludes) {
 550                             config.includes.add(s);
 551                         } else if (inExcludes) {
 552                             config.filter.exclude(s);
 553                         } else if (inAllows) {
 554                             config.filter.allow(s);
 555                         } else if (inPermits) {
 556                             config.permits.add(s);
 557                         } else if (inRequires) {
 558                             if (config.requires.containsKey(s)) {
 559                                 throw new RuntimeException(file + ", line " +
 560                                     lineNumber + " duplicated requires: \"" + s + "\"");
 561                             }
 562                             boolean isBootModule = s.equals("jdk.boot");
 563                             if (!local && isBootModule) {
 564                                 throw new RuntimeException(file + ", line " +
 565                                     lineNumber + " requires: \"" + s + "\" must be local");
 566                             }
 567                             RequiresModule rm = new RequiresModule(s, optional, reexport, local);
 568                             config.requires.put(s, rm);
 569                         }
 570                     }
 571                 }
 572                 if (lastchar == ';') {
 573                     inRoots = false;
 574                     inIncludes = false;
 575                     inExcludes = false;
 576                     inAllows = false;
 577                     inPermits = false;
 578                     inRequires = false;
 579                 }
 580             }
 581 
 582             if (inBlockComment) {
 583                 throw new RuntimeException(file + ", line " +
 584                         lineNumber + ", missing \"*/\" to end a block comment");
 585             }
 586             if (config != null) {
 587                 throw new RuntimeException(file + ", line " +
 588                         lineNumber + ", missing \"}\" to end module definition" +


 611             } else if (count++ > 0) {
 612                 sb.append(", ");
 613             }
 614             sb.append(s);
 615         }
 616         if (count > 0) {
 617             sb.append(";\n");
 618         }
 619         return sb.toString();
 620     }
 621 
 622     @Override
 623     public String toString() {
 624         StringBuilder sb = new StringBuilder();
 625         sb.append("module " + module).append(" {\n");
 626         sb.append(format("include", includes));
 627         sb.append(format("root", roots));
 628         sb.append(format("allow", filter.allow));
 629         sb.append(format("exclude", filter.exclude));
 630         Set<String> reqs = new TreeSet<String>();
 631         for (RequiresModule rm : requires.values()) {
 632             reqs.add(rm.toString());
 633         }
 634         sb.append(format("requires", reqs));
 635         sb.append(format("permits", permits));
 636         sb.append("}\n");
 637         return sb.toString();
 638     }
 639 }


  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package com.sun.classanalyzer;
  24 
  25 import java.io.BufferedReader;
  26 import java.io.FileInputStream;
  27 import java.io.IOException;
  28 import java.io.InputStreamReader;
  29 import java.util.ArrayList;
  30 import java.util.Collection;
  31 import java.util.LinkedList;
  32 import java.util.List;
  33 import java.util.Set;
  34 import java.util.TreeSet;
  35 import java.util.regex.Pattern;
  36 import java.util.EnumSet;

  37 import java.util.LinkedHashMap;
  38 import java.util.Map;
  39 import com.sun.classanalyzer.ModuleInfo.Dependence;
  40 
  41 /**
  42  *
  43  * @author Mandy Chung
  44  */
  45 public class ModuleConfig {
  46 
  47     private final Set<String> roots;
  48     protected final Set<String> includes;
  49     protected final Set<String> permits;
  50     protected final Map<String, Dependence> requires;
  51     private final Filter filter;
  52     private List<String> members;
  53     private String mainClass;
  54     final String module;
  55 
  56     ModuleConfig(String name) throws IOException {
  57         this(name, null);
  58     }
  59 
  60     ModuleConfig(String name, String mainClass) throws IOException {
  61         this.module = name;
  62         this.roots = new TreeSet<String>();
  63         this.includes = new TreeSet<String>();
  64         this.permits = new TreeSet<String>();
  65         this.requires = new LinkedHashMap<String, Dependence>();
  66         this.filter = new Filter(this);
  67         this.mainClass = mainClass;
  68     }
  69 
  70     List<String> members() {
  71         if (members == null) {
  72             members = new LinkedList<String>();
  73 
  74             for (String s : includes) {
  75                 if (!s.contains("*") && Module.findModule(s) != null) {
  76                     // module member
  77                     members.add(s);
  78                 }
  79             }
  80         }
  81         return members;
  82     }
  83 
  84     Set<String> permits() {
  85         return permits;
  86     }
  87 
  88     Collection<Dependence> requires() {
  89         return requires.values();
  90     }
  91 
  92     void export(Module m) {
  93         Dependence d = requires.get(m.name());
  94         if (d == null) {
  95             d = new Dependence(m, EnumSet.of(Dependence.Modifier.PUBLIC));
  96         } else if (!d.isPublic()){
  97             throw new RuntimeException(module + " should require public " + m.name());
  98         }
  99         requires.put(m.name(), d);
 100     }
 101 
 102     void addPermit(Module m) {
 103         permits.add(m.name());
 104     }
 105 
 106     String mainClass() {
 107         return mainClass;
 108     }
 109 
 110     boolean matchesRoot(String name) {
 111         for (String pattern : roots) {
 112             if (matches(name, pattern)) {
 113                 return true;
 114             }
 115         }
 116         return false;
 117     }
 118 
 119     boolean matchesIncludes(String name) {
 120         for (String pattern : includes) {
 121             if (matches(name, pattern)) {
 122                 return true;
 123             }
 124         }
 125         return false;


 561                         if (inRoots) {
 562                             config.roots.add(s);
 563                         } else if (inIncludes) {
 564                             config.includes.add(s);
 565                         } else if (inExcludes) {
 566                             config.filter.exclude(s);
 567                         } else if (inAllows) {
 568                             config.filter.allow(s);
 569                         } else if (inPermits) {
 570                             config.permits.add(s);
 571                         } else if (inRequires) {
 572                             if (config.requires.containsKey(s)) {
 573                                 throw new RuntimeException(file + ", line " +
 574                                     lineNumber + " duplicated requires: \"" + s + "\"");
 575                             }
 576                             boolean isBootModule = s.equals("jdk.boot");
 577                             if (!local && isBootModule) {
 578                                 throw new RuntimeException(file + ", line " +
 579                                     lineNumber + " requires: \"" + s + "\" must be local");
 580                             }
 581                             Dependence d = new Dependence(s, optional, reexport, local);
 582                             config.requires.put(s, d);
 583                         }
 584                     }
 585                 }
 586                 if (lastchar == ';') {
 587                     inRoots = false;
 588                     inIncludes = false;
 589                     inExcludes = false;
 590                     inAllows = false;
 591                     inPermits = false;
 592                     inRequires = false;
 593                 }
 594             }
 595 
 596             if (inBlockComment) {
 597                 throw new RuntimeException(file + ", line " +
 598                         lineNumber + ", missing \"*/\" to end a block comment");
 599             }
 600             if (config != null) {
 601                 throw new RuntimeException(file + ", line " +
 602                         lineNumber + ", missing \"}\" to end module definition" +


 625             } else if (count++ > 0) {
 626                 sb.append(", ");
 627             }
 628             sb.append(s);
 629         }
 630         if (count > 0) {
 631             sb.append(";\n");
 632         }
 633         return sb.toString();
 634     }
 635 
 636     @Override
 637     public String toString() {
 638         StringBuilder sb = new StringBuilder();
 639         sb.append("module " + module).append(" {\n");
 640         sb.append(format("include", includes));
 641         sb.append(format("root", roots));
 642         sb.append(format("allow", filter.allow));
 643         sb.append(format("exclude", filter.exclude));
 644         Set<String> reqs = new TreeSet<String>();
 645         for (Dependence rm : requires.values()) {
 646             reqs.add(rm.toString());
 647         }
 648         sb.append(format("requires", reqs));
 649         sb.append(format("permits", permits));
 650         sb.append("}\n");
 651         return sb.toString();
 652     }
 653 }