Skip to content

Commit

Permalink
Add list mojo
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 21, 2024
1 parent 0d0ec50 commit 0365986
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023-2024 Maveniverse Org.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*/
package eu.maveniverse.maven.toolbox.plugin.gav;

import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

@Mojo(name = "gav-list", requiresProject = false, threadSafe = true)
public class GavListMojo extends GavSearchMojoSupport {
/**
* The "gavoid" part to list.
*/
@Parameter(property = "gavoid", required = true)
private String gavoid;

@Override
protected void doExecute(ToolboxCommando toolboxCommando) throws MojoExecutionException {
try {
toolboxCommando.list(getRemoteRepository(toolboxCommando), gavoid, output);
} catch (IOException e) {
throw new MojoExecutionException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023-2024 Maveniverse Org.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*/
package eu.maveniverse.maven.toolbox.plugin.gav;

import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import org.apache.maven.plugins.annotations.Parameter;
import org.eclipse.aether.repository.RemoteRepository;

public abstract class GavSearchMojoSupport extends GavMojoSupport {
/**
* A repository ID. Maybe a "well known" one, or if all repository data given, a new one.
*/
@Parameter(property = "repositoryId", defaultValue = "central")
protected String repositoryId;

/**
* The base URI of the remote repository.
*/
@Parameter(property = "repositoryBaseUri")
protected String repositoryBaseUri;

/**
* The vendor of the remote repository.
*/
@Parameter(property = "repositoryVendor")
private String repositoryVendor;

protected RemoteRepository getRemoteRepository(ToolboxCommando toolboxCommando) {
RemoteRepository remoteRepository =
toolboxCommando.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();
}
}

0 comments on commit 0365986

Please sign in to comment.