001package org.apache.maven.repository.internal; 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.net.MalformedURLException; 023 024import org.apache.maven.repository.internal.util.ConsoleRepositoryListener; 025import org.apache.maven.repository.internal.util.ConsoleTransferListener; 026import org.codehaus.plexus.ContainerConfiguration; 027import org.codehaus.plexus.PlexusConstants; 028import org.codehaus.plexus.PlexusTestCase; 029import org.eclipse.aether.DefaultRepositorySystemSession; 030import org.eclipse.aether.RepositorySystem; 031import org.eclipse.aether.RepositorySystemSession; 032import org.eclipse.aether.repository.LocalRepository; 033import org.eclipse.aether.repository.RemoteRepository; 034 035public abstract class AbstractRepositoryTestCase 036 extends PlexusTestCase 037{ 038 protected RepositorySystem system; 039 040 protected RepositorySystemSession session; 041 042 @Override 043 protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) 044 { 045 super.customizeContainerConfiguration( containerConfiguration ); 046 containerConfiguration.setAutoWiring( true ); 047 containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); 048 } 049 050 @Override 051 protected void setUp() 052 throws Exception 053 { 054 super.setUp(); 055 system = lookup( RepositorySystem.class ); 056 session = newMavenRepositorySystemSession( system ); 057 } 058 059 @Override 060 protected void tearDown() 061 throws Exception 062 { 063 session = null; 064 system = null; 065 super.tearDown(); 066 } 067 068 public static RepositorySystemSession newMavenRepositorySystemSession( RepositorySystem system ) 069 { 070 DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); 071 072 LocalRepository localRepo = new LocalRepository( "target/local-repo" ); 073 session.setLocalRepositoryManager( system.newLocalRepositoryManager( session, localRepo ) ); 074 075 session.setTransferListener( new ConsoleTransferListener() ); 076 session.setRepositoryListener( new ConsoleRepositoryListener() ); 077 078 return session; 079 } 080 081 public static RemoteRepository newTestRepository() 082 throws MalformedURLException 083 { 084 return new RemoteRepository.Builder( "repo", "default", 085 getTestFile( "target/test-classes/repo" ).toURI().toURL().toString() ).build(); 086 } 087}