Browse Source

Move repository implementation into separate package

tags/v1.1.0
parent
commit
40fa057fa9
20 changed files with 95 additions and 43 deletions
  1. +3
    -3
      findbugs-known.xml
  2. +8
    -8
      src/main/java/org/perfectable/repositable/ArtifactHandler.java
  3. +6
    -6
      src/main/java/org/perfectable/repositable/MetadataHandler.java
  4. +2
    -0
      src/main/java/org/perfectable/repositable/Repository.java
  5. +12
    -11
      src/main/java/org/perfectable/repositable/Server.java
  6. +1
    -1
      src/main/java/org/perfectable/repositable/configuration/FileRepositoryConfiguration.java
  7. +1
    -1
      src/main/java/org/perfectable/repositable/configuration/RepositoryConfiguration.java
  8. +1
    -1
      src/main/java/org/perfectable/repositable/configuration/ServerConfiguration.java
  9. +2
    -2
      src/main/java/org/perfectable/repositable/configuration/VirtualRepositoryConfiguration.java
  10. +8
    -2
      src/main/java/org/perfectable/repositable/repository/AuthorizedRepository.java
  11. +7
    -1
      src/main/java/org/perfectable/repositable/repository/EmptyRepository.java
  12. +8
    -1
      src/main/java/org/perfectable/repositable/repository/FileRepository.java
  13. +9
    -2
      src/main/java/org/perfectable/repositable/repository/FilteredRepository.java
  14. +7
    -1
      src/main/java/org/perfectable/repositable/repository/Repositories.java
  15. +9
    -2
      src/main/java/org/perfectable/repositable/repository/VirtualRepository.java
  16. +2
    -0
      src/test/java/org/perfectable/repositable/FileRepositoryTest.java
  17. +2
    -0
      src/test/java/org/perfectable/repositable/GroupFilterTest.java
  18. +2
    -1
      src/test/java/org/perfectable/repositable/ReleaseFilterTest.java
  19. +2
    -0
      src/test/java/org/perfectable/repositable/SnapshotFilterTest.java
  20. +3
    -0
      src/test/java/org/perfectable/repositable/VirtualRepositoryTest.java

+ 3
- 3
findbugs-known.xml View File

@@ -1,9 +1,9 @@
<BugCollection version='3.0.1'>
<BugInstance abbrev='RV' category='BAD_PRACTICE' priority='2' type='RV_RETURN_VALUE_IGNORED_BAD_PRACTICE'>
<LongMessage>Exceptional return value of java.io.File.mkdirs() ignored in
org.perfectable.repositable.FileRepository.createDirectoryIfNeeded(Path)</LongMessage>
<Class classname='org.perfectable.repositable.FileRepository' primary='true' />
<Method classname='org.perfectable.repositable.FileRepository' name='createDirectoryIfNeeded'
org.perfectable.repositable.repository.FileRepository.createDirectoryIfNeeded(Path)</LongMessage>
<Class classname='org.perfectable.repositable.repository.FileRepository' primary='true' />
<Method classname='org.perfectable.repositable.repository.FileRepository' name='createDirectoryIfNeeded'
signature='(Ljava/nio/file/Path;)V'
isStatic='false' primary='true' />
<Method classname='java.io.File' name='mkdirs'


+ 8
- 8
src/main/java/org/perfectable/repositable/ArtifactHandler.java View File

@@ -18,15 +18,15 @@ import java.util.Optional;
public class ArtifactHandler implements RequestHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ArtifactHandler.class);

private final Repositories repositories;
private final RepositorySelector repositorySelector;
private final Locator locator;

