1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.war.util;
20
21 import java.util.Objects;
22
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.model.Dependency;
25 import org.apache.maven.project.MavenProject;
26
27
28
29
30 public class WarUtils {
31
32
33
34
35
36
37 public static Artifact getArtifact(MavenProject project, Dependency dependency) {
38 for (Artifact artifact : project.getArtifacts()) {
39 if (artifact.getGroupId().equals(dependency.getGroupId())
40 && artifact.getArtifactId().equals(dependency.getArtifactId())
41 && artifact.getType().equals(dependency.getType())) {
42 if (artifact.getClassifier() == null && dependency.getClassifier() == null) {
43 return artifact;
44 } else if (dependency.getClassifier() != null
45 && dependency.getClassifier().equals(artifact.getClassifier())) {
46 return artifact;
47 }
48 }
49 }
50 return null;
51 }
52
53
54
55
56
57
58 public static boolean isRelated(Artifact artifact, Dependency dependency) {
59 if (artifact == null || dependency == null) {
60 return false;
61 }
62
63 if (!Objects.equals(artifact.getGroupId(), dependency.getGroupId())) {
64 return false;
65 }
66 if (!Objects.equals(artifact.getArtifactId(), dependency.getArtifactId())) {
67 return false;
68 }
69 if (Objects.equals(artifact.getVersion(), dependency.getVersion())) {
70 return false;
71 }
72 if (Objects.equals(artifact.getType(), dependency.getType())) {
73 return false;
74 }
75 if (Objects.equals(artifact.getClassifier(), dependency.getClassifier())) {
76 return false;
77 }
78 if (Objects.equals(artifact.getScope(), dependency.getScope())) {
79 return false;
80 }
81 if (artifact.isOptional() != dependency.isOptional()) {
82 return false;
83 }
84
85 return true;
86 }
87 }