]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics/src/org/simantics/SimanticsPlatform.java
Fixed various bugs in TG readers
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / SimanticsPlatform.java
index 3638d3407df271caa1869b2e9d97cc266e3b535e..ad3b86d9c989814c64fbb1783c5a8982fe60940c 100644 (file)
@@ -41,6 +41,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.osgi.service.datalocation.Location;
 import org.eclipse.osgi.service.resolver.BundleDescription;
 import org.ini4j.Ini;
 import org.ini4j.InvalidFileFormatException;
@@ -696,7 +697,42 @@ public class SimanticsPlatform implements LifecycleListener {
         resetDatabase(monitor);
     }
 
-    public boolean handleBaselineDatabase() throws PlatformException {
+    private static Path tryGetInstallLocation() {
+        Location l = Platform.getInstallLocation();
+        return l == null ? null : new File(l.getURL().getPath()).toPath();
+    }
+
+    private Path resolveBaselineFile() throws PlatformException {
+        String dbBaselineArchive = System.getProperty("org.simantics.db.baseline", null);
+        if (dbBaselineArchive == null)
+            return null;
+
+        Path baseline = Paths.get(dbBaselineArchive);
+        if (baseline.isAbsolute()) {
+            if (!Files.isRegularFile(baseline))
+                throw new PlatformException("Specified database baseline archive " + baseline
+                        + " does not exist. Cannot initialize workspace database from baseline.");
+            return baseline;
+        }
+
+        // Relative path resolution order:
+        // 1. from the platform "install location"
+        // 2. from working directory
+        Path installLocation = tryGetInstallLocation();
+        if (installLocation != null) {
+            Path installedBaseline = installLocation.resolve(dbBaselineArchive);
+            if (Files.isRegularFile(installedBaseline))
+                return installedBaseline;
+        }
+        if (!Files.isRegularFile(baseline))
+            throw new PlatformException("Specified database baseline archive " + baseline
+                    + " does not exist in either the install location (" + installLocation
+                    + ") or the working directory (" + Paths.get(".").toAbsolutePath()
+                    + "). Cannot initialize workspace database.");
+        return null;
+    }
+
+    private boolean handleBaselineDatabase() throws PlatformException {
         Path workspaceLocation = Platform.getLocation().toFile().toPath();
         Path baselineIndicatorFile = workspaceLocation.resolve(".baselined");
         if (Files.isRegularFile(baselineIndicatorFile)) {
@@ -705,14 +741,10 @@ public class SimanticsPlatform implements LifecycleListener {
             return true;
         }
 
-        String dbBaselineArchive = System.getProperty("org.simantics.db.baseline", null);
-        if (dbBaselineArchive == null)
+        Path baseline = resolveBaselineFile();
+        if (baseline == null)
             return false;
 
-        Path baseline = Paths.get(dbBaselineArchive);
-        if (!Files.isRegularFile(baseline))
-            throw new PlatformException("Specified database baseline archive " + baseline + " does not exist. Cannot initialize workspace database.");
-
         DatabaseBaselines.validateBaselineFile(baseline);
         DatabaseBaselines.validateWorkspaceForBaselineInitialization(workspaceLocation);
         DatabaseBaselines.initializeWorkspaceWithBaseline(baseline, workspaceLocation, baselineIndicatorFile);