mirror of https://github.com/apache/archiva.git
use a better exception mechanism for that
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1387387 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
65768e8719
commit
5a3bf2a3af
|
@ -27,8 +27,8 @@ import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
import org.apache.archiva.maven2.metadata.MavenMetadataReader;
|
import org.apache.archiva.maven2.metadata.MavenMetadataReader;
|
||||||
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.archiva.metadata.repository.MetadataRepositoryException;
|
||||||
import org.apache.archiva.metadata.repository.filter.Filter;
|
import org.apache.archiva.metadata.repository.filter.Filter;
|
||||||
import org.apache.archiva.metadata.repository.filter.IncludesFilter;
|
|
||||||
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
|
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
|
||||||
import org.apache.archiva.model.ArchivaRepositoryMetadata;
|
import org.apache.archiva.model.ArchivaRepositoryMetadata;
|
||||||
import org.apache.archiva.repository.RepositoryException;
|
import org.apache.archiva.repository.RepositoryException;
|
||||||
|
@ -59,7 +59,7 @@ import java.util.regex.Pattern;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Service( "repositoryMerger#maven2" )
|
@Service ("repositoryMerger#maven2")
|
||||||
public class Maven2RepositoryMerger
|
public class Maven2RepositoryMerger
|
||||||
implements RepositoryMerger
|
implements RepositoryMerger
|
||||||
{
|
{
|
||||||
|
@ -80,8 +80,8 @@ public class Maven2RepositoryMerger
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Maven2RepositoryMerger(
|
public Maven2RepositoryMerger(
|
||||||
@Named( value = "archivaConfiguration#default" ) ArchivaConfiguration archivaConfiguration,
|
@Named (value = "archivaConfiguration#default") ArchivaConfiguration archivaConfiguration,
|
||||||
@Named( value = "repositoryPathTranslator#maven2" ) RepositoryPathTranslator repositoryPathTranslator )
|
@Named (value = "repositoryPathTranslator#maven2") RepositoryPathTranslator repositoryPathTranslator )
|
||||||
{
|
{
|
||||||
this.configuration = archivaConfiguration;
|
this.configuration = archivaConfiguration;
|
||||||
this.pathTranslator = repositoryPathTranslator;
|
this.pathTranslator = repositoryPathTranslator;
|
||||||
|
@ -93,30 +93,60 @@ public class Maven2RepositoryMerger
|
||||||
}
|
}
|
||||||
|
|
||||||
public void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId )
|
public void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId )
|
||||||
throws Exception
|
throws RepositoryMergerException
|
||||||
{
|
{
|
||||||
|
|
||||||
List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts( sourceRepoId );
|
try
|
||||||
for ( ArtifactMetadata artifactMetadata : artifactsInSourceRepo )
|
|
||||||
{
|
{
|
||||||
artifactMetadata.setRepositoryId( targetRepoId );
|
List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts( sourceRepoId );
|
||||||
createFolderStructure( sourceRepoId, targetRepoId, artifactMetadata );
|
for ( ArtifactMetadata artifactMetadata : artifactsInSourceRepo )
|
||||||
|
{
|
||||||
|
artifactMetadata.setRepositoryId( targetRepoId );
|
||||||
|
createFolderStructure( sourceRepoId, targetRepoId, artifactMetadata );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( MetadataRepositoryException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryMergerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryMergerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( RepositoryException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryMergerException( e.getMessage(), e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO when UI needs a subset to merge
|
// TODO when UI needs a subset to merge
|
||||||
public void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId,
|
public void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId,
|
||||||
Filter<ArtifactMetadata> filter )
|
Filter<ArtifactMetadata> filter )
|
||||||
throws Exception
|
throws RepositoryMergerException
|
||||||
{
|
{
|
||||||
List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepoId );
|
try
|
||||||
for ( ArtifactMetadata metadata : sourceArtifacts )
|
|
||||||
{
|
{
|
||||||
if ( filter.accept( metadata ) )
|
List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepoId );
|
||||||
|
for ( ArtifactMetadata metadata : sourceArtifacts )
|
||||||
{
|
{
|
||||||
createFolderStructure( sourceRepoId, targetRepoId, metadata );
|
if ( filter.accept( metadata ) )
|
||||||
|
{
|
||||||
|
createFolderStructure( sourceRepoId, targetRepoId, metadata );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch ( MetadataRepositoryException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryMergerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryMergerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( RepositoryException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryMergerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createFolderStructure( String sourceRepoId, String targetRepoId, ArtifactMetadata artifactMetadata )
|
private void createFolderStructure( String sourceRepoId, String targetRepoId, ArtifactMetadata artifactMetadata )
|
||||||
|
@ -206,7 +236,7 @@ public class Maven2RepositoryMerger
|
||||||
if ( versionMetaDataFileInSourceRepo.exists() )
|
if ( versionMetaDataFileInSourceRepo.exists() )
|
||||||
{//Pattern quote for windows path
|
{//Pattern quote for windows path
|
||||||
String relativePathToVersionMetadataFile =
|
String relativePathToVersionMetadataFile =
|
||||||
versionMetaDataFileInSourceRepo.getAbsolutePath().split( Pattern.quote( sourceRepoPath ) )[1];
|
versionMetaDataFileInSourceRepo.getAbsolutePath().split( Pattern.quote( sourceRepoPath ) )[1];
|
||||||
File versionMetaDataFileInTargetRepo = new File( targetRepoPath, relativePathToVersionMetadataFile );
|
File versionMetaDataFileInTargetRepo = new File( targetRepoPath, relativePathToVersionMetadataFile );
|
||||||
|
|
||||||
if ( !versionMetaDataFileInTargetRepo.exists() )
|
if ( !versionMetaDataFileInTargetRepo.exists() )
|
||||||
|
@ -352,30 +382,36 @@ public class Maven2RepositoryMerger
|
||||||
|
|
||||||
public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
|
public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
|
||||||
String targetRepo )
|
String targetRepo )
|
||||||
throws Exception
|
throws RepositoryMergerException
|
||||||
{
|
{
|
||||||
List<ArtifactMetadata> targetArtifacts = metadataRepository.getArtifacts( targetRepo );
|
try
|
||||||
List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepo );
|
|
||||||
List<ArtifactMetadata> conflictsArtifacts = new ArrayList<ArtifactMetadata>();
|
|
||||||
|
|
||||||
for ( ArtifactMetadata targetArtifact : targetArtifacts )
|
|
||||||
{
|
{
|
||||||
for ( ArtifactMetadata sourceArtifact : sourceArtifacts )
|
List<ArtifactMetadata> targetArtifacts = metadataRepository.getArtifacts( targetRepo );
|
||||||
|
List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepo );
|
||||||
|
List<ArtifactMetadata> conflictsArtifacts = new ArrayList<ArtifactMetadata>();
|
||||||
|
|
||||||
|
for ( ArtifactMetadata targetArtifact : targetArtifacts )
|
||||||
{
|
{
|
||||||
if ( isEquals( targetArtifact, sourceArtifact ) )
|
for ( ArtifactMetadata sourceArtifact : sourceArtifacts )
|
||||||
{
|
{
|
||||||
if ( !conflictsArtifacts.contains( sourceArtifact ) )
|
if ( isEquals( targetArtifact, sourceArtifact ) )
|
||||||
{
|
{
|
||||||
conflictsArtifacts.add( sourceArtifact );
|
if ( !conflictsArtifacts.contains( sourceArtifact ) )
|
||||||
|
{
|
||||||
|
conflictsArtifacts.add( sourceArtifact );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
sourceArtifacts.removeAll( conflictsArtifacts );
|
sourceArtifacts.removeAll( conflictsArtifacts );
|
||||||
Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
|
|
||||||
// merge( sourceRepo, targetRepo, artifactsWithOutConflicts );
|
return conflictsArtifacts;
|
||||||
return conflictsArtifacts;
|
}
|
||||||
|
catch ( MetadataRepositoryException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryMergerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEquals( ArtifactMetadata sourceArtifact, ArtifactMetadata targetArtifact )
|
private boolean isEquals( ArtifactMetadata sourceArtifact, ArtifactMetadata targetArtifact )
|
||||||
|
|
|
@ -28,13 +28,13 @@ import java.util.List;
|
||||||
public interface RepositoryMerger
|
public interface RepositoryMerger
|
||||||
{
|
{
|
||||||
void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId )
|
void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId )
|
||||||
throws Exception;
|
throws RepositoryMergerException;
|
||||||
|
|
||||||
void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId,
|
void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId,
|
||||||
Filter<ArtifactMetadata> filter )
|
Filter<ArtifactMetadata> filter )
|
||||||
throws Exception;
|
throws RepositoryMergerException;
|
||||||
|
|
||||||
List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
|
List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
|
||||||
String targetRepo )
|
String targetRepo )
|
||||||
throws Exception;
|
throws RepositoryMergerException;
|
||||||
}
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.apache.archiva.stagerepository.merge;
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Olivier Lamy
|
||||||
|
* @since 1.4-M3
|
||||||
|
*/
|
||||||
|
public class RepositoryMergerException
|
||||||
|
extends Exception
|
||||||
|
{
|
||||||
|
public RepositoryMergerException( String msg, Exception e )
|
||||||
|
{
|
||||||
|
super( msg, e );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue