View Javadoc
1   /*
2    * (C) Copyright 2006-2014 Nuxeo SA (http://nuxeo.com/) and contributors.
3    *
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the GNU Lesser General Public License
6    * (LGPL) version 2.1 which accompanies this distribution, and is available at
7    * http://www.gnu.org/licenses/lgpl-2.1.html
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * Contributors:
15   *     bstefanescu, slacoin, jcarsique
16   */
17  package org.nuxeo.build.maven.filter;
18  
19  import java.util.List;
20  
21  import org.apache.maven.artifact.Artifact;
22  import org.eclipse.aether.graph.DependencyNode;
23  
24  /**
25   * TODO NXBT-258
26   */
27  public class TypeFilter extends AbstractFilter {
28  
29      @Override
30      public String toString() {
31          return super.toString() + " [" + matcher + "]";
32      }
33  
34      protected SegmentMatch matcher;
35  
36      public TypeFilter(String pattern) {
37          this(SegmentMatch.parse(pattern));
38      }
39  
40      public TypeFilter(SegmentMatch matcher) {
41          this.matcher = matcher;
42      }
43  
44      @Override
45      public boolean accept(Artifact artifact) {
46          return result(matcher.match(artifact.getType()), artifact.toString());
47      }
48  
49      @Override
50      public boolean accept(DependencyNode node, List<DependencyNode> parents) {
51          org.eclipse.aether.artifact.Artifact artifact = node.getArtifact();
52          if (artifact == null) {
53              return result(matcher == SegmentMatch.ANY, node.toString());
54          }
55          return result(matcher.match(artifact.getExtension()), node.toString());
56      }
57  
58  }