| 1 | |
package org.apache.maven.shared.io.scan; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.apache.maven.shared.io.scan.mapping.SourceMapping; |
| 20 | |
|
| 21 | |
import java.io.File; |
| 22 | |
import java.util.Collections; |
| 23 | |
import java.util.HashSet; |
| 24 | |
import java.util.Iterator; |
| 25 | |
import java.util.List; |
| 26 | |
import java.util.Set; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
public class StaleResourceScanner |
| 33 | |
extends AbstractResourceInclusionScanner |
| 34 | |
{ |
| 35 | |
private final long lastUpdatedWithinMsecs; |
| 36 | |
|
| 37 | |
private final Set sourceIncludes; |
| 38 | |
|
| 39 | |
private final Set sourceExcludes; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public StaleResourceScanner() |
| 46 | |
{ |
| 47 | 0 | this( 0, Collections.singleton( "**/*" ), Collections.EMPTY_SET ); |
| 48 | 0 | } |
| 49 | |
|
| 50 | |
public StaleResourceScanner( long lastUpdatedWithinMsecs ) |
| 51 | |
{ |
| 52 | 0 | this( lastUpdatedWithinMsecs, Collections.singleton( "**/*" ), Collections.EMPTY_SET ); |
| 53 | 0 | } |
| 54 | |
|
| 55 | 0 | public StaleResourceScanner( long lastUpdatedWithinMsecs, Set sourceIncludes, Set sourceExcludes ) |
| 56 | |
{ |
| 57 | 0 | this.lastUpdatedWithinMsecs = lastUpdatedWithinMsecs; |
| 58 | |
|
| 59 | 0 | this.sourceIncludes = sourceIncludes; |
| 60 | |
|
| 61 | 0 | this.sourceExcludes = sourceExcludes; |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
public Set getIncludedSources( File sourceDir, File targetDir ) |
| 69 | |
throws InclusionScanException |
| 70 | |
{ |
| 71 | 0 | List srcMappings = getSourceMappings(); |
| 72 | |
|
| 73 | 0 | if ( srcMappings.isEmpty() ) |
| 74 | |
{ |
| 75 | 0 | return Collections.EMPTY_SET; |
| 76 | |
} |
| 77 | |
|
| 78 | 0 | String[] potentialIncludes = scanForSources( sourceDir, sourceIncludes, sourceExcludes ); |
| 79 | |
|
| 80 | 0 | Set matchingSources = new HashSet(); |
| 81 | |
|
| 82 | 0 | for ( int i = 0; i < potentialIncludes.length; i++ ) |
| 83 | |
{ |
| 84 | 0 | String path = potentialIncludes[i]; |
| 85 | |
|
| 86 | 0 | File sourceFile = new File( sourceDir, path ); |
| 87 | |
|
| 88 | 0 | staleSourceFileTesting: for ( Iterator patternIt = srcMappings.iterator(); patternIt.hasNext(); ) |
| 89 | |
{ |
| 90 | 0 | SourceMapping mapping = (SourceMapping) patternIt.next(); |
| 91 | |
|
| 92 | 0 | Set targetFiles = mapping.getTargetFiles( targetDir, path ); |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | 0 | for ( Iterator targetIt = targetFiles.iterator(); targetIt.hasNext(); ) |
| 98 | |
{ |
| 99 | 0 | File targetFile = (File) targetIt.next(); |
| 100 | |
|
| 101 | 0 | if ( !targetFile.exists() |
| 102 | 0 | || ( targetFile.lastModified() + lastUpdatedWithinMsecs < sourceFile.lastModified() ) ) |
| 103 | |
{ |
| 104 | 0 | matchingSources.add( sourceFile ); |
| 105 | 0 | break staleSourceFileTesting; |
| 106 | |
} |
| 107 | |
} |
| 108 | |
} |
| 109 | |
} |
| 110 | |
|
| 111 | 0 | return matchingSources; |
| 112 | |
} |
| 113 | |
} |