View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model-v3.vm
3   //  template, any modifications will be overwritten.
4   // ==============================================================
5   package org.apache.maven.model;
6   
7   import java.io.Serializable;
8   import java.util.AbstractList;
9   import java.util.ArrayList;
10  import java.util.Collections;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.Objects;
15  import java.util.stream.Collectors;
16  import java.util.stream.Stream;
17  import org.apache.maven.api.annotations.Generated;
18  import org.apache.maven.api.annotations.Nonnull;
19  
20  @Generated
21  public class PluginContainer
22      extends BaseObject
23  {
24  
25      public PluginContainer()
26      {
27          this( org.apache.maven.api.model.PluginContainer.newInstance() );
28      }
29  
30      public PluginContainer( org.apache.maven.api.model.PluginContainer delegate )
31      {
32          this( delegate, null );
33      }
34  
35      public PluginContainer( org.apache.maven.api.model.PluginContainer delegate, BaseObject parent )
36      {
37          super( delegate, parent );
38      }
39  
40      public PluginContainer clone()
41      {
42          return new PluginContainer( getDelegate() );
43      }
44  
45      public org.apache.maven.api.model.PluginContainer getDelegate()
46      {
47          return ( org.apache.maven.api.model.PluginContainer ) super.getDelegate();
48      }
49  
50      @Override
51      public boolean equals( Object o )
52      {
53          if ( this == o )
54          {
55              return true;
56          }
57          if ( o == null || !( o instanceof PluginContainer ) )
58          {
59              return false;
60          }
61          PluginContainer that = ( PluginContainer ) o;
62          return Objects.equals( this.delegate, that.delegate );
63      }
64  
65      @Override
66      public int hashCode()
67      {
68          return getDelegate().hashCode();
69      }
70  
71      @Nonnull
72      public List<Plugin> getPlugins()
73      {
74          return new WrapperList<Plugin, org.apache.maven.api.model.Plugin>(
75                      () -> getDelegate().getPlugins(), l -> update( getDelegate().withPlugins( l ) ),
76                      d -> new Plugin( d, this ), Plugin::getDelegate );
77      }
78  
79      public void setPlugins( List<Plugin> plugins )
80      {
81          if ( !Objects.equals( plugins, getDelegate().getPlugins() ) )
82          {
83              update( getDelegate().withPlugins(
84                      plugins.stream().map( c -> c.getDelegate() ).collect( Collectors.toList() ) ) );
85              plugins.forEach( e -> e.childrenTracking = this::replace );
86          }
87      }
88  
89      public void addPlugin( Plugin plugin )
90      {
91          update( getDelegate().withPlugins(
92                  Stream.concat( getDelegate().getPlugins().stream(), Stream.of( plugin.getDelegate() ) )
93                          .collect( Collectors.toList() ) ) );
94          plugin.childrenTracking = this::replace;
95      }
96  
97      public void removePlugin( Plugin plugin )
98      {
99          update( getDelegate().withPlugins(
100                 getDelegate().getPlugins().stream()
101                         .filter( e -> !Objects.equals( e, plugin ) )
102                         .collect( Collectors.toList() ) ) );
103         plugin.childrenTracking = null;
104     }
105 
106     public InputLocation getLocation( Object key )
107     {
108         org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation( key );
109         return loc != null ? new InputLocation( loc ) : null;
110     }
111 
112     public void setLocation( Object key, InputLocation location )
113     {
114         update( org.apache.maven.api.model.PluginContainer.newBuilder( getDelegate(), true )
115                         .location( key, location.toApiLocation() ).build() );
116     }
117 
118     protected boolean replace( Object oldDelegate, Object newDelegate )
119     {
120         if ( super.replace( oldDelegate, newDelegate ) )
121         {
122             return true;
123         }
124         if ( getDelegate().getPlugins().contains( oldDelegate ) )
125         {
126             List<org.apache.maven.api.model.Plugin> list = new ArrayList<>( getDelegate().getPlugins() );
127             list.replaceAll( d -> d == oldDelegate ? ( org.apache.maven.api.model.Plugin ) newDelegate : d );
128             update( getDelegate().withPlugins( list ) );
129             return true;
130         }
131         return false;
132     }
133 
134     public static List<org.apache.maven.api.model.PluginContainer> pluginContainerToApiV4( List<PluginContainer> list )
135     {
136         return list != null ? new WrapperList<>( list, PluginContainer::getDelegate, PluginContainer::new ) : null;
137     }
138 
139     public static List<PluginContainer> pluginContainerToApiV3( List<org.apache.maven.api.model.PluginContainer> list )
140     {
141         return list != null ? new WrapperList<>( list, PluginContainer::new, PluginContainer::getDelegate ) : null;
142     }
143 
144 
145             
146     Map<String, Plugin> pluginMap;
147 
148     /**
149      * Reset the {@code pluginsMap} field to {@code null}
150      */
151     public synchronized void flushPluginMap()
152     {
153         this.pluginMap = null;
154     }
155 
156     /**
157      * @return a Map of plugins field with {@code Plugins#getKey()} as key
158      * @see Plugin#getKey()
159      */
160     public synchronized Map<String, Plugin> getPluginsAsMap()
161     {
162         if ( pluginMap == null )
163         {
164             pluginMap = new java.util.LinkedHashMap<String, Plugin>();
165             if ( getPlugins() != null )
166             {
167                 for ( java.util.Iterator<Plugin> it = getPlugins().iterator(); it.hasNext(); )
168                 {
169                     Plugin plugin = (Plugin) it.next();
170                     pluginMap.put( plugin.getKey(), plugin );
171                 }
172             }
173         }
174 
175         return pluginMap;
176     }
177             
178           
179 
180             
181      @Override
182      public String toString()
183      {
184          return "PluginContainer {}";
185      }
186             
187           
188 }