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; ...@@ -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;
import org.codeability.sharing.plugins.api.ShoppingBasket.UserInfo; import org.codeability.sharing.plugins.api.ShoppingBasket.UserInfo;
import org.codeability.sharing.plugins.api.search.SearchResultDTO; 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.GitLabApi;
import org.gitlab4j.api.GitLabApiException; import org.gitlab4j.api.GitLabApiException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
...@@ -417,25 +419,23 @@ public class ShoppingBasketService { ...@@ -417,25 +419,23 @@ public class ShoppingBasketService {
boolean isDirectory) { boolean isDirectory) {
if (filePath == null) if (filePath == null)
return false; return false;
AntPathMatcher antPathMatcher = new AntPathMatcher();
for (String filter : filterOut) { for (String filter : filterOut) {
if (filter == null) { if (filter == null) {
log.warn("filter should never be null!"); log.warn("filter should never be null!");
continue; continue;
} }
String filePathToTest = filePath; IMatcher matcher;
// just adapt current path to pattern try {
if (filePathToTest if (filter.endsWith(FastIgnoreRule.PATH_SEPARATOR + ""))
.startsWith(AntPathMatcher.DEFAULT_PATH_SEPARATOR) matcher = IMatcher.createPathMatcher(
&& !filter filter.substring(0, filter.length() - 1), true);
.startsWith(AntPathMatcher.DEFAULT_PATH_SEPARATOR)) else
filePathToTest = filePathToTest.substring(1); matcher = IMatcher.createPathMatcher(filter, false);
if (!filePathToTest } catch (InvalidPatternException e) {
.startsWith(AntPathMatcher.DEFAULT_PATH_SEPARATOR) log.warn("Cannot parse pattern {}", filter);
&& filter.startsWith(AntPathMatcher.DEFAULT_PATH_SEPARATOR)) continue;
filePathToTest = AntPathMatcher.DEFAULT_PATH_SEPARATOR }
+ filePathToTest; if (matcher.matches(filePath, isDirectory, false)) {
if (antPathMatcher.match(filter, filePathToTest)) {
return true; return true;
} }
} }
......
...@@ -32,6 +32,11 @@ public class ShoppingBasketServiceTest { ...@@ -32,6 +32,11 @@ public class ShoppingBasketServiceTest {
new String[]{"**/some*.pdf"}, false)); new String[]{"**/some*.pdf"}, false));
assertTrue(ShoppingBasketService.filterOut("/someFile.txt", assertTrue(ShoppingBasketService.filterOut("/someFile.txt",
new String[]{"**/some*.txt"}, false)); 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 @Test
...@@ -50,12 +55,42 @@ public class ShoppingBasketServiceTest { ...@@ -50,12 +55,42 @@ public class ShoppingBasketServiceTest {
new String[]{"*/some/"}, true)); new String[]{"*/some/"}, true));
assertFalse(ShoppingBasketService.filterOut("parent/someDir", assertFalse(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"*/some/"}, true)); new String[]{"*/some/"}, true));
assertFalse(ShoppingBasketService.filterOut("parent/someDir", assertTrue(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"someDir/"}, true)); 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", assertTrue(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"**/someDir"}, true)); new String[]{"**/someDir"}, true));
assertTrue(ShoppingBasketService.filterOut("parent/someDir", assertTrue(ShoppingBasketService.filterOut("parent/someDir",
new String[]{"**/some*"}, true)); 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