]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Paster.getGraph() method for overriding classes."
authorMarko Luukkainen <Marko.Luukkainen@vtt.fi>
Thu, 11 May 2017 09:49:56 +0000 (12:49 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Thu, 11 May 2017 09:49:56 +0000 (12:49 +0300)
bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java
bundles/org.simantics.acorn/src/org/simantics/acorn/HeadState.java
bundles/org.simantics.acorn/src/org/simantics/acorn/MainState.java
bundles/org.simantics.acorn/src/org/simantics/acorn/internal/AcornDatabase.java
bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java
bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSRunner.java
bundles/pom.xml
features/org.simantics.sdk.feature/feature.xml

index 4c8df933777742532fcbf598f386362b81adafb5..9725ffe8da2df0aabb169b301b955642781205dd 100644 (file)
@@ -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);
index a6a1622c80027d68b11b05a7de6b6d1891bb26f5..ea54a418578c13dd335e6054ae547e51c4424092 100644 (file)
@@ -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) {
index ebc4079d51c64ccf1c2b40e372b89c3602e399cf..f5644c2aeda95b479ffab6f2331dc8c775a88f0e 100644 (file)
@@ -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);
index 12f0552e434e96638d6bdd7bcd22d440d3d9a674..a423fbdbe23b815871688fb17cb2c6fb165550f7 100644 (file)
@@ -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) {
index 15612d5fbd02905b8c2672d9621ad7d69dec719b..96276154237e11b31209dc1707c207edd68d8c71 100644 (file)
@@ -367,7 +367,7 @@ public class FileImportService {
 
     private static boolean isPerfectMatch(Set<String> candidates, String extension) {
         for (String ext : candidates) {
-            if (ext.startsWith("."))
+            if (ext.startsWith("*"))
                 ext = ext.substring(1);
             if (ext.equals(extension))
                 return true;
index 8171907bb93b9a6e802e8cac66146024140e1e5d..2311409f8f236699b47834d57d83d1f9ccf598dc 100644 (file)
@@ -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;
index 2df2507f771856901c27117fecaf107b56e5c114..beafd6ec71f61ea68e172b949025d296be6cb474 100644 (file)
@@ -89,6 +89,7 @@
                <module>org.simantics.db.procore.ui</module>
                <module>org.simantics.db.server</module>
                <module>org.simantics.db.services</module>
+               <module>org.simantics.db.testing</module>
                <module>org.simantics.debug.browser</module>
                <module>org.simantics.debug.browser.ui</module>
                <module>org.simantics.debug.graphical</module>
index fd56d697213a50233ff8ad0f14464daa6822f52c..603c6834cbb4d9e01054673d328e3550899fe60e 100644 (file)
          version="0.0.0"
          unpack="false"/>
 
+   <plugin
+         id="org.simantics.db.testing"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
 </feature>