Commit e9fa7143 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Merge branch 'master' into psychology

parents 19be831e 81c53181
Pipeline #225268 passed with stages
in 126 minutes and 35 seconds
...@@ -4,7 +4,7 @@ import javax.swing.*; ...@@ -4,7 +4,7 @@ import javax.swing.*;
import org.vadere.gui.components.utils.Messages; import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.utils.Resources; import org.vadere.gui.components.utils.Resources;
import org.vadere.simulator.projects.io.HashGenerator; import org.vadere.simulator.entrypoints.Version;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.text.MessageFormat; import java.text.MessageFormat;
...@@ -22,7 +22,7 @@ public class ActionShowAboutDialog extends AbstractAction { ...@@ -22,7 +22,7 @@ public class ActionShowAboutDialog extends AbstractAction {
public void actionPerformed(final ActionEvent event) { public void actionPerformed(final ActionEvent event) {
String text = ""; String text = "";
text += "<html>"; text += "<html>";
text += "<font size =\"3\"><em>" + MessageFormat.format(Messages.getString("ProjectView.version"), HashGenerator.releaseNumber()) + "</em></font><br>"; text += "<font size =\"3\"><em>" + MessageFormat.format(Messages.getString("ProjectView.version"), Version.releaseNumber()) + "</em></font><br>";
text += "<br>"; text += "<br>";
text += "<font size =\"3\">www.vadere.org</font><br>"; text += "<font size =\"3\">www.vadere.org</font><br>";
text += "<font size =\"3\">" + MessageFormat.format(Messages.getString("ProjectView.license.text"), "GNU Lesser General Public License (<em>LGPL</em>).") + "</font>"; text += "<font size =\"3\">" + MessageFormat.format(Messages.getString("ProjectView.license.text"), "GNU Lesser General Public License (<em>LGPL</em>).") + "</font>";
......
package org.vadere.simulator.entrypoints; package org.vadere.simulator.entrypoints;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.vadere.util.logging.Logger;
import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import java.util.Scanner;
/** /**
* Versions in strict order from oldest to newest. * Versions in strict order from oldest to newest.
*/ */
public enum Version { public enum Version {
UNDEFINED("undefined"), UNDEFINED("undefined"),
NOT_A_RELEASE("not a release"), NOT_A_RELEASE("not a release"),
V0_1(0, 1), V0_1(0, 1),
...@@ -35,14 +36,16 @@ public enum Version { ...@@ -35,14 +36,16 @@ public enum Version {
V1_8(1, 8), V1_8(1, 8),
V1_9(1, 9), V1_9(1, 9),
V1_10(1, 10), V1_10(1, 10),
V1_11(1, 11), V1_11(1, 11);
;
private static Logger logger = Logger.getLogger(Version.class);
private String label; private String label;
private int major; private int major;
private int minor; private int minor;
private static final String CURRENT_COMMIT_HASH_RESOURCE = "/current_commit_hash.txt";
Version(String label) { Version(String label) {
this.major = -1; this.major = -1;
...@@ -56,6 +59,35 @@ public enum Version { ...@@ -56,6 +59,35 @@ public enum Version {
this.label = major + "." + minor; this.label = major + "." + minor;
} }
public static String commitHash() {
String commitHash = getFirstStringTokenFromResource(CURRENT_COMMIT_HASH_RESOURCE);
if (commitHash == null) {
commitHash = "topographyWarning: no commit hash";
logger.warn("No commit hash found. The project will not contain a hash of the software source code.");
}
return commitHash;
}
public static String releaseNumber() {
return latest().label();
}
/* Read commit hash from file
*/
private static String getFirstStringTokenFromResource(String resource) {
final InputStream in = Version.class.getResourceAsStream(resource);
if (in != null) {
try (final Scanner scanner = new Scanner(in)) {
if (scanner.hasNext()) {
return scanner.next();
}
}
}
return null;
}
public String label() { public String label() {
return label; return label;
} }
......
...@@ -199,7 +199,7 @@ public class VadereConsole { ...@@ -199,7 +199,7 @@ public class VadereConsole {
.setDefault("func", utilsSubCommand); .setDefault("func", utilsSubCommand);
misc.addArgument("-i") misc.addArgument("-i")
.required(true) .required(false)
.type(String.class) .type(String.class)
.dest("input") .dest("input")
.help("A input file or directory depending on called method."); .help("A input file or directory depending on called method.");
......
...@@ -5,6 +5,7 @@ import net.sourceforge.argparse4j.inf.Namespace; ...@@ -5,6 +5,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.vadere.simulator.entrypoints.ScenarioFactory; import org.vadere.simulator.entrypoints.ScenarioFactory;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.entrypoints.cmd.SubCommandRunner; import org.vadere.simulator.entrypoints.cmd.SubCommandRunner;
import org.vadere.simulator.models.potential.fields.IPotentialField; import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.PotentialFieldDistancesBruteForce; import org.vadere.simulator.models.potential.fields.PotentialFieldDistancesBruteForce;
...@@ -37,7 +38,8 @@ public class UtilsSubCommand implements SubCommandRunner { ...@@ -37,7 +38,8 @@ public class UtilsSubCommand implements SubCommandRunner {
methods.put("getHash", Pair.of("[-i: file, -o: ignored]", this::getHash)); methods.put("getHash", Pair.of("[-i: file, -o: ignored]", this::getHash));
methods.put("binCache", Pair.of("[-i: file, -o: directory]",this::calculateBinCache)); methods.put("binCache", Pair.of("[-i: file, -o: directory]",this::calculateBinCache));
methods.put("txtCache", Pair.of("[-i: file, -o: directory]",this::calculateTextCache)); methods.put("txtCache", Pair.of("[-i: file, -o: directory]",this::calculateTextCache));
methods.put("getVersion", Pair.of("returns version",this::getVersion));
methods.put("getCommitHash", Pair.of("returns commit hash",this::getCommitHash));
} }
public String[] methodsString(){ public String[] methodsString(){
...@@ -85,10 +87,22 @@ public class UtilsSubCommand implements SubCommandRunner { ...@@ -85,10 +87,22 @@ public class UtilsSubCommand implements SubCommandRunner {
* Return the hash used to check if a new cache value needed to be calculated. * Return the hash used to check if a new cache value needed to be calculated.
*/ */
private void getHash(Namespace ns, ArgumentParser parser) throws Exception{ private void getHash(Namespace ns, ArgumentParser parser) throws Exception{
Scenario scenario = createScenario(ns.getString("input")); calculateCache(ns, parser, CacheType.TXT_CACHE);
System.out.println(ScenarioCache.getHash(scenario)); }
/**
* Returns the current version
*/
private void getVersion(Namespace ns, ArgumentParser parser) throws Exception{
System.out.println(Version.releaseNumber());
} }
private void getCommitHash(Namespace ns, ArgumentParser parser) throws Exception{
System.out.println(Version.commitHash());
/* String filename = Resources.class.getResource("/current_commit_hash.txt").getFile();
String commit_hash = (new BufferedReader(new FileReader(filename))).readLine();
System.out.println(commit_hash); */
}
private void calculateBinCache(Namespace ns, ArgumentParser parser) throws Exception{ private void calculateBinCache(Namespace ns, ArgumentParser parser) throws Exception{
calculateCache(ns, parser, CacheType.BIN_CACHE); calculateCache(ns, parser, CacheType.BIN_CACHE);
......
package org.vadere.simulator.projects.io;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.util.logging.Logger;
import java.io.InputStream;
import java.util.Scanner;
public class HashGenerator {
private static Logger logger = Logger.getLogger(HashGenerator.class);
private static final String CURRENT_COMMIT_HASH_RESOURCE = "/current_commit_hash.txt";
public static String commitHash() {
String commitHash = getFirstStringTokenFromResource(CURRENT_COMMIT_HASH_RESOURCE);
if (commitHash == null) {
commitHash = "topographyWarning: no commit hash";
logger.warn("No commit hash found. The project will not contain a hash of the software source code.");
}
return commitHash;
}
public static String releaseNumber() {
return Version.latest().label();
}
private static String getFirstStringTokenFromResource(String resource) {
final InputStream in = HashGenerator.class.getResourceAsStream(resource);
if (in != null) {
try (final Scanner scanner = new Scanner(in)) {
if (scanner.hasNext()) {
return scanner.next();
}
}
}
return null;
}
}
\ No newline at end of file
...@@ -3,8 +3,8 @@ package org.vadere.simulator.projects.io; ...@@ -3,8 +3,8 @@ package org.vadere.simulator.projects.io;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.models.MainModel; import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.projects.Domain;
import org.vadere.simulator.projects.Scenario; import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.ScenarioStore; import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager; import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
...@@ -99,9 +99,9 @@ public class JsonConverter { ...@@ -99,9 +99,9 @@ public class JsonConverter {
private static void serializeMeta(ObjectNode node, boolean commitHashIncluded, ScenarioStore scenarioStore) { private static void serializeMeta(ObjectNode node, boolean commitHashIncluded, ScenarioStore scenarioStore) {
node.put("name", scenarioStore.getName()); node.put("name", scenarioStore.getName());
node.put("description", scenarioStore.getDescription()); node.put("description", scenarioStore.getDescription());
node.put("release", HashGenerator.releaseNumber()); node.put("release", Version.releaseNumber());
if (commitHashIncluded) if (commitHashIncluded)
node.put("commithash", HashGenerator.commitHash()); node.put("commithash", Version.commitHash());
} }
private static ObjectNode serializeVadereNode(ScenarioStore scenarioStore) { private static ObjectNode serializeVadereNode(ScenarioStore scenarioStore) {
......
Supports Markdown
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