mirror of https://github.com/apache/archiva.git
remove plexus-spring : fixed for stage-repository-merge
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1130300 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
207e0997b4
commit
df2b9275e9
|
@ -35,7 +35,10 @@ import org.apache.maven.archiva.repository.RepositoryException;
|
||||||
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
|
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
|
||||||
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
|
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
|
||||||
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
|
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -50,23 +53,33 @@ import java.util.List;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @plexus.component role="org.apache.archiva.stagerepository.merge.RepositoryMerger" role-hint="maven2"
|
* plexus.component role="org.apache.archiva.stagerepository.merge.RepositoryMerger" role-hint="maven2"
|
||||||
*/
|
*/
|
||||||
|
@Service( "repositoryMerger#maven2" )
|
||||||
public class Maven2RepositoryMerger
|
public class Maven2RepositoryMerger
|
||||||
implements RepositoryMerger
|
implements RepositoryMerger
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @plexus.requirement role-hint="default"
|
* plexus.requirement role-hint="default"
|
||||||
*/
|
*/
|
||||||
private ArchivaConfiguration configuration;
|
private ArchivaConfiguration configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @plexus.requirement role-hint="maven2"
|
* plexus.requirement role-hint="maven2"
|
||||||
*/
|
*/
|
||||||
private RepositoryPathTranslator pathTranslator;
|
private RepositoryPathTranslator pathTranslator;
|
||||||
|
|
||||||
private static final String METADATA_FILENAME = "maven-metadata.xml";
|
private static final String METADATA_FILENAME = "maven-metadata.xml";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public Maven2RepositoryMerger(
|
||||||
|
@Named( value = "archivaConfiguration#default" ) ArchivaConfiguration archivaConfiguration,
|
||||||
|
@Named( value = "repositoryPathTranslator#maven2") RepositoryPathTranslator repositoryPathTranslator )
|
||||||
|
{
|
||||||
|
this.configuration = archivaConfiguration;
|
||||||
|
this.pathTranslator = repositoryPathTranslator;
|
||||||
|
}
|
||||||
|
|
||||||
public void setConfiguration( ArchivaConfiguration configuration )
|
public void setConfiguration( ArchivaConfiguration configuration )
|
||||||
{
|
{
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
@ -159,10 +172,10 @@ public class Maven2RepositoryMerger
|
||||||
|
|
||||||
String index = artifactPath.substring( lastIndex + 1 );
|
String index = artifactPath.substring( lastIndex + 1 );
|
||||||
int last = index.lastIndexOf( '.' );
|
int last = index.lastIndexOf( '.' );
|
||||||
File sourcePomFile = new File( sourceRepoPath, artifactPath.substring( 0, lastIndex ) + "/" +
|
File sourcePomFile = new File( sourceRepoPath, artifactPath.substring( 0, lastIndex ) + "/"
|
||||||
artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" );
|
+ artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" );
|
||||||
File targetPomFile = new File( targetRepoPath, artifactPath.substring( 0, lastIndex ) + "/" +
|
File targetPomFile = new File( targetRepoPath, artifactPath.substring( 0, lastIndex ) + "/"
|
||||||
artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" );
|
+ artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" );
|
||||||
|
|
||||||
if ( !targetPomFile.exists() && sourcePomFile.exists() )
|
if ( !targetPomFile.exists() && sourcePomFile.exists() )
|
||||||
{
|
{
|
||||||
|
@ -174,16 +187,15 @@ public class Maven2RepositoryMerger
|
||||||
{
|
{
|
||||||
|
|
||||||
// updating version metadata files
|
// updating version metadata files
|
||||||
File versionMetaDataFileInSourceRepo = pathTranslator.toFile( new File( sourceRepoPath ),
|
File versionMetaDataFileInSourceRepo =
|
||||||
artifactMetadata.getNamespace(),
|
pathTranslator.toFile( new File( sourceRepoPath ), artifactMetadata.getNamespace(),
|
||||||
artifactMetadata.getProject(),
|
artifactMetadata.getProject(), artifactMetadata.getVersion(),
|
||||||
artifactMetadata.getVersion(),
|
|
||||||
METADATA_FILENAME );
|
METADATA_FILENAME );
|
||||||
|
|
||||||
if ( versionMetaDataFileInSourceRepo.exists() )
|
if ( versionMetaDataFileInSourceRepo.exists() )
|
||||||
{
|
{
|
||||||
String relativePathToVersionMetadataFile = versionMetaDataFileInSourceRepo.getAbsolutePath().split(
|
String relativePathToVersionMetadataFile =
|
||||||
sourceRepoPath )[1];
|
versionMetaDataFileInSourceRepo.getAbsolutePath().split( sourceRepoPath )[1];
|
||||||
File versionMetaDataFileInTargetRepo = new File( targetRepoPath, relativePathToVersionMetadataFile );
|
File versionMetaDataFileInTargetRepo = new File( targetRepoPath, relativePathToVersionMetadataFile );
|
||||||
|
|
||||||
if ( !versionMetaDataFileInTargetRepo.exists() )
|
if ( !versionMetaDataFileInTargetRepo.exists() )
|
||||||
|
@ -203,8 +215,8 @@ public class Maven2RepositoryMerger
|
||||||
|
|
||||||
if ( projectMetadataFileInSourceRepo.exists() )
|
if ( projectMetadataFileInSourceRepo.exists() )
|
||||||
{
|
{
|
||||||
String relativePathToProjectMetadataFile = projectMetadataFileInSourceRepo.getAbsolutePath().split(
|
String relativePathToProjectMetadataFile =
|
||||||
sourceRepoPath )[1];
|
projectMetadataFileInSourceRepo.getAbsolutePath().split( sourceRepoPath )[1];
|
||||||
File projectMetadataFileInTargetRepo = new File( targetRepoPath, relativePathToProjectMetadataFile );
|
File projectMetadataFileInTargetRepo = new File( targetRepoPath, relativePathToProjectMetadataFile );
|
||||||
|
|
||||||
if ( !projectMetadataFileInTargetRepo.exists() )
|
if ( !projectMetadataFileInTargetRepo.exists() )
|
||||||
|
@ -352,10 +364,10 @@ public class Maven2RepositoryMerger
|
||||||
{
|
{
|
||||||
boolean isSame = false;
|
boolean isSame = false;
|
||||||
|
|
||||||
if ( ( sourceArtifact.getNamespace().equals( targetArtifact.getNamespace() ) ) &&
|
if ( ( sourceArtifact.getNamespace().equals( targetArtifact.getNamespace() ) )
|
||||||
( sourceArtifact.getProject().equals( targetArtifact.getProject() ) ) && ( sourceArtifact.getId().equals(
|
&& ( sourceArtifact.getProject().equals( targetArtifact.getProject() ) )
|
||||||
targetArtifact.getId() ) ) && ( sourceArtifact.getProjectVersion().equals(
|
&& ( sourceArtifact.getId().equals( targetArtifact.getId() ) )
|
||||||
targetArtifact.getProjectVersion() ) ) )
|
&& ( sourceArtifact.getProjectVersion().equals( targetArtifact.getProjectVersion() ) ) )
|
||||||
|
|
||||||
{
|
{
|
||||||
isSame = true;
|
isSame = true;
|
||||||
|
|
|
@ -34,7 +34,7 @@ public interface RepositoryMerger
|
||||||
Filter<ArtifactMetadata> filter )
|
Filter<ArtifactMetadata> filter )
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
|
List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
|
||||||
String targetRepo )
|
String targetRepo )
|
||||||
throws Exception;
|
throws Exception;
|
||||||
}
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
~ or more contributor license agreements. See the NOTICE file
|
||||||
|
~ distributed with this work for additional information
|
||||||
|
~ regarding copyright ownership. The ASF licenses this file
|
||||||
|
~ to you under the Apache License, Version 2.0 (the
|
||||||
|
~ "License"); you may not use this file except in compliance
|
||||||
|
~ with the License. You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
|
~ software distributed under the License is distributed on an
|
||||||
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
~ KIND, either express or implied. See the License for the
|
||||||
|
~ specific language governing permissions and limitations
|
||||||
|
~ under the License.
|
||||||
|
-->
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||||
|
http://www.springframework.org/schema/context
|
||||||
|
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
|
||||||
|
default-lazy-init="true">
|
||||||
|
|
||||||
|
<context:annotation-config/>
|
||||||
|
<context:component-scan base-package="org.apache.archiva.stagerepository.merge"/>
|
||||||
|
|
||||||
|
</beans>
|
|
@ -25,7 +25,9 @@ import org.apache.maven.archiva.configuration.ConfigurationListener;
|
||||||
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
|
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
|
||||||
import org.codehaus.plexus.registry.RegistryException;
|
import org.codehaus.plexus.registry.RegistryException;
|
||||||
import org.codehaus.plexus.registry.RegistryListener;
|
import org.codehaus.plexus.registry.RegistryListener;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service("archivaConfiguration#mocked")
|
||||||
public class StubConfiguration
|
public class StubConfiguration
|
||||||
implements ArchivaConfiguration
|
implements ArchivaConfiguration
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,30 +19,41 @@ package org.apache.archiva.stagerepository.merge;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.Configuration;
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
|
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
|
||||||
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith( SpringJUnit4ClassRunner.class )
|
||||||
|
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
|
||||||
public class Maven2RepositoryMergerTest
|
public class Maven2RepositoryMergerTest
|
||||||
extends PlexusInSpringTestCase
|
extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final String TEST_REPO_ID = "test";
|
private static final String TEST_REPO_ID = "test";
|
||||||
|
|
||||||
|
@Inject
|
||||||
private Maven2RepositoryMerger repositoryMerger;
|
private Maven2RepositoryMerger repositoryMerger;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ArchivaConfiguration configuration;
|
||||||
|
|
||||||
private MetadataRepository metadataRepository;
|
private MetadataRepository metadataRepository;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -52,7 +63,6 @@ public class Maven2RepositoryMergerTest
|
||||||
super.setUp();
|
super.setUp();
|
||||||
MockitoAnnotations.initMocks( this );
|
MockitoAnnotations.initMocks( this );
|
||||||
metadataRepository = mock( MetadataRepository.class );
|
metadataRepository = mock( MetadataRepository.class );
|
||||||
repositoryMerger = (Maven2RepositoryMerger) lookup( RepositoryMerger.class, "maven2" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ArtifactMetadata> getArtifacts()
|
private List<ArtifactMetadata> getArtifacts()
|
||||||
|
@ -69,14 +79,14 @@ public class Maven2RepositoryMergerTest
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMerge()
|
public void testMerge()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
|
|
||||||
Configuration c = new Configuration();
|
Configuration c = new Configuration();
|
||||||
ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
|
ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
|
||||||
testRepo.setId( TEST_REPO_ID );
|
testRepo.setId( TEST_REPO_ID );
|
||||||
testRepo.setLocation( getTestPath( "target/test-repository" ) );
|
testRepo.setLocation( "target/test-repository" );
|
||||||
|
|
||||||
RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
|
RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
|
||||||
List<String> knownContentConsumers = new ArrayList<String>();
|
List<String> knownContentConsumers = new ArrayList<String>();
|
||||||
|
@ -86,7 +96,7 @@ public class Maven2RepositoryMergerTest
|
||||||
|
|
||||||
ManagedRepositoryConfiguration targetRepo = new ManagedRepositoryConfiguration();
|
ManagedRepositoryConfiguration targetRepo = new ManagedRepositoryConfiguration();
|
||||||
targetRepo.setId( "target-rep" );
|
targetRepo.setId( "target-rep" );
|
||||||
targetRepo.setLocation( getTestPath( "target" ) );
|
targetRepo.setLocation( "target" );
|
||||||
c.addManagedRepository( testRepo );
|
c.addManagedRepository( testRepo );
|
||||||
c.addManagedRepository( targetRepo );
|
c.addManagedRepository( targetRepo );
|
||||||
configuration.save( c );
|
configuration.save( c );
|
||||||
|
@ -112,16 +122,15 @@ public class Maven2RepositoryMergerTest
|
||||||
sourceRepoArtifactsList.add( artifact1 );
|
sourceRepoArtifactsList.add( artifact1 );
|
||||||
List<ArtifactMetadata> targetRepoArtifactsList = getArtifacts();
|
List<ArtifactMetadata> targetRepoArtifactsList = getArtifacts();
|
||||||
|
|
||||||
ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
|
|
||||||
Configuration c = new Configuration();
|
Configuration c = new Configuration();
|
||||||
ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
|
ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
|
||||||
testRepo.setId( TEST_REPO_ID );
|
testRepo.setId( TEST_REPO_ID );
|
||||||
testRepo.setLocation( getTestPath( "target/test-repository" ) );
|
testRepo.setLocation( "target/test-repository" );
|
||||||
|
|
||||||
String sourceRepo = "src/test/resources/test-repository-with-conflict-artifacts";
|
String sourceRepo = "src/test/resources/test-repository-with-conflict-artifacts";
|
||||||
ManagedRepositoryConfiguration testRepoWithConflicts = new ManagedRepositoryConfiguration();
|
ManagedRepositoryConfiguration testRepoWithConflicts = new ManagedRepositoryConfiguration();
|
||||||
testRepoWithConflicts.setId( sourceRepoId );
|
testRepoWithConflicts.setId( sourceRepoId );
|
||||||
testRepoWithConflicts.setLocation( getTestPath( sourceRepo ) );
|
testRepoWithConflicts.setLocation( sourceRepo );
|
||||||
|
|
||||||
RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
|
RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
|
||||||
List<String> knownContentConsumers = new ArrayList<String>();
|
List<String> knownContentConsumers = new ArrayList<String>();
|
||||||
|
@ -133,8 +142,8 @@ public class Maven2RepositoryMergerTest
|
||||||
c.addManagedRepository( testRepoWithConflicts );
|
c.addManagedRepository( testRepoWithConflicts );
|
||||||
configuration.save( c );
|
configuration.save( c );
|
||||||
|
|
||||||
File targetRepoFile = new File( getTestPath(
|
File targetRepoFile = new File(
|
||||||
"/target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar" ) );
|
"/target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar" );
|
||||||
targetRepoFile.setReadOnly();
|
targetRepoFile.setReadOnly();
|
||||||
|
|
||||||
when( metadataRepository.getArtifacts( sourceRepoId ) ).thenReturn( sourceRepoArtifactsList );
|
when( metadataRepository.getArtifacts( sourceRepoId ) ).thenReturn( sourceRepoArtifactsList );
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
~ or more contributor license agreements. See the NOTICE file
|
||||||
|
~ distributed with this work for additional information
|
||||||
|
~ regarding copyright ownership. The ASF licenses this file
|
||||||
|
~ to you under the Apache License, Version 2.0 (the
|
||||||
|
~ "License"); you may not use this file except in compliance
|
||||||
|
~ with the License. You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
|
~ software distributed under the License is distributed on an
|
||||||
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
~ KIND, either express or implied. See the License for the
|
||||||
|
~ specific language governing permissions and limitations
|
||||||
|
~ under the License.
|
||||||
|
-->
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||||
|
http://www.springframework.org/schema/context
|
||||||
|
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
|
||||||
|
default-lazy-init="true">
|
||||||
|
|
||||||
|
<context:annotation-config/>
|
||||||
|
<context:component-scan base-package="org.apache.archiva.configuration"/>
|
||||||
|
<alias name="archivaConfiguration#mocked" alias="archivaConfiguration"/>
|
||||||
|
<alias name="archivaConfiguration#mocked" alias="archivaConfiguration#default" />
|
||||||
|
|
||||||
|
</beans>
|
Loading…
Reference in New Issue