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