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.core.module.descriptor;
19:
20: import java.util.ArrayList;
21: import java.util.Collection;
22: import java.util.Map;
23:
24: import org.apache.ivy.core.IvyPatternHelper;
25: import org.apache.ivy.core.module.id.ArtifactId;
26: import org.apache.ivy.plugins.matcher.PatternMatcher;
27: import org.apache.ivy.util.extendable.UnmodifiableExtendableItem;
28:
29: /**
30: * Abstract class used as implementation for both {@link IncludeRule} and {@link ExcludeRule},
31: * since their contract is almost identical
32: */
33: public abstract class AbstractIncludeExcludeRule extends
34: UnmodifiableExtendableItem implements ConfigurationAware {
35:
36: private ArtifactId id;
37:
38: private Collection confs = new ArrayList();
39:
40: private PatternMatcher patternMatcher;
41:
42: public AbstractIncludeExcludeRule(ArtifactId aid,
43: PatternMatcher matcher, Map extraAttributes) {
44: super (null, extraAttributes);
45: id = aid;
46: patternMatcher = matcher;
47: initStandardAttributes();
48: }
49:
50: private void initStandardAttributes() {
51: setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, id
52: .getModuleId().getOrganisation());
53: setStandardAttribute(IvyPatternHelper.MODULE_KEY, id
54: .getModuleId().getName());
55: setStandardAttribute(IvyPatternHelper.ARTIFACT_KEY, id
56: .getName());
57: setStandardAttribute(IvyPatternHelper.TYPE_KEY, id.getType());
58: setStandardAttribute(IvyPatternHelper.EXT_KEY, id.getExt());
59: setStandardAttribute("matcher", patternMatcher.getName());
60: }
61:
62: public boolean equals(Object obj) {
63: if (!(obj instanceof AbstractIncludeExcludeRule)) {
64: return false;
65: }
66: AbstractIncludeExcludeRule rule = (AbstractIncludeExcludeRule) obj;
67: return getId().equals(rule.getId());
68: }
69:
70: public int hashCode() {
71: return getId().hashCode();
72: }
73:
74: /**
75: * Add a configuration for this rule
76: *
77: * @param conf
78: */
79: public void addConfiguration(String conf) {
80: confs.add(conf);
81: }
82:
83: public ArtifactId getId() {
84: return id;
85: }
86:
87: public String[] getConfigurations() {
88: return (String[]) confs.toArray(new String[confs.size()]);
89: }
90:
91: public PatternMatcher getMatcher() {
92: return patternMatcher;
93: }
94:
95: public String toString() {
96: return id + "(" + confs + ")";
97: }
98: }
|