diff options
author | Martin Stockhammer <martin_s@apache.org> | 2017-10-03 19:27:15 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2017-10-03 19:27:15 +0200 |
commit | 3976c3fb23ffc68e0b8e83934db68f8db96f9c0f (patch) | |
tree | ed623f42a96988fe958bcc3a9eca05419228086d | |
parent | 1b89266820ad17ee6524706c2e15b6b08b432b8e (diff) | |
download | archiva-3976c3fb23ffc68e0b8e83934db68f8db96f9c0f.tar.gz archiva-3976c3fb23ffc68e0b8e83934db68f8db96f9c0f.zip |
Adding maven repository implementation
9 files changed, 98 insertions, 21 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/UnsupportedFeatureException.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/UnsupportedFeatureException.java index 6f798c240..112f3075d 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/UnsupportedFeatureException.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/UnsupportedFeatureException.java @@ -21,9 +21,10 @@ package org.apache.archiva.repository; /** * This exception is thrown if a given feature is not supported by the repository. + * This is a runtime exception. * */ -public class UnsupportedFeatureException extends Exception { +public class UnsupportedFeatureException extends RuntimeException { public UnsupportedFeatureException() { } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/ArtifactCleanupFeature.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/ArtifactCleanupFeature.java index 772733bf4..0243ff467 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/ArtifactCleanupFeature.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/ArtifactCleanupFeature.java @@ -33,6 +33,10 @@ public class ArtifactCleanupFeature implements RepositoryFeature<ArtifactCleanup private Period retentionTime = Period.ofDays(100); private int retentionCount = 2; + public ArtifactCleanupFeature() { + + } + public ArtifactCleanupFeature(boolean deleteReleasedSnapshots, Period retentionTime, int retentionCount) { this.deleteReleasedSnapshots = deleteReleasedSnapshots; this.retentionTime = retentionTime; @@ -40,7 +44,7 @@ public class ArtifactCleanupFeature implements RepositoryFeature<ArtifactCleanup } @Override - public ArtifactCleanupFeature getFeature() { + public ArtifactCleanupFeature get() { return this; } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java index 43b02217f..311e0d9cb 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java @@ -29,12 +29,16 @@ public class IndexCreationFeature implements RepositoryFeature<IndexCreationFeat private boolean skipPackedIndexCreation = false; + public IndexCreationFeature() { + + } + public IndexCreationFeature(boolean skipPackedIndexCreation) { this.skipPackedIndexCreation = skipPackedIndexCreation; } @Override - public IndexCreationFeature getFeature() { + public IndexCreationFeature get() { return this; } 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 5334ceed2..645d58141 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 @@ -33,7 +33,7 @@ public class RemoteIndexFeature implements RepositoryFeature<RemoteIndexFeature> @Override - public RemoteIndexFeature getFeature() { + public RemoteIndexFeature get() { return this; } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/RepositoryFeature.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/RepositoryFeature.java index 14b5c7414..a4df8a2a9 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/RepositoryFeature.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/features/RepositoryFeature.java @@ -37,5 +37,5 @@ public interface RepositoryFeature<T extends RepositoryFeature<T>> { return this.getClass().equals(clazz); } - T getFeature(); + T get(); } 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 70deadc56..edd071904 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 @@ -31,13 +31,17 @@ public class StagingRepositoryFeature implements RepositoryFeature<StagingReposi private ManagedRepository stagingRepository = null; private boolean stageRepoNeeded = false; + public StagingRepositoryFeature() { + + } + public StagingRepositoryFeature(ManagedRepository stagingRepository, boolean stageRepoNeeded) { this.stagingRepository = stagingRepository; this.stageRepoNeeded = stageRepoNeeded; } @Override - public StagingRepositoryFeature getFeature() { + public StagingRepositoryFeature get() { return this; } 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 c2a316bd5..dc16d162d 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 @@ -25,8 +25,10 @@ import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryCapabilities; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.StandardCapabilities; +import org.apache.archiva.repository.UnsupportedFeatureException; import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.repository.features.IndexCreationFeature; +import org.apache.archiva.repository.features.RepositoryFeature; import org.apache.archiva.repository.features.StagingRepositoryFeature; import java.util.Locale; @@ -39,6 +41,9 @@ 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( ); private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities( new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT }, @@ -53,14 +58,14 @@ public class MavenManagedRepository extends AbstractManagedRepository false ); - public MavenManagedRepository( RepositoryType type, String id, String name ) + public MavenManagedRepository( String id, String name ) { - super( type, id, name ); + super( RepositoryType.MAVEN, id, name ); } - public MavenManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name ) + public MavenManagedRepository( Locale primaryLocale, String id, String name ) { - super( primaryLocale, type, id, name ); + super( primaryLocale, RepositoryType.MAVEN, id, name ); } protected void setContent(ManagedRepositoryContent content) { @@ -78,4 +83,30 @@ public class MavenManagedRepository extends AbstractManagedRepository { return CAPABILITIES; } + + @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 { + throw new UnsupportedFeatureException( ); + } + } + + @Override + public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz ) + { + if (ArtifactCleanupFeature.class.equals(clazz) || + IndexCreationFeature.class.equals(clazz) || + StagingRepositoryFeature.class.equals(clazz)) { + return true; + } + return false; + } } 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 8323cd6fc..d35f1ccd9 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 @@ -1,22 +1,19 @@ package org.apache.archiva.repository.maven2; import org.apache.archiva.repository.AbstractRemoteRepository; -import org.apache.archiva.repository.AbstractRepository; import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RemoteRepository; -import org.apache.archiva.repository.RemoteRepositoryContent; import org.apache.archiva.repository.RepositoryCapabilities; -import org.apache.archiva.repository.RepositoryCredentials; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.StandardCapabilities; +import org.apache.archiva.repository.UnsupportedFeatureException; 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.RepositoryFeature; import org.apache.archiva.repository.features.StagingRepositoryFeature; -import java.time.Duration; import java.util.Locale; -import java.util.Map; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -43,6 +40,11 @@ import java.util.Map; 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( new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT }, new String[] { MavenManagedRepository.DEFAULT_LAYOUT, MavenManagedRepository.LEGACY_LAYOUT}, @@ -56,14 +58,14 @@ public class MavenRemoteRepository extends AbstractRemoteRepository false ); - public MavenRemoteRepository( RepositoryType type, String id, String name ) + public MavenRemoteRepository( String id, String name ) { - super( type, id, name ); + super( RepositoryType.MAVEN, id, name ); } - public MavenRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name ) + public MavenRemoteRepository( Locale primaryLocale, String id, String name ) { - super( primaryLocale, type, id, name ); + super( primaryLocale, RepositoryType.MAVEN, id, name ); } @Override @@ -71,4 +73,33 @@ public class MavenRemoteRepository extends AbstractRemoteRepository { return CAPABILITIES; } + + @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 )) { + return (RepositoryFeature<T>) remoteIndexFeature; + } else { + throw new UnsupportedFeatureException( ); + } + } + + @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)) { + 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 2cda87368..f2fc67e87 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 @@ -25,6 +25,7 @@ import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.RemoteRepository; import org.apache.archiva.repository.RepositoryProvider; import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.features.StagingRepositoryFeature; import java.util.HashSet; import java.util.Set; @@ -46,9 +47,10 @@ public class MavenRepositoryProvider implements RepositoryProvider } @Override - public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) + public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration cfg ) { - MavenManagedRepository repo = new MavenManagedRepository( null, null ,null ); + MavenManagedRepository repo = new MavenManagedRepository(cfg.getId() ,cfg.getName()); + StagingRepositoryFeature feature = repo.getFeature( StagingRepositoryFeature.class ).get(); return null; } |