aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2017-10-07 19:56:00 +0200
committerMartin Stockhammer <martin_s@apache.org>2017-10-07 19:56:00 +0200
commit267b6a702be7b3760607482dcc9d5af40f8e1609 (patch)
tree405eb9ce4fd387721100e1fe6bde6cf09dee8f05 /archiva-modules
parenta34090cf930dd36b68ef0380605db5550d517cce (diff)
downloadarchiva-267b6a702be7b3760607482dcc9d5af40f8e1609.tar.gz
archiva-267b6a702be7b3760607482dcc9d5af40f8e1609.zip
Repository changes and implementation of provider
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java3
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java27
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableManagedRepository.java6
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRemoteRepository.java15
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRepository.java1
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/PasswordCredentials.java49
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RemoteRepository.java11
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryCredentials.java4
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java38
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/RemoteIndexFeature.java37
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/StagingRepositoryFeature.java2
-rw-r--r--archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java12
-rw-r--r--archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java16
-rw-r--r--archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java112
14 files changed, 251 insertions, 82 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java
index a198b2828..d0edb72f5 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java
@@ -46,7 +46,8 @@ public abstract class AbstractManagedRepository extends AbstractRepository imple
return content;
}
- protected void setContent(ManagedRepositoryContent content) {
+ @Override
+ public void setContent(ManagedRepositoryContent content) {
this.content = content;
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java
index 73aeb8ab5..4d2842342 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java
@@ -40,7 +40,6 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem
private Map<String,String> extraHeaders = new HashMap<>( );
private Map<String,String> uExtraHeaders = Collections.unmodifiableMap( extraHeaders );
private Duration timeout;
- private Duration downloadTimeout;
private String proxyId;
private RemoteRepositoryContent content;
@@ -99,24 +98,13 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem
}
@Override
- public void setDownloadTimeout( Duration duration )
- {
- this.downloadTimeout=duration;
- }
-
- @Override
- public void setProxyId( String proxyId )
- {
- this.proxyId = proxyId;
- }
-
- @Override
public RemoteRepositoryContent getContent( )
{
return content;
}
- protected void setContent(RemoteRepositoryContent content) {
+ @Override
+ public void setContent(RemoteRepositoryContent content) {
this.content = content;
}
@@ -150,15 +138,4 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem
return timeout;
}
- @Override
- public Duration getDownloadTimeout( )
- {
- return downloadTimeout;
- }
-
- @Override
- public String getProxyId( )
- {
- return proxyId;
- }
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableManagedRepository.java
index 4d49a21fa..1e40805ee 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableManagedRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableManagedRepository.java
@@ -29,4 +29,10 @@ public interface EditableManagedRepository extends EditableRepository, ManagedRe
* @param blocksRedeployment The flag for blocking redeployments.
*/
void setBlocksRedeployment(boolean blocksRedeployment);
+
+ /**
+ * Sets the content
+ * @param content
+ */
+ void setContent(ManagedRepositoryContent content);
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRemoteRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRemoteRepository.java
index 0449149d3..f8a054f21 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRemoteRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRemoteRepository.java
@@ -75,17 +75,8 @@ public interface EditableRemoteRepository extends EditableRepository, RemoteRepo
void setTimeout(Duration duration);
/**
- * Sets the maximum duration for downloads from the remote repository.
- *
- * @param duration The amount of time after that a download is aborted.
- */
- void setDownloadTimeout(Duration duration);
-
- /**
- * Sets the proxy id that is used for requests to the remote repository.
- *
- * @param proxyId The id of the proxy.
+ * Sets the content.
+ * @param content
*/
- void setProxyId(String proxyId);
-
+ void setContent(RemoteRepositoryContent content);
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRepository.java
index 43839197f..8188e2131 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/EditableRepository.java
@@ -34,6 +34,7 @@ import java.util.Locale;
*/
public interface EditableRepository extends Repository
{
+
/**
* Returns the primary locale used for setting the default values for
* name and description.
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/PasswordCredentials.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/PasswordCredentials.java
new file mode 100644
index 000000000..44b087bd5
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/PasswordCredentials.java
@@ -0,0 +1,49 @@
+package org.apache.archiva.repository;
+
+/*
+ * 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.
+ */
+
+/**
+ * Simple credentials that hold username and password
+ */
+public class PasswordCredentials implements RepositoryCredentials
+{
+ String username;
+ char[] password;
+
+ public String getUsername( )
+ {
+ return username;
+ }
+
+ public void setUsername( String username )
+ {
+ this.username = username;
+ }
+
+ public char[] getPassword( )
+ {
+ return password;
+ }
+
+ public void setPassword( char[] password )
+ {
+ this.password = password;
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RemoteRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RemoteRepository.java
index 30c58c059..5a7c1e8ed 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RemoteRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RemoteRepository.java
@@ -69,16 +69,5 @@ public interface RemoteRepository extends Repository {
*/
Duration getTimeout();
- /**
- * Returns the time duration after that downloads from the remote repository are aborted.
- * @return
- */
- Duration getDownloadTimeout();
-
- /**
- * Returns the id of the proxy, that is used for accessing the remote repository.
- * @return The proxy id.
- */
- String getProxyId();
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryCredentials.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryCredentials.java
index ad0653d1c..2751bc05e 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryCredentials.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryCredentials.java
@@ -24,4 +24,8 @@ package org.apache.archiva.repository;
* Credentials used to login to a remote repository.
*/
public interface RepositoryCredentials {
+
+
}
+
+
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
index eaa3daf87..8844f585d 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
@@ -22,6 +22,9 @@ package org.apache.archiva.repository;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.archiva.repository.features.StagingRepositoryFeature;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@@ -39,6 +42,9 @@ import java.util.Map;
@Service("repositoryRegistry")
public class RepositoryRegistry
{
+
+ private static final Logger log = LoggerFactory.getLogger( RepositoryRegistry.class );
+
/**
* We inject all repository providers
*/
@@ -48,6 +54,9 @@ public class RepositoryRegistry
@Inject
ArchivaConfiguration archivaConfiguration;
+ @Inject
+ RepositoryContentFactory repositoryContentFactory;
+
private Map<String, ManagedRepository> managedRepositories = new HashMap<>( );
private Map<String, RemoteRepository> remoteRepositories = new HashMap<>( );
@@ -69,7 +78,8 @@ public class RepositoryRegistry
return map;
}
- private Map<String,ManagedRepository> getManagedRepositoriesFromConfig() {
+ private Map<String,ManagedRepository> getManagedRepositoriesFromConfig()
+ {
List<ManagedRepositoryConfiguration> managedRepoConfigs =
getArchivaConfiguration().getConfiguration().getManagedRepositories();
@@ -85,13 +95,37 @@ public class RepositoryRegistry
{
RepositoryType repositoryType = RepositoryType.valueOf( repoConfig.getType( ) );
if (providerMap.containsKey( repositoryType )) {
- managedRepos.put(repoConfig.getId(), providerMap.get(repositoryType).createManagedInstance( repoConfig ));
+ try
+ {
+ ManagedRepository repo = createNewManagedRepository( providerMap.get( repositoryType ), repoConfig );
+ managedRepos.put(repo.getId(), repo);
+ } catch (Exception e) {
+ log.error("Could not create managed repository "+repoConfig.getId(), e);
+ }
}
}
return managedRepos;
}
+ private ManagedRepository createNewManagedRepository(RepositoryProvider provider, ManagedRepositoryConfiguration cfg) throws RepositoryException
+ {
+ ManagedRepository repo = provider.createManagedInstance( cfg );
+ if (repo.supportsFeature( StagingRepositoryFeature.class )) {
+ StagingRepositoryFeature feature = repo.getFeature( StagingRepositoryFeature.class ).get();
+ if (feature.isStageRepoNeeded()) {
+ ManagedRepository stageRepo = getManagedRepository( repo.getId()+StagingRepositoryFeature.STAGING_REPO_POSTFIX );
+ feature.setStagingRepository( stageRepo );
+ }
+ }
+ if (repo instanceof EditableManagedRepository)
+ {
+ ((EditableManagedRepository)repo).setContent( repositoryContentFactory.getManagedRepositoryContent( repo.getId( ) ) );
+ }
+ return repo;
+
+ }
+
private Map<String,RemoteRepository> getRemoteRepositoriesFromConfig() {
List<RemoteRepositoryConfiguration> remoteRepoConfigs =
getArchivaConfiguration().getConfiguration().getRemoteRepositories();
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/RemoteIndexFeature.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/RemoteIndexFeature.java
index 645d58141..7f510ddf9 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/RemoteIndexFeature.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/RemoteIndexFeature.java
@@ -21,6 +21,7 @@ package org.apache.archiva.repository.features;
import java.net.URI;
+import java.time.Duration;
/**
* Feature for remote index download.
@@ -30,6 +31,8 @@ public class RemoteIndexFeature implements RepositoryFeature<RemoteIndexFeature>
private boolean downloadRemoteIndex = false;
private URI indexUri;
private boolean downloadRemoteIndexOnStartup = false;
+ private Duration downloadTimeout = Duration.ofSeconds( 600 );
+ private String proxyId = "";
@Override
@@ -85,4 +88,38 @@ public class RemoteIndexFeature implements RepositoryFeature<RemoteIndexFeature>
public void setDownloadRemoteIndexOnStartup(boolean downloadRemoteIndexOnStartup) {
this.downloadRemoteIndexOnStartup = downloadRemoteIndexOnStartup;
}
+
+ /**
+ * Returns the timeout after that the remote index download is aborted.
+ * @return the time duration after that, the download is aborted.
+ */
+ public Duration getDownloadTimeout() {
+ return this.downloadTimeout;
+ }
+
+ /**
+ * Sets the timeout after that a remote index download will be aborted.
+ * @param timeout The duration
+ */
+ public void setDownloadTimeout(Duration timeout) {
+ this.downloadTimeout = timeout;
+ }
+
+ /**
+ * Returns the id of the proxy, that should be used to download the remote index.
+ * @return The proxy id
+ */
+ public String getProxyId( )
+ {
+ return proxyId;
+ }
+
+ /**
+ * Sets the id of the proxy that should be used to download the remote index.
+ * @param proxyId
+ */
+ public void setProxyId( String proxyId )
+ {
+ this.proxyId = proxyId;
+ }
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/StagingRepositoryFeature.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/StagingRepositoryFeature.java
index edd071904..3e4ba1257 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/StagingRepositoryFeature.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/StagingRepositoryFeature.java
@@ -28,6 +28,8 @@ import org.apache.archiva.repository.ManagedRepository;
*/
public class StagingRepositoryFeature implements RepositoryFeature<StagingRepositoryFeature> {
+ public static final String STAGING_REPO_POSTFIX = "-stage";
+
private ManagedRepository stagingRepository = null;
private boolean stageRepoNeeded = false;
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java
index dc16d162d..0c24c7b02 100644
--- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java
+++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java
@@ -20,7 +20,6 @@ package org.apache.archiva.repository.maven2;
*/
import org.apache.archiva.repository.AbstractManagedRepository;
-import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryCapabilities;
import org.apache.archiva.repository.RepositoryType;
@@ -40,7 +39,6 @@ public class MavenManagedRepository extends AbstractManagedRepository
{
public static final String DEFAULT_LAYOUT = "default";
public static final String LEGACY_LAYOUT = "legacy";
- private ManagedRepositoryContent content;
private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( );
private IndexCreationFeature indexCreationFeature = new IndexCreationFeature( );
private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
@@ -68,16 +66,6 @@ public class MavenManagedRepository extends AbstractManagedRepository
super( primaryLocale, RepositoryType.MAVEN, id, name );
}
- protected void setContent(ManagedRepositoryContent content) {
- this.content = content;
- }
-
- @Override
- public ManagedRepositoryContent getContent( )
- {
- return content;
- }
-
@Override
public RepositoryCapabilities getCapabilities( )
{
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java
index d35f1ccd9..de2732267 100644
--- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java
+++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java
@@ -40,9 +40,6 @@ import java.util.Locale;
public class MavenRemoteRepository extends AbstractRemoteRepository
implements RemoteRepository
{
- private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( );
- private IndexCreationFeature indexCreationFeature = new IndexCreationFeature( );
- private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
private RemoteIndexFeature remoteIndexFeature = new RemoteIndexFeature();
private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
@@ -77,13 +74,7 @@ public class MavenRemoteRepository extends AbstractRemoteRepository
@Override
public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
{
- if (ArtifactCleanupFeature.class.equals(clazz)) {
- return (RepositoryFeature<T>) artifactCleanupFeature;
- } else if (IndexCreationFeature.class.equals(clazz)) {
- return (RepositoryFeature<T>) indexCreationFeature;
- } else if (StagingRepositoryFeature.class.equals(clazz)) {
- return (RepositoryFeature<T>) stagingRepositoryFeature;
- } else if (RemoteIndexFeature.class.equals( clazz )) {
+ if (RemoteIndexFeature.class.equals( clazz )) {
return (RepositoryFeature<T>) remoteIndexFeature;
} else {
throw new UnsupportedFeatureException( );
@@ -93,10 +84,7 @@ public class MavenRemoteRepository extends AbstractRemoteRepository
@Override
public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
{
- if (ArtifactCleanupFeature.class.equals(clazz) ||
- IndexCreationFeature.class.equals(clazz) ||
- StagingRepositoryFeature.class.equals(clazz) ||
- RemoteIndexFeature.class.equals(clazz)) {
+ if ( RemoteIndexFeature.class.equals(clazz)) {
return true;
} else {
return false;
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
index 370b60bdc..1c02e1f75 100644
--- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
+++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
@@ -19,24 +19,38 @@ package org.apache.archiva.repository.maven2;
* under the License.
*/
+import org.apache.archiva.configuration.AbstractRepositoryConfiguration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.archiva.repository.EditableRepository;
import org.apache.archiva.repository.ManagedRepository;
+import org.apache.archiva.repository.PasswordCredentials;
+import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RemoteRepository;
+import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryProvider;
import org.apache.archiva.repository.RepositoryType;
+import org.apache.archiva.repository.features.ArtifactCleanupFeature;
+import org.apache.archiva.repository.features.IndexCreationFeature;
+import org.apache.archiva.repository.features.RemoteIndexFeature;
import org.apache.archiva.repository.features.StagingRepositoryFeature;
+import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
import java.net.URI;
import java.net.URISyntaxException;
+import java.time.Duration;
+import java.time.Period;
import java.util.HashSet;
+import java.util.Locale;
import java.util.Set;
/**
* Provider for the maven2 repository implementations
*/
+@Service("mavenRepositoryProvider")
public class MavenRepositoryProvider implements RepositoryProvider
{
private static final Logger log = LoggerFactory.getLogger( MavenRepositoryProvider.class );
@@ -68,16 +82,104 @@ public class MavenRepositoryProvider implements RepositoryProvider
{
log.error("Could not set repository uri "+cfg.getLocation());
}
- cfg.getRefreshCronExpression();
+ setBaseConfig( repo, cfg );
+ repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
+ repo.setBlocksRedeployment( cfg.isBlockRedeployments() );
+ repo.setScanned( cfg.isScanned() );
+ Set<ReleaseScheme> schemes = new HashSet<>( );
+ if (cfg.isReleases()) {
+ repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
+ }
+ if (cfg.isSnapshots()) {
+ repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
+ }
+
+ StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature( StagingRepositoryFeature.class ).get();
+ stagingRepositoryFeature.setStageRepoNeeded( cfg.isStageRepoNeeded() );
+ // TODO: staging repository -> here or in repositoryregistry?
+
+ IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get( );
+ indexCreationFeature.setSkipPackedIndexCreation( cfg.isSkipPackedIndexCreation() );
- StagingRepositoryFeature feature = repo.getFeature( StagingRepositoryFeature.class ).get();
- return null;
+ ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature( ArtifactCleanupFeature.class ).get();
+
+ artifactCleanupFeature.setDeleteReleasedSnapshots( cfg.isDeleteReleasedSnapshots() );
+ artifactCleanupFeature.setRetentionCount( cfg.getRetentionCount() );
+ artifactCleanupFeature.setRetentionTime( Period.ofDays( cfg.getRetentionTime() ) );
+
+ return repo;
}
@Override
- public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration )
+ public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration cfg )
{
- return null;
+ MavenRemoteRepository repo = new MavenRemoteRepository( cfg.getId( ), cfg.getName( ) );
+ setBaseConfig( repo, cfg );
+ repo.setCheckPath( cfg.getCheckPath() );
+ repo.setSchedulingDefinition( cfg.getRefreshCronExpression() );
+ try
+ {
+ repo.setLocation(new URI(cfg.getUrl()));
+ }
+ catch ( URISyntaxException e )
+ {
+ log.error("Could not set remote url "+cfg.getUrl());
+ }
+ RemoteIndexFeature remoteIndexFeature = repo.getFeature( RemoteIndexFeature.class ).get();
+ remoteIndexFeature.setDownloadRemoteIndex( cfg.isDownloadRemoteIndex() );
+ remoteIndexFeature.setDownloadRemoteIndexOnStartup( cfg.isDownloadRemoteIndexOnStartup() );
+ remoteIndexFeature.setDownloadTimeout( Duration.ofSeconds( cfg.getRemoteDownloadTimeout()) );
+ remoteIndexFeature.setProxyId( cfg.getRemoteDownloadNetworkProxyId() );
+ if (cfg.isDownloadRemoteIndex())
+ {
+ try
+ {
+ remoteIndexFeature.setIndexUri( new URI( cfg.getRemoteIndexUrl( ) ) );
+ }
+ catch ( URISyntaxException e )
+ {
+ log.error( "Could not set remote index url " + cfg.getRemoteIndexUrl( ) );
+ remoteIndexFeature.setDownloadRemoteIndex( false );
+ remoteIndexFeature.setDownloadRemoteIndexOnStartup( false );
+ }
+ }
+ repo.setExtraHeaders( cfg.getExtraHeaders() );
+ repo.setExtraParameters( cfg.getExtraParameters() );
+ PasswordCredentials credentials = new PasswordCredentials();
+ credentials.setPassword( cfg.getPassword().toCharArray() );
+ credentials.setUsername( cfg.getUsername() );
+ repo.setCredentials( credentials );
+
+ return repo;
+ }
+
+ private void setBaseConfig( EditableRepository repo, AbstractRepositoryConfiguration cfg) {
+ repo.setDescription( Locale.getDefault( ), cfg.getDescription() );
+ String indexDir = cfg.getIndexDir();
+ try
+ {
+ if ( StringUtils.isEmpty( indexDir )) {
+ repo.setIndex( false );
+ repo.setIndexPath( null );
+ } else
+ {
+ if ( indexDir.startsWith( "file://" ) )
+ {
+ repo.setIndexPath( new URI( indexDir ) );
+ }
+ else
+ {
+ repo.setIndexPath( new URI( "file://" + indexDir ) );
+ }
+ }
+ }
+ catch ( URISyntaxException e )
+ {
+ log.error("Could not set index path "+cfg.getIndexDir());
+ repo.setIndex(false);
+ }
+ repo.setLayout( cfg.getLayout() );
+
}
}