Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WarUtils |
|
| 20.0;20 |
1 | package org.apache.maven.plugin.war.util; | |
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 org.apache.maven.artifact.Artifact; | |
23 | import org.apache.maven.model.Dependency; | |
24 | import org.apache.maven.project.MavenProject; | |
25 | import org.codehaus.plexus.util.StringUtils; | |
26 | ||
27 | import java.util.Iterator; | |
28 | ||
29 | /** | |
30 | * | |
31 | * @author Stephane Nicoll | |
32 | * @version $Id: WarUtils.java 743348 2009-02-11 14:40:19Z dennisl $ | |
33 | */ | |
34 | 0 | public class WarUtils |
35 | { | |
36 | ||
37 | ||
38 | public static Artifact getArtifact( MavenProject project, Dependency dependency ) | |
39 | { | |
40 | 0 | final Iterator it = project.getArtifacts().iterator(); |
41 | 0 | while ( it.hasNext() ) |
42 | { | |
43 | 0 | Artifact artifact = (Artifact) it.next(); |
44 | 0 | if ( artifact.getGroupId().equals( dependency.getGroupId() ) |
45 | && artifact.getArtifactId().equals( dependency.getArtifactId() ) | |
46 | && artifact.getType().equals( dependency.getType() ) ) | |
47 | { | |
48 | 0 | if ( artifact.getClassifier() == null && dependency.getClassifier() == null ) |
49 | { | |
50 | 0 | return artifact; |
51 | } | |
52 | 0 | else if ( dependency.getClassifier() != null |
53 | && dependency.getClassifier().equals( artifact.getClassifier() ) ) | |
54 | { | |
55 | 0 | return artifact; |
56 | } | |
57 | } | |
58 | 0 | } |
59 | 0 | return null; |
60 | } | |
61 | ||
62 | public static boolean isRelated( Artifact artifact, Dependency dependency ) | |
63 | { | |
64 | 190 | if ( artifact == null || dependency == null ) |
65 | { | |
66 | 0 | return false; |
67 | } | |
68 | ||
69 | 190 | if ( !StringUtils.equals( artifact.getGroupId(), dependency.getGroupId() ) ) |
70 | { | |
71 | 8 | return false; |
72 | } | |
73 | 182 | if ( !StringUtils.equals( artifact.getArtifactId(), dependency.getArtifactId() ) ) |
74 | { | |
75 | 76 | return false; |
76 | } | |
77 | 106 | if ( artifact.getVersion() != null ? !artifact.getVersion().equals( dependency.getVersion() ) |
78 | : dependency.getVersion() != null ) | |
79 | { | |
80 | 0 | return false; |
81 | } | |
82 | 106 | if ( artifact.getType() != null ? !artifact.getType().equals( dependency.getType() ) |
83 | : dependency.getType() != null ) | |
84 | { | |
85 | 0 | return false; |
86 | } | |
87 | 106 | if ( artifact.getClassifier() != null ? !artifact.getClassifier().equals( dependency.getClassifier() ) |
88 | : dependency.getClassifier() != null ) | |
89 | { | |
90 | 4 | return false; |
91 | } | |
92 | 102 | if ( artifact.getScope() != null ? !artifact.getScope().equals( dependency.getScope() ) |
93 | : dependency.getScope() != null ) | |
94 | { | |
95 | 0 | return false; |
96 | } | |
97 | 102 | if ( artifact.isOptional() != dependency.isOptional() ) |
98 | { | |
99 | 0 | return false; |
100 | } | |
101 | ||
102 | 102 | return true; |
103 | } | |
104 | ||
105 | public static boolean dependencyEquals( Dependency first, Dependency second ) | |
106 | { | |
107 | 48 | if ( first == second ) |
108 | { | |
109 | 14 | return true; |
110 | } | |
111 | ||
112 | 34 | if ( first.isOptional() != second.isOptional() ) |
113 | { | |
114 | 0 | return false; |
115 | } | |
116 | 34 | if ( !StringUtils.equals( first.getArtifactId(), second.getArtifactId() ) ) |
117 | { | |
118 | 14 | return false; |
119 | } | |
120 | 20 | if ( first.getClassifier() != null ? !first.getClassifier().equals( second.getClassifier() ) |
121 | : second.getClassifier() != null ) | |
122 | { | |
123 | 0 | return false; |
124 | } | |
125 | 20 | if ( first.getExclusions() != null ? !first.getExclusions().equals( second.getExclusions() ) |
126 | : second.getExclusions() != null ) | |
127 | { | |
128 | 0 | return false; |
129 | } | |
130 | 20 | if ( !StringUtils.equals( first.getGroupId(), second.getGroupId() ) ) |
131 | { | |
132 | 2 | return false; |
133 | } | |
134 | 18 | if ( first.getScope() != null ? !first.getScope().equals( second.getScope() ) : second.getScope() != null ) |
135 | { | |
136 | 2 | return false; |
137 | } | |
138 | 16 | if ( first.getSystemPath() != null ? !first.getSystemPath().equals( second.getSystemPath() ) |
139 | : second.getSystemPath() != null ) | |
140 | { | |
141 | 0 | return false; |
142 | } | |
143 | 16 | if ( first.getType() != null ? !first.getType().equals( second.getType() ) : second.getType() != null ) |
144 | { | |
145 | 0 | return false; |
146 | } | |
147 | 16 | if ( first.getVersion() != null ? !first.getVersion().equals( second.getVersion() ) |
148 | : second.getVersion() != null ) | |
149 | { | |
150 | 2 | return false; |
151 | } | |
152 | 14 | return true; |
153 | } | |
154 | ||
155 | ||
156 | } |