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