Skip to content

Package: ScmWorkingDirectorySupport

ScmWorkingDirectorySupport

nameinstructionbranchcomplexitylinemethod
getLatestTagMatching(String)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getTags()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isEmpty()
M: 7 C: 8
53%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$getLatestTagMatching$0(String, Tag)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
reversed(List)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.frontend.filesystem.scm.spi;
27:
28: import javax.annotation.Nonnull;
29: import java.util.Collections;
30: import java.util.List;
31: import java.util.Optional;
32: import java.io.IOException;
33: import java.nio.file.Path;
34: import lombok.Getter;
35: import lombok.RequiredArgsConstructor;
36: import lombok.extern.slf4j.Slf4j;
37: import static java.util.stream.Collectors.*;
38:
39: /***************************************************************************************************************************************************************
40: *
41: * A support class for implementing {@link ScmWorkingDirectory}.
42: *
43: * @author Fabrizio Giudici
44: *
45: **************************************************************************************************************************************************************/
46: @RequiredArgsConstructor @Slf4j
47: public abstract class ScmWorkingDirectorySupport implements ScmWorkingDirectory
48: {
49: /** The name of the configuration folder - e.g. .git or .hg. */
50: @Getter @Nonnull
51: private final String configFolderName;
52:
53: /** The folder where this working directory is stored. */
54: @Getter @Nonnull
55: protected final Path folder;
56:
57: /***********************************************************************************************************************************************************
58: * {@inheritDoc}
59: **********************************************************************************************************************************************************/
60: @Override
61: public boolean isEmpty()
62: {
63:• return !folder.toFile().exists() || (folder.toFile().list().length == 0);
64: }
65:
66: /***********************************************************************************************************************************************************
67: * {@inheritDoc}
68: **********************************************************************************************************************************************************/
69: @Override @Nonnull
70: public List<Tag> getTags()
71: throws InterruptedException, IOException
72: {
73: return listTags().stream().map(Tag::new).collect(toList());
74: }
75:
76: /***********************************************************************************************************************************************************
77: * {@inheritDoc}
78: **********************************************************************************************************************************************************/
79: @Override @Nonnull
80: public Optional<Tag> getLatestTagMatching (@Nonnull final String regexp)
81: throws InterruptedException, IOException
82: {
83: final var tags = getTags();
84: Collections.reverse(tags);
85: return tags.stream().filter(tag -> tag.getName().matches(regexp)).findFirst();
86: }
87:
88: /***********************************************************************************************************************************************************
89: * {@inheritDoc}
90: **********************************************************************************************************************************************************/
91: @Nonnull
92: public abstract List<String> listTags()
93: throws InterruptedException, IOException;
94:
95: /***********************************************************************************************************************************************************
96: * Returns a reversed list.
97: *
98: * @param list the list
99: * @param <T> the list generic type
100: * @return the reversed list
101: **********************************************************************************************************************************************************/
102: @Nonnull
103: protected static <T> List<T> reversed (@Nonnull final List<T> list)
104: {
105: Collections.reverse(list);
106: return list;
107: }
108: }