]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.project/src/org/simantics/project/management/SPMUtil.java
Merge commit '728147df5d63a3333daff3d8c0e9bfd4f5597e3a'
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / SPMUtil.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.project.management;\r
12 \r
13 import java.io.File;\r
14 import java.net.URI;\r
15 \r
16 import org.eclipse.core.runtime.IPath;\r
17 import org.eclipse.core.runtime.Platform;\r
18 import org.eclipse.core.runtime.preferences.DefaultScope;\r
19 import org.eclipse.core.runtime.preferences.IScopeContext;\r
20 import org.eclipse.core.runtime.preferences.InstanceScope;\r
21 import org.eclipse.equinox.p2.core.IProvisioningAgent;\r
22 import org.eclipse.equinox.p2.core.ProvisionException;\r
23 import org.simantics.project.internal.Activator;\r
24 import org.simantics.utils.strings.EString;\r
25 \r
26 /**\r
27  * This utility class contains methods for handling bundles in SPM application.\r
28  *\r
29  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
30  */\r
31 public class SPMUtil {\r
32 \r
33         private static IProvisioningAgent localAgent;\r
34         private static File workspacesLocation;\r
35         private static File coresLocation;\r
36 \r
37         /**\r
38          * Get bundle repository location in Simantics Project Management workspace.\r
39          *\r
40          * @return Bundle repository location\r
41          */\r
42         public static URI getRepositoryLocation() {\r
43                 return Platform.getLocation().append("repository").toFile().toURI();\r
44         }\r
45 \r
46         /**\r
47          * Create provisioning agent that handles local bundle repository.\r
48          *\r
49          * @return\r
50          * @throws ProvisionException\r
51          * @throws Exception\r
52          */\r
53         public synchronized static IProvisioningAgent getLocalAgent() throws ProvisionException {\r
54                 if (localAgent == null) {\r
55                         IPath agentLocation = Platform.getLocation().append("P2");\r
56                         localAgent = P2Util.createAgent( agentLocation );\r
57                 }\r
58                 return localAgent;\r
59         }\r
60 \r
61 \r
62 \r
63 \r
64         public static String[] getSourceLocations() {\r
65                 IScopeContext[] scopes = new IScopeContext[] { InstanceScope.INSTANCE, DefaultScope.INSTANCE };\r
66                 String yyy = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, RepositoryPreference.P_REPOSITY_SOURCES, "", scopes);\r
67                 return EString.explode(yyy, "\n");\r
68         }\r
69 \r
70         /**\r
71          * Get diretory that contains project workspaces\r
72          *\r
73          * @return\r
74          */\r
75         public synchronized static File getWorkspacesLocation() {\r
76                 if (workspacesLocation == null) {\r
77                         workspacesLocation = new File( Platform.getLocation().toFile(), "workspaces" );\r
78                 }\r
79                 return workspacesLocation;\r
80         }\r
81 \r
82         /**\r
83          * Get diretory that contains cores\r
84          *\r
85          * @return\r
86          */\r
87         public synchronized static File getCoresLocation() {\r
88                 if (coresLocation == null) {\r
89                         coresLocation = new File( Platform.getLocation().toFile(), "cores" );\r
90                 }\r
91                 return coresLocation;\r
92         }\r
93 \r
94         public static boolean isWorkspace(File path) {\r
95                 if (!path.exists()) return false;\r
96                 File db = new File(path, "db");\r
97                 if (!db.exists()) return false;\r
98 //              if (!isDatabase(db)) return false;\r
99 //              File p2 = new File(path, "p2");\r
100 //              if (!p2.exists()) return false;\r
101                 File props = new File(path, "simantics.cfg");\r
102                 if (!props.exists()) return false;\r
103                 return true;\r
104         }\r
105 \r
106 //      public static boolean isDatabase(File path) {\r
107 //              File config = new File(path, ProCoreConfigFile);\r
108 //              return config.exists();\r
109 //      }\r
110 \r
111 \r
112 }\r
113 \r