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 java.io.IOException; 023import java.io.UncheckedIOException; 024import java.nio.file.Files; 025import java.util.Collections; 026import java.util.List; 027 028import org.eclipse.aether.DefaultRepositorySystemSession; 029import org.eclipse.aether.artifact.Artifact; 030import org.eclipse.aether.internal.impl.DefaultRepositorySystemLifecycle; 031import org.eclipse.aether.repository.RemoteRepository; 032import org.eclipse.aether.resolution.ArtifactRequest; 033import org.eclipse.aether.resolution.ArtifactResult; 034 035/** 036 * UT for {@link GroupIdRemoteRepositoryFilterSource}. 037 */ 038public class GroupIdRemoteRepositoryFilterSourceTest extends RemoteRepositoryFilterSourceTestSupport 039{ 040 private GroupIdRemoteRepositoryFilterSource groupIdRemoteRepositoryFilterSource; 041 042 @Override 043 protected GroupIdRemoteRepositoryFilterSource getRemoteRepositoryFilterSource( 044 DefaultRepositorySystemSession session, RemoteRepository remoteRepository ) 045 { 046 return groupIdRemoteRepositoryFilterSource = 047 new GroupIdRemoteRepositoryFilterSource( new DefaultRepositorySystemLifecycle() ); 048 } 049 050 @Override 051 protected void enableSource( DefaultRepositorySystemSession session ) 052 { 053 session.setConfigProperty( "aether.remoteRepositoryFilter." + GroupIdRemoteRepositoryFilterSource.NAME, 054 Boolean.TRUE.toString() ); 055 } 056 057 protected void allowArtifact( DefaultRepositorySystemSession session, RemoteRepository remoteRepository, 058 Artifact artifact ) 059 { 060 DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession( session ); 061 try 062 { 063 Artifact resolvedArtifact = artifact.setFile( Files.createTempFile( "test", "tmp" ).toFile() ); 064 ArtifactResult artifactResult = new ArtifactResult( new ArtifactRequest( resolvedArtifact, 065 Collections.singletonList( remoteRepository ), "context" ) ); 066 artifactResult.setArtifact( resolvedArtifact ); 067 artifactResult.setRepository( remoteRepository ); 068 List<ArtifactResult> artifactResults = Collections.singletonList( artifactResult ); 069 enableSource( newSession ); 070 newSession.setConfigProperty( "aether.remoteRepositoryFilter." + GroupIdRemoteRepositoryFilterSource.NAME 071 + ".record", Boolean.TRUE.toString() ); 072 groupIdRemoteRepositoryFilterSource.postProcess( newSession, artifactResults ); 073 } 074 catch ( IOException e ) 075 { 076 throw new UncheckedIOException( e ); 077 } 078 079 } 080}