mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-05 07:29:22 +02:00
Limit scopes and rename bean (#1991)
This limits the scope of all cli related classes, so that they cannot be used outside of cli context and therefore cannot confuse other developers. Secondly, we rename RepositoryCommandDto to RepositoryCommandBean, because we have no data transfers here and the name might be confusing otherwise.
This commit is contained in:
@@ -31,7 +31,7 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class RepositoryCommandDto {
|
||||
class RepositoryCommandBean {
|
||||
private String name;
|
||||
private String namespace;
|
||||
private String type;
|
||||
@@ -40,7 +40,7 @@ import javax.validation.constraints.Email;
|
||||
|
||||
@CommandLine.Command(name = "create")
|
||||
@ParentCommand(value = RepositoryCommand.class)
|
||||
public class RepositoryCreateCommand implements Runnable {
|
||||
class RepositoryCreateCommand implements Runnable {
|
||||
|
||||
@CommandLine.Mixin
|
||||
private final RepositoryTemplateRenderer templateRenderer;
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.Collections;
|
||||
|
||||
@CommandLine.Command(name = "delete", aliases = "rm")
|
||||
@ParentCommand(RepositoryCommand.class)
|
||||
public class RepositoryDeleteCommand implements Runnable {
|
||||
class RepositoryDeleteCommand implements Runnable {
|
||||
|
||||
private static final String PROMPT_TEMPLATE = "{{i18n.repoDeletePrompt}}";
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import javax.inject.Inject;
|
||||
|
||||
@ParentCommand(value = RepositoryCommand.class)
|
||||
@CommandLine.Command(name = "get")
|
||||
public class RepositoryGetCommand implements Runnable {
|
||||
class RepositoryGetCommand implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "namespace/name", index = "0")
|
||||
private String repository;
|
||||
|
||||
@@ -38,7 +38,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
@ParentCommand(value = RepositoryCommand.class)
|
||||
@CommandLine.Command(name = "list", aliases = "ls")
|
||||
public class RepositoryListCommand implements Runnable {
|
||||
class RepositoryListCommand implements Runnable {
|
||||
|
||||
@CommandLine.Mixin
|
||||
private final TemplateRenderer templateRenderer;
|
||||
@@ -69,16 +69,16 @@ public class RepositoryListCommand implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Collection<RepositoryCommandDto> dtos = manager.getAll().stream().map(mapper::map).collect(Collectors.toList());
|
||||
Collection<RepositoryCommandBean> beans = manager.getAll().stream().map(mapper::map).collect(Collectors.toList());
|
||||
if (useShortTemplate) {
|
||||
templateRenderer.renderToStdout(SHORT_TEMPLATE, ImmutableMap.of("repos", dtos));
|
||||
templateRenderer.renderToStdout(SHORT_TEMPLATE, ImmutableMap.of("repos", beans));
|
||||
} else {
|
||||
Table table = templateRenderer.createTable();
|
||||
table.addHeader("repoName", "repoType", "repoUrl");
|
||||
for (RepositoryCommandDto dto : dtos) {
|
||||
table.addRow(dto.getNamespace() + "/" + dto.getName(), dto.getType(), dto.getUrl());
|
||||
for (RepositoryCommandBean bean : beans) {
|
||||
table.addRow(bean.getNamespace() + "/" + bean.getName(), bean.getType(), bean.getUrl());
|
||||
}
|
||||
templateRenderer.renderToStdout(TABLE_TEMPLATE, ImmutableMap.of("rows", table, "repos", dtos));
|
||||
templateRenderer.renderToStdout(TABLE_TEMPLATE, ImmutableMap.of("rows", table, "repos", beans));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import javax.validation.constraints.Email;
|
||||
|
||||
@ParentCommand(value = RepositoryCommand.class)
|
||||
@CommandLine.Command(name = "modify")
|
||||
public class RepositoryModifyCommand implements Runnable {
|
||||
class RepositoryModifyCommand implements Runnable {
|
||||
|
||||
@CommandLine.Mixin
|
||||
private final RepositoryTemplateRenderer templateRenderer;
|
||||
|
||||
@@ -35,7 +35,7 @@ import sonia.scm.template.TemplateEngineFactory;
|
||||
import javax.inject.Inject;
|
||||
import java.util.Collections;
|
||||
|
||||
public class RepositoryTemplateRenderer extends TemplateRenderer {
|
||||
class RepositoryTemplateRenderer extends TemplateRenderer {
|
||||
|
||||
private static final String DETAILS_TABLE_TEMPLATE = String.join("\n",
|
||||
"{{#rows}}",
|
||||
@@ -57,16 +57,16 @@ public class RepositoryTemplateRenderer extends TemplateRenderer {
|
||||
|
||||
public void render(Repository repository) {
|
||||
Table table = createTable();
|
||||
RepositoryCommandDto dto = mapper.map(repository);
|
||||
table.addLabelValueRow("repoNamespace", dto.getNamespace());
|
||||
table.addLabelValueRow("repoName", dto.getName());
|
||||
table.addLabelValueRow("repoType", dto.getType());
|
||||
table.addLabelValueRow("repoContact", dto.getContact());
|
||||
table.addLabelValueRow("repoCreationDate", dto.getCreationDate());
|
||||
table.addLabelValueRow("repoLastModified", dto.getLastModified());
|
||||
table.addLabelValueRow("repoUrl", dto.getUrl());
|
||||
table.addLabelValueRow("repoDescription", dto.getDescription());
|
||||
renderToStdout(DETAILS_TABLE_TEMPLATE, ImmutableMap.of("rows", table, "repo", dto));
|
||||
RepositoryCommandBean bean = mapper.map(repository);
|
||||
table.addLabelValueRow("repoNamespace", bean.getNamespace());
|
||||
table.addLabelValueRow("repoName", bean.getName());
|
||||
table.addLabelValueRow("repoType", bean.getType());
|
||||
table.addLabelValueRow("repoContact", bean.getContact());
|
||||
table.addLabelValueRow("repoCreationDate", bean.getCreationDate());
|
||||
table.addLabelValueRow("repoLastModified", bean.getLastModified());
|
||||
table.addLabelValueRow("repoUrl", bean.getUrl());
|
||||
table.addLabelValueRow("repoDescription", bean.getDescription());
|
||||
renderToStdout(DETAILS_TABLE_TEMPLATE, ImmutableMap.of("rows", table, "repo", bean));
|
||||
}
|
||||
|
||||
public void renderInvalidInputError() {
|
||||
|
||||
@@ -26,6 +26,7 @@ package sonia.scm.repository.cli;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ObjectFactory;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.RepositoryService;
|
||||
@@ -43,16 +44,17 @@ public abstract class RepositoryToRepositoryCommandDtoMapper {
|
||||
@Inject
|
||||
private RepositoryServiceFactory serviceFactory;
|
||||
|
||||
public abstract RepositoryCommandDto map(Repository modelObject);
|
||||
@Mapping(target = "url", ignore = true)
|
||||
abstract RepositoryCommandBean map(Repository modelObject);
|
||||
|
||||
@ObjectFactory
|
||||
RepositoryCommandDto createDto(Repository repository) {
|
||||
RepositoryCommandDto dto = new RepositoryCommandDto();
|
||||
RepositoryCommandBean createBean(Repository repository) {
|
||||
RepositoryCommandBean bean = new RepositoryCommandBean();
|
||||
try (RepositoryService service = serviceFactory.create(repository)) {
|
||||
Optional<ScmProtocol> protocolUrl = service.getSupportedProtocols().filter(p -> p.getType().equals("http")).findFirst();
|
||||
protocolUrl.ifPresent(scmProtocol -> dto.setUrl(scmProtocol.getUrl()));
|
||||
protocolUrl.ifPresent(scmProtocol -> bean.setUrl(scmProtocol.getUrl()));
|
||||
}
|
||||
return dto;
|
||||
return bean;
|
||||
}
|
||||
|
||||
String mapTimestampToISODate(Long timestamp) {
|
||||
|
||||
Reference in New Issue
Block a user