diff options
Diffstat (limited to 'archiva-modules/archiva-maven')
-rw-r--r-- | archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfo.java (renamed from archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java) | 42 | ||||
-rw-r--r-- | archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java | 12 | ||||
-rw-r--r-- | archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java (renamed from archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java) | 105 |
3 files changed, 106 insertions, 53 deletions
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 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"; + } + } + /** * <p> * 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 <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature(Class<T> clazz) throws UnsupportedFeatureException { + return null; + } + + @Override + public <T extends RepositoryFeature<T>> boolean supportsFeature(Class<T> 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 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<? extends ArtifactMappingProvider> 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 ) |