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 (plugins == null) {
71              plugins = Collections.emptyList();
72          }
73          if (!Objects.equals(plugins, getPlugins())) {
74              update(getDelegate().withPlugins(
75                  plugins.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
76              plugins.forEach(e -> e.childrenTracking = this::replace);
77          }
78      }
79  
80      public void addPlugin(Plugin plugin) {
81          update(getDelegate().withPlugins(
82                 Stream.concat(getDelegate().getPlugins().stream(), Stream.of(plugin.getDelegate()))
83                          .collect(Collectors.toList())));
84          plugin.childrenTracking = this::replace;
85      }
86  
87      public void removePlugin(Plugin plugin) {
88          update(getDelegate().withPlugins(
89                 getDelegate().getPlugins().stream()
90                          .filter(e -> !Objects.equals(e, plugin))
91                          .collect(Collectors.toList())));
92          plugin.childrenTracking = null;
93      }
94  
95      public InputLocation getLocation(Object key) {
96          org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation(key);
97          return loc != null ? new InputLocation(loc) : null;
98      }
99  
100     public void setLocation(Object key, InputLocation location) {
101         update(org.apache.maven.api.model.PluginContainer.newBuilder(getDelegate(), true)
102                         .location(key, location.toApiLocation()).build());
103     }
104 
105     protected boolean replace(Object oldDelegate, Object newDelegate) {
106         if (super.replace(oldDelegate, newDelegate)) {
107             return true;
108         }
109         if (getDelegate().getPlugins().contains(oldDelegate)) {
110             List<org.apache.maven.api.model.Plugin> list = new ArrayList<>(getDelegate().getPlugins());
111             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Plugin) newDelegate : d);
112             update(getDelegate().withPlugins(list));
113             return true;
114         }
115         return false;
116     }
117 
118     public static List<org.apache.maven.api.model.PluginContainer> pluginContainerToApiV4(List<PluginContainer> list) {
119         return list != null ? new WrapperList<>(list, PluginContainer::getDelegate, PluginContainer::new) : null;
120     }
121 
122     public static List<PluginContainer> pluginContainerToApiV3(List<org.apache.maven.api.model.PluginContainer> list) {
123         return list != null ? new WrapperList<>(list, PluginContainer::new, PluginContainer::getDelegate) : null;
124     }
125 
126 
127             
128     Map<String, Plugin> pluginMap;
129 
130     /**
131      * Reset the {@code pluginsMap} field to {@code null}
132      */
133     public synchronized void flushPluginMap()
134     {
135         this.pluginMap = null;
136     }
137 
138     /**
139      * @return a Map of plugins field with {@code Plugins#getKey()} as key
140      * @see Plugin#getKey()
141      */
142     public synchronized Map<String, Plugin> getPluginsAsMap()
143     {
144         if ( pluginMap == null )
145         {
146             pluginMap = new java.util.LinkedHashMap<String, Plugin>();
147             if ( getPlugins() != null )
148             {
149                 for ( java.util.Iterator<Plugin> it = getPlugins().iterator(); it.hasNext(); )
150                 {
151                     Plugin plugin = (Plugin) it.next();
152                     pluginMap.put( plugin.getKey(), plugin );
153                 }
154             }
155         }
156 
157         return pluginMap;
158     }
159             
160           
161 
162             
163      @Override
164      public String toString()
165      {
166          return "PluginContainer {}";
167      }
168             
169           
170 }