KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > artifact > resolver > filter > ScopeArtifactFilter


1 package org.apache.maven.artifact.resolver.filter;
2
3 import org.apache.maven.artifact.Artifact;
4 import org.apache.maven.artifact.DefaultArtifact;
5
6 /*
7  * Copyright 2001-2005 The Apache Software Foundation.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 /**
23  * Filter to only retain objects in the given scope or better.
24  *
25  * @author <a HREF="mailto:brett@apache.org">Brett Porter</a>
26  * @version $Id: ScopeArtifactFilter.java 326363 2005-10-19 03:53:10Z brett $
27  */

28 public class ScopeArtifactFilter
29     implements ArtifactFilter
30 {
31     private final boolean compileScope;
32
33     private final boolean runtimeScope;
34
35     private final boolean testScope;
36
37     private final boolean providedScope;
38
39     private final boolean systemScope;
40
41     public ScopeArtifactFilter( String JavaDoc scope )
42     {
43         if ( DefaultArtifact.SCOPE_COMPILE.equals( scope ) )
44         {
45             systemScope = true;
46             providedScope = true;
47             compileScope = true;
48             runtimeScope = false;
49             testScope = false;
50         }
51         else if ( DefaultArtifact.SCOPE_RUNTIME.equals( scope ) )
52         {
53             systemScope = false;
54             providedScope = false;
55             compileScope = true;
56             runtimeScope = true;
57             testScope = false;
58         }
59         else if ( DefaultArtifact.SCOPE_TEST.equals( scope ) )
60         {
61             systemScope = true;
62             providedScope = true;
63             compileScope = true;
64             runtimeScope = true;
65             testScope = true;
66         }
67         else
68         {
69             systemScope = false;
70             providedScope = false;
71             compileScope = false;
72             runtimeScope = false;
73             testScope = false;
74         }
75     }
76
77     public boolean include( Artifact artifact )
78     {
79         if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
80         {
81             return compileScope;
82         }
83         else if ( Artifact.SCOPE_RUNTIME.equals( artifact.getScope() ) )
84         {
85             return runtimeScope;
86         }
87         else if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
88         {
89             return testScope;
90         }
91         else if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) )
92         {
93             return providedScope;
94         }
95         else if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
96         {
97             return systemScope;
98         }
99         else
100         {
101             return true;
102         }
103     }
104 }
105
Popular Tags