/
AbstractModuleExclusion.java
118 lines (103 loc) · 3.68 KB
/
AbstractModuleExclusion.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes;
import org.gradle.api.artifacts.ModuleIdentifier;
import org.gradle.internal.component.model.IvyArtifactName;
import java.util.Collection;
abstract class AbstractModuleExclusion implements ModuleExclusion {
private int hashCode = -1;
private ModuleExclusion lastCheck;
private boolean lastCheckResult;
protected static boolean isWildcard(String attribute) {
return PatternMatchers.ANY_EXPRESSION.equals(attribute);
}
public boolean excludeArtifact(ModuleIdentifier module, IvyArtifactName artifact) {
return false;
}
public boolean mayExcludeArtifacts() {
return false;
}
public final boolean excludesSameModulesAs(ModuleExclusion filter) {
if (filter == this) {
return true;
}
AbstractModuleExclusion other = (AbstractModuleExclusion) filter;
boolean thisExcludesNothing = excludesNoModules();
boolean otherExcludesNothing = other.excludesNoModules();
if (thisExcludesNothing && otherExcludesNothing) {
return true;
}
if (thisExcludesNothing || otherExcludesNothing) {
return false;
}
if (!other.getClass().equals(getClass())) {
return false;
}
synchronized (this) {
// This is an optimization, based on the fact that in a large amount of times
// a specific exclusion is checked against the same filter the next time so
// we don't need to recompute the result: we can cache the last query
if (filter == lastCheck) {
return lastCheckResult;
}
lastCheck = other;
lastCheckResult = doExcludesSameModulesAs(other);
return lastCheckResult;
}
}
/**
* Only called when this and the other spec have the same class.
*/
protected boolean doExcludesSameModulesAs(AbstractModuleExclusion other) {
return false;
}
protected boolean excludesNoModules() {
return false;
}
/**
* Possibly unpack a composite spec into it's constituent parts, if those parts are applied as an intersection.
* @param specs
*/
protected void unpackEither(Collection<AbstractModuleExclusion> specs) {
specs.add(this);
}
/**
* Possibly unpack a composite spec into it's constituent parts, if those parts are applied as a union.
*/
protected void unpackAll(Collection<AbstractModuleExclusion> specs) {
specs.add(this);
}
@Override
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || obj.getClass() != getClass()) {
return false;
}
return doEquals(obj);
}
protected abstract boolean doEquals(Object obj);
@Override
public final int hashCode() {
if (hashCode != -1) {
return hashCode;
}
hashCode = doHashCode();
return hashCode;
}
protected abstract int doHashCode();
}