Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9ae0682a4127a58615d03f3b6355aef746d97428 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*******************************************************************************
 *  Copyright (c) 2008, 2010 IBM Corporation and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 *
 *  Contributors:
 *      IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.frameworkadmin.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdminRuntimeException;
import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
import org.junit.Before;
import org.junit.Test;

public class TestVMArg extends FwkAdminAndSimpleConfiguratorTest {

	private Manipulator m;

	@Override
	@Before
	public void setUp() throws Exception {
		super.setUp();
		m = createMinimalConfiguration(TestEclipseDataArea.class.getName());
	}
	@Test
	public void testVMInsideInstall() throws FrameworkAdminRuntimeException, IOException {
		// Test VM path in the install folder
		File jreLocation = new File(m.getLauncherData().getLauncher().getParentFile(), "jre");
		m.getLauncherData().setJvm(jreLocation);
		m.save(false);
		assertNotContent(getLauncherConfigFile(), jreLocation.getAbsolutePath());
		assertContent(getLauncherConfigFile(), "jre");
		assertContent(m.getLauncherData().getLauncherConfigLocation(), "-vm");
		assertContent(m.getLauncherData().getLauncherConfigLocation(), "jre");
		assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "file:");
		m.load();
		assertEquals(jreLocation, m.getLauncherData().getJvm());

		m.getLauncherData().setJvm(null);
		m.save(false);
		assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "-vm");
		assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "jre");
	}

//	public void testVMInsideInstall_MacOS() throws Exception {
//		m = createMinimalConfiguration(TestEclipseDataArea.class.getName(), Constants.OS_MACOSX);
//		final String expectedRelativePath = "../../../jre";
//
//		File jreLocation = new File(m.getLauncherData().getLauncher().getParentFile(), expectedRelativePath);
//		m.getLauncherData().setJvm(jreLocation);
//		m.save(false);
//
//		File launcherConfigFile = getLauncherConfigFile();
//		assertNotContent("No absolute JRE path must be present in " + launcherConfigFile, launcherConfigFile, jreLocation.getAbsolutePath());
//		assertContent("Relative JRE path must be present in " + launcherConfigFile, launcherConfigFile, expectedRelativePath);
//	}

//	public void testVMInsideInstall_MacOS_BundledLayout() throws Exception {
//		m = createMinimalConfiguration(TestEclipseDataArea.class.getName(), EclipseLauncherParser.MACOSX_BUNDLED);
//		// note the difference the traditional layout: one segment less
//		final String expectedRelativePath = "../../jre";
//
//		File jreLocation = new File(m.getLauncherData().getLauncher().getParentFile(), expectedRelativePath);
//		m.getLauncherData().setJvm(jreLocation);
//		m.save(false);
//
//		File launcherConfigFile = getLauncherConfigFile();
//		assertNotContent("No absolute JRE path must be present in " + launcherConfigFile, launcherConfigFile, jreLocation.getAbsolutePath());
//		assertContent("Relative JRE path must be present in " + launcherConfigFile, launcherConfigFile, expectedRelativePath);
//	}
	@Test
	public void testVMOutsideInstall() throws FrameworkAdminRuntimeException, IOException {
		// Test VM path in the install folder
		File jreLocation = new File(m.getLauncherData().getLauncher().getParentFile(), "../../jre").getCanonicalFile();
		m.getLauncherData().setJvm(jreLocation);
		m.save(false);
		assertContent(getLauncherConfigFile(), jreLocation.getAbsolutePath().replace('\\', '/'));
		assertContent(m.getLauncherData().getLauncherConfigLocation(), "-vm");
		assertContent(m.getLauncherData().getLauncherConfigLocation(), "jre");
		assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "file:");
		m.load();
		assertEquals(jreLocation, m.getLauncherData().getJvm());
	}
	@Test
	public void test269502() throws FrameworkAdminRuntimeException, IOException {
		// Test VM path in the install folder
		String winPath = "c:/ibm5sr3/bin";
		String linuxPath = "/Users/Pascal/ibm5sr3/bin";
		String chosenPath = Platform.getOS().equals("win32") ? winPath : linuxPath;
		File jreLocation = new File(chosenPath);
		m.getLauncherData().setJvm(jreLocation);
		m.save(false);
		assertContent(getLauncherConfigFile(), chosenPath);
		assertContent(m.getLauncherData().getLauncherConfigLocation(), "-vm");
		assertContent(m.getLauncherData().getLauncherConfigLocation(), chosenPath);
		assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "file:");
		m.load();
		assertEquals(jreLocation, m.getLauncherData().getJvm());
	}

//	public void test269502_MacOS() throws Exception {
//		m = createMinimalConfiguration(TestEclipseDataArea.class.getName(), Constants.OS_MACOSX);
//
//		//Test VM path in the install folder
//		String chosenPath = "/Users/Pascal/ibm5sr3/bin";
//		File jreLocation =  new File(chosenPath);
//		m.getLauncherData().setJvm(jreLocation);
//		m.save(false);
//		assertContent(getLauncherConfigFile(), chosenPath);
//		assertContent(m.getLauncherData().getLauncherConfigLocation(), "-vm");
//		assertContent(m.getLauncherData().getLauncherConfigLocation(), chosenPath);
//		assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "file:");
//		m.load();
//		assertEquals(jreLocation, m.getLauncherData().getJvm());
//	}

	/**
	 * But 282303: Have -vm ../jre as program arguments. See them vanish during the
	 * save operation of the manipulator
	 *
	 * @throws FrameworkAdminRuntimeException
	 * @throws IOException
	 */
	@Test
	public void test282303() throws FrameworkAdminRuntimeException, IOException {
		assertNotContent(getLauncherConfigFile(), "-vm");
		assertNotContent(getLauncherConfigFile(), "../mylocation");
		assertNotContent(getLauncherConfigFile(), "-otherarg");
		m.getLauncherData().addProgramArg("-vm");
		m.getLauncherData().addProgramArg("../mylocation");
		m.getLauncherData().addProgramArg("-otherarg");
		m.getLauncherData().setJvm(new File("../mylocation"));
		m.save(false);
		m.load();
		String[] args = m.getLauncherData().getProgramArgs();
		boolean found = false;
		for (int i = 0; i < args.length; i++) {
			if ("-vm".equals(args[i]) && i != args.length - 1) {
				if ("../mylocation".equals(args[++i])) {
					found = true;
					break;
				}
			}
		}
		assertTrue("Can't find vm argument.", found);
	}
}

Back to the top