More Java5
authorKarl Heinz Marbaise <khmarbaise@apache.org>
Fri, 11 Dec 2015 17:33:58 +0000 (17:33 +0000)
committerKarl Heinz Marbaise <khmarbaise@apache.org>
Fri, 11 Dec 2015 17:33:58 +0000 (17:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1719477 13f79535-47bb-0310-9956-ffa450edef68

src/main/java/org/apache/maven/shared/io/scan/AbstractResourceInclusionScanner.java
src/main/java/org/apache/maven/shared/io/scan/ResourceInclusionScanner.java
src/main/java/org/apache/maven/shared/io/scan/SimpleResourceInclusionScanner.java
src/main/java/org/apache/maven/shared/io/scan/StaleResourceScanner.java
src/main/java/org/apache/maven/shared/io/scan/mapping/SingleTargetMapping.java
src/main/java/org/apache/maven/shared/io/scan/mapping/SourceMapping.java
src/main/java/org/apache/maven/shared/io/scan/mapping/SuffixMapping.java
src/test/java/org/apache/maven/shared/io/scan/mapping/SuffixMappingTest.java

index eb86532..2f05f09 100644 (file)
@@ -19,15 +19,15 @@ package org.apache.maven.shared.io.scan;
  * under the License.
  */
 
-import org.apache.maven.shared.io.scan.mapping.SourceMapping;
-import org.apache.maven.shared.utils.io.DirectoryScanner;
-
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.maven.shared.io.scan.mapping.SourceMapping;
+import org.apache.maven.shared.utils.io.DirectoryScanner;
+
 /**
  * @author jdcasey
  * @version $Id$
@@ -35,7 +35,7 @@ import java.util.Set;
 public abstract class AbstractResourceInclusionScanner
     implements ResourceInclusionScanner
 {
-    private final List sourceMappings = new ArrayList();
+    private final List<SourceMapping> sourceMappings = new ArrayList<SourceMapping>();
 
     /** {@inheritDoc} */
     public final void addSourceMapping( SourceMapping sourceMapping )
@@ -46,7 +46,7 @@ public abstract class AbstractResourceInclusionScanner
     /**
      * @return The source mapping.
      */
-    protected final List getSourceMappings()
+    protected final List<SourceMapping> getSourceMappings()
     {
         return Collections.unmodifiableList( sourceMappings );
     }
@@ -57,7 +57,7 @@ public abstract class AbstractResourceInclusionScanner
      * @param sourceExcludes source excludes.
      * @return The resulting sources.
      */
-    protected String[] scanForSources( File sourceDir, Set sourceIncludes, Set sourceExcludes )
+    protected String[] scanForSources( File sourceDir, Set<String> sourceIncludes, Set<String> sourceExcludes )
     {
         DirectoryScanner ds = new DirectoryScanner();
         ds.setFollowSymlinks( true );
index 6fca1b8..5171124 100644 (file)
@@ -41,6 +41,6 @@ public interface ResourceInclusionScanner
      * @return The included sources.
      * @throws InclusionScanException in case of an error.
      */
-    Set getIncludedSources( File sourceDir, File targetDir )
+    Set<File> getIncludedSources( File sourceDir, File targetDir )
         throws InclusionScanException;
 }
index 719af8d..c0aed25 100644 (file)
@@ -24,6 +24,8 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.maven.shared.io.scan.mapping.SourceMapping;
+
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
@@ -31,15 +33,15 @@ import java.util.Set;
 public class SimpleResourceInclusionScanner
     extends AbstractResourceInclusionScanner
 {
-    private Set sourceIncludes;
+    private Set<String> sourceIncludes;
 
-    private Set sourceExcludes;
+    private Set<String> sourceExcludes;
 
     /**
      * @param sourceIncludes The source includes.
      * @param sourceExcludes The source excludes.
      */
-    public SimpleResourceInclusionScanner( Set sourceIncludes, Set sourceExcludes )
+    public SimpleResourceInclusionScanner( Set<String> sourceIncludes, Set<String> sourceExcludes )
     {
         this.sourceIncludes = sourceIncludes;
 
@@ -50,11 +52,11 @@ public class SimpleResourceInclusionScanner
     public Set getIncludedSources( File sourceDir, File targetDir )
         throws InclusionScanException
     {
-        List srcMappings = getSourceMappings();
+        List<SourceMapping> srcMappings = getSourceMappings();
 
         if ( srcMappings.isEmpty() )
         {
-            return Collections.EMPTY_SET;
+            return Collections.<String>emptySet();
         }
 
         return Collections.singleton( scanForSources( sourceDir, sourceIncludes, sourceExcludes ) );
index 6264de5..62358be 100644 (file)
@@ -19,15 +19,14 @@ package org.apache.maven.shared.io.scan;
  * under the License.
  */
 
-import org.apache.maven.shared.io.scan.mapping.SourceMapping;
-
 import java.io.File;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.maven.shared.io.scan.mapping.SourceMapping;
+
 /**
  * @author jdcasey
  * @version $Id$
@@ -37,9 +36,9 @@ public class StaleResourceScanner
 {
     private final long lastUpdatedWithinMsecs;
 
-    private final Set sourceIncludes;
+    private final Set<String> sourceIncludes;
 
-    private final Set sourceExcludes;
+    private final Set<String> sourceExcludes;
 
     // ----------------------------------------------------------------------
     //
@@ -50,7 +49,7 @@ public class StaleResourceScanner
      */
     public StaleResourceScanner()
     {
-        this( 0, Collections.singleton( "**/*" ), Collections.EMPTY_SET );
+        this( 0, Collections.singleton( "**/*" ), Collections.<String>emptySet() );
     }
 
     /**
@@ -58,7 +57,7 @@ public class StaleResourceScanner
      */
     public StaleResourceScanner( long lastUpdatedWithinMsecs )
     {
-        this( lastUpdatedWithinMsecs, Collections.singleton( "**/*" ), Collections.EMPTY_SET );
+        this( lastUpdatedWithinMsecs, Collections.singleton( "**/*" ), Collections.<String>emptySet() );
     }
 
     /**
@@ -66,7 +65,7 @@ public class StaleResourceScanner
      * @param sourceIncludes source includes.
      * @param sourceExcludes source excludes.
      */
-    public StaleResourceScanner( long lastUpdatedWithinMsecs, Set sourceIncludes, Set sourceExcludes )
+    public StaleResourceScanner( long lastUpdatedWithinMsecs, Set<String> sourceIncludes, Set<String> sourceExcludes )
     {
         this.lastUpdatedWithinMsecs = lastUpdatedWithinMsecs;
 
@@ -80,19 +79,19 @@ public class StaleResourceScanner
     // ----------------------------------------------------------------------
 
     /** {@inheritDoc} */
-    public Set getIncludedSources( File sourceDir, File targetDir )
+    public Set<File> getIncludedSources( File sourceDir, File targetDir )
         throws InclusionScanException
     {
-        List srcMappings = getSourceMappings();
+        List<SourceMapping> srcMappings = getSourceMappings();
 
         if ( srcMappings.isEmpty() )
         {
-            return Collections.EMPTY_SET;
+            return Collections.<File>emptySet();
         }
 
         String[] potentialIncludes = scanForSources( sourceDir, sourceIncludes, sourceExcludes );
 
-        Set matchingSources = new HashSet();
+        Set<File> matchingSources = new HashSet<File>();
 
         for ( int i = 0; i < potentialIncludes.length; i++ )
         {
@@ -100,19 +99,15 @@ public class StaleResourceScanner
 
             File sourceFile = new File( sourceDir, path );
 
-            staleSourceFileTesting: for ( Iterator patternIt = srcMappings.iterator(); patternIt.hasNext(); )
+            staleSourceFileTesting: for ( SourceMapping mapping : srcMappings )
             {
-                SourceMapping mapping = (SourceMapping) patternIt.next();
-
-                Set targetFiles = mapping.getTargetFiles( targetDir, path );
+                Set<File> targetFiles = mapping.getTargetFiles( targetDir, path );
 
                 // never include files that don't have corresponding target mappings.
                 // the targets don't have to exist on the filesystem, but the
                 // mappers must tell us to look for them.
-                for ( Iterator targetIt = targetFiles.iterator(); targetIt.hasNext(); )
+                for ( File targetFile : targetFiles )
                 {
-                    File targetFile = (File) targetIt.next();
-
                     if ( !targetFile.exists()
                         || ( targetFile.lastModified() + lastUpdatedWithinMsecs < sourceFile.lastModified() ) )
                     {
index e6badfd..2d1f337 100644 (file)
@@ -50,12 +50,12 @@ public class SingleTargetMapping
     }
 
     /** {@inheritDoc} */
-    public Set getTargetFiles( File targetDir, String source )
+    public Set<File> getTargetFiles( File targetDir, String source )
         throws InclusionScanException
     {
         if ( !source.endsWith( sourceSuffix ) )
         {
-            return Collections.EMPTY_SET;
+            return Collections.<File>emptySet();
         }
 
         return Collections.singleton( new File( targetDir, outputFile ) );
index bafcb99..7defc0b 100644 (file)
@@ -19,11 +19,11 @@ package org.apache.maven.shared.io.scan.mapping;
  * under the License.
  */
 
-import org.apache.maven.shared.io.scan.InclusionScanException;
-
 import java.io.File;
 import java.util.Set;
 
+import org.apache.maven.shared.io.scan.InclusionScanException;
+
 /**
  * @author jdcasey
  * @version $Id$
@@ -36,6 +36,6 @@ public interface SourceMapping
      * @return list of target files.
      * @throws InclusionScanException in case of an error.
      */
-    Set getTargetFiles( File targetDir, String source )
+    Set<File> getTargetFiles( File targetDir, String source )
         throws InclusionScanException;
 }
index 6bc9c10..75aa461 100644 (file)
@@ -22,7 +22,6 @@ package org.apache.maven.shared.io.scan.mapping;
 import java.io.File;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Set;
 
 /**
@@ -34,7 +33,7 @@ public final class SuffixMapping
 {
     private final String sourceSuffix;
 
-    private final Set targetSuffixes;
+    private final Set<String> targetSuffixes;
 
     /**
      * @param sourceSuffix source suffix.
@@ -51,26 +50,24 @@ public final class SuffixMapping
      * @param sourceSuffix source suffix.
      * @param targetSuffixes target suffixes.
      */
-    public SuffixMapping( String sourceSuffix, Set targetSuffixes )
+    public SuffixMapping( String sourceSuffix, Set<String> targetSuffixes )
     {
         this.sourceSuffix = sourceSuffix;
 
-        this.targetSuffixes = Collections.unmodifiableSet( targetSuffixes );
+        this.targetSuffixes = targetSuffixes;
     }
 
     /** {@inheritDoc} */
-    public Set getTargetFiles( File targetDir, String source )
+    public Set<File> getTargetFiles( File targetDir, String source )
     {
-        Set targetFiles = new HashSet();
+        Set<File> targetFiles = new HashSet<File>();
 
         if ( source.endsWith( sourceSuffix ) )
         {
             String base = source.substring( 0, source.length() - sourceSuffix.length() );
 
-            for ( Iterator it = targetSuffixes.iterator(); it.hasNext(); )
+            for ( String suffix : targetSuffixes )
             {
-                String suffix = (String) it.next();
-
                 targetFiles.add( new File( targetDir, base + suffix ) );
             }
         }
index 801d299..197aad6 100644 (file)
@@ -19,20 +19,22 @@ package org.apache.maven.shared.io.scan.mapping;
  * under the License.
  */
 
-
-import junit.framework.TestCase;
-import org.apache.maven.shared.io.scan.InclusionScanException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.maven.shared.io.scan.InclusionScanException;
+import org.junit.Test;
+
 /**
  * @author jdcasey
  */
 public class SuffixMappingTest
-    extends TestCase
 {
+    @Test
     public void testShouldReturnSingleClassFileForSingleJavaFile()
         throws InclusionScanException
     {
@@ -40,15 +42,17 @@ public class SuffixMappingTest
 
         File basedir = new File( "." );
 
+        System.out.println( "basedir:" + basedir.getAbsolutePath() );
         SuffixMapping mapping = new SuffixMapping( ".java", ".class" );
 
-        Set results = mapping.getTargetFiles( basedir, base + ".java" );
+        Set<File> results = mapping.getTargetFiles( basedir, base + ".java" );
 
         assertEquals( "Returned wrong number of target files.", 1, results.size() );
 
         assertEquals( "Target file is wrong.", new File( basedir, base + ".class" ), results.iterator().next() );
     }
 
+    @Test
     public void testShouldNotReturnClassFileWhenSourceFileHasWrongSuffix()
         throws InclusionScanException
     {
@@ -58,11 +62,12 @@ public class SuffixMappingTest
 
         SuffixMapping mapping = new SuffixMapping( ".java", ".class" );
 
-        Set results = mapping.getTargetFiles( basedir, base + ".xml" );
+        Set<File> results = mapping.getTargetFiles( basedir, base + ".xml" );
 
         assertTrue( "Returned wrong number of target files.", results.isEmpty() );
     }
 
+    @Test
     public void testShouldReturnOneClassFileAndOneXmlFileForSingleJavaFile()
         throws InclusionScanException
     {
@@ -70,13 +75,13 @@ public class SuffixMappingTest
 
         File basedir = new File( "." );
 
-        Set targets = new HashSet();
+        Set<String> targets = new HashSet<String>();
         targets.add( ".class" );
         targets.add( ".xml" );
 
         SuffixMapping mapping = new SuffixMapping( ".java", targets );
 
-        Set results = mapping.getTargetFiles( basedir, base + ".java" );
+        Set<File> results = mapping.getTargetFiles( basedir, base + ".java" );
 
         assertEquals( "Returned wrong number of target files.", 2, results.size() );
 
@@ -85,6 +90,7 @@ public class SuffixMappingTest
         assertTrue( "Targets do not contain class target.", results.contains( new File( basedir, base + ".xml" ) ) );
     }
 
+    @Test
     public void testShouldReturnNoTargetFilesWhenSourceFileHasWrongSuffix()
         throws InclusionScanException
     {
@@ -92,17 +98,18 @@ public class SuffixMappingTest
 
         File basedir = new File( "." );
 
-        Set targets = new HashSet();
+        Set<String> targets = new HashSet<String>();
         targets.add( ".class" );
         targets.add( ".xml" );
 
         SuffixMapping mapping = new SuffixMapping( ".java", targets );
 
-        Set results = mapping.getTargetFiles( basedir, base + ".apt" );
+        Set<File> results = mapping.getTargetFiles( basedir, base + ".apt" );
 
         assertTrue( "Returned wrong number of target files.", results.isEmpty() );
     }
 
+    @Test
     public void testSingleTargetMapper()
         throws InclusionScanException
     {
@@ -112,7 +119,7 @@ public class SuffixMappingTest
 
         SingleTargetMapping mapping = new SingleTargetMapping( ".cs", "/foo" );
 
-        Set results = mapping.getTargetFiles( basedir, base + ".apt" );
+        Set<File> results = mapping.getTargetFiles( basedir, base + ".apt" );
 
         assertTrue( results.isEmpty() );