Skip to content

Commit

Permalink
Merge pull request #132 from DEsoftware/mirrored-remote-repos
Browse files Browse the repository at this point in the history
AbstractGitflowBasedRepositoryMojo supports now mirrored repos
  • Loading branch information
bvarner committed Apr 17, 2023
2 parents 41f08b4 + 152c08d commit 04fb7c2
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.e_gineering.maven.gitflowhelper;

import static java.nio.charset.StandardCharsets.UTF_8;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
Expand Down Expand Up @@ -38,8 +39,6 @@
import java.util.Objects;
import java.util.Optional;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* Common configuration and plumbing (support methods) for Repository operations on Gitflow Mojo.
*/
Expand Down Expand Up @@ -80,7 +79,7 @@ private static PrintWriter newPrintWriter(File catalog) throws FileNotFoundExcep

@Component
private MavenProjectHelper projectHelper;

/**
* Creates a Maven ArtifactRepository for targeting deployments.
*
Expand All @@ -91,12 +90,18 @@ private static PrintWriter newPrintWriter(File catalog) throws FileNotFoundExcep
*/
ArtifactRepository getDeploymentRepository(final String id) throws MojoFailureException {
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();
}

if (!repo.isPresent()) {
throw new MojoFailureException("No Repository with id `" + id + "` is defined.");
Optional<ArtifactRepository> mirroredRepo = project.getRemoteArtifactRepositories().stream()
.flatMap(r -> r.getMirroredRepositories().stream()).filter(r -> r.getId().equals(id)).findFirst();
if(mirroredRepo.isPresent()) {
return mirroredRepo.get();
}
return repo.get();
throw new MojoFailureException("No Repository with id `" + id + "` is defined.");
}

/**
Expand Down

0 comments on commit 04fb7c2

Please sign in to comment.