View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.artifact.resolver.filter;
20  
21  import org.apache.maven.artifact.Artifact;
22  
23  /**
24   * Filter to only retain objects in the given artifactScope or better.
25   *
26   */
27  abstract class AbstractScopeArtifactFilter implements ArtifactFilter {
28  
29      private boolean compileScope;
30  
31      private boolean runtimeScope;
32  
33      private boolean testScope;
34  
35      private boolean providedScope;
36  
37      private boolean systemScope;
38  
39      void addScopeInternal(String scope) {
40          if (Artifact.SCOPE_COMPILE.equals(scope)) {
41              systemScope = true;
42              providedScope = true;
43              compileScope = true;
44          } else if (Artifact.SCOPE_RUNTIME.equals(scope)) {
45              compileScope = true;
46              runtimeScope = true;
47          } else if (Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals(scope)) {
48              systemScope = true;
49              providedScope = true;
50              compileScope = true;
51              runtimeScope = true;
52          } else if (Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals(scope)) {
53              systemScope = true;
54              compileScope = true;
55              runtimeScope = true;
56          } else if (Artifact.SCOPE_TEST.equals(scope)) {
57              systemScope = true;
58              providedScope = true;
59              compileScope = true;
60              runtimeScope = true;
61              testScope = true;
62          }
63      }
64  
65      public boolean include(Artifact artifact) {
66          if (Artifact.SCOPE_COMPILE.equals(artifact.getScope())) {
67              return compileScope;
68          } else if (Artifact.SCOPE_RUNTIME.equals(artifact.getScope())) {
69              return runtimeScope;
70          } else if (Artifact.SCOPE_TEST.equals(artifact.getScope())) {
71              return testScope;
72          } else if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
73              return providedScope;
74          } else if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
75              return systemScope;
76          } else {
77              return true;
78          }
79      }
80  }