< prev index next >

langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.jdeps;
  27 
  28 import static com.sun.tools.jdeps.JdepsConfiguration.*;
  29 
  30 import com.sun.tools.classfile.Dependency.Location;


  31 import java.io.IOException;


  32 import java.io.UncheckedIOException;
  33 import java.util.Collections;
  34 import java.util.Comparator;
  35 import java.util.HashMap;
  36 import java.util.HashSet;
  37 import java.util.Map;
  38 import java.util.MissingResourceException;
  39 import java.util.Objects;
  40 import java.util.Optional;
  41 import java.util.ResourceBundle;
  42 import java.util.Set;
  43 import java.util.stream.Collectors;
  44 import java.util.stream.Stream;
  45 
  46 /**
  47  * Dependency Analyzer.
  48  */
  49 public class Analyzer {
  50     /**
  51      * Type of the dependency analysis.  Appropriate level of data
  52      * will be stored.
  53      */
  54     public enum Type {
  55         SUMMARY,
  56         MODULE,  // equivalent to summary in addition, print module descriptor
  57         PACKAGE,
  58         CLASS,
  59         VERBOSE
  60     }
  61 


 352                         this.targetArchive == d.targetArchive;
 353             }
 354             return false;
 355         }
 356 
 357         @Override
 358         public int hashCode() {
 359             return Objects.hash(this.origin,
 360                                 this.originArchive,
 361                                 this.target,
 362                                 this.targetArchive);
 363         }
 364 
 365         public String toString() {
 366             return String.format("%s (%s) -> %s (%s)%n",
 367                     origin, originArchive.getName(),
 368                     target, targetArchive.getName());
 369         }
 370     }
 371 
 372     static final JdkInternals REMOVED_JDK_INTERNALS = new JdkInternals();
 373 
 374     static class JdkInternals extends Module {
 375         private final String BUNDLE = "com.sun.tools.jdeps.resources.jdkinternals";
 376 
 377         private final Set<String> jdkinternals;
 378         private final Set<String> jdkUnsupportedClasses;
 379         private JdkInternals() {
 380             super("JDK removed internal API");
 381 
 382             try {
 383                 ResourceBundle rb = ResourceBundle.getBundle(BUNDLE);
 384                 this.jdkinternals = rb.keySet();
 385             } catch (MissingResourceException e) {
 386                 throw new InternalError("Cannot find jdkinternals resource bundle");

 387             }
 388 
 389             this.jdkUnsupportedClasses = getUnsupportedClasses();
 390         }
 391 
 392         public boolean contains(Location location) {
 393             if (jdkUnsupportedClasses.contains(location.getName() + ".class")) {
 394                 return false;
 395             }
 396 
 397             String cn = location.getClassName();
 398             int i = cn.lastIndexOf('.');
 399             String pn = i > 0 ? cn.substring(0, i) : "";
 400             return jdkinternals.contains(cn) || jdkinternals.contains(pn);





 401         }
 402 
 403         @Override
 404         public String name() {
 405             return getName();
 406         }
 407 
 408         @Override
 409         public boolean isJDK() {
 410             return true;
 411         }
 412 
 413         @Override
 414         public boolean isExported(String pn) {
 415             return false;
 416         }
 417 
 418         private Set<String> getUnsupportedClasses() {
 419             // jdk.unsupported may not be observable
 420             Optional<Module> om = Profile.FULL_JRE.findModule(JDK_UNSUPPORTED);
 421             if (om.isPresent()) {
 422                 return om.get().reader().entries();
 423             }
 424 
 425             // find from local run-time image
 426             SystemModuleFinder system = new SystemModuleFinder();
 427             if (system.find(JDK_UNSUPPORTED).isPresent()) {
 428                 try {
 429                     return system.getClassReader(JDK_UNSUPPORTED).entries();
 430                 } catch (IOException e) {
 431                     throw new UncheckedIOException(e);
 432                 }
 433             }
 434 
 435             return Collections.emptySet();
 436         }
 437     }
 438 }


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.jdeps;
  27 


  28 import com.sun.tools.classfile.Dependency.Location;
  29 
  30 import java.io.BufferedReader;
  31 import java.io.IOException;
  32 import java.io.InputStream;
  33 import java.io.InputStreamReader;
  34 import java.io.UncheckedIOException;
  35 import java.util.Collections;
  36 import java.util.Comparator;
  37 import java.util.HashMap;
  38 import java.util.HashSet;
  39 import java.util.Map;

  40 import java.util.Objects;


  41 import java.util.Set;
  42 import java.util.stream.Collectors;
  43 import java.util.stream.Stream;
  44 
  45 /**
  46  * Dependency Analyzer.
  47  */
  48 public class Analyzer {
  49     /**
  50      * Type of the dependency analysis.  Appropriate level of data
  51      * will be stored.
  52      */
  53     public enum Type {
  54         SUMMARY,
  55         MODULE,  // equivalent to summary in addition, print module descriptor
  56         PACKAGE,
  57         CLASS,
  58         VERBOSE
  59     }
  60 


 351                         this.targetArchive == d.targetArchive;
 352             }
 353             return false;
 354         }
 355 
 356         @Override
 357         public int hashCode() {
 358             return Objects.hash(this.origin,
 359                                 this.originArchive,
 360                                 this.target,
 361                                 this.targetArchive);
 362         }
 363 
 364         public String toString() {
 365             return String.format("%s (%s) -> %s (%s)%n",
 366                     origin, originArchive.getName(),
 367                     target, targetArchive.getName());
 368         }
 369     }
 370 
 371     static final Jdk8Internals REMOVED_JDK_INTERNALS = new Jdk8Internals();
 372 
 373     static class Jdk8Internals extends Module {
 374         private final String JDK8_INTERNALS = "/com/sun/tools/jdeps/resources/jdk8_internals.txt";
 375         private final Set<String> jdk8Internals;
 376         private Jdk8Internals() {


 377             super("JDK removed internal API");
 378             try (InputStream in = JdepsTask.class.getResourceAsStream(JDK8_INTERNALS);
 379                  BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
 380                 this.jdk8Internals = reader.lines()
 381                                           .filter(ln -> !ln.startsWith("#"))
 382                                           .collect(Collectors.toSet());
 383             } catch (IOException e) {
 384                 throw new UncheckedIOException(e);
 385             }


 386         }
 387 
 388         public boolean contains(Location location) {




 389             String cn = location.getClassName();
 390             int i = cn.lastIndexOf('.');
 391             String pn = i > 0 ? cn.substring(0, i) : "";
 392 
 393             if (!jdk8Internals.contains(pn)) {
 394                 return false;
 395             }
 396 
 397             return jdk8Internals.contains(pn);
 398         }
 399 
 400         @Override
 401         public String name() {
 402             return getName();
 403         }
 404 
 405         @Override
 406         public boolean isJDK() {
 407             return true;
 408         }
 409 
 410         @Override
 411         public boolean isExported(String pn) {
 412             return false;




















 413         }
 414     }
 415 }
< prev index next >