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
103 changes: 103 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Real-Time-Traffic-Simulation-with-Java</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>25</source>
<target>25</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<mainClass>sumo.sim.gui.GuiApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>sumo.sim.Launcher</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.12.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>opentest4j</artifactId>
<groupId>org.opentest4j</groupId>
</exclusion>
<exclusion>
<artifactId>junit-platform-commons</artifactId>
<groupId>org.junit.platform</groupId>
</exclusion>
<exclusion>
<artifactId>apiguardian-api</artifactId>
<groupId>org.apiguardian</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.12.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>junit-platform-engine</artifactId>
<groupId>org.junit.platform</groupId>
</exclusion>
<exclusion>
<artifactId>apiguardian-api</artifactId>
<groupId>org.apiguardian</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>25</maven.compiler.target>
<maven.compiler.source>25</maven.compiler.source>
<javafx.maven.plugin.version>0.0.8</javafx.maven.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javafx.version>25.0.1</javafx.version>
<junit.version>5.12.1</junit.version>
</properties>
</project>
22 changes: 17 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,23 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<doclint>none</doclint>
</configuration>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>sumo.sim.Launcher</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/sumo/sim/Launcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sumo.sim;

public class Launcher {
/**
* Used for running .exe and preventing javaFX loading issues.
* @param args
*/
public static void main(String[] args) {
Main.main(args); // calls main class
}
}
104 changes: 89 additions & 15 deletions src/main/java/sumo/sim/logic/SumoMapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,72 @@
public class SumoMapManager {

private final Map<String, SumoMapConfig> maps = new HashMap<>(); // hashmap of configs
private final File mapFolder;

//Logger
private static final Logger logger = java.util.logging.Logger.getLogger(SumoMapManager.class.getName());

public SumoMapManager(){
loadDefaultMaps();
this.mapFolder = initializeMaps();
}


/**
* Checks file paths.
* Directory is saved in mapFolder.
*/
private File initializeMaps() {
String userDir = System.getProperty("user.dir");
File releaseFolder = new File(userDir + File.separator + "SumoConfig");
File devFolder = new File("src/main/resources/SumoConfig");

if (releaseFolder.exists() && releaseFolder.isDirectory()) {
logger.log(Level.INFO, "Release mode: " + releaseFolder.getAbsolutePath());
loadSpecificMap(releaseFolder, "Frankfurt1", "Frankfurt1", "frankfurt1_fixed.sumocfg");
loadSpecificMap(releaseFolder, "Frankfurt2", "Frankfurt2", "frankfurt2.sumocfg");

return releaseFolder;
} else {
logger.log(Level.INFO, "Dev mode " + devFolder.getAbsolutePath());
loadDefaultMapsDev();
return devFolder;
}
}

/**
* Loads all Default Maps with hardcoded paths
*/
private void loadDefaultMaps(){
maps.put("Frankfurt1", new SumoMapConfig(
"Frankfurt1",
new File("src/main/resources/SumoConfig/Frankfurt1/frankfurt1_fixed.net.xml"),
new File("src/main/resources/SumoConfig/Frankfurt1/frankfurt1_fixed.rou.xml"),
new File("src/main/resources/SumoConfig/Frankfurt1/frankfurt1_fixed.sumocfg")
));

maps.put("Frankfurt2", new SumoMapConfig(
"Frankfurt2",
new File ("src/main/resources/SumoConfig/Frankfurt2/frankfurt2.net.xml"),
new File ("src/main/resources/SumoConfig/Frankfurt2/frankfurt2.rou.xml"),
new File ("src/main/resources/SumoConfig/Frankfurt2/frankfurt2.sumocfg")
));
private void loadDefaultMapsDev() {
try {
maps.put("Frankfurt1", new SumoMapConfig(
"Frankfurt1",
new File("src/main/resources/SumoConfig/Frankfurt1/frankfurt1_fixed.net.xml"),
new File("src/main/resources/SumoConfig/Frankfurt1/frankfurt1_fixed.rou.xml"),
new File("src/main/resources/SumoConfig/Frankfurt1/frankfurt1_fixed.sumocfg")
));

maps.put("Frankfurt2", new SumoMapConfig(
"Frankfurt2",
new File("src/main/resources/SumoConfig/Frankfurt2/frankfurt2.net.xml"),
new File("src/main/resources/SumoConfig/Frankfurt2/frankfurt2.rou.xml"),
new File("src/main/resources/SumoConfig/Frankfurt2/frankfurt2.sumocfg")
));
} catch (Exception e) {
logger.log(Level.WARNING, "Error loading default maps", e);
}
}


private void loadSpecificMap(File baseFolder, String mapKey, String subFolder, String fileName) {
if (!baseFolder.exists()) return;

File mapFile = new File(baseFolder, subFolder + File.separator + fileName);

try {
checkFileCustomName(mapFile, mapKey);
} catch (MapLoadingException e) {
logger.log(Level.WARNING, "Could not load default map: " + mapKey + " (" + mapFile.getAbsolutePath() + ")", e);
}
}

public void chooseFile(Stage stage) throws MapLoadingException {
Expand Down Expand Up @@ -102,6 +142,40 @@ private void checkFile(File file) throws MapLoadingException {
}
}

/**
* For Release only
* @param file
* @param customName
* @throws MapLoadingException
*/
public void checkFileCustomName(File file, String customName) throws MapLoadingException {
if (file == null || !file.exists()) {
throw new MapLoadingException("Could not find Files: " + (file != null ? file.getAbsolutePath() : "null"));
}

XML xml = new XML(file.getAbsolutePath());
Map<String, String> inputs = xml.getConfigInputs();

String netFileString = inputs.get("net-file");
String rouFileString = inputs.get("route-files");

if (netFileString != null && rouFileString != null) {
File netFile = new File(file.getParent(), netFileString);
File rouFile = new File(file.getParent(), rouFileString);

// if inputs do not exist
if (!netFile.exists()) throw new MapLoadingException("Net-File misses: " + netFile.getAbsolutePath());
if (!rouFile.exists()) throw new MapLoadingException("Rou-File misses: " + rouFile.getAbsolutePath());

SumoMapConfig newConfig = new SumoMapConfig(customName, netFile, rouFile, file);
maps.put(customName, newConfig);

logger.log(Level.INFO, "Map loaded: " + customName);
} else {
throw new MapLoadingException("Incomplete Config: " + file.getName());
}
}

public List<String> getNames() {
return new ArrayList<>(maps.keySet()); // retrieves all keys, keys = names
}
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/sumo/sim/logic/WrapperController.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,26 @@ public class WrapperController {
*/
public WrapperController(GuiController guiController, SumoMapManager mapManager) {
// Select Windows (.exe) or UNIX binary based on static function Util.getOSType()
sumoBinary = Util.getOSType().equals("Windows")
// using sumo-gui for visualisation now, will later be replaced by our own rendered map
? "src/main/resources/Binaries/sumo.exe"
: "/usr/local/bin/sumo";

String os = Util.getOSType();
String binaryName = os.equals("Windows") ? "sumo.exe" : "sumo"; // sumo binary name

// for .exe -> binaries folder should be beside executable
String baseDir = System.getProperty("user.dir");
File releaseBinary = new File(baseDir + File.separator + "Binaries" + File.separator + binaryName);

File devBinary = new File("src/main/resources/Binaries/" + binaryName);

if (releaseBinary.exists()) {
this.sumoBinary = releaseBinary.getAbsolutePath();
logger.log(Level.INFO, "Release mode: " + this.sumoBinary);
} else if (devBinary.exists()) {
this.sumoBinary = devBinary.getAbsolutePath();
logger.log(Level.INFO, "Dev mode: " + this.sumoBinary);
} else {
logger.log(Level.SEVERE, "Could not find SUMO Binary .");
throw new RuntimeException("SUMO Binary not found in: " + releaseBinary.getAbsolutePath());
}

// config knows both .rou and .net XMLs
mapConfig = mapManager.getConfig("Frankfurt1"); // Frankfurt, TestMap
Expand Down