Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 07b085e4df1bd974998a4e38c74b1eae231979d2 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*******************************************************************************
 *  Copyright (c) 2003 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:
 *     Red Hat, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.reconciler.dropins;

import java.io.*;
import java.util.Properties;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.Platform;
import org.eclipse.equinox.internal.p2.updatesite.Activator;
import org.eclipse.equinox.p2.tests.sharedinstall.AbstractSharedInstallTest;

public class SharedInstallTestsProfileSpoofEnabledConfigured extends SharedInstallTestsProfileSpoofEnabled {

	private File extensions;

	public static Test suite() {
		TestSuite suite = new ReconcilerTestSuite();
		suite.setName(SharedInstallTestsProfileSpoofEnabledConfigured.class.getName());
		suite.addTest(new SharedInstallTestsProfileSpoofEnabledConfigured("testBasicStartup"));
		suite.addTest(new SharedInstallTestsProfileSpoofEnabledConfigured("testReadOnlyDropinsStartup"));
		suite.addTest(new SharedInstallTestsProfileSpoofEnabledConfigured("testUserDropinsStartup"));
		return suite;
	}

	/*
	 * Constructor for the class.
	 */
	public SharedInstallTestsProfileSpoofEnabledConfigured(String name) {
		super(name);
	}

	public void reconcileReadOnly(String message, File extensions) {
		reconcileReadOnly(message, extensions, false);
	}

	public void reconcileReadOnly(String message, File extensions, boolean debug) {
		File root = new File(Activator.getBundleContext().getProperty("java.home"));
		root = new File(root, "bin");
		File exe = new File(root, "javaw.exe");
		if (!exe.exists())
			exe = new File(root, "java");

		String configuration = new File(userBase, "configuration").getAbsolutePath();
		String command[];
		if (!debug) {
			if (extensions != null) {
				command = new String[] {(new File(output, "eclipse/eclipse")).getAbsolutePath(), "--launcher.suppressErrors", "-debug", "-consolelog", "-nosplash", "-application", "org.eclipse.equinox.p2.reconciler.application", "-configuration", configuration, "-vm", exe.getAbsolutePath(), "-vmArgs", "-Dosgi.checkConfiguration=true", "-Dp2.fragments=" + extensions.toString()};
			} else {
				command = new String[] {(new File(output, "eclipse/eclipse")).getAbsolutePath(), "--launcher.suppressErrors", "-debug", "-consolelog", "-nosplash", "-application", "org.eclipse.equinox.p2.reconciler.application", "-configuration", configuration, "-vm", exe.getAbsolutePath(), "-vmArgs", "-Dosgi.checkConfiguration=true"};
			}
		} else {
			if (extensions != null) {
				command = new String[] {(new File(output, "eclipse/eclipse")).getAbsolutePath(), "--launcher.suppressErrors", "-debug", "-consolelog", "-nosplash", "-application", "org.eclipse.equinox.p2.reconciler.application", "-configuration", configuration, "-vm", exe.getAbsolutePath(), "-vmArgs", "-Dosgi.checkConfiguration=true", "-Dp2.fragments=" + extensions.toString(), "-Xdebug", "-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y"};
			} else {
				command = new String[] {(new File(output, "eclipse/eclipse")).getAbsolutePath(), "--launcher.suppressErrors", "-debug", "-consolelog", "-nosplash", "-application", "org.eclipse.equinox.p2.reconciler.application", "-configuration", configuration, "-vm", exe.getAbsolutePath(), "-vmArgs", "-Dosgi.checkConfiguration=true", "-Xdebug", "-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y"};
			}
		}
		run(message, command);
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		extensions = getTempFolder();
		copy("", getTestData("", "testData/reconciler/extensions/ext1"), extensions);
		setReadOnly(extensions, true);
	}

	@Override
	protected void tearDown() throws Exception {
		setReadOnly(extensions, false);
		extensions.delete();
		super.tearDown();
	}

	public void testBasicStartup() throws IOException {
		assertInitialized();
		setupReadOnlyInstall();
		try {
			File userBundlesInfo = new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/bundles.info");
			File userConfigIni = new File(userBase, "configuration/config.ini");
			assertFalse("0.1", userBundlesInfo.exists());
			assertFalse("0.2", userConfigIni.exists());
			reconcileReadOnly("0.21", extensions);
			assertFalse("0.3", userBundlesInfo.exists());
			assertTrue("0.4", userConfigIni.exists());

			Properties props = new Properties();
			InputStream is = new BufferedInputStream(new FileInputStream(userConfigIni));
			try {
				props.load(is);
			} finally {
				is.close();
			}
			assertTrue("0.5", props.containsKey("osgi.sharedConfiguration.area"));
			assertTrue("0.6", props.size() == 1);
		} finally {
			cleanupReadOnlyInstall();
		}
	}

