Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6279982aeb7d9be9716b497100d3bdbc5d1beb4c (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
/*******************************************************************************
 * Copyright (c) 2015 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:
 *     Rapicorp, inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.touchpoint.natives.actions;

import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.touchpoint.natives.Activator;
import org.eclipse.equinox.internal.p2.touchpoint.natives.Messages;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.osgi.service.environment.EnvironmentInfo;
import org.osgi.framework.*;
import org.osgi.service.packageadmin.PackageAdmin;

public class BlockMacUpdate extends ProvisioningAction {

	@Override
	public IStatus execute(Map<String, Object> parameters) {
		if (!runningOldMacLayout())
			return Status.OK_STATUS;
		return new Status(IStatus.ERROR, Activator.ID, Messages.BlockMacUpdate_1);
	}

	private boolean runningOldMacLayout() {
		if (!org.eclipse.osgi.service.environment.Constants.OS_MACOSX.equals(getOS()))
			return false;
		Version fwkAdminVersion = getFrameworkAdminVersion();
		if (fwkAdminVersion == null)
			return false;
		if (fwkAdminVersion.compareTo(new Version("1.0.500.v201523")) < 0) //$NON-NLS-1$
			return true;
		return false;
	}

	private Version getFrameworkAdminVersion() {
		ServiceReference<PackageAdmin> sr = Activator.getContext().getServiceReference(PackageAdmin.class);
		if (sr == null)
			return null;
		PackageAdmin packageAdmin = Activator.getContext().getService(sr);
		if (packageAdmin == null)
			return null;
		Activator.getContext().ungetService(sr);
		Bundle[] bundles = packageAdmin.getBundles("org.eclipse.equinox.frameworkadmin.equinox", null); //$NON-NLS-1$
		if (bundles == null)
			return null;
		//Return the first bundle that is not installed or uninstalled
		for (int i = 0; i < bundles.length; i++) {
			if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
				return bundles[i].getVersion();
			}
		}
		return null;
	}

	private String getOS() {
		ServiceReference<EnvironmentInfo> sr = Activator.getContext().getServiceReference(EnvironmentInfo.class);
		if (sr == null)
			return null;
		String value = Activator.getContext().getService(sr).getOS();
		Activator.getContext().ungetService(sr);
		return value;
	}

	@Override
	public IStatus undo(Map<String, Object> parameters) {
		// TODO Auto-generated method stub
		return null;
	}

}

Back to the top