Search in sources :

Example 1 with FolderDirectoryEntry

use of com.thoughtworks.go.domain.FolderDirectoryEntry in project gocd by gocd.

the class DirectoryReader method listEntries.

/**
     * Recursively builds a tree of the specified rootFolder
     * TODO: ChrisS : Note that the URL stuff is completely wrong and should NOT be here - that is view, this is model
     */
public DirectoryEntries listEntries(File rootFolder, String relativePath) {
    DirectoryEntries entries = new DirectoryEntries();
    if (rootFolder == null) {
        return entries;
    }
    File[] files = rootFolder.listFiles(VISIBLE_NON_SERIALIZED_FILES);
    if (files == null) {
        return entries;
    }
    Arrays.sort(files, new FileComparator());
    for (File file : files) {
        String name = file.getName();
        String url = getUrl(relativePath, name);
        entries.add(file.isDirectory() ? new FolderDirectoryEntry(name, url, listEntries(file, getCurrentPath(relativePath) + name)) : new FileDirectoryEntry(name, url));
    }
    return entries;
}
Also used : FolderDirectoryEntry(com.thoughtworks.go.domain.FolderDirectoryEntry) DirectoryEntries(com.thoughtworks.go.domain.DirectoryEntries) FileDirectoryEntry(com.thoughtworks.go.domain.FileDirectoryEntry) File(java.io.File)

Example 2 with FolderDirectoryEntry

use of com.thoughtworks.go.domain.FolderDirectoryEntry in project gocd by gocd.

the class DirectoryReaderTest method shouldGetListOfFilesAndFolders.

@Test
public void shouldGetListOfFilesAndFolders() throws Exception {
    TestFileUtil.createTestFile(testFolder, "text.html");
    File subFolder = TestFileUtil.createTestFolder(testFolder, "primate");
    TestFileUtil.createTestFile(subFolder, "baboon.html");
    DirectoryReader reader = new DirectoryReader(jobIdentifier);
    List<DirectoryEntry> entries = reader.listEntries(testFolder, folderRoot);
    assertThat(entries.size(), is(2));
    FolderDirectoryEntry folder = (FolderDirectoryEntry) entries.get(0);
    assertThat(folder.getFileName(), is("primate"));
    assertThat(folder.getUrl(), is("/files/pipelineName/LATEST/stageName/LATEST/buildName" + folderRoot + "/primate"));
    assertThat(entries.get(1).getFileName(), is("text.html"));
    assertThat(folder.getSubDirectory().get(0).getFileName(), is("baboon.html"));
    assertThat(folder.getSubDirectory().get(0).getUrl(), is("/files/pipelineName/LATEST/stageName/LATEST/buildName" + folderRoot + "/primate/baboon.html"));
}
Also used : FolderDirectoryEntry(com.thoughtworks.go.domain.FolderDirectoryEntry) FolderDirectoryEntry(com.thoughtworks.go.domain.FolderDirectoryEntry) DirectoryEntry(com.thoughtworks.go.domain.DirectoryEntry) File(java.io.File) Test(org.junit.Test)

Example 3 with FolderDirectoryEntry

use of com.thoughtworks.go.domain.FolderDirectoryEntry in project gocd by gocd.

the class DirectoryReaderTest method shouldGetSubSubFolder.

@Test
public void shouldGetSubSubFolder() throws Exception {
    TestFileUtil.createTestFile(TestFileUtil.createTestFolder(TestFileUtil.createTestFolder(testFolder, "primate"), "monkey"), "baboon.html");
    DirectoryReader reader = new DirectoryReader(jobIdentifier);
    List<DirectoryEntry> entries = reader.listEntries(testFolder, folderRoot);
    FolderDirectoryEntry folder = (FolderDirectoryEntry) entries.get(0);
    assertThat(folder.getFileName(), is("primate"));
    FolderDirectoryEntry subFolder = (FolderDirectoryEntry) folder.getSubDirectory().get(0);
    assertThat(subFolder.getFileName(), is("monkey"));
    assertThat(subFolder.getSubDirectory().get(0).getFileName(), is("baboon.html"));
    assertThat(subFolder.getSubDirectory().get(0).getUrl(), is("/files/pipelineName/LATEST/stageName/LATEST/buildName" + folderRoot + "/primate/monkey/baboon.html"));
}
Also used : FolderDirectoryEntry(com.thoughtworks.go.domain.FolderDirectoryEntry) FolderDirectoryEntry(com.thoughtworks.go.domain.FolderDirectoryEntry) DirectoryEntry(com.thoughtworks.go.domain.DirectoryEntry) Test(org.junit.Test)

