Skip to main content
summaryrefslogtreecommitdiffstats
blob: e584c7664e1f0a4406ff0dbb06413a8484e61b92 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
 * Copyright (c) 2007, 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.ui.admin;

import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.Platform;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.osgi.service.environment.EnvironmentInfo;

/**
 * Factory class that can create a new profile with the correct
 * default values.
 * 
 * @since 3.4
 *
 */
public class ProfileFactory {

	static private String FLAVOR_DEFAULT = "tooling"; //$NON-NLS-1$
	static private String EMPTY = ""; //$NON-NLS-1$
	static private EnvironmentInfo info;

	public static IProfile makeProfile(String profileId) {
		Map<String, String> profileProperties = new HashMap<String, String>();
		profileProperties.put(IProfile.PROP_INSTALL_FOLDER, getDefaultLocation());
		profileProperties.put(IProfile.PROP_ENVIRONMENTS, getDefaultEnvironments());
		profileProperties.put(IProfile.PROP_NL, getDefaultNL());

		try {
			return ProvAdminUIActivator.getDefault().getProfileRegistry().addProfile(profileId, profileProperties);
		} catch (ProvisionException e) {
			// log
		}
		return null;
	}

	public static String getDefaultLocation() {
		return Platform.getUserLocation().getURL().getPath();
	}

	public static String getDefaultFlavor() {
		return FLAVOR_DEFAULT;
	}

	private static EnvironmentInfo getEnvironmentInfo() {
		if (info == null) {
			info = (EnvironmentInfo) ServiceHelper.getService(ProvUIActivator.getContext(), EnvironmentInfo.class.getName());
		}
		return info;
	}

	public static String getDefaultNL() {
		if (getEnvironmentInfo() != null) {
			return info.getNL();
		}
		return EMPTY;
	}

	public static String getDefaultEnvironments() {
		if (getEnvironmentInfo() != null) {
			return "osgi.os=" //$NON-NLS-1$
					+ info.getOS() + ",osgi.ws=" + info.getWS() //$NON-NLS-1$
					+ ",osgi.arch=" + info.getOSArch(); //$NON-NLS-1$
		}
		return EMPTY;
	}
}

Back to the top