1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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
17 * under the License.
18 */
19 package org.apache.maven.report.projectinfo.dependencies;
20
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.model.Dependency;
28
29 /**
30 * @author Nick Stolwijk
31 * @since 2.1
32 */
33 public class ManagementDependencies {
34 private final List<Dependency> dependencies;
35
36 /**
37 * @param projectDependencies the list of dependencies.
38 */
39 public ManagementDependencies(List<Dependency> projectDependencies) {
40 this.dependencies = projectDependencies;
41 }
42
43 /**
44 * @return <code>true</code> if dependencies is not null and not empty.
45 */
46 public boolean hasDependencies() {
47 return (dependencies != null) && (!this.dependencies.isEmpty());
48 }
49
50 /**
51 * @return dependencies
52 */
53 public List<Dependency> getManagementDependencies() {
54 return new ArrayList<>(dependencies);
55 }
56
57 /**
58 * @return the dependencies by scope
59 * @see Artifact#SCOPE_COMPILE
60 * @see Artifact#SCOPE_PROVIDED
61 * @see Artifact#SCOPE_RUNTIME
62 * @see Artifact#SCOPE_SYSTEM
63 * @see Artifact#SCOPE_TEST
64 */
65 public Map<String, List<Dependency>> getManagementDependenciesByScope() {
66 Map<String, List<Dependency>> dependenciesByScope = new HashMap<>();
67 for (Dependency dependency : dependencies) {
68 String scope = dependency.getScope() != null ? dependency.getScope() : Artifact.SCOPE_COMPILE;
69 List<Dependency> multiValue = dependenciesByScope.get(scope);
70 if (multiValue == null) {
71 multiValue = new ArrayList<>();
72 }
73 multiValue.add(dependency);
74 dependenciesByScope.put(scope, multiValue);
75 }
76
77 return dependenciesByScope;
78 }
79 }