View | Details | Raw Unified | Return to bug 233939 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/tests/resources/regression/Bug_233939.java (+101 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.tests.resources.regression;
12
13
import org.eclipse.core.runtime.IPath;
14
15
import org.eclipse.core.runtime.CoreException;
16
17
import java.io.IOException;
18
import junit.framework.Test;
19
import junit.framework.TestSuite;
20
import org.eclipse.core.resources.*;
21
import org.eclipse.core.tests.resources.ResourceTest;
22
23
public class Bug_233939 extends ResourceTest {
24
	/**
25
	 * Constructor for Bug_233939.
26
	 */
27
	public Bug_233939() {
28
		super();
29
	}
30
31
	/**
32
	 * Constructor for Bug_233939.
33
	 * @param name
34
	 */
35
	public Bug_233939(String name) {
36
		super(name);
37
	}
38
39
	public static Test suite() {
40
		return new TestSuite(Bug_233939.class);
41
	}
42
43
	public void testBug() {
44
		String fileName = "file.txt";
45
		
46
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
47
		IProject project = root.getProject(getUniqueString());
48
		IFile file = project.getFile(fileName);
49
		
50
		IPath fileInTempDirPath = getTempDir().addTrailingSeparator().append(fileName);
51
		
52
		// create a project
53
		try {
54
			project.create(getMonitor());
55
			project.open(getMonitor());
56
		} catch (CoreException e) {
57
			fail("1.0", e);
58
		}
59
60
		// create a file in the temp dir
61
		try {
62
			fileInTempDirPath.toFile().createNewFile();
63
		} catch (IOException e) {
64
			fail("2.0", e);
65
		}
66
67
		// create a link to the file in the temp dir and refresh,
68
		// the resource in the workspace should have symbolic link attribute set
69
		mkLink(project.getLocation().toFile(), fileName, fileInTempDirPath.toString());
70
		try {
71
			project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
72
		} catch (CoreException e) {
73
			fail("3.0", e);
74
		}
75
		assertExistsInWorkspace("4.0", file);
76
		assertTrue("5.0", file.getResourceAttributes().isSymbolicLink());
77
		
78
		IFile[] files = root.findFilesForLocation(file.getLocation());
79
		assertEquals("7.0", 1, files.length);
80
		assertEquals("7.1", file, files[0]);
81
		
82
//		IFile[] files = root.findFilesForLocation(fileInTempDirPath);
83
//		assertEquals("6.0", 1, files.length);
84
//		assertEquals("6.1", file, files[0]);
85
	}
86
87
	private void mkLink(java.io.File basedir, String src, String tgt) {
88
		String[] envp = {};
89
		try {
90
			Process p;
91
			String[] cmd = {"ln", "-s", tgt, src};
92
			p = Runtime.getRuntime().exec(cmd, envp, basedir);
93
			int exitcode = p.waitFor();
94
			assertEquals(exitcode, 0);
95
		} catch (IOException e) {
96
			fail("mkLink", e);
97
		} catch (InterruptedException e) {
98
			fail("mkLink", e);
99
		}
100
	}
101
}

Return to bug 233939