You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2021/04/10 09:05:58 UTC

[maven-shared-io] branch MSHARED-930 created (now 102e396)

This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a change to branch MSHARED-930
in repository https://gitbox.apache.org/repos/asf/maven-shared-io.git.


      at 102e396  [MSHARED-930] Fix SimpleResourceInclusionScanner.getIncludedSources() returns wrong generic type

This branch includes the following new commits:

     new 102e396  [MSHARED-930] Fix SimpleResourceInclusionScanner.getIncludedSources() returns wrong generic type

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[maven-shared-io] 01/01: [MSHARED-930] Fix SimpleResourceInclusionScanner.getIncludedSources() returns wrong generic type

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MSHARED-930
in repository https://gitbox.apache.org/repos/asf/maven-shared-io.git

commit 102e3968d564cfa49417f9708ce817835d8a0127
Author: dengliming <li...@gmail.com>
AuthorDate: Sun Jul 5 10:24:19 2020 +0800

    [MSHARED-930] Fix SimpleResourceInclusionScanner.getIncludedSources() returns wrong generic type
    
    Closes #10
---
 .../io/scan/SimpleResourceInclusionScanner.java    | 12 ++++-
 .../scan/SimpleResourceInclusionScannerTest.java   | 59 ++++++++++++++++++++++
 2 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/io/scan/SimpleResourceInclusionScanner.java b/src/main/java/org/apache/maven/shared/io/scan/SimpleResourceInclusionScanner.java
index c0aed25..eb86017 100644
--- a/src/main/java/org/apache/maven/shared/io/scan/SimpleResourceInclusionScanner.java
+++ b/src/main/java/org/apache/maven/shared/io/scan/SimpleResourceInclusionScanner.java
@@ -21,6 +21,7 @@ package org.apache.maven.shared.io.scan;
 
 import java.io.File;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -56,9 +57,16 @@ public class SimpleResourceInclusionScanner
 
         if ( srcMappings.isEmpty() )
         {
-            return Collections.<String>emptySet();
+            return Collections.<File>emptySet();
         }
 
-        return Collections.singleton( scanForSources( sourceDir, sourceIncludes, sourceExcludes ) );
+        Set<File> matchingSources = new HashSet<>();
+        String[] sourcePaths = scanForSources( sourceDir, sourceIncludes, sourceExcludes );
+
+        for ( String sourcePath : sourcePaths )
+        {
+            matchingSources.add( new File( sourceDir, sourcePath ) );
+        }
+        return matchingSources;
     }
 }
diff --git a/src/test/java/org/apache/maven/shared/io/scan/SimpleResourceInclusionScannerTest.java b/src/test/java/org/apache/maven/shared/io/scan/SimpleResourceInclusionScannerTest.java
new file mode 100644
index 0000000..3ba2cf9
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/io/scan/SimpleResourceInclusionScannerTest.java
@@ -0,0 +1,59 @@
+package org.apache.maven.shared.io.scan;
+
+/*
+ * 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.io.scan.mapping.SuffixMapping;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author dengliming
+ */
+public class SimpleResourceInclusionScannerTest {
+
+    @Test
+    public void testGetIncludedSources() throws IOException, InclusionScanException
+    {
+        File baseDir = new File("target" );
+        baseDir.deleteOnExit();
+        baseDir.mkdirs();
+        File f = File.createTempFile( "source1.", ".test", baseDir );
+
+        Set<String> sourceIncludes = new HashSet<>();
+        sourceIncludes.add( "**/*" + f.getName() );
+        Set<String> sourceExcludes = new HashSet<>();
+        SimpleResourceInclusionScanner simpleResourceInclusionScanner = new SimpleResourceInclusionScanner( sourceIncludes, sourceExcludes );
+        Set<String> targets = new HashSet<>();
+        targets.add( ".class" );
+        simpleResourceInclusionScanner.addSourceMapping(new SuffixMapping( ".java", targets ));
+        Set results = simpleResourceInclusionScanner.getIncludedSources( baseDir, baseDir );
+        assertTrue( results.size() > 0 );
+        Object file = results.iterator().next();
+        assertTrue( file instanceof File );
+        assertEquals( f.getName(), ( (File) file ).getName() );
+    }
+}