mirror of https://github.com/apache/archiva.git
PR: MRM-59
Made the proxy able to respond to m1 path requests git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@380871 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c810070fd7
commit
76e034ab47
|
@ -49,7 +49,7 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* @author Edwin Punzalan
|
||||
* @plexus.component role="org.apache.maven.repository.proxy.ProxyManager" role-hint="default"
|
||||
* @plexus.component role="org.apache.maven.repository.proxy.ProxyManager"
|
||||
*/
|
||||
public class DefaultProxyManager
|
||||
extends AbstractLogEnabled
|
||||
|
|
|
@ -49,7 +49,8 @@ public class ProxyManagerFactory
|
|||
public ProxyManager getProxyManager( String proxy_type, ProxyConfiguration config )
|
||||
throws ComponentLookupException
|
||||
{
|
||||
ProxyManager proxy = (ProxyManager) container.lookup( ProxyManager.ROLE, proxy_type );
|
||||
ProxyManager proxy = (ProxyManager) container.lookup( ProxyManager.ROLE );
|
||||
config.setLayout( proxy_type );
|
||||
proxy.setConfiguration( config );
|
||||
return proxy;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
|
||||
import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout;
|
||||
import org.apache.maven.repository.proxy.repository.ProxyRepository;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -52,6 +53,8 @@ public class ProxyConfiguration
|
|||
|
||||
private List repositories = new ArrayList();
|
||||
|
||||
private ArtifactRepositoryLayout layout;
|
||||
|
||||
/**
|
||||
* Method to set/unset the web-view of the repository cache
|
||||
*
|
||||
|
@ -83,11 +86,9 @@ public class ProxyConfiguration
|
|||
standardPolicy = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
|
||||
ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
|
||||
|
||||
ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
|
||||
|
||||
repoCache = artifactRepositoryFactory.createArtifactRepository( "localCache",
|
||||
"file://" + new File( path ).getAbsolutePath(),
|
||||
layout, standardPolicy, standardPolicy );
|
||||
getLayout(), standardPolicy, standardPolicy );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,7 +160,6 @@ public class ProxyConfiguration
|
|||
this.setBrowsable( rcc.isBrowsable() );
|
||||
|
||||
List repoList = new ArrayList();
|
||||
ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
|
||||
for ( Iterator repos = rcc.getRepos().iterator(); repos.hasNext(); )
|
||||
{
|
||||
RepoConfiguration repoConfig = (RepoConfiguration) repos.next();
|
||||
|
@ -167,7 +167,7 @@ public class ProxyConfiguration
|
|||
//skip local store repo
|
||||
if ( !repoConfig.getKey().equals( "global" ) )
|
||||
{
|
||||
ProxyRepository repo = new ProxyRepository( repoConfig.getKey(), repoConfig.getUrl(), layout );
|
||||
ProxyRepository repo = new ProxyRepository( repoConfig.getKey(), repoConfig.getUrl(), getLayout() );
|
||||
repo.setCacheFailures( repoConfig.getCacheFailures() );
|
||||
repo.setCachePeriod( repoConfig.getCachePeriod() );
|
||||
repo.setHardfail( repoConfig.getHardFail() );
|
||||
|
@ -186,4 +186,26 @@ public class ProxyConfiguration
|
|||
|
||||
this.setRepositories( repoList );
|
||||
}
|
||||
|
||||
public ArtifactRepositoryLayout getLayout()
|
||||
{
|
||||
if ( layout == null )
|
||||
{
|
||||
setLayout( "default" );
|
||||
}
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
public void setLayout( String layout )
|
||||
{
|
||||
if ( "legacy".equalsIgnoreCase( layout ) )
|
||||
{
|
||||
this.layout = new LegacyRepositoryLayout();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.layout = new DefaultRepositoryLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,150 @@
|
|||
package org.apache.maven.repository.proxy;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout;
|
||||
import org.apache.maven.repository.proxy.configuration.ProxyConfiguration;
|
||||
import org.apache.maven.repository.proxy.repository.ProxyRepository;
|
||||
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Edwin Punzalan
|
||||
*/
|
||||
public class LegacyProxyManagerTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
private ProxyManager proxy;
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
ProxyManagerFactory factory = (ProxyManagerFactory) container.lookup( ProxyManagerFactory.ROLE );
|
||||
proxy = factory.getProxyManager( "default", getTestConfiguration() );
|
||||
}
|
||||
|
||||
public void testExceptions()
|
||||
{
|
||||
proxy.setConfiguration( null );
|
||||
|
||||
try
|
||||
{
|
||||
proxy.get( "/invalid" );
|
||||
fail( "Expected empty configuration error." );
|
||||
}
|
||||
catch ( ProxyException e )
|
||||
{
|
||||
assertEquals( "Expected Exception not thrown.", "No proxy configuration defined.", e.getMessage() );
|
||||
}
|
||||
catch ( ResourceDoesNotExistException e )
|
||||
{
|
||||
fail( "Expected Exception not thrown." );
|
||||
}
|
||||
}
|
||||
|
||||
public void testArtifactDownload()
|
||||
throws Exception
|
||||
{
|
||||
//test download
|
||||
File file = proxy.get( "/commons-logging/jars/commons-logging-1.0.jar" );
|
||||
assertTrue( "File must be downloaded.", file.exists() );
|
||||
assertTrue( "Downloaded file should be present in the cache.",
|
||||
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
|
||||
|
||||
//test cache
|
||||
file = proxy.get( "/commons-logging/jars/commons-logging-1.0.jar" );
|
||||
|
||||
try
|
||||
{
|
||||
file = proxy.get( "/commons-logging/jars/commons-logging-2.0.jar" );
|
||||
fail( "Expected ResourceDoesNotExistException exception not thrown" );
|
||||
}
|
||||
catch ( ResourceDoesNotExistException e )
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
|
||||
public void testArtifactChecksum()
|
||||
throws Exception
|
||||
{
|
||||
//force the downlod from the remote repository, use getRemoteFile()
|
||||
File file = proxy.getRemoteFile( "/commons-logging/jars/commons-logging-1.0.jar.md5" );
|
||||
assertTrue( "File must be downloaded.", file.exists() );
|
||||
assertTrue( "Downloaded file should be present in the cache.",
|
||||
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
|
||||
}
|
||||
|
||||
public void testNonArtifactWithNoChecksum()
|
||||
throws Exception
|
||||
{
|
||||
File file = proxy.get( "/not-standard/repository/file.txt" );
|
||||
assertTrue( "File must be downloaded.", file.exists() );
|
||||
assertTrue( "Downloaded file should be present in the cache.",
|
||||
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
|
||||
}
|
||||
|
||||
public void testNonArtifactWithMD5Checksum()
|
||||
throws Exception
|
||||
{
|
||||
File file = proxy.get( "/checksumed-md5/repository/file.txt" );
|
||||
assertTrue( "File must be downloaded.", file.exists() );
|
||||
assertTrue( "Downloaded file should be present in the cache.",
|
||||
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
|
||||
}
|
||||
|
||||
public void testNonArtifactWithSHA1Checksum()
|
||||
throws Exception
|
||||
{
|
||||
File file = proxy.get( "/checksumed-sha1/repository/file.txt" );
|
||||
assertTrue( "File must be downloaded.", file.exists() );
|
||||
assertTrue( "Downloaded file should be present in the cache.",
|
||||
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
container.release( proxy );
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private ProxyConfiguration getTestConfiguration()
|
||||
throws ComponentLookupException
|
||||
{
|
||||
ProxyConfiguration config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE );
|
||||
|
||||
config.setRepositoryCachePath( "target/proxy-cache" );
|
||||
|
||||
ArtifactRepositoryLayout layout = new LegacyRepositoryLayout();
|
||||
|
||||
File repo1File = getTestFile( "src/test/m1-remote-repo" );
|
||||
|
||||
ProxyRepository repo1 = new ProxyRepository( "m1-test-repo", "file://" + repo1File.getAbsolutePath(), layout );
|
||||
|
||||
config.addRepository( repo1 );
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
test file only
|
|
@ -0,0 +1 @@
|
|||
a473f827aa9d5df4e84c802e054c50f7
|
|
@ -0,0 +1 @@
|
|||
test file only
|
|
@ -0,0 +1 @@
|
|||
afb037c2bd96fe1ef1cfd220e82682d088d60d3e
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
240b26992977c9ad119efb91cb21f8f8
|
|
@ -0,0 +1,6 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.0</version>
|
||||
</project>
|
|
@ -0,0 +1 @@
|
|||
test file only
|
Loading…
Reference in New Issue