From 31bc77d5039d53a386edb10f6b3fc4bf4d18b20f Mon Sep 17 00:00:00 2001 From: Emmanuel Venisse Date: Mon, 26 Feb 2007 16:07:53 +0000 Subject: [PATCH] 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 --- .../DefaultLegacyRepositoryConverter.java | 31 +++++++++++----- .../DefaultConfiguredRepositoryFactory.java | 35 ++++++++++--------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java index 469cc33e3..abf303bcb 100644 --- a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java +++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java @@ -19,6 +19,7 @@ package org.apache.maven.archiva.converter.legacy; * under the License. */ +import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.converter.ConversionListener; import org.apache.maven.archiva.converter.RepositoryConversionException; import org.apache.maven.archiva.discoverer.Discoverer; @@ -76,11 +77,25 @@ public class DefaultLegacyRepositoryConverter try { - legacyRepository = artifactRepositoryFactory.createArtifactRepository( "legacy", legacyRepositoryDirectory - .toURI().toURL().toString(), legacyLayout, null, null ); + String legacyRepositoryDir = legacyRepositoryDirectory.toURI().toURL().toString(); + String repositoryDir = repositoryDirectory.toURI().toURL().toString(); - repository = artifactRepositoryFactory.createArtifactRepository( "default", repositoryDirectory.toURI() - .toURL().toString(), defaultLayout, null, null ); + //workaround for spaces non converted by PathUtils in wagon + //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 ) { @@ -97,14 +112,14 @@ public class DefaultLegacyRepositoryConverter } catch ( DiscovererException e ) { - throw new RepositoryConversionException( "Unable to convert repository due to discoverer error:" - + e.getMessage(), e ); + throw new RepositoryConversionException( + "Unable to convert repository due to discoverer error:" + e.getMessage(), e ); } } /** * Add a listener to the conversion process. - * + * * @param listener the listener to add. */ public void addConversionListener( ConversionListener listener ) @@ -114,7 +129,7 @@ public class DefaultLegacyRepositoryConverter /** * Remove a listener from the conversion process. - * + * * @param listener the listener to remove. */ public void removeConversionListener( ConversionListener listener ) diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/configuration/DefaultConfiguredRepositoryFactory.java b/archiva-core/src/main/java/org/apache/maven/archiva/configuration/DefaultConfiguredRepositoryFactory.java index 575124396..4c7e05e5a 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/configuration/DefaultConfiguredRepositoryFactory.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/configuration/DefaultConfiguredRepositoryFactory.java @@ -53,18 +53,7 @@ public class DefaultConfiguredRepositoryFactory public ArtifactRepository createRepository( RepositoryConfiguration configuration ) { - File repositoryDirectory = new File( 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 ); + return createRepository( configuration.getLayout(), configuration.getId(), configuration.getDirectory()); } public ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration ) @@ -126,10 +115,24 @@ public class DefaultConfiguredRepositoryFactory public ArtifactRepository createLocalRepository( Configuration configuration ) { - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( "default" ); - File localRepository = new File( configuration.getLocalRepository() ); - localRepository.mkdirs(); - return repoFactory.createArtifactRepository( "local", localRepository.toURI().toString(), layout, null, null ); + return createRepository( "default", "local", configuration.getLocalRepository() ); + } + + 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 )