PR: MRM-107

Removed classes from maven-proxy that may not be required at all.

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@386036 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Edwin L. Punzalan 2006-03-15 10:27:57 +00:00
parent e6c475550f
commit d3e88a986a
13 changed files with 312 additions and 1098 deletions

View File

@ -1,50 +0,0 @@
package org.apache.maven.repository.proxy.configuration;
/*
* Copyright 2003-2004 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 java.io.File;
/**
* Strips file:/// off the front of the configured URL and uses that to find files locally.
*
* @author Ben Walding
*/
public class FileRepoConfiguration
extends RepoConfiguration
{
private final String basePath;
public FileRepoConfiguration( String key, String url, String description, boolean copy, boolean hardFail,
boolean cacheFailures, long cachePeriod )
{
super( key, url, description, copy, hardFail, cacheFailures, cachePeriod );
basePath = url.substring( 8 );
}
public String getBasePath()
{
return basePath;
}
/**
* Given a relative path, returns the absolute file in the repository
*/
public File getLocalFile( String path )
{
return new File( basePath + path );
}
}

View File

@ -1,14 +0,0 @@
package org.apache.maven.repository.proxy.configuration;
/**
* @author Ben Walding
*/
public class GlobalRepoConfiguration
extends FileRepoConfiguration
{
public GlobalRepoConfiguration( String basePath )
{
super( "global", "file:///" + basePath, "Global Repository", false, true, false, 0 );
}
}

View File

@ -1,64 +0,0 @@
package org.apache.maven.repository.proxy.configuration;
/*
* Copyright 2003-2004 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.
*/
/**
* @author Ben Walding
*/
public class HttpRepoConfiguration
extends RepoConfiguration
{
private final String username;
private final String password;
private final MavenProxyConfiguration proxy;
public HttpRepoConfiguration( String key, String url, String description, String username, String password,
boolean hardFail, MavenProxyConfiguration proxy, boolean cacheFailures,
long cachePeriod )
{
super( key, url, description, true, hardFail, cacheFailures, cachePeriod );
this.username = username;
this.password = password;
this.proxy = proxy;
}
/**
*
*/
public String getPassword()
{
return password;
}
/**
*
*/
public String getUsername()
{
return username;
}
/**
*
*/
public MavenProxyConfiguration getProxy()
{
return proxy;
}
}

View File

@ -1,54 +0,0 @@
package org.apache.maven.repository.proxy.configuration;
/**
* Immutable.
*
* @author Ben Walding
*/
public class MavenProxyConfiguration
{
private final String key;
private final String host;
private final int port;
private final String username;
private final String password;
public MavenProxyConfiguration( String key, String host, int port, String username, String password )
{
this.key = key;
this.host = host;
this.port = port;
this.username = username;
this.password = password;
}
public String getHost()
{
return host;
}
public String getKey()
{
return key;
}
public String getPassword()
{
return password;
}
public int getPort()
{
return port;
}
public String getUsername()
{
return username;
}
}

View File

@ -1,67 +0,0 @@
package org.apache.maven.repository.proxy.configuration;
import org.apache.maven.repository.proxy.repository.ProxyRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
/**
* @author Edwin Punzalan
*/
public class MavenProxyConfigurationReader
{
/**
* Uses maven-proxy classes to read a maven-proxy properties configuration
*
* @param mavenProxyConfigurationFile The location of the maven-proxy configuration file
* @throws ValidationException When a problem occured while processing the properties file
* @throws java.io.IOException When a problem occured while reading the property file
*/
public ProxyConfiguration loadMavenProxyConfiguration( File mavenProxyConfigurationFile )
throws ValidationException, IOException
{
ProxyConfiguration configuration = new ProxyConfiguration();
MavenProxyPropertyLoader loader = new MavenProxyPropertyLoader();
RetrievalComponentConfiguration rcc = loader.load( new FileInputStream( mavenProxyConfigurationFile ) );
configuration.setRepositoryCachePath( rcc.getLocalStore() );
List repoList = new ArrayList();
for ( Iterator repos = rcc.getRepos().iterator(); repos.hasNext(); )
{
RepoConfiguration repoConfig = (RepoConfiguration) repos.next();
//skip local store repo
if ( !repoConfig.getKey().equals( "global" ) )
{
ProxyRepository repo = new ProxyRepository( repoConfig.getKey(), repoConfig.getUrl(), new DefaultRepositoryLayout() );
repo.setCacheFailures( repoConfig.getCacheFailures() );
repo.setCachePeriod( repoConfig.getCachePeriod() );
repo.setHardfail( repoConfig.getHardFail() );
if ( repoConfig instanceof HttpRepoConfiguration )
{
HttpRepoConfiguration httpRepo = (HttpRepoConfiguration) repoConfig;
MavenProxyConfiguration httpProxy = httpRepo.getProxy();
//todo put into the configuration the proxy
if ( httpProxy != null )
{
repo.setProxied( true );
}
}
repoList.add( repo );
}
}
configuration.setRepositories( repoList );
return configuration;
}
}

