X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics%2Fsrc%2Forg%2Fsimantics%2FSimanticsPlatform.java;h=ad3b86d9c989814c64fbb1783c5a8982fe60940c;hp=3638d3407df271caa1869b2e9d97cc266e3b535e;hb=69d8f2b115a832560eca0d56903c8977178b71ab;hpb=9ea5cf59a4d87c3db3a486e86d7b54efffd5516d diff --git a/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java b/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java index 3638d3407..ad3b86d9c 100644 --- a/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java +++ b/bundles/org.simantics/src/org/simantics/SimanticsPlatform.java @@ -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);