Skip to content

Package: ScmWorkingDirectorySupport

ScmWorkingDirectorySupport

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