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   * Mojo (goals) bindings to a lifecycle phase.
32   *
33   * @see LifecycleMojo
34   */
35  public class LifecyclePhase
36  {
37  
38      private List<LifecycleMojo> mojos;
39  
40      public LifecyclePhase()
41      {
42      }
43  
44      public LifecyclePhase( String goals )
45      {
46          set( goals );
47      }
48  
49      public List<LifecycleMojo> getMojos()
50      {
51          return mojos;
52      }
53  
54      public void setMojos( List<LifecycleMojo> mojos )
55      {
56          this.mojos = mojos;
57      }
58  
59      public void set( String goals )
60      {
61          mojos = new ArrayList<>();
62  
63          if ( StringUtils.isNotEmpty( goals ) )
64          {
65              String[] mojoGoals = StringUtils.split( goals, "," );
66  
67              for ( String mojoGoal: mojoGoals )
68              {
69                  LifecycleMojo lifecycleMojo = new LifecycleMojo();
70                  lifecycleMojo.setGoal( mojoGoal.trim() );
71                  mojos.add( lifecycleMojo );
72              }
73          }
74      }
75  
76      @Override
77      public String toString()
78      {
79          StringBuilder sb = new StringBuilder();
80          boolean first = true;
81          List<LifecycleMojo> mojos = getMojos();
82          if ( mojos != null )
83          {
84              for ( LifecycleMojo mojo: mojos )
85              {
86                  if ( first )
87                  {
88                      first = false;
89                  }
90                  else
91                  {
92                      sb.append( ',' );
93                  }
94                  sb.append( mojo.getGoal() );
95              }
96          }
97          return sb.toString();
98      }
99  
100     @Deprecated
101     public static Map<String, String> toLegacyMap( Map<String, LifecyclePhase> lifecyclePhases )
102     {
103         if ( lifecyclePhases == null )
104         {
105             return null;
106         }
107 
108         if ( lifecyclePhases.isEmpty() )
109         {
110             return Collections.emptyMap();
111         }
112 
113         Map<String, String> phases = new LinkedHashMap<>();
114         for ( Map.Entry<String, LifecyclePhase> e: lifecyclePhases.entrySet() )
115         {
116             phases.put( e.getKey(), e.getValue().toString() );
117         }
118         return phases;
119     }
120 
121 }