Skip to content

Commit

Permalink
Handle reposes fully
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 21, 2024
1 parent bf3d267 commit 0d0ec50
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ public abstract class SearchCommandSupport extends CommandSupport {

@CommandLine.Option(
names = {"--repositoryBaseUri"},
defaultValue = "https://repo.maven.apache.org/maven2/",
description = "The targeted repository base Uri")
protected String repositoryBaseUri;

@CommandLine.Option(
names = {"--repositoryVendor"},
defaultValue = "central",
description = "The targeted repository vendor")
protected String repositoryVendor;

protected RemoteRepository getRemoteRepository() {
return new RemoteRepository.Builder(repositoryId, "default", repositoryBaseUri).build();
RemoteRepository remoteRepository =
getToolboxCommando(getContext()).getKnownRemoteRepositories().get(repositoryId);
if (remoteRepository != null) {
return remoteRepository;
}
if (repositoryBaseUri == null && repositoryVendor == null) {
throw new IllegalArgumentException("for new remote repository one must specify all information");
}
return new RemoteRepository.Builder(repositoryId, repositoryVendor, repositoryBaseUri).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.eclipse.aether.artifact.Artifact;
Expand Down Expand Up @@ -44,6 +45,12 @@ static ToolboxCommando create(Runtime runtime, Context context) {
*/
void close();

String getVersion();

boolean dump(boolean verbose, Output output);

// Resolver related commands: they target current context contained RemoteRepository

/**
* Shorthand method, creates {@link ResolutionRoot} our of passed in artifact.
*/
Expand All @@ -56,12 +63,6 @@ default ResolutionRoot loadGav(String gav) throws ArtifactDescriptorException {
*/
ResolutionRoot loadGav(String gav, Collection<String> boms) throws ArtifactDescriptorException;

String getVersion();

boolean dump(boolean verbose, Output output);

// Resolver related commands: they target current context contained RemoteRepository

boolean classpath(ResolutionScope resolutionScope, ResolutionRoot resolutionRoot, Output output);

boolean copy(Collection<Artifact> artifacts, Consumer<Collection<Artifact>> consumer, Output output);
Expand Down Expand Up @@ -100,6 +101,8 @@ boolean resolveTransitive(

// Search API related commands: they target one single RemoteRepository

Map<String, RemoteRepository> getKnownRemoteRepositories();

boolean exists(
RemoteRepository remoteRepository,
String gav,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
public interface ToolboxSearchApi {
/**
* Shorthand for some "well known" repositories.
* <p>
* Important note: while these ARE {@link RemoteRepository} instances, they are NOT usable with Resolver, only
* with Search API.
*/
Map<String, RemoteRepository> getKnownRemoteRepositories();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ public boolean tree(
}
}

@Override
public Map<String, RemoteRepository> getKnownRemoteRepositories() {
return toolboxSearchApi.getKnownRemoteRepositories();
}

@Override
public boolean exists(
RemoteRepository remoteRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,50 +44,52 @@ public class ToolboxSearchApiImpl implements ToolboxSearchApi {

public ToolboxSearchApiImpl() {
Map<String, RemoteRepository> rr = new HashMap<>();
rr.put(ContextOverrides.CENTRAL.getId(), ContextOverrides.CENTRAL);
rr.put(
ContextOverrides.CENTRAL.getId(),
new RemoteRepository.Builder(
ContextOverrides.CENTRAL.getId(), "central", ContextOverrides.CENTRAL.getUrl())
.build());
rr.put(
"sonatype-oss-releases",
new RemoteRepository.Builder(
"sonatype-oss-releases",
"default",
"nx2",
"https://oss.sonatype.org/content/repositories/releases/")
.build());
rr.put(
"sonatype-oss-staging",
new RemoteRepository.Builder(
"sonatype-oss-staging", "default", "https://oss.sonatype.org/content/groups/staging//")
"sonatype-oss-staging", "nx2", "https://oss.sonatype.org/content/groups/staging//")
.build());
rr.put(
"sonatype-s01-releases",
new RemoteRepository.Builder(
"sonatype-s01-releases",
"default",
"nx2",
"https://s01.oss.sonatype.org/content/repositories/releases/")
.build());
rr.put(
"sonatype-s01-staging",
new RemoteRepository.Builder(
"sonatype-s01-staging",
"default",
"https://s01.oss.sonatype.org/content/groups/staging//")
"sonatype-s01-staging", "nx2", "https://s01.oss.sonatype.org/content/groups/staging//")
.build());
rr.put(
"apache-releases",
new RemoteRepository.Builder(
"apache-releases",
"default",
"nx2",
"https://repository.apache.org/content/repositories/releases/")
.build());
rr.put(
"apache-staging",
new RemoteRepository.Builder(
"apache-staging", "default", "https://repository.apache.org/content/groups/staging/")
"apache-staging", "nx2", "https://repository.apache.org/content/groups/staging/")
.build());
rr.put(
"apache-maven-staging",
new RemoteRepository.Builder(
"apache-maven-staging",
"default",
"nx2",
"https://repository.apache.org/content/groups/maven-staging-group/")
.build());
this.knownRemoteRepositories = Collections.unmodifiableMap(rr);
Expand All @@ -101,11 +103,12 @@ public Map<String, RemoteRepository> getKnownRemoteRepositories() {
@Override
public SearchBackend getRemoteRepositoryBackend(RemoteRepository remoteRepository) {
final ResponseExtractor extractor;
// TODO: this needs more
if (ContextOverrides.CENTRAL.getId().equals(remoteRepository.getId())) {
if ("central".equals(remoteRepository.getContentType())) {
extractor = new MavenCentralResponseExtractor();
} else {
} else if ("nx2".equals(remoteRepository.getContentType())) {
extractor = new Nx2ResponseExtractor();
} else {
throw new IllegalArgumentException("Unsupported extractor");
}
return RemoteRepositorySearchBackendFactory.create(
remoteRepository.getId() + "-rr",
Expand Down

0 comments on commit 0d0ec50

Please sign in to comment.