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.test.util;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.Iterator;
24  import java.util.List;
25  
26  import org.eclipse.aether.RepositorySystemSession;
27  import org.eclipse.aether.collection.VersionFilter;
28  import org.eclipse.aether.graph.Dependency;
29  import org.eclipse.aether.repository.ArtifactRepository;
30  import org.eclipse.aether.repository.RemoteRepository;
31  import org.eclipse.aether.resolution.VersionRangeResult;
32  import org.eclipse.aether.version.Version;
33  import org.eclipse.aether.version.VersionConstraint;
34  
35  /**
36   */
37  class TestVersionFilterContext implements VersionFilter.VersionFilterContext {
38  
39      private final RepositorySystemSession session;
40  
41      private final Dependency dependency;
42  
43      private final VersionRangeResult result;
44  
45      private final List<Version> versions;
46  
47      TestVersionFilterContext(RepositorySystemSession session, VersionRangeResult result) {
48          this.session = session;
49          this.result = result;
50          dependency = new Dependency(result.getRequest().getArtifact(), "");
51          versions = new ArrayList<>(result.getVersions());
52      }
53  
54      public RepositorySystemSession getSession() {
55          return session;
56      }
57  
58      public Dependency getDependency() {
59          return dependency;
60      }
61  
62      public int getCount() {
63          return versions.size();
64      }
65  
66      public Iterator<Version> iterator() {
67          return versions.iterator();
68      }
69  
70      public VersionConstraint getVersionConstraint() {
71          return result.getVersionConstraint();
72      }
73  
74      public ArtifactRepository getRepository(Version version) {
75          return result.getRepository(version);
76      }
77  
78      public List<RemoteRepository> getRepositories() {
79          return Collections.unmodifiableList(result.getRequest().getRepositories());
80      }
81  }