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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-24 / +41 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 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 1002-1034 Link Here
1002
	/*
1002
	/*
1003
	 * Resolves the ".." in the given path. Returns the given path if it contains no ".." segment.
1003
	 * Resolves the ".." in the given path. Returns the given path if it contains no ".." segment.
1004
	 */
1004
	 */
1005
	public static IPath resolveDotDot(IPath path) {
1005
	public static IPath resolveDotDot(IPath reference, IPath path) {
1006
		IPath newPath = null;
1006
		IPath newPath = null;
1007
		IPath workspaceLocation = null;
1007
		IPath workspaceLocation = workspaceRoot.getLocation();
1008
		for (int i = 0, length = path.segmentCount(); i < length; i++) {
1008
		if (reference == null || workspaceLocation.isPrefixOf(reference)) {
1009
			String segment = path.segment(i);
1009
			for (int i = 0, length = path.segmentCount(); i < length; i++) {
1010
			if (DOT_DOT.equals(segment)) {
1010
				String segment = path.segment(i);
1011
				if (newPath == null) {
1011
				if (DOT_DOT.equals(segment)) {
1012
					if (i == 0) {
1012
					if (newPath == null) {
1013
						workspaceLocation = workspaceRoot.getLocation();
1013
						if (i == 0) {
1014
						newPath = workspaceLocation;
1014
							workspaceLocation = workspaceRoot.getLocation();
1015
							newPath = workspaceLocation;
1016
						} else {
1017
							newPath = path.removeFirstSegments(i);
1018
						}
1015
					} else {
1019
					} else {
1016
						newPath = path.removeFirstSegments(i);
1020
						if (newPath.segmentCount() > 0) {
1021
							newPath = newPath.removeLastSegments(1);
1022
						} else {
1023
							workspaceLocation = workspaceRoot.getLocation();
1024
							newPath = workspaceLocation;
1025
						}
1017
					}
1026
					}
1018
				} else {
1027
				} else if (newPath != null) {
1019
					if (newPath.segmentCount() > 0) {
1028
					if (newPath.equals(workspaceLocation) && workspaceRoot.getProject(segment).isAccessible()) {
1020
						newPath = newPath.removeLastSegments(1);
1029
						newPath = new Path(segment).makeAbsolute();
1021
					} else {
1030
					} else {
1022
						workspaceLocation = workspaceRoot.getLocation();
1031
						newPath = newPath.append(segment);
1023
						newPath = workspaceLocation;
1024
					}
1032
					}
1025
				}
1033
				}
1026
			} else if (newPath != null) {
1034
			}
1027
				if (newPath.equals(workspaceLocation) && workspaceRoot.getProject(segment).isAccessible()) {
1035
		}
1028
					newPath = new Path(segment).makeAbsolute();
1036
		else {
1029
				} else {
1037
			for (int i = 0, length = path.segmentCount(); i < length; i++) {
1038
				String segment = path.segment(i);
1039
				if (DOT_DOT.equals(segment)) {
1040
					if (newPath == null){
1041
						newPath = reference;
1042
					}
1043
					if (newPath.segmentCount() > 0) {
1044
						newPath = newPath.removeLastSegments(1);
1045
	 				}
1046
				} else if (newPath != null) {
1030
					newPath = newPath.append(segment);
1047
					newPath = newPath.append(segment);
1031
				}
1048
	 			}
1032
			}
1049
			}
1033
		}
1050
		}
1034
		if (newPath == null)
1051
		if (newPath == null)
Lines 1419-1426 Link Here
1419
		return buffer.toString();
1436
		return buffer.toString();
1420
	}
1437
	}
1421
	
1438
	
