1 package org.apache.archiva.repository.maven.dependency.tree;
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
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
20 import org.apache.archiva.maven2.model.Artifact;
21 import org.apache.archiva.maven2.model.TreeEntry;
22 import org.eclipse.aether.graph.DependencyNode;
23 import org.eclipse.aether.graph.DependencyVisitor;
24 import org.modelmapper.ModelMapper;
25 import org.modelmapper.convention.MatchingStrategies;
27 import java.util.List;
30 * @author Olivier Lamy
33 public class TreeDependencyNodeVisitor
34 implements DependencyVisitor
37 final List<TreeEntry> treeEntries;
39 private TreeEntry currentEntry;
41 private org.eclipse.aether.graph.DependencyNode firstDependencyNode;
43 public TreeDependencyNodeVisitor( List<TreeEntry> treeEntries )
45 this.treeEntries = treeEntries;
50 public boolean visitEnter( DependencyNode dependencyNode )
53 new TreeEntry( getModelMapper().map( dependencyNode.getDependency().getArtifact(), Artifact.class ) );
54 entry.getArtifact().setFileExtension( dependencyNode.getDependency().getArtifact().getExtension() );
55 entry.getArtifact().setScope( dependencyNode.getDependency().getScope() );
56 entry.setParent( currentEntry );
59 if ( firstDependencyNode == null )
61 firstDependencyNode = dependencyNode;
62 treeEntries.add( currentEntry );
66 currentEntry.getParent().getChilds().add( currentEntry );
72 public boolean visitLeave( DependencyNode dependencyNode )
74 currentEntry = currentEntry.getParent();
78 private static class ModelMapperHolder
80 private static ModelMapper MODEL_MAPPER = new ModelMapper();
84 MODEL_MAPPER.getConfiguration().setMatchingStrategy( MatchingStrategies.STRICT );
88 protected ModelMapper getModelMapper()
90 return ModelMapperHolder.MODEL_MAPPER;