use of com.thoughtworks.go.domain.DirectoryEntries 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.DirectoryEntries in project gocd by gocd.
the class JobDetailPresentationModelTest method shouldAddFakeConsoleOutputEntryIfJobIsNotCompleted.
@Test
public void shouldAddFakeConsoleOutputEntryIfJobIsNotCompleted() throws Exception {
JobInstance job = building("job");
JobDetailPresentationModel model = new JobDetailPresentationModel(job, null, null, null, null, null, artifactsService, null, custom("stage"));
when(artifactsService.findArtifact(job.getIdentifier(), "")).thenReturn(mock(File.class));
when(artifactsService.findArtifactUrl(job.getIdentifier(), getConsoleOutputFolderAndFileName())).thenReturn("path/to/console");
when(directoryReader.listEntries(any(File.class), eq(""))).thenReturn(new DirectoryEntries());
DirectoryEntries expected = new DirectoryEntries();
expected.addFolder("cruise-output").addFile("console.log", "path/to/console");
assertThat(model.getArtifactFiles(directoryReader), is(expected));
}
use of com.thoughtworks.go.domain.DirectoryEntries 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;
}
use of com.thoughtworks.go.domain.DirectoryEntries in project gocd by gocd.
the class JobDetailPresentationModelTest method shouldShowMessage.
@Test
public void shouldShowMessage() throws IllegalArtifactLocationException {
JobInstance jobInstance = JobInstanceMother.completed("job-1");
Stage stage = new Stage();
stage.setArtifactsDeleted(true);
DirectoryEntries directoryEntries = new DirectoryEntries();
when(directoryReader.listEntries(any(File.class), any(String.class))).thenReturn(directoryEntries);
JobDetailPresentationModel jobDetailPresentationModel = new JobDetailPresentationModel(jobInstance, null, null, null, null, null, artifactsService, null, stage);
DirectoryEntries artifactFiles = jobDetailPresentationModel.getArtifactFiles(directoryReader);
assertThat(artifactFiles.isArtifactsDeleted(), is(true));
}
Aggregations