diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-05-19 17:35:34 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-05-19 17:35:34 +0200 |
commit | 4c5e00e833f5ddafb68ccd44b02db7df00c5eeba (patch) | |
tree | 1ec8b126e3333837856196f04ad4e96f94738a67 /archiva-modules/archiva-maven/archiva-maven-repository | |
parent | 17c3bb60da9fa76d69f53fc6c42e9b49c959e644 (diff) | |
download | archiva-4c5e00e833f5ddafb68ccd44b02db7df00c5eeba.tar.gz archiva-4c5e00e833f5ddafb68ccd44b02db7df00c5eeba.zip |
Adding repository group
Diffstat (limited to 'archiva-modules/archiva-maven/archiva-maven-repository')
3 files changed, 128 insertions, 38 deletions
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/pom.xml b/archiva-modules/archiva-maven/archiva-maven-repository/pom.xml index e9cd8d052..627bd5be7 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/pom.xml +++ b/archiva-modules/archiva-maven/archiva-maven-repository/pom.xml @@ -56,6 +56,7 @@ <groupId>org.apache.archiva</groupId> <artifactId>archiva-model</artifactId> </dependency> + <dependency> <groupId>org.apache.archiva.maven</groupId> <artifactId>archiva-maven-proxy</artifactId> diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java new file mode 100644 index 000000000..e9845ba99 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java @@ -0,0 +1,81 @@ +package org.apache.archiva.repository.maven2; + +/* + * 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.common.filelock.FileLockManager; +import org.apache.archiva.repository.*; +import org.apache.archiva.repository.content.FilesystemStorage; +import org.apache.archiva.repository.features.ArtifactCleanupFeature; +import org.apache.archiva.repository.features.IndexCreationFeature; +import org.apache.archiva.repository.features.StagingRepositoryFeature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Locale; + +public class MavenRepositoryGroup extends AbstractRepositoryGroup implements EditableRepositoryGroup { + + private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities( + new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT }, + new String[] { MavenManagedRepository.DEFAULT_LAYOUT, MavenManagedRepository.LEGACY_LAYOUT}, + new String[] {}, + new String[] {ArtifactCleanupFeature.class.getName(), IndexCreationFeature.class.getName(), + StagingRepositoryFeature.class.getName()}, + true, + true, + true, + true, + false + ); + + private final Logger log = LoggerFactory.getLogger(MavenRepositoryGroup.class); + + private FileLockManager lockManager; + private FilesystemStorage fsStorage; + + public MavenRepositoryGroup(String id, String name, Path repositoryBase, FileLockManager lockManager) { + super(RepositoryType.MAVEN, id, name, repositoryBase); + this.lockManager = lockManager; + init(); + } + + public MavenRepositoryGroup(Locale primaryLocale, String id, String name, Path repositoryBase, FileLockManager lockManager) { + super(primaryLocale, RepositoryType.MAVEN, id, name, repositoryBase); + this.lockManager = lockManager; + init(); + } + + private Path getRepositoryPath() { + return getRepositoryBase().resolve(getId()); + } + + private void init() { + setCapabilities(CAPABILITIES); + try { + fsStorage = new FilesystemStorage(getRepositoryPath(), lockManager); + } catch (IOException e) { + log.error("IOException while initializing repository group with path {}",getRepositoryBase()); + throw new RuntimeException("Fatal error while accessing repository path "+ getRepositoryBase(), e); + } + setStorage(fsStorage); + } +} diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java index 79a9fb9e6..280cb36de 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java @@ -19,24 +19,9 @@ package org.apache.archiva.repository.maven2; * under the License. */ -import org.apache.archiva.configuration.AbstractRepositoryConfiguration; -import org.apache.archiva.configuration.ArchivaConfiguration; -import org.apache.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.archiva.configuration.RemoteRepositoryConfiguration; -import org.apache.archiva.repository.BasicManagedRepository; -import org.apache.archiva.repository.EditableManagedRepository; -import org.apache.archiva.repository.EditableRemoteRepository; -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.RepositoryCredentials; -import org.apache.archiva.repository.RepositoryEvent; -import org.apache.archiva.repository.RepositoryException; -import org.apache.archiva.repository.RepositoryProvider; -import org.apache.archiva.repository.RepositoryType; -import org.apache.archiva.repository.UnsupportedURIException; +import org.apache.archiva.common.filelock.FileLockManager; +import org.apache.archiva.configuration.*; +import org.apache.archiva.repository.*; import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; @@ -57,6 +42,7 @@ import java.time.Duration; import java.time.Period; import java.time.temporal.ChronoUnit; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -71,6 +57,12 @@ public class MavenRepositoryProvider implements RepositoryProvider { @Inject private ArchivaConfiguration archivaConfiguration; + @Inject + private RepositoryRegistry repositoryRegistry; + + @Inject + private FileLockManager fileLockManager; + private static final Logger log = LoggerFactory.getLogger(MavenRepositoryProvider.class); static final Set<RepositoryType> TYPES = new HashSet<>(); @@ -94,6 +86,11 @@ public class MavenRepositoryProvider implements RepositoryProvider { return new MavenRemoteRepository(id, name, archivaConfiguration.getRemoteRepositoryBaseDir()); } + @Override + public EditableRepositoryGroup createRepositoryGroup(String id, String name) { + return new MavenRepositoryGroup(id, name, archivaConfiguration.getRepositoryBaseDir(), fileLockManager); + } + private URI getURIFromString(String uriStr) throws RepositoryException { URI uri; try { @@ -165,26 +162,6 @@ public class MavenRepositoryProvider implements RepositoryProvider { indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation()); indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir())); indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir())); - /* -> Should be created by MavenIndexProvider - - Path indexPath; - if (indexCreationFeature.getIndexPath().getScheme() == null) { - indexPath = Paths.get(indexCreationFeature.getIndexPath().getPath()); - } else { - indexPath = Paths.get(indexCreationFeature.getIndexPath()); - } - Path absoluteIndexPath; - if (indexPath.isAbsolute()) { - absoluteIndexPath = indexPath; - } else { - absoluteIndexPath = PathUtil.getPathFromUri(repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath()); - } - try { - Files.createDirectories(absoluteIndexPath); - } catch (IOException e) { - log.error("Could not create index directory {}", absoluteIndexPath); - throw new RepositoryException("Could not create index directory " + absoluteIndexPath); - }*/ ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get(); @@ -269,6 +246,22 @@ public class MavenRepositoryProvider implements RepositoryProvider { } @Override + public RepositoryGroup createRepositoryGroup(RepositoryGroupConfiguration configuration) throws RepositoryException { + Path repositoryGroupBase = getArchivaConfiguration().getRepositoryGroupBaseDir(); + return new MavenRepositoryGroup(configuration.getId(), configuration.getId(), + repositoryGroupBase, fileLockManager); + } + + @Override + public void updateRepositoryGroupInstance(EditableRepositoryGroup repositoryGroup, RepositoryGroupConfiguration configuration) throws RepositoryException { + repositoryGroup.setName(repositoryGroup.getPrimaryLocale(), configuration.getName()); + repositoryGroup.setRepositories(configuration.getRepositories().stream().map(rid -> repositoryRegistry.getManagedRepository(rid)).collect(Collectors.toList())); + repositoryGroup.setMergedIndexPath(configuration.getMergedIndexPath()); + repositoryGroup.setMergedIndexTTL(configuration.getMergedIndexTtl()); + repositoryGroup.setSchedulingDefinition(configuration.getCronExpression()); + } + + @Override public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException { if (!(remoteRepository instanceof MavenRemoteRepository)) { log.error("Wrong remote repository type " + remoteRepository.getClass().getName()); @@ -353,6 +346,21 @@ public class MavenRepositoryProvider implements RepositoryProvider { } + @Override + public RepositoryGroupConfiguration getRepositoryGroupConfiguration(RepositoryGroup repositoryGroup) throws RepositoryException { + if (repositoryGroup.getType() != RepositoryType.MAVEN) { + throw new RepositoryException("The given repository group is not of MAVEN type"); + } + RepositoryGroupConfiguration cfg = new RepositoryGroupConfiguration(); + cfg.setId(repositoryGroup.getId()); + cfg.setName(repositoryGroup.getName()); + cfg.setMergedIndexPath(repositoryGroup.getMergedIndexPath().getPath()); + cfg.setMergedIndexTtl(repositoryGroup.getMergedIndexTTL()); + cfg.setRepositories(repositoryGroup.getRepositories().stream().map(r -> r.getId()).collect(Collectors.toList())); + cfg.setCronExpression(repositoryGroup.getSchedulingDefinition()); + return cfg; + } + private ManagedRepositoryConfiguration getStageRepoConfig(ManagedRepositoryConfiguration repository) { ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration(); stagingRepository.setId(repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX); |