1 package org.apache.maven.ant.tasks.support;
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.resolver.filter.ArtifactFilter;
24
25 /**
26 * Filter to only retain objects in the given scope(s).
27 *
28 * @author pgier
29 */
30 public class SpecificScopesArtifactFilter
31 implements ArtifactFilter
32 {
33 private boolean compileScope;
34
35 private boolean runtimeScope;
36
37 private boolean testScope;
38
39 private boolean providedScope;
40
41 private boolean systemScope;
42
43 /**
44 * Takes a comma separated list of scopes to include.
45 *
46 * @param scopes A comma separated list of scopes
47 */
48 public SpecificScopesArtifactFilter( String scopes )
49 {
50 String[] scopeList = scopes.split( "," );
51
52 for ( String aScopeList : scopeList )
53 {
54 if ( aScopeList.trim().equals( Artifact.SCOPE_COMPILE ) )
55 {
56 compileScope = true;
57 }
58 else if ( aScopeList.trim().equals( Artifact.SCOPE_PROVIDED ) )
59 {
60 providedScope = true;
61 }
62 else if ( aScopeList.trim().equals( Artifact.SCOPE_RUNTIME ) )
63 {
64 runtimeScope = true;
65 }
66 else if ( aScopeList.trim().equals( Artifact.SCOPE_SYSTEM ) )
67 {
68 systemScope = true;
69 }
70 else if ( aScopeList.trim().equals( Artifact.SCOPE_TEST ) )
71 {
72 testScope = true;
73 }
74 }
75 }
76
77 /** {@inheritDoc} */
78 @Override
79 public boolean include( Artifact artifact )
80 {
81 if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
82 {
83 return compileScope;
84 }
85 else if ( Artifact.SCOPE_RUNTIME.equals( artifact.getScope() ) )
86 {
87 return runtimeScope;
88 }
89 else if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
90 {
91 return testScope;
92 }
93 else if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) )
94 {
95 return providedScope;
96 }
97 else if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
98 {
99 return systemScope;
100 }
101 else
102 {
103 return true;
104 }
105 }
106 }