Remove %20 in directories name when they contain spaces

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@511870 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Emmanuel Venisse 2007-02-26 16:07:53 +00:00
parent 401840ce73
commit 31bc77d503
2 changed files with 42 additions and 24 deletions

View File

@ -19,6 +19,7 @@ package org.apache.maven.archiva.converter.legacy;
* under the License. * under the License.
*/ */
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.converter.ConversionListener; import org.apache.maven.archiva.converter.ConversionListener;
import org.apache.maven.archiva.converter.RepositoryConversionException; import org.apache.maven.archiva.converter.RepositoryConversionException;
import org.apache.maven.archiva.discoverer.Discoverer; import org.apache.maven.archiva.discoverer.Discoverer;
@ -76,11 +77,25 @@ public class DefaultLegacyRepositoryConverter
try try
{ {
legacyRepository = artifactRepositoryFactory.createArtifactRepository( "legacy", legacyRepositoryDirectory String legacyRepositoryDir = legacyRepositoryDirectory.toURI().toURL().toString();
.toURI().toURL().toString(), legacyLayout, null, null ); String repositoryDir = repositoryDirectory.toURI().toURL().toString();
repository = artifactRepositoryFactory.createArtifactRepository( "default", repositoryDirectory.toURI() //workaround for spaces non converted by PathUtils in wagon
.toURL().toString(), defaultLayout, null, null ); //TODO: remove it when PathUtils will be fixed
if ( legacyRepositoryDir.indexOf( "%20" ) >= 0 )
{
legacyRepositoryDir = StringUtils.replace( legacyRepositoryDir, "%20", " " );
}
if ( repositoryDir.indexOf( "%20" ) >= 0 )
{
repositoryDir = StringUtils.replace( repositoryDir, "%20", " " );
}
legacyRepository = artifactRepositoryFactory.createArtifactRepository( "legacy", legacyRepositoryDir,
legacyLayout, null, null );
repository = artifactRepositoryFactory.createArtifactRepository( "default", repositoryDir, defaultLayout,
null, null );
} }
catch ( MalformedURLException e ) catch ( MalformedURLException e )
{ {
@ -97,14 +112,14 @@ public class DefaultLegacyRepositoryConverter
} }
catch ( DiscovererException e ) catch ( DiscovererException e )
{ {
throw new RepositoryConversionException( "Unable to convert repository due to discoverer error:" throw new RepositoryConversionException(
+ e.getMessage(), e ); "Unable to convert repository due to discoverer error:" + e.getMessage(), e );
} }
} }
/** /**
* Add a listener to the conversion process. * Add a listener to the conversion process.
* *
* @param listener the listener to add. * @param listener the listener to add.
*/ */
public void addConversionListener( ConversionListener listener ) public void addConversionListener( ConversionListener listener )
@ -114,7 +129,7 @@ public class DefaultLegacyRepositoryConverter
/** /**
* Remove a listener from the conversion process. * Remove a listener from the conversion process.
* *
* @param listener the listener to remove. * @param listener the listener to remove.
*/ */
public void removeConversionListener( ConversionListener listener ) public void removeConversionListener( ConversionListener listener )

View File

@ -53,18 +53,7 @@ public class DefaultConfiguredRepositoryFactory
public ArtifactRepository createRepository( RepositoryConfiguration configuration ) public ArtifactRepository createRepository( RepositoryConfiguration configuration )
{ {
File repositoryDirectory = new File( configuration.getDirectory() ); return createRepository( configuration.getLayout(), configuration.getId(), configuration.getDirectory());
String repoDir = repositoryDirectory.toURI().toString();
//workaround for spaces non converted by PathUtils in wagon
//todo: remove it when PathUtils will be fixed
if ( repoDir.indexOf( "%20" ) >= 0 )
{
repoDir = StringUtils.replace( repoDir, "%20", " " );
}
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() );
return repoFactory.createArtifactRepository( configuration.getId(), repoDir, layout, null, null );
} }
public ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration ) public ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration )
@ -126,10 +115,24 @@ public class DefaultConfiguredRepositoryFactory
public ArtifactRepository createLocalRepository( Configuration configuration ) public ArtifactRepository createLocalRepository( Configuration configuration )
{ {
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( "default" ); return createRepository( "default", "local", configuration.getLocalRepository() );
File localRepository = new File( configuration.getLocalRepository() ); }
localRepository.mkdirs();
return repoFactory.createArtifactRepository( "local", localRepository.toURI().toString(), layout, null, null ); public ArtifactRepository createRepository( String layout, String id, String directory )
{
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) repositoryLayouts.get( layout );
File repository = new File( directory );
repository.mkdirs();
String repoDir = repository.toURI().toString();
//workaround for spaces non converted by PathUtils in wagon
//TODO: remove it when PathUtils will be fixed
if ( repoDir.indexOf( "%20" ) >= 0 )
{
repoDir = StringUtils.replace( repoDir, "%20", " " );
}
return repoFactory.createArtifactRepository( id, repoDir, repositoryLayout, null, null );
} }
private static String getUpdatePolicy( String policy, int interval ) private static String getUpdatePolicy( String policy, int interval )