Search in sources :

Example 6 with ArtifactTreeElement

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()));
}
Also used : ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) Test(org.testng.annotations.Test)

Example 7 with ArtifactTreeElement

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");
}
Also used : ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) Test(org.testng.annotations.Test)

Example 8 with ArtifactTreeElement

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;
}
Also used : ArtifactElement(jetbrains.buildServer.web.artifacts.browser.ArtifactElement) ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with ArtifactTreeElement

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);
}
Also used : java.util(java.util) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) BuildArtifact(jetbrains.buildServer.serverSide.artifacts.BuildArtifact) Converter(jetbrains.buildServer.util.Converter) jetbrains.buildServer.server.rest.errors(jetbrains.buildServer.server.rest.errors) BuildArtifacts(jetbrains.buildServer.serverSide.artifacts.BuildArtifacts) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) StringUtil(jetbrains.buildServer.util.StringUtil) LogUtil(jetbrains.buildServer.serverSide.impl.LogUtil) Logger(com.intellij.openapi.diagnostic.Logger) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) PagerData(jetbrains.buildServer.server.rest.model.PagerData) BuildArtifactHolder(jetbrains.buildServer.serverSide.artifacts.BuildArtifactHolder) ArtifactElement(jetbrains.buildServer.web.artifacts.browser.ArtifactElement) jetbrains.buildServer.util.browser(jetbrains.buildServer.util.browser) ServiceLocator(jetbrains.buildServer.ServiceLocator) AntPatternTreeMatcher(jetbrains.buildServer.util.pathMatcher.AntPatternTreeMatcher) ArtifactsBrowserImpl(jetbrains.buildServer.web.artifacts.browser.ArtifactsBrowserImpl) ExceptionUtil(jetbrains.buildServer.util.ExceptionUtil) IOException(java.io.IOException) ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) Collectors(java.util.stream.Collectors) File(java.io.File) PathNode(jetbrains.buildServer.util.pathMatcher.PathNode) ArtifactsConstants(jetbrains.buildServer.ArtifactsConstants) BuildArtifactsViewMode(jetbrains.buildServer.serverSide.artifacts.BuildArtifactsViewMode) Nullable(org.jetbrains.annotations.Nullable) FileApiUrlBuilder(jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) BuildPromotionEx(jetbrains.buildServer.serverSide.BuildPromotionEx) InputStream(java.io.InputStream) AntPatternTreeMatcher(jetbrains.buildServer.util.pathMatcher.AntPatternTreeMatcher) PathNode(jetbrains.buildServer.util.pathMatcher.PathNode) ArtifactElement(jetbrains.buildServer.web.artifacts.browser.ArtifactElement) ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) IOException(java.io.IOException) ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ArtifactTreeElement (jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement)9 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 FileApiUrlBuilder (jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder)2 ArtifactElement (jetbrains.buildServer.web.artifacts.browser.ArtifactElement)2 Nullable (org.jetbrains.annotations.Nullable)2 Logger (com.intellij.openapi.diagnostic.Logger)1 ApiOperation (io.swagger.annotations.ApiOperation)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 ParseException (java.text.ParseException)1 java.util (java.util)1 Date (java.util.Date)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1