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