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