1
- package org .apache .maven .shared .artifact .filter ;
2
-
3
1
/*
4
2
* Licensed to the Apache Software Foundation (ASF) under one
5
3
* or more contributor license agreements. See the NOTICE file
9
7
* "License"); you may not use this file except in compliance
10
8
* with the License. You may obtain a copy of the License at
11
9
*
12
- * http://www.apache.org/licenses/LICENSE-2.0
10
+ * http://www.apache.org/licenses/LICENSE-2.0
13
11
*
14
12
* Unless required by applicable law or agreed to in writing,
15
13
* software distributed under the License is distributed on an
18
16
* specific language governing permissions and limitations
19
17
* under the License.
20
18
*/
19
+ package org .apache .maven .shared .artifact .filter ;
20
+
21
+ import java .util .List ;
21
22
22
23
import org .apache .maven .artifact .Artifact ;
23
24
import org .apache .maven .artifact .resolver .filter .ArtifactFilter ;
24
25
import org .apache .maven .artifact .versioning .DefaultArtifactVersion ;
25
26
import org .apache .maven .artifact .versioning .InvalidVersionSpecificationException ;
26
27
import org .apache .maven .artifact .versioning .VersionRange ;
27
28
28
- import java .util .List ;
29
-
30
29
/**
31
30
* Filter to include or exclude artifacts from a list of patterns. The artifact pattern syntax is of the form:
32
31
*
44
43
*
45
44
* @author <a href="mailto:[email protected] ">Mark Hobson</a>
46
45
*/
47
- public abstract class AbstractStrictPatternArtifactFilter implements ArtifactFilter
48
- {
46
+ public abstract class AbstractStrictPatternArtifactFilter implements ArtifactFilter {
49
47
// fields -----------------------------------------------------------------
50
48
51
49
/**
@@ -70,23 +68,19 @@ public abstract class AbstractStrictPatternArtifactFilter implements ArtifactFil
70
68
* <code>true</code> to include artifacts that match the patterns, or <code>false</code> to exclude
71
69
* them
72
70
*/
73
- public AbstractStrictPatternArtifactFilter ( List <String > patterns , boolean include )
74
- {
71
+ public AbstractStrictPatternArtifactFilter (List <String > patterns , boolean include ) {
75
72
this .patterns = patterns ;
76
73
this .include = include ;
77
74
}
78
75
79
76
// ArtifactFilter methods -------------------------------------------------
80
77
81
78
/** {@inheritDoc} */
82
- public boolean include ( Artifact artifact )
83
- {
79
+ public boolean include (Artifact artifact ) {
84
80
boolean matched = false ;
85
81
86
- for ( String pattern : patterns )
87
- {
88
- if ( include ( artifact , pattern ) )
89
- {
82
+ for (String pattern : patterns ) {
83
+ if (include (artifact , pattern )) {
90
84
matched = true ;
91
85
break ;
92
86
}
@@ -99,96 +93,79 @@ public boolean include( Artifact artifact )
99
93
100
94
/**
101
95
* Gets whether the specified artifact matches the specified pattern.
102
- *
96
+ *
103
97
* @param artifact
104
98
* the artifact to check
105
99
* @param pattern
106
100
* the pattern to match, as defined above
107
101
* @return <code>true</code> if the specified artifact is matched by the specified pattern
108
102
*/
109
- private boolean include ( Artifact artifact , String pattern )
110
- {
103
+ private boolean include (Artifact artifact , String pattern ) {
111
104
String [] tokens = new String [] {
112
- artifact .getGroupId (),
113
- artifact .getArtifactId (),
114
- artifact .getType (),
115
- artifact .getBaseVersion ()
105
+ artifact .getGroupId (), artifact .getArtifactId (), artifact .getType (), artifact .getBaseVersion ()
116
106
};
117
107
118
- String [] patternTokens = pattern .split ( ":" );
108
+ String [] patternTokens = pattern .split (":" );
119
109
120
110
// fail immediately if pattern tokens outnumber tokens to match
121
111
boolean matched = patternTokens .length <= tokens .length ;
122
112
123
- for ( int i = 0 ; matched && i < patternTokens .length ; i ++ )
124
- {
125
- matched = matches ( tokens [i ], patternTokens [i ] );
113
+ for (int i = 0 ; matched && i < patternTokens .length ; i ++) {
114
+ matched = matches (tokens [i ], patternTokens [i ]);
126
115
}
127
116
128
117
return matched ;
129
118
}
130
119
131
120
/**
132
121
* Gets whether the specified token matches the specified pattern segment.
133
- *
122
+ *
134
123
* @param token
135
124
* the token to check
136
125
* @param pattern
137
126
* the pattern segment to match, as defined above
138
127
* @return <code>true</code> if the specified token is matched by the specified pattern segment
139
128
*/
140
- private boolean matches ( String token , String pattern )
141
- {
129
+ private boolean matches (String token , String pattern ) {
142
130
boolean matches ;
143
131
144
132
// support full wildcard and implied wildcard
145
- if ( "*" .equals ( pattern ) || pattern .length () == 0 )
146
- {
133
+ if ("*" .equals (pattern ) || pattern .length () == 0 ) {
147
134
matches = true ;
148
135
}
149
136
// support contains wildcard
150
- else if ( pattern .startsWith ( "*" ) && pattern .endsWith ( "*" ) )
151
- {
152
- String contains = pattern .substring ( 1 , pattern .length () - 1 );
137
+ else if (pattern .startsWith ("*" ) && pattern .endsWith ("*" )) {
138
+ String contains = pattern .substring (1 , pattern .length () - 1 );
153
139
154
- matches = token .contains ( contains );
140
+ matches = token .contains (contains );
155
141
}
156
142
// support leading wildcard
157
- else if ( pattern .startsWith ( "*" ) )
158
- {
159
- matches = token .endsWith ( pattern .substring ( 1 ) );
143
+ else if (pattern .startsWith ("*" )) {
144
+ matches = token .endsWith (pattern .substring (1 ));
160
145
}
161
146
// support trailing wildcard
162
- else if ( pattern .endsWith ( "*" ) )
163
- {
164
- String prefix = pattern .substring ( 0 , pattern .length () - 1 );
147
+ else if (pattern .endsWith ("*" )) {
148
+ String prefix = pattern .substring (0 , pattern .length () - 1 );
165
149
166
- matches = token .startsWith ( prefix );
150
+ matches = token .startsWith (prefix );
167
151
}
168
- // support versions range
169
- else if ( pattern .startsWith ( "[" ) || pattern .startsWith ( "(" ) )
170
- {
171
- matches = isVersionIncludedInRange ( token , pattern );
152
+ // support versions range
153
+ else if (pattern .startsWith ("[" ) || pattern .startsWith ("(" )) {
154
+ matches = isVersionIncludedInRange (token , pattern );
172
155
}
173
156
// support exact match
174
- else
175
- {
176
- matches = token .equals ( pattern );
157
+ else {
158
+ matches = token .equals (pattern );
177
159
}
178
160
179
161
return matches ;
180
162
}
181
163
182
- private boolean isVersionIncludedInRange ( final String version , final String range )
183
- {
184
- try
185
- {
186
- return VersionRange .createFromVersionSpec ( range ).containsVersion ( new DefaultArtifactVersion ( version ) );
187
- }
188
- catch ( InvalidVersionSpecificationException e )
189
- {
164
+ private boolean isVersionIncludedInRange (final String version , final String range ) {
165
+ try {
166
+ return VersionRange .createFromVersionSpec (range ).containsVersion (new DefaultArtifactVersion (version ));
167
+ } catch (InvalidVersionSpecificationException e ) {
190
168
return false ;
191
169
}
192
170
}
193
-
194
171
}
0 commit comments