Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ScopeArtifactFilter |
|
| 7.5;7,5 |
1 | package org.apache.maven.artifact.resolver.filter; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import org.apache.maven.artifact.Artifact; | |
23 | import org.apache.maven.artifact.DefaultArtifact; | |
24 | ||
25 | /** | |
26 | * Filter to only retain objects in the given scope or better. | |
27 | * | |
28 | * @author <a href="mailto:brett@apache.org">Brett Porter</a> | |
29 | * @version $Id: ScopeArtifactFilter.java 495147 2007-01-11 07:47:53Z jvanzyl $ | |
30 | */ | |
31 | public class ScopeArtifactFilter | |
32 | implements ArtifactFilter | |
33 | { | |
34 | private final boolean compileScope; | |
35 | ||
36 | private final boolean runtimeScope; | |
37 | ||
38 | private final boolean testScope; | |
39 | ||
40 | private final boolean providedScope; | |
41 | ||
42 | private final boolean systemScope; | |
43 | ||
44 | public ScopeArtifactFilter( String scope ) | |
45 | 40 | { |
46 | 40 | if ( DefaultArtifact.SCOPE_COMPILE.equals( scope ) ) |
47 | { | |
48 | 23 | systemScope = true; |
49 | 23 | providedScope = true; |
50 | 23 | compileScope = true; |
51 | 23 | runtimeScope = false; |
52 | 23 | testScope = false; |
53 | } | |
54 | 17 | else if ( DefaultArtifact.SCOPE_RUNTIME.equals( scope ) ) |
55 | { | |
56 | 11 | systemScope = false; |
57 | 11 | providedScope = false; |
58 | 11 | compileScope = true; |
59 | 11 | runtimeScope = true; |
60 | 11 | testScope = false; |
61 | } | |
62 | 6 | else if ( DefaultArtifact.SCOPE_TEST.equals( scope ) ) |
63 | { | |
64 | 6 | systemScope = true; |
65 | 6 | providedScope = true; |
66 | 6 | compileScope = true; |
67 | 6 | runtimeScope = true; |
68 | 6 | testScope = true; |
69 | } | |
70 | else | |
71 | { | |
72 | 0 | systemScope = false; |
73 | 0 | providedScope = false; |
74 | 0 | compileScope = false; |
75 | 0 | runtimeScope = false; |
76 | 0 | testScope = false; |
77 | } | |
78 | 40 | } |
79 | ||
80 | public boolean include( Artifact artifact ) | |
81 | { | |
82 | 769 | if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) ) |
83 | { | |
84 | 398 | return compileScope; |
85 | } | |
86 | 371 | else if ( Artifact.SCOPE_RUNTIME.equals( artifact.getScope() ) ) |
87 | { | |
88 | 25 | return runtimeScope; |
89 | } | |
90 | 346 | else if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) ) |
91 | { | |
92 | 19 | return testScope; |
93 | } | |
94 | 327 | else if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) ) |
95 | { | |
96 | 3 | return providedScope; |
97 | } | |
98 | 324 | else if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) ) |
99 | { | |
100 | 4 | return systemScope; |
101 | } | |
102 | else | |
103 | { | |
104 | 320 | return true; |
105 | } | |
106 | } | |
107 | } |