aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-maven
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2020-06-02 22:53:18 +0200
committerMartin Stockhammer <martin_s@apache.org>2020-06-02 22:53:18 +0200
commit873753536bbc1cd1639016ae845625f631f3cff1 (patch)
tree0345e0a67b08ceae743a8a8fb8e7db5772a9dceb /archiva-modules/archiva-maven
parent22a8cbfd22c8cfb33a8d4e3e82cf22a7c03df68b (diff)
downloadarchiva-873753536bbc1cd1639016ae845625f631f3cff1.tar.gz
archiva-873753536bbc1cd1639016ae845625f631f3cff1.zip
Switching to new repository layout
Diffstat (limited to 'archiva-modules/archiva-maven')
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java6
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java12
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/DefaultPathParser.java1
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java34
4 files changed, 40 insertions, 13 deletions
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java
index e15bbfb1d..291e0a914 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java
@@ -34,8 +34,7 @@ import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
/**
* SnapshotTransferTest
@@ -314,6 +313,7 @@ public class SnapshotTransferTest
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
+ assertNotNull( downloadedFile );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
@@ -333,6 +333,7 @@ public class SnapshotTransferTest
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
+ artifact.setProjectVersion( "1.0-SNAPSHOT" );
assertTrue( Files.exists(expectedFile) );
@@ -344,6 +345,7 @@ public class SnapshotTransferTest
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
+ assertNotNull( downloadedFile );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
index e49c913c7..970645139 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
@@ -36,6 +36,7 @@ import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.Namespace;
import org.apache.archiva.repository.content.Project;
import org.apache.archiva.repository.content.Version;
+import org.apache.archiva.repository.content.base.ArchivaArtifact;
import org.apache.archiva.repository.content.base.ArchivaContentItem;
import org.apache.archiva.repository.content.base.ArchivaDataItem;
import org.apache.archiva.repository.content.base.ArchivaNamespace;
@@ -173,7 +174,15 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
@Override
public Artifact getArtifact( ItemSelector selector ) throws ContentAccessException
{
- return null;
+ StringBuilder path = new StringBuilder(selector.getNamespace( ).replace( ".", "/" ));
+ path.append( "/" ).append( selector.getProjectId( ) ).append( "/" ).append( selector.getVersion( ) );
+ path.append( "/" ).append( selector.getArtifactId( ) ).append( "-" ).append( selector.getArtifactVersion( ) ).append( "." ).append( selector.getType( ) );
+ StorageAsset asset = fsStorage.getAsset( path.toString( ) );
+ ArchivaNamespace ns = ArchivaNamespace.withRepository( repository.getContent( ) ).withAsset( asset.getParent( ).getParent( ).getParent( ) ).withNamespace( selector.getNamespace( ) ).build( );
+ ArchivaProject project = ArchivaProject.withRepository( repository.getContent( ) ).withAsset( asset.getParent( ).getParent( ) ).withNamespace( ns ).withId( selector.getProjectId( ) ).build( );
+ ArchivaVersion version = ArchivaVersion.withRepository( repository.getContent( ) ).withAsset( asset.getParent( ) ).withProject( project ).withVersion( selector.getVersion( ) ).build( );
+ ArchivaArtifact artifact = ArchivaArtifact.withAsset( asset ).withVersion( version ).withId( selector.getArtifactId( ) ).withArtifactVersion( selector.getArtifactVersion( ) ).withType( selector.getType( ) ).build( );
+ return artifact;
}
@Override
@@ -424,6 +433,7 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
artifact.setGroupId( metadata.getNamespace() );
artifact.setArtifactId( metadata.getProject() );
artifact.setVersion( metadata.getVersion() );
+ artifact.setProjectVersion( metadata.getProjectVersion( ) );
MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
if ( facet != null )
{
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/DefaultPathParser.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/DefaultPathParser.java
index 4754f1360..f37910744 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/DefaultPathParser.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/DefaultPathParser.java
@@ -79,6 +79,7 @@ public class DefaultPathParser
artifact.setGroupId( metadata.getNamespace() );
artifact.setArtifactId( metadata.getProject() );
artifact.setVersion( metadata.getVersion() );
+ artifact.setProjectVersion( metadata.getProjectVersion( ) );
MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
if ( facet != null )
{
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java
index 552e766a9..bcda250eb 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java
@@ -39,7 +39,10 @@ import org.apache.archiva.proxy.model.NetworkProxy;
import org.apache.archiva.proxy.model.ProxyConnector;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.content.Artifact;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.PathParser;
+import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.maven.MavenSystemManager;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.repository.storage.StorageAsset;
@@ -572,28 +575,39 @@ public class Maven2RepositoryStorage
pomReference.setGroupId(artifact.getGroupId());
pomReference.setArtifactId(artifact.getArtifactId());
pomReference.setVersion(artifact.getVersion());
+ pomReference.setProjectVersion( artifact.getProjectVersion() );
pomReference.setType("pom");
+ BaseRepositoryContentLayout layout;
+ try
+ {
+ layout = managedRepository.getContent( ).getLayout( BaseRepositoryContentLayout.class );
+ }
+ catch ( LayoutException e )
+ {
+ throw new ProxyDownloadException( "Could not set layout " + e.getMessage( ), new HashMap<>( ) );
+ }
RepositoryType repositoryType = managedRepository.getType();
if (!proxyRegistry.hasHandler(repositoryType)) {
throw new ProxyDownloadException("No proxy handler found for repository type " + repositoryType, new HashMap<>());
}
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( artifact.getGroupId( ) )
+ .withProjectId( artifact.getArtifactId( ) )
+ .withArtifactId( artifact.getArtifactId( ) )
+ .withVersion( artifact.getVersion( ) )
+ .withArtifactVersion( artifact.getVersion( ) )
+ .withType( "pom" ).build( );
+
+ Artifact pom = layout.getArtifact( selector );
+
RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(repositoryType).get(0);
// Get the artifact POM from proxied repositories if needed
proxyHandler.fetchFromProxies(managedRepository, pomReference);
// Open and read the POM from the managed repo
- StorageAsset pom = null;
- try
- {
- pom = managedRepository.getContent().getLayout( BaseRepositoryContentLayout.class ).toFile(pomReference);
- }
- catch ( LayoutException e )
- {
- throw new ProxyDownloadException( "Cannot convert layout ", new HashMap<>( ) );
- }
if (!pom.exists()) {
return;
@@ -603,7 +617,7 @@ public class Maven2RepositoryStorage
// MavenXpp3Reader leaves the file open, so we need to close it ourselves.
Model model;
- try (Reader reader = Channels.newReader(pom.getReadChannel(), Charset.defaultCharset().name())) {
+ try (Reader reader = Channels.newReader(pom.getAsset().getReadChannel(), Charset.defaultCharset().name())) {
model = MAVEN_XPP_3_READER.read(reader);
}