in
return inputTreeChanges.hasChanged();
}
+ private static final int MAX_FILE_WALK_LIMIT = 20;
+
+ /**
+ * Performs a check on compiled class files to ensure that the bytecode version
+ * hasn't changed between runs.
+ *
+ * This is limited to check a maximum of {@link #MAX_FILE_WALK_LIMIT}.
+ *
+ * @return true if a bytecode version differs from the actual release version.
+ */
+ private boolean hasBytecodeChanged() {
+ String currentVersion = getVersionRelease();
+ JavaVersion javaVersion = JavaVersion.parse(currentVersion).asMajor();
+
+ try (Stream walk = Files.walk(getOutputDirectory().toPath())) {
+ Map pathVersionMap = walk.filter(file -> "class"
+ .equals(FileUtils.extension(file.getFileName().toString())))
+ .limit(MAX_FILE_WALK_LIMIT)
+ .collect(Collectors.toMap(Function.identity(), JavaClassfileVersion::of));
+ for (Map.Entry entry : pathVersionMap.entrySet()) {
+ Path path = entry.getKey();
+ JavaClassfileVersion classFileVersion = entry.getValue();
+ JavaVersion javaFileVersion = classFileVersion.javaVersion().asMajor();
+ if (enablePreview != classFileVersion.isPreview() || javaFileVersion.compareTo(javaVersion) != 0) {
+ if (getLog().isDebugEnabled() || showCompilationChanges) {
+ getLog().info(String.format(
+ "\tBytecode file change: %s from %s to %s", path, javaFileVersion, javaVersion));
+ }
+ return true;
+ }
+ }
+ return false;
+ } catch (UncheckedIOException | IOException e) {
+ getLog().warn("Error reading bytecode version", e);
+ return false;
+ }
+ }
+
+ private String getVersionRelease() {
+ return getRelease() != null ? getRelease() : getTarget() != null ? getTarget() : DEFAULT_TARGET;
+ }
+
public void setTarget(String target) {
this.target = target;
targetOrReleaseSet = true;