diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-07-28 15:24:13 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-07-28 15:24:13 +0200 |
commit | bb3b074aaf5a2be0d81c950ecf1588fe8efa3316 (patch) | |
tree | 8f165780e4d81cfdb6ed4a73c40fbed3a6f39a69 /archiva-modules/plugins | |
parent | 8e4acdc82a875ca32e39eb216b879c002d228de3 (diff) | |
download | archiva-bb3b074aaf5a2be0d81c950ecf1588fe8efa3316.tar.gz archiva-bb3b074aaf5a2be0d81c950ecf1588fe8efa3316.zip |
Refactoring to StorageAsset access
Diffstat (limited to 'archiva-modules/plugins')
2 files changed, 32 insertions, 14 deletions
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java index 2cd68f41b..3ebed1a49 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java @@ -38,6 +38,7 @@ import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.archiva.xml.XMLException; +import java.io.IOException; import java.util.Collection; /** @@ -118,7 +119,7 @@ public class MockRepositoryStorage @Override public String getFilePathWithVersion( String requestPath, ManagedRepositoryContent managedRepositoryContent ) - throws RelocationException, XMLException + throws RelocationException, XMLException, IOException { return null; } diff --git a/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java b/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java index 049f3a719..7b8c64230 100644 --- a/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java +++ b/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java @@ -19,6 +19,7 @@ package org.apache.archiva.stagerepository.merge; * under the License. */ +import org.apache.archiva.common.filelock.DefaultFileLockManager; import org.apache.archiva.common.utils.VersionComparator; import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.configuration.ArchivaConfiguration; @@ -34,6 +35,9 @@ import org.apache.archiva.model.ArchivaRepositoryMetadata; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.metadata.RepositoryMetadataWriter; +import org.apache.archiva.repository.storage.FilesystemAsset; +import org.apache.archiva.repository.storage.FilesystemStorage; +import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.xml.XMLException; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; @@ -42,7 +46,10 @@ import org.springframework.stereotype.Service; import javax.inject.Inject; import javax.inject.Named; +import java.io.BufferedWriter; import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.Buffer; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -227,20 +234,22 @@ public class Maven2RepositoryMerger { // updating version metadata files - Path versionMetaDataFileInSourceRepo = - pathTranslator.toFile( Paths.get( sourceRepoPath ), artifactMetadata.getNamespace(), + FilesystemStorage fsStorage = new FilesystemStorage(Paths.get(sourceRepoPath), new DefaultFileLockManager()); + + StorageAsset versionMetaDataFileInSourceRepo = + pathTranslator.toFile( new FilesystemAsset(fsStorage, "", Paths.get(sourceRepoPath)), artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getVersion(), METADATA_FILENAME ); - if ( Files.exists(versionMetaDataFileInSourceRepo) ) + if ( versionMetaDataFileInSourceRepo.exists() ) {//Pattern quote for windows path String relativePathToVersionMetadataFile = - versionMetaDataFileInSourceRepo.toAbsolutePath().toString().split( Pattern.quote( sourceRepoPath ) )[1]; + versionMetaDataFileInSourceRepo.getPath().toString().split( Pattern.quote( sourceRepoPath ) )[1]; Path versionMetaDataFileInTargetRepo = Paths.get( targetRepoPath, relativePathToVersionMetadataFile ); if ( !Files.exists(versionMetaDataFileInTargetRepo) ) { - copyFile( versionMetaDataFileInSourceRepo, versionMetaDataFileInTargetRepo ); + copyFile( versionMetaDataFileInSourceRepo.getFilePath(), versionMetaDataFileInTargetRepo ); } else { @@ -250,19 +259,19 @@ public class Maven2RepositoryMerger } // updating project meta data file - Path projectDirectoryInSourceRepo = versionMetaDataFileInSourceRepo.getParent().getParent(); - Path projectMetadataFileInSourceRepo = projectDirectoryInSourceRepo.resolve(METADATA_FILENAME ); + StorageAsset projectDirectoryInSourceRepo = versionMetaDataFileInSourceRepo.getParent().getParent(); + StorageAsset projectMetadataFileInSourceRepo = projectDirectoryInSourceRepo.resolve(METADATA_FILENAME ); - if ( Files.exists(projectMetadataFileInSourceRepo) ) + if ( projectMetadataFileInSourceRepo.exists() ) { String relativePathToProjectMetadataFile = - projectMetadataFileInSourceRepo.toAbsolutePath().toString().split( Pattern.quote( sourceRepoPath ) )[1]; + projectMetadataFileInSourceRepo.getPath().split( Pattern.quote( sourceRepoPath ) )[1]; Path projectMetadataFileInTargetRepo = Paths.get( targetRepoPath, relativePathToProjectMetadataFile ); if ( !Files.exists(projectMetadataFileInTargetRepo) ) { - copyFile( projectMetadataFileInSourceRepo, projectMetadataFileInTargetRepo ); + copyFile( projectMetadataFileInSourceRepo.getFilePath(), projectMetadataFileInTargetRepo ); } else { @@ -331,7 +340,11 @@ public class Maven2RepositoryMerger projectMetadata.setReleasedVersion( latestVersion ); } - RepositoryMetadataWriter.write( projectMetadata, projectMetaDataFileIntargetRepo ); + try(BufferedWriter writer = Files.newBufferedWriter(projectMetaDataFileIntargetRepo)) { + RepositoryMetadataWriter.write( projectMetadata, writer ); + } catch (IOException e) { + throw new RepositoryMetadataException(e); + } } @@ -348,7 +361,11 @@ public class Maven2RepositoryMerger } versionMetadata.setLastUpdatedTimestamp( lastUpdatedTimestamp ); - RepositoryMetadataWriter.write( versionMetadata, versionMetaDataFileInTargetRepo ); + try(BufferedWriter writer = Files.newBufferedWriter(versionMetaDataFileInTargetRepo) ) { + RepositoryMetadataWriter.write( versionMetadata, writer); + } catch (IOException e) { + throw new RepositoryMetadataException(e); + } } private ArchivaRepositoryMetadata getMetadata( Path metadataFile ) @@ -361,7 +378,7 @@ public class Maven2RepositoryMerger { metadata = MavenMetadataReader.read( metadataFile ); } - catch ( XMLException e ) + catch (XMLException | IOException e ) { throw new RepositoryMetadataException( e.getMessage(), e ); } |