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:
Olivier Lamy 2012-09-18 22:02:33 +00:00
parent 65768e8719
commit 5a3bf2a3af
3 changed files with 101 additions and 33 deletions

View File

@ -27,8 +27,8 @@ import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.maven2.metadata.MavenMetadataReader;
import org.apache.archiva.metadata.model.ArtifactMetadata;
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.IncludesFilter;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.repository.RepositoryException;
@ -93,9 +93,11 @@ public class Maven2RepositoryMerger
}
public void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId )
throws Exception
throws RepositoryMergerException
{
try
{
List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts( sourceRepoId );
for ( ArtifactMetadata artifactMetadata : artifactsInSourceRepo )
{
@ -103,11 +105,26 @@ public class Maven2RepositoryMerger
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
public void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId,
Filter<ArtifactMetadata> filter )
throws Exception
throws RepositoryMergerException
{
try
{
List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepoId );
for ( ArtifactMetadata metadata : sourceArtifacts )
@ -118,6 +135,19 @@ public class Maven2RepositoryMerger
}
}
}
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 )
throws IOException, RepositoryException
@ -352,7 +382,9 @@ public class Maven2RepositoryMerger
public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
String targetRepo )
throws Exception
throws RepositoryMergerException
{
try
{
List<ArtifactMetadata> targetArtifacts = metadataRepository.getArtifacts( targetRepo );
List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepo );
@ -373,10 +405,14 @@ public class Maven2RepositoryMerger
}
sourceArtifacts.removeAll( conflictsArtifacts );
Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
// merge( sourceRepo, targetRepo, artifactsWithOutConflicts );
return conflictsArtifacts;
}
catch ( MetadataRepositoryException e )
{
throw new RepositoryMergerException( e.getMessage(), e );
}
}
private boolean isEquals( ArtifactMetadata sourceArtifact, ArtifactMetadata targetArtifact )
{

View File

@ -28,13 +28,13 @@ import java.util.List;
public interface RepositoryMerger
{
void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId )
throws Exception;
throws RepositoryMergerException;
void merge( MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId,
Filter<ArtifactMetadata> filter )
throws Exception;
throws RepositoryMergerException;
List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo,
String targetRepo )
throws Exception;
throws RepositoryMergerException;
}

View File

@ -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 );
}
}