wilx commented on code in PR #1102:
URL: 
https://github.com/apache/maven-compiler-plugin/pull/1102#discussion_r3736767207


##########
src/main/java/org/apache/maven/plugin/compiler/DependencyState.java:
##########
@@ -0,0 +1,306 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugin.compiler;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.shared.incremental.IncrementalBuildHelper;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Persists the class path and module path used by a compiler Mojo execution 
and detects dependencies modified during
+ * the current Maven build while collecting that state.
+ */
+final class DependencyState {
+    private static final String STATE_FILE = "dependencies.lst";
+    private static final String STATE_SEPARATOR = "\t";
+    private static final Set<String> DEFAULT_FILE_EXTENSIONS =
+            Collections.unmodifiableSet(new HashSet<>(Arrays.asList("class", 
"jar")));
+
+    private DependencyState() {}
+
+    static boolean hasChanged(
+            IncrementalBuildHelper incrementalBuildHelper,
+            File outputDirectory,
+            List<String> classpathElements,
+            List<String> modulepathElements,
+            Configuration configuration) {
+        Path stateFile = null;
+        try {
+            stateFile = 
incrementalBuildHelper.getMojoStatusDirectory().toPath().resolve(STATE_FILE);
+        } catch (MojoExecutionException e) {
+            configuration.log.warn("Error reading mojo status directory.");
+        }
+
+        List<String> oldState = Collections.emptyList();
+        boolean hasPreviousState = stateFile != null && 
Files.isRegularFile(stateFile);
+        if (hasPreviousState) {
+            try {
+                oldState = Files.readAllLines(stateFile);
+            } catch (IOException e) {
+                configuration.log.warn("Error while reading old dependency 
status: " + stateFile);
+                hasPreviousState = false;
+            }
+        }
+
+        List<String> newState = new ArrayList<>();
+        ScanContext context = new ScanContext(outputDirectory, configuration);
+        Path changedDependency = addDependencies(newState, "classpath:", 
classpathElements, context, null);
+        changedDependency = addDependencies(newState, "modulepath:", 
modulepathElements, context, changedDependency);
+
+        if (stateFile != null) {
+            try {
+                Files.write(stateFile, newState);
+            } catch (IOException e) {
+                configuration.log.warn("Error while writing new dependency 
status: " + stateFile);
+            }
+        }
+
+        if (hasPreviousState && !oldState.equals(newState)) {
+            if (configuration.log.isDebugEnabled() || 
configuration.showChanges) {
+                logChanges(oldState, newState, configuration.log);
+            }
+            return true;
+        }
+        if (changedDependency != null) {
+            if (configuration.log.isDebugEnabled() || 
configuration.showChanges) {
+                configuration.log.info("\tNew dependency detected: " + 
changedDependency.toAbsolutePath());

Review Comment:
   The `log.info` is there because it is possible to get the line printed with 
user supplied `maven.compiler.showCompilationChanges` property. If it were 
`log.debug` it would not print if the user asked via the property. I can change 
it to `debug` for `configuration.log.isDebugEnabled()` and keep the `info` for 
`configuration.showChanges`. But that seems unnecessary nuanced. 



##########
src/main/java/org/apache/maven/plugin/compiler/DependencyState.java:
##########
@@ -0,0 +1,306 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugin.compiler;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.shared.incremental.IncrementalBuildHelper;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Persists the class path and module path used by a compiler Mojo execution 
and detects dependencies modified during
+ * the current Maven build while collecting that state.
+ */
+final class DependencyState {
+    private static final String STATE_FILE = "dependencies.lst";
+    private static final String STATE_SEPARATOR = "\t";
+    private static final Set<String> DEFAULT_FILE_EXTENSIONS =
+            Collections.unmodifiableSet(new HashSet<>(Arrays.asList("class", 
"jar")));
+
+    private DependencyState() {}
+
+    static boolean hasChanged(
+            IncrementalBuildHelper incrementalBuildHelper,
+            File outputDirectory,
+            List<String> classpathElements,
+            List<String> modulepathElements,
+            Configuration configuration) {
+        Path stateFile = null;
+        try {
+            stateFile = 
incrementalBuildHelper.getMojoStatusDirectory().toPath().resolve(STATE_FILE);
+        } catch (MojoExecutionException e) {
+            configuration.log.warn("Error reading mojo status directory.");
+        }
+
+        List<String> oldState = Collections.emptyList();
+        boolean hasPreviousState = stateFile != null && 
Files.isRegularFile(stateFile);
+        if (hasPreviousState) {
+            try {
+                oldState = Files.readAllLines(stateFile);
+            } catch (IOException e) {
+                configuration.log.warn("Error while reading old dependency 
status: " + stateFile);
+                hasPreviousState = false;
+            }
+        }
+
+        List<String> newState = new ArrayList<>();
+        ScanContext context = new ScanContext(outputDirectory, configuration);
+        Path changedDependency = addDependencies(newState, "classpath:", 
classpathElements, context, null);
+        changedDependency = addDependencies(newState, "modulepath:", 
modulepathElements, context, changedDependency);
+
+        if (stateFile != null) {
+            try {
+                Files.write(stateFile, newState);
+            } catch (IOException e) {
+                configuration.log.warn("Error while writing new dependency 
status: " + stateFile);
+            }
+        }
+
+        if (hasPreviousState && !oldState.equals(newState)) {
+            if (configuration.log.isDebugEnabled() || 
configuration.showChanges) {
+                logChanges(oldState, newState, configuration.log);
+            }
+            return true;
+        }
+        if (changedDependency != null) {
+            if (configuration.log.isDebugEnabled() || 
configuration.showChanges) {
+                configuration.log.info("\tNew dependency detected: " + 
changedDependency.toAbsolutePath());

Review Comment:
   The `log.info` is there because it is possible to get the line printed with 
user supplied `maven.compiler.showCompilationChanges` property. If it were 
`log.debug` it would not print if the user asked via the property. I can change 
it to `debug` for `configuration.log.isDebugEnabled()` and keep the `info` for 
`configuration.showChanges`. But that seems unnecessarily nuanced. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to