From d297eaef94117930751130fac9adec934a10023e Mon Sep 17 00:00:00 2001 From: Xavier Hanin Date: Tue, 31 Jan 2006 09:26:34 +0000 Subject: [PATCH] IMPROVE: add possibility to choose matcher on include exclude and conflict manager rules (IVY-161) git-svn-id: https://svn.apache.org/repos/asf/incubator/ivy/trunk@484195 13f79535-47bb-0310-9956-ffa450edef68 --- .../fr/jayasoft/ivy/matcher/AnyMatcher.java | 28 ++++++++++ .../ivy/matcher/GlobPatternMatcher.java | 55 +++++++++++++++++++ src/java/fr/jayasoft/ivy/matcher/Matcher.java | 12 ++++ 3 files changed, 95 insertions(+) create mode 100644 src/java/fr/jayasoft/ivy/matcher/AnyMatcher.java create mode 100644 src/java/fr/jayasoft/ivy/matcher/GlobPatternMatcher.java create mode 100644 src/java/fr/jayasoft/ivy/matcher/Matcher.java diff --git a/src/java/fr/jayasoft/ivy/matcher/AnyMatcher.java b/src/java/fr/jayasoft/ivy/matcher/AnyMatcher.java new file mode 100644 index 00000000..ffb4e1b4 --- /dev/null +++ b/src/java/fr/jayasoft/ivy/matcher/AnyMatcher.java @@ -0,0 +1,28 @@ +/* + * This file is subject to the licence found in LICENCE.TXT in the root directory of the project. + * Copyright Jayasoft 2005 - All rights reserved + * + * #SNAPSHOT# + */ +package fr.jayasoft.ivy.matcher; + +public class AnyMatcher implements Matcher { + private final static Matcher INSTANCE = new AnyMatcher(); + + public static Matcher getInstance() { + return INSTANCE; + } + + private AnyMatcher() { + + } + + public boolean matches(String str) { + return true; + } + + public boolean isExact() { + return false; + } + +} diff --git a/src/java/fr/jayasoft/ivy/matcher/GlobPatternMatcher.java b/src/java/fr/jayasoft/ivy/matcher/GlobPatternMatcher.java new file mode 100644 index 00000000..d2b5619c --- /dev/null +++ b/src/java/fr/jayasoft/ivy/matcher/GlobPatternMatcher.java @@ -0,0 +1,55 @@ +/* + * This file is subject to the licence found in LICENCE.TXT in the root directory of the project. + * Copyright Jayasoft 2005 - All rights reserved + * + * #SNAPSHOT# + */ +package fr.jayasoft.ivy.matcher; + +import org.apache.oro.text.GlobCompiler; +import org.apache.oro.text.regex.MalformedPatternException; +import org.apache.oro.text.regex.Pattern; +import org.apache.oro.text.regex.Perl5Matcher; + +import fr.jayasoft.ivy.util.Message; + + +public final class GlobPatternMatcher implements PatternMatcher { + public static class GlobMatcher implements Matcher { + private Pattern _p; + + public GlobMatcher(String exp) { + try { + _p = new GlobCompiler().compile(exp); + } catch (MalformedPatternException e) { + Message.error("impossible to compile glob pattern: "+exp); + } + } + + public boolean matches(String str) { + return _p != null && new Perl5Matcher().matches(str, _p); + } + + public boolean isExact() { + return false; + } + } + private static final GlobPatternMatcher INSTANCE = new GlobPatternMatcher(); + public static PatternMatcher getInstance() { + return INSTANCE; + } + + private GlobPatternMatcher() { + } + + public String getName() { + return GLOB; + } + + public Matcher getMatcher(String exp) { + if (ANY_EXPRESSION.equals(exp)) { + return AnyMatcher.getInstance(); + } + return new GlobMatcher(exp); + } +} diff --git a/src/java/fr/jayasoft/ivy/matcher/Matcher.java b/src/java/fr/jayasoft/ivy/matcher/Matcher.java new file mode 100644 index 00000000..d6a9e820 --- /dev/null +++ b/src/java/fr/jayasoft/ivy/matcher/Matcher.java @@ -0,0 +1,12 @@ +/* + * This file is subject to the licence found in LICENCE.TXT in the root directory of the project. + * Copyright Jayasoft 2005 - All rights reserved + * + * #SNAPSHOT# + */ +package fr.jayasoft.ivy.matcher; + +public interface Matcher { + public boolean matches(String str); + public boolean isExact(); +}