From 8fe612cc068162c406ad866853b2bfd62f375581 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Tue, 20 Oct 2020 10:24:31 +0200 Subject: [PATCH 1/9] create lookup command --- .../sonia/scm/repository/api/Command.java | 7 ++- .../repository/api/LookupCommandBuilder.java | 49 +++++++++++++++++ .../scm/repository/api/RepositoryService.java | 14 +++++ .../scm/repository/spi/LookupCommand.java | 35 ++++++++++++ .../repository/spi/LookupCommandRequest.java | 35 ++++++++++++ .../spi/RepositoryServiceProvider.java | 8 +++ .../scm/repository/spi/SvnLookupCommand.java | 55 +++++++++++++++++++ .../spi/SvnRepositoryServiceProvider.java | 4 +- 8 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java create mode 100644 scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java create mode 100644 scm-core/src/main/java/sonia/scm/repository/spi/LookupCommandRequest.java create mode 100644 scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java diff --git a/scm-core/src/main/java/sonia/scm/repository/api/Command.java b/scm-core/src/main/java/sonia/scm/repository/api/Command.java index d00c898233..5f3e060165 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/Command.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/Command.java @@ -57,5 +57,10 @@ public enum Command /** * @since 2.0 */ - MODIFICATIONS, MERGE, DIFF_RESULT, BRANCH, MODIFY; + MODIFICATIONS, MERGE, DIFF_RESULT, BRANCH, MODIFY, + + /** + * @since 2.8.0 + */ + LOOKUP; } diff --git a/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java new file mode 100644 index 0000000000..bc083521ac --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java @@ -0,0 +1,49 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.repository.api; + +import sonia.scm.repository.spi.LookupCommand; +import sonia.scm.repository.spi.LookupCommandRequest; + +/** + * The lookup command executes a lookup for additional repository information. + * + * @since 2.8.0 + */ +public class LookupCommandBuilder { + + private final LookupCommand lookupCommand; + private final LookupCommandRequest request = new LookupCommandRequest(); + + public LookupCommandBuilder(LookupCommand lookupCommand) { + this.lookupCommand = lookupCommand; + } + + public T lookup(Class type, String... args) { + request.setType(type); + request.setArgs(args); + return lookupCommand.lookup(request); + } +} diff --git a/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java b/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java index aa2a41782d..f0ffcec338 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java @@ -429,6 +429,20 @@ public final class RepositoryService implements Closeable { return new ModifyCommandBuilder(provider.getModifyCommand(), workdirProvider, eMail); } + /** + * The lookup command executes a lookup which returns additional information for the repository. + * + * @return instance of {@link LookupCommandBuilder} + * @throws CommandNotSupportedException if the command is not supported + * by the implementation of the repository service provider. + * @since 2.8.0 + */ + public LookupCommandBuilder getLookupCommand() { + LOG.debug("create lookup command for repository {}", + repository.getNamespaceAndName()); + return new LookupCommandBuilder(provider.getLookupCommand()); + } + /** * Returns true if the command is supported by the repository service. * diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java b/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java new file mode 100644 index 0000000000..5d9cf64060 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java @@ -0,0 +1,35 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.repository.spi; + +public interface LookupCommand { + + /** + * Executes lookup for given parameters. + * @param request Arguments provided for the lookup. + * @return Result of provided type. + */ + T lookup(LookupCommandRequest request); +} diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommandRequest.java b/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommandRequest.java new file mode 100644 index 0000000000..a3ceb13414 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommandRequest.java @@ -0,0 +1,35 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.repository.spi; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class LookupCommandRequest { + private Class type; + private String[] args; +} diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java b/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java index 6bde899617..f5e52e294c 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java @@ -274,4 +274,12 @@ public abstract class RepositoryServiceProvider implements Closeable { throw new CommandNotSupportedException(Command.MODIFY); } + + /** + * @since 2.8.0 + */ + public LookupCommand getLookupCommand() + { + throw new CommandNotSupportedException(Command.LOOKUP); + } } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java new file mode 100644 index 0000000000..908d618bec --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java @@ -0,0 +1,55 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.repository.spi; + +import lombok.extern.slf4j.Slf4j; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.io.SVNRepository; + +import java.util.Arrays; + +@Slf4j +public class SvnLookupCommand extends AbstractSvnCommand implements LookupCommand { + + protected SvnLookupCommand(SvnContext context) { + super(context); + } + + @Override + public T lookup(LookupCommandRequest request) { + try { + SVNRepository repository = context.open(); + if (request.getArgs()[0].equalsIgnoreCase("props")) { + if (Arrays.stream(request.getArgs()).anyMatch(a -> a.equalsIgnoreCase("uuid"))) { + return (T) repository.getRepositoryUUID(false); + } + } + } catch (SVNException | ClassCastException e) { + log.error("Invalid lookup request", e); + } + + return null; + } +} diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java index 1548fba869..827f9dfb03 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java @@ -46,7 +46,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider //J- public static final Set COMMANDS = ImmutableSet.of( Command.BLAME, Command.BROWSE, Command.CAT, Command.DIFF, - Command.LOG, Command.BUNDLE, Command.UNBUNDLE, Command.MODIFY + Command.LOG, Command.BUNDLE, Command.UNBUNDLE, Command.MODIFY, Command.LOOKUP ); //J+ @@ -156,6 +156,8 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider return new SvnModifyCommand(context, workingCopyFactory); } + public LookupCommand getLookupCommand() { return new SvnLookupCommand(context);} + /** * Method description * From 018ebf03ba549813c11e85edb803822464872631 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Tue, 20 Oct 2020 13:14:03 +0200 Subject: [PATCH 2/9] fix unit test --- .../test/java/sonia/scm/api/v2/resources/MeResourceTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/MeResourceTest.java b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/MeResourceTest.java index 953f4638ad..e25576f2a3 100644 --- a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/MeResourceTest.java +++ b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/MeResourceTest.java @@ -43,6 +43,7 @@ import sonia.scm.ContextEntry; import sonia.scm.group.GroupCollector; import sonia.scm.security.ApiKey; import sonia.scm.security.ApiKeyService; +import sonia.scm.user.EMail; import sonia.scm.user.InvalidPasswordException; import sonia.scm.user.User; import sonia.scm.user.UserManager; @@ -96,6 +97,9 @@ public class MeResourceTest { @Mock private ApiKeyService apiKeyService; + @Mock + private EMail eMail; + @InjectMocks private MeDtoFactory meDtoFactory; @InjectMocks From c005944a5c0f2e8875e1e6e80905b7cdbea465e6 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Tue, 20 Oct 2020 14:07:06 +0200 Subject: [PATCH 3/9] wrap lookup command result in java.util.Optional to clarify api --- .../repository/api/LookupCommandBuilder.java | 4 +- .../scm/repository/spi/LookupCommand.java | 5 +- .../scm/repository/spi/SvnLookupCommand.java | 29 ++++--- .../repository/spi/SvnLookupCommandTest.java | 80 +++++++++++++++++++ 4 files changed, 107 insertions(+), 11 deletions(-) create mode 100644 scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLookupCommandTest.java diff --git a/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java index bc083521ac..61f4be80a8 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java @@ -27,6 +27,8 @@ package sonia.scm.repository.api; import sonia.scm.repository.spi.LookupCommand; import sonia.scm.repository.spi.LookupCommandRequest; +import java.util.Optional; + /** * The lookup command executes a lookup for additional repository information. * @@ -41,7 +43,7 @@ public class LookupCommandBuilder { this.lookupCommand = lookupCommand; } - public T lookup(Class type, String... args) { + public Optional lookup(Class type, String... args) { request.setType(type); request.setArgs(args); return lookupCommand.lookup(request); diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java b/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java index 5d9cf64060..57cf4f7851 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java @@ -24,12 +24,15 @@ package sonia.scm.repository.spi; +import java.util.Optional; + public interface LookupCommand { /** * Executes lookup for given parameters. + * * @param request Arguments provided for the lookup. * @return Result of provided type. */ - T lookup(LookupCommandRequest request); + Optional lookup(LookupCommandRequest request); } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java index 908d618bec..336950e8cb 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java @@ -29,6 +29,7 @@ import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.io.SVNRepository; import java.util.Arrays; +import java.util.Optional; @Slf4j public class SvnLookupCommand extends AbstractSvnCommand implements LookupCommand { @@ -38,18 +39,28 @@ public class SvnLookupCommand extends AbstractSvnCommand implements LookupComman } @Override - public T lookup(LookupCommandRequest request) { + public Optional lookup(LookupCommandRequest request) { try { - SVNRepository repository = context.open(); - if (request.getArgs()[0].equalsIgnoreCase("props")) { - if (Arrays.stream(request.getArgs()).anyMatch(a -> a.equalsIgnoreCase("uuid"))) { - return (T) repository.getRepositoryUUID(false); - } + if (requestContainsArg(request, "props")) { + return lookupProps(request); } - } catch (SVNException | ClassCastException e) { - log.error("Invalid lookup request", e); + } catch (SVNException e) { + log.error("Lookup failed: ", e); } - return null; + return Optional.empty(); + } + + private Optional lookupProps(LookupCommandRequest request) throws SVNException { + if (requestContainsArg(request, "uuid")) { + SVNRepository repository = context.open(); + return Optional.of((T) repository.getRepositoryUUID(true)); + } + log.debug("No result found on lookup"); + return Optional.empty(); + } + + private boolean requestContainsArg(LookupCommandRequest request, String props) { + return Arrays.stream(request.getArgs()).anyMatch(a -> a.equalsIgnoreCase(props)); } } diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLookupCommandTest.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLookupCommandTest.java new file mode 100644 index 0000000000..a9c3925954 --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLookupCommandTest.java @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.repository.spi; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.io.SVNRepository; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class SvnLookupCommandTest { + + @Mock + SvnContext context; + + @Mock + SVNRepository svnRepository; + + @InjectMocks + SvnLookupCommand command; + + @Test + void shouldReturnEmptyOptional() { + LookupCommandRequest request = new LookupCommandRequest(); + request.setType(String.class); + request.setArgs(new String[]{"props"}); + + Optional result = command.lookup(request); + + assertThat(result).isNotPresent(); + } + + @Test + void shouldReturnRepositoryUUID() throws SVNException { + String uuid = "trillian-hitchhiker-42"; + when(context.open()).thenReturn(svnRepository); + when(svnRepository.getRepositoryUUID(true)).thenReturn(uuid); + + LookupCommandRequest request = new LookupCommandRequest(); + request.setType(String.class); + request.setArgs(new String[]{"props", "uuid"}); + + Optional result = command.lookup(request); + + assertThat(result).isPresent(); + assertThat(result.get()) + .isInstanceOf(String.class) + .isEqualTo(uuid); + } +} From 96233997b453d8ddea830faed53e71bc71f3256b Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Wed, 4 Nov 2020 09:27:16 +0100 Subject: [PATCH 4/9] change SvnLookupCommand implementation to match the svn lookup api --- .../java/sonia/scm/repository/spi/SvnLookupCommand.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java index 336950e8cb..14119cd851 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java @@ -28,7 +28,6 @@ import lombok.extern.slf4j.Slf4j; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.io.SVNRepository; -import java.util.Arrays; import java.util.Optional; @Slf4j @@ -41,7 +40,7 @@ public class SvnLookupCommand extends AbstractSvnCommand implements LookupComman @Override public Optional lookup(LookupCommandRequest request) { try { - if (requestContainsArg(request, "props")) { + if ("propget".equalsIgnoreCase(request.getArgs()[0])) { return lookupProps(request); } } catch (SVNException e) { @@ -52,15 +51,11 @@ public class SvnLookupCommand extends AbstractSvnCommand implements LookupComman } private Optional lookupProps(LookupCommandRequest request) throws SVNException { - if (requestContainsArg(request, "uuid")) { + if (request.getArgs()[1].equalsIgnoreCase("uuid")) { SVNRepository repository = context.open(); return Optional.of((T) repository.getRepositoryUUID(true)); } log.debug("No result found on lookup"); return Optional.empty(); } - - private boolean requestContainsArg(LookupCommandRequest request, String props) { - return Arrays.stream(request.getArgs()).anyMatch(a -> a.equalsIgnoreCase(props)); - } } From 1709fa0e3df2382c96459a1803969f2fa4141972 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Tue, 10 Nov 2020 10:08:15 +0100 Subject: [PATCH 5/9] update java doc since version --- scm-core/src/main/java/sonia/scm/repository/api/Command.java | 2 +- .../java/sonia/scm/repository/api/LookupCommandBuilder.java | 2 +- .../main/java/sonia/scm/repository/api/RepositoryService.java | 2 +- .../sonia/scm/repository/spi/RepositoryServiceProvider.java | 2 +- .../java/sonia/scm/repository/spi/SvnLookupCommandTest.java | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/repository/api/Command.java b/scm-core/src/main/java/sonia/scm/repository/api/Command.java index 5f3e060165..4a2d3e77ae 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/Command.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/Command.java @@ -60,7 +60,7 @@ public enum Command MODIFICATIONS, MERGE, DIFF_RESULT, BRANCH, MODIFY, /** - * @since 2.8.0 + * @since 2.10.0 */ LOOKUP; } diff --git a/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java index 61f4be80a8..794771d81a 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java @@ -32,7 +32,7 @@ import java.util.Optional; /** * The lookup command executes a lookup for additional repository information. * - * @since 2.8.0 + * @since 2.10.0 */ public class LookupCommandBuilder { diff --git a/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java b/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java index f814ae7aab..15c2f3f523 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java @@ -436,7 +436,7 @@ public final class RepositoryService implements Closeable { * @return instance of {@link LookupCommandBuilder} * @throws CommandNotSupportedException if the command is not supported * by the implementation of the repository service provider. - * @since 2.8.0 + * @since 2.10.0 */ public LookupCommandBuilder getLookupCommand() { LOG.debug("create lookup command for repository {}", diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java b/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java index f5e52e294c..091c9b46b3 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java @@ -276,7 +276,7 @@ public abstract class RepositoryServiceProvider implements Closeable } /** - * @since 2.8.0 + * @since 2.10.0 */ public LookupCommand getLookupCommand() { diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLookupCommandTest.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLookupCommandTest.java index a9c3925954..df4fedae92 100644 --- a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLookupCommandTest.java +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLookupCommandTest.java @@ -53,7 +53,7 @@ class SvnLookupCommandTest { void shouldReturnEmptyOptional() { LookupCommandRequest request = new LookupCommandRequest(); request.setType(String.class); - request.setArgs(new String[]{"props"}); + request.setArgs(new String[]{"propget"}); Optional result = command.lookup(request); @@ -68,7 +68,7 @@ class SvnLookupCommandTest { LookupCommandRequest request = new LookupCommandRequest(); request.setType(String.class); - request.setArgs(new String[]{"props", "uuid"}); + request.setArgs(new String[]{"propget", "uuid", "/"}); Optional result = command.lookup(request); From 4ed3a0aef67231be54bd2b57e0b3a0c780cf3960 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Tue, 10 Nov 2020 10:15:43 +0100 Subject: [PATCH 6/9] update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99b640e468..b7b6e84501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased +### Added +- Lookup command which provides further repository information ([#1415](https://github.com/scm-manager/scm-manager/pull/1415)) + ## [2.9.0] - 2020-11-06 ### Added - Tracing api ([#1393](https://github.com/scm-manager/scm-manager/pull/#1393)) From c6d3a8054edfb30cb9f67e86721d8e474d954cad Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Tue, 10 Nov 2020 10:51:20 +0100 Subject: [PATCH 7/9] fix code smell --- .../main/java/sonia/scm/repository/spi/SvnLookupCommand.java | 2 +- .../sonia/scm/repository/spi/SvnRepositoryServiceProvider.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java index 14119cd851..e23018095a 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java @@ -40,7 +40,7 @@ public class SvnLookupCommand extends AbstractSvnCommand implements LookupComman @Override public Optional lookup(LookupCommandRequest request) { try { - if ("propget".equalsIgnoreCase(request.getArgs()[0])) { + if (request.getArgs().length > 1 && "propget".equalsIgnoreCase(request.getArgs()[0])) { return lookupProps(request); } } catch (SVNException e) { diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java index 827f9dfb03..bce2d48f4b 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java @@ -156,6 +156,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider return new SvnModifyCommand(context, workingCopyFactory); } + @Override public LookupCommand getLookupCommand() { return new SvnLookupCommand(context);} /** From 8e10f7e7ed33a0c2f20b74fb7d63c6c5279b1218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Thu, 12 Nov 2020 08:10:01 +0100 Subject: [PATCH 8/9] Fix generics as far as possible --- .../sonia/scm/repository/api/LookupCommandBuilder.java | 2 +- .../main/java/sonia/scm/repository/spi/LookupCommand.java | 2 +- .../sonia/scm/repository/spi/LookupCommandRequest.java | 4 ++-- .../java/sonia/scm/repository/spi/SvnLookupCommand.java | 7 +++++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java index 794771d81a..2c047b97eb 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/LookupCommandBuilder.java @@ -37,13 +37,13 @@ import java.util.Optional; public class LookupCommandBuilder { private final LookupCommand lookupCommand; - private final LookupCommandRequest request = new LookupCommandRequest(); public LookupCommandBuilder(LookupCommand lookupCommand) { this.lookupCommand = lookupCommand; } public Optional lookup(Class type, String... args) { + LookupCommandRequest request = new LookupCommandRequest<>(); request.setType(type); request.setArgs(args); return lookupCommand.lookup(request); diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java b/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java index 57cf4f7851..363d50ec4e 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommand.java @@ -34,5 +34,5 @@ public interface LookupCommand { * @param request Arguments provided for the lookup. * @return Result of provided type. */ - Optional lookup(LookupCommandRequest request); + Optional lookup(LookupCommandRequest request); } diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommandRequest.java b/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommandRequest.java index a3ceb13414..0094351038 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommandRequest.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/LookupCommandRequest.java @@ -29,7 +29,7 @@ import lombok.Setter; @Getter @Setter -public class LookupCommandRequest { - private Class type; +public class LookupCommandRequest { + private Class type; private String[] args; } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java index e23018095a..ed79e40e25 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLookupCommand.java @@ -38,7 +38,7 @@ public class SvnLookupCommand extends AbstractSvnCommand implements LookupComman } @Override - public Optional lookup(LookupCommandRequest request) { + public Optional lookup(LookupCommandRequest request) { try { if (request.getArgs().length > 1 && "propget".equalsIgnoreCase(request.getArgs()[0])) { return lookupProps(request); @@ -50,8 +50,11 @@ public class SvnLookupCommand extends AbstractSvnCommand implements LookupComman return Optional.empty(); } - private Optional lookupProps(LookupCommandRequest request) throws SVNException { + private Optional lookupProps(LookupCommandRequest request) throws SVNException { if (request.getArgs()[1].equalsIgnoreCase("uuid")) { + if (!request.getType().equals(String.class)) { + throw new IllegalArgumentException("uuid can only be returned as String"); + } SVNRepository repository = context.open(); return Optional.of((T) repository.getRepositoryUUID(true)); } From 6abf793f498185377b98a6cb03459339364e4ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Thu, 12 Nov 2020 08:11:13 +0100 Subject: [PATCH 9/9] Fix formatting --- .../scm/repository/spi/SvnRepositoryServiceProvider.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java index bce2d48f4b..f948a7168f 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java @@ -148,16 +148,20 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider return new SvnLogCommand(context); } + @Override public ModificationsCommand getModificationsCommand() { return new SvnModificationsCommand(context); } + @Override public ModifyCommand getModifyCommand() { return new SvnModifyCommand(context, workingCopyFactory); } @Override - public LookupCommand getLookupCommand() { return new SvnLookupCommand(context);} + public LookupCommand getLookupCommand() { + return new SvnLookupCommand(context); + } /** * Method description