001package org.eclipse.aether.internal.impl.collect; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.ArrayList; 023import java.util.Collections; 024import java.util.Iterator; 025import java.util.List; 026 027import org.eclipse.aether.RepositorySystemSession; 028import org.eclipse.aether.collection.VersionFilter; 029import org.eclipse.aether.graph.Dependency; 030import org.eclipse.aether.repository.ArtifactRepository; 031import org.eclipse.aether.repository.RemoteRepository; 032import org.eclipse.aether.resolution.VersionRangeResult; 033import org.eclipse.aether.version.Version; 034import org.eclipse.aether.version.VersionConstraint; 035 036/** 037 * Default implementation of {@link VersionFilter.VersionFilterContext}. 038 * Internal helper class for collector implementations. 039 */ 040public final class DefaultVersionFilterContext 041 implements VersionFilter.VersionFilterContext 042{ 043 private final RepositorySystemSession session; 044 045 private Dependency dependency; 046 047 VersionRangeResult result; 048 049 private List<Version> versions; 050 051 public DefaultVersionFilterContext( RepositorySystemSession session ) 052 { 053 this.session = session; 054 } 055 056 public void set( Dependency dependency, VersionRangeResult result ) 057 { 058 this.dependency = dependency; 059 this.result = result; 060 this.versions = new ArrayList<>( result.getVersions() ); 061 } 062 063 public List<Version> get() 064 { 065 return new ArrayList<>( versions ); 066 } 067 068 @Override 069 public RepositorySystemSession getSession() 070 { 071 return session; 072 } 073 074 @Override 075 public Dependency getDependency() 076 { 077 return dependency; 078 } 079 080 @Override 081 public VersionConstraint getVersionConstraint() 082 { 083 return result.getVersionConstraint(); 084 } 085 086 @Override 087 public int getCount() 088 { 089 return versions.size(); 090 } 091 092 @Override 093 public ArtifactRepository getRepository( Version version ) 094 { 095 return result.getRepository( version ); 096 } 097 098 @Override 099 public List<RemoteRepository> getRepositories() 100 { 101 return Collections.unmodifiableList( result.getRequest().getRepositories() ); 102 } 103 104 @Override 105 public Iterator<Version> iterator() 106 { 107 return versions.iterator(); 108 } 109 110 @Override 111 public String toString() 112 { 113 return dependency + " " + result.getVersions(); 114 } 115}