Skip to content

Commit 60ee92d

Browse files
authored
Improve logging in JctCompilationFactoryImpl.java
Signed-off-by: Ashley <[email protected]>
1 parent 2b7ac31 commit 60ee92d

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImpl.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import javax.tools.JavaCompiler;
4141
import javax.tools.JavaFileObject;
4242
import javax.tools.JavaFileObject.Kind;
43+
import javax.tools.Location;
4344
import javax.tools.StandardLocation;
4445
import org.apiguardian.api.API;
4546
import 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

Comments
 (0)