mirror of https://github.com/apache/archiva.git
moved configuration validations inside the configuration object
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@414043 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d58fe15c35
commit
3e28334fa3
|
@ -20,12 +20,10 @@ import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
|
||||||
import org.apache.maven.repository.proxy.repository.ProxyRepository;
|
import org.apache.maven.repository.proxy.repository.ProxyRepository;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
@ -116,26 +114,11 @@ public class MavenProxyPropertyLoader
|
||||||
|
|
||||||
config.setRepositories( repositories );
|
config.setRepositories( repositories );
|
||||||
|
|
||||||
validateDirectories( config );
|
config.validate();
|
||||||
validateRemoteRepo( config );
|
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo should be shared with any other configuration loader - move method to configuration?
|
|
||||||
*/
|
|
||||||
private static void validateRemoteRepo( ProxyConfiguration configuration )
|
|
||||||
throws ValidationException
|
|
||||||
{
|
|
||||||
//Verify remote repository set
|
|
||||||
//only warn if missing
|
|
||||||
if ( configuration.getRepositories().size() < 1 )
|
|
||||||
{
|
|
||||||
throw new ValidationException( "At least one remote repository must be configured." );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Properties getSubset( Properties props, String prefix )
|
private Properties getSubset( Properties props, String prefix )
|
||||||
{
|
{
|
||||||
Enumeration keys = props.keys();
|
Enumeration keys = props.keys();
|
||||||
|
@ -173,31 +156,4 @@ public class MavenProxyPropertyLoader
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo should be shared with any other configuration loader - move method to configuration?
|
|
||||||
*/
|
|
||||||
private static void validateDirectories( ProxyConfiguration configuration )
|
|
||||||
throws ValidationException
|
|
||||||
{
|
|
||||||
File f = new File( configuration.getRepositoryCachePath() );
|
|
||||||
if ( !f.exists() )
|
|
||||||
{
|
|
||||||
throw new ValidationException( "Specified directory does not exist: " + f.getAbsolutePath() );
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( Iterator repos = configuration.getRepositories().iterator(); repos.hasNext(); )
|
|
||||||
{
|
|
||||||
ProxyRepository repo = (ProxyRepository) repos.next();
|
|
||||||
if ( repo.getUrl().startsWith( "file://" ) )
|
|
||||||
{
|
|
||||||
File f2 = new File( repo.getBasedir() );
|
|
||||||
if ( !f2.exists() )
|
|
||||||
{
|
|
||||||
throw new ValidationException( "Specified directory does not exist: " + f2.getAbsolutePath() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -23,6 +23,7 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to represent the configuration file for the proxy
|
* Class to represent the configuration file for the proxy
|
||||||
|
@ -141,4 +142,45 @@ public class ProxyConfiguration
|
||||||
{
|
{
|
||||||
this.layout = layout;
|
this.layout = layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void validate()
|
||||||
|
throws ValidationException
|
||||||
|
{
|
||||||
|
validateRemoteRepo();
|
||||||
|
validateDirectories();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateRemoteRepo( )
|
||||||
|
throws ValidationException
|
||||||
|
{
|
||||||
|
//Verify remote repository set
|
||||||
|
//only warn if missing
|
||||||
|
if ( getRepositories().size() < 1 )
|
||||||
|
{
|
||||||
|
throw new ValidationException( "At least one remote repository must be configured." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateDirectories()
|
||||||
|
throws ValidationException
|
||||||
|
{
|
||||||
|
File f = new File( getRepositoryCachePath() );
|
||||||
|
if ( !f.exists() )
|
||||||
|
{
|
||||||
|
throw new ValidationException( "Specified directory does not exist: " + f.getAbsolutePath() );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( Iterator repos = getRepositories().iterator(); repos.hasNext(); )
|
||||||
|
{
|
||||||
|
ProxyRepository repo = (ProxyRepository) repos.next();
|
||||||
|
if ( repo.getUrl().startsWith( "file://" ) )
|
||||||
|
{
|
||||||
|
File f2 = new File( repo.getBasedir() );
|
||||||
|
if ( !f2.exists() )
|
||||||
|
{
|
||||||
|
throw new ValidationException( "Specified directory does not exist: " + f2.getAbsolutePath() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue