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
9 * VTT Technical Research Centre of Finland - initial API and implementation
10 *******************************************************************************/
11 package org.simantics.project.management;
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;
27 * This utility class contains methods for handling bundles in SPM application.
29 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
31 public class SPMUtil {
33 private static IProvisioningAgent localAgent;
34 private static File workspacesLocation;
35 private static File coresLocation;
38 * Get bundle repository location in Simantics Project Management workspace.
40 * @return Bundle repository location
42 public static URI getRepositoryLocation() {
43 return Platform.getLocation().append("repository").toFile().toURI();
47 * Create provisioning agent that handles local bundle repository.
50 * @throws ProvisionException
53 public synchronized static IProvisioningAgent getLocalAgent() throws ProvisionException {
54 if (localAgent == null) {
55 IPath agentLocation = Platform.getLocation().append("P2");
56 localAgent = P2Util.createAgent( agentLocation );
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");
71 * Get diretory that contains project workspaces
75 public synchronized static File getWorkspacesLocation() {
76 if (workspacesLocation == null) {
77 workspacesLocation = new File( Platform.getLocation().toFile(), "workspaces" );
79 return workspacesLocation;
83 * Get diretory that contains cores
87 public synchronized static File getCoresLocation() {
88 if (coresLocation == null) {
89 coresLocation = new File( Platform.getLocation().toFile(), "cores" );
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;
106 // public static boolean isDatabase(File path) {
107 // File config = new File(path, ProCoreConfigFile);
108 // return config.exists();