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          this(org.apache.maven.api.model.PluginContainer.newInstance());
27      }
28  
29      public PluginContainer(org.apache.maven.api.model.PluginContainer delegate) {
30          this(delegate, null);
31      }
32  
33      public PluginContainer(org.apache.maven.api.model.PluginContainer delegate, BaseObject parent) {
34          super(delegate, parent);
35      }
36  
37      public PluginContainer clone(){
38          return new PluginContainer(getDelegate());
39      }
40  
41      public org.apache.maven.api.model.PluginContainer getDelegate() {
42          return (org.apache.maven.api.model.PluginContainer) super.getDelegate();
43      }
44  
45      @Override
46      public boolean equals(Object o) {
47          if (this == o) {
48              return true;
49          }
50          if (o == null || !(o instanceof PluginContainer)) {
51              return false;
52          }
53          PluginContainer that = (PluginContainer) o;
54          return Objects.equals(this.delegate, that.delegate);
55      }
56  
57      @Override
58      public int hashCode() {
59          return getDelegate().hashCode();
60      }
61  
62      @Nonnull
63      public List<Plugin> getPlugins() {
64          return new WrapperList<Plugin, org.apache.maven.api.model.Plugin>(
65                      () -> getDelegate().getPlugins(), l -> update(getDelegate().withPlugins(l)),
66                      d -> new Plugin(d, this), Plugin::getDelegate);
67      }
68  
69      public void setPlugins(List<Plugin> plugins) {
70          if (!Objects.equals(plugins, getPlugins())) {
71              update(getDelegate().withPlugins(
72                     plugins.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
73              plugins.forEach(e -> e.childrenTracking = this::replace);
74          }
75      }
76  
77      public void addPlugin(Plugin plugin) {
78          update(getDelegate().withPlugins(
79                 Stream.concat(getDelegate().getPlugins().stream(), Stream.of(plugin.getDelegate()))
80                          .collect(Collectors.toList())));
81          plugin.childrenTracking = this::replace;
82      }
83  
84      public void removePlugin(Plugin plugin) {
85          update(getDelegate().withPlugins(
86                 getDelegate().getPlugins().stream()
87                          .filter(e -> !Objects.equals(e, plugin))
88                          .collect(Collectors.toList())));
89          plugin.childrenTracking = null;
90      }
91  
92      public InputLocation getLocation(Object key) {
93          org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation(key);
94          return loc != null ? new InputLocation(loc) : null;
95      }
96  
97      public void setLocation(Object key, InputLocation location) {
98          update(org.apache.maven.api.model.PluginContainer.newBuilder(getDelegate(), true)
99                          .location(key, location.toApiLocation()).build());
100     }
101 
102     protected boolean replace(Object oldDelegate, Object newDelegate) {
103         if (super.replace(oldDelegate, newDelegate)) {
104             return true;
105         }
106         if (getDelegate().getPlugins().contains(oldDelegate)) {
107             List<org.apache.maven.api.model.Plugin> list = new ArrayList<>(getDelegate().getPlugins());
108             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Plugin) newDelegate : d);
109             update(getDelegate().withPlugins(list));
110             return true;
111         }
112         return false;
113     }
114 
115     public static List<org.apache.maven.api.model.PluginContainer> pluginContainerToApiV4(List<PluginContainer> list) {
116         return list != null ? new WrapperList<>(list, PluginContainer::getDelegate, PluginContainer::new) : null;
117     }
118 
119     public static List<PluginContainer> pluginContainerToApiV3(List<org.apache.maven.api.model.PluginContainer> list) {
120         return list != null ? new WrapperList<>(list, PluginContainer::new, PluginContainer::getDelegate) : null;
121     }
122 
123 
124             
125     Map<String, Plugin> pluginMap;
126 
127     /**
128      * Reset the {@code pluginsMap} field to {@code null}
129      */
130     public synchronized void flushPluginMap()
131     {
132         this.pluginMap = null;
133     }
134 
135     /**
136      * @return a Map of plugins field with {@code Plugins#getKey()} as key
137      * @see Plugin#getKey()
138      */
139     public synchronized Map<String, Plugin> getPluginsAsMap()
140     {
141         if ( pluginMap == null )
142         {
143             pluginMap = new java.util.LinkedHashMap<String, Plugin>();
144             if ( getPlugins() != null )
145             {
146                 for ( java.util.Iterator<Plugin> it = getPlugins().iterator(); it.hasNext(); )
147                 {
148                     Plugin plugin = (Plugin) it.next();
149                     pluginMap.put( plugin.getKey(), plugin );
150                 }
151             }
152         }
153 
154         return pluginMap;
155     }
156             
157           
158 
159             
160      @Override
161      public String toString()
162      {
163          return "PluginContainer {}";
164      }
165             
166           
167 }