use of jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement in project teamcity-rest by JetBrains.
the class BuildArtifactsFinderTest method testNestedArchives.
@Test
public void testNestedArchives() {
ArtifactTreeElement element;
List<ArtifactTreeElement> artifacts = getArtifacts("archive_nested.zip", null);
assertSize(2, artifacts);
element = findElement(artifacts, "archive_nested.zip!/archive.zip");
assertNotNull(element);
assertTrue(element.isArchive());
assertTrue(element.isLeaf());
assertTrue(element.isContentAvailable());
assertNull(element.getChildren());
artifacts = getArtifacts("archive_nested.zip", "browseArchives:true");
assertSize(2, artifacts);
element = findElement(artifacts, "archive_nested.zip!/archive.zip");
assertNotNull(element);
assertTrue(element.isArchive());
assertFalse(element.isLeaf());
assertTrue(element.isContentAvailable());
assertSize(2, Lists.newArrayList(element.getChildren()));
artifacts = getArtifacts("archive_nested.zip", "browseArchives:true,recursive:true");
assertSize(8, artifacts);
element = findElement(artifacts, "archive_nested.zip!/archive.zip");
assertNotNull(element);
assertTrue(element.isArchive());
assertFalse(element.isLeaf());
assertTrue(element.isContentAvailable());
assertSize(2, Lists.newArrayList(element.getChildren()));
}
use of jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement in project teamcity-rest by JetBrains.
the class BuildArtifactsFinderTest method testLocatorArchive1.
@Test
public void testLocatorArchive1() {
ArtifactTreeElement element;
List<ArtifactTreeElement> artifacts = getArtifacts("", null);
assertSize(4, artifacts);
assertContainsByFullName(artifacts, "dir1");
assertContainsByFullName(artifacts, "file.txt");
assertContainsByFullName(artifacts, "archive_nested.zip");
assertContainsByFullName(artifacts, "archive.zip");
element = findElement(artifacts, "dir1");
assertFalse(element.isArchive());
assertFalse(element.isLeaf());
assertFalse(element.isContentAvailable());
assertSize(1, Lists.newArrayList(element.getChildren()));
element = findElement(artifacts, "archive.zip");
assertTrue(element.isArchive());
assertTrue(element.isLeaf());
assertTrue(element.isContentAvailable());
// as archives browsing not enabled
assertNull(element.getChildren());
artifacts = getArtifacts("", "browseArchives:true");
assertSize(4, artifacts);
assertContainsByFullName(artifacts, "dir1");
assertContainsByFullName(artifacts, "file.txt");
assertContainsByFullName(artifacts, "archive_nested.zip");
assertContainsByFullName(artifacts, "archive.zip");
element = findElement(artifacts, "archive.zip");
assertTrue(element.isArchive());
assertFalse(element.isLeaf());
assertTrue(element.isContentAvailable());
assertSize(2, Lists.newArrayList(element.getChildren()));
artifacts = getArtifacts("", "browseArchives:false");
assertSize(4, artifacts);
assertContainsByFullName(artifacts, "dir1");
assertContainsByFullName(artifacts, "file.txt");
assertContainsByFullName(artifacts, "archive_nested.zip");
assertContainsByFullName(artifacts, "archive.zip");
element = findElement(artifacts, "archive.zip");
assertTrue(element.isArchive());
assertTrue(element.isLeaf());
assertTrue(element.isContentAvailable());
assertNull(element.getChildren());
artifacts = getArtifacts("", "hidden:true");
assertSize(1, artifacts);
assertContainsByFullName(artifacts, ".teamcity");
artifacts = getArtifacts(".teamcity", "hidden:true");
assertSize(4, artifacts);
assertContainsByFullName(artifacts, ".teamcity/logs");
assertContainsByFullName(artifacts, ".teamcity/settings");
assertContainsByFullName(artifacts, ".teamcity/properties");
assertContainsByFullName(artifacts, ".teamcity/dirA");
artifacts = getArtifacts(".teamcity/dirA", "hidden:true");
assertSize(1, artifacts);
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip");
element = findElement(artifacts, ".teamcity/dirA/archive1.zip");
assertTrue(element.isArchive());
assertTrue(element.isLeaf());
assertTrue(element.isContentAvailable());
artifacts = getArtifacts(".teamcity/dirA", "hidden:true,browseArchives:false");
assertSize(1, artifacts);
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip");
element = findElement(artifacts, ".teamcity/dirA/archive1.zip");
assertTrue(element.isArchive());
assertTrue(element.isLeaf());
assertTrue(element.isContentAvailable());
artifacts = getArtifacts(".teamcity/dirA", "hidden:true,browseArchives:true");
assertSize(1, artifacts);
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip");
element = findElement(artifacts, ".teamcity/dirA/archive1.zip");
assertTrue(element.isArchive());
assertFalse(element.isLeaf());
assertTrue(element.isContentAvailable());
assertSize(2, Lists.newArrayList(element.getChildren()));
artifacts = getArtifacts(".teamcity/dirA", "hidden:true,browseArchives:true,recursive:true");
assertSize(7, artifacts);
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/file4.txt");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/a");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/a/file1.txt");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/a/file2.txt");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/a/b");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/a/b/file3.txt");
element = findElement(artifacts, ".teamcity/dirA/archive1.zip");
assertTrue(element.isArchive());
assertFalse(element.isLeaf());
assertTrue(element.isContentAvailable());
assertSize(2, Lists.newArrayList(element.getChildren()));
artifacts = getArtifacts(".teamcity/dirA", "hidden:true,browseArchives:true,recursive:true", ".teamcity/dirA", myBuildWithArtifacts.getBuildPromotion());
assertSize(7, artifacts);
assertContainsByFullName(artifacts, "archive1.zip");
assertContainsByFullName(artifacts, "archive1.zip!/file4.txt");
assertContainsByFullName(artifacts, "archive1.zip!/a");
assertContainsByFullName(artifacts, "archive1.zip!/a/file1.txt");
assertContainsByFullName(artifacts, "archive1.zip!/a/file2.txt");
assertContainsByFullName(artifacts, "archive1.zip!/a/b");
assertContainsByFullName(artifacts, "archive1.zip!/a/b/file3.txt");
element = findElement(artifacts, "archive1.zip");
assertTrue(element.isArchive());
assertFalse(element.isLeaf());
assertTrue(element.isContentAvailable());
assertSize(2, Lists.newArrayList(element.getChildren()));
artifacts = getArtifacts(".teamcity/dirA", "hidden:true,browseArchives:true,recursive:true,directory:false");
assertSize(4, artifacts);
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/file4.txt");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/a/file1.txt");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/a/file2.txt");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/a/b/file3.txt");
artifacts = getArtifacts("archive.zip", null);
assertSize(2, artifacts);
assertContainsByFullName(artifacts, "archive.zip!/a");
assertContainsByFullName(artifacts, "archive.zip!/file4.txt");
artifacts = getArtifacts("archive.zip", "browseArchives:true");
assertSize(2, artifacts);
assertContainsByFullName(artifacts, "archive.zip!/a");
assertContainsByFullName(artifacts, "archive.zip!/file4.txt");
element = findElement(artifacts, "archive.zip!/file4.txt");
assertNotNull(element);
assertEquals("file4.txt", element.getName());
assertFalse(element.isArchive());
artifacts = getArtifacts(".teamcity", "hidden:true");
assertSize(4, artifacts);
assertContainsByFullName(artifacts, ".teamcity/dirA");
assertContainsByFullName(artifacts, ".teamcity/logs");
assertContainsByFullName(artifacts, ".teamcity/properties");
assertContainsByFullName(artifacts, ".teamcity/settings");
artifacts = getArtifacts(".teamcity/dirA", "hidden:true");
assertSize(1, artifacts);
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip");
artifacts = getArtifacts(".teamcity/dirA", "hidden:true,browseArchives:true");
assertSize(1, artifacts);
element = findElement(artifacts, ".teamcity/dirA/archive1.zip");
assertNotNull(element);
assertTrue(element.isArchive());
assertFalse(element.isLeaf());
assertTrue(element.isContentAvailable());
assertSize(2, Lists.newArrayList(element.getChildren()));
artifacts = getArtifacts(".teamcity/dirA/archive1.zip", "hidden:true");
assertSize(2, artifacts);
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/a");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/file4.txt");
artifacts = getArtifacts(".teamcity/dirA/archive1.zip", "hidden:true,browseArchives:true");
assertSize(2, artifacts);
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/a");
assertContainsByFullName(artifacts, ".teamcity/dirA/archive1.zip!/file4.txt");
}
use of jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement in project teamcity-rest by JetBrains.
the class BuildArtifactsFinder method getSingleItemByPatternPath.
@Nullable
private static Element getSingleItemByPatternPath(@NotNull final String pathWithPatterns, @NotNull final Element root, @NotNull final Browser browser, @NotNull final ServiceLocator serviceLocator) {
final List<ArtifactTreeElement> items = getItems(root, Locator.getStringLocator(DIMENSION_PATTERNS, pathWithPatterns), null, serviceLocator);
if (items.size() > 0) {
final ArtifactTreeElement first = items.get(0);
// now find it in browser to make sure archive's children can be listed
final Element foundAgain = browser.getElement(first.getFullName());
return foundAgain != null ? foundAgain : first;
}
return null;
}
use of jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement in project teamcity-rest by JetBrains.
the class BuildArtifactsFinder method getPrefilteredItems.
@NotNull
@Override
public ItemHolder<ArtifactTreeElement> getPrefilteredItems(@NotNull final Locator locator) {
setLocatorDefaults(locator);
Boolean includeHidden = locator.getSingleDimensionValueAsBoolean(HIDDEN_DIMENSION_NAME);
if (isWithinHidden(myBaseElement)) {
includeHidden = null;
}
List<String> rules = new ArrayList<>();
final String filePatterns = locator.getSingleDimensionValue(DIMENSION_PATTERNS);
if (filePatterns != null) {
// might consider smarter splitting later
final String[] splittedPatterns = filePatterns.split(",");
if (splittedPatterns.length > 0) {
rules.addAll(Arrays.asList(splittedPatterns));
}
} else {
rules.add("+:**");
}
long childrenNestingLevel = 1;
final String recursive = locator.getSingleDimensionValue(DIMENSION_RECURSIVE);
if (recursive != null) {
final Boolean parsedBoolean = Locator.getStrictBoolean(recursive);
if (parsedBoolean != null) {
if (parsedBoolean) {
childrenNestingLevel = -1;
} else {
childrenNestingLevel = 1;
}
} else {
// treat as nesting number
try {
childrenNestingLevel = Long.parseLong(recursive);
} catch (NumberFormatException e) {
throw new BadRequestException("Cannot parse value '" + recursive + "' for dimension '" + DIMENSION_RECURSIVE + "': should be boolean or nesting level number");
}
}
}
long archiveChildrenNestingLevel = 0;
final String listArchives = locator.getSingleDimensionValue(ARCHIVES_DIMENSION_NAME);
if (listArchives != null) {
final Boolean parsedBoolean = Locator.getStrictBoolean(listArchives);
if (parsedBoolean != null) {
if (parsedBoolean) {
archiveChildrenNestingLevel = 1;
} else {
archiveChildrenNestingLevel = 0;
}
} else {
// treat as nesting number
try {
archiveChildrenNestingLevel = Long.parseLong(listArchives);
} catch (NumberFormatException e) {
throw new BadRequestException("Cannot parse value '" + listArchives + "' for dimension '" + ARCHIVES_DIMENSION_NAME + "': should be boolean or nesting level number");
}
}
}
Boolean includeDirectories = locator.getSingleDimensionValueAsBoolean(DIRECTORY_DIMENSION_NAME);
final List<ArtifactTreeElement> result = new ArrayList<>();
AntPatternTreeMatcher.ScanOption[] options = {};
if (includeDirectories != null && !includeDirectories) {
// does not seem to have any effect, see TW-41662
options = new AntPatternTreeMatcher.ScanOption[] { AntPatternTreeMatcher.ScanOption.LEAFS_ONLY };
}
final Node rootNode = new Node(myBaseElement, childrenNestingLevel, archiveChildrenNestingLevel, includeHidden, true);
final Collection<Node> rawResult = AntPatternTreeMatcher.scan(rootNode, rules, options);
final Boolean finalIncludeDirectories = includeDirectories;
result.addAll(CollectionsUtil.filterAndConvertCollection(rawResult, Node::getElement, data -> {
if (rootNode.equals(data)) {
// TeamCity API issue: should support not returning the first node in API
return false;
}
// noinspection RedundantIfStatement
if (!FilterUtil.isIncludedByBooleanFilter(finalIncludeDirectories, !data.getElement().isLeaf())) {
return false;
}
return true;
}));
try {
Collections.sort(result, ARTIFACT_COMPARATOR);
} catch (Exception e) {
LOG.error("Error sorting results: " + result.stream().map(Element::getFullName).collect(Collectors.joining(", ", "{", "}")), e);
}
return getItemHolder(result);
}
Aggregations