Commit 81c53181 authored by Marion Goedel's avatar Marion Goedel
Browse files

Refactoring: Removed HashGenerator and moved functionality in Version.java

parent b2b17f64
Pipeline #225050 passed with stages
in 127 minutes and 25 seconds
......@@ -4,7 +4,7 @@ import javax.swing.*;
import org.vadere.gui.components.utils.Messages;
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.text.MessageFormat;
......@@ -22,7 +22,7 @@ public class ActionShowAboutDialog extends AbstractAction {
public void actionPerformed(final ActionEvent event) {
String text = "";
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 += "<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>";
......
package org.vadere.simulator.entrypoints;
import org.jetbrains.annotations.NotNull;
import org.vadere.util.logging.Logger;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Optional;
import java.util.Scanner;
/**
* Versions in strict order from oldest to newest.
*/
public enum Version {
UNDEFINED("undefined"),
NOT_A_RELEASE("not a release"),
V0_1(0, 1),
......@@ -35,14 +36,16 @@ public enum Version {
V1_8(1, 8),
V1_9(1, 9),
V1_10(1, 10),
V1_11(1, 11),
;
V1_11(1, 11);
private static Logger logger = Logger.getLogger(Version.class);
private String label;
private int major;
private int minor;
private static final String CURRENT_COMMIT_HASH_RESOURCE = "/current_commit_hash.txt";
Version(String label) {
this.major = -1;
......@@ -56,6 +59,35 @@ public enum Version {
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() {
return label;
}
......
package org.vadere.simulator.entrypoints.cmd.commands;
import com.google.common.io.Resources;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.Namespace;
......@@ -13,7 +12,6 @@ import org.vadere.simulator.models.potential.fields.PotentialFieldDistancesBrute
import org.vadere.simulator.models.potential.solver.EikonalSolverCacheProvider;
import org.vadere.simulator.projects.Domain;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.io.HashGenerator;
import org.vadere.simulator.utils.cache.ScenarioCache;
import org.vadere.state.attributes.models.AttributesFloorField;
import org.vadere.state.scenario.Target;
......@@ -21,9 +19,6 @@ import org.vadere.state.types.CacheType;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.logging.Logger;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
......@@ -99,14 +94,14 @@ public class UtilsSubCommand implements SubCommandRunner {
* Returns the current version
*/
private void getVersion(Namespace ns, ArgumentParser parser) throws Exception{
System.out.println(Version.latest().toString());
System.out.println(Version.releaseNumber());
}
private void getCommitHash(Namespace ns, ArgumentParser parser) throws Exception{
System.out.println(HashGenerator.commitHash());
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); */
System.out.println(commit_hash); */
}
private void calculateBinCache(Namespace ns, ArgumentParser parser) throws Exception{
......
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;
import java.io.IOException;
import java.util.List;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.projects.Domain;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
......@@ -99,9 +99,9 @@ public class JsonConverter {
private static void serializeMeta(ObjectNode node, boolean commitHashIncluded, ScenarioStore scenarioStore) {
node.put("name", scenarioStore.getName());
node.put("description", scenarioStore.getDescription());
node.put("release", HashGenerator.releaseNumber());
node.put("release", Version.releaseNumber());
if (commitHashIncluded)
node.put("commithash", HashGenerator.commitHash());
node.put("commithash", Version.commitHash());
}
private static ObjectNode serializeVadereNode(ScenarioStore scenarioStore) {
......
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