diff options
author | Martin Stockhammer <martin_s@apache.org> | 2020-02-01 00:41:34 +0100 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2020-02-01 00:41:34 +0100 |
commit | 865e3fef2449f093ddfb6c133563de0a0b5d4659 (patch) | |
tree | 38975ae0f82f587a49df840346012dc87f650283 /archiva-modules/archiva-web/archiva-rest | |
parent | 5fe962ccce28d60c2745343e0174fed42bd5e2b5 (diff) | |
download | archiva-865e3fef2449f093ddfb6c133563de0a0b5d4659.tar.gz archiva-865e3fef2449f093ddfb6c133563de0a0b5d4659.zip |
Adding metadatareader interface
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest')
2 files changed, 30 insertions, 37 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index 3bb2a87db..7899fdf22 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -42,6 +42,8 @@ import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryNotFoundException; +import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.metadata.MetadataReader; import org.apache.archiva.repository.metadata.base.MetadataTools; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.repository.storage.StorageUtil; @@ -87,6 +89,9 @@ public class DefaultBrowseService ProxyRegistry proxyRegistry; @Inject + RepositoryRegistry repositoryRegistry; + + @Inject @Named( value = "browse#versionMetadata" ) private Cache<String, ProjectVersionMetadata> versionMetadataCache; @@ -919,30 +924,24 @@ public class DefaultBrowseService StorageAsset metadataFile = file.getStorage().getAsset(file.getParent().getPath()+"/"+MetadataTools.MAVEN_METADATA ); if ( metadataFile.exists() ) { - try - { - ArchivaRepositoryMetadata archivaRepositoryMetadata = - MavenMetadataReader.read( metadataFile ); - int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber(); - String timeStamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp(); - // rebuild file name with timestamped version and build number - String timeStampFileName = new StringBuilder( artifactId ).append( '-' ) // - .append( StringUtils.remove( version, "-" + VersionUtil.SNAPSHOT ) ) // - .append( '-' ).append( timeStamp ) // - .append( '-' ).append( Integer.toString( buildNumber ) ) // - .append( ( StringUtils.isEmpty( classifier ) ? "" : "-" + classifier ) ) // - .append( ".jar" ).toString(); - - StorageAsset timeStampFile = file.getStorage().getAsset(file.getParent().getPath() + "/" + timeStampFileName ); - log.debug( "try to find timestamped snapshot version file: {}", timeStampFile.getPath() ); - if ( timeStampFile.exists() ) - { - return true; - } - } - catch (XMLException | IOException e ) + MetadataReader metadataReader = repositoryRegistry.getMetadataReader( managedRepositoryContent.getRepository( ).getType( ) ); + ArchivaRepositoryMetadata archivaRepositoryMetadata = + metadataReader.read( metadataFile ); + int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber(); + String timeStamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp(); + // rebuild file name with timestamped version and build number + String timeStampFileName = new StringBuilder( artifactId ).append( '-' ) // + .append( StringUtils.remove( version, "-" + VersionUtil.SNAPSHOT ) ) // + .append( '-' ).append( timeStamp ) // + .append( '-' ).append( Integer.toString( buildNumber ) ) // + .append( ( StringUtils.isEmpty( classifier ) ? "" : "-" + classifier ) ) // + .append( ".jar" ).toString(); + + StorageAsset timeStampFile = file.getStorage().getAsset(file.getParent().getPath() + "/" + timeStampFileName ); + log.debug( "try to find timestamped snapshot version file: {}", timeStampFile.getPath() ); + if ( timeStampFile.exists() ) { - log.warn( "skip fail to find timestamped snapshot file: {}", e.getMessage() ); + return true; } } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java index 55c999530..8cf4ec039 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java @@ -50,6 +50,7 @@ import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryNotFoundException; import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.storage.RepositoryStorage; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.repository.storage.StorageUtil; @@ -404,7 +405,7 @@ public class DefaultRepositoriesService String timestamp = null; StorageAsset versionMetadataFile = target.getAsset(path + "/" + MetadataTools.MAVEN_METADATA ); - /* unused */ getMetadata( versionMetadataFile ); + /* unused */ getMetadata( targetRepository.getRepository().getType(), versionMetadataFile ); if ( !targetDir.exists() ) { @@ -454,7 +455,7 @@ public class DefaultRepositoriesService // explicitly update only if metadata-updater consumer is not enabled! if ( !archivaAdministration.getKnownContentConsumers().contains( "metadata-updater" ) ) { - updateProjectMetadata( target, targetDir, lastUpdatedTimestamp, timestamp, newBuildNumber, + updateProjectMetadata( target.getType(), target, targetDir, lastUpdatedTimestamp, timestamp, newBuildNumber, fixChecksums, artifactTransferRequest ); @@ -505,20 +506,13 @@ public class DefaultRepositoriesService } } - private ArchivaRepositoryMetadata getMetadata( StorageAsset metadataFile ) + private ArchivaRepositoryMetadata getMetadata( RepositoryType repositoryType, StorageAsset metadataFile ) throws RepositoryMetadataException { ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata(); if ( metadataFile.exists() ) { - try - { - metadata = MavenMetadataReader.read( metadataFile.getFilePath() ); - } - catch (XMLException e ) - { - throw new RepositoryMetadataException( e.getMessage(), e ); - } + metadata = repositoryRegistry.getMetadataReader( repositoryType ).read( metadataFile ); } return metadata; } @@ -553,7 +547,7 @@ public class DefaultRepositoriesService } } - private void updateProjectMetadata( RepositoryStorage storage, StorageAsset targetPath, Date lastUpdatedTimestamp, String timestamp, int buildNumber, + private void updateProjectMetadata( RepositoryType repositoryType, RepositoryStorage storage, StorageAsset targetPath, Date lastUpdatedTimestamp, String timestamp, int buildNumber, boolean fixChecksums, ArtifactTransferRequest artifactTransferRequest ) throws RepositoryMetadataException { @@ -563,7 +557,7 @@ public class DefaultRepositoriesService StorageAsset projectDir = targetPath.getParent(); StorageAsset projectMetadataFile = storage.getAsset( projectDir.getPath()+"/"+MetadataTools.MAVEN_METADATA ); - ArchivaRepositoryMetadata projectMetadata = getMetadata( projectMetadataFile ); + ArchivaRepositoryMetadata projectMetadata = getMetadata( repositoryType, projectMetadataFile ); if ( projectMetadataFile.exists() ) { @@ -854,7 +848,7 @@ public class DefaultRepositoriesService repository.deleteArtifact( artifactRef ); } StorageAsset metadataFile = getMetadata( repo, targetPath.getPath() ); - ArchivaRepositoryMetadata metadata = getMetadata( metadataFile ); + ArchivaRepositoryMetadata metadata = getMetadata( repository.getRepository().getType(), metadataFile ); updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, artifact ); } |