]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "(refs #7042) Added a new compiler optimization (eta-reduce)"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 20 Feb 2017 10:13:29 +0000 (12:13 +0200)
committerGerrit Code Review <gerrit2@www.simantics.org>
Mon, 20 Feb 2017 10:13:29 +0000 (12:13 +0200)
14 files changed:
bundles/org.simantics.fileimport.ui/META-INF/MANIFEST.MF
bundles/org.simantics.fileimport.ui/src/org/simantics/fileimport/ui/ImportFileHandler.java
bundles/org.simantics.fileimport/META-INF/MANIFEST.MF
bundles/org.simantics.fileimport/scl/Dropins/Core.scl
bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java
bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java
bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileReferenceFileImport.java
bundles/org.simantics.fileimport/src/org/simantics/fileimport/LibraryFolderFileImport.java
bundles/org.simantics.fileimport/src/org/simantics/fileimport/scl/DropinsSCL.java
bundles/org.simantics.g2d/src/org/simantics/g2d/chassis/AWTChassis.java
bundles/org.simantics.simulation/META-INF/MANIFEST.MF
bundles/org.simantics.simulation/src/org/simantics/simulation/project/ExperimentManager.java
bundles/org.simantics.spreadsheet.fileimport/src/org/simantics/spreadsheet/fileimport/ExcelFileImport.java
features/org.simantics.ui.workbench.feature/feature.xml

index 94cc4b9d270782b7654d5c19fe365f2602fb87e1..db1100bc370c780c823d029993b6c597e4c36540 100644 (file)
@@ -9,7 +9,8 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100.v20150407-1430",
  org.eclipse.e4.core.di,
  org.eclipse.e4.ui.services,
- org.simantics.fileimport;bundle-version="1.0.0"
+ org.simantics.fileimport;bundle-version="1.0.0",
+ org.slf4j.api
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Import-Package: javax.inject;version="1.0.0"
 Bundle-ActivationPolicy: lazy
index 3da6858a3f35ef51021632aab00ecfb95d07cb2d..21f8d3c4d8b6dc52767e3b1b9b5b8357df192191 100644 (file)
@@ -4,6 +4,7 @@ package org.simantics.fileimport.ui;
 import java.nio.file.Paths;
 import java.util.Map;
 import java.util.Optional;
+import java.util.function.Consumer;
 
 import javax.inject.Named;
 
