001package org.eclipse.aether.internal.impl.filter; 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 org.eclipse.aether.RepositorySystemSession; 023import org.eclipse.aether.artifact.Artifact; 024import org.eclipse.aether.metadata.Metadata; 025import org.eclipse.aether.repository.RemoteRepository; 026import org.eclipse.aether.spi.connector.filter.RemoteRepositoryFilter; 027import org.eclipse.aether.spi.connector.filter.RemoteRepositoryFilterSource; 028 029/** 030 * Some filters used in UTs. 031 */ 032public final class Filters 033{ 034 /** 035 * Returns a filter that always accepts. 036 */ 037 public static RemoteRepositoryFilterSource alwaysAccept() 038 { 039 return new RemoteRepositoryFilterSource() 040 { 041 public String getName() 042 { 043 return "always-accept"; 044 } 045 046 private final RemoteRepositoryFilter.Result RESULT = 047 new RemoteRepositoryFilterSourceSupport.SimpleResult( true, getName() ); 048 049 @Override 050 public RemoteRepositoryFilter getRemoteRepositoryFilter( RepositorySystemSession session ) 051 { 052 return new RemoteRepositoryFilter() 053 { 054 @Override 055 public Result acceptArtifact( RemoteRepository remoteRepository, Artifact artifact ) 056 { 057 return RESULT; 058 } 059 060 @Override 061 public Result acceptMetadata( RemoteRepository remoteRepository, Metadata metadata ) 062 { 063 return RESULT; 064 } 065 }; 066 } 067 }; 068 } 069 070 /** 071 * Returns a filter that always accepts from given repo. 072 */ 073 public static RemoteRepositoryFilterSource alwaysAcceptFrom( String repoId ) 074 { 075 return new RemoteRepositoryFilterSource() 076 { 077 public String getName() 078 { 079 return "always-accept-" + repoId; 080 } 081 082 private final RemoteRepositoryFilter.Result MATCHED = 083 new RemoteRepositoryFilterSourceSupport.SimpleResult( true, getName() ); 084 085 private final RemoteRepositoryFilter.Result UNMATCHED = 086 new RemoteRepositoryFilterSourceSupport.SimpleResult( false, getName() ); 087 088 @Override 089 public RemoteRepositoryFilter getRemoteRepositoryFilter( RepositorySystemSession session ) 090 { 091 return new RemoteRepositoryFilter() 092 { 093 @Override 094 public Result acceptArtifact( RemoteRepository remoteRepository, Artifact artifact ) 095 { 096 return repoId.equals( remoteRepository.getId() ) ? MATCHED : UNMATCHED; 097 } 098 099 @Override 100 public Result acceptMetadata( RemoteRepository remoteRepository, Metadata metadata ) 101 { 102 return repoId.equals( remoteRepository.getId() ) ? MATCHED : UNMATCHED; 103 } 104 }; 105 } 106 }; 107 } 108 109 /** 110 * Returns a filter that never accepts. 111 */ 112 public static RemoteRepositoryFilterSource neverAccept() 113 { 114 return new RemoteRepositoryFilterSource() 115 { 116 public String getName() 117 { 118 return "never-accept"; 119 } 120 121 private final RemoteRepositoryFilter.Result RESULT = 122 new RemoteRepositoryFilterSourceSupport.SimpleResult( false, getName() ); 123 124 @Override 125 public RemoteRepositoryFilter getRemoteRepositoryFilter( RepositorySystemSession session ) 126 { 127 return new RemoteRepositoryFilter() 128 { 129 @Override 130 public Result acceptArtifact( RemoteRepository remoteRepository, Artifact artifact ) 131 { 132 return RESULT; 133 } 134 135 @Override 136 public Result acceptMetadata( RemoteRepository remoteRepository, Metadata metadata ) 137 { 138 return RESULT; 139 } 140 }; 141 } 142 }; 143 } 144 145 /** 146 * Returns a filter that never accepts from given repo. 147 */ 148 public static RemoteRepositoryFilterSource neverAcceptFrom( String repoId ) 149 { 150 return new RemoteRepositoryFilterSource() 151 { 152 public String getName() 153 { 154 return "never-accept-" + repoId; 155 } 156 157 private final RemoteRepositoryFilter.Result MATCHED = 158 new RemoteRepositoryFilterSourceSupport.SimpleResult( false, getName() ); 159 160 private final RemoteRepositoryFilter.Result UNMATCHED = 161 new RemoteRepositoryFilterSourceSupport.SimpleResult( true, getName() ); 162 163 @Override 164 public RemoteRepositoryFilter getRemoteRepositoryFilter( RepositorySystemSession session ) 165 { 166 return new RemoteRepositoryFilter() 167 { 168 @Override 169 public Result acceptArtifact( RemoteRepository remoteRepository, Artifact artifact ) 170 { 171 return repoId.equals( remoteRepository.getId() ) ? MATCHED : UNMATCHED; 172 } 173 174 @Override 175 public Result acceptMetadata( RemoteRepository remoteRepository, Metadata metadata ) 176 { 177 return repoId.equals( remoteRepository.getId() ) ? MATCHED : UNMATCHED; 178 } 179 }; 180 } 181 }; 182 } 183}