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