1 package org.apache.maven.archiva.converter;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.commons.io.FileUtils;
23 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
24 import org.apache.maven.archiva.converter.legacy.LegacyRepositoryConverter;
25 import org.apache.maven.artifact.factory.ArtifactFactory;
26 import org.apache.maven.artifact.repository.ArtifactRepository;
27 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
28 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
29 import org.codehaus.plexus.i18n.I18N;
30 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
33 import java.io.IOException;
34 import java.util.ArrayList;
35 import java.util.List;
38 * Test the repository converter.
40 * @todo what about deletions from the source repository?
41 * @todo use artifact-test instead
42 * @todo should reject if dependencies are missing - rely on reporting?
43 * @todo group metadata
45 public class RepositoryConverterTest
46 extends PlexusInSpringTestCase
48 private ArtifactRepository sourceRepository;
50 private ManagedRepositoryConfiguration targetRepository;
52 private LegacyRepositoryConverter repositoryConverter;
54 private ArtifactFactory artifactFactory;
56 private static final int SLEEP_MILLIS = 100;
60 protected void setUp()
65 ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
67 ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
69 File sourceBase = getTestFile( "src/test/source-repository" );
70 sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null,
73 layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
75 File targetBase = getTestFile( "target/test-target-repository" );
76 copyDirectoryStructure( getTestFile( "src/test/target-repository" ), targetBase );
78 targetRepository = new ManagedRepositoryConfiguration();
79 targetRepository.setId( "target" );
80 targetRepository.setName( "Target Repo" );
81 targetRepository.setLocation( targetBase.getAbsolutePath() );
82 targetRepository.setLayout( "default" );
84 repositoryConverter = (LegacyRepositoryConverter) lookup( LegacyRepositoryConverter.ROLE, "default" );
86 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
88 i18n = (I18N) lookup( I18N.ROLE );
91 protected void tearDown()
97 private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
100 if ( !sourceDirectory.exists() )
102 throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." );
105 File[] files = sourceDirectory.listFiles();
107 String sourcePath = sourceDirectory.getAbsolutePath();
109 for ( int i = 0; i < files.length; i++ )
111 File file = files[i];
113 String dest = file.getAbsolutePath();
115 dest = dest.substring( sourcePath.length() + 1 );
117 File destination = new File( destinationDirectory, dest );
121 destination = destination.getParentFile();
123 FileUtils.copyFileToDirectory( file, destination );
125 else if ( file.isDirectory() )
127 if ( !".svn".equals( file.getName() ) )
129 if ( !destination.exists() && !destination.mkdirs() )
131 throw new IOException( "Could not create destination directory '"
132 + destination.getAbsolutePath() + "'." );
134 copyDirectoryStructure( file, destination );
139 throw new IOException( "Unknown file type: " + file.getAbsolutePath() );
144 public void testLegacyConversion()
145 throws IOException, RepositoryConversionException
147 File legacyRepoDir = new File( sourceRepository.getBasedir() );
148 File destRepoDir = new File( targetRepository.getLocation() );
149 List excludes = new ArrayList();
150 repositoryConverter.convertLegacyRepository( legacyRepoDir, destRepoDir, excludes );