aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml16
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-maven/pom.xml20
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-maven/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java294
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-maven/src/main/resources/META-INF/spring-context.xml2
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java1
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java14
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java235
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java22
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/RepositoryContentProviderMock.java4
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-maven/src/test/resources/META-INF/spring-context.xml41
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ArchivaProxyRegistry.java5
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java27
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ProxyRegistry.java8
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml29
-rwxr-xr-xarchiva-modules/archiva-base/archiva-proxy/src/test/resources/spring-context.xml123
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java3
16 files changed, 491 insertions, 353 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml
index 908c9b5ee..d50eea78b 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml
@@ -32,7 +32,7 @@
<mockito:mock id="mockManagedRepositoryAdmin" class="org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin" />
<mockito:mock id="mockRemoteRepositoryAdmin" class="org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin" />
- <context:component-scan base-package="org.apache.archiva.repository.mock,org.apache.archiva.repository.content.maven2"/>
+ <context:component-scan base-package="org.apache.archiva.scheduler.repository,org.apache.archiva.repository.mock,org.apache.archiva.repository.content.maven2"/>
<alias name="mockRepositoryProvider" alias="mavenRepositoryProvider" />
@@ -40,4 +40,18 @@
<bean name="proxyConnectorAdmin#mock" class="org.apache.archiva.mock.MockProxyConnectorAdmin"/>
<bean name="networkProxyAdmin#mock" class="org.apache.archiva.mock.MockNetworkProxyAdmin"/>
+
+
+ <bean name="scheduler" class="org.apache.archiva.redback.components.scheduler.DefaultScheduler">
+ <property name="properties">
+ <props>
+ <prop key="org.quartz.scheduler.instanceName">scheduler1</prop>
+ <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
+ <prop key="org.quartz.threadPool.threadCount">1</prop>
+ <prop key="org.quartz.threadPool.threadPriority">4</prop>
+ <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
+ </props>
+ </property>
+ </bean>
+
</beans> \ No newline at end of file
diff --git a/archiva-modules/archiva-base/archiva-proxy-maven/pom.xml b/archiva-modules/archiva-base/archiva-proxy-maven/pom.xml
index a6d77c3fd..8feac8d28 100644
--- a/archiva-modules/archiva-base/archiva-proxy-maven/pom.xml
+++ b/archiva-modules/archiva-base/archiva-proxy-maven/pom.xml
@@ -17,7 +17,8 @@
~ specific language governing permissions and limitations
~ under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>archiva-base</artifactId>
@@ -161,4 +162,21 @@
</dependencies>
+ <build>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>src/test/repositories/**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
</project>
diff --git a/archiva-modules/archiva-base/archiva-proxy-maven/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java b/archiva-modules/archiva-base/archiva-proxy-maven/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java
index 2ab724389..b59d99835 100644
--- a/archiva-modules/archiva-base/archiva-proxy-maven/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java
+++ b/archiva-modules/archiva-base/archiva-proxy-maven/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java
@@ -58,6 +58,7 @@ import java.util.concurrent.ConcurrentMap;
public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
private static final List<RepositoryType> REPOSITORY_TYPES = new ArrayList<>();
+
static {
REPOSITORY_TYPES.add(RepositoryType.MAVEN);
}
@@ -75,20 +76,19 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
private void updateWagonProxyInfo(Map<String, NetworkProxy> proxyList) {
this.networkProxyMap.clear();
List<NetworkProxyConfiguration> networkProxies = getArchivaConfiguration().getConfiguration().getNetworkProxies();
- for ( Map.Entry<String, NetworkProxy> proxyEntry: proxyList.entrySet() )
- {
+ for (Map.Entry<String, NetworkProxy> proxyEntry : proxyList.entrySet()) {
String key = proxyEntry.getKey();
NetworkProxy networkProxyDef = proxyEntry.getValue();
ProxyInfo proxy = new ProxyInfo();
- proxy.setType( networkProxyDef.getProtocol() );
- proxy.setHost( networkProxyDef.getHost() );
- proxy.setPort( networkProxyDef.getPort() );
- proxy.setUserName( networkProxyDef.getUsername() );
- proxy.setPassword( networkProxyDef.getPassword() );
+ proxy.setType(networkProxyDef.getProtocol());
+ proxy.setHost(networkProxyDef.getHost());
+ proxy.setPort(networkProxyDef.getPort());
+ proxy.setUserName(networkProxyDef.getUsername());
+ proxy.setPassword(networkProxyDef.getPassword());
- this.networkProxyMap.put( key, proxy );
+ this.networkProxyMap.put(key, proxy);
}
}
@@ -111,98 +111,79 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @param repository
* @throws ProxyException
* @throws NotModifiedException
- *
*/
- protected void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository, Path tmpMd5,
- Path tmpSha1, Path tmpResource, String url, String remotePath, Path resource,
- Path workingDirectory, ManagedRepositoryContent repository )
- throws ProxyException, NotModifiedException
- {
+ protected void transferResources(ProxyConnector connector, RemoteRepositoryContent remoteRepository, Path tmpMd5,
+ Path tmpSha1, Path tmpResource, String url, String remotePath, Path resource,
+ Path workingDirectory, ManagedRepositoryContent repository)
+ throws ProxyException, NotModifiedException {
Wagon wagon = null;
- try
- {
+ try {
RepositoryURL repoUrl = remoteRepository.getURL();
String protocol = repoUrl.getProtocol();
NetworkProxy networkProxy = null;
String proxyId = connector.getProxyId();
- if ( StringUtils.isNotBlank( proxyId ) )
- {
+ if (StringUtils.isNotBlank(proxyId)) {
- networkProxy = getNetworkProxy( proxyId );
+ networkProxy = getNetworkProxy(proxyId);
}
- if (networkProxy==null) {
- throw new ProxyException("No network proxy configurations found for id "+proxyId);
+ WagonFactoryRequest wagonFactoryRequest = new WagonFactoryRequest("wagon#" + protocol,
+ remoteRepository.getRepository().getExtraHeaders());
+ if (networkProxy == null) {
+
+ log.warn("No network proxy with id {} found for connector {}->{}", proxyId,
+ connector.getSourceRepository().getId(), connector.getTargetRepository().getId());
+ } else {
+ wagonFactoryRequest = wagonFactoryRequest.networkProxy(networkProxy);
}
- WagonFactoryRequest wagonFactoryRequest = new WagonFactoryRequest( "wagon#" + protocol,
- remoteRepository.getRepository().getExtraHeaders() ).networkProxy(
- networkProxy );
- wagon = wagonFactory.getWagon( wagonFactoryRequest );
- if ( wagon == null )
- {
- throw new ProxyException( "Unsupported target repository protocol: " + protocol );
+ wagon = wagonFactory.getWagon(wagonFactoryRequest);
+ if (wagon == null) {
+ throw new ProxyException("Unsupported target repository protocol: " + protocol);
}
- if ( wagon == null )
- {
- throw new ProxyException( "Unsupported target repository protocol: " + protocol );
+ if (wagon == null) {
+ throw new ProxyException("Unsupported target repository protocol: " + protocol);
}
- boolean connected = connectToRepository( connector, wagon, remoteRepository );
- if ( connected )
- {
- transferArtifact( wagon, remoteRepository, remotePath, repository, resource, workingDirectory,
- tmpResource );
+ boolean connected = connectToRepository(connector, wagon, remoteRepository);
+ if (connected) {
+ transferArtifact(wagon, remoteRepository, remotePath, repository, resource, workingDirectory,
+ tmpResource);
// TODO: these should be used to validate the download based on the policies, not always downloaded
// to
// save on connections since md5 is rarely used
- transferChecksum( wagon, remoteRepository, remotePath, repository, resource, workingDirectory, ".sha1",
- tmpSha1 );
- transferChecksum( wagon, remoteRepository, remotePath, repository, resource, workingDirectory, ".md5",
- tmpMd5 );
+ transferChecksum(wagon, remoteRepository, remotePath, repository, resource, workingDirectory, ".sha1",
+ tmpSha1);
+ transferChecksum(wagon, remoteRepository, remotePath, repository, resource, workingDirectory, ".md5",
+ tmpMd5);
}
- }
- catch ( NotFoundException e )
- {
- urlFailureCache.cacheFailure( url );
+ } catch (NotFoundException e) {
+ urlFailureCache.cacheFailure(url);
throw e;
- }
- catch ( NotModifiedException e )
- {
+ } catch (NotModifiedException e) {
// Do not cache url here.
throw e;
- }
- catch ( ProxyException e )
- {
- urlFailureCache.cacheFailure( url );
+ } catch (ProxyException e) {
+ urlFailureCache.cacheFailure(url);
throw e;
- }
- catch ( WagonFactoryException e )
- {
- throw new ProxyException( e.getMessage(), e );
- }
- finally
- {
- if ( wagon != null )
- {
- try
- {
+ } catch (WagonFactoryException e) {
+ throw new ProxyException(e.getMessage(), e);
+ } finally {
+ if (wagon != null) {
+ try {
wagon.disconnect();
- }
- catch ( ConnectionException e )
- {
- log.warn( "Unable to disconnect wagon.", e );
+ } catch (ConnectionException e) {
+ log.warn("Unable to disconnect wagon.", e);
}
}
}
}
- protected void transferArtifact( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
- ManagedRepositoryContent repository, Path resource, Path tmpDirectory,
- Path destFile )
- throws ProxyException
- {
- transferSimpleFile( wagon, remoteRepository, remotePath, repository, resource, destFile );
+ protected void transferArtifact(Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
+ ManagedRepositoryContent repository, Path resource, Path tmpDirectory,
+ Path destFile)
+ throws ProxyException {
+ transferSimpleFile(wagon, remoteRepository, remotePath, repository, resource, destFile);
}
/**
@@ -219,39 +200,30 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @param ext the type of checksum to transfer (example: ".md5" or ".sha1")
* @throws ProxyException if copying the downloaded file into place did not succeed.
*/
- protected void transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
- ManagedRepositoryContent repository, Path resource, Path tmpDirectory, String ext,
- Path destFile )
- throws ProxyException
- {
+ protected void transferChecksum(Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
+ ManagedRepositoryContent repository, Path resource, Path tmpDirectory, String ext,
+ Path destFile)
+ throws ProxyException {
String url = remoteRepository.getURL().getUrl() + remotePath + ext;
// Transfer checksum does not use the policy.
- if ( urlFailureCache.hasFailedBefore( url ) )
- {
+ if (urlFailureCache.hasFailedBefore(url)) {
return;
}
- try
- {
- transferSimpleFile( wagon, remoteRepository, remotePath + ext, repository, resource, destFile );
- log.debug( "Checksum {} Downloaded: {} to move to {}", url, destFile, resource );
- }
- catch ( NotFoundException e )
- {
- urlFailureCache.cacheFailure( url );
- log.debug( "Transfer failed, checksum not found: {}", url );
+ try {
+ transferSimpleFile(wagon, remoteRepository, remotePath + ext, repository, resource, destFile);
+ log.debug("Checksum {} Downloaded: {} to move to {}", url, destFile, resource);
+ } catch (NotFoundException e) {
+ urlFailureCache.cacheFailure(url);
+ log.debug("Transfer failed, checksum not found: {}", url);
// Consume it, do not pass this on.
- }
- catch ( NotModifiedException e )
- {
- log.debug( "Transfer skipped, checksum not modified: {}", url );
+ } catch (NotModifiedException e) {
+ log.debug("Transfer skipped, checksum not modified: {}", url);
// Consume it, do not pass this on.
- }
- catch ( ProxyException e )
- {
- urlFailureCache.cacheFailure( url );
- log.warn( "Transfer failed on checksum: {} : {}", url, e.getMessage(), e );
+ } catch (ProxyException e) {
+ urlFailureCache.cacheFailure(url);
+ log.warn("Transfer failed on checksum: {} : {}", url, e.getMessage(), e);
// Critical issue, pass it on.
throw e;
}
@@ -267,67 +239,52 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @param origFile the local file to save to
* @throws ProxyException if there was a problem moving the downloaded file into place.
*/
- protected void transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
- ManagedRepositoryContent repository, Path origFile, Path destFile )
- throws ProxyException
- {
- assert ( remotePath != null );
+ protected void transferSimpleFile(Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
+ ManagedRepositoryContent repository, Path origFile, Path destFile)
+ throws ProxyException {
+ assert (remotePath != null);
// Transfer the file.
- try
- {
+ try {
boolean success = false;
- if ( !Files.exists(origFile))
- {
- log.debug( "Retrieving {} from {}", remotePath, remoteRepository.getRepository().getName() );
- wagon.get( addParameters( remotePath, remoteRepository.getRepository() ), destFile.toFile() );
+ if (!Files.exists(origFile)) {
+ log.debug("Retrieving {} from {}", remotePath, remoteRepository.getRepository().getName());
+ wagon.get(addParameters(remotePath, remoteRepository.getRepository()), destFile.toFile());
success = true;
// You wouldn't get here on failure, a WagonException would have been thrown.
- log.debug( "Downloaded successfully." );
- }
- else
- {
- log.debug( "Retrieving {} from {} if updated", remotePath, remoteRepository.getRepository().getName() );
- try
- {
- success = wagon.getIfNewer( addParameters( remotePath, remoteRepository.getRepository() ), destFile.toFile(),
- Files.getLastModifiedTime(origFile).toMillis());
+ log.debug("Downloaded successfully.");
+ } else {
+ log.debug("Retrieving {} from {} if updated", remotePath, remoteRepository.getRepository().getName());
+ try {
+ success = wagon.getIfNewer(addParameters(remotePath, remoteRepository.getRepository()), destFile.toFile(),
+ Files.getLastModifiedTime(origFile).toMillis());
+ } catch (IOException e) {
+ throw new ProxyException("Failed to the modification time of " + origFile.toAbsolutePath());
}
- catch ( IOException e )
- {
- throw new ProxyException( "Failed to the modification time of "+origFile.toAbsolutePath() );
- }
- if ( !success )
- {
+ if (!success) {
throw new NotModifiedException(
- "Not downloaded, as local file is newer than remote side: " + origFile.toAbsolutePath() );
+ "Not downloaded, as local file is newer than remote side: " + origFile.toAbsolutePath());
}
- if ( Files.exists(destFile))
- {
- log.debug( "Downloaded successfully." );
+ if (Files.exists(destFile)) {
+ log.debug("Downloaded successfully.");
}
}
- }
- catch ( ResourceDoesNotExistException e )
- {
+ } catch (ResourceDoesNotExistException e) {
throw new NotFoundException(
- "Resource [" + remoteRepository.getURL() + "/" + remotePath + "] does not exist: " + e.getMessage(),
- e );
- }
- catch ( WagonException e )
- {
+ "Resource [" + remoteRepository.getURL() + "/" + remotePath + "] does not exist: " + e.getMessage(),
+ e);
+ } catch (WagonException e) {
// TODO: shouldn't have to drill into the cause, but TransferFailedException is often not descriptive enough
String msg =
- "Download failure on resource [" + remoteRepository.getURL() + "/" + remotePath + "]:" + e.getMessage();
- if ( e.getCause() != null )
- {
+ "Download failure on resource [" + remoteRepository.getURL() + "/" + remotePath + "]:" + e.getMessage();
+ if (e.getCause() != null) {
msg += " (cause: " + e.getCause() + ")";
}
- throw new ProxyException( msg, e );
+ throw new ProxyException(msg, e);
}
}
@@ -339,30 +296,25 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @param remoteRepository the remote repository to connect to.
* @return true if the connection was successful. false if not connected.
*/
- protected boolean connectToRepository( ProxyConnector connector, Wagon wagon,
- RemoteRepositoryContent remoteRepository )
- {
+ protected boolean connectToRepository(ProxyConnector connector, Wagon wagon,
+ RemoteRepositoryContent remoteRepository) {
boolean connected = false;
final ProxyInfo networkProxy =
- connector.getProxyId() == null ? null : this.networkProxyMap.get( connector.getProxyId() );
+ connector.getProxyId() == null ? null : this.networkProxyMap.get(connector.getProxyId());
- if ( log.isDebugEnabled() )
- {
- if ( networkProxy != null )
- {
+ if (log.isDebugEnabled()) {
+ if (networkProxy != null) {
// TODO: move to proxyInfo.toString()
String msg = "Using network proxy " + networkProxy.getHost() + ":" + networkProxy.getPort()
- + " to connect to remote repository " + remoteRepository.getURL();
- if ( networkProxy.getNonProxyHosts() != null )
- {
+ + " to connect to remote repository " + remoteRepository.getURL();
+ if (networkProxy.getNonProxyHosts() != null) {
msg += "; excluding hosts: " + networkProxy.getNonProxyHosts();
}
- if ( StringUtils.isNotBlank( networkProxy.getUserName() ) )
- {
+ if (StringUtils.isNotBlank(networkProxy.getUserName())) {
msg += "; as user: " + networkProxy.getUserName();
}
- log.debug( msg );
+ log.debug(msg);
}
}
@@ -370,18 +322,17 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
String username = "";
String password = "";
RepositoryCredentials repCred = remoteRepository.getRepository().getLoginCredentials();
- if (repCred!=null && repCred instanceof PasswordCredentials) {
+ if (repCred != null && repCred instanceof PasswordCredentials) {
PasswordCredentials pwdCred = (PasswordCredentials) repCred;
username = pwdCred.getUsername();
- password = pwdCred.getPassword()==null ? "" : new String(pwdCred.getPassword());
+ password = pwdCred.getPassword() == null ? "" : new String(pwdCred.getPassword());
}
- if ( StringUtils.isNotBlank( username ) && StringUtils.isNotBlank( password ) )
- {
- log.debug( "Using username {} to connect to remote repository {}", username, remoteRepository.getURL() );
+ if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
+ log.debug("Using username {} to connect to remote repository {}", username, remoteRepository.getURL());
authInfo = new AuthenticationInfo();
- authInfo.setUserName( username );
- authInfo.setPassword( password );
+ authInfo.setUserName(username);
+ authInfo.setPassword(password);
}
// Convert seconds to milliseconds
@@ -390,19 +341,16 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
// Set timeout read and connect
// FIXME olamy having 2 config values
- wagon.setReadTimeout( (int) timeoutInMilliseconds );
- wagon.setTimeout( (int) timeoutInMilliseconds );
+ wagon.setReadTimeout((int) timeoutInMilliseconds);
+ wagon.setTimeout((int) timeoutInMilliseconds);
- try
- {
+ try {
Repository wagonRepository =
- new Repository( remoteRepository.getId(), remoteRepository.getURL().toString() );
- wagon.connect( wagonRepository, authInfo, networkProxy );
+ new Repository(remoteRepository.getId(), remoteRepository.getURL().toString());
+ wagon.connect(wagonRepository, authInfo, networkProxy);
connected = true;
- }
- catch ( ConnectionException | AuthenticationException e )
- {
- log.warn( "Could not connect to {}: {}", remoteRepository.getRepository().getName(), e.getMessage() );
+ } catch (ConnectionException | AuthenticationException e) {
+ log.warn("Could not connect to {}: {}", remoteRepository.getRepository().getName(), e.getMessage());
connected = false;
}
@@ -410,13 +358,11 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
}
- public WagonFactory getWagonFactory()
- {
+ public WagonFactory getWagonFactory() {
return wagonFactory;
}
- public void setWagonFactory( WagonFactory wagonFactory )
- {
+ public void setWagonFactory(WagonFactory wagonFactory) {
this.wagonFactory = wagonFactory;
}
diff --git a/archiva-modules/archiva-base/archiva-proxy-maven/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-proxy-maven/src/main/resources/META-INF/spring-context.xml
index 7374f3685..ac08cdbc3 100644
--- a/archiva-modules/archiva-base/archiva-proxy-maven/src/main/resources/META-INF/spring-context.xml
+++ b/archiva-modules/archiva-base/archiva-proxy-maven/src/main/resources/META-INF/spring-context.xml
@@ -28,7 +28,7 @@
default-lazy-init="true">
<context:annotation-config/>
- <context:component-scan base-package="org.apache.archiva.proxy.common"/>
+ <context:component-scan base-package="org.apache.archiva.proxy.maven"/>
<bean name="wagon#http" scope="prototype" class="org.apache.maven.wagon.providers.http.HttpWagon"/>
diff --git a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java
index 4813ddd8b..30f780c70 100644
--- a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java
+++ b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java
@@ -381,6 +381,7 @@ public abstract class AbstractProxyTestCase
ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
connectorConfig.setSourceRepoId( sourceRepoId );
connectorConfig.setTargetRepoId( targetRepoId );
+ connectorConfig.setProxyId(sourceRepoId);
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CHECKSUM, checksumPolicy );
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, releasePolicy );
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, snapshotPolicy );
diff --git a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java
index d3e207af9..c3d7c1108 100644
--- a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java
+++ b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java
@@ -125,7 +125,6 @@ public class HttpProxyTransferTest
// Make the destination dir.
Files.createDirectories(destRepoDir);
- managedDefaultRepository = createRepository(MANAGED_ID, "Default Managed Repository", repoPath, "default");
Handler handler = new AbstractHandler()
{
@@ -168,6 +167,7 @@ public class HttpProxyTransferTest
proxyConfig.setProtocol( "http" );
proxyConfig.setId( PROXY_ID );
config.getConfiguration().addNetworkProxy( proxyConfig );
+ ( (MockConfiguration) config ).triggerChange("networkProxies.networkProxy(0).host", "localhost");
// Setup target (proxied to) repository.
RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration();
@@ -179,6 +179,10 @@ public class HttpProxyTransferTest
config.getConfiguration().addRemoteRepository( repoConfig );
+ repositoryRegistry.reload();
+
+ managedDefaultRepository = createRepository(MANAGED_ID, "Default Managed Repository", repoPath, "default");
+
}
@After
@@ -192,8 +196,8 @@ public class HttpProxyTransferTest
public void testGetOverHttpProxy()
throws Exception
{
- Assertions.assertThat( System.getProperty( "http.proxyHost" ) ).isEmpty();
- Assertions.assertThat( System.getProperty( "http.proxyPort" ) ).isEmpty();
+ Assertions.assertThat( System.getProperty( "http.proxyHost", "" ) ).isEmpty();
+ Assertions.assertThat( System.getProperty( "http.proxyPort", "" ) ).isEmpty();
String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
@@ -218,8 +222,8 @@ public class HttpProxyTransferTest
String actualContents = FileUtils.readFileToString( downloadedFile.toFile(), Charset.defaultCharset() );
assertEquals( "Check file contents.", expectedContents, actualContents );
- Assertions.assertThat( System.getProperty( "http.proxyHost" ) ).isEmpty();
- Assertions.assertThat( System.getProperty( "http.proxyPort" ) ).isEmpty();
+ Assertions.assertThat( System.getProperty( "http.proxyHost" , "") ).isEmpty();
+ Assertions.assertThat( System.getProperty( "http.proxyPort" , "") ).isEmpty();
}
private void addConnector()
diff --git a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
index 2b06667a8..e185c3e73 100644
--- a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
+++ b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
@@ -19,16 +19,25 @@ package org.apache.archiva.repository.mock;
* under the License.
*/
+import org.apache.archiva.common.utils.VersionUtil;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
import org.apache.archiva.model.ArchivaArtifact;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.ProjectReference;
import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.content.PathParser;
+import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* @author Martin Stockhammer <martin_s@apache.org>
@@ -36,8 +45,17 @@ import java.util.Set;
@Service("managedRepositoryContent#mock")
public class ManagedRepositoryContentMock implements ManagedRepositoryContent
{
+ private static final String PATH_SEPARATOR = "/";
+ private static final String GROUP_SEPARATOR = ".";
+ public static final String MAVEN_METADATA = "maven-metadata.xml";
+
+
private ManagedRepository repository;
+ ManagedRepositoryContentMock(ManagedRepository repo) {
+ this.repository = repo;
+ }
+
@Override
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException
{
@@ -65,7 +83,7 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
@Override
public String getId( )
{
- return null;
+ return repository.getId();
}
@Override
@@ -122,16 +140,199 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
this.repository = repo;
}
+ private Map<ArtifactReference, String> refs = new HashMap<>();
+
@Override
public ArtifactReference toArtifactReference( String path ) throws LayoutException
{
- return null;
+ if ( StringUtils.isBlank( path ) )
+ {
+ throw new LayoutException( "Unable to convert blank path." );
+ }
+
+ ArtifactMetadata metadata = getArtifactForPath("test-repository", path);
+
+ ArtifactReference artifact = new ArtifactReference();
+ artifact.setGroupId( metadata.getNamespace() );
+ artifact.setArtifactId( metadata.getProject() );
+ artifact.setVersion( metadata.getVersion() );
+ MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
+ if ( facet != null )
+ {
+ artifact.setClassifier( facet.getClassifier() );
+ artifact.setType( facet.getType() );
+ }
+ refs.put(artifact, path);
+ return artifact;
+ }
+
+ public ArtifactMetadata getArtifactForPath( String repoId, String relativePath )
+ {
+ String[] parts = relativePath.replace( '\\', '/' ).split( "/" );
+
+ int len = parts.length;
+ if ( len < 4 )
+ {
+ throw new IllegalArgumentException(
+ "Not a valid artifact path in a Maven 2 repository, not enough directories: " + relativePath );
+ }
+
+ String id = parts[--len];
+ String baseVersion = parts[--len];
+ String artifactId = parts[--len];
+ StringBuilder groupIdBuilder = new StringBuilder();
+ for ( int i = 0; i < len - 1; i++ )
+ {
+ groupIdBuilder.append( parts[i] );
+ groupIdBuilder.append( '.' );
+ }
+ groupIdBuilder.append( parts[len - 1] );
+
+ return getArtifactFromId( repoId, groupIdBuilder.toString(), artifactId, baseVersion, id );
+ }
+
+ private static final Pattern TIMESTAMP_PATTERN = Pattern.compile( "([0-9]{8}.[0-9]{6})-([0-9]+).*" );
+
+
+
+ public ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion,
+ String id )
+ {
+ if ( !id.startsWith( projectId + "-" ) )
+ {
+ throw new IllegalArgumentException( "Not a valid artifact path in a Maven 2 repository, filename '" + id
+ + "' doesn't start with artifact ID '" + projectId + "'" );
+ }
+
+ MavenArtifactFacet facet = new MavenArtifactFacet();
+
+ int index = projectId.length() + 1;
+ String version;
+ String idSubStrFromVersion = id.substring( index );
+ if ( idSubStrFromVersion.startsWith( projectVersion ) && !VersionUtil.isUniqueSnapshot( projectVersion ) )
+ {
+ // non-snapshot versions, or non-timestamped snapshot versions
+ version = projectVersion;
+ }
+ else if ( VersionUtil.isGenericSnapshot( projectVersion ) )
+ {
+ // timestamped snapshots
+ try
+ {
+ int mainVersionLength = projectVersion.length() - 8; // 8 is length of "SNAPSHOT"
+ if ( mainVersionLength == 0 )
+ {
+ throw new IllegalArgumentException(
+ "Timestamped snapshots must contain the main version, filename was '" + id + "'" );
+ }
+
+ Matcher m = TIMESTAMP_PATTERN.matcher( idSubStrFromVersion.substring( mainVersionLength ) );
+ m.matches();
+ String timestamp = m.group( 1 );
+ String buildNumber = m.group( 2 );
+ facet.setTimestamp( timestamp );
+ facet.setBuildNumber( Integer.parseInt( buildNumber ) );
+ version = idSubStrFromVersion.substring( 0, mainVersionLength ) + timestamp + "-" + buildNumber;
+ }
+ catch ( IllegalStateException e )
+ {
+ throw new IllegalArgumentException( "Not a valid artifact path in a Maven 2 repository, filename '" + id
+ + "' doesn't contain a timestamped version matching snapshot '"
+ + projectVersion + "'", e);
+ }
+ }
+ else
+ {
+ // invalid
+ throw new IllegalArgumentException(
+ "Not a valid artifact path in a Maven 2 repository, filename '" + id + "' doesn't contain version '"
+ + projectVersion + "'" );
+ }
+
+ String classifier;
+ String ext;
+ index += version.length();
+ if ( index == id.length() )
+ {
+ // no classifier or extension
+ classifier = null;
+ ext = null;
+ }
+ else
+ {
+ char c = id.charAt( index );
+ if ( c == '-' )
+ {
+ // classifier up until '.'
+ int extIndex = id.indexOf( '.', index );
+ if ( extIndex >= 0 )
+ {
+ classifier = id.substring( index + 1, extIndex );
+ ext = id.substring( extIndex + 1 );
+ }
+ else
+ {
+ classifier = id.substring( index + 1 );
+ ext = null;
+ }
+ }
+ else if ( c == '.' )
+ {
+ // rest is the extension
+ classifier = null;
+ ext = id.substring( index + 1 );
+ }
+ else
+ {
+ throw new IllegalArgumentException( "Not a valid artifact path in a Maven 2 repository, filename '" + id
+ + "' expected classifier or extension but got '"
+ + id.substring( index ) + "'" );
+ }
+ }
+
+ ArtifactMetadata metadata = new ArtifactMetadata();
+ metadata.setId( id );
+ metadata.setNamespace( namespace );
+ metadata.setProject( projectId );
+ metadata.setRepositoryId( repoId );
+ metadata.setProjectVersion( projectVersion );
+ metadata.setVersion( version );
+
+ facet.setClassifier( classifier );
+
+ // we use our own provider here instead of directly accessing Maven's artifact handlers as it has no way
+ // to select the correct order to apply multiple extensions mappings to a preferred type
+ // TODO: this won't allow the user to decide order to apply them if there are conflicts or desired changes -
+ // perhaps the plugins could register missing entries in configuration, then we just use configuration
+ // here?
+
+ String type = null;
+
+
+ // use extension as default
+ if ( type == null )
+ {
+ type = ext;
+ }
+
+ // TODO: should we allow this instead?
+ if ( type == null )
+ {
+ throw new IllegalArgumentException(
+ "Not a valid artifact path in a Maven 2 repository, filename '" + id + "' does not have a type" );
+ }
+
+ facet.setType( type );
+ metadata.addFacet( facet );
+
+ return metadata;
}
+
@Override
public Path toFile( ArtifactReference reference )
{
- return null;
+ return Paths.get(getRepoRoot(), refs.get(reference));
}
@Override
@@ -140,16 +341,36 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
return null;
}
- @Override
+ private String formatAsDirectory( String directory )
+ {
+ return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
+ }
+
public String toMetadataPath( ProjectReference reference )
{
- return null;
+ StringBuilder path = new StringBuilder();
+
+ path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
+ path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
+ path.append( MAVEN_METADATA );
+
+ return path.toString();
}
- @Override
public String toMetadataPath( VersionedReference reference )
{
- return null;
+ StringBuilder path = new StringBuilder();
+
+ path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
+ path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
+ if ( reference.getVersion() != null )
+ {
+ // add the version only if it is present
+ path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR );
+ }
+ path.append( MAVEN_METADATA );
+
+ return path.toString();
}
@Override
diff --git a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java
index c797b5686..4ab4a5aae 100644
--- a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java
+++ b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java
@@ -19,11 +19,13 @@ package org.apache.archiva.repository.mock;
* under the License.
*/
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.RepositoryURL;
import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RemoteRepositoryContent;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
/**
@@ -34,22 +36,26 @@ public class RemoteRepositoryContentMock implements RemoteRepositoryContent
{
RemoteRepository repository;
+ RemoteRepositoryContentMock(RemoteRepository repo) {
+ this.repository = repo;
+ }
+
@Override
public String getId( )
{
- return null;
+ return repository.getId();
}
@Override
public RemoteRepository getRepository( )
{
- return null;
+ return repository;
}
@Override
public RepositoryURL getURL( )
{
- return null;
+ return new RepositoryURL(repository.getLocation().toString());
}
@Override
@@ -67,7 +73,15 @@ public class RemoteRepositoryContentMock implements RemoteRepositoryContent
@Override
public String toPath( ArtifactReference reference )
{
- return null;
+ String baseVersion;
+ if (VersionUtil.isSnapshot(reference.getVersion())) {
+ baseVersion=VersionUtil.getBaseVersion(reference.getVersion());
+ } else {
+ baseVersion=reference.getVersion();
+ }
+ return reference.getGroupId().replaceAll("\\.", "/")+"/"+reference.getArtifactId()+"/"+baseVersion+"/"
+ +reference.getArtifactId()+"-"+reference.getVersion()+(
+ StringUtils.isNotEmpty(reference.getClassifier()) ? "-"+reference.getClassifier() : "")+"."+reference.getType();
}
@Override
diff --git a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/RepositoryContentProviderMock.java b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/RepositoryContentProviderMock.java
index 3693e0725..2822ae976 100644
--- a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/RepositoryContentProviderMock.java
+++ b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/java/org/apache/archiva/repository/mock/RepositoryContentProviderMock.java
@@ -51,12 +51,12 @@ public class RepositoryContentProviderMock implements RepositoryContentProvider
@Override
public RemoteRepositoryContent createRemoteContent(RemoteRepository repository) throws RepositoryException {
- return new RemoteRepositoryContentMock();
+ return new RemoteRepositoryContentMock(repository);
}
@Override
public ManagedRepositoryContent createManagedContent(ManagedRepository repository) throws RepositoryException {
- return new ManagedRepositoryContentMock();
+ return new ManagedRepositoryContentMock(repository);
}
@Override
diff --git a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/resources/META-INF/spring-context.xml
index 7afd4a422..f900a933b 100644
--- a/archiva-modules/archiva-base/archiva-proxy-maven/src/test/resources/META-INF/spring-context.xml
+++ b/archiva-modules/archiva-base/archiva-proxy-maven/src/test/resources/META-INF/spring-context.xml
@@ -20,10 +20,49 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd"
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
default-lazy-init="true">
+ <context:component-scan base-package="org.apache.archiva.proxy.maven"/>
+
<bean name="wagon#file" scope="prototype" class="org.apache.maven.wagon.providers.file.FileWagon"/>
+ <alias name="userConfiguration#redback" alias="userConfiguration#default"/>
+
+ <!-- ***
+ JPA settings
+ *** -->
+ <bean name="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="jpaVendorAdapter" >
+ <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter" />
+ </property>
+ <property name="persistenceXmlLocation" value="classpath:META-INF/persistence-hsqldb.xml" />
+ <property name="jpaPropertyMap">
+ <map>
+ <entry key="openjpa.ConnectionURL" value="jdbc:hsqldb:mem:redback_database" />
+ <entry key="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver" />
+ <entry key="openjpa.ConnectionUserName" value="sa" />
+ <entry key="openjpa.ConnectionPassword" value="" />
+ <entry key="openjpa.Log" value="${openjpa.Log:DefaultLevel=INFO,Runtime=ERROR,Tool=ERROR,SQL=ERROR,Schema=ERROR,MetaData=ERROR}" />
+ <entry key="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
+ <entry key="openjpa.jdbc.MappingDefaults"
+ value="ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict"/>
+ </map>
+ </property>
+
+ </bean>
+
+ <bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" >
+ <property name="entityManagerFactory" ref="entityManagerFactory" />
+ </bean>
+
+ <tx:annotation-driven />
+ <!-- ***
+ End of JPA settings
+ *** -->
+
</beans> \ No newline at end of file
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ArchivaProxyRegistry.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ArchivaProxyRegistry.java
index 73316145b..6869c34bd 100644
--- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ArchivaProxyRegistry.java
+++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ArchivaProxyRegistry.java
@@ -150,6 +150,11 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
}
@Override
+ public boolean hasHandler(RepositoryType type) {
+ return this.handlerMap.containsKey(type);
+ }
+
+ @Override
public void configurationEvent(ConfigurationEvent event) {
log.debug("Config changed updating proxy list");
updateNetworkProxies();
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java
index 3f6bfe66d..5622fe5c4 100644
--- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java
+++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java
@@ -60,6 +60,7 @@ import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHandler, RegistryListener {
@@ -97,13 +98,13 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
@PostConstruct
public void initialize()
{
- initConnectorsAndNetworkProxies();
+ initConnectors();
archivaConfiguration.addChangeListener( this );
}
@SuppressWarnings("unchecked")
- private void initConnectorsAndNetworkProxies()
+ private void initConnectors()
{
ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator();
@@ -226,6 +227,21 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
return proxyConnectorRuleConfigurations;
}
+ private void updateNetworkProxies() {
+ Map<String, NetworkProxy> proxies = archivaConfiguration.getConfiguration().getNetworkProxies().stream().map(p -> {
+ NetworkProxy np = new NetworkProxy();
+ np.setId(p.getId());
+ np.setUseNtlm(p.isUseNtlm());
+ np.setUsername(p.getUsername());
+ np.setPassword(p.getPassword());
+ np.setProtocol(p.getProtocol());
+ np.setHost(p.getHost());
+ np.setPort(p.getPort());
+ return np;
+ }).collect(Collectors.toMap(p -> p.getId(), p -> p));
+ setNetworkProxies(proxies);
+ }
+
@Override
public Path fetchFromProxies(ManagedRepositoryContent repository, ArtifactReference artifact )
throws ProxyDownloadException
@@ -911,12 +927,13 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
@Override
public void afterConfigurationChange(Registry registry, String propertyName, Object propertyValue )
{
- if ( ConfigurationNames.isNetworkProxy( propertyName ) //
- || ConfigurationNames.isManagedRepositories( propertyName ) //
+ if ( ConfigurationNames.isManagedRepositories( propertyName ) //
|| ConfigurationNames.isRemoteRepositories( propertyName ) //
|| ConfigurationNames.isProxyConnector( propertyName ) ) //
{
- initConnectorsAndNetworkProxies();
+ initConnectors();
+ } else if (ConfigurationNames.isNetworkProxy(propertyName)) {
+ updateNetworkProxies();
}
}
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ProxyRegistry.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ProxyRegistry.java
index 56f3d518b..95c096a23 100644
--- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ProxyRegistry.java
+++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ProxyRegistry.java
@@ -52,6 +52,14 @@ public interface ProxyRegistry {
List<RepositoryProxyHandler> getHandler(RepositoryType type);
/**
+ * Returns true, if there are proxy handler registered for the given type.
+ *
+ * @param type The repository type
+ * @return True, if a handler is registered, otherwise false.
+ */
+ boolean hasHandler(RepositoryType type);
+
+ /**
* Returns the list of all proxy connectors.
* @return
*/
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml
deleted file mode 100644
index 537762dd0..000000000
--- a/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
- default-lazy-init="true">
-
-
-
-</beans> \ No newline at end of file
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-proxy/src/test/resources/spring-context.xml
deleted file mode 100755
index 9917806a0..000000000
--- a/archiva-modules/archiva-base/archiva-proxy/src/test/resources/spring-context.xml
+++ /dev/null
@@ -1,123 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
- default-lazy-init="true">
-
- <context:annotation-config/>
- <context:component-scan base-package="org.apache.archiva.metadata.repository,org.apache.archiva.proxy,org.apache.archiva.repository.mock"/>
- <alias name="mockRepositoryProvider" alias="mavenRepositoryProvider" />
-
- <alias name="archivaConfiguration#mock" alias="archivaConfiguration#default"/>
- <alias name="archivaConfiguration#mock" alias="archivaConfiguration"/>
- <alias name="archivaTaskScheduler#repositoryMock" alias="archivaTaskScheduler#repository" />
-
- <bean name="scheduler" class="org.apache.archiva.redback.components.scheduler.DefaultScheduler">
- <property name="properties">
- <props>
- <prop key="org.quartz.scheduler.instanceName">scheduler1</prop>
- <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
- <prop key="org.quartz.threadPool.threadCount">1</prop>
- <prop key="org.quartz.threadPool.threadPriority">4</prop>
- <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
- </props>
- </property>
- </bean>
-
- <bean name="repositoryContentFactory#mocked" class="org.apache.archiva.repository.RepositoryContentFactory">
- <property name="archivaConfiguration" ref="archivaConfiguration#mock"/>
- </bean>
-
-
-
- <bean name="repositoryProxyConnectors#test" class="org.apache.archiva.proxy.maven.MavenRepositoryProxyHandler">
- <property name="archivaConfiguration" ref="archivaConfiguration#mock"/>
- <property name="repositoryFactory" ref="repositoryContentFactory#mocked"/>
- <property name="metadataTools" ref="metadataTools#mocked"/>
- </bean>
-
- <bean name="metadataTools#default" class="org.apache.archiva.repository.metadata.MetadataTools">
- <property name="configuration" ref="archivaConfiguration#mock"/>
- </bean>
-
- <bean name="metadataTools#mocked" class="org.apache.archiva.repository.metadata.MetadataTools">
- <property name="configuration" ref="archivaConfiguration#mock"/>
- </bean>
-
-
- <bean name="cache#url-failures-cache" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache" lazy-init="true"
- destroy-method="dispose">
- <property name="diskExpiryThreadIntervalSeconds" value="600"/>
- <property name="diskPersistent" value="false"/>
- <property name="diskStorePath" value="${appserver.base}/tmp/urlcache"/>
- <property name="maxElementsInMemory" value="1000"/>
- <property name="memoryEvictionPolicy" value="LRU"/>
- <property name="name" value="url-failures-cache"/>
- <property name="overflowToDisk" value="false"/>
- <!-- 45 minutes = 2700 seconds -->
- <property name="timeToIdleSeconds" value="2700"/>
- <!-- 30 minutes = 1800 seconds -->
- <property name="timeToLiveSeconds" value="1800"/>
- </bean>
-
- <bean name="wagon#test" class="org.apache.archiva.proxy.WagonDelegate" scope="singleton"/>
- <bean name="wagon#file" scope="prototype" class="org.apache.maven.wagon.providers.file.FileWagon"/>
-
- <alias name="userConfiguration#redback" alias="userConfiguration#default"/>
-
- <!-- ***
- JPA settings
- *** -->
- <bean name="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="jpaVendorAdapter" >
- <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter" />
- </property>
- <property name="persistenceXmlLocation" value="classpath:META-INF/persistence-hsqldb.xml" />
- <property name="jpaPropertyMap">
- <map>
- <entry key="openjpa.ConnectionURL" value="jdbc:hsqldb:mem:redback_database" />
- <entry key="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver" />
- <entry key="openjpa.ConnectionUserName" value="sa" />
- <entry key="openjpa.ConnectionPassword" value="" />
- <entry key="openjpa.Log" value="${openjpa.Log:DefaultLevel=INFO,Runtime=ERROR,Tool=ERROR,SQL=ERROR,Schema=ERROR,MetaData=ERROR}" />
- <entry key="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
- <entry key="openjpa.jdbc.MappingDefaults"
- value="ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict"/>
- </map>
- </property>
-
- </bean>
-
- <bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" >
- <property name="entityManagerFactory" ref="entityManagerFactory" />
- </bean>
-
- <tx:annotation-driven />
- <!-- ***
- End of JPA settings
- *** -->
-
-</beans> \ No newline at end of file
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java
index 8312e2b61..9df3f49c6 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java
@@ -357,6 +357,7 @@ public class MetadataTools
@PostConstruct
public void initialize()
{
+ assert(configuration != null);
this.artifactPatterns = new ArrayList<>();
this.proxies = new HashMap<>();
initConfigVariables();
@@ -898,6 +899,8 @@ public class MetadataTools
private void initConfigVariables()
{
+ assert(this.artifactPatterns!=null);
+ assert(proxies!=null);
synchronized ( this.artifactPatterns )
{
this.artifactPatterns.clear();