*/ | */ | ||||
Set<ReleaseScheme> getActiveReleaseSchemes(); | Set<ReleaseScheme> 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(); | |||||
} | } |
*/ | */ | ||||
void close(); | void close(); | ||||
} | } |
* @return the adjusted (to native) path. | * @return the adjusted (to native) path. | ||||
* @throws LayoutException if the path cannot be parsed. | * @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 | * Extension method that allows to provide different features that are not supported by all |
return CAPABILITIES; | return CAPABILITIES; | ||||
} | } | ||||
@Override | |||||
public RepositoryRequestInfo getRequestInfo() { | |||||
return null; | |||||
} | |||||
} | } |
*/ | */ | ||||
import org.apache.archiva.model.ArtifactReference; | 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.content.PathParser; | ||||
import org.apache.archiva.repository.features.RepositoryFeature; | |||||
import org.apache.archiva.repository.metadata.MetadataTools; | import org.apache.archiva.repository.metadata.MetadataTools; | ||||
import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||
* RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate | * RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate | ||||
* ArtifactReference. | * ArtifactReference. | ||||
*/ | */ | ||||
public class RepositoryRequest | |||||
public class MavenRepositoryRequestInfo implements RepositoryRequestInfo | |||||
{ | { | ||||
private PathParser defaultPathParser = new DefaultPathParser(); | private PathParser defaultPathParser = new DefaultPathParser(); | ||||
public RepositoryRequest() | |||||
ManagedRepository repository; | |||||
public MavenRepositoryRequestInfo(ManagedRepository repository) | |||||
{ | { | ||||
// no op | |||||
this.repository = repository; | |||||
} | } | ||||
/** | /** | ||||
return false; | return false; | ||||
} | } | ||||
@Override | |||||
public String getLayout(String requestPath) { | |||||
if (isDefault(requestPath)) { | |||||
return "default"; | |||||
} else if (isLegacy(requestPath)) { | |||||
return "legacy"; | |||||
} else { | |||||
return "unknown"; | |||||
} | |||||
} | |||||
/** | /** | ||||
* <p> | * <p> | ||||
* Tests the path to see if it conforms to the expectations of a default layout request. | * Tests the path to see if it conforms to the expectations of a default layout request. | ||||
* @param requestedPath the path to test. | * @param requestedPath the path to test. | ||||
* @return true if the requestedPath is likely that of a default layout request. | * @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 ) ) | if ( StringUtils.isBlank( requestedPath ) ) | ||||
{ | { | ||||
* @param requestedPath the path to test. | * @param requestedPath the path to test. | ||||
* @return true if the requestedPath is likely that of a legacy layout request. | * @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 ) ) | if ( StringUtils.isBlank( requestedPath ) ) | ||||
{ | { | ||||
* Adjust the requestedPath to conform to the native layout of the provided {@link org.apache.archiva.repository.ManagedRepositoryContent}. | * 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 requestedPath the incoming requested path. | ||||
* @param repository the repository to adjust to. | |||||
* @return the adjusted (to native) path. | * @return the adjusted (to native) path. | ||||
* @throws LayoutException if the path cannot be parsed. | * @throws LayoutException if the path cannot be parsed. | ||||
*/ | */ | ||||
public String toNativePath( String requestedPath, ManagedRepositoryContent repository ) | |||||
public String toNativePath( String requestedPath) | |||||
throws LayoutException | throws LayoutException | ||||
{ | { | ||||
if ( StringUtils.isBlank( requestedPath ) ) | if ( StringUtils.isBlank( requestedPath ) ) | ||||
// Treat as an artifact reference. | // Treat as an artifact reference. | ||||
ArtifactReference ref = toArtifactReference( referencedResource ); | ArtifactReference ref = toArtifactReference( referencedResource ); | ||||
String adjustedPath = repository.toPath( ref ); | |||||
String adjustedPath = repository.getContent().toPath( ref ); | |||||
return adjustedPath + supportfile; | 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; | |||||
} | |||||
} | } |
*/ | */ | ||||
import org.apache.archiva.common.utils.PathUtil; | 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.ArtifactCleanupFeature; | ||||
import org.apache.archiva.repository.features.IndexCreationFeature; | import org.apache.archiva.repository.features.IndexCreationFeature; | ||||
import org.apache.archiva.repository.features.RepositoryFeature; | import org.apache.archiva.repository.features.RepositoryFeature; | ||||
} | } | ||||
} | } | ||||
@Override | |||||
public RepositoryRequestInfo getRequestInfo() { | |||||
return new MavenRepositoryRequestInfo(this); | |||||
} | |||||
} | } |
import org.apache.archiva.common.utils.FileUtils; | import org.apache.archiva.common.utils.FileUtils; | ||||
import org.apache.archiva.configuration.ArchivaConfiguration; | 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.model.ArtifactReference; | ||||
import org.apache.archiva.repository.LayoutException; | import org.apache.archiva.repository.LayoutException; | ||||
import org.apache.archiva.repository.ManagedRepositoryContent; | import org.apache.archiva.repository.ManagedRepositoryContent; | ||||
import javax.inject.Named; | import javax.inject.Named; | ||||
import java.nio.file.Path; | import java.nio.file.Path; | ||||
import java.nio.file.Paths; | import java.nio.file.Paths; | ||||
import java.util.List; | |||||
import static org.junit.Assert.*; | import static org.junit.Assert.*; | ||||
@RunWith( ArchivaSpringJUnit4ClassRunner.class ) | @RunWith( ArchivaSpringJUnit4ClassRunner.class ) | ||||
@ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", | @ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", | ||||
"classpath:/spring-context-repo-request-test.xml" } ) | "classpath:/spring-context-repo-request-test.xml" } ) | ||||
public class RepositoryRequestTest | |||||
public class MavenRepositoryRequestInfoTest | |||||
{ | { | ||||
@Inject | @Inject | ||||
protected ApplicationContext applicationContext; | protected ApplicationContext applicationContext; | ||||
@Inject | |||||
FileTypes fileTypes; | |||||
@Inject | @Inject | ||||
@Named( "archivaConfiguration#repo-request-test" ) | @Named( "archivaConfiguration#repo-request-test" ) | ||||
private ArchivaConfiguration archivaConfiguration; | 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 | @Before | ||||
public void setUp() | public void setUp() | ||||
throws Exception | 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 | @Test | ||||
@Test | @Test | ||||
public void testIsDefault() | 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 | @Test | ||||
public void testIsLegacy() | 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 ) | private ManagedRepositoryContent createManagedRepo( String layout ) | ||||
// Test (artifact) default to default - dual extension | // Test (artifact) default to default - dual extension | ||||
assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", | 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") ); | |||||
} | } | ||||
// Test (metadata) default to default | // Test (metadata) default to default | ||||
assertEquals( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", | 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") ); | |||||
} | } | ||||
// Test bad request path (too short) | // Test bad request path (too short) | ||||
try | 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." ); | fail( "Should have thrown an exception about a too short path." ); | ||||
} | } | ||||
catch ( LayoutException e ) | catch ( LayoutException e ) | ||||
// Test bad request path (too short) | // Test bad request path (too short) | ||||
try | try | ||||
{ | { | ||||
repoRequest.toNativePath( "", repository ); | |||||
repoRequest.toNativePath( ""); | |||||
fail( "Should have thrown an exception about an blank request." ); | fail( "Should have thrown an exception about an blank request." ); | ||||
} | } | ||||
catch ( LayoutException e ) | catch ( LayoutException e ) | ||||
// Test bad request path (too short) | // Test bad request path (too short) | ||||
try | try | ||||
{ | { | ||||
repoRequest.toNativePath( null, repository ); | |||||
repoRequest.toNativePath( null); | |||||
fail( "Should have thrown an exception about an null request." ); | fail( "Should have thrown an exception about an null request." ); | ||||
} | } | ||||
catch ( LayoutException e ) | catch ( LayoutException e ) | ||||
// Test bad request path (too short) | // Test bad request path (too short) | ||||
try | 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." ); | fail( "Should have thrown an exception about an invalid type." ); | ||||
} | } | ||||
catch ( LayoutException e ) | catch ( LayoutException e ) |
import org.apache.archiva.redback.system.SecuritySession; | import org.apache.archiva.redback.system.SecuritySession; | ||||
import org.apache.archiva.redback.users.User; | import org.apache.archiva.redback.users.User; | ||||
import org.apache.archiva.redback.users.UserManager; | 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.events.AuditListener; | ||||
import org.apache.archiva.repository.features.IndexCreationFeature; | import org.apache.archiva.repository.features.IndexCreationFeature; | ||||
import org.apache.archiva.repository.metadata.MetadataTools; | import org.apache.archiva.repository.metadata.MetadataTools; | ||||
@Inject | @Inject | ||||
private List<AuditListener> auditListeners = new ArrayList<>(); | private List<AuditListener> auditListeners = new ArrayList<>(); | ||||
@Inject | |||||
private RepositoryContentFactory repositoryFactory; | |||||
private RepositoryRequest repositoryRequest; | |||||
@Inject | @Inject | ||||
private ProxyRegistry proxyRegistry; | private ProxyRegistry proxyRegistry; | ||||
this.digestMd5 = plexusSisuBridge.lookup( Digester.class, "md5" ); | this.digestMd5 = plexusSisuBridge.lookup( Digester.class, "md5" ); | ||||
this.digestSha1 = plexusSisuBridge.lookup( Digester.class, "sha1" ); | this.digestSha1 = plexusSisuBridge.lookup( Digester.class, "sha1" ); | ||||
// TODO remove this hard dependency on maven !! | |||||
repositoryRequest = new RepositoryRequest( ); | |||||
} | } | ||||
@PostConstruct | @PostConstruct | ||||
List<String> resourcesInAbsolutePath = new ArrayList<>(); | List<String> resourcesInAbsolutePath = new ArrayList<>(); | ||||
boolean readMethod = WebdavMethodUtil.isReadMethod( request.getMethod() ); | boolean readMethod = WebdavMethodUtil.isReadMethod( request.getMethod() ); | ||||
RepositoryRequestInfo repositoryRequestInfo = null; | |||||
DavResource resource; | DavResource resource; | ||||
if ( repoGroupConfig != null ) | if ( repoGroupConfig != null ) | ||||
{ | { | ||||
List<String> repositories = new ArrayList<>( repoGroupConfig.getRepositories() ); | List<String> repositories = new ArrayList<>( repoGroupConfig.getRepositories() ); | ||||
resource = processRepositoryGroup( request, archivaLocator, repositories, activePrincipal, | resource = processRepositoryGroup( request, archivaLocator, repositories, activePrincipal, | ||||
resourcesInAbsolutePath, repoGroupConfig ); | resourcesInAbsolutePath, repoGroupConfig ); | ||||
for (String repoId: repositories ) { | |||||
ManagedRepository repo = repositoryRegistry.getManagedRepository(repoId); | |||||
if (repo!=null) { | |||||
repositoryRequestInfo = repo.getRequestInfo(); | |||||
break; | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
else | else | ||||
resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent, | resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent, | ||||
repo); | repo); | ||||
repositoryRequestInfo = repo.getRequestInfo(); | |||||
String logicalResource = getLogicalResource( archivaLocator, null, false ); | String logicalResource = getLogicalResource( archivaLocator, null, false ); | ||||
resourcesInAbsolutePath.add( | resourcesInAbsolutePath.add( | ||||
Paths.get( managedRepositoryContent.getRepoRoot(), logicalResource ).toAbsolutePath().toString() ); | Paths.get( managedRepositoryContent.getRepoRoot(), logicalResource ).toAbsolutePath().toString() ); | ||||
// MRM-872 : merge all available metadata | // MRM-872 : merge all available metadata | ||||
// merge metadata only when requested via the repo group | // merge metadata only when requested via the repo group | ||||
if ( ( repositoryRequest.isMetadata( requestedResource ) || repositoryRequest.isMetadataSupportFile( | |||||
if ( ( repositoryRequestInfo.isMetadata( requestedResource ) || repositoryRequestInfo.isMetadataSupportFile( | |||||
requestedResource ) ) && repoGroupConfig != null ) | requestedResource ) ) && repoGroupConfig != null ) | ||||
{ | { | ||||
// this should only be at the project level not version level! | // this should only be at the project level not version level! | ||||
filePath = filePath + "/maven-metadata-" + repoGroupConfig.getId() + ".xml"; | filePath = filePath + "/maven-metadata-" + repoGroupConfig.getId() + ".xml"; | ||||
// for MRM-872 handle checksums of the merged metadata files | // for MRM-872 handle checksums of the merged metadata files | ||||
if ( repositoryRequest.isSupportFile( requestedResource ) ) | |||||
if ( repositoryRequestInfo.isSupportFile( requestedResource ) ) | |||||
{ | { | ||||
Path metadataChecksum = | Path metadataChecksum = | ||||
Paths.get( filePath + "." + StringUtils.substringAfterLast( requestedResource, "." ) ); | Paths.get( filePath + "." + StringUtils.substringAfterLast( requestedResource, "." ) ); | ||||
{ | { | ||||
// Perform an adjustment of the resource to the managed | // Perform an adjustment of the resource to the managed | ||||
// repository expected path. | // repository expected path. | ||||
String localResourcePath = | |||||
repositoryRequest.toNativePath( logicalResource.getPath(), managedRepositoryContent ); | |||||
String localResourcePath = managedRepository.getRequestInfo().toNativePath( logicalResource.getPath() ); | |||||
resourceFile = Paths.get( managedRepositoryContent.getRepoRoot(), localResourcePath ); | resourceFile = Paths.get( managedRepositoryContent.getRepoRoot(), localResourcePath ); | ||||
resource = | resource = | ||||
new ArchivaDavResource( resourceFile.toAbsolutePath().toString(), logicalResource.getPath(), | new ArchivaDavResource( resourceFile.toAbsolutePath().toString(), logicalResource.getPath(), | ||||
if ( request.getMethod().equals( HTTP_PUT_METHOD ) ) | if ( request.getMethod().equals( HTTP_PUT_METHOD ) ) | ||||
{ | { | ||||
String resourcePath = logicalResource.getPath(); | String resourcePath = logicalResource.getPath(); | ||||
RepositoryRequestInfo repositoryRequestInfo = managedRepository.getRequestInfo(); | |||||
// check if target repo is enabled for releases | // check if target repo is enabled for releases | ||||
// we suppose that release-artifacts can be deployed only to repos 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; | ArtifactReference artifact = null; | ||||
try | try | ||||
if (!proxyRegistry.hasHandler(managedRepository.getRepository().getType())) { | if (!proxyRegistry.hasHandler(managedRepository.getRepository().getType())) { | ||||
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No proxy handler found for repository type "+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); | RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(managedRepository.getRepository().getType()).get(0); | ||||
if ( repositoryRequest.isSupportFile( path ) ) | |||||
if ( repositoryRequestInfo.isSupportFile( path ) ) | |||||
{ | { | ||||
Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path ); | Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path ); | ||||
} | } | ||||
// Is it a Metadata resource? | // 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(); | return proxyHandler.fetchMetadataFromProxies( managedRepository, path ).isModified(); | ||||
} | } | ||||
// Is it an Archetype Catalog? | // 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. | // FIXME we must implement a merge of remote archetype catalog from remote servers. | ||||
Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path ); | Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path ); | ||||
try | try | ||||
{ | { | ||||
// Get the artifact reference in a layout neutral way. | // Get the artifact reference in a layout neutral way. | ||||
ArtifactReference artifact = repositoryRequest.toArtifactReference( path ); | |||||
ArtifactReference artifact = repositoryRequestInfo.toArtifactReference( path ); | |||||
if ( artifact != null ) | if ( artifact != null ) | ||||
{ | { | ||||
this.archivaConfiguration = archivaConfiguration; | this.archivaConfiguration = archivaConfiguration; | ||||
} | } | ||||
public void setRepositoryFactory( RepositoryContentFactory repositoryFactory ) | |||||
{ | |||||
this.repositoryFactory = repositoryFactory; | |||||
} | |||||
public void setRepositoryRequest( RepositoryRequest repositoryRequest ) | |||||
{ | |||||
this.repositoryRequest = repositoryRequest; | |||||
} | |||||
public RemoteRepositoryAdmin getRemoteRepositoryAdmin() | public RemoteRepositoryAdmin getRemoteRepositoryAdmin() | ||||
{ | { | ||||
return remoteRepositoryAdmin; | return remoteRepositoryAdmin; |
import org.apache.archiva.repository.RepositoryRegistry; | import org.apache.archiva.repository.RepositoryRegistry; | ||||
import org.apache.archiva.repository.RepositoryType; | import org.apache.archiva.repository.RepositoryType; | ||||
import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent; | 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.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; | ||||
import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||
import org.apache.jackrabbit.webdav.DavException; | import org.apache.jackrabbit.webdav.DavException; | ||||
private IMocksControl repoRequestControl; | private IMocksControl repoRequestControl; | ||||
private RepositoryRequest repoRequest; | |||||
private MavenRepositoryRequestInfo repoRequest; | |||||
private IMocksControl responseControl; | private IMocksControl responseControl; | ||||
repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class ); | repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class ); | ||||
repoRequestControl = createControl(); | repoRequestControl = createControl(); | ||||
repoRequest = repoRequestControl.createMock( RepositoryRequest.class ); | |||||
repoRequest = repoRequestControl.createMock( MavenRepositoryRequestInfo.class ); | |||||
resourceFactory = | resourceFactory = | ||||
new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration ); | new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration ); | ||||
resourceFactory.setArchivaConfiguration( archivaConfiguration ); | resourceFactory.setArchivaConfiguration( archivaConfiguration ); | ||||
resourceFactory.setRepositoryFactory( repoFactory ); | |||||
resourceFactory.setRepositoryRequest( repoRequest ); | |||||
proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear(); | proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear(); | ||||
proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this)); | proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this)); | ||||
resourceFactory.setProxyRegistry(proxyRegistry); | resourceFactory.setProxyRegistry(proxyRegistry); | ||||
expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true ); | expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true ); | ||||
expect( | 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( | expect( repoRequest.toArtifactReference( | ||||
"org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ); | "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(), | Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), | ||||
"target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString()); | "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString()); | ||||
expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ); | expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ); | ||||
expect( | 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( | expect( repoRequest.toArtifactReference( | ||||
"org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ); | "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(), | Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), | ||||
"target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString()); | "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString()); | ||||
expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 ); | expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 ); | ||||
expect( | 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( | expect( repoRequest.toArtifactReference( | ||||
"org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 ); | "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(), | Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), | ||||
"target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() ); | "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(), | .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()); | "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString()); | ||||
ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO ); | ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO ); | ||||
// use actual object (this performs the isMetadata, isDefault and isSupportFile check!) | // 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 | try | ||||
{ | { | ||||
ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO ); | ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO ); | ||||
// use actual object (this performs the isMetadata, isDefault and isSupportFile check!) | |||||
RepositoryRequest repoRequest = new RepositoryRequest( ); | |||||
resourceFactory.setRepositoryRequest( repoRequest ); | |||||
try | try | ||||
{ | { | ||||
archivaConfigurationControl.reset(); | archivaConfigurationControl.reset(); | ||||
LEGACY_REPO, new ArchivaDavLocatorFactory() ); | LEGACY_REPO, new ArchivaDavLocatorFactory() ); | ||||
// use actual object (this performs the isMetadata, isDefault and isSupportFile check!) | |||||
RepositoryRequest repoRequest = new RepositoryRequest( ); | |||||
resourceFactory.setRepositoryRequest( repoRequest ); | |||||
try | try | ||||
{ | { | ||||
archivaConfigurationControl.reset(); | archivaConfigurationControl.reset(); |