Chapter 10. Spring.NET miscellanea

The Spring.NET Framework

Chapter 10. Spring.NET miscellanea

10.1. Introduction

This chapter contains miscellanea information on features, goodies, caveats that does not belong to any paricular area.

10.2. PathMatcher

Note, Spring.Util.PathMatcher is currently only available in CVS, not the RC3 release. If you want to use these feature please get the code from CVS (instructions) or from the download section of the Spring.NET website that contains an .zip with the full CVS tree.

Spring.Util.PathMatcher provides Ant/NAnt-like path name matching features.

To do the match, you use the method:

static bool Match(string pattern, string path)

If you want to decide if case is important or not use the method:

static bool Match(string pattern, string path, bool ignoreCase)

10.2.1. General rules

To build your pattern, you use the *, ? and ** building blocks:

  • *: matches any number of non slash characters;

  • ?: matches exactly 1 (one) non slash/dot character;

  • **: matches any subdirectory, without taking care of the depth;

10.2.2. Matching filenames

A file name can be matched using the following notation:

foo?bar.*

matches:

fooAbar.txt
foo1bar.txt
foo_bar.txt
foo-bar.txt

does not match:

foo.bar.txt
foo/bar.txt
foo\bar.txt

The classical all files pattern:

*.*

matches:

foo.db
.db
foo
foo.bar.db
foo.db.db
db.db.db

does not match:

c:/
c:/foo.db
c:/foo
c:/.db
c:/foo.foo.db
//server/foo

10.2.3. Matching subdirectories

A directory name can be matched at any depth level using the following notation:

**/db/**

That pattern matches the following paths:

/db
//server/db
c:/db
c:/spring/app/db/foo.db
//Program Files/App/spaced dir/db/foo.db
/home/spring/spaced dir/db/v1/foo.db

but does not match these:

c:/spring/app/db-v1/foo.db
/home/spring/spaced dir/db-v1/foo.db

You can compose subdirectories to match like this:

**/bin/**/tmp/**

That pattern matches the following paths:

c:/spring/foo/bin/bar/tmp/a
c:/spring/foo/bin/tmp/a/b.c

but does not match these:

c:/spring/foo/bin/bar/temp/a
c:/tmp/foo/bin/bar/a/b.c

You can use more advanced patterns:

**/.spring-assemblies*/**

matches:

c:/.spring-assemblies
c:/.spring-assembliesabcd73xs
c:/app/.spring-assembliesabcd73xs
c:/app/.spring-assembliesabcd73xs/foo.dll
//server/app/.spring-assembliesabcd73xs

does not match:

c:/app/.spring-assemblie

10.2.4. Case does matter, slashes don't

.NET is expected to be a cross-platform development ... platform. So, PathMatcher will match taking care of the case of the pattern and the case of the path. For example:

**/db/**/*.DB

matches:

c:/spring/service/deploy/app/db/foo.DB

but does not match:

c:/spring/service/deploy/app/DB/foo.DB
c:spring/service/deploy/app/spaced dir/DB/foo.DB
//server/share/service/deploy/app/DB/backup/foo.db

If you do not matter about case, you should explicitly tell the Pathmatcher.

Back and forward slashes, in the very same cross-platform spirit, are not important:

spring/foo.bar

matches all the following paths:

c:\spring\foo.bar
c:/spring\foo.bar
c:/spring/foo.bar
/spring/foo.bar
\spring\foo.bar