View Javadoc
1   package org.apache.maven.lifecycle.mapping;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  /**
31   * LifecyclePhase
32   */
33  public class LifecyclePhase
34  {
35      
36      private List<LifecycleMojo> mojos;
37      
38      public LifecyclePhase()
39      {
40      }
41      
42      public LifecyclePhase( String goals )
43      {
44          set( goals );
45      }
46      
47      public List<LifecycleMojo> getMojos()
48      {
49          return mojos;
50      }
51      
52      public void setMojos( List<LifecycleMojo> mojos )
53      {
54          this.mojos = mojos;
55      }
56      
57      public void set( String goals )
58      {
59          mojos = new ArrayList<>();
60          
61          if ( StringUtils.isNotEmpty( goals ) )
62          {
63              String[] mojoGoals = StringUtils.split( goals, "," );
64              
65              for ( String mojoGoal: mojoGoals )
66              {
67                  LifecycleMojo lifecycleMojo = new LifecycleMojo();
68                  lifecycleMojo.setGoal( mojoGoal.trim() );
69                  mojos.add( lifecycleMojo );
70              }
71          }
72      }
73      
74      @Override
75      public String toString()
76      {
77          StringBuilder sb = new StringBuilder();
78          boolean first = true;
79          List<LifecycleMojo> mojos = getMojos();
80          if ( mojos != null )
81          {
82              for ( LifecycleMojo mojo: mojos )
83              {
84                  if ( first )
85                  {
86                      first = false;
87                  }
88                  else
89                  {
90                      sb.append( ',' );
91                  }
92                  sb.append( mojo.getGoal() );
93              }
94          }
95          return sb.toString();
96      }
97      
98      @Deprecated
99      public static Map<String, String> toLegacyMap( Map<String, LifecyclePhase> lifecyclePhases )
100     {
101         if ( lifecyclePhases == null )
102         {
103             return null;
104         }
105         
106         if ( lifecyclePhases.isEmpty() )
107         {
108             return Collections.emptyMap();
109         }
110         
111         Map<String, String> phases = new LinkedHashMap<>();
112         for ( Map.Entry<String, LifecyclePhase> e: lifecyclePhases.entrySet() )
113         {
114             phases.put( e.getKey(), e.getValue().toString() );
115         }
116         return phases;
117     }
118     
119 }