langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/BuildState.java
changeset 26107 a4a156a33c94
parent 26104 34de7e01b3c1
parent 25874 83c19f00452c
child 31115 8d8e98052d5d
equal deleted inserted replaced
25876:d06a6d3c66c0 26107:a4a156a33c94
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    29 import java.util.HashMap;
    29 import java.util.HashMap;
    30 import java.util.HashSet;
    30 import java.util.HashSet;
    31 import java.util.Map;
    31 import java.util.Map;
    32 import java.util.Set;
    32 import java.util.Set;
    33 
    33 
       
    34 import com.sun.tools.javac.util.Assert;
       
    35 
    34 /**
    36 /**
    35  * The build state class captures the source code and generated artifacts
    37  * The build state class captures the source code and generated artifacts
    36  * from a build. There are usually two build states, the previous one (prev),
    38  * from a build. There are usually two build states, the previous one (prev),
    37  * loaded from the javac_state file, and the current one (now).
    39  * loaded from the javac_state file, and the current one (now).
    38  *
    40  *
    39  * <p><b>This is NOT part of any supported API.
    41  *  <p><b>This is NOT part of any supported API.
    40  * If you write code that depends on this, you do so at your own
    42  *  If you write code that depends on this, you do so at your own risk.
    41  * risk.  This code and its internal interfaces are subject to change
    43  *  This code and its internal interfaces are subject to change or
    42  * or deletion without notice.</b></p>
    44  *  deletion without notice.</b>
    43  */
    45  */
    44 public class BuildState {
    46 public class BuildState {
    45     private Map<String,Module> modules = new HashMap<>();
    47     private Map<String,Module> modules = new HashMap<>();
    46     private Map<String,Package> packages = new HashMap<>();
    48     private Map<String,Package> packages = new HashMap<>();
    47     private Map<String,Source> sources = new HashMap<>();
    49     private Map<String,Source> sources = new HashMap<>();
    73      * The package name "base:java.lang" will fetch the module named "base".
    75      * The package name "base:java.lang" will fetch the module named "base".
    74      * The package name ":java.net" will fetch the default module.
    76      * The package name ":java.net" will fetch the default module.
    75      */
    77      */
    76     Module findModuleFromPackageName(String pkg) {
    78     Module findModuleFromPackageName(String pkg) {
    77         int cp = pkg.indexOf(':');
    79         int cp = pkg.indexOf(':');
    78         assert(cp != -1);
    80         Assert.check(cp != -1);
    79         String mod = pkg.substring(0, cp);
    81         String mod = pkg.substring(0, cp);
    80         return lookupModule(mod);
    82         return lookupModule(mod);
    81     }
    83     }
    82 
    84 
    83     /**
    85     /**
    92         // Extract all the found packages.
    94         // Extract all the found packages.
    93         for (Module i : modules.values()) {
    95         for (Module i : modules.values()) {
    94             for (Map.Entry<String,Package> j : i.packages().entrySet()) {
    96             for (Map.Entry<String,Package> j : i.packages().entrySet()) {
    95                 Package p = packages.get(j.getKey());
    97                 Package p = packages.get(j.getKey());
    96                 // Check that no two different packages are stored under same name.
    98                 // Check that no two different packages are stored under same name.
    97                 assert(p == null || p == j.getValue());
    99                 Assert.check(p == null || p == j.getValue());
    98                 if (p == null) {
   100                 if (p == null) {
    99                     p = j.getValue();
   101                     p = j.getValue();
   100                     packages.put(j.getKey(),j.getValue());
   102                     packages.put(j.getKey(),j.getValue());
   101                 }
   103                 }
   102                 for (Map.Entry<String,Source> k : p.sources().entrySet()) {
   104                 for (Map.Entry<String,Source> k : p.sources().entrySet()) {
   103                     Source s = sources.get(k.getKey());
   105                     Source s = sources.get(k.getKey());
   104                     // Check that no two different sources are stored under same name.
   106                     // Check that no two different sources are stored under same name.
   105                     assert(s == null || s == k.getValue());
   107                     Assert.check(s == null || s == k.getValue());
   106                     if (s == null) {
   108                     if (s == null) {
   107                         s = k.getValue();
   109                         s = k.getValue();
   108                         sources.put(k.getKey(), k.getValue());
   110                         sources.put(k.getKey(), k.getValue());
   109                     }
   111                     }
   110                 }
   112                 }
   111                 for (Map.Entry<String,File> g : p.artifacts().entrySet()) {
   113                 for (Map.Entry<String,File> g : p.artifacts().entrySet()) {
   112                     File f = artifacts.get(g.getKey());
   114                     File f = artifacts.get(g.getKey());
   113                     // Check that no two artifacts are stored under the same file.
   115                     // Check that no two artifacts are stored under the same file.
   114                     assert(f == null || f == g.getValue());
   116                     Assert.check(f == null || f == g.getValue());
   115                     if (f == null) {
   117                     if (f == null) {
   116                         f = g.getValue();
   118                         f = g.getValue();
   117                         artifacts.put(g.getKey(), g.getValue());
   119                         artifacts.put(g.getKey(), g.getValue());
   118                     }
   120                     }
   119                 }
   121                 }
   132         // Extract all the found packages.
   134         // Extract all the found packages.
   133         for (Module i : modules.values()) {
   135         for (Module i : modules.values()) {
   134             for (Map.Entry<String,Package> j : i.packages().entrySet()) {
   136             for (Map.Entry<String,Package> j : i.packages().entrySet()) {
   135                 Package p = packages.get(j.getKey());
   137                 Package p = packages.get(j.getKey());
   136                 // Check that no two different packages are stored under same name.
   138                 // Check that no two different packages are stored under same name.
   137                 assert(p == null || p == j.getValue());
   139                 Assert.check(p == null || p == j.getValue());
   138                 p = j.getValue();
   140                 p = j.getValue();
   139                 packages.put(j.getKey(),j.getValue());
   141                 packages.put(j.getKey(),j.getValue());
   140                 for (Map.Entry<String,File> g : p.artifacts().entrySet()) {
   142                 for (Map.Entry<String,File> g : p.artifacts().entrySet()) {
   141                     File f = artifacts.get(g.getKey());
   143                     File f = artifacts.get(g.getKey());
   142                     // Check that no two artifacts are stored under the same file.
   144                     // Check that no two artifacts are stored under the same file.
   143                     assert(f == null || f == g.getValue());
   145                     Assert.check(f == null || f == g.getValue());
   144                     artifacts.put(g.getKey(), g.getValue());
   146                     artifacts.put(g.getKey(), g.getValue());
   145                 }
   147                 }
   146             }
   148             }
   147         }
   149         }
   148     }
   150     }