Selaa lähdekoodia

Add very simple report viewer versioning. Shall be changed in the future.

Sebastian Hahner 4 vuotta sitten
vanhempi
commit
a449a80280

+ 2 - 1
.gitignore

@@ -5,7 +5,7 @@ target/
 
 *.class
 
-result
+
 
 # Mobile Tools for Java (J2ME)
 .mtj.tmp/
@@ -30,4 +30,5 @@ hs_err_pid*
 .antlr/
 
 # default result file name, should never be commited
+result/
 result.zip

+ 5 - 1
core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java

@@ -18,6 +18,7 @@ import java.util.Set;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
+import de.jplag.reporting.reportobject.model.Version;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,6 +43,9 @@ public class ReportObjectFactory {
     private static final ToDiskWriter fileWriter = new ToDiskWriter();
     public static final String OVERVIEW_FILE_NAME = "overview.json";
     public static final String SUBMISSIONS_FOLDER = "submissions";
+
+    // FIXME: This shall be moved to a better visible and upgradable position
+    public static final Version REPORT_VIEWER_VERSION = new Version(4, 0, 0);
     private Map<String, String> submissionNameToIdMap;
     private Function<Submission, String> submissionToIdFunction;
     private Map<String, Map<String, String>> submissionNameToNameToComparisonFileName;
@@ -141,7 +145,7 @@ public class ReportObjectFactory {
         String baseCodePath = result.getOptions().hasBaseCode() ? result.getOptions().baseCodeSubmissionDirectory().getName() : "";
         ClusteringResultMapper clusteringResultMapper = new ClusteringResultMapper(submissionToIdFunction);
 
-        OverviewReport overviewReport = new OverviewReport(folders.stream().map(File::getPath).toList(), // submissionFolderPath
+        OverviewReport overviewReport = new OverviewReport(REPORT_VIEWER_VERSION, folders.stream().map(File::getPath).toList(), // submissionFolderPath
                 baseCodePath, // baseCodeFolderPath
                 result.getOptions().language().getName(), // language
                 result.getOptions().fileSuffixes(), // fileExtensions

+ 2 - 0
core/src/main/java/de/jplag/reporting/reportobject/model/OverviewReport.java

@@ -8,6 +8,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 
 public record OverviewReport(
 
+        @JsonProperty("version") Version version,
+
         @JsonProperty("submission_folder_path") List<String> submissionFolderPath,
 
         @JsonProperty("base_code_folder_path") String baseCodeFolderPath,

+ 15 - 0
core/src/main/java/de/jplag/reporting/reportobject/model/Version.java

@@ -0,0 +1,15 @@
+package de.jplag.reporting.reportobject.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * This record represents a version number according to <a href="https://semver.org/">https://semver.org/</a>.
+ * This version number is used to compare generated result.zip files with the version of the report-viewer.
+ *
+ * @param major MAJOR version when you make incompatible API changes
+ * @param minor MINOR version when you add functionality in a backwards compatible manner
+ * @param patch PATCH version when you make backwards compatible bug fixes
+ */
+public record Version(@JsonProperty("major") int major, @JsonProperty("minor") int minor,
+                      @JsonProperty("patch") int patch) {
+}

+ 5 - 0
report-viewer/src/model/Version.ts

@@ -0,0 +1,5 @@
+export type Version = {
+    major: number,
+    minor: number,
+    patch: number
+}

+ 21 - 0
report-viewer/src/model/factories/OverviewFactory.ts

@@ -3,10 +3,23 @@ import { Metric } from "../Metric";
 import { ComparisonListElement } from "../ComparisonListElement";
 import { Cluster } from "@/model/Cluster";
 import store from "@/store/store";
+import { Version } from "../Version";
 
 export class OverviewFactory {
 
+  // FIXME: Find a better more visible position to store this
+  static reportViewerVersion: Version = {major: 4, minor: 0, patch: 0};
+
   static getOverview(json: Record<string, unknown>): Overview {
+    const jsonVersion = json.version as Record<string, number>;
+    const version: Version = {
+      major: jsonVersion.major,
+      minor: jsonVersion.minor,
+      patch: jsonVersion.patch
+    }
+
+    OverviewFactory.compareVersions(version, this.reportViewerVersion);
+
     const submissionFolder = json.submission_folder_path as Array<string>;
     const baseCodeFolder = "";
     const language = json.language as string;
@@ -68,6 +81,14 @@ export class OverviewFactory {
     );
   }
 
+  static compareVersions(jsonVersion: Version, reportViewerVersion: Version) {
+    if(jsonVersion.major !== reportViewerVersion.major ||
+       jsonVersion.minor !== reportViewerVersion.minor ||
+       jsonVersion.patch !== reportViewerVersion.patch) {
+        console.warn("The result's version tag does not fit the report viewer's version. Trying to read it anyhow but be careful.")
+       }
+  }
+
   private static  saveSubmissionsToComparisonNameMap(json: Record<string, unknown>){
     const submissionIdsToComparisonName =
     json.submission_ids_to_comparison_file_name as Map<