From: Tuukka Lehtonen Date: Thu, 11 May 2017 10:55:39 +0000 (+0300) Subject: Merge "Fix RouteGraphNode styling" X-Git-Tag: v1.29.0~63 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=4ba2b2689c18c640afdd5ed8f65216e30b152674;hp=c684e246101adc478671274a9aae1979bfc02820 Merge "Fix RouteGraphNode styling" --- diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java index 4c8df9337..9725ffe8d 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java @@ -406,35 +406,39 @@ public class ClusterManager { lastSessionDirectory = dbFolder.resolve(Integer.toString(mainState.headDir - 1)); // Head State - try { - state = HeadState.load(lastSessionDirectory); - } catch (InvalidHeadStateException e) { - // For backwards compatibility only! - Throwable cause = e.getCause(); - if (cause instanceof Throwable) { - try { - org.simantics.db.javacore.HeadState oldState = org.simantics.db.javacore.HeadState.load(lastSessionDirectory); - - HeadState newState = new HeadState(); - newState.clusters = oldState.clusters; - newState.cs = oldState.cs; - newState.files = oldState.files; - newState.stream = oldState.stream; - newState.headChangeSetId = oldState.headChangeSetId; - newState.reservedIds = oldState.reservedIds; - newState.transactionId = oldState.transactionId; - state = newState; - } catch (InvalidHeadStateException e1) { - throw new IOException("Could not load HeadState due to corruption", e1); - } - } else { - // This should never happen as MainState.load() checks the integrity - // of head.state files and rolls back in cases of corruption until a - // consistent state is found (could be case 0 - initial db state) - // IF this does happen something is completely wrong - throw new IOException("Could not load HeadState due to corruption", e); - } - } + if (mainState.isInitial()) { + state = new HeadState(); + } else { + try { + state = HeadState.load(lastSessionDirectory); + } catch (InvalidHeadStateException e) { + // For backwards compatibility only! + Throwable cause = e.getCause(); + if (cause instanceof Throwable) { + try { + org.simantics.db.javacore.HeadState oldState = org.simantics.db.javacore.HeadState.load(lastSessionDirectory); + + HeadState newState = new HeadState(); + newState.clusters = oldState.clusters; + newState.cs = oldState.cs; + newState.files = oldState.files; + newState.stream = oldState.stream; + newState.headChangeSetId = oldState.headChangeSetId; + newState.reservedIds = oldState.reservedIds; + newState.transactionId = oldState.transactionId; + state = newState; + } catch (InvalidHeadStateException e1) { + throw new IOException("Could not load HeadState due to corruption", e1); + } + } else { + // This should never happen as MainState.load() checks the integrity + // of head.state files and rolls back in cases of corruption until a + // consistent state is found (could be case 0 - initial db state) + // IF this does happen something is completely wrong + throw new IOException("Could not load HeadState due to corruption", e); + } + } + } try { workingDirectory = dbFolder.resolve(Integer.toString(mainState.headDir)); Files.createDirectories(workingDirectory); diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/HeadState.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/HeadState.java index a6a1622c8..ea54a4185 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/HeadState.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/HeadState.java @@ -62,8 +62,7 @@ public class HeadState { HeadState1 old = HeadState1.load(directory); return old.migrate(); } - return new HeadState(); -// throw new InvalidHeadStateException(i); + throw new InvalidHeadStateException(i); } catch (NoSuchAlgorithmException e) { throw new Error("SHA-1 Algorithm not found", e); } catch (Throwable t) { diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/MainState.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/MainState.java index ebc4079d5..f5644c2ae 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/MainState.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/MainState.java @@ -38,6 +38,10 @@ public class MainState implements Serializable { private MainState(int headDir) { this.headDir = headDir; } + + public boolean isInitial() { + return this.headDir == 0; + } public static MainState load(Path directory, Runnable rollbackCallback) throws IOException { Files.createDirectories(directory); diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/internal/AcornDatabase.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/internal/AcornDatabase.java index 12f0552e4..a423fbdbe 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/internal/AcornDatabase.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/internal/AcornDatabase.java @@ -2,16 +2,14 @@ package org.simantics.acorn.internal; import java.io.File; import java.io.IOException; -import java.nio.channels.FileChannel; +import java.io.RandomAccessFile; import java.nio.channels.FileLock; import java.nio.file.DirectoryStream; -import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileVisitOption; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardOpenOption; import java.nio.file.attribute.BasicFileAttributes; import java.util.EnumSet; import java.util.Properties; @@ -41,7 +39,7 @@ public class AcornDatabase implements Database { private DatabaseUserAgent userAgent; - private FileChannel lockFileChannel; + private RandomAccessFile raLockFile; private FileLock lock; @@ -119,23 +117,17 @@ public class AcornDatabase implements Database { @Override public synchronized void start() throws ProCoreException { try { - try { - lockFileChannel = lockFile.getFileSystem().provider().newFileChannel(lockFile, - EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)); - } catch (FileAlreadyExistsException e) { - throw new ProCoreException("The database in folder " + folder.toAbsolutePath() + " is already in use!", e); - } - - lock = lockFileChannel.tryLock(); + raLockFile = new RandomAccessFile(lockFile.toFile(), "rw"); + lock = raLockFile.getChannel().tryLock(); if (lock == null) { - safeLoggingClose(lockFileChannel, lockFile); + safeLoggingClose(raLockFile, lockFile); throw new ProCoreException("The database in folder " + folder.toAbsolutePath() + " is already in use!"); } - isRunning = true; } catch (IOException e) { LOGGER.error("Failed to start database at " + folder.toAbsolutePath(), e); - safeLoggingClose(lockFileChannel, lockFile); + safeLoggingClose(raLockFile, lockFile); + throw new ProCoreException("Failed to start database at " + folder.toAbsolutePath(), e); } } @@ -151,8 +143,8 @@ public class AcornDatabase implements Database { try { safeLoggingClose(lock, lockFile); lock = null; - safeLoggingClose(lockFileChannel, lockFile); - lockFileChannel = null; + safeLoggingClose(raLockFile, lockFile); + raLockFile = null; Files.deleteIfExists(lockFile); isRunning = false; } catch (IOException e) { diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java index 15612d5fb..962761542 100644 --- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java @@ -367,7 +367,7 @@ public class FileImportService { private static boolean isPerfectMatch(Set candidates, String extension) { for (String ext : candidates) { - if (ext.startsWith(".")) + if (ext.startsWith("*")) ext = ext.substring(1); if (ext.equals(extension)) return true; diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSRunner.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSRunner.java index 8171907bb..2311409f8 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSRunner.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSRunner.java @@ -1,7 +1,5 @@ package org.simantics.tests.modelled.junit; -import java.util.List; - import org.junit.runner.Description; import org.junit.runner.Result; import org.junit.runner.Runner; diff --git a/bundles/pom.xml b/bundles/pom.xml index 2df2507f7..beafd6ec7 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -89,6 +89,7 @@ org.simantics.db.procore.ui org.simantics.db.server org.simantics.db.services + org.simantics.db.testing org.simantics.debug.browser org.simantics.debug.browser.ui org.simantics.debug.graphical diff --git a/features/org.simantics.sdk.feature/feature.xml b/features/org.simantics.sdk.feature/feature.xml index fd56d6972..603c6834c 100644 --- a/features/org.simantics.sdk.feature/feature.xml +++ b/features/org.simantics.sdk.feature/feature.xml @@ -258,4 +258,11 @@ version="0.0.0" unpack="false"/> + +