1 package org.apache.maven.report.projectinfo.dependencies;
2
3 /*
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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
19 * under the License.
20 */
21
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.apache.maven.artifact.Artifact;
29 import org.apache.maven.model.Dependency;
30
31 /**
32 * @author Nick Stolwijk
33 * @version $Id: ManagementDependencies.java 890109 2009-12-13 19:57:28Z ltheussl $
34 * @since 2.1
35 */
36 public class ManagementDependencies
37 {
38 private final List managementDependencies;
39
40 /**
41 * @param projectDependencies the list of dependencies.
42 */
43 public ManagementDependencies( List projectDependencies )
44 {
45 this.managementDependencies = projectDependencies;
46 }
47
48 /**
49 * @return <code>true</code> if managementDependencies is not null and not empty.
50 */
51 public boolean hasDependencies()
52 {
53 return ( managementDependencies != null ) && ( !this.managementDependencies.isEmpty() );
54 }
55
56 /**
57 * @return managementDependencies
58 */
59 public List getManagementDependencies()
60 {
61 return new ArrayList( managementDependencies );
62 }
63
64 /**
65 * @return the managementDependencies by scope
66 * @see Artifact#SCOPE_COMPILE
67 * @see Artifact#SCOPE_PROVIDED
68 * @see Artifact#SCOPE_RUNTIME
69 * @see Artifact#SCOPE_SYSTEM
70 * @see Artifact#SCOPE_TEST
71 */
72 public Map getManagementDependenciesByScope()
73 {
74 Map dependenciesByScope = new HashMap();
75 for ( Iterator i = getManagementDependencies().iterator(); i.hasNext(); )
76 {
77 Dependency dependency = (Dependency) i.next();
78 String scope = dependency.getScope() != null ? dependency.getScope() : Artifact.SCOPE_COMPILE;
79 List multiValue = (List) dependenciesByScope.get( scope );
80 if ( multiValue == null )
81 {
82 multiValue = new ArrayList();
83 }
84 multiValue.add( dependency );
85 dependenciesByScope.put( scope, multiValue );
86 }
87
88 return dependenciesByScope;
89 }
90 }