git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1403507 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.4-M4
package org.apache.archiva.proxy; | |||||
package org.apache.archiva.proxy.model; | |||||
/* | /* | ||||
* Licensed to the Apache Software Foundation (ASF) under one | * Licensed to the Apache Software Foundation (ASF) under one |
<groupId>org.apache.archiva</groupId> | <groupId>org.apache.archiva</groupId> | ||||
<artifactId>archiva-scheduler-repository-api</artifactId> | <artifactId>archiva-scheduler-repository-api</artifactId> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>org.apache.archiva</groupId> | |||||
<artifactId>maven2-repository</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.apache.archiva</groupId> | |||||
<artifactId>archiva-proxy-api</artifactId> | |||||
</dependency> | |||||
<dependency> | <dependency> | ||||
<groupId>org.apache.archiva</groupId> | <groupId>org.apache.archiva</groupId> | ||||
<artifactId>archiva-proxy-common</artifactId> | <artifactId>archiva-proxy-common</artifactId> |
import org.apache.archiva.proxy.common.WagonFactory; | import org.apache.archiva.proxy.common.WagonFactory; | ||||
import org.apache.archiva.proxy.common.WagonFactoryException; | import org.apache.archiva.proxy.common.WagonFactoryException; | ||||
import org.apache.archiva.proxy.common.WagonFactoryRequest; | import org.apache.archiva.proxy.common.WagonFactoryRequest; | ||||
import org.apache.archiva.proxy.model.ProxyConnector; | |||||
import org.apache.archiva.proxy.model.RepositoryProxyConnectors; | |||||
import org.apache.archiva.redback.components.registry.Registry; | import org.apache.archiva.redback.components.registry.Registry; | ||||
import org.apache.archiva.redback.components.registry.RegistryListener; | import org.apache.archiva.redback.components.registry.RegistryListener; | ||||
import org.apache.archiva.redback.components.taskqueue.TaskQueueException; | import org.apache.archiva.redback.components.taskqueue.TaskQueueException; |
* under the License. | * under the License. | ||||
*/ | */ | ||||
import org.apache.archiva.proxy.model.ProxyConnector; | |||||
import java.util.Comparator; | import java.util.Comparator; | ||||
/** | /** |
package org.apache.archiva.proxy; | |||||
/* | |||||
* Licensed to the Apache Software Foundation (ASF) under one | |||||
* or more contributor license agreements. See the NOTICE file | |||||
* distributed with this work for additional information | |||||
* regarding copyright ownership. The ASF licenses this file | |||||
* to you under the Apache License, Version 2.0 (the | |||||
* "License"); you may not use this file except in compliance | |||||
* with the License. You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, | |||||
* software distributed under the License is distributed on an | |||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||||
* KIND, either express or implied. See the License for the | |||||
* specific language governing permissions and limitations | |||||
* under the License. | |||||
*/ | |||||
import org.apache.archiva.model.ArtifactReference; | |||||
import org.apache.archiva.policies.ProxyDownloadException; | |||||
import org.apache.archiva.repository.ManagedRepositoryContent; | |||||
import java.io.File; | |||||
import java.util.List; | |||||
/** | |||||
* Handler for potential repository proxy connectors. | |||||
* | |||||
* | |||||
*/ | |||||
public interface RepositoryProxyConnectors | |||||
{ | |||||
/** | |||||
* Performs the artifact fetch operation against the target repositories | |||||
* of the provided source repository. | |||||
* | |||||
* If the artifact is found, it is downloaded and placed into the source repository | |||||
* filesystem. | |||||
* | |||||
* @param repository the source repository to use. (must be a managed repository) | |||||
* @param artifact the artifact to fetch. | |||||
* @return the file that was obtained, or null if no content was obtained | |||||
* @throws ProxyDownloadException if there was a problem fetching the content from the target repositories. | |||||
*/ | |||||
public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) | |||||
throws ProxyDownloadException; | |||||
/** | |||||
* Performs the metadata fetch operation against the target repositories | |||||
* of the provided source repository. | |||||
* | |||||
* If the metadata is found, it is downloaded and placed into the source repository | |||||
* filesystem. | |||||
* | |||||
* @param repository the source repository to use. (must be a managed repository) | |||||
* @param metadata the metadata to fetch. | |||||
* @return the file that was obtained, or null if no content was obtained | |||||
*/ | |||||
public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath ); | |||||
/** | |||||
* Performs the fetch operation against the target repositories | |||||
* of the provided source repository. | |||||
* | |||||
* @param repository the source repository to use. (must be a managed repository) | |||||
* @param path the path of the resource to fetch | |||||
* @return the file that was obtained, or null if no content was obtained | |||||
*/ | |||||
public File fetchFromProxies( ManagedRepositoryContent managedRepository, String path ); | |||||
/** | |||||
* Get the List of {@link ProxyConnector} objects of the source repository. | |||||
* | |||||
* @param repository the source repository to look for. | |||||
* @return the List of {@link ProxyConnector} objects. | |||||
*/ | |||||
public List<ProxyConnector> getProxyConnectors( ManagedRepositoryContent repository ); | |||||
/** | |||||
* Tests to see if the provided repository is a source repository for | |||||
* any {@link ProxyConnector} objects. | |||||
* | |||||
* @param repository the source repository to look for. | |||||
* @return true if there are proxy connectors that use the provided | |||||
* repository as a source repository. | |||||
*/ | |||||
public boolean hasProxies( ManagedRepositoryContent repository ); | |||||
} |
import org.apache.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy; | import org.apache.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy; | ||||
import org.apache.archiva.policies.ReleasesPolicy; | import org.apache.archiva.policies.ReleasesPolicy; | ||||
import org.apache.archiva.policies.SnapshotsPolicy; | import org.apache.archiva.policies.SnapshotsPolicy; | ||||
import org.apache.archiva.proxy.model.RepositoryProxyConnectors; | |||||
import org.apache.archiva.repository.ManagedRepositoryContent; | import org.apache.archiva.repository.ManagedRepositoryContent; | ||||
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; | import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; | ||||
import org.apache.commons.io.FileUtils; | import org.apache.commons.io.FileUtils; |
import org.apache.archiva.admin.model.beans.ManagedRepository; | import org.apache.archiva.admin.model.beans.ManagedRepository; | ||||
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; | import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; | ||||
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; | import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; | ||||
import org.apache.archiva.proxy.model.RepositoryProxyConnectors; | |||||
import org.apache.commons.io.FileUtils; | import org.apache.commons.io.FileUtils; | ||||
import org.apache.archiva.configuration.ArchivaConfiguration; | import org.apache.archiva.configuration.ArchivaConfiguration; | ||||
import org.apache.archiva.configuration.NetworkProxyConfiguration; | import org.apache.archiva.configuration.NetworkProxyConfiguration; |
<module>archiva-consumers</module> | <module>archiva-consumers</module> | ||||
<module>archiva-repository-layer</module> | <module>archiva-repository-layer</module> | ||||
<module>archiva-xml-tools</module> | <module>archiva-xml-tools</module> | ||||
<module>archiva-proxy-api</module> | |||||
<module>archiva-proxy-common</module> | <module>archiva-proxy-common</module> | ||||
<module>archiva-proxy</module> | <module>archiva-proxy</module> | ||||
<module>archiva-transaction</module> | <module>archiva-transaction</module> |
import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMetadataVersionComparator; | import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMetadataVersionComparator; | ||||
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; | import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; | ||||
import org.apache.archiva.model.ArchivaArtifact; | import org.apache.archiva.model.ArchivaArtifact; | ||||
import org.apache.archiva.proxy.RepositoryProxyConnectors; | |||||
import org.apache.archiva.proxy.model.RepositoryProxyConnectors; | |||||
import org.apache.archiva.repository.ManagedRepositoryContent; | import org.apache.archiva.repository.ManagedRepositoryContent; | ||||
import org.apache.archiva.repository.RepositoryContentFactory; | import org.apache.archiva.repository.RepositoryContentFactory; | ||||
import org.apache.archiva.repository.RepositoryException; | import org.apache.archiva.repository.RepositoryException; |
import org.apache.archiva.model.ArchivaRepositoryMetadata; | import org.apache.archiva.model.ArchivaRepositoryMetadata; | ||||
import org.apache.archiva.model.ArtifactReference; | import org.apache.archiva.model.ArtifactReference; | ||||
import org.apache.archiva.policies.ProxyDownloadException; | import org.apache.archiva.policies.ProxyDownloadException; | ||||
import org.apache.archiva.proxy.RepositoryProxyConnectors; | |||||
import org.apache.archiva.proxy.model.RepositoryProxyConnectors; | |||||
import org.apache.archiva.redback.authentication.AuthenticationException; | import org.apache.archiva.redback.authentication.AuthenticationException; | ||||
import org.apache.archiva.redback.authentication.AuthenticationResult; | import org.apache.archiva.redback.authentication.AuthenticationResult; | ||||
import org.apache.archiva.redback.authorization.AuthorizationException; | import org.apache.archiva.redback.authorization.AuthorizationException; |
<groupId>org.apache.archiva</groupId> | <groupId>org.apache.archiva</groupId> | ||||
<artifactId>archiva-maven2-metadata</artifactId> | <artifactId>archiva-maven2-metadata</artifactId> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<!--dependency> | |||||
<groupId>org.apache.archiva</groupId> | <groupId>org.apache.archiva</groupId> | ||||
<artifactId>archiva-proxy</artifactId> | <artifactId>archiva-proxy</artifactId> | ||||
</dependency> | |||||
</dependency--> | |||||
<dependency> | <dependency> | ||||
<groupId>org.apache.archiva</groupId> | <groupId>org.apache.archiva</groupId> | ||||
<artifactId>problem-reports</artifactId> | <artifactId>problem-reports</artifactId> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>org.apache.archiva</groupId> | |||||
<artifactId>archiva-proxy-api</artifactId> | |||||
</dependency> | |||||
<dependency> | <dependency> | ||||
<groupId>org.apache.archiva</groupId> | <groupId>org.apache.archiva</groupId> | ||||
<artifactId>archiva-proxy-common</artifactId> | <artifactId>archiva-proxy-common</artifactId> |
import org.apache.archiva.model.ArtifactReference; | import org.apache.archiva.model.ArtifactReference; | ||||
import org.apache.archiva.model.SnapshotVersion; | import org.apache.archiva.model.SnapshotVersion; | ||||
import org.apache.archiva.policies.ProxyDownloadException; | import org.apache.archiva.policies.ProxyDownloadException; | ||||
import org.apache.archiva.proxy.RepositoryProxyConnectors; | |||||
import org.apache.archiva.proxy.common.WagonFactory; | import org.apache.archiva.proxy.common.WagonFactory; | ||||
import org.apache.archiva.proxy.model.RepositoryProxyConnectors; | |||||
import org.apache.archiva.reports.RepositoryProblemFacet; | import org.apache.archiva.reports.RepositoryProblemFacet; | ||||
import org.apache.archiva.repository.ManagedRepositoryContent; | import org.apache.archiva.repository.ManagedRepositoryContent; | ||||
import org.apache.archiva.xml.XMLException; | import org.apache.archiva.xml.XMLException; |
import static org.junit.Assert.*; | import static org.junit.Assert.*; | ||||
/** | /** | ||||
* AbstractDefaultRepositoryContentTestCase | |||||
* | |||||
* | |||||
* AbstractDefaultRepositoryContentTestCase | |||||
*/ | */ | ||||
@RunWith ( ArchivaSpringJUnit4ClassRunner.class ) | @RunWith ( ArchivaSpringJUnit4ClassRunner.class ) | ||||
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) | @ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) | ||||
public abstract class AbstractDefaultRepositoryContentTestCase | public abstract class AbstractDefaultRepositoryContentTestCase | ||||
extends AbstractRepositoryLayerTestCase | |||||
{ | { | ||||
@Test | @Test | ||||
public void testBadPathMissingType() | public void testBadPathMissingType() | ||||
@Test | @Test | ||||
public void testBadPathReleaseInSnapshotDir() | public void testBadPathReleaseInSnapshotDir() | ||||
{ | { | ||||
assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" ); | |||||
assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", | |||||
"non snapshot artifact inside of a snapshot dir" ); | |||||
} | } | ||||
@Test | @Test | ||||
"wrong artifact id" ); | "wrong artifact id" ); | ||||
} | } | ||||
/** | |||||
/** | |||||
* [MRM-432] Oddball version spec. | * [MRM-432] Oddball version spec. | ||||
* Example of an oddball / unusual version spec. | * Example of an oddball / unusual version spec. | ||||
* | |||||
* @throws org.apache.archiva.repository.layout.LayoutException | * @throws org.apache.archiva.repository.layout.LayoutException | ||||
* | |||||
*/ | */ | ||||
@Test | @Test | ||||
public void testGoodButOddVersionSpecGanymedSsh2() | public void testGoodButOddVersionSpecGanymedSsh2() | ||||
/** | /** | ||||
* [MRM-432] Oddball version spec. | * [MRM-432] Oddball version spec. | ||||
* Example of an oddball / unusual version spec. | * Example of an oddball / unusual version spec. | ||||
* | |||||
* @throws org.apache.archiva.repository.layout.LayoutException | * @throws org.apache.archiva.repository.layout.LayoutException | ||||
* | |||||
*/ | */ | ||||
@Test | @Test | ||||
public void testGoodButOddVersionSpecJavaxComm() | public void testGoodButOddVersionSpecJavaxComm() | ||||
/** | /** | ||||
* [MRM-432] Oddball version spec. | * [MRM-432] Oddball version spec. | ||||
* Example of an oddball / unusual version spec. | * Example of an oddball / unusual version spec. | ||||
* | |||||
* @throws org.apache.archiva.repository.layout.LayoutException | * @throws org.apache.archiva.repository.layout.LayoutException | ||||
* | |||||
*/ | */ | ||||
@Test | @Test | ||||
public void testGoodButOddVersionSpecJavaxPersistence() | public void testGoodButOddVersionSpecJavaxPersistence() | ||||
String version = "0.3"; | String version = "0.3"; | ||||
String classifier = null; | String classifier = null; | ||||
String type = "pom"; | String type = "pom"; | ||||
String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom"; | |||||
String path = | |||||
"com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom"; | |||||
assertLayout( path, groupId, artifactId, version, classifier, type ); | assertLayout( path, groupId, artifactId, version, classifier, type ); | ||||
} | } | ||||
/** | /** | ||||
* Test the classifier, and java-source type spec. | * Test the classifier, and java-source type spec. | ||||
* | |||||
* @throws org.apache.archiva.repository.layout.LayoutException | * @throws org.apache.archiva.repository.layout.LayoutException | ||||
* | |||||
*/ | */ | ||||
@Test | @Test | ||||
public void testGoodFooLibSources() | public void testGoodFooLibSources() | ||||
/** | /** | ||||
* A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. | * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. | ||||
* | |||||
* @throws org.apache.archiva.repository.layout.LayoutException | * @throws org.apache.archiva.repository.layout.LayoutException | ||||
* | |||||
*/ | */ | ||||
@Test | @Test | ||||
public void testGoodSnapshotMavenTest() | public void testGoodSnapshotMavenTest() | ||||
String version = "3.1-beta-1-20050831.101112-42"; | String version = "3.1-beta-1-20050831.101112-42"; | ||||
String classifier = null; | String classifier = null; | ||||
String type = "jar"; | String type = "jar"; | ||||
String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar"; | |||||
String path = | |||||
"org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar"; | |||||
assertLayout( path, groupId, artifactId, version, classifier, type ); | assertLayout( path, groupId, artifactId, version, classifier, type ); | ||||
} | } | ||||
assertLayout( path, groupId, artifactId, version, classifier, type ); | assertLayout( path, groupId, artifactId, version, classifier, type ); | ||||
} | } | ||||
/** | /** | ||||
* [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. | * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. | ||||
* Example uses "test" in artifact Id, which is also part of the versionKeyword list. | * Example uses "test" in artifact Id, which is also part of the versionKeyword list. | ||||
private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId, | private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId, | ||||
String version, String classifier, String type ) | String version, String classifier, String type ) | ||||
{ | { | ||||
String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier | |||||
+ ":" + type; | |||||
String expectedId = | |||||
"ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type; | |||||
assertNotNull( expectedId + " - Should not be null.", actualReference ); | assertNotNull( expectedId + " - Should not be null.", actualReference ); | ||||
try | try | ||||
{ | { | ||||
toArtifactReference( path ); | toArtifactReference( path ); | ||||
fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); | |||||
fail( | |||||
"Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); | |||||
} | } | ||||
catch ( LayoutException e ) | catch ( LayoutException e ) | ||||
{ | { | ||||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) ); | assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) ); | ||||
} | } | ||||
private ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier, | |||||
protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier, | |||||
String type ) | String type ) | ||||
{ | { | ||||
ArtifactReference artifact = new ArtifactReference(); | ArtifactReference artifact = new ArtifactReference(); |
/** | /** | ||||
* ManagedDefaultRepositoryContentTest | * ManagedDefaultRepositoryContentTest | ||||
* | |||||
* | |||||
*/ | */ | ||||
@RunWith ( ArchivaSpringJUnit4ClassRunner.class ) | @RunWith ( ArchivaSpringJUnit4ClassRunner.class ) | ||||
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) | @ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) | ||||
public class ManagedDefaultRepositoryContentTest | public class ManagedDefaultRepositoryContentTest | ||||
extends AbstractRepositoryLayerTestCase | |||||
extends AbstractDefaultRepositoryContentTestCase | |||||
{ | { | ||||
@Inject | @Inject | ||||
@Named( value = "managedRepositoryContent#default" ) | |||||
@Named ( value = "managedRepositoryContent#default" ) | |||||
private ManagedRepositoryContent repoContent; | private ManagedRepositoryContent repoContent; | ||||
@Inject | @Inject | ||||
FileTypes fileTypes; | FileTypes fileTypes; | ||||
@Inject @Named(value = "archivaConfiguration#default") | |||||
@Inject | |||||
@Named ( value = "archivaConfiguration#default" ) | |||||
ArchivaConfiguration archivaConfiguration; | ArchivaConfiguration archivaConfiguration; | ||||
@Before | @Before | ||||
ManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", repoDir ); | ManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", repoDir ); | ||||
FileType fileType = | |||||
(FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); | |||||
FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); | |||||
fileType.addPattern( "**/*.xml" ); | fileType.addPattern( "**/*.xml" ); | ||||
assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); | assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); | ||||
@RunWith ( ArchivaSpringJUnit4ClassRunner.class ) | @RunWith ( ArchivaSpringJUnit4ClassRunner.class ) | ||||
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) | @ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) | ||||
public class ManagedLegacyRepositoryContentTest | public class ManagedLegacyRepositoryContentTest | ||||
extends AbstractRepositoryLayerTestCase | |||||
extends AbstractDefaultRepositoryContentTestCase | |||||
{ | { | ||||
@Inject | @Inject | ||||
@Named( value = "managedRepositoryContent#legacy" ) | @Named( value = "managedRepositoryContent#legacy" ) |
<artifactId>archiva-policies</artifactId> | <artifactId>archiva-policies</artifactId> | ||||
<version>${project.version}</version> | <version>${project.version}</version> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>org.apache.archiva</groupId> | |||||
<artifactId>archiva-proxy-api</artifactId> | |||||
<version>${project.version}</version> | |||||
</dependency> | |||||
<dependency> | <dependency> | ||||
<groupId>org.apache.archiva</groupId> | <groupId>org.apache.archiva</groupId> | ||||
<artifactId>archiva-proxy</artifactId> | <artifactId>archiva-proxy</artifactId> |