Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f3153e05fdd0e76817d4f89a4ded8afcd5b44e01 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*******************************************************************************
 * Copyright (c) 2008 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.frameworkadmin.tests;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
import org.eclipse.equinox.internal.frameworkadmin.equinox.EquinoxConstants;
import org.eclipse.equinox.internal.provisional.frameworkadmin.*;
import org.eclipse.osgi.service.environment.Constants;
import org.osgi.framework.BundleException;

public class MacOSLikeSetup extends FwkAdminAndSimpleConfiguratorTest {

	public MacOSLikeSetup(String name) {
		super(name);
	}

	public void testMacOSSetup() throws FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException {
		FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin();
		Manipulator manipulator = fwkAdmin.getManipulator();

		File installFolder = new File(Activator.getContext().getDataFile(MacOSLikeSetup.class.getName()), "eclipse");
		File configurationFolder = new File(installFolder, "configuration");
		File launcherFolder = new File(installFolder, "Eclipse.app/Contents/MacOS/"); 
		File launcherName = new File(launcherFolder, "eclipse");

		LauncherData launcherData = manipulator.getLauncherData();
		launcherData.setFwConfigLocation(configurationFolder);
		launcherData.setLauncher(launcherName);
		launcherData.setLauncherConfigLocation(new File(launcherFolder, "eclipse.ini"));
		launcherData.setOS(Constants.OS_MACOSX);

		//Setup the plugins as they should
		File osgiJar = new File(installFolder, "plugins/org.eclipse.osgi.jar");
		File scJar = new File(installFolder, "plugins/org.eclipse.equinox.simpleconfigurator.jar");
		File launcherJar = new File(installFolder, "plugins/org.eclipse.equinox.launcher.jar");
		copy("OSGi", new File(FileLocator.toFileURL(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).getPath()), osgiJar);
		copy("SC", new File(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).getPath()), scJar);
		copy("Startup", new File(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.launcher.jar")).getPath()), launcherJar);
		
		manipulator.getConfigData().addBundle(new BundleInfo(osgiJar.toURI()));
		manipulator.getConfigData().addBundle(new BundleInfo(scJar.toURI(), 1, true));
		manipulator.getConfigData().addBundle(new BundleInfo(launcherJar.toURI()));
		
		manipulator.getLauncherData().addProgramArg(EquinoxConstants.OPTION_STARTUP);
		manipulator.getLauncherData().addProgramArg(launcherJar.toURI().toString());
		
		manipulator.getLauncherData().setFwJar(osgiJar);
		
		try {
			manipulator.save(false);
		} catch (IllegalStateException e) {
			//TODO We ignore the framework JAR location not set exception
		}
		File launcherIni = new File(launcherFolder, "eclipse.ini");
		assertNotContent(launcherIni, "-configuration");
		assertNotContent(launcherIni, "-install");
		assertContent(launcherIni, "-startup");
		assertContent(launcherIni, "../../../plugins/org.eclipse.equinox.launcher.jar");
		assertNotContent(launcherIni, MacOSLikeSetup.class.getName());
		assertNotContent(new File(configurationFolder, "config.ini"), MacOSLikeSetup.class.getName());
		assertTrue("bundles.info missing", new File(configurationFolder, "org.eclipse.equinox.simpleconfigurator/bundles.info").exists());
		
	}
	
	public void testMacWithoutStartupOrFw() throws Exception {
		FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin();
		Manipulator manipulator = fwkAdmin.getManipulator();

		File installFolder = new File(Activator.getContext().getDataFile(MacOSLikeSetup.class.getName()), "eclipse");
		File configurationFolder = new File(installFolder, "configuration");
		File launcherFolder = new File(installFolder, "Eclipse.app/Contents/MacOS/"); 
		File launcherName = new File(launcherFolder, "eclipse");

		LauncherData launcherData = manipulator.getLauncherData();
		launcherData.setFwConfigLocation(configurationFolder);
		launcherData.setLauncher(launcherName);
		launcherData.setOS(Constants.OS_MACOSX);
		
		File osgiJar = new File(installFolder, "plugins/org.eclipse.osgi.jar");
		File scJar = new File(installFolder, "plugins/org.eclipse.equinox.simpleconfigurator.jar");
		File bundle = new File(installFolder, "plugins/bundle_1");
		copy("OSGi", new File(FileLocator.toFileURL(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).getPath()), osgiJar);
		copy("SC", new File(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).getPath()), scJar);
		copy("bundle", new File(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).getPath()), bundle);
		
		manipulator.getConfigData().addBundle(new BundleInfo(osgiJar.toURI()));
		manipulator.getConfigData().addBundle(new BundleInfo(scJar.toURI(), 1, true));
		manipulator.getConfigData().addBundle(new BundleInfo(bundle.toURI()));
		manipulator.save(false);
		
		File launcherIni = new File(launcherFolder, "eclipse.ini");
		File bundleInfo = new File(configurationFolder, "org.eclipse.equinox.simpleconfigurator/bundles.info");
		assertNotContent(launcherIni, "-configuration");
		assertNotContent(launcherIni, "../../../configuration");
		assertContent(bundleInfo, "file:plugins/bundle_1/");
	}
}

Back to the top