]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics/src/org/simantics/SimanticsPlatform.java
Easier baselines
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / SimanticsPlatform.java
index c0a85cd1ac1c06343b7a9bfb516b2efb84eb80fc..730e4e8877470439c8fd88cc8b47050db3bcfb66 100644 (file)
@@ -239,7 +239,7 @@ public class SimanticsPlatform implements LifecycleListener {
         if (progressMonitor == null)
             progressMonitor = new NullProgressMonitor();
         Path workspaceLocation = Platform.getLocation().toFile().toPath();
-        Path dbLocation = workspaceLocation.resolve("db");
+        Path dbLocation = dbLocation();
         Path dbIniPath = workspaceLocation.resolve("db.ini");
         // The driver file overrides any command line arguments to prevent
         // using the wrong driver for an existing database directory.
@@ -679,8 +679,9 @@ public class SimanticsPlatform implements LifecycleListener {
 
     public void resetDatabase(IProgressMonitor monitor) throws PlatformException {
         // TODO: fix this to use Path APIs
-        File dbLocation = Platform.getLocation().append("db").toFile();
-        if(!dbLocation.exists()) return;
+        File dbLocation = dbLocation().toFile();
+        if(!dbLocation.exists())
+            return;
         try { // Load driver
             Driver driver = Manager.getDriver("acorn");
             Management management = driver.getManagement(dbLocation.getAbsolutePath(), null);
@@ -721,53 +722,16 @@ public class SimanticsPlatform implements LifecycleListener {
         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.");
+    public Path databaseExists() {
+        Path dbLocation = dbLocation();
+        if(Files.exists(dbLocation))
+            return dbLocation;
         return null;
     }
-
-    private boolean handleBaselineDatabase() throws PlatformException {
+    
+    public Path dbLocation() {
         Path workspaceLocation = Platform.getLocation().toFile().toPath();
-        Path baselineIndicatorFile = workspaceLocation.resolve(".baselined");
-        if (Files.isRegularFile(baselineIndicatorFile)) {
-            // This means that the workspace has already been initialized from
-            // a database baseline and further initialization is not necessary.
-            return true;
-        }
-
-        Path baseline = resolveBaselineFile();
-        if (baseline == null)
-            return false;
-
-        DatabaseBaselines.validateBaselineFile(baseline);
-        DatabaseBaselines.validateWorkspaceForBaselineInitialization(workspaceLocation);
-        DatabaseBaselines.initializeWorkspaceWithBaseline(baseline, workspaceLocation, baselineIndicatorFile);
-        return true;
+        return workspaceLocation.resolve("db");
     }
 
     /**
@@ -827,7 +791,7 @@ public class SimanticsPlatform implements LifecycleListener {
 
         // 0.3 Handle baseline database before opening db
         @SuppressWarnings("unused")
-        boolean usingBaseline = handleBaselineDatabase();
+        boolean usingBaseline = DatabaseBaselines.handleBaselineDatabase(tryGetInstallLocation(), databaseExists() != null);
 
         // 1. Assert there is a database at <workspace>/db
         SessionDescriptor sessionDescriptor = setupDatabase(databaseDriverId, monitor.newChild(200, SubMonitor.SUPPRESS_NONE), workspacePolicy, userAgent);