Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2227a70e0b714ccbd550e6792efed4939e63526e (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
/*******************************************************************************
 * Copyright (c) 2013 Ericsson AB 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: 
 *     Ericsson AB - initial API and implementation
 ******************************************************************************/
package org.eclipse.equinox.p2.tests.sharedinstall;

import java.io.File;
import java.io.FilenameFilter;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.equinox.p2.tests.reconciler.dropins.ReconcilerTestSuite;

//This test verifies that when eclipse runs for the first time and it has been run previously, then the migration wizard is presented.

//This test is separated in two classes. 
//This class is responsible for setting up eclipse once
//The second class (InitialSharedInstallReadTest) is responsible for carrying out the real test
//The test is setup this way in order to reuse all the testing infrastructure without having the modify much of it.
public class InitialSharedInstall extends AbstractSharedInstallTest {

	public static Test suite() {
		TestSuite suite = new ReconcilerTestSuite();
		if (isRunningJava16orPrevious())
			return suite;

		suite.setName(InitialSharedInstall.class.getName());
		suite.addTest(new InitialSharedInstall("setupRun"));

		TestSuite suite2 = new ReconcilerTestSuite();
		suite2.addTest(new InitialSharedInstallRealTest("testImportFromPreviousInstall"));

		suite.addTest(suite2);
		return suite;
	}

	public static boolean isRunningJava16orPrevious() {
		try {
			Class.forName("java.nio.file.attribute.AclEntry");
		} catch (ClassNotFoundException e) {
			return true;
		}
		return false;
	}

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

	public void setupRun() {
		cleanupDotEclipseFolder();
		assertInitialized();
		replaceDotEclipseProductFile(new File(output, "eclipse"), "p2.automated.test", "1.0.0");
		setupReadOnlyInstall();
		reallyReadOnly(readOnlyBase);
		System.out.println(readOnlyBase);
		System.out.println(userBase);

		{
			//This causes an installation of Eclipse to be created in the default location (~/.eclipse/...)
			installFeature1InUserWithoutSpecifyingConfiguration();
		}
		removeReallyReadOnly(readOnlyBase);
	}

	private void cleanupDotEclipseFolder() {
		File userHome = new File(System.getProperty("user.home"));
		File dotEclipse = new File(userHome, ".eclipse");
		File[] toDelete = dotEclipse.listFiles(new FilenameFilter() {
			public boolean accept(File dir, String name) {
				if (name.startsWith("p2.automated.test"))
					return true;
				return false;
			}
		});
		for (int i = 0; i < toDelete.length; i++) {
			delete(toDelete[i]);
		}
	}
}

Back to the top