1 /* 2 * Copyright 2013 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.maven.plugin.jboss.modules.aether; 17 18 import java.util.List; 19 20 import org.sonatype.aether.artifact.Artifact; 21 import org.sonatype.aether.collection.DependencyTraverser; 22 import org.sonatype.aether.graph.Dependency; 23 24 import de.smartics.maven.plugin.jboss.modules.descriptor.ArtifactClusion; 25 import de.smartics.maven.plugin.jboss.modules.descriptor.ModuleDescriptor; 26 27 /** 28 * Prunes the dependency tree upon information on excluded artifacts and skipped 29 * modules. 30 */ 31 public class PruningDependencyTraverser extends DelegateDependencyTraverser 32 { 33 // ********************************* Fields ********************************* 34 35 // --- constants ------------------------------------------------------------ 36 37 // --- members -------------------------------------------------------------- 38 39 /** 40 * The artifacts to exclude. 41 */ 42 private final List<ArtifactClusion> exclusions; 43 44 /** 45 * The list of modules to skip. 46 */ 47 private final List<ModuleDescriptor> skipModules; 48 49 // ****************************** Initializer ******************************* 50 51 // ****************************** Constructors ****************************** 52 53 /** 54 * Default constructor. 55 * 56 * @param delegate the traverse to delegate to after own check is not 57 * rejecting. 58 * @param exclusions the artifacts to exclude. 59 * @param skipModules the list of modules to skip. 60 * @throws NullPointerException if {@code delegate} is <code>null</code>. 61 */ 62 public PruningDependencyTraverser(final DependencyTraverser delegate, 63 final List<ArtifactClusion> exclusions, final List<ModuleDescriptor> skipModules) 64 throws NullPointerException 65 { 66 super(delegate); 67 this.exclusions = exclusions; 68 this.skipModules = skipModules; 69 } 70 71 // ****************************** Inner Classes ***************************** 72 73 // ********************************* Methods ******************************** 74 75 // --- init ----------------------------------------------------------------- 76 77 // --- get&set -------------------------------------------------------------- 78 79 // --- business ------------------------------------------------------------- 80 81 @Override 82 protected boolean doTraverseDependency(final Dependency dependency) 83 { 84 final Artifact artifact = dependency.getArtifact(); 85 for (final ArtifactClusion exclusion : exclusions) 86 { 87 final boolean exclude = exclusion.matches(artifact).isMatched(); 88 if (exclude) 89 { 90 return false; 91 } 92 } 93 94 for (final ModuleDescriptor module : skipModules) 95 { 96 final boolean exclude = module.match(artifact).isMatched(); 97 if (exclude) 98 { 99 return false; 100 } 101 } 102 103 return true; 104 } 105 106 // --- object basics -------------------------------------------------------- 107 108 }