Subversion Repository Public Repository

litesoft

Diff Revisions 308 vs 309 for /trunk/Java/ScarPlus/src/com/esotericsoftware/filesystem/Paths.java

Diff revisions: vs.
  @@ -101,7 +101,7 @@
101 101 */
102 102 public void glob( String dir, String... patterns )
103 103 {
104 - new DirPatterns( dir, patterns ).addTo( mPaths );
104 + new PathPatterns( dir, patterns ).addTo( mPaths );
105 105 }
106 106
107 107 // ^^^^^^^^^^^^^^^^^^^^^^^ Should These be supported as they can introduce potentially conflicting FileSubPaths ^^^^^^^^^^^^^^^^^^^^^^^
  @@ -337,30 +337,38 @@
337 337 }
338 338 }
339 339
340 - private static class DirPatterns
340 + private static class PathPatterns
341 341 {
342 - private File mDir;
342 + private File mPath;
343 343 private List<Pattern> mIncludes = new ArrayList<Pattern>();
344 344 private List<Pattern> mExcludes = new ArrayList<Pattern>();
345 345
346 - public DirPatterns( String pDir, String[] pPatterns )
346 + public PathPatterns( String pPath, String[] pPatterns )
347 347 {
348 - pDir = Util.deNull( pDir, "." ).trim();
348 + pPath = Util.deNull( pPath, "." ).trim();
349 349 if ( pPatterns == null || pPatterns.length == 0 )
350 350 {
351 - String[] split = pDir.split( "\\|" ); // split on a '|'
352 - pDir = split[0].trim();
351 + String[] split = pPath.split( "\\|" ); // split on a '|'
352 + pPath = split[0].trim();
353 353 pPatterns = new String[split.length - 1];
354 354 for ( int i = 1, n = split.length; i < n; i++ )
355 355 {
356 356 pPatterns[i - 1] = split[i].trim();
357 357 }
358 358 }
359 - mDir = new File( pDir );
360 - if ( !mDir.isDirectory() )
359 + mPath = new File( pPath );
360 + if ( mPath.isFile() )
361 361 {
362 + if ( pPatterns.length != 0 )
363 + {
364 + throw new IllegalArgumentException( "Files (e.g. " + mPath + ") may NOT have patterns: " + Arrays.asList( pPatterns ) );
365 + }
362 366 return;
363 367 }
368 + if ( !mPath.isDirectory() )
369 + {
370 + throw new IllegalArgumentException( "Path Reference not a File or Directory: " + mPath );
371 + }
364 372 List<String> zIncludes = new ArrayList<String>();
365 373 List<String> zExcludes = new ArrayList<String>();
366 374 for ( String zPattern : pPatterns )
  @@ -401,12 +409,17 @@
401 409
402 410 public void addTo( Collection<FilePath> pPaths )
403 411 {
404 - if ( mDir.isDirectory() )
412 + if ( mPath.isFile() )
413 + {
414 + pPaths.add( new FilePath( mPath.getParentFile(), mPath.getName() ) );
415 + return;
416 + }
417 + if ( mPath.isDirectory() )
405 418 {
406 - String[] zFileNames = mDir.list();
419 + String[] zFileNames = mPath.list();
407 420 for ( String zFileName : zFileNames )
408 421 {
409 - File zFile = new File( mDir, zFileName );
422 + File zFile = new File( mPath, zFileName );
410 423 if ( zFile.isDirectory() )
411 424 {
412 425 if ( !excludedDir( zFileName ) && acceptableDir( zFileName ) )
  @@ -418,7 +431,7 @@
418 431 {
419 432 if ( !excludedFile( zFileName ) && acceptableFile( zFileName ) )
420 433 {
421 - pPaths.add( new FilePath( mDir, zFileName ) );
434 + pPaths.add( new FilePath( mPath, zFileName ) );
422 435 }
423 436 }
424 437 }
  @@ -443,7 +456,7 @@
443 456 {
444 457 if ( !excludedFile( zPath ) && acceptableFile( zPath ) )
445 458 {
446 - pPaths.add( new FilePath( mDir, zPath ) );
459 + pPaths.add( new FilePath( mPath, zPath ) );
447 460 }
448 461 }
449 462 }