Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

RepositoryConverterTest.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package org.apache.archiva.converter;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import junit.framework.TestCase;
  21. import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
  22. import org.apache.archiva.converter.legacy.LegacyRepositoryConverter;
  23. import org.apache.commons.io.FileUtils;
  24. import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
  25. import org.apache.maven.artifact.repository.ArtifactRepository;
  26. import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
  27. import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
  28. import org.junit.Before;
  29. import org.junit.Test;
  30. import org.junit.runner.RunWith;
  31. import org.springframework.test.context.ContextConfiguration;
  32. import javax.inject.Inject;
  33. import javax.inject.Named;
  34. import java.io.File;
  35. import java.io.IOException;
  36. import java.util.ArrayList;
  37. import java.util.List;
  38. import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
  39. /**
  40. * Test the repository converter.
  41. *
  42. * @todo what about deletions from the source repository?
  43. * @todo use artifact-test instead
  44. * @todo should reject if dependencies are missing - rely on reporting?
  45. * @todo group metadata
  46. */
  47. @RunWith( ArchivaSpringJUnit4ClassRunner.class )
  48. @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
  49. public class RepositoryConverterTest
  50. extends TestCase
  51. {
  52. private ArtifactRepository sourceRepository;
  53. private ManagedRepositoryConfiguration targetRepository;
  54. @Inject
  55. @Named(value = "legacyRepositoryConverter#default")
  56. private LegacyRepositoryConverter repositoryConverter;
  57. @Inject
  58. PlexusSisuBridge plexusSisuBridge;
  59. @Before
  60. public void setUp()
  61. throws Exception
  62. {
  63. super.setUp();
  64. ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
  65. //(ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
  66. ArtifactRepositoryLayout layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "legacy" );
  67. //(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
  68. File sourceBase = new File( "src/test/source-repository" );
  69. sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null,
  70. null );
  71. layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
  72. //(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
  73. File targetBase = new File( "target/test-target-repository" );
  74. copyDirectoryStructure( new File( "src/test/target-repository" ), targetBase );
  75. targetRepository = new ManagedRepositoryConfiguration();
  76. targetRepository.setId( "target" );
  77. targetRepository.setName( "Target Repo" );
  78. targetRepository.setLocation( targetBase.getAbsolutePath() );
  79. targetRepository.setLayout( "default" );
  80. //repositoryConverter = (LegacyRepositoryConverter) lookup( LegacyRepositoryConverter.ROLE, "default" );
  81. }
  82. protected void tearDown()
  83. throws Exception
  84. {
  85. super.tearDown();
  86. }
  87. private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
  88. throws IOException
  89. {
  90. if ( !sourceDirectory.exists() )
  91. {
  92. throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." );
  93. }
  94. File[] files = sourceDirectory.listFiles();
  95. String sourcePath = sourceDirectory.getAbsolutePath();
  96. for ( int i = 0; i < files.length; i++ )
  97. {
  98. File file = files[i];
  99. String dest = file.getAbsolutePath();
  100. dest = dest.substring( sourcePath.length() + 1 );
  101. File destination = new File( destinationDirectory, dest );
  102. if ( file.isFile() )
  103. {
  104. destination = destination.getParentFile();
  105. FileUtils.copyFileToDirectory( file, destination );
  106. }
  107. else if ( file.isDirectory() )
  108. {
  109. if ( !".svn".equals( file.getName() ) )
  110. {
  111. if ( !destination.exists() && !destination.mkdirs() )
  112. {
  113. throw new IOException( "Could not create destination directory '"
  114. + destination.getAbsolutePath() + "'." );
  115. }
  116. copyDirectoryStructure( file, destination );
  117. }
  118. }
  119. else
  120. {
  121. throw new IOException( "Unknown file type: " + file.getAbsolutePath() );
  122. }
  123. }
  124. }
  125. @Test
  126. public void testLegacyConversion()
  127. throws IOException, RepositoryConversionException
  128. {
  129. File legacyRepoDir = new File( sourceRepository.getBasedir() );
  130. File destRepoDir = new File( targetRepository.getLocation() );
  131. List<String> excludes = new ArrayList<>();
  132. repositoryConverter.convertLegacyRepository( legacyRepoDir, destRepoDir, excludes );
  133. }
  134. }