From 7adddbe141186225bc33e918727ceb3bed6646f3 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Thu, 9 May 2019 22:58:14 +0200 Subject: [PATCH] Changing maven implementation to new RequestInfo interface --- .../archiva/repository/ManagedRepository.java | 7 ++ .../apache/archiva/repository/Repository.java | 1 + .../repository/RepositoryRequestInfo.java | 2 +- .../repository/BasicManagedRepository.java | 5 + ...t.java => MavenRepositoryRequestInfo.java} | 42 +++++-- .../maven2/MavenManagedRepository.java | 12 +- ...va => MavenRepositoryRequestInfoTest.java} | 105 ++++++++++++------ .../webdav/ArchivaDavResourceFactory.java | 58 ++++------ .../webdav/ArchivaDavResourceFactoryTest.java | 47 +++----- 9 files changed, 160 insertions(+), 119 deletions(-) rename archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/{RepositoryRequest.java => MavenRepositoryRequestInfo.java} (88%) rename archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/{RepositoryRequestTest.java => MavenRepositoryRequestInfoTest.java} (80%) diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepository.java index 1dea02bb1..3acd16198 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepository.java @@ -47,4 +47,11 @@ public interface ManagedRepository extends Repository { */ Set getActiveReleaseSchemes(); + + /** + * Returns the request info object, which you can use for gathering information from the web request path. + * @return Instance of a request info object that corresponds to this repository + */ + RepositoryRequestInfo getRequestInfo(); + } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java index f80f94b0d..384639821 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java @@ -180,4 +180,5 @@ public interface Repository extends RepositoryEventHandler { */ void close(); + } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java index 043c09cce..ecc97b844 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java @@ -118,7 +118,7 @@ public interface RepositoryRequestInfo * @return the adjusted (to native) path. * @throws LayoutException if the path cannot be parsed. */ - void toNativePath( String requestPath); + String toNativePath( String requestPath) throws LayoutException; /** * Extension method that allows to provide different features that are not supported by all diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java index d424862a9..d45daead6 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java @@ -80,4 +80,9 @@ public class BasicManagedRepository extends AbstractManagedRepository return CAPABILITIES; } + + @Override + public RepositoryRequestInfo getRequestInfo() { + return null; + } } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfo.java similarity index 88% rename from archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java rename to archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfo.java index fa7ec895b..9e70ede01 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfo.java @@ -20,9 +20,9 @@ package org.apache.archiva.repository.content.maven2; */ import org.apache.archiva.model.ArtifactReference; -import org.apache.archiva.repository.LayoutException; -import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.*; import org.apache.archiva.repository.content.PathParser; +import org.apache.archiva.repository.features.RepositoryFeature; import org.apache.archiva.repository.metadata.MetadataTools; import org.apache.commons.lang.StringUtils; @@ -30,13 +30,15 @@ import org.apache.commons.lang.StringUtils; * RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate * ArtifactReference. */ -public class RepositoryRequest +public class MavenRepositoryRequestInfo implements RepositoryRequestInfo { private PathParser defaultPathParser = new DefaultPathParser(); - public RepositoryRequest() + ManagedRepository repository; + + public MavenRepositoryRequestInfo(ManagedRepository repository) { - // no op + this.repository = repository; } /** @@ -150,6 +152,17 @@ public class RepositoryRequest return false; } + @Override + public String getLayout(String requestPath) { + if (isDefault(requestPath)) { + return "default"; + } else if (isLegacy(requestPath)) { + return "legacy"; + } else { + return "unknown"; + } + } + /** *

* Tests the path to see if it conforms to the expectations of a default layout request. @@ -164,7 +177,7 @@ public class RepositoryRequest * @param requestedPath the path to test. * @return true if the requestedPath is likely that of a default layout request. */ - public boolean isDefault( String requestedPath ) + private boolean isDefault( String requestedPath ) { if ( StringUtils.isBlank( requestedPath ) ) { @@ -219,7 +232,7 @@ public class RepositoryRequest * @param requestedPath the path to test. * @return true if the requestedPath is likely that of a legacy layout request. */ - public boolean isLegacy( String requestedPath ) + private boolean isLegacy( String requestedPath ) { if ( StringUtils.isBlank( requestedPath ) ) { @@ -234,11 +247,10 @@ public class RepositoryRequest * Adjust the requestedPath to conform to the native layout of the provided {@link org.apache.archiva.repository.ManagedRepositoryContent}. * * @param requestedPath the incoming requested path. - * @param repository the repository to adjust to. * @return the adjusted (to native) path. * @throws LayoutException if the path cannot be parsed. */ - public String toNativePath( String requestedPath, ManagedRepositoryContent repository ) + public String toNativePath( String requestedPath) throws LayoutException { if ( StringUtils.isBlank( requestedPath ) ) @@ -269,7 +281,17 @@ public class RepositoryRequest // Treat as an artifact reference. ArtifactReference ref = toArtifactReference( referencedResource ); - String adjustedPath = repository.toPath( ref ); + String adjustedPath = repository.getContent().toPath( ref ); return adjustedPath + supportfile; } + + @Override + public > RepositoryFeature getFeature(Class clazz) throws UnsupportedFeatureException { + return null; + } + + @Override + public > boolean supportsFeature(Class clazz) { + return false; + } } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java index ea55b7c5e..c002854b5 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java @@ -20,12 +20,8 @@ package org.apache.archiva.repository.maven2; */ import org.apache.archiva.common.utils.PathUtil; -import org.apache.archiva.repository.AbstractManagedRepository; -import org.apache.archiva.repository.ReleaseScheme; -import org.apache.archiva.repository.RepositoryCapabilities; -import org.apache.archiva.repository.RepositoryType; -import org.apache.archiva.repository.StandardCapabilities; -import org.apache.archiva.repository.UnsupportedFeatureException; +import org.apache.archiva.repository.*; +import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo; import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RepositoryFeature; @@ -137,4 +133,8 @@ public class MavenManagedRepository extends AbstractManagedRepository } } + @Override + public RepositoryRequestInfo getRequestInfo() { + return new MavenRepositoryRequestInfo(this); + } } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java similarity index 80% rename from archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java rename to archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java index db3210863..95bbf0f3a 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java @@ -21,6 +21,9 @@ package org.apache.archiva.repository.content.maven2; import org.apache.archiva.common.utils.FileUtils; import org.apache.archiva.configuration.ArchivaConfiguration; +import org.apache.archiva.configuration.FileType; +import org.apache.archiva.configuration.FileTypes; +import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.ManagedRepositoryContent; @@ -38,6 +41,7 @@ import javax.inject.Inject; import javax.inject.Named; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; import static org.junit.Assert.*; @@ -47,23 +51,52 @@ import static org.junit.Assert.*; @RunWith( ArchivaSpringJUnit4ClassRunner.class ) @ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-repo-request-test.xml" } ) -public class RepositoryRequestTest +public class MavenRepositoryRequestInfoTest { @Inject protected ApplicationContext applicationContext; + @Inject + FileTypes fileTypes; + @Inject @Named( "archivaConfiguration#repo-request-test" ) private ArchivaConfiguration archivaConfiguration; - private RepositoryRequest repoRequest; + @Inject + List artifactMappingProviders; + + private MavenRepositoryRequestInfo repoRequest; + + + protected MavenManagedRepository createRepository( String id, String name, Path location ) + { + MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent().toAbsolutePath()); + repo.setLocation( location.toAbsolutePath().toUri() ); + return repo; + } + @Before public void setUp() throws Exception { - repoRequest = new RepositoryRequest(); + + Path repoDir = Paths.get( "src/test/repositories/default-repository" ); + MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", repoDir ); + + FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); + fileType.addPattern( "**/*.xml" ); + assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); + + fileTypes.afterConfigurationChange( null, "fileType", null ); + + ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent(artifactMappingProviders, fileTypes); + //repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" ); + repoContent.setRepository( repository ); + repository.setContent(repoContent); + repoRequest = new MavenRepositoryRequestInfo(repository); } @Test @@ -330,41 +363,41 @@ public class RepositoryRequestTest @Test public void testIsDefault() { - assertFalse( repoRequest.isDefault( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); - assertFalse( repoRequest.isDefault( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) ); - assertFalse( repoRequest.isDefault( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) ); + assertNotEquals( "default", repoRequest.getLayout( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); + assertNotEquals("default", repoRequest.getLayout( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) ); + assertNotEquals("default", repoRequest.getLayout( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) ); - assertTrue( repoRequest.isDefault( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); - assertTrue( repoRequest.isDefault( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); - assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); - assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); - assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); - assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml" ) ); - assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml.sha1" ) ); - assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml.md5" ) ); + assertEquals("default", repoRequest.getLayout( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); + assertEquals("default", repoRequest.getLayout( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); + assertEquals("default", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); + assertEquals("default", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); + assertEquals("default", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); + assertEquals("default", repoRequest.getLayout( "eclipse/jdtcore/maven-metadata.xml" ) ); + assertEquals("default", repoRequest.getLayout( "eclipse/jdtcore/maven-metadata.xml.sha1" ) ); + assertEquals("default", repoRequest.getLayout( "eclipse/jdtcore/maven-metadata.xml.md5" ) ); - assertFalse( repoRequest.isDefault( null ) ); - assertFalse( repoRequest.isDefault( "" ) ); - assertFalse( repoRequest.isDefault( "foo" ) ); - assertFalse( repoRequest.isDefault( "some.short/path" ) ); + assertNotEquals("default", repoRequest.getLayout( null ) ); + assertNotEquals("default", repoRequest.getLayout( "" ) ); + assertNotEquals("default", repoRequest.getLayout( "foo" ) ); + assertNotEquals("default", repoRequest.getLayout( "some.short/path" ) ); } @Test public void testIsLegacy() { - assertTrue( repoRequest.isLegacy( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); - assertTrue( repoRequest.isLegacy( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) ); - assertTrue( repoRequest.isLegacy( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) ); + assertEquals("legacy", repoRequest.getLayout( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); + assertEquals("legacy", repoRequest.getLayout( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) ); + assertEquals("legacy", repoRequest.getLayout( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) ); - assertFalse( repoRequest.isLegacy( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); - assertFalse( repoRequest.isLegacy( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); - assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); - assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); - assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); + assertNotEquals("legacy", repoRequest.getLayout( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); + assertNotEquals("legacy", repoRequest.getLayout( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); + assertNotEquals("legacy", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); + assertNotEquals("legacy", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); + assertNotEquals("legacy", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); - assertFalse( repoRequest.isLegacy( null ) ); - assertFalse( repoRequest.isLegacy( "" ) ); - assertFalse( repoRequest.isLegacy( "some.short/path" ) ); + assertNotEquals("legacy", repoRequest.getLayout( null ) ); + assertNotEquals("legacy", repoRequest.getLayout( "" ) ); + assertNotEquals("legacy", repoRequest.getLayout( "some.short/path" ) ); } private ManagedRepositoryContent createManagedRepo( String layout ) @@ -385,8 +418,7 @@ public class RepositoryRequestTest // Test (artifact) default to default - dual extension assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", - repoRequest.toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", - repository ) ); + repoRequest.toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip") ); } @@ -398,8 +430,7 @@ public class RepositoryRequestTest // Test (metadata) default to default assertEquals( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", - repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", - repository ) ); + repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1") ); } @@ -412,7 +443,7 @@ public class RepositoryRequestTest // Test bad request path (too short) try { - repoRequest.toNativePath( "org.apache.derby/license.txt", repository ); + repoRequest.toNativePath( "org.apache.derby/license.txt"); fail( "Should have thrown an exception about a too short path." ); } catch ( LayoutException e ) @@ -430,7 +461,7 @@ public class RepositoryRequestTest // Test bad request path (too short) try { - repoRequest.toNativePath( "", repository ); + repoRequest.toNativePath( ""); fail( "Should have thrown an exception about an blank request." ); } catch ( LayoutException e ) @@ -448,7 +479,7 @@ public class RepositoryRequestTest // Test bad request path (too short) try { - repoRequest.toNativePath( null, repository ); + repoRequest.toNativePath( null); fail( "Should have thrown an exception about an null request." ); } catch ( LayoutException e ) @@ -466,7 +497,7 @@ public class RepositoryRequestTest // Test bad request path (too short) try { - repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/license.txt", repository ); + repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/license.txt"); fail( "Should have thrown an exception about an invalid type." ); } catch ( LayoutException e ) diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index b229ec981..3cdf4c67f 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -58,13 +58,8 @@ import org.apache.archiva.redback.policy.MustChangePasswordException; import org.apache.archiva.redback.system.SecuritySession; import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.UserManager; -import org.apache.archiva.repository.LayoutException; -import org.apache.archiva.repository.ManagedRepository; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.ReleaseScheme; -import org.apache.archiva.repository.RepositoryContentFactory; -import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.archiva.repository.content.maven2.RepositoryRequest; +import org.apache.archiva.repository.*; +import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo; import org.apache.archiva.repository.events.AuditListener; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.metadata.MetadataTools; @@ -132,11 +127,6 @@ public class ArchivaDavResourceFactory @Inject private List auditListeners = new ArrayList<>(); - @Inject - private RepositoryContentFactory repositoryFactory; - - private RepositoryRequest repositoryRequest; - @Inject private ProxyRegistry proxyRegistry; @@ -203,8 +193,6 @@ public class ArchivaDavResourceFactory this.digestMd5 = plexusSisuBridge.lookup( Digester.class, "md5" ); this.digestSha1 = plexusSisuBridge.lookup( Digester.class, "sha1" ); - // TODO remove this hard dependency on maven !! - repositoryRequest = new RepositoryRequest( ); } @PostConstruct @@ -228,6 +216,7 @@ public class ArchivaDavResourceFactory List resourcesInAbsolutePath = new ArrayList<>(); boolean readMethod = WebdavMethodUtil.isReadMethod( request.getMethod() ); + RepositoryRequestInfo repositoryRequestInfo = null; DavResource resource; if ( repoGroupConfig != null ) { @@ -259,6 +248,13 @@ public class ArchivaDavResourceFactory List repositories = new ArrayList<>( repoGroupConfig.getRepositories() ); resource = processRepositoryGroup( request, archivaLocator, repositories, activePrincipal, resourcesInAbsolutePath, repoGroupConfig ); + for (String repoId: repositories ) { + ManagedRepository repo = repositoryRegistry.getManagedRepository(repoId); + if (repo!=null) { + repositoryRequestInfo = repo.getRequestInfo(); + break; + } + } } } else @@ -315,7 +311,7 @@ public class ArchivaDavResourceFactory resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent, repo); - + repositoryRequestInfo = repo.getRequestInfo(); String logicalResource = getLogicalResource( archivaLocator, null, false ); resourcesInAbsolutePath.add( Paths.get( managedRepositoryContent.getRepoRoot(), logicalResource ).toAbsolutePath().toString() ); @@ -326,7 +322,7 @@ public class ArchivaDavResourceFactory // MRM-872 : merge all available metadata // merge metadata only when requested via the repo group - if ( ( repositoryRequest.isMetadata( requestedResource ) || repositoryRequest.isMetadataSupportFile( + if ( ( repositoryRequestInfo.isMetadata( requestedResource ) || repositoryRequestInfo.isMetadataSupportFile( requestedResource ) ) && repoGroupConfig != null ) { // this should only be at the project level not version level! @@ -340,7 +336,7 @@ public class ArchivaDavResourceFactory filePath = filePath + "/maven-metadata-" + repoGroupConfig.getId() + ".xml"; // for MRM-872 handle checksums of the merged metadata files - if ( repositoryRequest.isSupportFile( requestedResource ) ) + if ( repositoryRequestInfo.isSupportFile( requestedResource ) ) { Path metadataChecksum = Paths.get( filePath + "." + StringUtils.substringAfterLast( requestedResource, "." ) ); @@ -609,8 +605,7 @@ public class ArchivaDavResourceFactory { // Perform an adjustment of the resource to the managed // repository expected path. - String localResourcePath = - repositoryRequest.toNativePath( logicalResource.getPath(), managedRepositoryContent ); + String localResourcePath = managedRepository.getRequestInfo().toNativePath( logicalResource.getPath() ); resourceFile = Paths.get( managedRepositoryContent.getRepoRoot(), localResourcePath ); resource = new ArchivaDavResource( resourceFile.toAbsolutePath().toString(), logicalResource.getPath(), @@ -650,11 +645,11 @@ public class ArchivaDavResourceFactory if ( request.getMethod().equals( HTTP_PUT_METHOD ) ) { String resourcePath = logicalResource.getPath(); - + RepositoryRequestInfo repositoryRequestInfo = managedRepository.getRequestInfo(); // check if target repo is enabled for releases // we suppose that release-artifacts can be deployed only to repos enabled for releases - if ( managedRepositoryContent.getRepository().getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE ) && !repositoryRequest.isMetadata( - resourcePath ) && !repositoryRequest.isSupportFile( resourcePath ) ) + if ( managedRepositoryContent.getRepository().getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE ) && !repositoryRequestInfo.isMetadata( + resourcePath ) && !repositoryRequestInfo.isSupportFile( resourcePath ) ) { ArtifactReference artifact = null; try @@ -756,8 +751,9 @@ public class ArchivaDavResourceFactory if (!proxyRegistry.hasHandler(managedRepository.getRepository().getType())) { throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No proxy handler found for repository type "+managedRepository.getRepository().getType()); } + RepositoryRequestInfo repositoryRequestInfo = managedRepository.getRepository().getRequestInfo(); RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(managedRepository.getRepository().getType()).get(0); - if ( repositoryRequest.isSupportFile( path ) ) + if ( repositoryRequestInfo.isSupportFile( path ) ) { Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path ); @@ -765,13 +761,13 @@ public class ArchivaDavResourceFactory } // Is it a Metadata resource? - if ( repositoryRequest.isDefault( path ) && repositoryRequest.isMetadata( path ) ) + if ( "default".equals(repositoryRequestInfo.getLayout( path )) && repositoryRequestInfo.isMetadata( path ) ) { return proxyHandler.fetchMetadataFromProxies( managedRepository, path ).isModified(); } // Is it an Archetype Catalog? - if ( repositoryRequest.isArchetypeCatalog( path ) ) + if ( repositoryRequestInfo.isArchetypeCatalog( path ) ) { // FIXME we must implement a merge of remote archetype catalog from remote servers. Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path ); @@ -783,7 +779,7 @@ public class ArchivaDavResourceFactory try { // Get the artifact reference in a layout neutral way. - ArtifactReference artifact = repositoryRequest.toArtifactReference( path ); + ArtifactReference artifact = repositoryRequestInfo.toArtifactReference( path ); if ( artifact != null ) { @@ -1418,16 +1414,6 @@ public class ArchivaDavResourceFactory this.archivaConfiguration = archivaConfiguration; } - public void setRepositoryFactory( RepositoryContentFactory repositoryFactory ) - { - this.repositoryFactory = repositoryFactory; - } - - public void setRepositoryRequest( RepositoryRequest repositoryRequest ) - { - this.repositoryRequest = repositoryRequest; - } - public RemoteRepositoryAdmin getRemoteRepositoryAdmin() { return remoteRepositoryAdmin; diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java index 22a99f3b0..6932a31c4 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java @@ -47,7 +47,7 @@ import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent; -import org.apache.archiva.repository.content.maven2.RepositoryRequest; +import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.webdav.DavException; @@ -105,7 +105,7 @@ public class ArchivaDavResourceFactoryTest private IMocksControl repoRequestControl; - private RepositoryRequest repoRequest; + private MavenRepositoryRequestInfo repoRequest; private IMocksControl responseControl; @@ -222,13 +222,11 @@ public class ArchivaDavResourceFactoryTest repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class ); repoRequestControl = createControl(); - repoRequest = repoRequestControl.createMock( RepositoryRequest.class ); + repoRequest = repoRequestControl.createMock( MavenRepositoryRequestInfo.class ); resourceFactory = new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration ); resourceFactory.setArchivaConfiguration( archivaConfiguration ); - resourceFactory.setRepositoryFactory( repoFactory ); - resourceFactory.setRepositoryRequest( repoRequest ); proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear(); proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this)); resourceFactory.setProxyRegistry(proxyRegistry); @@ -353,14 +351,14 @@ public class ArchivaDavResourceFactoryTest expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true ); expect( - repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( - false ); + repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( + "legacy" ); expect( repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ); - expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", - internalRepo ) ).andReturn( + expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" + ) ).andReturn( Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString()); @@ -433,14 +431,14 @@ public class ArchivaDavResourceFactoryTest expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ); expect( - repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( - false ); + repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( + "legacy" ); expect( repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ); - expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", - internalRepo ) ).andReturn( + expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" + ) ).andReturn( Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString()); @@ -515,19 +513,19 @@ public class ArchivaDavResourceFactoryTest expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 ); expect( - repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( - false ).times( 2 ); + repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( + "legacy" ).times( 2 ); expect( repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 ); - expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", - internalRepo ) ).andReturn( + expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" + ) ).andReturn( Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() ); - expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", - localMirrorRepo ) ) + expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" + ) ) .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString()); @@ -565,8 +563,7 @@ public class ArchivaDavResourceFactoryTest ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO ); // use actual object (this performs the isMetadata, isDefault and isSupportFile check!) - RepositoryRequest repoRequest = new RepositoryRequest( ); - resourceFactory.setRepositoryRequest( repoRequest ); + MavenRepositoryRequestInfo repoRequest = new MavenRepositoryRequestInfo(internalRepo.getRepository() ); try { @@ -624,10 +621,6 @@ public class ArchivaDavResourceFactoryTest ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO ); - // use actual object (this performs the isMetadata, isDefault and isSupportFile check!) - RepositoryRequest repoRequest = new RepositoryRequest( ); - resourceFactory.setRepositoryRequest( repoRequest ); - try { archivaConfigurationControl.reset(); @@ -680,10 +673,6 @@ public class ArchivaDavResourceFactoryTest LEGACY_REPO, new ArchivaDavLocatorFactory() ); - // use actual object (this performs the isMetadata, isDefault and isSupportFile check!) - RepositoryRequest repoRequest = new RepositoryRequest( ); - resourceFactory.setRepositoryRequest( repoRequest ); - try { archivaConfigurationControl.reset(); -- 2.39.5