@@ -14,9 +15,13 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Shell;
 import org.simantics.fileimport.FileImportService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ImportFileHandler {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(ImportFileHandler.class);
+    
     @CanExecute
     public boolean canExecute() {
         return !FileImportService.supportedExtensionsWithFilters().isEmpty();
@@ -44,6 +49,9 @@ public class ImportFileHandler {
         final String fileName = dialog.open();
         if (fileName == null)
             return;
-        FileImportService.performFileImport(Paths.get(fileName), Optional.empty());
+
+        FileImportService.performFileImport(Paths.get(fileName), Optional.of((Consumer<Throwable>) t -> {
+            LOGGER.error("Could not import file " + fileName, t);
+        }));
     }
 }
\ No newline at end of file
index bbb632778cee2fbd035dbab3e06afaf990d0d12a..a8d8f0752c54d45171227163e5d40f34f0ffc570 100644 (file)
@@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.core.runtime,
  org.simantics,
  org.simantics.graphfile;bundle-version="0.1.0",
  org.simantics.graphfile.ontology;bundle-version="0.1.0",
- org.simantics.modeling;bundle-version="1.1.1"
+ org.simantics.modeling;bundle-version="1.1.1",
+ org.slf4j.api
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
 Export-Package: org.simantics.fileimport
index 7b3c354a35ddd40e73c9302a9a1af7c900b4559e..878326ba1e4ee6c7b42e99cc7f469f17071629f5 100644 (file)
@@ -7,6 +7,10 @@ importJava "org.simantics.fileimport.scl.DropinsSCL" where
     getUploadedFiles :: () -> <Proc> MMap.T String Long
     removeFileForId :: Long -> <Proc> ()
 
+
+importJava "org.simantics.fileimport.FileImportService" where
+    performFileImport :: String -> String -> <Proc> String
+
 getUploadedDropinFiles :: () -> <Proc> [Long]
 getUploadedDropinFiles dummy = do
     files = getUploadedFiles ()
index 9c0f77072c2cdbecb0071f3ac8f9022e36837902..2918674518aade7bed60e1780686ab5c8d18efea 100644 (file)
@@ -13,8 +13,9 @@ import org.simantics.fileimport.dropins.FileImportDropins;
 
 public class Activator implements BundleActivator {
 
-       private static BundleContext context;
+    private static BundleContext context;
        
+    private static Path modelsFolder = null;
        private static Path dropinsFolder = null;
 
        static BundleContext getContext() {
@@ -48,4 +49,14 @@ public class Activator implements BundleActivator {
            return dropinsFolder;
        }
 
+    public static Path getModelsFolder() throws IOException {
+        if (modelsFolder == null) {
+            IPath state = Platform.getStateLocation(context.getBundle());
+            modelsFolder = Paths.get(state.append("models").toOSString());
+            if (!Files.exists(modelsFolder))
+                Files.createDirectories(modelsFolder);
+        }
+        return modelsFolder;
+    }
+
 }
index fcbd3cc30c33a04f87993e8307a1fda32b895fc4..ddb9dabae71478a184ef9845af5debd7097327a8 100644 (file)
@@ -17,7 +17,11 @@ import java.util.function.Consumer;
 
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
+import org.simantics.databoard.util.Base64;
 import org.simantics.fileimport.dropins.FileImportDropins;
+import org.simantics.utils.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Utility class for Simantics File import functions
@@ -27,6 +31,8 @@ import org.simantics.fileimport.dropins.FileImportDropins;
  */
 public class FileImportService {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(FileImportService.class);
+    
     private FileImportService() {}
     
     public static final String DB_FILE = ".simanticsdb";
@@ -37,7 +43,7 @@ public class FileImportService {
             serviceReferences = Activator.getContext().getAllServiceReferences(IGenericFileImport.class.getName(),
                     null);
         } catch (InvalidSyntaxException e) {
-            e.printStackTrace();
+            LOGGER.error("Could not get service references for IGenericFileImport!", e);
         }
         if (serviceReferences.length == 0)
             return Collections.emptyList();
@@ -63,6 +69,33 @@ public class FileImportService {
 
         return extensionsWithFilters;
     }
+    
+    private static class ConsumerHolder implements Consumer<Throwable> {
+
+        private Throwable throwable;
+        
+        @Override
+        public void accept(Throwable t) {
+            throwable = t;
+        }
+        
+        public Throwable getThrowable() {
+            return throwable;
+        }
+        
+    }
+    
+    public static String performFileImport(String base64, String name) throws Throwable {
+        byte[] bytes = Base64.decode(base64);
+        Path file = Activator.getModelsFolder().resolve(name);
+        Files.write(file, bytes);
+        
+        ConsumerHolder holder = new ConsumerHolder();
+        String result = performFileImport(file, Optional.of(holder));
+        if (holder.getThrowable() != null)
+            throw holder.getThrowable();
+        return result;
+    }
 
     /**
      * Method that performs the import of the given file. This method is called when e.g. {@link FileImportDropins} watcher detects {@link java.nio.file.StandardWatchEventKinds.ENTRY_CREATE} operation
@@ -70,22 +103,31 @@ public class FileImportService {
      * @param file Path file to be imported
      * @param callback Optional callback which can be used to catch Throwables thrown in the import process
      */
-    public static void performFileImport(Path file, Optional<Consumer<Throwable>> callback) {
-        if (file.getFileName().toString().equals(DB_FILE))
-            return;
+    public static String performFileImport(Path file, Optional<Consumer<Throwable>> callback) {
+        if (file.getFileName().toString().equals(DB_FILE)) {
+            return null;
+        }
+        String result = "Import failed";
         Optional<IGenericFileImport> serviceOp = findServiceForFileExtension(file);
-        serviceOp.ifPresent(service -> {
+        if (serviceOp.isPresent()) {
+            IGenericFileImport service = serviceOp.get();
             try {
                 Optional<String> resource = service.perform(file);
                 saveResourceForPath(file, resource);
+                result = resource.get();
             } catch (Throwable t) {
                 if (callback.isPresent()) {
                     callback.get().accept(t);
                 } else {
-                    t.printStackTrace();
+                    LOGGER.error("Could not import file " + file, t);
                 }
             }
-        });
+        } else {
+            LOGGER.warn("Could not find service for importing file " + file);
+            if (callback.isPresent())
+                callback.get().accept(new Exception("Could not find IGenericFileImport service for file " + file));
+        }
+        return result;
     }
 
     
index 2fea9fde3dd2baac7146293af64b0c640862d513..aa367178125860447af3614a4a01086e3da77ea0 100644 (file)
@@ -6,21 +6,15 @@ import java.util.Map;
 import java.util.Optional;
 
 import org.simantics.db.Resource;
-import org.simantics.db.exception.DatabaseException;
 import org.simantics.graphfile.util.GraphFileUtil;
 
 public class FileReferenceFileImport extends SimanticsResourceFileImport {
 
-    private static final Map<String, String> ALLOWED_EXTENSIONS = Collections.singletonMap("*.asd", "All files");
+    private static final Map<String, String> ALLOWED_EXTENSIONS = Collections.singletonMap("*", "All files");
     
     @Override
-    public Optional<Resource> perform(Resource parent, Path file) {
-        try {
-            return Optional.of(GraphFileUtil.createFileReference(parent, file));
-        } catch (DatabaseException e) {
-            e.printStackTrace();
-            return Optional.empty();
-        }
+    public Optional<Resource> perform(Resource parent, Path file) throws Exception {
+        return Optional.of(GraphFileUtil.createFileReference(parent, file));
     }
 
     @Override
index 40deb1c148a7c5652ae0569d8e1606793b1d2c85..012c757c214c4a2914703fa6c6341e0ed6d185c8 100644 (file)
@@ -22,19 +22,14 @@ public class LibraryFolderFileImport extends SimanticsResourceFileImport {
     }
 
     @Override
-    public Optional<Resource> perform(Resource parent, Path file) {
+    public Optional<Resource> perform(Resource parent, Path file) throws Exception {
         final String name = file.getFileName().toString();
-        try {
-            return Optional.of(Simantics.getSession().syncRequest(new WriteResultRequest<Resource>() {
+        return Optional.of(Simantics.getSession().syncRequest(new WriteResultRequest<Resource>() {
 
-                @Override
-                public Resource perform(WriteGraph graph) throws DatabaseException {
-                    return ModelingUtils.createLibrary(graph, parent, name);
-                }
-            }));
-        } catch (DatabaseException e) {
-            e.printStackTrace();
-            return Optional.empty();
-        }
+            @Override
+            public Resource perform(WriteGraph graph) throws DatabaseException {
+                return ModelingUtils.createLibrary(graph, parent, name);
+            }
+        }));
     }
 }
index 74d2a0322f45c426e0fffa1434e888641e69632c..50fd584466bedd5849d950b9c778f80b16441fa3 100644 (file)
@@ -21,6 +21,8 @@ import org.simantics.fileimport.FileImportService;
 import org.simantics.fileimport.dropins.FileImportDropins;
 import org.simantics.layer0.Layer0;
 import org.simantics.utils.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * SCL interface for Simantics File Import Functionality
@@ -30,6 +32,8 @@ import org.simantics.utils.FileUtils;
  *
  */
 public class DropinsSCL {
+    
+    private static final Logger LOGGER = LoggerFactory.getLogger(DropinsSCL.class);
 
     public static void watchDropinsFolder() {
         FileImportDropins.watchDropinsFolder();
@@ -42,8 +46,9 @@ public class DropinsSCL {
     public static void uploadToDropinsBase64(String base64, String fileName) {
         // ensure that watcher is awake
         FileImportDropins.watchDropinsFolder();
+        Path rootFolder = null;
         try {
-            Path rootFolder = Activator.getDropinsFolder();
+            rootFolder = Activator.getDropinsFolder();
             Path newFile = rootFolder.resolve(fileName);
             if (Files.exists(newFile)) {
                 newFile = findFreshFileName(rootFolder, fileName);
@@ -51,7 +56,7 @@ public class DropinsSCL {
             byte[] bytes = Base64.decode(base64);
             FileUtils.writeFile(newFile.toFile(), bytes);
         } catch (IOException e) {
-            e.printStackTrace();
+            LOGGER.error("Could not upload base64 to file " + (rootFolder != null ? rootFolder.resolve(fileName).toAbsolutePath() : ""), e);
         }
     }
 
index 17304ef3e548da3642672c21993c6f4e4042e6c8..2679ef620ac5c87b65de2337c9a188219895a88e 100644 (file)
@@ -81,6 +81,8 @@ public class AWTChassis extends JComponent implements ICanvasChassis {
     private transient boolean                    closed           = false;
     protected ICanvasContext                     canvasContext;
 
+    private boolean useVolatileImage = true;
+    
     // Marks the content dirty
     protected IContentListener contentListener = new IContentListener() {
         @Override
@@ -277,6 +279,14 @@ public class AWTChassis extends JComponent implements ICanvasChassis {
     public IHintContext getHintContext() {
         return hintCtx;
     }
+    
+    public void setUseVolatileImage(boolean useVolatileImage) {
+               this.useVolatileImage = useVolatileImage;
+       }
+    
+    public boolean isUseVolatileImage() {
+               return useVolatileImage;
+       }
 
     private void paintScenegraph(Graphics2D g2d, Rectangle controlBounds) {
         Color bg = getBackground();
@@ -355,7 +365,9 @@ public class AWTChassis extends JComponent implements ICanvasChassis {
             startmem = Runtime.getRuntime().freeMemory();
             start = System.nanoTime();
         }
-        VolatileImage buffer = paintToVolatileImage(g2d, b);
+        VolatileImage buffer = null;
+        if (useVolatileImage)
+               buffer = paintToVolatileImage(g2d, b);
         if (closed)
             return;
         if (DebugPolicy.PERF_CHASSIS_RENDER_FRAME) {
index 53d5638b242daabe6e2f682d3514091163a1a2cd..f1ba40ed48468bdc5d834b193578a12c894beede 100644 (file)
@@ -12,7 +12,8 @@ Require-Bundle: org.simantics.ui;bundle-version="1.0.0",
  org.simantics.modeling.ontology;bundle-version="1.2.0",
  org.simantics.fastlz;bundle-version="1.2.1",
  org.apache.commons.compress;bundle-version="1.7.0",
- org.simantics.lz4;bundle-version="1.3.0"
+ org.simantics.lz4;bundle-version="1.3.0",
+ org.slf4j.api;bundle-version="1.7.0"
 Export-Package: org.simantics.simulation,
  org.simantics.simulation.data,
  org.simantics.simulation.experiment,
index ec56854751f55bc5d5666cb29422b6a7ff10e184..613346b1147830521336c31d7a64c761e0f6da60 100644 (file)
@@ -37,12 +37,16 @@ import org.simantics.simulation.experiment.IExperimentListener;
 import org.simantics.simulation.model.IModel;
 import org.simantics.ui.workbench.WorkbenchShutdownService;
 import org.simantics.utils.datastructures.ListenerList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Simple local ExperimentManager implementation
  */
 public class ExperimentManager implements IExperimentManager {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(ExperimentManager.class);
+
     CopyOnWriteArrayList<IExperimentManagerListener> listeners = new CopyOnWriteArrayList<IExperimentManagerListener>();
     ListenerList<IExperiment> experiments = new ListenerList<IExperiment>(IExperiment.class);
     IExperiment activeExperiment;
@@ -218,9 +222,9 @@ public class ExperimentManager implements IExperimentManager {
 
             if (!listeners.isEmpty()) {
                 // Some clients are leaking listeners. Shame on them.
-                System.err.println("ExperimentManager still contains the following listeners after disposal:");
+                LOGGER.warn("ExperimentManager still contains the following listeners after disposal:");
                 for (IExperimentManagerListener listener : listeners)
-                    System.err.println("\t" + listener);
+                    LOGGER.warn("\t" + listener);
             }
         }
     }
index 3963f6e7b1b6d0857b8d58d8e68fd67c682d4c47..6719f5913fd6c288a741b6c0359d69d0eb47444b 100644 (file)
@@ -18,8 +18,8 @@ public class ExcelFileImport extends SimanticsResourceFileImport {
     }
     
     @Override
-    public Optional<Resource> perform(Resource parent, Path file) {
-        return Optional.empty();
+    public Optional<Resource> perform(Resource parent, Path file) throws Exception {
+        throw new UnsupportedOperationException("Excel import is not yet supported");
     }
 
     @Override
index dfa20f265dd3b23f97fcda08e4b721993edac93b..b234acd5cc5bf988c7073d2c48370e383fecb052 100644 (file)
          version="0.0.0"
          unpack="false"/>
 
+  <plugin
+         id="org.eclipse.jetty.http"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="org.eclipse.jetty.server"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="org.eclipse.jetty.servlet"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="org.eclipse.jetty.util"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="org.eclipse.jetty.io"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="org.eclipse.jetty.security"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="org.eclipse.ui.cheatsheets"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="javax.servlet"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
 </feature>