1 package org.apache.archiva.dependency.tree.maven2;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.maven2.model.Artifact;
22 import org.apache.archiva.maven2.model.TreeEntry;
23 import org.eclipse.aether.graph.DependencyVisitor;
24 import org.modelmapper.ModelMapper;
25 import org.modelmapper.convention.MatchingStrategies;
26 import org.eclipse.aether.graph.DependencyNode;
27 import org.eclipse.aether.graph.DependencyVisitor;
29 import java.util.List;
32 * @author Olivier Lamy
35 public class TreeDependencyNodeVisitor
36 implements DependencyVisitor
39 final List<TreeEntry> treeEntries;
41 private TreeEntry currentEntry;
43 private org.eclipse.aether.graph.DependencyNode firstDependencyNode;
45 public TreeDependencyNodeVisitor( List<TreeEntry> treeEntries )
47 this.treeEntries = treeEntries;
52 public boolean visitEnter( DependencyNode dependencyNode )
55 new TreeEntry( getModelMapper().map( dependencyNode.getDependency().getArtifact(), Artifact.class ) );
56 entry.getArtifact().setFileExtension( dependencyNode.getDependency().getArtifact().getExtension() );
57 entry.getArtifact().setScope( dependencyNode.getDependency().getScope() );
58 entry.setParent( currentEntry );
61 if ( firstDependencyNode == null )
63 firstDependencyNode = dependencyNode;
64 treeEntries.add( currentEntry );
68 currentEntry.getParent().getChilds().add( currentEntry );
74 public boolean visitLeave( DependencyNode dependencyNode )
76 currentEntry = currentEntry.getParent();
80 private static class ModelMapperHolder
82 private static ModelMapper MODEL_MAPPER = new ModelMapper();
86 MODEL_MAPPER.getConfiguration().setMatchingStrategy( MatchingStrategies.STRICT );
90 protected ModelMapper getModelMapper()
92 return ModelMapperHolder.MODEL_MAPPER;