View File

@ -16,9 +16,14 @@ package org.apache.maven.repository.proxy.configuration;
* limitations under the License.
*/
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.repository.proxy.repository.ProxyRepository;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
@ -30,113 +35,57 @@ import java.util.StringTokenizer;
*/
public class MavenProxyPropertyLoader
{
private static final String REPO_LOCAL_STORE = "repo.local.store";
public static final String REPO_LOCAL_STORE = "repo.local.store";
private static final String PROXY_LIST = "proxy.list";
public static final String REPO_CUSTOM_STORE = "repo.custom.store";
private static final String REPO_LIST = "repo.list";
public static final String PORT = "port";
public static final String SNAPSHOT_UPDATE = "snapshot.update";
public static final String SNAPSHOT_CACHE_FAILURES = "snapshot.cache.failures";
public static final String METADATA_UPDATE = "metadata.update";
public static final String POM_UPDATE = "pom.update";
public static final int DEFAULT_PORT = 4321;
public static final String LAST_MODIFIED_DATE_FORMAT = "lastModifiedDateFormat";
public static final String DEFAULT_LAST_MODIFIED_DATE_FORMAT = null;
public static final String BROWSABLE = "browsable";
public static final String SEARCHABLE = "searchable";
public static final String STYLESHEET = "stylesheet";
public static final String BGCOLOR = "css.bgColor";
public static final String BGCOLORHIGHLIGHT = "css.bgColorHighlight";
public static final String ROWCOLOR = "css.rowColor";
public static final String ROWCOLORHIGHLIGHT = "css.rowColorHighlight";
public static final String PREFIX = "prefix";
private static final String SERVERNAME = "serverName";
public RetrievalComponentConfiguration load( Properties props )
public ProxyConfiguration load( Properties props )
throws ValidationException
{
RetrievalComponentConfiguration rcc = new RetrievalComponentConfiguration();
ProxyConfiguration config = new ProxyConfiguration();
String localStore = getMandatoryProperty( props, REPO_LOCAL_STORE );
GlobalRepoConfiguration globalRepo = new GlobalRepoConfiguration( localStore );
rcc.setLocalStore( localStore );
rcc.addRepo( globalRepo );
config.setLayout( "default" );
if ( props.getProperty( PORT ) == null )
{
rcc.setPort( DEFAULT_PORT );
}
else
{
try
{
rcc.setPort( Integer.parseInt( props.getProperty( PORT ) ) );
}
catch ( NumberFormatException ex )
{
throw new ValidationException( "Property " + PORT + " must be a integer" );
}
}
config.setRepositoryCachePath( getMandatoryProperty( props, REPO_LOCAL_STORE ) );
rcc.setSnapshotUpdate( Boolean.valueOf( getMandatoryProperty( props, SNAPSHOT_UPDATE ) ).booleanValue() );
rcc.setMetaDataUpdate(
Boolean.valueOf( getOptionalProperty( props, METADATA_UPDATE, "true" ) ).booleanValue() );
rcc.setPOMUpdate( Boolean.valueOf( getOptionalProperty( props, POM_UPDATE, "false" ) ).booleanValue() );
rcc.setBrowsable( Boolean.valueOf( getMandatoryProperty( props, BROWSABLE ) ).booleanValue() );
rcc.setSearchable( Boolean.valueOf( getOptionalProperty( props, SEARCHABLE, "true" ) ).booleanValue() );
rcc.setServerName( props.getProperty( SERVERNAME ) );
rcc.setPrefix( getMandatoryProperty( props, PREFIX ) );
rcc.setLastModifiedDateFormat( props.getProperty( LAST_MODIFIED_DATE_FORMAT ) );
rcc.setStylesheet( getOptionalProperty( props, STYLESHEET, null ) );
rcc.setBgColor( getOptionalProperty( props, BGCOLOR, "#14B" ) );
rcc.setBgColorHighlight( getOptionalProperty( props, BGCOLORHIGHLIGHT, "#9BF" ) );
rcc.setRowColor( getOptionalProperty( props, ROWCOLOR, "#CCF" ) );
rcc.setRowColorHighlight( getOptionalProperty( props, ROWCOLORHIGHLIGHT, "#DDF" ) );
if ( rcc.getPrefix().length() == 0 )
{
//System.err.println( "Using an empty 'prefix' is deprecated behaviour. Please set a prefix." );
}
{
String propertyList = props.getProperty( "proxy.list" );
{//just get the first proxy and break
String propertyList = props.getProperty( PROXY_LIST );
if ( propertyList != null )
{
StringTokenizer tok = new StringTokenizer( propertyList, "," );
while ( tok.hasMoreTokens() )
{
String key = tok.nextToken();
String host = getMandatoryProperty( props, "proxy." + key + ".host" );
int port = Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) );
// the username and password isn't required
String username = props.getProperty( "proxy." + key + ".username" );
String password = props.getProperty( "proxy." + key + ".password" );
MavenProxyConfiguration pc = new MavenProxyConfiguration( key, host, port, username, password );
rcc.addProxy( pc );
if ( StringUtils.isNotEmpty( key ) )
{
String host = getMandatoryProperty( props, "proxy." + key + ".host" );
int port = Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) );
// the username and password isn't required
String username = props.getProperty( "proxy." + key + ".username" );
String password = props.getProperty( "proxy." + key + ".password" );
if ( StringUtils.isNotEmpty( username ) )
{
config.setHttpProxy( host, port, username, password );
}
else
{
config.setHttpProxy( host, port );
}
//accept only one proxy configuration
break;
}
}
}
}
{
String repoList = getMandatoryProperty( props, "repo.list" );
List repositories = new ArrayList();
{ //get the remote repository list
String repoList = getMandatoryProperty( props, REPO_LIST );
StringTokenizer tok = new StringTokenizer( repoList, "," );
while ( tok.hasMoreTokens() )
@ -145,97 +94,39 @@ public class MavenProxyPropertyLoader
Properties repoProps = getSubset( props, "repo." + key + "." );
String url = getMandatoryProperty( props, "repo." + key + ".url" );
// the username, password and proxy are not mandatory
String username = repoProps.getProperty( "username" );
String password = repoProps.getProperty( "password" );
String description = repoProps.getProperty( "description" );
String proxyKey = repoProps.getProperty( "proxy" );
Boolean cacheFailures = Boolean.valueOf( repoProps.getProperty( "cache.failures", "false" ) );
Long cachePeriod = Long.valueOf( repoProps.getProperty( "cache.period", "0" ) );
Boolean hardFail = Boolean.valueOf( repoProps.getProperty( "hardfail", "true" ) );
boolean cacheFailures = Boolean.valueOf( repoProps.getProperty( "cache.failures", "false" ) ).booleanValue();
boolean hardFail = Boolean.valueOf( repoProps.getProperty( "hardfail", "true" ) ).booleanValue();
long cachePeriod = Long.parseLong( repoProps.getProperty( "cache.period", "0" ) );
MavenProxyConfiguration proxy = null;
if ( proxyKey != null )
ProxyRepository repository =
new ProxyRepository( key, url, new DefaultRepositoryLayout(), cacheFailures, cachePeriod );
repository.setHardfail( hardFail );
if ( StringUtils.isNotEmpty( proxyKey ) )
{
proxy = rcc.getProxy( proxyKey );
repository.setProxied( true );
}
if ( description == null || description.trim().length() == 0 )
{
description = key;
}
RepoConfiguration rc = null;
if ( url.startsWith( "http://" ) )
{
rc = new HttpRepoConfiguration( key, url, description, username, password, hardFail.booleanValue(),
proxy, cacheFailures.booleanValue(), cachePeriod.longValue() );
}
if ( url.startsWith( "file:///" ) )
{
boolean copy = "true".equalsIgnoreCase( repoProps.getProperty( "copy" ) );
rc = new FileRepoConfiguration( key, url, description, copy, hardFail.booleanValue(), cacheFailures
.booleanValue(), cachePeriod.longValue() );
}
if ( rc == null )
{
throw new ValidationException( "Unknown upstream repository type: " + url );
}
rcc.addRepo( rc );
repositories.add( repository );
}
}
validateDirectories( rcc );
validateLocalRepo( rcc );
validateRemoteRepo( rcc );
return rcc;
config.setRepositories( repositories );
validateDirectories( config );
validateRemoteRepo( config );
return config;
}
/**
* Checks to make sure a specific value is set
*
* @throws ValidationException if value is null
*/
private String checkSet( String value, String propertyName )
throws ValidationException
{
if ( value == null )
{
throw new ValidationException( "Missing property '" + propertyName + "'" );
}
return value;
}
private void validateLocalRepo( RetrievalComponentConfiguration rcc )
throws ValidationException
{
//Verify local repository set
String tmp = checkSet( rcc.getLocalStore(), MavenProxyPropertyLoader.REPO_LOCAL_STORE );
File file = new File( tmp );
if ( !file.exists() )
{
throw new ValidationException( "The local repository doesn't exist: " + file.getAbsolutePath() );
}
if ( !file.isDirectory() )
{
throw new ValidationException( "The local repository must be a directory: " + file.getAbsolutePath() );
}
}
private void validateRemoteRepo( RetrievalComponentConfiguration rcc )
private void validateRemoteRepo( ProxyConfiguration configuration )
throws ValidationException
{
//Verify remote repository set
//only warn if missing
if ( rcc.getRepos().size() < 1 )
if ( configuration.getRepositories().size() < 1 )
{
throw new ValidationException( "At least one remote repository must be configured." );
}
@ -258,7 +149,7 @@ public class MavenProxyPropertyLoader
return result;
}
public RetrievalComponentConfiguration load( InputStream is )
public ProxyConfiguration load( InputStream is )
throws IOException, ValidationException
{
Properties props = new Properties();
@ -279,35 +170,21 @@ public class MavenProxyPropertyLoader
return value;
}
private String getOptionalProperty( Properties props, String key, String defaultValue )
{
final String value = props.getProperty( key );
if ( value == null )
{
return defaultValue;
}
return value;
}
private void validateDirectories( RetrievalComponentConfiguration rcc )
private void validateDirectories( ProxyConfiguration configuration )
throws ValidationException
{
File f = new File( rcc.getLocalStore() );
File f = new File( configuration.getRepositoryCachePath() );
if ( !f.exists() )
{
throw new ValidationException( "Specified directory does not exist: " + f.getAbsolutePath() );
}
List repos = rcc.getRepos();
for ( Iterator iter = repos.iterator(); iter.hasNext(); )
for ( Iterator repos = configuration.getRepositories().iterator(); repos.hasNext(); )
{
RepoConfiguration repo = (RepoConfiguration) iter.next();
if ( repo instanceof FileRepoConfiguration )
ProxyRepository repo = (ProxyRepository) repos.next();
if ( repo.getUrl().startsWith( "file://" ) )
{
FileRepoConfiguration fileRepo = (FileRepoConfiguration) repo;
File f2 = new File( fileRepo.getBasePath() );
File f2 = new File( repo.getBasedir() );
if ( !f2.exists() )
{
throw new ValidationException( "Specified directory does not exist: " + f2.getAbsolutePath() );

View File

@ -1,30 +0,0 @@
package org.apache.maven.repository.proxy.configuration;
/*
* 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.
*/
/**
* @author Edwin Punzalan
*/
public class MavenProxyRepoConfiguration
extends RepoConfiguration
{
public MavenProxyRepoConfiguration( String key, String url, String description, boolean copy, boolean hardFail,
boolean cacheFailures, long cachePeriod )
{
super( key, url, description, copy, hardFail, cacheFailures, cachePeriod );
}
}

View File

@ -1,110 +0,0 @@
package org.apache.maven.repository.proxy.configuration;
/*
* Copyright 2003-2004 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.codehaus.plexus.logging.AbstractLogEnabled;
/**
* Immutable.
* <p/>
* hardfail - if a repository is set to hard fail, then the download engine will terminate the whole download
* process (with a status 500) if any of the repositories have unexpected errors.
* <p/>
* if a repository expects an error - eg. 400 (not found) - then it is not required to terminate the
* download process.
*
* @author Ben Walding
*/
public abstract class RepoConfiguration
extends AbstractLogEnabled
{
private final String key;
private final String description;
private final String url;
private final boolean copy;
private final boolean hardFail;
private final boolean cacheFailures;
private final long cachePeriod;
public RepoConfiguration( String key, String url, String description, boolean copy, boolean hardFail,
boolean cacheFailures, long cachePeriod )
{
this.key = key;
this.url = url;
this.description = description;
this.copy = copy;
this.hardFail = hardFail;
this.cacheFailures = cacheFailures;
this.cachePeriod = cachePeriod;
}
/**
*
*/
public String getUrl()
{
return url;
}
/**
*
*/
public String getKey()
{
return key;
}
/**
* If a file repository is set to "copy" mode, it will copy the found files into
* the main repository store.
*/
public boolean getCopy()
{
return copy;
}
public String getDescription()
{
return description;
}
public boolean getHardFail()
{
return hardFail;
}
public boolean getCacheFailures()
{
return cacheFailures;
}
public long getCachePeriod()
{
return cachePeriod;
}
public String toString()
{
return "Repo[" + getKey() + "]";
}
}

View File

@ -1,311 +0,0 @@
package org.apache.maven.repository.proxy.configuration;
/*
* 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 java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
/**
* @author Ben Walding
*/
public class RetrievalComponentConfiguration
{
private final Map proxies = new HashMap();
private final List repos = new ArrayList();
private String localStore;
private String serverName;
private String bgColor;
private String bgColorHighlight;
private String rowColor;
private String rowColorHighlight;
private String stylesheet;
private boolean searchable;
private boolean browsable;
private int port;
private String prefix;
private boolean snapshotUpdate;
private boolean metaDataUpdate;
private boolean pomUpdate;
private String lastModifiedDateFormat;
public String getPrefix()
{
return prefix;
}
public void setPrefix( String prefix )
{
this.prefix = prefix;
}
/**
* @return
*/
public boolean isBrowsable()
{
return browsable;
}
/**
* @param browsable
*/
public void setBrowsable( boolean browsable )
{
this.browsable = browsable;
}
public int getPort()
{
return port;
}
public void setPort( int port )
{
this.port = port;
}
/**
* @return
*/
public String getLocalStore()
{
return localStore;
}
/**
* @param localStore
*/
public void setLocalStore( String localStore )
{
this.localStore = localStore;
}
public void addProxy( MavenProxyConfiguration pc )
{
proxies.put( pc.getKey(), pc );
}
public void removeProxy( String key )
{
proxies.remove( key );
}
public MavenProxyConfiguration getProxy( String key )
{
return (MavenProxyConfiguration) proxies.get( key );
}
/**
* There is no specific order to proxy configuration.
*
* @return
*/
public List getProxies()
{
return new ArrayList( proxies.values() );
}
public void addRepo( RepoConfiguration repo )
{
repos.add( repo );
}
public List getRepos()
{
return Collections.unmodifiableList( repos );
}
public String getServerName()
{
return serverName;
}
public void setServerName( String serverName )
{
this.serverName = serverName;
}
public void setSnapshotUpdate( boolean snapshotUpdate )
{
this.snapshotUpdate = snapshotUpdate;
}
public boolean getSnapshotUpdate()
{
return snapshotUpdate;
}
public void setMetaDataUpdate( boolean metaDataUpdate )
{
this.metaDataUpdate = metaDataUpdate;
}
public boolean getMetaDataUpdate()
{
return metaDataUpdate;
}
public void setPOMUpdate( boolean pomUpdate )
{
this.pomUpdate = pomUpdate;
}
public boolean getPOMUpdate()
{
return pomUpdate;
}
public String getLastModifiedDateFormat()
{
return lastModifiedDateFormat;
}
public void setLastModifiedDateFormat( String lastModifiedDateFormat )
{
this.lastModifiedDateFormat = lastModifiedDateFormat;
}
public boolean isSearchable()
{
return searchable;
}
public void setSearchable( boolean searchable )
{
this.searchable = searchable;
}
/**
* @return the global repo configuration
*/
public GlobalRepoConfiguration getGlobalRepo()
{
for ( Iterator iter = repos.iterator(); iter.hasNext(); )
{
RepoConfiguration repo = (RepoConfiguration) iter.next();
if ( repo instanceof GlobalRepoConfiguration )
{
return (GlobalRepoConfiguration) repo;
}
}
return null;
}
private ThreadLocal dateFormatThreadLocal = new ThreadLocal()
{
protected synchronized Object initialValue()
{
DateFormat df;
if ( getLastModifiedDateFormat() == null || getLastModifiedDateFormat() == "" )
{
df = new SimpleDateFormat();
}
else
{
df = new SimpleDateFormat( getLastModifiedDateFormat() );
}
df.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
return df;
}
};
/**
* Retrieves and casts the appropriate DateFormat object from a ThreadLocal
*
* @return
*/
public DateFormat getLastModifiedDateFormatForThread()
{
return (DateFormat) dateFormatThreadLocal.get();
}
public String getBgColor()
{
return bgColor;
}
public void setBgColor( String bgColor )
{
this.bgColor = bgColor;
}
public String getBgColorHighlight()
{
return bgColorHighlight;
}
public void setBgColorHighlight( String bgColorHighlight )
{
this.bgColorHighlight = bgColorHighlight;
}
public String getStylesheet()
{
return stylesheet;
}
public void setStylesheet( String stylesheet )
{
this.stylesheet = stylesheet;
}
public String getRowColor()
{
return rowColor;
}
public void setRowColor( String rowColor )
{
this.rowColor = rowColor;
}
public String getRowColorHighlight()
{
return rowColorHighlight;
}
public void setRowColorHighlight( String rowColorHighlight )
{
this.rowColorHighlight = rowColorHighlight;
}
}

View File

@ -33,7 +33,7 @@ public class ProxyRepository
private boolean cacheFailures = false;
private boolean hardfail = false;
private boolean hardfail = true;
private boolean proxied = false;

View File

@ -108,7 +108,7 @@ repo.list=local-repo,www-ibiblio-org,dist-codehaus-org,private-example-com
#local-store
# The local store represents a location that local jars you host can be located.
# This could also be achieved by having a local http repository, but this is less cumbersome
repo.local-repo.url=file:///./target/remote-repo1
repo.local-repo.url=file://target
repo.local-repo.description=Super Secret Custom Repository
#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos
repo.local-repo.copy=false

View File

@ -0,0 +1,103 @@
package org.apache.maven.repository.proxy.configuration;
/*
* 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.repository.proxy.repository.ProxyRepository;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
/**
* @author Edwin Punzalan
*/
public class MavenProxyPropertyLoaderTest
extends PlexusTestCase
{
public void testLoadValidMavenProxyConfiguration()
throws ValidationException, IOException
{
MavenProxyPropertyLoader loader = new MavenProxyPropertyLoader();
//must create the test directory bec configuration is using relative path which varies
FileUtils.mkdir( "target/remote-repo1" );
try
{
File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
ProxyConfiguration config = loader.load( new FileInputStream( confFile ) );
assertTrue( "cache path changed", config.getRepositoryCachePath().endsWith( "target" ) );
assertEquals( "Count repositories", 4, config.getRepositories().size() );
int idx = 0;
for ( Iterator repos = config.getRepositories().iterator(); repos.hasNext(); )
{
idx++;
ProxyRepository repo = (ProxyRepository) repos.next();
//switch is made to check for ordering
switch ( idx )
{
case 1:
assertEquals( "Repository name not as expected", "local-repo", repo.getKey() );
assertEquals( "Repository url does not match its name", "file://target",
repo.getUrl() );
assertEquals( "Repository cache period check failed", 0, repo.getCachePeriod() );
assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
break;
case 2:
assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getKey() );
assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2",
repo.getUrl() );
assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() );
assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
break;
case 3:
assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getKey() );
assertEquals( "Repository url does not match its name", "http://dist.codehaus.org",
repo.getUrl() );
assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() );
assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
break;
case 4:
assertEquals( "Repository name not as expected", "private-example-com", repo.getKey() );
assertEquals( "Repository url does not match its name", "http://private.example.com/internal",
repo.getUrl() );
assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() );
assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
break;
default:
fail( "Unexpected order count" );
}
}
}
//make sure to delete the test directory after tests
finally
{
FileUtils.deleteDirectory( "target/remote-repo1" );
}
}
}

