2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.ivy.plugins.version;
20
import java.util.ArrayList;
21
import java.util.HashMap;
22
import java.util.List;
24
import java.util.StringTokenizer;
26
import org.apache.ivy.core.IvyContext;
27
import org.apache.ivy.core.IvyPatternHelper;
28
import org.apache.ivy.core.module.id.ModuleRevisionId;
29
import org.apache.ivy.plugins.matcher.Matcher;
30
import org.apache.ivy.plugins.matcher.PatternMatcher;
36
private String revision;
38
private String pattern;
42
private String matcher;
44
public String getArgs() {
48
public void setArgs(String args) {
52
public String getMatcher() {
56
public void setMatcher(String matcher) {
57
this.matcher = matcher;
60
public String getPattern() {
64
public void setPattern(String pattern) {
65
this.pattern = pattern;
68
public String getRevision() {
72
public void setRevision(String revision) {
73
this.revision = revision;
76
public Matcher getPatternMatcher(ModuleRevisionId askedMrid) {
77
String revision = askedMrid.getRevision();
79
String[] args = split(getArgs());
80
String[] argValues = getRevisionArgs(revision);
82
if (args.length != argValues.length) {
83
return new NoMatchMatcher();
86
Map variables = new HashMap();
87
for (int i = 0; i < args.length; i++) {
88
variables.put(args[i], argValues[i]);
91
String pattern = getPattern();
92
pattern = IvyPatternHelper.substituteVariables(pattern, variables);
94
PatternMatcher pMatcher = IvyContext.getContext().getSettings().getMatcher(matcher);
95
return pMatcher.getMatcher(pattern);
98
private String[] getRevisionArgs(String revision) {
99
int bracketStartIndex = revision.indexOf('(');
100
if (bracketStartIndex == -1) {
101
return new String[0];
104
int bracketEndIndex = revision.indexOf(')');
105
if (bracketEndIndex <= (bracketStartIndex + 1)) {
106
return new String[0];
109
String args = revision.substring(bracketStartIndex + 1, bracketEndIndex);
113
private static String[] split(String string) {
114
if (string == null) {
115
return new String[0];
118
StringTokenizer tokenizer = new StringTokenizer(string, ", ");
119
List tokens = new ArrayList();
120
while (tokenizer.hasMoreTokens()) {
121
tokens.add(tokenizer.nextToken());
124
return (String[]) tokens.toArray(new String[tokens.size()]);
127
private static class NoMatchMatcher implements Matcher {
128
public boolean isExact() {
132
public boolean matches(String str) {