Example 4 with FolderDirectoryEntry

use of com.thoughtworks.go.domain.FolderDirectoryEntry in project gocd by gocd.

the class DirectoryReaderTest method shouldGetListOfFilesWithDirectoriesFirstAndFilesInAlphabeticOrder.

@Test
public void shouldGetListOfFilesWithDirectoriesFirstAndFilesInAlphabeticOrder() throws Exception {
    TestFileUtil.createTestFile(testFolder, "build.html");
    File subFolder = TestFileUtil.createTestFolder(testFolder, "testoutput");
    TestFileUtil.createTestFile(subFolder, "baboon.html");
    TestFileUtil.createTestFile(subFolder, "apple.html");
    TestFileUtil.createTestFile(subFolder, "pear.html");
    DirectoryReader reader = new DirectoryReader(jobIdentifier);
    List<DirectoryEntry> entries = reader.listEntries(testFolder, folderRoot);
    assertThat(entries.size(), is(2));
    FolderDirectoryEntry folder = (FolderDirectoryEntry) entries.get(0);
    assertThat(folder.getFileName(), is("testoutput"));
    assertThat(entries.get(1).getFileName(), is("build.html"));
    assertThat(folder.getSubDirectory().get(0).getFileName(), is("apple.html"));
    assertThat(folder.getSubDirectory().get(1).getFileName(), is("baboon.html"));
    assertThat(folder.getSubDirectory().get(2).getFileName(), is("pear.html"));
}
Also used : FolderDirectoryEntry(com.thoughtworks.go.domain.FolderDirectoryEntry) FolderDirectoryEntry(com.thoughtworks.go.domain.FolderDirectoryEntry) DirectoryEntry(com.thoughtworks.go.domain.DirectoryEntry) File(java.io.File) Test(org.junit.Test)

Example 5 with FolderDirectoryEntry

use of com.thoughtworks.go.domain.FolderDirectoryEntry in project gocd by gocd.

the class StageDetailPresentationModel method getArtifactFiles.

public DirectoryEntries getArtifactFiles() throws IllegalArtifactLocationException {
    JobInstances withNonEmptyArtifacts = stage.getJobInstances();
    DirectoryEntries artifacts = new DirectoryEntries();
    for (JobInstance instance : withNonEmptyArtifacts) {
        DirectoryReader directoryReader = new DirectoryReader(instance.getIdentifier());
        DirectoryEntries subDirectories = directoryReader.listEntries(artifactsService.findArtifact(instance.getIdentifier(), ""), "");
        artifacts.add(new FolderDirectoryEntry(instance.getName(), "", subDirectories));
    }
    return artifacts;
}
Also used : FolderDirectoryEntry(com.thoughtworks.go.domain.FolderDirectoryEntry) DirectoryEntries(com.thoughtworks.go.domain.DirectoryEntries) JobInstance(com.thoughtworks.go.domain.JobInstance) DirectoryReader(com.thoughtworks.go.util.DirectoryReader) JobInstances(com.thoughtworks.go.domain.JobInstances)

Aggregations

FolderDirectoryEntry (com.thoughtworks.go.domain.FolderDirectoryEntry)5 DirectoryEntry (com.thoughtworks.go.domain.DirectoryEntry)3 File (java.io.File)3 Test (org.junit.Test)3 DirectoryEntries (com.thoughtworks.go.domain.DirectoryEntries)2 FileDirectoryEntry (com.thoughtworks.go.domain.FileDirectoryEntry)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 JobInstances (com.thoughtworks.go.domain.JobInstances)1 DirectoryReader (com.thoughtworks.go.util.DirectoryReader)1