1 package org.apache.maven.plugin.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 import java.util.Iterator;
28
29
30
31
32
33
34 public class WarUtils
35 {
36
37
38 public static Artifact getArtifact( MavenProject project, Dependency dependency )
39 {
40 final Iterator it = project.getArtifacts().iterator();
41 while ( it.hasNext() )
42 {
43 Artifact artifact = (Artifact) it.next();
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 public static boolean isRelated( Artifact artifact, Dependency dependency )
63 {
64 if ( artifact == null || dependency == null )
65 {
66 return false;
67 }
68
69 if ( !StringUtils.equals( artifact.getGroupId(), dependency.getGroupId() ) )
70 {
71 return false;
72 }
73 if ( !StringUtils.equals( artifact.getArtifactId(), dependency.getArtifactId() ) )
74 {
75 return false;
76 }
77 if ( artifact.getVersion() != null ? !artifact.getVersion().equals( dependency.getVersion() )
78 : dependency.getVersion() != null )
79 {
80 return false;
81 }
82 if ( artifact.getType() != null ? !artifact.getType().equals( dependency.getType() )
83 : dependency.getType() != null )
84 {
85 return false;
86 }
87 if ( artifact.getClassifier() != null ? !artifact.getClassifier().equals( dependency.getClassifier() )
88 : dependency.getClassifier() != null )
89 {
90 return false;
91 }
92 if ( artifact.getScope() != null ? !artifact.getScope().equals( dependency.getScope() )
93 : dependency.getScope() != null )
94 {
95 return false;
96 }
97 if ( artifact.isOptional() != dependency.isOptional() )
98 {
99 return false;
100 }
101
102 return true;
103 }
104
105 public static boolean dependencyEquals( Dependency first, Dependency second )
106 {
107 if ( first == second )
108 {
109 return true;
110 }
111
112 if ( first.isOptional() != second.isOptional() )
113 {
114 return false;
115 }
116 if ( !StringUtils.equals( first.getArtifactId(), second.getArtifactId() ) )
117 {
118 return false;
119 }
120 if ( first.getClassifier() != null ? !first.getClassifier().equals( second.getClassifier() )
121 : second.getClassifier() != null )
122 {
123 return false;
124 }
125 if ( first.getExclusions() != null ? !first.getExclusions().equals( second.getExclusions() )
126 : second.getExclusions() != null )
127 {
128 return false;
129 }
130 if ( !StringUtils.equals( first.getGroupId(), second.getGroupId() ) )
131 {
132 return false;
133 }
134 if ( first.getScope() != null ? !first.getScope().equals( second.getScope() ) : second.getScope() != null )
135 {
136 return false;
137 }
138 if ( first.getSystemPath() != null ? !first.getSystemPath().equals( second.getSystemPath() )
139 : second.getSystemPath() != null )
140 {
141 return false;
142 }
143 if ( first.getType() != null ? !first.getType().equals( second.getType() ) : second.getType() != null )
144 {
145 return false;
146 }
147 if ( first.getVersion() != null ? !first.getVersion().equals( second.getVersion() )
148 : second.getVersion() != null )
149 {
150 return false;
151 }
152 return true;
153 }
154
155
156 }