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.charset.StandardCharsets; 025import java.nio.file.Files; 026import java.nio.file.Path; 027 028import org.eclipse.aether.DefaultRepositorySystemSession; 029import org.eclipse.aether.artifact.Artifact; 030import org.eclipse.aether.internal.impl.DefaultRepositoryLayoutProvider; 031import org.eclipse.aether.internal.impl.Maven2RepositoryLayoutFactory; 032import org.eclipse.aether.repository.RemoteRepository; 033import org.eclipse.aether.spi.connector.filter.RemoteRepositoryFilterSource; 034 035/** 036 * UT for {@link PrefixesRemoteRepositoryFilterSource}. 037 */ 038public class PrefixesRemoteRepositoryFilterSourceTest extends RemoteRepositoryFilterSourceTestSupport 039{ 040 @Override 041 protected RemoteRepositoryFilterSource getRemoteRepositoryFilterSource( 042 DefaultRepositorySystemSession session, RemoteRepository remoteRepository ) 043 { 044 DefaultRepositoryLayoutProvider layoutProvider = new DefaultRepositoryLayoutProvider(); 045 layoutProvider.addRepositoryLayoutFactory( new Maven2RepositoryLayoutFactory() ); 046 return new PrefixesRemoteRepositoryFilterSource( layoutProvider ); 047 } 048 049 @Override 050 protected void enableSource( DefaultRepositorySystemSession session ) 051 { 052 session.setConfigProperty( "aether.remoteRepositoryFilter." + PrefixesRemoteRepositoryFilterSource.NAME, 053 Boolean.TRUE.toString() ); 054 } 055 056 @Override 057 protected void allowArtifact( DefaultRepositorySystemSession session, RemoteRepository remoteRepository, 058 Artifact artifact ) 059 { 060 try 061 { 062 Path baseDir = session.getLocalRepository().getBasedir().toPath() 063 .resolve( PrefixesRemoteRepositoryFilterSource.LOCAL_REPO_PREFIX_DIR ); 064 Path groupId = baseDir 065 .resolve( PrefixesRemoteRepositoryFilterSource.PREFIXES_FILE_PREFIX + remoteRepository.getId() 066 + PrefixesRemoteRepositoryFilterSource.PREFIXES_FILE_SUFFIX ); 067 Files.createDirectories( groupId.getParent() ); 068 Files.write( groupId, artifact.getGroupId().replaceAll( "\\.", "/" ).getBytes( StandardCharsets.UTF_8 ) ); 069 } 070 catch ( IOException e ) 071 { 072 throw new UncheckedIOException( e ); 073 } 074 } 075}