@@ -70,23 +70,24 @@ class PathModularization {
7070 * It may however contain more than one entry if module hierarchy was detected,
7171 * in which case there is one key per sub-directory.
7272 *
73+ * <p>Values are instances of either {@link ModuleDescriptor} or {@link String}.
74+ * The latter case happens when a JAR file has no {@code module-info.class} entry
75+ * but has an automatic name declared in {@code META-INF/MANIFEST.MF}.</p>
76+ *
7377 * <p>This map may contain null values if the constructor was invoked with {@code resolve}
7478 * parameter set to false. This is more efficient when only the module existence needs to
7579 * be tested, and module descriptors are not needed.</p>
76- *
77- * @see #getModuleNames()
7880 */
79- private final Map <Path , String > descriptors ;
81+ @ Nonnull
82+ final Map <Path , Object > descriptors ;
8083
8184 /**
8285 * Whether module hierarchy was detected. If false, then package hierarchy is assumed.
8386 * In a package hierarchy, the {@linkplain #descriptors} map has either zero or one entry.
8487 * In a module hierarchy, the descriptors map may have an arbitrary number of entries,
8588 * including one (so the map size cannot be used as a criterion).
86- *
87- * @see #isModuleHierarchy()
8889 */
89- private final boolean isModuleHierarchy ;
90+ final boolean isModuleHierarchy ;
9091
9192 /**
9293 * Constructs an empty instance for non-modular dependencies.
@@ -144,13 +145,13 @@ private PathModularization() {
144145 */
145146 Path file = path .resolve (MODULE_INFO );
146147 if (Files .isRegularFile (file )) {
147- String name = null ;
148+ ModuleDescriptor descriptor = null ;
148149 if (resolve ) {
149150 try (InputStream in = Files .newInputStream (file )) {
150- name = getModuleName (in );
151+ descriptor = ModuleDescriptor . read (in );
151152 }
152153 }
153- descriptors = Collections .singletonMap (file , name );
154+ descriptors = Collections .singletonMap (file , descriptor );
154155 isModuleHierarchy = false ;
155156 return ;
156157 }
@@ -160,27 +161,27 @@ private PathModularization() {
160161 * source files.
161162 */
162163 if (Files .isDirectory (file )) {
163- Map < Path , String > names = new HashMap <>();
164+ var multi = new HashMap <Path , ModuleDescriptor >();
164165 try (Stream <Path > subdirs = Files .list (file )) {
165166 subdirs .filter (Files ::isDirectory ).forEach ((subdir ) -> {
166167 Path mf = subdir .resolve (MODULE_INFO );
167168 if (Files .isRegularFile (mf )) {
168- String name = null ;
169+ ModuleDescriptor descriptor = null ;
169170 if (resolve ) {
170171 try (InputStream in = Files .newInputStream (mf )) {
171- name = getModuleName (in );
172+ descriptor = ModuleDescriptor . read (in );
172173 } catch (IOException e ) {
173174 throw new UncheckedIOException (e );
174175 }
175176 }
176- names .put (mf , name );
177+ multi .put (mf , descriptor );
177178 }
178179 });
179180 } catch (UncheckedIOException e ) {
180181 throw e .getCause ();
181182 }
182- if (!names .isEmpty ()) {
183- descriptors = Collections .unmodifiableMap (names );
183+ if (!multi .isEmpty ()) {
184+ descriptors = Collections .unmodifiableMap (multi );
184185 isModuleHierarchy = true ;
185186 return ;
186187 }
@@ -194,13 +195,13 @@ private PathModularization() {
194195 try (JarFile jar = new JarFile (path .toFile ())) {
195196 ZipEntry entry = jar .getEntry (MODULE_INFO );
196197 if (entry != null ) {
197- String name = null ;
198+ ModuleDescriptor descriptor = null ;
198199 if (resolve ) {
199200 try (InputStream in = jar .getInputStream (entry )) {
200- name = getModuleName (in );
201+ descriptor = ModuleDescriptor . read (in );
201202 }
202203 }
203- descriptors = Collections .singletonMap (path , name );
204+ descriptors = Collections .singletonMap (path , descriptor );
204205 isModuleHierarchy = false ;
205206 return ;
206207 }
@@ -209,7 +210,7 @@ private PathModularization() {
209210 if (mf != null ) {
210211 Object name = mf .getMainAttributes ().get (AUTO_MODULE_NAME );
211212 if (name instanceof String ) {
212- descriptors = Collections .singletonMap (path , ( String ) name );
213+ descriptors = Collections .singletonMap (path , name );
213214 isModuleHierarchy = false ;
214215 return ;
215216 }
@@ -220,15 +221,6 @@ private PathModularization() {
220221 isModuleHierarchy = false ;
221222 }
222223
223- /**
224- * {@return the module name declared in the given {@code module-info} descriptor}.
225- * The input stream may be for a file or for an entry in a JAR file.
226- */
227- @ Nonnull
228- private static String getModuleName (InputStream in ) throws IOException {
229- return ModuleDescriptor .read (in ).name ();
230- }
231-
232224 /**
233225 * {@return the type of path detected}. The return value is {@link JavaPathType#MODULES}
234226 * if the dependency is a modular JAR file or a directory containing module descriptor(s),
@@ -253,31 +245,6 @@ public void addIfFilenameBasedAutomodules(Collection<String> automodulesDetected
253245 }
254246 }
255247
256- /**
257- * {@return whether module hierarchy was detected}. If {@code false}, then package hierarchy is assumed.
258- * In a package hierarchy, the {@linkplain #getModuleNames()} map of modules has either zero or one entry.
259- * In a module hierarchy, the descriptors map may have an arbitrary number of entries,
260- * including one (so the map size cannot be used as a criterion).
261- */
262- public boolean isModuleHierarchy () {
263- return isModuleHierarchy ;
264- }
265-
266- /**
267- * {@return the module names for the path specified at construction time}.
268- * This map is usually either empty if no module was found, or a singleton map.
269- * It may however contain more than one entry if module hierarchy was detected,
270- * in which case there is one key per sub-directory.
271- *
272- * <p>This map may contain null values if the constructor was invoked with {@code resolve}
273- * parameter set to false. This is more efficient when only the module existence needs to
274- * be tested, and module descriptors are not needed.</p>
275- */
276- @ Nonnull
277- public Map <Path , String > getModuleNames () {
278- return descriptors ;
279- }
280-
281248 /**
282249 * {@return whether the dependency contains a module of the given name}.
283250 */
0 commit comments