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 / +39 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
							newPath = workspaceLocation;
1015
						} else {
1016
							newPath = path.removeFirstSegments(i);
1017
						}
1015
					} else {
1018
					} else {
1016
						newPath = path.removeFirstSegments(i);
1019
						if (newPath.segmentCount() > 0) {
1020
							newPath = newPath.removeLastSegments(1);
1021
						} else {
1022
							newPath = workspaceLocation;
1023
						}
1017
					}
1024
					}
1018
				} else {
1025
				} else if (newPath != null) {
1019
					if (newPath.segmentCount() > 0) {
1026
					if (newPath.equals(workspaceLocation) && workspaceRoot.getProject(segment).isAccessible()) {
1020
						newPath = newPath.removeLastSegments(1);
1027
						newPath = new Path(segment).makeAbsolute();
1021
					} else {
1028
					} else {
1022
						workspaceLocation = workspaceRoot.getLocation();
1029
						newPath = newPath.append(segment);
1023
						newPath = workspaceLocation;
1024
					}
1030
					}
1025
				}
1031
				}
1026
			} else if (newPath != null) {
1032
			}
1027
				if (newPath.equals(workspaceLocation) && workspaceRoot.getProject(segment).isAccessible()) {
1033
		}
1028
					newPath = new Path(segment).makeAbsolute();
1034
		else {
1029
				} else {
1035
			for (int i = 0, length = path.segmentCount(); i < length; i++) {
1036
				String segment = path.segment(i);
1037
				if (DOT_DOT.equals(segment)) {
1038
					if (newPath == null){
1039
						newPath = reference;
1040
					}
1041
					if (newPath.segmentCount() > 0) {
1042
						newPath = newPath.removeLastSegments(1);
1043
	 				}
1044
				} else if (newPath != null) {
1030
					newPath = newPath.append(segment);
1045
					newPath = newPath.append(segment);
1031
				}
1046
	 			}
1032
			}
1047
			}
1033
		}
1048
		}
1034
		if (newPath == null)
1049
		if (newPath == null)
Lines 1419-1426 Link Here
1419
		return buffer.toString();
1434
		return buffer.toString();
1420
	}
1435
	}
1421
	
1436
	
1422
	public ClasspathEntry resolvedDotDot() {
1437
	public ClasspathEntry resolvedDotDot(IPath reference) {
1423
		IPath resolvedPath = resolveDotDot(this.path);
1438
		IPath resolvedPath = resolveDotDot(reference, this.path);
1424
		if (resolvedPath == this.path)
1439
		if (resolvedPath == this.path)
1425
			return this;
1440
			return this;
1426
		return new ClasspathEntry(
1441
		return new ClasspathEntry(
Lines 1919-1925 Link Here
1919
1934
1920
			// library entry check
1935
			// library entry check
1921
			case IClasspathEntry.CPE_LIBRARY :
1936
			case IClasspathEntry.CPE_LIBRARY :
1922
				path = ClasspathEntry.resolveDotDot(path);
1937
				path = ClasspathEntry.resolveDotDot(project.getProject().getLocation(), path);
1923
				
1938
				
1924
				// do not validate entries from Class-Path: in manifest
1939
				// do not validate entries from Class-Path: in manifest
1925
				// (these entries are considered optional since the user cannot act on them)
1940
				// (these entries are considered optional since the user cannot act on them)
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-1 / +2 lines)
Lines 2416-2422 Link Here
2416
		IPath resolvedPath = getResolvedVariablePath(entry.getPath(), usePreviousSession);
2416
		IPath resolvedPath = getResolvedVariablePath(entry.getPath(), usePreviousSession);
2417
		if (resolvedPath == null)
2417
		if (resolvedPath == null)
2418
			return null;
2418
			return null;
2419
		resolvedPath = ClasspathEntry.resolveDotDot(resolvedPath);
2419
		// By passing a null reference path, we keep it relative to workspace root.
2420
		resolvedPath = ClasspathEntry.resolveDotDot(null, resolvedPath);
2420
2421
2421
		Object target = JavaModel.getTarget(resolvedPath, false);
2422
		Object target = JavaModel.getTarget(resolvedPath, false);
2422
		if (target == null)
2423
		if (target == null)
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-4 / +4 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 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: Relative Classpath entries should not be resolved relative to the workspace
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