desruisseaux commented on code in PR #508:
URL: https://github.com/apache/maven-jar-plugin/pull/508#discussion_r3892102757


##########
src/main/java/org/apache/maven/plugins/jar/TimestampCheck.java:
##########
@@ -0,0 +1,237 @@
+/*
+ * 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.plugins.jar;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.nio.file.attribute.FileTime;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.apache.maven.api.plugin.Log;
+
+/**
+ * Checks file timestamps in order to determine if anything changed compared 
to an existing <abbr>JAR</abbr> file.
+ * This class may scan directories, but only if they have not already been 
visited by {@link FileCollector}.
+ * Note that the latter can occur only if {@link FileCollector} has no {@code 
PathMatcher}.
+ * Therefore, this class uses no {@code PathMatcher} neither.
+ *
+ * <h2>Ignore files</h2>
+ * The {@code META-INF/MANIFEST.MF} file and the {@code META-INF/maven/} 
directory are ignored.
+ * See {@link #isIgnored(Path)} for the rational.
+ */
+final class TimestampCheck extends SimpleFileVisitor<Path> {
+    /**
+     * The base directory of archived files.
+     */
+    private final Path classesDir;
+
+    /**
+     * Path to the existing <abbr>JAR</abbr> file.
+     */
+    private final Path jarFile;
+
+    /**
+     * The last modified time of the <abbr>JAR</abbr> file.
+     */
+    private final FileTime jarFileTime;
+
+    /**
+     * Where to send non-fatal error messages.
+     */
+    private final Log logger;
+
+    /**
+     * Entries of the <abbr>JAR</abbr> file. Note that getting elements from 
this enumeration can be costly.
+     * Therefore, we do not fetch all elements in advance but only when needed.
+     */
+    private Enumeration<? extends ZipEntry> entries;
+
+    /**
+     * Files found in the <abbr>JAR</abbr> file but not yet traversed by the 
file visitor.
+     * Files are added lazily only when needed, and removed as soon as they 
have been traversed.
+     * Path are absolute (resolved with {@link #classesDir}).
+     */
+    private final Set<Path> filesInJAR;
+
+    /**
+     * Some of the files in the build directory. This list contains only the 
files for which we have already
+     * verified the timestamp. We store them in a separated list for avoiding 
to check the timestamp twice.
+     * We need this list because we still need to verify if the files are in 
the {@link #jarFile}.
+     */
+    private final Set<Path> filesInBuild;
+
+    /**
+     * Whether at least one file is more recent than the <abbr>JAR</abbr> file.
+     * The scan of files will stop quickly after this flag become {@code true}.

Review Comment:
   Not immediately because there is a few method calls between the moment when 
this flag is set and the moment when it is read and the visit interrupted.



-- 
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