Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractGitflowBasedRepositoryMojo supports now mirrored repos #132

Merged
merged 1 commit into from
Apr 17, 2023
Merged
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
@@ -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