01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.plugins.matcher;
19:
20: import org.apache.ivy.core.module.id.ArtifactId;
21: import org.apache.ivy.core.module.id.ModuleId;
22: import org.apache.ivy.core.module.id.ModuleRevisionId;
23:
24: /**
25: * Set of helper methods to match ModuleId, ModuleRevisionId, ArtifactId
26: */
27: public final class MatcherHelper {
28: // TODO this class might be better off as MatcherUtils in util package
29:
30: private MatcherHelper() {
31: }
32:
33: public static boolean matches(PatternMatcher m, String expression,
34: String input) {
35: return m.getMatcher(expression).matches(input);
36: }
37:
38: public static boolean matches(PatternMatcher m, ModuleId exp,
39: ModuleId mid) {
40: return matches(m, exp.getOrganisation(), mid.getOrganisation())
41: && matches(m, exp.getName(), mid.getName());
42: }
43:
44: public static boolean matches(PatternMatcher m,
45: ModuleRevisionId exp, ModuleRevisionId mrid) {
46: return matches(m, exp.getOrganisation(), mrid.getOrganisation())
47: && matches(m, exp.getName(), mrid.getName())
48: && matches(m, exp.getRevision(), mrid.getRevision());
49: }
50:
51: public static boolean matches(PatternMatcher m, ArtifactId exp,
52: ArtifactId aid) {
53: return matches(m, exp.getModuleId(), aid.getModuleId())
54: && matches(m, exp.getName(), aid.getName())
55: && matches(m, exp.getExt(), aid.getExt())
56: && matches(m, exp.getType(), aid.getType());
57: }
58:
59: public static boolean isExact(PatternMatcher m, ModuleRevisionId exp) {
60: return isExact(m, exp.getOrganisation())
61: && isExact(m, exp.getName())
62: && isExact(m, exp.getRevision());
63: }
64:
65: // unused
66: public static boolean isExact(PatternMatcher m, ModuleId exp) {
67: return isExact(m, exp.getOrganisation())
68: && isExact(m, exp.getName());
69: }
70:
71: public static boolean isExact(PatternMatcher m, String exp) {
72: return m.getMatcher(exp).isExact();
73: }
74: }
|