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   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
27   */
28  abstract class AbstractScopeArtifactFilter implements ArtifactFilter {
29  
30      private boolean compileScope;
31  
32      private boolean runtimeScope;
33  
34      private boolean testScope;
35  
36      private boolean providedScope;
37  
38      private boolean systemScope;
39  
40      void addScopeInternal(String scope) {
41          if (Artifact.SCOPE_COMPILE.equals(scope)) {
42              systemScope = true;
43              providedScope = true;
44              compileScope = true;
45          } else if (Artifact.SCOPE_RUNTIME.equals(scope)) {
46              compileScope = true;
47              runtimeScope = true;
48          } else if (Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals(scope)) {
49              systemScope = true;
50              providedScope = true;
51              compileScope = true;
52              runtimeScope = true;
53          } else if (Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals(scope)) {
54              systemScope = true;
55              compileScope = true;
56              runtimeScope = true;
57          } else if (Artifact.SCOPE_TEST.equals(scope)) {
58              systemScope = true;
59              providedScope = true;
60              compileScope = true;
61              runtimeScope = true;
62              testScope = true;
63          }
64      }
65  
66      public boolean include(Artifact artifact) {
67          if (Artifact.SCOPE_COMPILE.equals(artifact.getScope())) {
68              return compileScope;
69          } else if (Artifact.SCOPE_RUNTIME.equals(artifact.getScope())) {
70              return runtimeScope;
71          } else if (Artifact.SCOPE_TEST.equals(artifact.getScope())) {
72              return testScope;
73          } else if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
74              return providedScope;
75          } else if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
76              return systemScope;
77          } else {
78              return true;
79          }
80      }
81  }