Commit 186d58c0 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Create ProjectOutput in VadereProject constructor

This must be set even if the output directory is not valid yet. If
a new VadereProject is created but not saved, there is no representation
of the project on the hard drive and thus no output directories to load
from. ProjectOutput did not handled this correctly.
parent 919f8a3a
......@@ -2,6 +2,8 @@ package org.vadere.simulator.projects;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.simulator.projects.io.IOOutput;
import org.vadere.util.io.IOUtils;
......@@ -26,6 +28,9 @@ import java.util.stream.Collectors;
* @author Stefan Schuhbäck
*/
public class ProjectOutput {
private static final Logger logger = LogManager.getLogger(ProjectOutput.class);
private final VadereProject project;
private ConcurrentMap<String, SimulationOutput> simulationOutputs;
......@@ -98,8 +103,7 @@ public class ProjectOutput {
try {
Files.walkFileTree(project.getOutputDir(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
throws IOException {
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs){
String dirName = dir.toFile().getName();
......@@ -132,7 +136,7 @@ public class ProjectOutput {
});
} catch (IOException e) {
e.printStackTrace();
logger.info(String.format("output directory '%s' of project '%s' is not valid.", project.getOutputDir(), project.getName()));
}
}
......
......@@ -44,6 +44,7 @@ public class VadereProject {
this.name = name;
scenarios.forEach(scenario -> addScenario(scenario));
this.outputDirectory = Paths.get("output");
this.projectOutput = new ProjectOutput(this);
}
public void saveChanges() {
......
......@@ -14,11 +14,14 @@ import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class ProjectOutputTest {
......@@ -87,4 +90,10 @@ public class ProjectOutputTest {
//cleanup
IOOutput.deleteOutputDirectory(project.getOutputDir().resolve("testOutput3").toFile());
}
@Test
public void projectOutputSet(){
VadereProject proj = new VadereProject("test", new LinkedList<>());
assertNotNull(proj.getProjectOutput());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment