]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.project/src/org/simantics/project/management/SPMUtil.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / SPMUtil.java
diff --git a/bundles/org.simantics.project/src/org/simantics/project/management/SPMUtil.java b/bundles/org.simantics.project/src/org/simantics/project/management/SPMUtil.java
new file mode 100644 (file)
index 0000000..d739d1a
--- /dev/null
@@ -0,0 +1,113 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.project.management;\r
+\r
+import java.io.File;\r
+import java.net.URI;\r
+\r
+import org.eclipse.core.runtime.IPath;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.core.runtime.preferences.DefaultScope;\r
+import org.eclipse.core.runtime.preferences.IScopeContext;\r
+import org.eclipse.core.runtime.preferences.InstanceScope;\r
+import org.eclipse.equinox.p2.core.IProvisioningAgent;\r
+import org.eclipse.equinox.p2.core.ProvisionException;\r
+import org.simantics.project.internal.Activator;\r
+import org.simantics.utils.strings.EString;\r
+\r
+/**\r
+ * This utility class contains methods for handling bundles in SPM application.\r
+ *\r
+ * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
+ */\r
+public class SPMUtil {\r
+\r
+       private static IProvisioningAgent localAgent;\r
+       private static File workspacesLocation;\r
+       private static File coresLocation;\r
+\r
+       /**\r
+        * Get bundle repository location in Simantics Project Management workspace.\r
+        *\r
+        * @return Bundle repository location\r
+        */\r
+       public static URI getRepositoryLocation() {\r
+               return Platform.getLocation().append("repository").toFile().toURI();\r
+       }\r
+\r
+       /**\r
+        * Create provisioning agent that handles local bundle repository.\r
+        *\r
+        * @return\r
+        * @throws ProvisionException\r
+        * @throws Exception\r
+        */\r
+       public synchronized static IProvisioningAgent getLocalAgent() throws ProvisionException {\r
+               if (localAgent == null) {\r
+                       IPath agentLocation = Platform.getLocation().append("P2");\r
+                       localAgent = P2Util.createAgent( agentLocation );\r
+               }\r
+               return localAgent;\r
+       }\r
+\r
+\r
+\r
+\r
+       public static String[] getSourceLocations() {\r
+               IScopeContext[] scopes = new IScopeContext[] { InstanceScope.INSTANCE, DefaultScope.INSTANCE };\r
+               String yyy = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, RepositoryPreference.P_REPOSITY_SOURCES, "", scopes);\r
+               return EString.explode(yyy, "\n");\r
+       }\r
+\r
+       /**\r
+        * Get diretory that contains project workspaces\r
+        *\r
+        * @return\r
+        */\r
+       public synchronized static File getWorkspacesLocation() {\r
+               if (workspacesLocation == null) {\r
+                       workspacesLocation = new File( Platform.getLocation().toFile(), "workspaces" );\r
+               }\r
+               return workspacesLocation;\r
+       }\r
+\r
+       /**\r
+        * Get diretory that contains cores\r
+        *\r
+        * @return\r
+        */\r
+       public synchronized static File getCoresLocation() {\r
+               if (coresLocation == null) {\r
+                       coresLocation = new File( Platform.getLocation().toFile(), "cores" );\r
+               }\r
+               return coresLocation;\r
+       }\r
+\r
+       public static boolean isWorkspace(File path) {\r
+               if (!path.exists()) return false;\r
+               File db = new File(path, "db");\r
+               if (!db.exists()) return false;\r
+//             if (!isDatabase(db)) return false;\r
+//             File p2 = new File(path, "p2");\r
+//             if (!p2.exists()) return false;\r
+               File props = new File(path, "simantics.cfg");\r
+               if (!props.exists()) return false;\r
+               return true;\r
+       }\r
+\r
+//     public static boolean isDatabase(File path) {\r
+//             File config = new File(path, ProCoreConfigFile);\r
+//             return config.exists();\r
+//     }\r
+\r
+\r
+}\r
+\r