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  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 }