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 junit.framework.TestCase;
23 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
24 import org.apache.archiva.converter.RepositoryConversionException;
25 import org.apache.archiva.converter.legacy.LegacyRepositoryConverter;
26 import org.apache.commons.io.FileUtils;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.apache.maven.artifact.repository.ArtifactRepository;
29 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
30 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
37 import javax.inject.Inject;
38 import javax.inject.Named;
40 import java.io.IOException;
41 import java.util.ArrayList;
42 import java.util.List;
45 * Test the repository converter.
47 * @todo what about deletions from the source repository?
48 * @todo use artifact-test instead
49 * @todo should reject if dependencies are missing - rely on reporting?
50 * @todo group metadata
52 @RunWith( SpringJUnit4ClassRunner.class )
53 @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
54 public class RepositoryConverterTest
57 private ArtifactRepository sourceRepository;
59 private ManagedRepositoryConfiguration targetRepository;
62 @Named(value = "legacyRepositoryConverter#default")
63 private LegacyRepositoryConverter repositoryConverter;
66 PlexusSisuBridge plexusSisuBridge;
74 ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
75 //(ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
77 ArtifactRepositoryLayout layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "legacy" );
78 //(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
80 File sourceBase = new File( "src/test/source-repository" );
81 sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null,
84 layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
85 //(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
87 File targetBase = new File( "target/test-target-repository" );
88 copyDirectoryStructure( new File( "src/test/target-repository" ), targetBase );
90 targetRepository = new ManagedRepositoryConfiguration();
91 targetRepository.setId( "target" );
92 targetRepository.setName( "Target Repo" );
93 targetRepository.setLocation( targetBase.getAbsolutePath() );
94 targetRepository.setLayout( "default" );
96 //repositoryConverter = (LegacyRepositoryConverter) lookup( LegacyRepositoryConverter.ROLE, "default" );
99 protected void tearDown()
105 private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
108 if ( !sourceDirectory.exists() )
110 throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." );
113 File[] files = sourceDirectory.listFiles();
115 String sourcePath = sourceDirectory.getAbsolutePath();
117 for ( int i = 0; i < files.length; i++ )
119 File file = files[i];
121 String dest = file.getAbsolutePath();
123 dest = dest.substring( sourcePath.length() + 1 );
125 File destination = new File( destinationDirectory, dest );
129 destination = destination.getParentFile();
131 FileUtils.copyFileToDirectory( file, destination );
133 else if ( file.isDirectory() )
135 if ( !".svn".equals( file.getName() ) )
137 if ( !destination.exists() && !destination.mkdirs() )
139 throw new IOException( "Could not create destination directory '"
140 + destination.getAbsolutePath() + "'." );
142 copyDirectoryStructure( file, destination );
147 throw new IOException( "Unknown file type: " + file.getAbsolutePath() );
153 public void testLegacyConversion()
154 throws IOException, RepositoryConversionException
156 File legacyRepoDir = new File( sourceRepository.getBasedir() );
157 File destRepoDir = new File( targetRepository.getLocation() );
158 List<String> excludes = new ArrayList<String>();
159 repositoryConverter.convertLegacyRepository( legacyRepoDir, destRepoDir, excludes );