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;
}
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"));
}
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"));
}
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"));
}
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;
}
Aggregations