	public void testReadOnlyDropinsStartup() throws IOException {
		if (Platform.getOS().equals(Platform.OS_MACOSX))
			return;

		assertInitialized();
		assertDoesNotExistInBundlesInfo("0.1", "myBundle");
		File jar = getTestData("2.0", "testData/reconciler/plugins/myBundle_1.0.0.jar");
		add("0.2", "dropins", jar);
		setupReadOnlyInstall();
		try {
			File userBundlesInfo = new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/bundles.info");
			File userConfigIni = new File(userBase, "configuration/config.ini");
			assertFalse("0.1", userBundlesInfo.exists());
			assertFalse("0.2", userConfigIni.exists());

			reconcileReadOnly("0.21", extensions);

			assertTrue("0.3", userBundlesInfo.exists());
			assertTrue("0.4", userConfigIni.exists());

			assertTrue(isInBundlesInfo(userBundlesInfo, "myBundle", null));
			assertTrue(isInBundlesInfo(userBundlesInfo, "zzz", null));

			// remove the bundle from the dropins and reconcile
			setReadOnly(readOnlyBase, false);
			AbstractSharedInstallTest.removeReallyReadOnly(readOnlyBase);
			assertTrue("0.7", readOnlyBase.canWrite());
			remove("1.0", "dropins", "myBundle_1.0.0.jar");
			setReadOnly(readOnlyBase, true);
			AbstractSharedInstallTest.reallyReadOnly(readOnlyBase);

			reconcileReadOnly("0.21", extensions, false);

			assertFalse(isInBundlesInfo(userBundlesInfo, "myBundle", null));
			assertTrue(isInBundlesInfo(userBundlesInfo, "zzz", null));

			reconcileReadOnly("0.2105", null, false);

			// those two will never pass. Disabling extensions while no dropins change
			// causes master profile to be loaded and user bundles *not* touched

			//			assertFalse(isInBundlesInfo(userBundlesInfo, "myBundle", null));
			//			assertFalse(isInBundlesInfo(userBundlesInfo, "zzz", null));

			// only dropin change (or any other p2 operations) causes p2 to write a
			// new, up-to-date bundles.info
			setReadOnly(readOnlyBase, false);
			AbstractSharedInstallTest.removeReallyReadOnly(readOnlyBase);
			assertTrue("0.7", readOnlyBase.canWrite());
			add("0.211", "dropins", jar);
			setReadOnly(readOnlyBase, true);
			AbstractSharedInstallTest.reallyReadOnly(readOnlyBase);

			//no extension - new bundles.info should be written
			reconcileReadOnly("0.22", null, false);

			assertTrue(isInBundlesInfo(userBundlesInfo, "myBundle", null));
			assertFalse(isInBundlesInfo(userBundlesInfo, "zzz", null));
		} finally {
			cleanupReadOnlyInstall();
			// try to remove it in case an exception was thrown
			remove("1.0", "dropins", "myBundle_1.0.0.jar");
		}
	}

	public void testUserDropinsStartup() throws IOException {
		if (Platform.getOS().equals(Platform.OS_MACOSX))
			return;

		assertInitialized();
		assertDoesNotExistInBundlesInfo("0.1", "myBundle");
		File jar = getTestData("2.0", "testData/reconciler/plugins/myBundle_1.0.0.jar");
		File dropins = new File(userBase, "dropins");
		setupReadOnlyInstall();
		try {
			dropins.mkdir();

			copy("copying to dropins", jar, new File(dropins, jar.getName()));

			File userBundlesInfo = new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/bundles.info");
			File userConfigIni = new File(userBase, "configuration/config.ini");
			assertFalse("0.1", userBundlesInfo.exists());
			assertFalse("0.2", userConfigIni.exists());

			reconcileReadOnly("0.21", extensions);

			assertTrue("0.3", userBundlesInfo.exists());
			assertTrue("0.4", userConfigIni.exists());

			assertTrue(isInBundlesInfo(userBundlesInfo, "myBundle", null));
			assertTrue(isInBundlesInfo(userBundlesInfo, "zzz", null));
			// remove the bundle from the dropins and reconcile
			delete(dropins);

			reconcileReadOnly("0.21", extensions);
			assertFalse(isInBundlesInfo(userBundlesInfo, "myBundle", null));
			assertTrue(isInBundlesInfo(userBundlesInfo, "zzz", null));

			reconcileReadOnly("0.2105", null, false);

			// those two will never pass. Disabling extensions while no dropins change
			// causes master profile to be loaded and user bundles *not* touched

			//			assertFalse(isInBundlesInfo(userBundlesInfo, "myBundle", null));
			//			assertFalse(isInBundlesInfo(userBundlesInfo, "zzz", null));

			// only dropin change (or any other p2 operations) causes p2 to write a
			// new, up-to-date bundles.info

			//no extension - new bundles.info should be written
			dropins.mkdir();
			copy("copying to dropins", jar, new File(dropins, jar.getName()));
			reconcileReadOnly("0.22", null, false);

			assertTrue(isInBundlesInfo(userBundlesInfo, "myBundle", null));
			assertFalse(isInBundlesInfo(userBundlesInfo, "zzz", null));
		} finally {
			delete(dropins);
			cleanupReadOnlyInstall();
		}
	}
}

Back to the top