View File

@ -79,7 +79,7 @@ public class ProxyConfigurationTest
assertEquals( "repo2", repo.getId() );
assertEquals( "http://www.ibiblio.org/maven", repo.getUrl() );
assertFalse( repo.isCacheFailures() );
assertFalse( repo.isHardfail() );
assertTrue( repo.isHardfail() );
assertEquals( 3600, repo.getCachePeriod() );
assertEquals( repo2, repo );
assertTrue( repo.isProxied() );
@ -108,72 +108,6 @@ public class ProxyConfigurationTest
assertEquals( repositories, config.getRepositories() );
}
// public void testLoadValidMavenProxyConfiguration()
// throws ValidationException, IOException
// {
// //must create the test directory bec configuration is using relative path which varies
// FileUtils.mkdir( "target/remote-repo1" );
//
// try
// {
// File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
//
// config.loadMavenProxyConfiguration( confFile );
//
// assertTrue( "cache path changed", config.getRepositoryCachePath().endsWith( "target" ) );
//
// assertEquals( "Count repositories", 4, config.getRepositories().size() );
//
// int idx = 0;
// for ( Iterator repos = config.getRepositories().iterator(); repos.hasNext(); )
// {
// idx++;
//
// ProxyRepository repo = (ProxyRepository) repos.next();
//
// //switch is made to check for ordering
// switch ( idx )
// {
// case 1:
// assertEquals( "Repository name not as expected", "local-repo", repo.getKey() );
// assertEquals( "Repository url does not match its name", "file:///./target/remote-repo1",
// repo.getUrl() );
// assertEquals( "Repository cache period check failed", 0, repo.getCachePeriod() );
// assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
// break;
// case 2:
// assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getKey() );
// assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2",
// repo.getUrl() );
// assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() );
// assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
// break;
// case 3:
// assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getKey() );
// assertEquals( "Repository url does not match its name", "http://dist.codehaus.org",
// repo.getUrl() );
// assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() );
// assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
// break;
// case 4:
// assertEquals( "Repository name not as expected", "private-example-com", repo.getKey() );
// assertEquals( "Repository url does not match its name", "http://private.example.com/internal",
// repo.getUrl() );
// assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() );
// assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
// break;
// default:
// fail( "Unexpected order count" );
// }
// }
// }
// //make sure to delete the test directory after tests
// finally
// {
// FileUtils.deleteDirectory( "target/remote-repo1" );
// }
// }
//
protected void tearDown()
throws Exception
{