< prev index next >

test/jdk/jdk/modules/etc/UpgradeableModules.java

Print this page


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  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  */


  26  * @summary Verify that upgradeable modules are not hashed in java.base
  27  *          whereas non-upgradeable modules are.
  28  * @modules java.base/jdk.internal.module
  29  * @run main UpgradeableModules
  30  */
  31 
  32 import jdk.internal.module.ModuleHashes;
  33 import jdk.internal.module.ModuleReferenceImpl;
  34 
  35 import java.lang.module.ModuleFinder;
  36 import java.lang.module.ModuleReference;
  37 import java.lang.module.ResolvedModule;
  38 import java.util.HashSet;
  39 import java.util.List;
  40 import java.util.Optional;
  41 import java.util.Set;
  42 import java.util.stream.Collectors;
  43 
  44 public class UpgradeableModules {
  45     private static final List<String> UPGRADEABLE_MODULES =
  46         List.of("java.activation",
  47                 "java.compiler",
  48                 "java.corba",
  49                 "java.jnlp",
  50                 "java.transaction",
  51                 "java.xml.bind",
  52                 "java.xml.ws",
  53                 "java.xml.ws.annotation",
  54                 "jdk.internal.vm.compiler",
  55                 "jdk.deploy",
  56                 "jdk.javaws",
  57                 "jdk.plugin",
  58                 "jdk.plugin.dom",
  59                 "jdk.xml.bind",
  60                 "jdk.xml.ws");
  61 
  62     public static void main(String... args) {
  63         Set<String> hashedModules = hashedModules();
  64         if (hashedModules.isEmpty())
  65             return;
  66 
  67         if (UPGRADEABLE_MODULES.stream().anyMatch(hashedModules::contains)) {
  68             throw new RuntimeException("upgradeable modules are hashed: " +
  69                 UPGRADEABLE_MODULES.stream()
  70                     .filter(hashedModules::contains)
  71                     .collect(Collectors.joining(" ")));
  72         }
  73 
  74         Set<String> nonUpgradeableModules =
  75             ModuleFinder.ofSystem().findAll().stream()
  76                 .map(mref -> mref.descriptor().name())
  77                 .filter(mn -> !UPGRADEABLE_MODULES.contains(mn))
  78                 .collect(Collectors.toSet());
  79 
  80         if (nonUpgradeableModules.stream().anyMatch(mn -> !hashedModules.contains(mn))) {


   1 /*
   2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  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  */


  26  * @summary Verify that upgradeable modules are not hashed in java.base
  27  *          whereas non-upgradeable modules are.
  28  * @modules java.base/jdk.internal.module
  29  * @run main UpgradeableModules
  30  */
  31 
  32 import jdk.internal.module.ModuleHashes;
  33 import jdk.internal.module.ModuleReferenceImpl;
  34 
  35 import java.lang.module.ModuleFinder;
  36 import java.lang.module.ModuleReference;
  37 import java.lang.module.ResolvedModule;
  38 import java.util.HashSet;
  39 import java.util.List;
  40 import java.util.Optional;
  41 import java.util.Set;
  42 import java.util.stream.Collectors;
  43 
  44 public class UpgradeableModules {
  45     private static final List<String> UPGRADEABLE_MODULES =
  46         List.of("java.compiler",


  47                 "java.jnlp",




  48                 "jdk.internal.vm.compiler",
  49                 "jdk.deploy",
  50                 "jdk.javaws",
  51                 "jdk.plugin",
  52                 "jdk.plugin.dom"
  53                 );

  54 
  55     public static void main(String... args) {
  56         Set<String> hashedModules = hashedModules();
  57         if (hashedModules.isEmpty())
  58             return;
  59 
  60         if (UPGRADEABLE_MODULES.stream().anyMatch(hashedModules::contains)) {
  61             throw new RuntimeException("upgradeable modules are hashed: " +
  62                 UPGRADEABLE_MODULES.stream()
  63                     .filter(hashedModules::contains)
  64                     .collect(Collectors.joining(" ")));
  65         }
  66 
  67         Set<String> nonUpgradeableModules =
  68             ModuleFinder.ofSystem().findAll().stream()
  69                 .map(mref -> mref.descriptor().name())
  70                 .filter(mn -> !UPGRADEABLE_MODULES.contains(mn))
  71                 .collect(Collectors.toSet());
  72 
  73         if (nonUpgradeableModules.stream().anyMatch(mn -> !hashedModules.contains(mn))) {


< prev index next >