Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.esotericsoftware.wildcard;

import com.esotericsoftware.utils.*;

import java.io.*;
import java.util.*;
import java.util.regex.Pattern;

class RegexScanner {
    private final File rootDir;
    private final List<Pattern> includePatterns;
    private final List<String> matches = new ArrayList( 128 );

    public RegexScanner( File rootDir, List<String> includes, List<String> excludes ) {
        if ( rootDir == null ) {
            throw new IllegalArgumentException( "rootDir cannot be null." );
        }
        if ( !rootDir.exists() ) {
            throw new IllegalArgumentException( "Directory does not exist: " + rootDir );
        }
        if ( !rootDir.isDirectory() ) {
            throw new IllegalArgumentException( "File must be a directory: " + rootDir );
        }
        try {
            rootDir = rootDir.getCanonicalFile();
        }
        catch ( IOException ex ) {
            throw new FileSystemException( "OS error determining canonical path: " + rootDir, ex );
        }
        this.rootDir = rootDir;

        if ( includes == null ) {
            throw new IllegalArgumentException( "includes cannot be null." );
        }
        if ( excludes == null ) {
            throw new IllegalArgumentException( "excludes cannot be null." );
        }

        includePatterns = new ArrayList();
        for ( String include : includes ) {
            includePatterns.add( Pattern.compile( include, Pattern.CASE_INSENSITIVE ) );
        }

        List<Pattern> excludePatterns = new ArrayList();
        for ( String exclude : excludes ) {
            excludePatterns.add( Pattern.compile( exclude, Pattern.CASE_INSENSITIVE ) );
        }

        scanDir( rootDir );

        for ( Iterator matchIter = matches.iterator(); matchIter.hasNext(); ) {
            String filePath = (String) matchIter.next();
            for ( Pattern exclude : excludePatterns ) {
                if ( exclude.matcher( filePath ).matches() ) {
                    matchIter.remove();
                }
            }
        }
    }

    private void scanDir( File dir ) {
        for ( File file : dir.listFiles() ) {
            for ( Pattern include : includePatterns ) {
                String filePath = file.getPath().substring( rootDir.getPath().length() + 1 );
                if ( include.matcher( filePath ).matches() ) {
                    matches.add( filePath );
                    break;
                }
            }
            if ( file.isDirectory() ) {
                scanDir( file );
            }
        }
    }

    public List<String> matches() {
        return matches;
    }

    public File rootDir() {
        return rootDir;
    }

    public static void main( String[] args ) {
        // System.out.println(new Paths("C:\\Java\\ls", "**"));
        List<String> includes = new ArrayList();
        includes.add( "core[^T]+php" );
        // includes.add(".*/lavaserver/.*");
        List<String> excludes = new ArrayList();
        // excludes.add("website/**/doc**");
        long start = System.nanoTime();
        List<String> files = new RegexScanner( new File( "..\\website\\includes" ), includes, excludes ).matches();
        long end = System.nanoTime();
        System.out.println( files.toString().replaceAll( ", ", "\n" ).replaceAll( "[\\[\\]]", "" ) );
        System.out.println( (end - start) / 1000000f );
    }
}

Commits for litesoft/trunk/Java/ScarPlus/src/com/esotericsoftware/wildcard/RegexScanner.java

Diff revisions: vs.
Revision Author Commited Message
974 Diff Diff GeorgeS picture GeorgeS Mon 25 Aug, 2014 00:35:54 +0000

Updated to support usage specific artifact repositories

959 Diff Diff GeorgeS picture GeorgeS Sat 19 Jul, 2014 15:27:50 +0000

Scar update

950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

943 Diff Diff GeorgeS picture GeorgeS Tue 03 Jun, 2014 04:25:50 +0000

Extracting commonfoundation

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

315 Diff Diff GeorgeS picture GeorgeS Sun 17 Jul, 2011 15:48:36 +0000
287 Diff Diff GeorgeS picture GeorgeS Mon 20 Jun, 2011 06:24:24 +0000
182 GeorgeS picture GeorgeS Sat 23 Apr, 2011 00:19:10 +0000