< prev index next >

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

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 35,45 **** import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor.Builder; import java.lang.module.ModuleDescriptor.Requires; import java.lang.module.ModuleDescriptor.Exports; import java.lang.module.ModuleDescriptor.Opens; - import java.lang.module.ModuleDescriptor.Version; import java.nio.ByteBuffer; import java.nio.BufferUnderflowException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; --- 35,44 ----
*** 49,59 **** import java.util.Set; import java.util.function.Supplier; import jdk.internal.misc.JavaLangModuleAccess; import jdk.internal.misc.SharedSecrets; - import jdk.internal.module.ModuleResolution; import static jdk.internal.module.ClassFileConstants.*; /** --- 48,57 ----
*** 219,229 **** // the names of the attributes found in the class file Set<String> attributes = new HashSet<>(); Builder builder = null; ! Set<String> packages = null; String mainClass = null; String[] osValues = null; ModuleHashes hashes = null; ModuleResolution moduleResolution = null; --- 217,227 ---- // the names of the attributes found in the class file Set<String> attributes = new HashSet<>(); Builder builder = null; ! Set<String> allPackages = null; String mainClass = null; String[] osValues = null; ModuleHashes hashes = null; ModuleResolution moduleResolution = null;
*** 243,253 **** case MODULE : builder = readModuleAttribute(in, cpool); break; case MODULE_PACKAGES : ! packages = readModulePackagesAttribute(in, cpool); break; case MODULE_MAIN_CLASS : mainClass = readModuleMainClassAttribute(in, cpool); break; --- 241,251 ---- case MODULE : builder = readModuleAttribute(in, cpool); break; case MODULE_PACKAGES : ! allPackages = readModulePackagesAttribute(in, cpool); break; case MODULE_MAIN_CLASS : mainClass = readModuleMainClassAttribute(in, cpool); break;
*** 282,336 **** // the Module attribute is required if (builder == null) { throw invalidModuleDescriptor(MODULE + " attribute not found"); } // If the ModulePackages attribute is not present then the packageFinder // is used to find the set of packages boolean usedPackageFinder = false; ! if (packages == null && packageFinder != null) { try { ! packages = new HashSet<>(packageFinder.get()); } catch (UncheckedIOException x) { throw x.getCause(); } usedPackageFinder = true; } ! if (packages != null) { ! Set<String> exportedPackages = JLMA.exportedPackages(builder); ! Set<String> openPackages = JLMA.openPackages(builder); ! if (packages.containsAll(exportedPackages) ! && packages.containsAll(openPackages)) { ! packages.removeAll(exportedPackages); ! packages.removeAll(openPackages); ! } else { ! // the set of packages is not complete ! Set<String> exportedAndOpenPackages = new HashSet<>(); ! exportedAndOpenPackages.addAll(exportedPackages); ! exportedAndOpenPackages.addAll(openPackages); ! for (String pn : exportedAndOpenPackages) { ! if (!packages.contains(pn)) { String tail; if (usedPackageFinder) { ! tail = " not found by package finder"; } else { ! tail = " missing from ModulePackages attribute"; ! } ! throw invalidModuleDescriptor("Package " + pn + tail); ! } ! } ! assert false; // should not get here ! } ! builder.contains(packages); } ! if (mainClass != null) ! builder.mainClass(mainClass); ! if (osValues != null) { ! if (osValues[0] != null) builder.osName(osValues[0]); ! if (osValues[1] != null) builder.osArch(osValues[1]); ! if (osValues[2] != null) builder.osVersion(osValues[2]); } ModuleDescriptor descriptor = builder.build(); return new Attributes(descriptor, hashes, moduleResolution); } --- 280,327 ---- // the Module attribute is required if (builder == null) { throw invalidModuleDescriptor(MODULE + " attribute not found"); } + // ModuleMainClass and ModuleTarget attributes + if (mainClass != null) { + builder.mainClass(mainClass); + } + if (osValues != null) { + if (osValues[0] != null) builder.osName(osValues[0]); + if (osValues[1] != null) builder.osArch(osValues[1]); + if (osValues[2] != null) builder.osVersion(osValues[2]); + } + // If the ModulePackages attribute is not present then the packageFinder // is used to find the set of packages boolean usedPackageFinder = false; ! if (allPackages == null && packageFinder != null) { try { ! allPackages = packageFinder.get(); } catch (UncheckedIOException x) { throw x.getCause(); } usedPackageFinder = true; } ! if (allPackages != null) { ! Set<String> knownPackages = JLMA.packages(builder); ! if (!allPackages.containsAll(knownPackages)) { ! Set<String> missingPackages = new HashSet<>(knownPackages); ! missingPackages.removeAll(allPackages); ! assert !missingPackages.isEmpty(); ! String missingPackage = missingPackages.iterator().next(); String tail; if (usedPackageFinder) { ! tail = " not found in module"; } else { ! tail = " missing from ModulePackages class file attribute"; } + throw invalidModuleDescriptor("Package " + missingPackage + tail); ! } ! builder.packages(allPackages); } ModuleDescriptor descriptor = builder.build(); return new Attributes(descriptor, hashes, moduleResolution); }
*** 345,358 **** // module_name int module_name_index = in.readUnsignedShort(); String mn = cpool.getModuleName(module_name_index); int module_flags = in.readUnsignedShort(); boolean open = ((module_flags & ACC_OPEN) != 0); ! boolean synthetic = ((module_flags & ACC_SYNTHETIC) != 0); ! Builder builder = JLMA.newModuleBuilder(mn, false, open, synthetic); int module_version_index = in.readUnsignedShort(); if (module_version_index != 0) { String vs = cpool.getUtf8(module_version_index); builder.version(vs); --- 336,356 ---- // module_name int module_name_index = in.readUnsignedShort(); String mn = cpool.getModuleName(module_name_index); int module_flags = in.readUnsignedShort(); + + Set<ModuleDescriptor.Modifier> modifiers = new HashSet<>(); boolean open = ((module_flags & ACC_OPEN) != 0); ! if (open) ! modifiers.add(ModuleDescriptor.Modifier.OPEN); ! if ((module_flags & ACC_SYNTHETIC) != 0) ! modifiers.add(ModuleDescriptor.Modifier.SYNTHETIC); ! if ((module_flags & ACC_MANDATED) != 0) ! modifiers.add(ModuleDescriptor.Modifier.MANDATED); ! Builder builder = JLMA.newModuleBuilder(mn, false, modifiers); int module_version_index = in.readUnsignedShort(); if (module_version_index != 0) { String vs = cpool.getUtf8(module_version_index); builder.version(vs);
*** 379,398 **** if ((requires_flags & ACC_MANDATED) != 0) mods.add(Requires.Modifier.MANDATED); } int requires_version_index = in.readUnsignedShort(); ! Version compiledVersion = null; ! if (requires_version_index != 0) { ! String vs = cpool.getUtf8(requires_version_index); ! compiledVersion = Version.parse(vs); ! } ! ! if (compiledVersion == null) { builder.requires(mods, dn); } else { ! builder.requires(mods, dn, compiledVersion); } if (dn.equals("java.base")) requiresJavaBase = true; } --- 377,391 ---- if ((requires_flags & ACC_MANDATED) != 0) mods.add(Requires.Modifier.MANDATED); } int requires_version_index = in.readUnsignedShort(); ! if (requires_version_index == 0) { builder.requires(mods, dn); } else { ! String vs = cpool.getUtf8(requires_version_index); ! JLMA.requires(builder, mods, dn, vs); } if (dn.equals("java.base")) requiresJavaBase = true; }
*** 627,647 **** return false; } /** * Return true if the given attribute name is the name of a pre-defined ! * attribute that is not allowed in the class file. ! * ! * Except for Module, InnerClasses, SourceFile, SourceDebugExtension, and ! * Deprecated, none of the pre-defined attributes in JVMS 4.7 may appear. */ private static boolean isAttributeDisallowed(String name) { Set<String> notAllowed = predefinedNotAllowed; if (notAllowed == null) { notAllowed = Set.of( "ConstantValue", "Code", "StackMapTable", "Exceptions", "EnclosingMethod", "Signature", "LineNumberTable", --- 620,638 ---- return false; } /** * Return true if the given attribute name is the name of a pre-defined ! * attribute in JVMS 4.7 that is not allowed in a module-info class. */ private static boolean isAttributeDisallowed(String name) { Set<String> notAllowed = predefinedNotAllowed; if (notAllowed == null) { notAllowed = Set.of( "ConstantValue", "Code", + "Deprecated", "StackMapTable", "Exceptions", "EnclosingMethod", "Signature", "LineNumberTable",
< prev index next >