1 package org.apache.maven.plugins.war.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
28
29
30
31 public class WarUtils
32 {
33
34
35
36
37
38
39 public static Artifact getArtifact( MavenProject project, Dependency dependency )
40 {
41 for ( Object o : project.getArtifacts() )
42 {
43 Artifact artifact = (Artifact) o;
44 if ( artifact.getGroupId().equals( dependency.getGroupId() )
45 && artifact.getArtifactId().equals( dependency.getArtifactId() )
46 && artifact.getType().equals( dependency.getType() ) )
47 {
48 if ( artifact.getClassifier() == null && dependency.getClassifier() == null )
49 {
50 return artifact;
51 }
52 else if ( dependency.getClassifier() != null
53 && dependency.getClassifier().equals( artifact.getClassifier() ) )
54 {
55 return artifact;
56 }
57 }
58 }
59 return null;
60 }
61
62
63
64
65
66
67 public static boolean isRelated( Artifact artifact, Dependency dependency )
68 {
69 if ( artifact == null || dependency == null )
70 {
71 return false;
72 }
73
74 if ( !StringUtils.equals( artifact.getGroupId(), dependency.getGroupId() ) )
75 {
76 return false;
77 }
78 if ( !StringUtils.equals( artifact.getArtifactId(), dependency.getArtifactId() ) )
79 {
80 return false;
81 }
82 if ( artifact.getVersion() != null ? !artifact.getVersion().equals( dependency.getVersion() )
83 : dependency.getVersion() != null )
84 {
85 return false;
86 }
87 if ( artifact.getType() != null ? !artifact.getType().equals( dependency.getType() )
88 : dependency.getType() != null )
89 {
90 return false;
91 }
92 if ( artifact.getClassifier() != null ? !artifact.getClassifier().equals( dependency.getClassifier() )
93 : dependency.getClassifier() != null )
94 {
95 return false;
96 }
97 if ( artifact.getScope() != null ? !artifact.getScope().equals( dependency.getScope() )
98 : dependency.getScope() != null )
99 {
100 return false;
101 }
102 if ( artifact.isOptional() != dependency.isOptional() )
103 {
104 return false;
105 }
106
107 return true;
108 }
109
110
111
112
113
114
115 public static boolean dependencyEquals( Dependency first, Dependency second )
116 {
117 if ( first == second )
118 {
119 return true;
120 }
121
122 if ( first.isOptional() != second.isOptional() )
123 {
124 return false;
125 }
126 if ( !StringUtils.equals( first.getArtifactId(), second.getArtifactId() ) )
127 {
128 return false;
129 }
130 if ( first.getClassifier() != null ? !first.getClassifier().equals( second.getClassifier() )
131 : second.getClassifier() != null )
132 {
133 return false;
134 }
135 if ( first.getExclusions() != null ? !first.getExclusions().equals( second.getExclusions() )
136 : second.getExclusions() != null )
137 {
138 return false;
139 }
140 if ( !StringUtils.equals( first.getGroupId(), second.getGroupId() ) )
141 {
142 return false;
143 }
144 if ( first.getScope() != null ? !first.getScope().equals( second.getScope() ) : second.getScope() != null )
145 {
146 return false;
147 }
148 if ( first.getSystemPath() != null ? !first.getSystemPath().equals( second.getSystemPath() )
149 : second.getSystemPath() != null )
150 {
151 return false;
152 }
153 if ( first.getType() != null ? !first.getType().equals( second.getType() ) : second.getType() != null )
154 {
155 return false;
156 }
157 if ( first.getVersion() != null ? !first.getVersion().equals( second.getVersion() )
158 : second.getVersion() != null )
159 {
160 return false;
161 }
162 return true;
163 }
164
165 }