Skip to content

Commit 1fe1e81

Browse files
committed
Ignore JPMS when all modules are automatic
1 parent 5ebcc05 commit 1fe1e81

3 files changed

Lines changed: 93 additions & 15 deletions

File tree

xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/JavadocModule.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,22 @@
2525
*/
2626
class JavadocModule
2727
{
28-
private final String moduleName;
28+
private String moduleName;
29+
30+
private boolean isAutomatic;
31+
32+
private final Path artifactPath;
2933

3034
private final List<Path> sourcePaths;
3135

3236
private final List<Path> binaryPaths;
3337

34-
public JavadocModule( String moduleName, Path artifactPath, List<Path> sourcePaths, List<Path> dependencies )
38+
public JavadocModule( String moduleName, boolean isAutomatic, Path artifactPath, List<Path> sourcePaths,
39+
List<Path> dependencies )
3540
{
3641
this.moduleName = moduleName;
42+
this.isAutomatic = isAutomatic;
43+
this.artifactPath = artifactPath;
3744
this.sourcePaths = sourcePaths;
3845
binaryPaths = new ArrayList<>( Collections.singleton( artifactPath ) );
3946
binaryPaths.addAll( dependencies );
@@ -54,6 +61,11 @@ public boolean isNotModular()
5461
return moduleName == null;
5562
}
5663

64+
public boolean isAutomatic()
65+
{
66+
return isAutomatic;
67+
}
68+
5769
public List<Path> getSourcePaths()
5870
{
5971
return sourcePaths;
@@ -63,4 +75,17 @@ public List<Path> getClassPaths()
6375
{
6476
return binaryPaths;
6577
}
78+
79+
public JavadocModule demodularize()
80+
{
81+
return new JavadocModule( null, false, artifactPath, sourcePaths, binaryPaths );
82+
}
83+
84+
@Override
85+
public String toString()
86+
{
87+
String name = moduleName != null ? moduleName : "UNNAMED";
88+
String automatic = isAutomatic ? "automatic" : "non-automatic";
89+
return automatic + " module " + name + " at " + artifactPath;
90+
}
6691
}

xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/JavadocMojo.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ else if ( project.getBuild().getOutputDirectory() != null )
181181
// Ignore dependency resolution errors
182182
}
183183

184-
String moduleName = ignoreJPMS ? null : moduleGleaner.glean( artifactPath );
185-
186184
List<Path> sourcePaths = project.getCompileSourceRoots().stream() //
187185
.filter( Objects::nonNull ) //
188186
.map( Paths::get ) //
@@ -191,7 +189,9 @@ else if ( project.getBuild().getOutputDirectory() != null )
191189
.filter( Files::isDirectory ) //
192190
.collect( Collectors.toList() );
193191

194-
modules.add( new JavadocModule( moduleName, artifactPath, sourcePaths, dependencies ) );
192+
JavadocModule module = moduleGleaner.glean( artifactPath, sourcePaths, dependencies, ignoreJPMS );
193+
modules.add( module );
194+
logger.debug( "Gleaner found " + module );
195195
}
196196

197197
private List<JavadocModule> discoverModules()
@@ -212,6 +212,21 @@ private List<JavadocModule> discoverModules()
212212
}
213213
}
214214

215+
long nModular = modules.stream().filter( JavadocModule::isModular ).count();
216+
long nAutomatic = modules.stream().filter( JavadocModule::isAutomatic ).count();
217+
long nNonAutomatic = nModular - nAutomatic;
218+
if ( nAutomatic > 0 && nNonAutomatic > 0 )
219+
{
220+
logger.warn( "Found " + nNonAutomatic + " non-automacit modules (with module-info) and " + nAutomatic
221+
+ " automatic modules. Mixing automatic and non-automatic modules is not supported."
222+
+ " Javadoc is likely to fail. For more info see debug output." );
223+
}
224+
if ( nAutomatic == nModular )
225+
{
226+
logger.info( "All discovered modules are automatic modules, thus ignoring JPMS" );
227+
modules = modules.stream().map( JavadocModule::demodularize ).collect( Collectors.toList() );
228+
}
229+
215230
return modules;
216231
}
217232

xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/ModuleGleaner.java

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.InputStream;
2222
import java.nio.file.Files;
2323
import java.nio.file.Path;
24+
import java.util.List;
2425
import java.util.jar.JarEntry;
2526
import java.util.jar.JarInputStream;
2627
import java.util.jar.Manifest;
@@ -34,7 +35,7 @@
3435
*/
3536
class ModuleGleaner
3637
{
37-
private String gleanFromManifest( Manifest mf )
38+
private String gleanAutomaticFromManifest( Manifest mf )
3839
{
3940
if ( mf != null )
4041
{
@@ -47,7 +48,28 @@ private String gleanFromManifest( Manifest mf )
4748
return null;
4849
}
4950

50-
private String gleanFromModuleInfo( InputStream inputStream )
51+
private String gleanAutomaticFromJar( Path jarPath )
52+
{
53+
try ( JarInputStream jis = new JarInputStream( Files.newInputStream( jarPath ) ) )
54+
{
55+
return gleanAutomaticFromManifest( jis.getManifest() );
56+
}
57+
catch ( IOException e )
58+
{
59+
return null;
60+
}
61+
}
62+
63+
private String gleanAutomatic( Path path )
64+
{
65+
if ( path.getFileName().toString().endsWith( ".jar" ) )
66+
{
67+
return gleanAutomaticFromJar( path );
68+
}
69+
return null;
70+
}
71+
72+
private String gleanFromModuleInfoClass( InputStream inputStream )
5173
throws IOException
5274
{
5375
String[] moduleName = new String[1];
@@ -64,37 +86,37 @@ public ModuleVisitor visitModule( String modName, int modAccess, String modVersi
6486
return moduleName[0];
6587
}
6688

67-
private String gleanFromJar( Path jarPath )
89+
private String gleanModuleInfoFromJar( Path jarPath )
6890
{
6991
try ( JarInputStream jis = new JarInputStream( Files.newInputStream( jarPath ) ) )
7092
{
7193
for ( JarEntry entry; ( entry = jis.getNextJarEntry() ) != null; )
7294
{
7395
if ( "module-info.class".equals( entry.getName() ) )
7496
{
75-
String moduleName = gleanFromModuleInfo( jis );
97+
String moduleName = gleanFromModuleInfoClass( jis );
7698
if ( moduleName != null )
7799
{
78100
return moduleName;
79101
}
80102
}
81103
}
82-
return gleanFromManifest( jis.getManifest() );
104+
return null;
83105
}
84106
catch ( IOException e )
85107
{
86108
return null;
87109
}
88110
}
89111

90-
private String gleanFromClasses( Path classesPath )
112+
private String gleanModuleInfoFromClasses( Path classesPath )
91113
{
92114
Path moduleInfoPath = classesPath.resolve( "module-info.class" );
93115
if ( Files.isRegularFile( moduleInfoPath ) )
94116
{
95117
try ( InputStream is = Files.newInputStream( moduleInfoPath ) )
96118
{
97-
return gleanFromModuleInfo( is );
119+
return gleanFromModuleInfoClass( is );
98120
}
99121
catch ( IOException e )
100122
{
@@ -103,16 +125,32 @@ private String gleanFromClasses( Path classesPath )
103125
return null;
104126
}
105127

106-
public String glean( Path path )
128+
private String gleanModuleInfo( Path path )
107129
{
108130
if ( Files.isDirectory( path ) )
109131
{
110-
return gleanFromClasses( path );
132+
return gleanModuleInfoFromClasses( path );
111133
}
112134
if ( path.getFileName().toString().endsWith( ".jar" ) )
113135
{
114-
return gleanFromJar( path );
136+
return gleanModuleInfoFromJar( path );
115137
}
116138
return null;
117139
}
140+
141+
public JavadocModule glean( Path artifactPath, List<Path> sourcePaths, List<Path> dependencies, boolean ignoreJPMS )
142+
{
143+
String moduleName = null;
144+
boolean isAutomatic = false;
145+
if ( !ignoreJPMS )
146+
{
147+
moduleName = gleanModuleInfo( artifactPath );
148+
if ( moduleName == null )
149+
{
150+
moduleName = gleanAutomatic( artifactPath );
151+
isAutomatic = moduleName != null;
152+
}
153+
}
154+
return new JavadocModule( moduleName, isAutomatic, artifactPath, sourcePaths, dependencies );
155+
}
118156
}

0 commit comments

Comments
 (0)