Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 335864 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/tests/harness/CoreTest.java (-14 / +29 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2010 IBM Corporation and others.
2
 * Copyright (c) 2004, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-22 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *	IBM Corporation - initial API and implementation
9
 *	IBM Corporation - initial API and implementation
10
 *	Martin Oberhuber (Wind River) - [232426] createSymLink() method
10
 *	Martin Oberhuber (Wind River) - [232426] createSymLink() method
11
 *	Martin Oberhuber (Wind River) - [335864] ResourceAttributeTest fails on Win7
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.core.tests.harness;
13
package org.eclipse.core.tests.harness;
13
14
15
import java.io.BufferedReader;
14
import java.io.ByteArrayInputStream;
16
import java.io.ByteArrayInputStream;
15
import java.io.File;
17
import java.io.File;
16
import java.io.FileInputStream;
18
import java.io.FileInputStream;
17
import java.io.FileOutputStream;
19
import java.io.FileOutputStream;
18
import java.io.IOException;
20
import java.io.IOException;
19
import java.io.InputStream;
21
import java.io.InputStream;
22
import java.io.InputStreamReader;
20
import java.io.OutputStream;
23
import java.io.OutputStream;
21
import java.io.PrintStream;
24
import java.io.PrintStream;
22
import junit.framework.AssertionFailedError;
25
import junit.framework.AssertionFailedError;
Lines 27-32 Link Here
27
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.core.runtime.IStatus;
28
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.core.runtime.Platform;
29
import org.eclipse.core.runtime.Status;
32
import org.eclipse.core.runtime.Status;
33
import org.osgi.framework.Version;
30
34
31
/**
35
/**
32
 * @since 3.1
36
 * @since 3.1
Lines 210-221 Link Here
210
		String[] envp = {};
214
		String[] envp = {};
211
		try {
215
		try {
212
			Process p;
216
			Process p;
213
			if (isWindowsVista() || isWindows7()) {
217
			if (isWindowsVistaOrHigher()) {
214
				if (isDir) {
218
				if (isDir) {
215
					String[] cmd = {"mklink", "/d", linkName, linkTgt};
219
					String[] cmd = {"cmd", "/c", "mklink", "/d", linkName, linkTgt};
216
					p = Runtime.getRuntime().exec(cmd, envp, basedir);
220
					p = Runtime.getRuntime().exec(cmd, envp, basedir);
217
				} else {
221
				} else {
218
					String[] cmd = {"mklink", linkName, linkTgt};
222
					String[] cmd = {"cmd", "/c", "mklink", linkName, linkTgt};
219
					p = Runtime.getRuntime().exec(cmd, envp, basedir);
223
					p = Runtime.getRuntime().exec(cmd, envp, basedir);
220
				}
224
				}
221
			} else {
225
			} else {
Lines 223-229 Link Here
223
				p = Runtime.getRuntime().exec(cmd, envp, basedir);
227
				p = Runtime.getRuntime().exec(cmd, envp, basedir);
224
			}
228
			}
225
			int exitcode = p.waitFor();
229
			int exitcode = p.waitFor();
226
			assertEquals(exitcode, 0);
230
			if (exitcode!=0) {
231
				String result = new BufferedReader(new InputStreamReader(p.getErrorStream())).readLine();
232
				assertEquals("createSymLink: "+result+", exitcode", 0, exitcode);
233
			}
227
		} catch (IOException e) {
234
		} catch (IOException e) {
228
			fail("createSymLink", e);
235
			fail("createSymLink", e);
229
		} catch (InterruptedException e) {
236
		} catch (InterruptedException e) {
Lines 314-332 Link Here
314
		return System.currentTimeMillis() + "-" + Math.random();
321
		return System.currentTimeMillis() + "-" + Math.random();
315
	}
322
	}
316
323
324
	private static boolean isWindowsMinVersion(int major, int minor, int micro) {
325
		if (Platform.getOS().equals(Platform.OS_WIN32)) {
326
			try {
327
				Version v = Version.parseVersion(System.getProperty("org.osgi.framework.os.version")); //$NON-NLS-1$ 
328
				return v.compareTo(new Version(major,minor,micro))>=0;
329
			} catch(IllegalArgumentException e) {
330
				/* drop down to returning false */
331
			}
332
			 
333
		}
334
		return false;
335
	}
336
	
317
	/**
337
	/**
318
	 * Test if running on Windows Vista.
338
	 * Test if running on Windows Vista or higher.
319
	 * @return <code>true</code> if running on Windows Vista.
339
	 * @return <code>true</code> if running on Windows Vista or higher.
320
	 */
340
	 */
321
	private static boolean isWindowsVista() {
341
	private static boolean isWindowsVistaOrHigher() {
322
		return Platform.getOS().equals(Platform.OS_WIN32) && "6.0".equals(System.getProperty("org.osgi.framework.os.version")); //$NON-NLS-1$ //$NON-NLS-2$
342
		return isWindowsMinVersion(6,0,0);
323
	}
343
	}
324
	
344
	
325
	private static boolean isWindows7() {
326
		return "Windows7".equals(System.getProperty("org.osgi.framework.os.name")) //$NON-NLS-1$ //$NON-NLS-2$
327
				|| (Platform.getOS().equals(Platform.OS_WIN32) && "6.1.0".equals(System.getProperty("org.osgi.framework.os.version"))); //$NON-NLS-1$ //$NON-NLS-2$
328
	}
329
330
	/**
345
	/**
331
	 * Copy the data from the input stream to the output stream.
346
	 * Copy the data from the input stream to the output stream.
332
	 * Close both streams when finished.
347
	 * Close both streams when finished.

Return to bug 335864