Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,21 @@ private static PrintWriter newPrintWriter(File catalog) throws FileNotFoundExcep
* @throws MojoFailureException if the repository id is not defined.
*/
ArtifactRepository getDeploymentRepository(final String id) throws MojoFailureException {
return getDeploymentRepositoryOpt(id).orElseThrow(() -> new MojoFailureException("No Repository with id `" + id + "` is defined."));
}

/**
* Get an repository by the repository ID.
*
* @param id the repository identifier
* @return optional to the repository (never @Code{null})
*/
Optional<ArtifactRepository> getDeploymentRepositoryOpt(String id) {
Objects.requireNonNull(id, "A repository id must be specified.");

Optional<ArtifactRepository> repo = project.getRemoteArtifactRepositories().stream().filter(r -> r.getId().equals(id)).findFirst();
if (repo.isPresent()) {
return repo.get();
return repo;
}

Optional<ArtifactRepository> mirroredRepo = project.getRemoteArtifactRepositories().stream()
Expand All @@ -105,9 +115,10 @@ ArtifactRepository getDeploymentRepository(final String id) throws MojoFailureEx
if(artifactRepository.getAuthentication() == null) {
artifactRepository.setAuthentication(getAuthentication(artifactRepository));
}
return artifactRepository;
return Optional.of(artifactRepository);
}
throw new MojoFailureException("No Repository with id `" + id + "` is defined.");

return Optional.empty();
}

/**
Expand Down Expand Up @@ -210,10 +221,11 @@ private void catalogArtifact(PrintWriter writer, Artifact artifact) {
* @throws MojoExecutionException for any unhandled maven exception
*/
void attachExistingArtifacts(@Nullable final String sourceRepository, final boolean disableLocal)
throws MojoExecutionException, MojoFailureException {
throws MojoExecutionException {

List<ArtifactRepository> remoteArtifactRepositories = new ArrayList<>();
Optional<ArtifactRepository> repo = project.getRemoteArtifactRepositories().stream().filter(r -> r.getId().equals(sourceRepository)).findFirst();

Optional<ArtifactRepository> repo = getDeploymentRepositoryOpt(sourceRepository);
if (repo.isPresent()) {
remoteArtifactRepositories.add(repo.get());
} else {
Expand Down