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.ant.tasks.support;
20  
21  import org.apache.maven.artifact.Artifact;
22  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
23  
24  /**
25   * Filter to only retain objects in the given scope(s).
26   *
27   * @author pgier
28   */
29  public class SpecificScopesArtifactFilter implements ArtifactFilter {
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      /**
41       * Takes a comma separated list of scopes to include.
42       *
43       * @param scopes A comma separated list of scopes
44       */
45      public SpecificScopesArtifactFilter(String scopes) {
46          String[] scopeList = scopes.split(",");
47  
48          for (String aScopeList : scopeList) {
49              if (aScopeList.trim().equals(Artifact.SCOPE_COMPILE)) {
50                  compileScope = true;
51              } else if (aScopeList.trim().equals(Artifact.SCOPE_PROVIDED)) {
52                  providedScope = true;
53              } else if (aScopeList.trim().equals(Artifact.SCOPE_RUNTIME)) {
54                  runtimeScope = true;
55              } else if (aScopeList.trim().equals(Artifact.SCOPE_SYSTEM)) {
56                  systemScope = true;
57              } else if (aScopeList.trim().equals(Artifact.SCOPE_TEST)) {
58                  testScope = true;
59              }
60          }
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public boolean include(Artifact artifact) {
66          if (Artifact.SCOPE_COMPILE.equals(artifact.getScope())) {
67              return compileScope;
68          } else if (Artifact.SCOPE_RUNTIME.equals(artifact.getScope())) {
69              return runtimeScope;
70          } else if (Artifact.SCOPE_TEST.equals(artifact.getScope())) {
71              return testScope;
72          } else if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
73              return providedScope;
74          } else if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
75              return systemScope;
76          } else {
77              return true;
78          }
79      }
80  }