public static ArtifactHandler of(Repositories repositories, Locator locator) {
return new ArtifactHandler(repositories, locator);
public static ArtifactHandler of(RepositorySelector repositorySelector, Locator locator) {
return new ArtifactHandler(repositorySelector, locator);
}

private ArtifactHandler(Repositories repositories, Locator locator) {
this.repositories = repositories;
private ArtifactHandler(RepositorySelector repositorySelector, Locator locator) {
this.repositorySelector = repositorySelector;
this.locator = locator;
}

@@ -51,7 +51,7 @@ public class ArtifactHandler implements RequestHandler {
}

private HttpResponse handleRetrieval(ArtifactLocation location) {
Optional<Artifact> artifactContent = location.find(repositories);
Optional<Artifact> artifactContent = location.find(repositorySelector);
if(!artifactContent.isPresent()) {
return HttpResponse.NOT_FOUND;
}
@@ -62,7 +62,7 @@ public class ArtifactHandler implements RequestHandler {
}

private HttpResponse handleProbe(ArtifactLocation location) {
Optional<Artifact> artifactHeaders = location.find(repositories);
Optional<Artifact> artifactHeaders = location.find(repositorySelector);
if(!artifactHeaders.isPresent()) {
return HttpResponse.NOT_FOUND;
}
@@ -81,7 +81,7 @@ public class ArtifactHandler implements RequestHandler {
return HttpResponse.status(HttpStatus.UNAUTHORIZED);
}
try {
location.add(repositories, PublishedArtifact.of(request), uploader);
location.add(repositorySelector, PublishedArtifact.of(request), uploader);
}
catch (UnauthorizedUserException e) {
LOGGER.info("Not allowed user {} tried to upload {}", uploader, location);


+ 6
- 6
src/main/java/org/perfectable/repositable/MetadataHandler.java View File

@@ -15,15 +15,15 @@ import java.io.OutputStream;
public final class MetadataHandler implements RequestHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(MetadataHandler.class);

private final Repositories repositories;
private final RepositorySelector repositorySelector;
private final Locator locator;

public static MetadataHandler of(Repositories repositories, Locator locator) {
return new MetadataHandler(repositories, locator);
public static MetadataHandler of(RepositorySelector repositorySelector, Locator locator) {
return new MetadataHandler(repositorySelector, locator);
}

private MetadataHandler(Repositories repositories, Locator locator) {
this.repositories = repositories;
private MetadataHandler(RepositorySelector repositorySelector, Locator locator) {
this.repositorySelector = repositorySelector;
this.locator = locator;
}

@@ -46,7 +46,7 @@ public final class MetadataHandler implements RequestHandler {
}

private HttpResponse handleRetrieval(MetadataLocation location) {
Metadata metadata = location.fetch(repositories);
Metadata metadata = location.fetch(repositorySelector);
LOGGER.debug("Requested metadata {}", location);
if(metadata.isEmpty()) {
return HttpResponse.NOT_FOUND;


+ 2
- 0
src/main/java/org/perfectable/repositable/Repository.java View File

@@ -4,6 +4,8 @@ import org.perfectable.repositable.authorization.UnauthorizedUserException;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.authorization.UserSet;
import org.perfectable.repositable.metadata.Metadata;
import org.perfectable.repositable.repository.AuthorizedRepository;
import org.perfectable.repositable.repository.FilteredRepository;

import java.util.Optional;



+ 12
- 11
src/main/java/org/perfectable/repositable/Server.java View File

@@ -3,6 +3,7 @@ package org.perfectable.repositable;
import com.google.common.base.StandardSystemProperty;
import org.perfectable.repositable.authorization.Group;
import org.perfectable.repositable.configuration.ServerConfiguration;
import org.perfectable.repositable.repository.Repositories;
import org.perfectable.webable.ServerConfigurator;
import org.perfectable.webable.ServerMonitor;
import org.perfectable.webable.WebApplication;
@@ -24,12 +25,12 @@ public final class Server {
private static final int DEFAULT_PORT = 8080;

private final int port;
private final Repositories repositories;
private final RepositorySelector repositorySelector;
private final Group loggableUsers;

private Server(int port, Repositories repositories, Group loggableUsers) {
private Server(int port, RepositorySelector repositorySelector, Group loggableUsers) {
this.port = port;
this.repositories = repositories;
this.repositorySelector = repositorySelector;
this.loggableUsers = loggableUsers;
}

@@ -38,15 +39,15 @@ public final class Server {
}

public Server withPort(int newPort) {
return new Server(newPort, repositories, loggableUsers);
return new Server(newPort, repositorySelector, loggableUsers);
}

public Server withRepositories(Repositories newRepositories) {
return new Server(port, newRepositories, loggableUsers);
public Server withRepositories(RepositorySelector repositorySelector) {
return new Server(port, repositorySelector, loggableUsers);
}

public Server withLoggableUser(Group newLoggableUsers) {
return new Server(port, repositories, newLoggableUsers);
return new Server(port, repositorySelector, newLoggableUsers);
}

private ServerConfigurator<?> createServerConfiguration() {
@@ -55,10 +56,10 @@ public final class Server {
.withPort(port)
.extend(HandlerServerConfigurationExtension.create())
.withGlobalChannel(BasicAuthenticationRequestChannel.of(requestAuthenticator))
.withHandler(VersionMetadataLocation.PATH_PATTERN, MetadataHandler.of(repositories, VersionMetadataLocation::fromPath))
.withHandler(ModuleMetadataLocation.PATH_PATTERN, MetadataHandler.of(repositories, ModuleMetadataLocation::fromPath))
.withHandler(ReleaseLocation.PATH_PATTERN, ArtifactHandler.of(repositories, ReleaseLocation::fromPath))
.withHandler(SnapshotLocation.PATH_PATTERN, ArtifactHandler.of(repositories, SnapshotLocation::fromPath))
.withHandler(VersionMetadataLocation.PATH_PATTERN, MetadataHandler.of(repositorySelector, VersionMetadataLocation::fromPath))
.withHandler(ModuleMetadataLocation.PATH_PATTERN, MetadataHandler.of(repositorySelector, ModuleMetadataLocation::fromPath))
.withHandler(ReleaseLocation.PATH_PATTERN, ArtifactHandler.of(repositorySelector, ReleaseLocation::fromPath))
.withHandler(SnapshotLocation.PATH_PATTERN, ArtifactHandler.of(repositorySelector, SnapshotLocation::fromPath))
.withRootHandler(RequestHandler.constant(HttpResponse.NOT_FOUND));
}



+ 1
- 1
src/main/java/org/perfectable/repositable/configuration/FileRepositoryConfiguration.java View File

@@ -1,6 +1,6 @@
package org.perfectable.repositable.configuration;

import org.perfectable.repositable.FileRepository;
import org.perfectable.repositable.repository.FileRepository;
import org.perfectable.repositable.Filter;
import org.perfectable.repositable.Repository;
import org.perfectable.repositable.authorization.Group;


+ 1
- 1
src/main/java/org/perfectable/repositable/configuration/RepositoryConfiguration.java View File

@@ -1,6 +1,6 @@
package org.perfectable.repositable.configuration;

import org.perfectable.repositable.Repositories;
import org.perfectable.repositable.repository.Repositories;
import org.perfectable.repositable.Repository;

import javax.xml.bind.annotation.XmlAccessType;


+ 1
- 1
src/main/java/org/perfectable/repositable/configuration/ServerConfiguration.java View File

@@ -1,6 +1,6 @@
package org.perfectable.repositable.configuration;

import org.perfectable.repositable.Repositories;
import org.perfectable.repositable.repository.Repositories;
import org.perfectable.repositable.Server;
import org.perfectable.repositable.authorization.Group;



+ 2
- 2
src/main/java/org/perfectable/repositable/configuration/VirtualRepositoryConfiguration.java View File

@@ -1,7 +1,7 @@
package org.perfectable.repositable.configuration;

import org.perfectable.repositable.Repositories;
import org.perfectable.repositable.VirtualRepository;
import org.perfectable.repositable.repository.Repositories;
import org.perfectable.repositable.repository.VirtualRepository;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;


src/main/java/org/perfectable/repositable/AuthorizedRepository.java → src/main/java/org/perfectable/repositable/repository/AuthorizedRepository.java View File

@@ -1,5 +1,11 @@
package org.perfectable.repositable;

package org.perfectable.repositable.repository;

import org.perfectable.repositable.Artifact;
import org.perfectable.repositable.ArtifactIdentifier;
import org.perfectable.repositable.HashMethod;
import org.perfectable.repositable.InsertionRejected;
import org.perfectable.repositable.MetadataIdentifier;
import org.perfectable.repositable.Repository;
import org.perfectable.repositable.authorization.UnauthorizedUserException;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.authorization.UserSet;

src/main/java/org/perfectable/repositable/EmptyRepository.java → src/main/java/org/perfectable/repositable/repository/EmptyRepository.java View File

@@ -1,5 +1,11 @@
package org.perfectable.repositable;
package org.perfectable.repositable.repository;

import org.perfectable.repositable.Artifact;
import org.perfectable.repositable.ArtifactIdentifier;
import org.perfectable.repositable.HashMethod;
import org.perfectable.repositable.InsertionRejected;
import org.perfectable.repositable.MetadataIdentifier;
import org.perfectable.repositable.Repository;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.metadata.Metadata;


src/main/java/org/perfectable/repositable/FileRepository.java → src/main/java/org/perfectable/repositable/repository/FileRepository.java View File

@@ -1,6 +1,13 @@
package org.perfectable.repositable;
package org.perfectable.repositable.repository;

import com.google.common.io.Files;
import org.perfectable.repositable.Artifact;
import org.perfectable.repositable.ArtifactIdentifier;
import org.perfectable.repositable.FileArtifact;
import org.perfectable.repositable.HashMethod;
import org.perfectable.repositable.InsertionRejected;
import org.perfectable.repositable.MetadataIdentifier;
import org.perfectable.repositable.Repository;
import org.perfectable.repositable.authorization.UnauthorizedUserException;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.metadata.Metadata;

src/main/java/org/perfectable/repositable/FilteredRepository.java → src/main/java/org/perfectable/repositable/repository/FilteredRepository.java View File

@@ -1,5 +1,12 @@
package org.perfectable.repositable;

package org.perfectable.repositable.repository;

import org.perfectable.repositable.Artifact;
import org.perfectable.repositable.ArtifactIdentifier;
import org.perfectable.repositable.Filter;
import org.perfectable.repositable.HashMethod;
import org.perfectable.repositable.InsertionRejected;
import org.perfectable.repositable.MetadataIdentifier;
import org.perfectable.repositable.Repository;
import org.perfectable.repositable.authorization.UnauthorizedUserException;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.metadata.Metadata;

src/main/java/org/perfectable/repositable/Repositories.java → src/main/java/org/perfectable/repositable/repository/Repositories.java View File

@@ -1,6 +1,12 @@
package org.perfectable.repositable;
package org.perfectable.repositable.repository;

import com.google.common.collect.ImmutableSortedMap;
import org.perfectable.repositable.Artifact;
import org.perfectable.repositable.ArtifactIdentifier;
import org.perfectable.repositable.MetadataIdentifier;
import org.perfectable.repositable.Repository;
import org.perfectable.repositable.RepositorySelector;
import org.perfectable.repositable.RepositorySet;
import org.perfectable.repositable.metadata.Metadata;

import java.util.Collection;

src/main/java/org/perfectable/repositable/VirtualRepository.java → src/main/java/org/perfectable/repositable/repository/VirtualRepository.java View File

@@ -1,5 +1,12 @@
package org.perfectable.repositable;

package org.perfectable.repositable.repository;

import org.perfectable.repositable.Artifact;
import org.perfectable.repositable.ArtifactIdentifier;
import org.perfectable.repositable.HashMethod;
import org.perfectable.repositable.InsertionRejected;
import org.perfectable.repositable.MetadataIdentifier;
import org.perfectable.repositable.Repository;
import org.perfectable.repositable.RepositorySet;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.metadata.Metadata;


+ 2
- 0
src/test/java/org/perfectable/repositable/FileRepositoryTest.java View File

@@ -6,6 +6,8 @@ import com.google.common.net.MediaType;
import org.junit.Test;
import org.perfectable.repositable.authorization.Group;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.repository.FileRepository;
import org.perfectable.repositable.repository.Repositories;

import javax.servlet.http.HttpServletResponse;
import java.io.File;


+ 2
- 0
src/test/java/org/perfectable/repositable/GroupFilterTest.java View File

@@ -7,6 +7,8 @@ import org.junit.Test;
import org.perfectable.repositable.authorization.Group;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.filter.GroupFilter;
import org.perfectable.repositable.repository.FileRepository;
import org.perfectable.repositable.repository.Repositories;

import javax.servlet.http.HttpServletResponse;
import java.io.File;


+ 2
- 1
src/test/java/org/perfectable/repositable/ReleaseFilterTest.java View File

@@ -6,8 +6,9 @@ import com.google.common.net.MediaType;
import org.junit.Test;
import org.perfectable.repositable.authorization.Group;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.filter.GroupFilter;
import org.perfectable.repositable.filter.StabilityFilter;
import org.perfectable.repositable.repository.FileRepository;
import org.perfectable.repositable.repository.Repositories;

import javax.servlet.http.HttpServletResponse;
import java.io.File;


+ 2
- 0
src/test/java/org/perfectable/repositable/SnapshotFilterTest.java View File

@@ -7,6 +7,8 @@ import org.junit.Test;
import org.perfectable.repositable.authorization.Group;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.filter.StabilityFilter;
import org.perfectable.repositable.repository.FileRepository;
import org.perfectable.repositable.repository.Repositories;

import javax.servlet.http.HttpServletResponse;
import java.io.File;


+ 3
- 0
src/test/java/org/perfectable/repositable/VirtualRepositoryTest.java View File

@@ -6,6 +6,9 @@ import com.google.common.net.MediaType;
import org.junit.Test;
import org.perfectable.repositable.authorization.Group;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.repository.FileRepository;
import org.perfectable.repositable.repository.Repositories;
import org.perfectable.repositable.repository.VirtualRepository;

import javax.servlet.http.HttpServletResponse;
import java.io.File;


Loading…
Cancel
Save