1422
	public ClasspathEntry resolvedDotDot() {
1439
	public ClasspathEntry resolvedDotDot(IPath reference) {
1423
		IPath resolvedPath = resolveDotDot(this.path);
1440
		IPath resolvedPath = resolveDotDot(reference, this.path);
1424
		if (resolvedPath == this.path)
1441
		if (resolvedPath == this.path)
1425
			return this;
1442
			return this;
1426
		return new ClasspathEntry(
1443
		return new ClasspathEntry(
Lines 1919-1925 Link Here
1919
1936
1920
			// library entry check
1937
			// library entry check
1921
			case IClasspathEntry.CPE_LIBRARY :
1938
			case IClasspathEntry.CPE_LIBRARY :
1922
				path = ClasspathEntry.resolveDotDot(path);
1939
				path = ClasspathEntry.resolveDotDot(project.getProject().getLocation(), path);
1923
				
1940
				
1924
				// do not validate entries from Class-Path: in manifest
1941
				// do not validate entries from Class-Path: in manifest
1925
				// (these entries are considered optional since the user cannot act on them)
1942
				// (these entries are considered optional since the user cannot act on them)
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-1 / +5 lines)
Lines 2409-2414 Link Here
2409
	}
2409
	}
2410
2410
2411
	public IClasspathEntry resolveVariableEntry(IClasspathEntry entry, boolean usePreviousSession) {
2411
	public IClasspathEntry resolveVariableEntry(IClasspathEntry entry, boolean usePreviousSession) {
2412
		return resolveVariableEntry(entry, ResourcesPlugin.getWorkspace().getRoot().getLocation(), usePreviousSession);
2413
	}
2414
	
2415
	public IClasspathEntry resolveVariableEntry(IClasspathEntry entry, IPath projectPath, boolean usePreviousSession) {
2412
2416
2413
		if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE)
2417
		if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE)
2414
			return entry;
2418
			return entry;
Lines 2416-2422 Link Here
2416
		IPath resolvedPath = getResolvedVariablePath(entry.getPath(), usePreviousSession);
2420
		IPath resolvedPath = getResolvedVariablePath(entry.getPath(), usePreviousSession);
2417
		if (resolvedPath == null)
2421
		if (resolvedPath == null)
2418
			return null;
2422
			return null;
2419
		resolvedPath = ClasspathEntry.resolveDotDot(resolvedPath);
2423
		resolvedPath = ClasspathEntry.resolveDotDot(projectPath, resolvedPath);
2420
2424
2421
		Object target = JavaModel.getTarget(resolvedPath, false);
2425
		Object target = JavaModel.getTarget(resolvedPath, false);
2422
		if (target == null)
2426
		if (target == null)
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-5 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 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 2588-2594 Link Here
2588
			for (int index = 0; index < rawClasspath.length; index++) {
2588
			for (int index = 0; index < rawClasspath.length; index++) {
2589
				IClasspathEntry currentEntry = rawClasspath[index]; 
2589
				IClasspathEntry currentEntry = rawClasspath[index]; 
2590
				if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
2590
				if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
2591
					rawLibrariesPath.add(ClasspathEntry.resolveDotDot(currentEntry.getPath()));
2591
					rawLibrariesPath.add(ClasspathEntry.resolveDotDot(getProject().getLocation(), currentEntry.getPath()));
2592
				}
2592
				}
2593
			}
2593
			}
