View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.internal.impl;
20  
21  import java.util.ArrayList;
22  import java.util.Arrays;
23  import java.util.Collections;
24  import java.util.EnumSet;
25  import java.util.List;
26  import java.util.Set;
27  import java.util.stream.Collectors;
28  
29  import org.eclipse.aether.RepositoryEvent;
30  import org.eclipse.aether.RepositoryListener;
31  
32  import static java.util.Objects.requireNonNull;
33  
34  /**
35   * Collects observed repository events for later inspection.
36   */
37  class RecordingRepositoryListener implements RepositoryListener {
38  
39      private final List<RepositoryEvent> events = Collections.synchronizedList(new ArrayList<>());
40  
41      public List<RepositoryEvent> getEvents(RepositoryEvent.EventType... types) {
42          if (types == null || types.length == 0) {
43              return events;
44          }
45          Set<RepositoryEvent.EventType> requiredTypes = EnumSet.copyOf(Arrays.asList(types));
46          return events.stream().filter(e -> requiredTypes.contains(e.getType())).collect(Collectors.toList());
47      }
48  
49      public void clear() {
50          events.clear();
51      }
52  
53      public void artifactDescriptorInvalid(RepositoryEvent event) {
54          requireNonNull(event, "event cannot be null");
55          events.add(event);
56      }
57  
58      public void artifactDescriptorMissing(RepositoryEvent event) {
59          requireNonNull(event, "event cannot be null");
60          events.add(event);
61      }
62  
63      public void metadataInvalid(RepositoryEvent event) {
64          requireNonNull(event, "event cannot be null");
65          events.add(event);
66      }
67  
68      public void artifactResolving(RepositoryEvent event) {
69          requireNonNull(event, "event cannot be null");
70          events.add(event);
71      }
72  
73      public void artifactResolved(RepositoryEvent event) {
74          requireNonNull(event, "event cannot be null");
75          events.add(event);
76      }
77  
78      public void artifactDownloading(RepositoryEvent event) {
79          requireNonNull(event, "event cannot be null");
80          events.add(event);
81      }
82  
83      public void artifactDownloaded(RepositoryEvent event) {
84          requireNonNull(event, "event cannot be null");
85          events.add(event);
86      }
87  
88      public void metadataDownloaded(RepositoryEvent event) {
89          requireNonNull(event, "event cannot be null");
90          events.add(event);
91      }
92  
93      public void metadataDownloading(RepositoryEvent event) {
94          requireNonNull(event, "event cannot be null");
95          events.add(event);
96      }
97  
98      public void metadataResolving(RepositoryEvent event) {
99          requireNonNull(event, "event cannot be null");
100         events.add(event);
101     }
102 
103     public void metadataResolved(RepositoryEvent event) {
104         requireNonNull(event, "event cannot be null");
105         events.add(event);
106     }
107 
108     public void artifactInstalling(RepositoryEvent event) {
109         requireNonNull(event, "event cannot be null");
110         events.add(event);
111     }
112 
113     public void artifactInstalled(RepositoryEvent event) {
114         requireNonNull(event, "event cannot be null");
115         events.add(event);
116     }
117 
118     public void metadataInstalling(RepositoryEvent event) {
119         requireNonNull(event, "event cannot be null");
120         events.add(event);
121     }
122 
123     public void metadataInstalled(RepositoryEvent event) {
124         requireNonNull(event, "event cannot be null");
125         events.add(event);
126     }
127 
128     public void artifactDeploying(RepositoryEvent event) {
129         requireNonNull(event, "event cannot be null");
130         events.add(event);
131     }
132 
133     public void artifactDeployed(RepositoryEvent event) {
134         requireNonNull(event, "event cannot be null");
135         events.add(event);
136     }
137 
138     public void metadataDeploying(RepositoryEvent event) {
139         requireNonNull(event, "event cannot be null");
140         events.add(event);
141     }
142 
143     public void metadataDeployed(RepositoryEvent event) {
144         requireNonNull(event, "event cannot be null");
145         events.add(event);
146     }
147 }