1 package org.apache.maven.model.converter;
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.model.Plugin;
23
24 import java.util.Comparator;
25
26
27
28
29
30
31
32
33 public class PluginComparator
34 implements Comparator
35 {
36 public int compare( Object o1, Object o2 )
37 {
38
39 if ( o1 == null && o2 == null )
40 {
41 return 0;
42 }
43 if ( o1 == null )
44 {
45 return -1;
46 }
47 if ( o2 == null )
48 {
49 return 1;
50 }
51
52
53 if ( !( o1 instanceof Plugin ) && !( o2 instanceof Plugin ) )
54 {
55 return 0;
56 }
57 if ( !( o1 instanceof Plugin ) )
58 {
59 return -1;
60 }
61 if ( !( o2 instanceof Plugin ) )
62 {
63 return 1;
64 }
65 Plugin plugin1 = (Plugin) o1;
66 Plugin plugin2 = (Plugin) o2;
67
68
69 if ( plugin1.getGroupId() == null && plugin2.getGroupId() == null )
70 {
71 return compareArtifactId( plugin1, plugin2 );
72 }
73 if ( plugin1.getGroupId() == null )
74 {
75 return -1;
76 }
77 if ( plugin2.getGroupId() == null )
78 {
79 return 1;
80 }
81
82
83 int answer;
84 answer = plugin1.getGroupId().compareTo( plugin2.getGroupId() );
85 if ( answer == 0 )
86 {
87 answer = compareArtifactId( plugin1, plugin2 );
88 }
89
90 return answer;
91 }
92
93 private int compareArtifactId( Plugin plugin1, Plugin plugin2 )
94 {
95 if ( plugin1.getArtifactId() == null && plugin2.getArtifactId() == null )
96 {
97 return 0;
98 }
99 if ( plugin1.getArtifactId() == null )
100 {
101 return -1;
102 }
103 if ( plugin2.getArtifactId() == null )
104 {
105 return 1;
106 }
107 return plugin1.getArtifactId().compareTo( plugin2.getArtifactId() );
108 }
109 }