Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ public class ImageGenerator implements Runnable {
public ImageGenerator(Subfolder sourceFolder, GenerationMode mode, Collection<Subfolder> outputs) {
this.sourceFolder = sourceFolder;
this.mode = mode;
this.outputs = outputs;
this.outputs = outputs.stream()
.filter(output -> !isSourceFolder(output))
.toList();
this.state = ImageGeneratorStep.LIST_SOURCE_FOLDER;
this.sources = Collections.emptyList();
this.contentToBeGenerated = new LinkedList<>();
Expand All @@ -133,6 +135,27 @@ public void removeGeneratedContent() {
}
}

/**
* Returns whether the given subfolder represents the configured source folder.
* The contents of the source folder must never be regenerated.
*
* @param subfolder
* subfolder to check
* @return whether the subfolder is the configured source folder
*/
private boolean isSourceFolder(Subfolder subfolder) {
Folder source = sourceFolder.getFolder();
Folder output = subfolder.getFolder();

if (source == output) {
return true;
}

return Objects.nonNull(source.getId())
&& Objects.nonNull(output.getId())
&& Objects.equals(source.getId(), output.getId());
}

/**
* Appends the element to the list of elements to be generated.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,41 @@ public void testRecreatingAllMissingOrDamagedImagesForFilesInTheSameFolder() thr
assertNotEquals(resultFileTwoBefore, lastModifiedTime(mixedResultTwo), mixedResultTwo + MESSAGE_NOT_CHANGED);
assertNotEquals(resultFileThreeBefore, lastModifiedTime(mixedResultThree), mixedResultThree + MESSAGE_NOT_CHANGED);
}

/**
* Verifies that the configured source folder is ignored when it is also
* supplied as an output folder.
*/
@Test
public void testSourceFolderIsNotRegenerated() throws Exception {
Process process = new Process();
process.setId(processId);
process.setTitle(processTitle);

Folder folder = new Folder();
folder.setPath(tiffFolder);
folder.setMimeType(tiffType);
folder.setDerivative(1.0);

Subfolder sourceFolder = new Subfolder(process, folder);
VariableReplacer variableReplacer = new MockVariableReplacer(processTitle);
setField(sourceFolder, "variableReplacer", variableReplacer);

Subfolder outputFolder = new Subfolder(process, folder);
setField(outputFolder, "variableReplacer", variableReplacer);

Collection<Subfolder> outputs = Collections.singletonList(outputFolder);
// Intentionally use the same Folder configuration for source and output.
ImageGenerator imageGenerator = new ImageGenerator(sourceFolder, GenerationMode.ALL, outputs);

Optional<FileTime> inputFileOneBefore = lastModifiedTime(inputFileOne);
Optional<FileTime> inputFileTwoBefore = lastModifiedTime(inputFileTwo);
Optional<FileTime> inputFileThreeBefore = lastModifiedTime(inputFileThree);

imageGenerator.run();

assertEquals(inputFileOneBefore, lastModifiedTime(inputFileOne), inputFileOne + MESSAGE_CHANGED);
assertEquals(inputFileTwoBefore, lastModifiedTime(inputFileTwo), inputFileTwo + MESSAGE_CHANGED);
assertEquals(inputFileThreeBefore, lastModifiedTime(inputFileThree), inputFileThree + MESSAGE_CHANGED);
}
}