1   package org.apache.maven.lifecycle.mapping;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.LinkedHashMap;
25  import java.util.List;
26  import java.util.Map;
27  
28  import org.codehaus.plexus.util.StringUtils;
29  
30  public class LifecyclePhase
31  {
32      
33      private List<LifecycleMojo> mojos;
34      
35      public LifecyclePhase()
36      {
37      }
38      
39      public LifecyclePhase( String goals )
40      {
41          set( goals );
42      }
43      
44      public List<LifecycleMojo> getMojos()
45      {
46          return mojos;
47      }
48      
49      public void setMojos( List<LifecycleMojo> mojos )
50      {
51          this.mojos = mojos;
52      }
53      
54      public void set( String goals )
55      {
56          mojos = new ArrayList<>();
57          
58          if ( StringUtils.isNotEmpty( goals ) )
59          {
60              String[] mojoGoals = StringUtils.split( goals, "," );
61              
62              for ( String mojoGoal: mojoGoals )
63              {
64                  LifecycleMojo lifecycleMojo = new LifecycleMojo();
65                  lifecycleMojo.setGoal( mojoGoal.trim() );
66                  mojos.add( lifecycleMojo );
67              }
68          }
69      }
70      
71      @Override
72      public String toString()
73      {
74          StringBuilder sb = new StringBuilder();
75          boolean first = true;
76          List<LifecycleMojo> mojos = getMojos();
77          if ( mojos != null )
78          {
79              for ( LifecycleMojo mojo: mojos )
80              {
81                  if ( first )
82                  {
83                      first = false;
84                  }
85                  else
86                  {
87                      sb.append( ',' );
88                  }
89                  sb.append( mojo.getGoal() );
90              }
91          }
92          return sb.toString();
93      }
94      
95      @Deprecated
96      public static Map<String, String> toLegacyMap( Map<String, LifecyclePhase> lifecyclePhases )
97      {
98          if ( lifecyclePhases == null )
99          {
100             return null;
101         }
102         
103         if ( lifecyclePhases.isEmpty() )
104         {
105             return Collections.emptyMap();
106         }
107         
108         Map<String, String> phases = new LinkedHashMap<>();
109         for ( Map.Entry<String, LifecyclePhase> e: lifecyclePhases.entrySet() )
110         {
111             phases.put( e.getKey(), e.getValue().toString() );
112         }
113         return phases;
114     }
115     
116 }