From: Hannu Niemistö Date: Tue, 16 Aug 2016 11:08:02 +0000 (+0300) Subject: Merge remote-tracking branch 'origin/svn' X-Git-Tag: v1.25.0~174 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c1e8357dfbda3a12efbe2243a505200beb9aed71;hp=93771ec80d6630bf6b31b1bf9f62b05277e95074;p=simantics%2Fplatform.git Merge remote-tracking branch 'origin/svn' Change-Id: Ib64bce0e85c78300c078f16a948d9db2f4872ed5 --- diff --git a/bundles/org.simantics.backup.db/.classpath b/bundles/org.simantics.backup.db/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.backup.db/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.backup.db/.project b/bundles/org.simantics.backup.db/.project new file mode 100644 index 000000000..7dca7f136 --- /dev/null +++ b/bundles/org.simantics.backup.db/.project @@ -0,0 +1,33 @@ + + + org.simantics.backup.db + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.simantics.backup.db/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.backup.db/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.backup.db/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.backup.db/META-INF/MANIFEST.MF b/bundles/org.simantics.backup.db/META-INF/MANIFEST.MF new file mode 100644 index 000000000..27255bf14 --- /dev/null +++ b/bundles/org.simantics.backup.db/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Modelled Backup Provider +Bundle-SymbolicName: org.simantics.backup.db +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.simantics.backup.db.Activator +Require-Bundle: org.simantics, + org.simantics.backup.ontology, + org.simantics.backup +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Service-Component: OSGI-INF/component.xml diff --git a/bundles/org.simantics.backup.db/OSGI-INF/component.xml b/bundles/org.simantics.backup.db/OSGI-INF/component.xml new file mode 100644 index 000000000..6b299801b --- /dev/null +++ b/bundles/org.simantics.backup.db/OSGI-INF/component.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.backup.db/build.properties b/bundles/org.simantics.backup.db/build.properties new file mode 100644 index 000000000..5a2708a18 --- /dev/null +++ b/bundles/org.simantics.backup.db/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + scl/,\ + OSGI-INF/component.xml diff --git a/bundles/org.simantics.backup.db/scl/Simantics/Backup.scl b/bundles/org.simantics.backup.db/scl/Simantics/Backup.scl new file mode 100644 index 000000000..1fafb0113 --- /dev/null +++ b/bundles/org.simantics.backup.db/scl/Simantics/Backup.scl @@ -0,0 +1,15 @@ +import "Simantics/DB" + +importJava "org.simantics.backup.IBackupProvider" where + data IBackupProvider + +importJava "org.simantics.backup.db.ModelledBackup" where + modelledBackup :: + ( ()) -> + (String -> Integer -> (() -> Maybe String)) -> + ( ()) -> + (String -> Integer -> ()) -> + IBackupProvider + +importJava "org.simantics.backup.BackupProviderService" where + backup :: String -> Integer -> () \ No newline at end of file diff --git a/bundles/org.simantics.backup.db/src/org/simantics/backup/db/Activator.java b/bundles/org.simantics.backup.db/src/org/simantics/backup/db/Activator.java new file mode 100644 index 000000000..8f87f9a30 --- /dev/null +++ b/bundles/org.simantics.backup.db/src/org/simantics/backup/db/Activator.java @@ -0,0 +1,30 @@ +package org.simantics.backup.db; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + private static BundleContext context; + + static BundleContext getContext() { + return context; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext bundleContext) throws Exception { + Activator.context = bundleContext; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext bundleContext) throws Exception { + Activator.context = null; + } + +} diff --git a/bundles/org.simantics.backup.db/src/org/simantics/backup/db/ModelledBackup.java b/bundles/org.simantics.backup.db/src/org/simantics/backup/db/ModelledBackup.java new file mode 100644 index 000000000..258915ce8 --- /dev/null +++ b/bundles/org.simantics.backup.db/src/org/simantics/backup/db/ModelledBackup.java @@ -0,0 +1,82 @@ +package org.simantics.backup.db; + +import java.nio.file.Path; +import java.util.concurrent.Callable; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; + +import org.simantics.backup.BackupException; +import org.simantics.backup.IBackupProvider; +import org.simantics.scl.runtime.function.Function1; +import org.simantics.scl.runtime.function.Function2; +import org.simantics.scl.runtime.tuple.Tuple0; + +public class ModelledBackup implements IBackupProvider { + + private final Function1 lockFunc; + private final Function2> backupFunc; + private final Function1 unlockFunc; + private final Function2 restoreFunc; + + private ModelledBackup( + Function1 lockFunc, + Function2> backupFunc, + Function1 unlockFunc, + Function2 restoreFunc) { + this.lockFunc = lockFunc; + this.backupFunc = backupFunc; + this.unlockFunc = unlockFunc; + this.restoreFunc = restoreFunc; + } + + @Override + public void lock() { + lockFunc.apply(Tuple0.INSTANCE); + } + + @Override + public Future backup(Path targetPath, int revision) { + + final Function1 fn = backupFunc.apply(targetPath.toString(), revision); + + final FutureTask futureTask = new FutureTask(new Callable() { + @Override + public BackupException call() throws Exception { + try { + String error = fn.apply(Tuple0.INSTANCE); + if (error != null) { + return new BackupException(error); + } else { + return null; + } + } catch (Throwable t) { + return new BackupException(t); + } + } + }); + + Thread thread = new Thread(futureTask, "Backup Provider Thread " + backupFunc.toString()); + thread.start(); + + return futureTask; + } + + @Override + public void unlock() { + unlockFunc.apply(Tuple0.INSTANCE); + } + + @Override + public void restore(Path fromPath, int revision) { + restoreFunc.apply(fromPath.toString(), revision); + } + + public static IBackupProvider modelledBackup( + Function1 lockFunc, + Function2> backupFunc, + Function1 unlockFunc, + Function2 restoreFunc) { + + return new ModelledBackup(lockFunc, backupFunc, unlockFunc, restoreFunc); + } +} diff --git a/bundles/org.simantics.backup.db/src/org/simantics/backup/db/ModelledBackupProvider.java b/bundles/org.simantics.backup.db/src/org/simantics/backup/db/ModelledBackupProvider.java new file mode 100644 index 000000000..3aaefabbc --- /dev/null +++ b/bundles/org.simantics.backup.db/src/org/simantics/backup/db/ModelledBackupProvider.java @@ -0,0 +1,133 @@ +package org.simantics.backup.db; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Status; +import org.simantics.Simantics; +import org.simantics.backup.Activator; +import org.simantics.backup.BackupException; +import org.simantics.backup.Backups; +import org.simantics.backup.IBackupProvider; +import org.simantics.backup.ontology.BackupResource; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Instances; +import org.simantics.db.layer0.util.Layer0Utils; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; + +public class ModelledBackupProvider implements IBackupProvider { + + List modelledBackups = new ArrayList<>(); + + public ModelledBackupProvider() { + // Should this be on the constructor or can there be dynamic ontologies? + this.modelledBackups = getModelledBackups(); + } + + @Override + public void lock() throws BackupException { + Backups.lock(modelledBackups); + } + + @Override + public Future backup(Path targetPath, int revision) throws BackupException { + final List> backups = new ArrayList<>(); + final List exceptions = new ArrayList<>(backups.size()); + for (IBackupProvider modelledBackup : modelledBackups) { + try { + Future future = modelledBackup.backup(targetPath, revision); + backups.add(future); + } catch (BackupException e) { + exceptions.add(e); + } + } + FutureTask task = new FutureTask<>(new Callable() { + + @Override + public BackupException call() throws Exception { + for (Future f : backups) { + try { + Exception exception = f.get(); + if (exception != null) + exceptions.add(exception); + } catch (InterruptedException | ExecutionException e) { + exceptions.add(e); + } + } + BackupException problem = null; + // Throw BackupException if any of the backup operations failed. + if (!exceptions.isEmpty()) { + IStatus[] ss = exceptions.stream() + .map(e -> new Status(IStatus.ERROR, Activator.BUNDLE_ID, e.getMessage(), e)) + .toArray(IStatus[]::new); + problem = new BackupException(new CoreException(new MultiStatus(Activator.BUNDLE_ID, 0, ss, + "Backup operation(s) failed to complete.", null))); + } + return problem; + } + }); + new Thread(task).run(); + return task; + } + + @Override + public void unlock() throws BackupException { + Backups.unlock(modelledBackups); + } + + @Override + public void restore(Path fromPath, int revision) throws BackupException { + for (IBackupProvider modelledBackup : modelledBackups) { + modelledBackup.restore(fromPath, revision); + } + } + + + private List getModelledBackups() { + List modelledProviders = new ArrayList<>(0); + try { + modelledProviders = Simantics.getSession().syncRequest(new UniqueRead>() { + + @Override + public List perform(ReadGraph graph) throws DatabaseException { + BackupResource BACKUP = BackupResource.getInstance(graph); + Instances query = graph.adapt(BACKUP.ModelledBackupProvider, Instances.class); + + HashSet providers = new HashSet<>(); + + List ontologies = Layer0Utils.listOntologies(graph); + for (Resource ontology : ontologies) { + for(Resource provider : query.find(graph, ontology)) { + providers.add(provider); + } + } + List modelledBackups = new ArrayList<>(); + for (Resource provider : providers) { + Variable variable = Variables.getVariable(graph, provider); + IBackupProvider modelledBackup = variable.getPropertyValue(graph, "instance"); + modelledBackups.add(modelledBackup); + } + + return modelledBackups; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return modelledProviders; + } + +} diff --git a/bundles/org.simantics.backup.ontology/.classpath b/bundles/org.simantics.backup.ontology/.classpath new file mode 100644 index 000000000..b1dabee38 --- /dev/null +++ b/bundles/org.simantics.backup.ontology/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.backup.ontology/.project b/bundles/org.simantics.backup.ontology/.project new file mode 100644 index 000000000..af5199b11 --- /dev/null +++ b/bundles/org.simantics.backup.ontology/.project @@ -0,0 +1,34 @@ + + + org.simantics.backup.ontology + + + + + + org.simantics.graph.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.simantics.graph.nature + + diff --git a/bundles/org.simantics.backup.ontology/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.backup.ontology/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..11f6e462d --- /dev/null +++ b/bundles/org.simantics.backup.ontology/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/bundles/org.simantics.backup.ontology/META-INF/MANIFEST.MF b/bundles/org.simantics.backup.ontology/META-INF/MANIFEST.MF new file mode 100644 index 000000000..94a4bfa73 --- /dev/null +++ b/bundles/org.simantics.backup.ontology/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics Backup Ontology +Bundle-SymbolicName: org.simantics.backup.ontology +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.simantics.backup.ontology.Activator +Require-Bundle: org.eclipse.core.runtime, + org.simantics.layer0, + org.simantics.structural.ontology;bundle-version="1.2.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-ActivationPolicy: lazy +Export-Package: org.simantics.backup.ontology diff --git a/bundles/org.simantics.backup.ontology/build.properties b/bundles/org.simantics.backup.ontology/build.properties new file mode 100644 index 000000000..022de1735 --- /dev/null +++ b/bundles/org.simantics.backup.ontology/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + graph.tg diff --git a/bundles/org.simantics.backup.ontology/graph.tg b/bundles/org.simantics.backup.ontology/graph.tg new file mode 100644 index 000000000..bcb6d8562 Binary files /dev/null and b/bundles/org.simantics.backup.ontology/graph.tg differ diff --git a/bundles/org.simantics.backup.ontology/graph/Backup.pgraph b/bundles/org.simantics.backup.ontology/graph/Backup.pgraph new file mode 100644 index 000000000..aad660b11 --- /dev/null +++ b/bundles/org.simantics.backup.ontology/graph/Backup.pgraph @@ -0,0 +1,21 @@ +L0 = +STR = + +BACKUP = : L0.Ontology + @L0.new + L0.HasResourceClass "org.simantics.backup.ontology.BackupResource" + +BACKUP.SCLMain : L0.SCLModule + L0.SCLModule.definition _ : L0.String + @L0.loadString "scl/SCLMain.scl" + +BACKUP.ModelledBackupProvider BACKUP.ModelledBackupProvider.instance ==> "IBackupProvider" () { + public BackupResource perform(ReadGraph graph) throws DatabaseException { + QueryControl qc = graph.getService(QueryControl.class); + return new BackupResource(qc.getIndependentGraph(graph)); + } + }); + session.registerService(BackupResource.class, ret); + } + return ret; + } + +} + diff --git a/features/org.jfree.feature/.project b/features/org.jfree.feature/.project new file mode 100644 index 000000000..293973d0d --- /dev/null +++ b/features/org.jfree.feature/.project @@ -0,0 +1,17 @@ + + + org.jfree.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/features/org.jfree.feature/build.properties b/features/org.jfree.feature/build.properties new file mode 100644 index 000000000..82ab19c62 --- /dev/null +++ b/features/org.jfree.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/features/org.jfree.feature/feature.xml b/features/org.jfree.feature/feature.xml new file mode 100644 index 000000000..c3cfc1851 --- /dev/null +++ b/features/org.jfree.feature/feature.xml @@ -0,0 +1,98 @@ + + + + + JFree.org Java libraries. + + + + Object Refinery Limited + + + + GNU LESSER GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/> + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. +0. Additional Definitions. + +As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License. + +“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. + +An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. + +A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”. + +The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. + +The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. +1. Exception to Section 3 of the GNU GPL. + +You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. +2. Conveying Modified Versions. + +If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: + + * a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or + * b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. + +3. Object Code Incorporating Material from Library Header Files. + +The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: + + * a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. + * b) Accompany the object code with a copy of the GNU GPL and this license document. + +4. Combined Works. + +You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: + + * a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. + * b) Accompany the Combined Work with a copy of the GNU GPL and this license document. + * c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. + * d) Do one of the following: + o 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. + o 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. + * e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) + +5. Combined Libraries. + +You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: + + * a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. + * b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +6. Revised Versions of the GNU Lesser General Public License. + +The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. + +If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. + + + + + + + diff --git a/features/org.simantics.desktop.feature/feature.xml b/features/org.simantics.desktop.feature/feature.xml index d29ccac34..ee8db3761 100644 --- a/features/org.simantics.desktop.feature/feature.xml +++ b/features/org.simantics.desktop.feature/feature.xml @@ -26,7 +26,7 @@ version="0.0.0"/> + +