1111import java .nio .file .attribute .BasicFileAttributes ;
1212import java .util .concurrent .atomic .AtomicReference ;
1313
14+ import org .jboss .logging .Logger ;
15+
1416import io .quarkus .deployment .annotations .BuildStep ;
1517import io .quarkus .deployment .pkg .builditem .BuildSystemTargetBuildItem ;
1618import io .quarkus .deployment .pkg .builditem .CompiledJavaVersionBuildItem ;
1719
1820public class CompiledJavaVersionBuildStep {
1921
22+ private static final Logger log = Logger .getLogger (CompiledJavaVersionBuildStep .class );
23+
2024 /**
2125 * Determines the Java version by looking up the major version of the first successfully parsed
2226 * application .class file that is found
2327 */
2428 @ BuildStep
2529 public CompiledJavaVersionBuildItem compiledJavaVersion (BuildSystemTargetBuildItem buildSystemTarget ) {
2630 if ((buildSystemTarget .getOutputDirectory () == null ) || (!Files .exists (buildSystemTarget .getOutputDirectory ()))) {
31+ log .debug ("Skipping because output directory does not exist" );
2732 // needed for Arquillian TCK tests
2833 return CompiledJavaVersionBuildItem .unknown ();
2934 }
3035 AtomicReference <Integer > majorVersion = new AtomicReference <>(null );
3136 try {
37+ log .debugf ("Walking directory '%s'" , buildSystemTarget .getOutputDirectory ().toAbsolutePath ().toString ());
3238 Files .walkFileTree (buildSystemTarget .getOutputDirectory (), new SimpleFileVisitor <>() {
3339 @ Override
3440 public FileVisitResult visitFile (Path file , BasicFileAttributes attrs ) {
3541 if (file .getFileName ().toString ().endsWith (".class" )) {
42+ log .debugf ("Checking file '%s'" , file .toAbsolutePath ().toString ());
3643 try (InputStream in = new FileInputStream (file .toFile ())) {
3744 DataInputStream data = new DataInputStream (in );
3845 if (0xCAFEBABE == data .readInt ()) {
3946 data .readUnsignedShort (); // minor version -> we don't care about it
40- majorVersion .set (data .readUnsignedShort ());
47+ int v = data .readUnsignedShort ();
48+ majorVersion .set (v );
49+ log .debugf ("Determined compile java version to be %d" , v );
4150 return FileVisitResult .TERMINATE ;
4251 }
43- } catch (IOException ignored ) {
44-
52+ } catch (IOException e ) {
53+ log . debugf ( e , "Encountered exception while processing file '%s'" , file . toAbsolutePath (). toString ());
4554 }
4655 }
4756 // if this was not .class file or there was an error parsing its contents, we continue on to the next file
@@ -52,6 +61,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
5261
5362 }
5463 if (majorVersion .get () == null ) {
64+ log .debug ("No .class files located" );
5565 return CompiledJavaVersionBuildItem .unknown ();
5666 }
5767 return CompiledJavaVersionBuildItem .fromMajorJavaVersion (majorVersion .get ());
0 commit comments