1 package org.apache.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 junit.framework.TestCase;
23 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
24 import org.apache.archiva.converter.legacy.LegacyRepositoryConverter;
25 import org.apache.commons.io.FileUtils;
26 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
27 import org.apache.maven.artifact.repository.ArtifactRepository;
28 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
29 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.springframework.test.context.ContextConfiguration;
35 import javax.inject.Inject;
36 import javax.inject.Named;
38 import java.io.IOException;
39 import java.util.ArrayList;
40 import java.util.List;
41 import org.apache.archiva.test.ArchivaSpringJUnit4ClassRunner;
44 * Test the repository converter.
46 * @todo what about deletions from the source repository?
47 * @todo use artifact-test instead
48 * @todo should reject if dependencies are missing - rely on reporting?
49 * @todo group metadata
51 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
52 @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
53 public class RepositoryConverterTest
56 private ArtifactRepository sourceRepository;
58 private ManagedRepositoryConfiguration targetRepository;
61 @Named(value = "legacyRepositoryConverter#default")
62 private LegacyRepositoryConverter repositoryConverter;
65 PlexusSisuBridge plexusSisuBridge;
73 ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
74 //(ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
76 ArtifactRepositoryLayout layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "legacy" );
77 //(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
79 File sourceBase = new File( "src/test/source-repository" );
80 sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null,
83 layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
84 //(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
86 File targetBase = new File( "target/test-target-repository" );
87 copyDirectoryStructure( new File( "src/test/target-repository" ), targetBase );
89 targetRepository = new ManagedRepositoryConfiguration();
90 targetRepository.setId( "target" );
91 targetRepository.setName( "Target Repo" );
92 targetRepository.setLocation( targetBase.getAbsolutePath() );
93 targetRepository.setLayout( "default" );
95 //repositoryConverter = (LegacyRepositoryConverter) lookup( LegacyRepositoryConverter.ROLE, "default" );
98 protected void tearDown()
104 private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
107 if ( !sourceDirectory.exists() )
109 throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." );
112 File[] files = sourceDirectory.listFiles();
114 String sourcePath = sourceDirectory.getAbsolutePath();
116 for ( int i = 0; i < files.length; i++ )
118 File file = files[i];
120 String dest = file.getAbsolutePath();
122 dest = dest.substring( sourcePath.length() + 1 );
124 File destination = new File( destinationDirectory, dest );
128 destination = destination.getParentFile();
130 FileUtils.copyFileToDirectory( file, destination );
132 else if ( file.isDirectory() )
134 if ( !".svn".equals( file.getName() ) )
136 if ( !destination.exists() && !destination.mkdirs() )
138 throw new IOException( "Could not create destination directory '"
139 + destination.getAbsolutePath() + "'." );
141 copyDirectoryStructure( file, destination );
146 throw new IOException( "Unknown file type: " + file.getAbsolutePath() );
152 public void testLegacyConversion()
153 throws IOException, RepositoryConversionException
155 File legacyRepoDir = new File( sourceRepository.getBasedir() );
156 File destRepoDir = new File( targetRepository.getLocation() );
157 List<String> excludes = new ArrayList<String>();
158 repositoryConverter.convertLegacyRepository( legacyRepoDir, destRepoDir, excludes );