Ver código fonte

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
tags/archiva-1.4-M1
Olivier Lamy 13 anos atrás
pai
commit
df2b9275e9

+ 32
- 20
archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java Ver arquivo

@@ -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.RepositoryMetadataReader;
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.FileInputStream;
import java.io.FileOutputStream;
@@ -50,23 +53,33 @@ import java.util.List;
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
implements RepositoryMerger
{
/**
* @plexus.requirement role-hint="default"
* plexus.requirement role-hint="default"
*/
private ArchivaConfiguration configuration;

/**
* @plexus.requirement role-hint="maven2"
* plexus.requirement role-hint="maven2"
*/
private RepositoryPathTranslator pathTranslator;

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 )
{
this.configuration = configuration;
@@ -159,10 +172,10 @@ public class Maven2RepositoryMerger

String index = artifactPath.substring( lastIndex + 1 );
int last = index.lastIndexOf( '.' );
File sourcePomFile = new File( sourceRepoPath, artifactPath.substring( 0, lastIndex ) + "/" +
artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" );
File targetPomFile = new File( targetRepoPath, artifactPath.substring( 0, lastIndex ) + "/" +
artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" );
File sourcePomFile = new File( sourceRepoPath, artifactPath.substring( 0, lastIndex ) + "/"
+ artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" );
File targetPomFile = new File( targetRepoPath, artifactPath.substring( 0, lastIndex ) + "/"
+ artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" );

if ( !targetPomFile.exists() && sourcePomFile.exists() )
{
@@ -174,16 +187,15 @@ public class Maven2RepositoryMerger
{

// updating version metadata files
File versionMetaDataFileInSourceRepo = pathTranslator.toFile( new File( sourceRepoPath ),
artifactMetadata.getNamespace(),
artifactMetadata.getProject(),
artifactMetadata.getVersion(),
METADATA_FILENAME );
File versionMetaDataFileInSourceRepo =
pathTranslator.toFile( new File( sourceRepoPath ), artifactMetadata.getNamespace(),
artifactMetadata.getProject(), artifactMetadata.getVersion(),
METADATA_FILENAME );

if ( versionMetaDataFileInSourceRepo.exists() )
{
String relativePathToVersionMetadataFile = versionMetaDataFileInSourceRepo.getAbsolutePath().split(
sourceRepoPath )[1];
String relativePathToVersionMetadataFile =
versionMetaDataFileInSourceRepo.getAbsolutePath().split( sourceRepoPath )[1];
File versionMetaDataFileInTargetRepo = new File( targetRepoPath, relativePathToVersionMetadataFile );

if ( !versionMetaDataFileInTargetRepo.exists() )
@@ -203,8 +215,8 @@ public class Maven2RepositoryMerger

if ( projectMetadataFileInSourceRepo.exists() )
{
String relativePathToProjectMetadataFile = projectMetadataFileInSourceRepo.getAbsolutePath().split(
sourceRepoPath )[1];
String relativePathToProjectMetadataFile =
projectMetadataFileInSourceRepo.getAbsolutePath().split( sourceRepoPath )[1];
File projectMetadataFileInTargetRepo = new File( targetRepoPath, relativePathToProjectMetadataFile );

if ( !projectMetadataFileInTargetRepo.exists() )
@@ -352,10 +364,10 @@ public class Maven2RepositoryMerger
{
boolean isSame = false;

if ( ( sourceArtifact.getNamespace().equals( targetArtifact.getNamespace() ) ) &&
( sourceArtifact.getProject().equals( targetArtifact.getProject() ) ) && ( sourceArtifact.getId().equals(
targetArtifact.getId() ) ) && ( sourceArtifact.getProjectVersion().equals(
targetArtifact.getProjectVersion() ) ) )
if ( ( sourceArtifact.getNamespace().equals( targetArtifact.getNamespace() ) )
&& ( sourceArtifact.getProject().equals( targetArtifact.getProject() ) )
&& ( sourceArtifact.getId().equals( targetArtifact.getId() ) )
&& ( sourceArtifact.getProjectVersion().equals( targetArtifact.getProjectVersion() ) ) )

{
isSame = true;

+ 2
- 2
archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/RepositoryMerger.java Ver arquivo

@@ -34,7 +34,7 @@ public interface RepositoryMerger
Filter<ArtifactMetadata> filter )
throws Exception;

public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
String targetRepo )
List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
String targetRepo )
throws Exception;
}

+ 33
- 0
archiva-modules/plugins/stage-repository-merge/src/main/resources/META-INF/spring-context.xml Ver arquivo

@@ -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>

+ 2
- 0
archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java Ver arquivo

@@ -25,7 +25,9 @@ import org.apache.maven.archiva.configuration.ConfigurationListener;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
import org.springframework.stereotype.Service;

@Service("archivaConfiguration#mocked")
public class StubConfiguration
implements ArchivaConfiguration
{

+ 20
- 11
archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMergerTest.java Ver arquivo

@@ -19,30 +19,41 @@ package org.apache.archiva.stagerepository.merge;
* under the License.
*/

import junit.framework.TestCase;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
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.util.ArrayList;
import java.util.List;

import static org.mockito.Mockito.*;

@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
public class Maven2RepositoryMergerTest
extends PlexusInSpringTestCase
extends TestCase
{

private static final String TEST_REPO_ID = "test";

@Inject
private Maven2RepositoryMerger repositoryMerger;

@Inject
ArchivaConfiguration configuration;

private MetadataRepository metadataRepository;

@Before
@@ -52,7 +63,6 @@ public class Maven2RepositoryMergerTest
super.setUp();
MockitoAnnotations.initMocks( this );
metadataRepository = mock( MetadataRepository.class );
repositoryMerger = (Maven2RepositoryMerger) lookup( RepositoryMerger.class, "maven2" );
}

private List<ArtifactMetadata> getArtifacts()
@@ -69,14 +79,14 @@ public class Maven2RepositoryMergerTest
return metadata;
}

@Test
public void testMerge()
throws Exception
{
ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
Configuration c = new Configuration();
ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
testRepo.setId( TEST_REPO_ID );
testRepo.setLocation( getTestPath( "target/test-repository" ) );
testRepo.setLocation( "target/test-repository" );

RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
List<String> knownContentConsumers = new ArrayList<String>();
@@ -86,7 +96,7 @@ public class Maven2RepositoryMergerTest

ManagedRepositoryConfiguration targetRepo = new ManagedRepositoryConfiguration();
targetRepo.setId( "target-rep" );
targetRepo.setLocation( getTestPath( "target" ) );
targetRepo.setLocation( "target" );
c.addManagedRepository( testRepo );
c.addManagedRepository( targetRepo );
configuration.save( c );
@@ -112,16 +122,15 @@ public class Maven2RepositoryMergerTest
sourceRepoArtifactsList.add( artifact1 );
List<ArtifactMetadata> targetRepoArtifactsList = getArtifacts();

ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
Configuration c = new Configuration();
ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
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";
ManagedRepositoryConfiguration testRepoWithConflicts = new ManagedRepositoryConfiguration();
testRepoWithConflicts.setId( sourceRepoId );
testRepoWithConflicts.setLocation( getTestPath( sourceRepo ) );
testRepoWithConflicts.setLocation( sourceRepo );

RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
List<String> knownContentConsumers = new ArrayList<String>();
@@ -133,8 +142,8 @@ public class Maven2RepositoryMergerTest
c.addManagedRepository( testRepoWithConflicts );
configuration.save( c );

File targetRepoFile = new File( getTestPath(
"/target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar" ) );
File targetRepoFile = new File(
"/target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar" );
targetRepoFile.setReadOnly();

when( metadataRepository.getArtifacts( sourceRepoId ) ).thenReturn( sourceRepoArtifactsList );

+ 35
- 0
archiva-modules/plugins/stage-repository-merge/src/test/resources/spring-context.xml Ver arquivo

@@ -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>

Carregando…
Cancelar
Salvar