4040import javax .tools .JavaCompiler ;
4141import javax .tools .JavaFileObject ;
4242import javax .tools .JavaFileObject .Kind ;
43+ import javax .tools .Location ;
4344import javax .tools .StandardLocation ;
4445import org .apiguardian .api .API ;
4546import org .apiguardian .api .API .Status ;
@@ -74,6 +75,9 @@ public JctCompilation createCompilation(
7475 ) {
7576 try {
7677 return createCheckedCompilation (flags , fileManager , jsr199Compiler , classNames );
78+ } catch (JctCompilerException ex ) {
79+ // Fall through, do not rewrap these.
80+ throw ex ;
7781 } catch (Exception ex ) {
7882 throw new JctCompilerException (
7983 "Failed to perform compilation, an unexpected exception was raised" , ex
@@ -139,12 +143,19 @@ private JctCompilation createCheckedCompilation(
139143 }
140144
141145 private Set <JavaFileObject > findCompilationUnits (JctFileManager fileManager ) throws IOException {
142- var modules = IterableUtils
146+ var locations = IterableUtils
143147 .flatten (fileManager .listLocationsForModules (StandardLocation .MODULE_SOURCE_PATH ));
144148
145- var locations = modules .isEmpty ()
146- ? Set .of (StandardLocation .SOURCE_PATH )
147- : modules ;
149+ if (locations .isEmpty ()) {
150+ LOGGER .info (
151+ "No multi-module sources found, will use the source path to find classes to compile"
152+ );
153+ locations = Set .of (StandardLocation .SOURCE_PATH );
154+ } else {
155+ LOGGER .info (
156+ "Multi-module sources found, will use the module source path to find classes to compile"
157+ );
158+ }
148159
149160 var objects = new LinkedHashSet <JavaFileObject >();
150161
@@ -155,6 +166,12 @@ private Set<JavaFileObject> findCompilationUnits(JctFileManager fileManager) thr
155166 }
156167 }
157168
169+ if (objects .isEmpty ()) {
170+ throw new JctCompilerException (
171+ "No compilation units were found. Did you forget to add something?"
172+ );
173+ }
174+
158175 return objects ;
159176 }
160177}
0 commit comments