This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 16f24b50 authored by Michael Breu's avatar Michael Breu
Browse files

Umstellung auf gitIgnore Pattern

parent 943b61ec
3 merge requests!148November Release,!146Put the sonar-analyze job into a separate stage,!136Resolve "Download für Unteraufgaben soll nicht das ganze Projekt runterladen"
......@@ -18,13 +18,15 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.codeability.sharing.plugins.api.ShoppingBasket;
import org.codeability.sharing.plugins.api.ShoppingBasket.UserInfo;
import org.codeability.sharing.plugins.api.search.SearchResultDTO;
import org.eclipse.jgit.errors.InvalidPatternException;
import org.eclipse.jgit.ignore.FastIgnoreRule;
import org.eclipse.jgit.ignore.IMatcher;
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.StreamUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
......@@ -417,25 +419,23 @@ public class ShoppingBasketService {
boolean isDirectory) {
if (filePath == null)
return false;
AntPathMatcher antPathMatcher = new AntPathMatcher();
for (String filter : filterOut) {
if (filter == null) {
log.warn("filter should never be null!");
continue;
}
String filePathToTest = filePath;
// just adapt current path to pattern
if (filePathToTest
.startsWith(AntPathMatcher.DEFAULT_PATH_SEPARATOR)
&& !filter
.startsWith(AntPathMatcher.DEFAULT_PATH_SEPARATOR))
filePathToTest = filePathToTest.substring(1);
if (!filePathToTest
.startsWith(AntPathMatcher.DEFAULT_PATH_SEPARATOR)
&& filter.startsWith(AntPathMatcher.DEFAULT_PATH_SEPARATOR))
filePathToTest = AntPathMatcher.DEFAULT_PATH_SEPARATOR
+ filePathToTest;
if (antPathMatcher.match(filter, filePathToTest)) {
IMatcher matcher;
try {
if (filter.endsWith(FastIgnoreRule.PATH_SEPARATOR + ""))
matcher = IMatcher.createPathMatcher(
filter.substring(0, filter.length() - 1), true);
else
matcher = IMatcher.createPathMatcher(filter, false);
} catch (InvalidPatternException e) {
log.warn("Cannot parse pattern {}", filter);
continue;
}
if (matcher.matches(filePath, isDirectory, false)) {
return true;
}
}
......
......@@ -32,6 +32,11 @@ public class ShoppingBasketServiceTest {
new String[]{"**/some*.pdf"}, false));
assertTrue(ShoppingBasketService.filterOut("/someFile.txt",
new String[]{"**/some*.txt"}, false));
assertTrue(ShoppingBasketService.filterOut("parent/someFile.txt",
new String[]{"**/some*.txt"}, false));
assertFalse(ShoppingBasketService.filterOut("parent/someFile.txt",
new String[]{"**/someFile.txt/"}, false));
}
@Test
......@@ -50,12 +55,42 @@ public class ShoppingBasketServiceTest {
new String[]{"*/some/"}, true));
assertFalse(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"*/some/"}, true));
assertFalse(ShoppingBasketService.filterOut("parent/someDir",
assertTrue(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"someDir/"}, true));
assertTrue(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"*/someDir"}, true));
assertTrue(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"*/some*"}, true));
assertTrue(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"**/someDir"}, true));
assertTrue(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"**/some*"}, true));
assertTrue(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"parent"}, true));
}
@Test
public void filterOutTestsWithPathes() {
assertFalse(ShoppingBasketService.filterOut("/root/parent/someDir",
new String[]{}, true));
assertFalse(ShoppingBasketService.filterOut("/root/parent/someDir",
new String[]{"parent/some"}, true));
assertTrue(ShoppingBasketService.filterOut("/root/parent/someDir",
new String[]{"*/*rent/some*"}, true));
assertFalse(ShoppingBasketService.filterOut("/root/parent/someDir",
new String[]{"parent/some*"}, true));
assertFalse(ShoppingBasketService.filterOut("/root/parent/someDir",
new String[]{"par*/some*"}, true));
assertTrue(ShoppingBasketService.filterOut("/root/parent/someDir",
new String[]{"*/parent/some*"}, true));
assertTrue(ShoppingBasketService.filterOut("/root/parent/someDir",
new String[]{"*/*/some*"}, true));
assertTrue(ShoppingBasketService.filterOut("/root/parent/someDir",
new String[]{"**/some*"}, true));
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment