1 package com.soebes.maven.extensions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collections;
23 import java.util.Comparator;
24 import java.util.LinkedList;
25 import java.util.List;
26
27 import org.apache.maven.eventspy.AbstractEventSpy;
28 import org.apache.maven.plugins.annotations.LifecyclePhase;
29
30
31
32
33 class LifeCycleOrdering
34 extends AbstractEventSpy
35 {
36 private final List<String> predefinedPhases = new LinkedList<>();
37
38 private void initializePredefinedPhases()
39 {
40
41
42
43
44 initPredefinedFromTo( LifecyclePhase.PRE_CLEAN, LifecyclePhase.POST_CLEAN );
45 initPredefinedFromTo( LifecyclePhase.VALIDATE, LifecyclePhase.DEPLOY );
46 initPredefinedFromTo( LifecyclePhase.PRE_SITE, LifecyclePhase.SITE_DEPLOY );
47 }
48
49 private void initPredefinedFromTo( LifecyclePhase from, LifecyclePhase to )
50 {
51 LifecyclePhase[] values = LifecyclePhase.values();
52
53 for ( int item = from.ordinal(); item <= to.ordinal(); item++ )
54 {
55 predefinedPhases.add( values[item].id() );
56 }
57 }
58
59 public LifeCycleOrdering()
60 {
61 initializePredefinedPhases();
62 }
63
64 public List<String> getPredefinedPhases()
65 {
66 return predefinedPhases;
67 }
68
69 protected void orderLifeCycleOnPreparedOrder( List<String> lifeCyclePhases )
70 {
71
72 Collections.sort( lifeCyclePhases, new Comparator<String>()
73 {
74 public int compare( String left, String right )
75 {
76 return Integer.compare( predefinedPhases.indexOf( left ), predefinedPhases.indexOf( right ) );
77 }
78 } );
79 }
80
81 }