1 package org.apache.maven.archiva.plugins.dev.testgen;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.factory.ArtifactFactory;
24 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
25 import org.apache.maven.artifact.versioning.VersionRange;
26 import org.apache.maven.model.Dependency;
27 import org.apache.maven.model.DependencyManagement;
28 import org.apache.maven.project.MavenProject;
29 import org.apache.maven.project.ProjectBuildingException;
31 import java.util.Collections;
32 import java.util.HashMap;
33 import java.util.Iterator;
37 * DependencyUtils - common utilities for dependencies.
39 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
42 public class DependencyUtils
44 public static Map getManagedVersionMap( MavenProject project, ArtifactFactory factory ) throws ProjectBuildingException
46 DependencyManagement dependencyManagement = project.getDependencyManagement();
47 Map managedVersionMap;
49 if ( dependencyManagement != null && dependencyManagement.getDependencies() != null )
51 managedVersionMap = new HashMap();
53 for ( Iterator iterator = dependencyManagement.getDependencies().iterator(); iterator.hasNext(); )
55 Dependency dependency = (Dependency) iterator.next();
59 VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() );
62 factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
63 versionRange, dependency.getType(),
64 dependency.getClassifier(), dependency.getScope() );
66 managedVersionMap.put( dependency.getManagementKey(), artifact );
68 catch ( InvalidVersionSpecificationException exception )
70 throw new ProjectBuildingException( project.getId(), "Unable to parse version '"
71 + dependency.getVersion() + "' for dependency '" + dependency.getManagementKey()
72 + "': " + exception.getMessage(), exception );
78 managedVersionMap = Collections.EMPTY_MAP;
81 return managedVersionMap;