2594
			if (referencedEntries != null) {
2594
			if (referencedEntries != null) {
Lines 2619-2625 Link Here
2619
2619
2620
				case IClasspathEntry.CPE_VARIABLE :
2620
				case IClasspathEntry.CPE_VARIABLE :
2621
					try {
2621
					try {
2622
						resolvedEntry = manager.resolveVariableEntry(rawEntry, usePreviousSession);
2622
						resolvedEntry = manager.resolveVariableEntry(rawEntry, this.getProject().getLocation(), usePreviousSession);
2623
					} catch (ClasspathEntry.AssertionFailedException e) {
2623
					} catch (ClasspathEntry.AssertionFailedException e) {
2624
						// Catch the assertion failure and set status instead
2624
						// Catch the assertion failure and set status instead
2625
						// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=55992
2625
						// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=55992
Lines 2676-2682 Link Here
2676
						
2676
						
2677
						if (cEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
2677
						if (cEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
2678
							// resolve ".." in library path
2678
							// resolve ".." in library path
2679
							cEntry = cEntry.resolvedDotDot();
2679
							cEntry = cEntry.resolvedDotDot(getProject().getLocation());
2680
							// https://bugs.eclipse.org/bugs/show_bug.cgi?id=313965
2680
							// https://bugs.eclipse.org/bugs/show_bug.cgi?id=313965
2681
							// Do not resolve if the system attribute is set to false	
2681
							// Do not resolve if the system attribute is set to false	
2682
							if (resolveChainedLibraries
2682
							if (resolveChainedLibraries
Lines 2697-2703 Link Here
2697
2697
2698
				case IClasspathEntry.CPE_LIBRARY:
2698
				case IClasspathEntry.CPE_LIBRARY:
2699
					// resolve ".." in library path
2699
					// resolve ".." in library path
2700
					resolvedEntry = ((ClasspathEntry) rawEntry).resolvedDotDot();
2700
					resolvedEntry = ((ClasspathEntry) rawEntry).resolvedDotDot(getProject().getLocation());
2701
					
2701
					
2702
					if (resolveChainedLibraries && result.rawReverseMap.get(resolvedEntry.getPath()) == null) {
2702
					if (resolveChainedLibraries && result.rawReverseMap.get(resolvedEntry.getPath()) == null) {
2703
						// resolve Class-Path: in manifest
2703
						// resolve Class-Path: in manifest
(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (+50 lines)
Lines 14-24 Link Here
14
import java.io.File;
14
import java.io.File;
15
import java.io.FileOutputStream;
15
import java.io.FileOutputStream;
16
import java.io.IOException;
16
import java.io.IOException;
17
import java.net.URI;
17
import java.util.Hashtable;
18
import java.util.Hashtable;
18
import java.util.Map;
19
import java.util.Map;
19
20
20
import junit.framework.Test;
21
import junit.framework.Test;
21
22
23
import org.eclipse.core.filesystem.URIUtil;
22
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IFolder;
25
import org.eclipse.core.resources.IFolder;
24
import org.eclipse.core.resources.IMarker;
26
import org.eclipse.core.resources.IMarker;
Lines 6861-6865 Link Here
6861
		deleteProject("P");
6863
		deleteProject("P");
6862
	}
6864
	}
6863
}
6865
}
6866
/**
6867
 * @bug 274737: [API] Add new API to ease the retrieval of the parameter annotations for an IMethod
6868
 * 
6869
 * Test that for an external project, relative paths are resolve relative to the project location.
6870
 * 
6871
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737"
6872
 * @throws Exception
6873
 */
6874
public void testBug274737() throws Exception {
6875
	try {
6876
		createExternalFolder("development/third_party");
6877
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("ExternalProject");
6878
		URI uri=  URIUtil.toURI(new Path(getExternalResourcePath("development")).append("ExternalProject"));
6879
		IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName());
6880
		desc.setLocationURI(uri);
6881
		project.create(desc, null);
6882
		if (!project.isOpen()) {
6883
			project.open(null);
6884
		}
6885
		
6886
		addJavaNature("ExternalProject");
6887
		IJavaProject javaProject = JavaCore.create(project);
6888
		IClasspathEntry[] classpath = new IClasspathEntry[2];
6889
		Util.createJar(
6890
				new String[0],
6891
				new String[] {
6892
					"META-INF/MANIFEST.MF",
6893
					"Manifest-Version: 1.0\n" +
6894
					"Class-Path: \n",
6895
				},
6896
				getExternalResourcePath("development/third_party/lib.jar"),
6897
				JavaCore.VERSION_1_4);
6898
		createExternalFolder("development/ExternalProject/src");
6899
		createExternalFolder("development/ExternalProject/bin");
6900
		classpath[0] = JavaCore.newSourceEntry(new Path("/ExternalProject/src"), null, null);
6901
		classpath[1] = JavaCore.newLibraryEntry(new Path("../third_party/lib.jar"), null, null);
6902
		javaProject.setRawClasspath(classpath, new Path("/ExternalProject/bin"), null);
6903
		
6904
		refresh(javaProject);
6905
		waitForAutoBuild();
6906
		assertMarkers("Unexpected markers", "", javaProject);
6907
		
6908
	} finally {
6909
		deleteProject("ExternalProject");
6910
		deleteExternalResource("development");
6911
6912
	}	
6913
}
6864
6914
6865
}
6915
}

Return to bug 274737