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 java.util.Objects;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.model.Dependency;
26 import org.apache.maven.project.MavenProject;
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 ( Artifact artifact : project.getArtifacts() )
42 {
43 if ( artifact.getGroupId().equals( dependency.getGroupId() )
44 && artifact.getArtifactId().equals( dependency.getArtifactId() )
45 && artifact.getType().equals( dependency.getType() ) )
46 {
47 if ( artifact.getClassifier() == null && dependency.getClassifier() == null )
48 {
49 return artifact;
50 }
51 else if ( dependency.getClassifier() != null
52 && dependency.getClassifier().equals( artifact.getClassifier() ) )
53 {
54 return artifact;
55 }
56 }
57 }
58 return null;
59 }
60
61
62
63
64
65
66 public static boolean isRelated( Artifact artifact, Dependency dependency )
67 {
68 if ( artifact == null || dependency == null )
69 {
70 return false;
71 }
72
73 if ( !Objects.equals( artifact.getGroupId(), dependency.getGroupId() ) )
74 {
75 return false;
76 }
77 if ( !Objects.equals( artifact.getArtifactId(), dependency.getArtifactId() ) )
78 {
79 return false;
80 }
81 if ( Objects.equals( artifact.getVersion(), dependency.getVersion() ) )
82 {
83 return false;
84 }
85 if ( Objects.equals( artifact.getType(), dependency.getType() ) )
86 {
87 return false;
88 }
89 if ( Objects.equals( artifact.getClassifier(), dependency.getClassifier() ) )
90 {
91 return false;
92 }
93 if ( Objects.equals( artifact.getScope(), dependency.getScope() ) )
94 {
95 return false;
96 }
97 if ( artifact.isOptional() != dependency.isOptional() )
98 {
99 return false;
100 }
101
102 return true;
103 }
104
105 }