Search in sources :

Example 1 with DirectoryEntries

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;
}
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 DirectoryEntries

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));
}
Also used : DirectoryEntries(com.thoughtworks.go.domain.DirectoryEntries) JobInstance(com.thoughtworks.go.domain.JobInstance) File(java.io.File) Test(org.junit.Test)

Example 3 with DirectoryEntries

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

Example 4 with DirectoryEntries

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));
}
Also used : DirectoryEntries(com.thoughtworks.go.domain.DirectoryEntries) JobInstance(com.thoughtworks.go.domain.JobInstance) Stage(com.thoughtworks.go.domain.Stage) File(java.io.File) Test(org.junit.Test)

Aggregations

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