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      @Override
54      public void artifactDescriptorInvalid(RepositoryEvent event) {
55          requireNonNull(event, "event cannot be null");
56          events.add(event);
57      }
58  
59      @Override
60      public void artifactDescriptorMissing(RepositoryEvent event) {
61          requireNonNull(event, "event cannot be null");
62          events.add(event);
63      }
64  
65      @Override
66      public void metadataInvalid(RepositoryEvent event) {
67          requireNonNull(event, "event cannot be null");
68          events.add(event);
69      }
70  
71      @Override
72      public void artifactResolving(RepositoryEvent event) {
73          requireNonNull(event, "event cannot be null");
74          events.add(event);
75      }
76  
77      @Override
78      public void artifactResolved(RepositoryEvent event) {
79          requireNonNull(event, "event cannot be null");
80          events.add(event);
81      }
82  
83      @Override
84      public void artifactDownloading(RepositoryEvent event) {
85          requireNonNull(event, "event cannot be null");
86          events.add(event);
87      }
88  
89      @Override
90      public void artifactDownloaded(RepositoryEvent event) {
91          requireNonNull(event, "event cannot be null");
92          events.add(event);
93      }
94  
95      @Override
96      public void metadataDownloaded(RepositoryEvent event) {
97          requireNonNull(event, "event cannot be null");
98          events.add(event);
99      }
100 
101     @Override
102     public void metadataDownloading(RepositoryEvent event) {
103         requireNonNull(event, "event cannot be null");
104         events.add(event);
105     }
106 
107     @Override
108     public void metadataResolving(RepositoryEvent event) {
109         requireNonNull(event, "event cannot be null");
110         events.add(event);
111     }
112 
113     @Override
114     public void metadataResolved(RepositoryEvent event) {
115         requireNonNull(event, "event cannot be null");
116         events.add(event);
117     }
118 
119     @Override
120     public void artifactInstalling(RepositoryEvent event) {
121         requireNonNull(event, "event cannot be null");
122         events.add(event);
123     }
124 
125     @Override
126     public void artifactInstalled(RepositoryEvent event) {
127         requireNonNull(event, "event cannot be null");
128         events.add(event);
129     }
130 
131     @Override
132     public void metadataInstalling(RepositoryEvent event) {
133         requireNonNull(event, "event cannot be null");
134         events.add(event);
135     }
136 
137     @Override
138     public void metadataInstalled(RepositoryEvent event) {
139         requireNonNull(event, "event cannot be null");
140         events.add(event);
141     }
142 
143     @Override
144     public void artifactDeploying(RepositoryEvent event) {
145         requireNonNull(event, "event cannot be null");
146         events.add(event);
147     }
148 
149     @Override
150     public void artifactDeployed(RepositoryEvent event) {
151         requireNonNull(event, "event cannot be null");
152         events.add(event);
153     }
154 
155     @Override
156     public void metadataDeploying(RepositoryEvent event) {
157         requireNonNull(event, "event cannot be null");
158         events.add(event);
159     }
160 
161     @Override
162     public void metadataDeployed(RepositoryEvent event) {
163         requireNonNull(event, "event cannot be null");
164         events.add(event);
165     }
166 }