View Javadoc

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  
24  /**
25   * Filter to only retain objects in the given artifactScope or better.
26   *
27   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
28   * @version $Id: AbstractScopeArtifactFilter.java 829934 2009-10-26 20:16:00Z bentmann $
29   */
30  abstract class AbstractScopeArtifactFilter
31      implements ArtifactFilter
32  {
33  
34      private boolean compileScope;
35  
36      private boolean runtimeScope;
37  
38      private boolean testScope;
39  
40      private boolean providedScope;
41  
42      private boolean systemScope;
43  
44      void addScopeInternal( String scope )
45      {
46          if ( Artifact.SCOPE_COMPILE.equals( scope ) )
47          {
48              systemScope = true;
49              providedScope = true;
50              compileScope = true;
51          }
52          else if ( Artifact.SCOPE_RUNTIME.equals( scope ) )
53          {
54              compileScope = true;
55              runtimeScope = true;
56          }
57          else if ( Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals( scope ) )
58          {
59              systemScope = true;
60              providedScope = true;
61              compileScope = true;
62              runtimeScope = true;
63          }
64          else if ( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals( scope ) )
65          {
66              systemScope = true;
67              compileScope = true;
68              runtimeScope = true;
69          }
70          else if ( Artifact.SCOPE_TEST.equals( scope ) )
71          {
72              systemScope = true;
73              providedScope = true;
74              compileScope = true;
75              runtimeScope = true;
76              testScope = true;
77          }
78      }
79  
80      public boolean include( Artifact artifact )
81      {
82          if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
83          {
84              return compileScope;
85          }
86          else if ( Artifact.SCOPE_RUNTIME.equals( artifact.getScope() ) )
87          {
88              return runtimeScope;
89          }
90          else if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
91          {
92              return testScope;
93          }
94          else if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) )
95          {
96              return providedScope;
97          }
98          else if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
99          {
100             return systemScope;
101         }
102         else
103         {
104             return true;
105         }
106     }
107 
108 }