You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2020/06/10 14:26:53 UTC

[GitHub] [maven-shared-utils] elharo commented on a change in pull request #54: rework directory scanner to ensure it can enforce exclusions and it uses path

elharo commented on a change in pull request #54:
URL: https://github.com/apache/maven-shared-utils/pull/54#discussion_r438162710



##########
File path: src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java
##########
@@ -243,14 +243,6 @@ public void testSimpleExcludes()
                 /* expExclDirs     */ NONE );
     }
 
-    public void testIsSymbolicLink()

Review comment:
       why is this test removed?

##########
File path: src/main/java/org/apache/maven/shared/utils/io/MatchPattern.java
##########
@@ -33,9 +33,7 @@
  * Significantly more efficient than using strings, since re-evaluation and re-tokenizing is avoided.
  *
  * @author Kristian Rosenvold
- * @deprecated use {@code java.nio.filejava.nio.file.DirectoryStream.Filter<T>} and related classes

Review comment:
       please retain this

##########
File path: src/test/java/org/apache/maven/shared/utils/io/conductor/EnforceExcludesOverIncludesTest.java
##########
@@ -0,0 +1,92 @@
+package org.apache.maven.shared.utils.io.conductor;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.shared.utils.io.DirectoryScanner;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.FileWriter;

Review comment:
       danger: this class depends on platform default encoding. Avoid.

##########
File path: src/main/java/org/apache/maven/shared/utils/io/conductor/EnforceExcludesOverIncludes.java
##########
@@ -0,0 +1,58 @@
+package org.apache.maven.shared.utils.io.conductor;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.shared.utils.io.DirectoryScanner;
+import org.apache.maven.shared.utils.io.MatchPatterns;
+import org.apache.maven.shared.utils.io.ScanConductor;
+import org.apache.maven.shared.utils.io.ScannerAware;
+
+import java.io.File;
+
+/**
+ * If an exclude is defined on a folder it will bypass the visit of the children

Review comment:
       will bypass --> bypasses
   
   In general, tech writing prefers the present tense
   
   better yet bypass the visit --> does not visit

##########
File path: src/test/java/org/apache/maven/shared/utils/io/conductor/EnforceExcludesOverIncludesTest.java
##########
@@ -0,0 +1,92 @@
+package org.apache.maven.shared.utils.io.conductor;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.shared.utils.io.DirectoryScanner;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+
+public class EnforceExcludesOverIncludesTest
+{
+    @Rule
+    public final TemporaryFolder folder = new TemporaryFolder();
+
+    @Test
+    public void dontVisitChildren() throws IOException
+    {
+        createFakeFiles();
+
+        DirectoryScanner scanner = new DirectoryScanner();
+        scanner.setScanConductor(new EnforceExcludesOverIncludes());
+        scanner.setExcludes( "**/target/**" );
+        scanner.setIncludes( "**" ); // files in target will match include but our conductor will bypass them anyway
+        scanner.setBasedir( folder.getRoot() );
+        scanner.scan();
+        assertResultEquals( asList( "bar", "sub/other" ), scanner.getIncludedFiles() );
+        assertResultEquals( singletonList( "target" ), scanner.getExcludedDirectories() );
+    }
+
+    @Test // we don't set the conductor to ensure we have a "control" test to compare to the other
+    public void controlTest() throws IOException
+    {
+        createFakeFiles();
+
+        DirectoryScanner scanner = new DirectoryScanner();
+        scanner.setExcludes( "**/target/**" );
+        scanner.setIncludes( "**" ); // files in target will match include but our conductor will bypass them anyway
+        scanner.setBasedir( folder.getRoot() );
+        scanner.scan();
+        assertResultEquals( asList( "bar", "sub/other" ), scanner.getIncludedFiles() );
+        assertResultEquals( asList( "target", "target/nested" ), scanner.getExcludedDirectories() );
+    }
+
+    private void createFakeFiles() throws IOException
+    {
+        touch(new File(folder.getRoot(), "bar"));
+        touch(new File(folder.getRoot(), "sub/other"));
+        touch(new File(folder.getRoot(), "target/foo"));
+        touch(new File(folder.getRoot(), "target/nested/dummy"));
+    }
+
+    private void assertResultEquals( final List<String> expected, final String[] actual )
+    {
+        final List<String> actualList = new ArrayList<>( asList( actual ) );
+        Collections.sort( actualList );
+        assertEquals( expected, actualList );
+    }
+
+    private void touch( final File file ) throws IOException
+    {
+        file.getParentFile().mkdirs();
+        new FileWriter( file ).close();

Review comment:
       This is weird. Perhaps just file.createNewFile()




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org