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 316650
Collapse All | Expand All

(-)src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
2
 * Copyright (c) 2008, 2010 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 32-37 Link Here
32
		suite.addTestSuite(JVMArgumentActionLogicTest.class);
32
		suite.addTestSuite(JVMArgumentActionLogicTest.class);
33
		suite.addTestSuite(LinkActionTest.class);
33
		suite.addTestSuite(LinkActionTest.class);
34
		suite.addTestSuite(MarkStartedActionTest.class);
34
		suite.addTestSuite(MarkStartedActionTest.class);
35
		suite.addTestSuite(PathUtilTest.class);
35
		suite.addTestSuite(RemoveJVMArgumentActionTest.class);
36
		suite.addTestSuite(RemoveJVMArgumentActionTest.class);
36
		suite.addTestSuite(RemoveProgramArgumentActionTest.class);
37
		suite.addTestSuite(RemoveProgramArgumentActionTest.class);
37
		suite.addTestSuite(RemoveRepositoryActionTest.class);
38
		suite.addTestSuite(RemoveRepositoryActionTest.class);
(-)src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/PathUtilTest.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.equinox.p2.tests.touchpoint.eclipse;
12
13
import java.net.MalformedURLException;
14
import java.net.URL;
15
import org.eclipse.equinox.internal.p2.update.PathUtil;
16
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
17
18
/**
19
 * Tests for {@link org.eclipse.equinox.internal.p2.update.PathUtil}.
20
 */
21
public class PathUtilTest extends AbstractProvisioningTest {
22
	/** Constant value indicating if the current platform is Windows */
23
	private static final boolean WINDOWS = java.io.File.separatorChar == '\\';
24
25
	public void testMakeRelative() throws MalformedURLException {
26
		if (!WINDOWS)
27
			return;
28
		Object[][] data = new Object[][] {
29
				// simple path
30
				new Object[] {"file:/c:/a/b", new URL("file:/c:/a/x"), "file:../b"},
31
				// common root
32
				new Object[] {"file:/c:/eclipse/plugins/foo.jar", new URL("file:/c:/eclipse/"), "file:plugins\\foo.jar"},
33
				// different drives
34
				new Object[] {"file:/c:/a/b", new URL("file:/d:/a/x"), "file:/c:/a/b"}, //
35
				new Object[] {"file:/c:/eclipse/plugins/foo.jar", new URL("file:/d:/eclipse/"), "file:/c:/eclipse/plugins/foo.jar"},
36
				// non-local
37
				new Object[] {"http:/c:/a/b", new URL("file:/c:/a/x"), "http:/c:/a/b"}, //
38
				new Object[] {"file:/c:/a/b", new URL("http:/c:/a/x"), "file:/c:/a/b"}, //
39
				//
40
				new Object[] {"file:/c:/a/b", new URL("file:/C:/a/x"), "file:../b"}, //
41
				new Object[] {"file:/c:/", new URL("file:/d:/"), "file:/c:/"}, //
42
				new Object[] {"file:/c:/", new URL("file:/c:/"), "file:/c:/"}, //
43
		};
44
		for (int i = 0; i < data.length; i++) {
45
			String location = data[i][0].toString();
46
			URL root = (URL) data[i][1];
47
			String expected = data[i][2].toString();
48
			String actual = PathUtil.makeRelative(location, root);
49
			assertEquals("2." + Integer.toString(i), expected, actual);
50
		}
51
	}
52
}
(-)src/org/eclipse/equinox/internal/p2/update/PathUtil.java (-6 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2010 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 12-22 Link Here
12
12
13
import java.io.File;
13
import java.io.File;
14
import java.net.URL;
14
import java.net.URL;
15
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.Path;
17
16
18
/**
17
/**
19
 * 
18
 * Note the methods on this class have inconsistent and unintuitive behaviour. However
19
 * they are unchanged for backwards compatibility. Clients should really use
20
 * {@link URIUtil} instead.
20
 * @since 1.0
21
 * @since 1.0
21
 */
22
 */
22
public class PathUtil {
23
public class PathUtil {
Lines 64-73 Link Here
64
	/*
65
	/*
65
	 * Make the given path relative to the specified root, if applicable. If not, then
66
	 * Make the given path relative to the specified root, if applicable. If not, then
66
	 * return the path as-is.
67
	 * return the path as-is.
67
	 * 
68
	 * Method similar to one from SimpleConfigurationManipulatorImpl.
69
	 */
68
	 */
70
	private static String makeRelative(IPath toRel, IPath base) {
69
	private static String makeRelative(IPath toRel, IPath base) {
70
		//can't make relative if devices are not equal
71
		final String device = toRel.getDevice();
72
		if (device != base.getDevice() && (device == null || !device.equalsIgnoreCase(base.getDevice())))
73
			return toRel.toOSString();
71
		int i = base.matchingFirstSegments(toRel);
74
		int i = base.matchingFirstSegments(toRel);
72
		if (i == 0) {
75
		if (i == 0) {
73
			return toRel.toOSString();
76
			return toRel.toOSString();
Lines 78-83 Link Here
78
		}
81
		}
79
		if (i == toRel.segmentCount())
82
		if (i == toRel.segmentCount())
80
			return "."; //$NON-NLS-1$
83
			return "."; //$NON-NLS-1$
84
		//TODO This will return mixed path with some / and some \ on windows!!
81
		result += toRel.setDevice(null).removeFirstSegments(i).toOSString();
85
		result += toRel.setDevice(null).removeFirstSegments(i).toOSString();
82
		return result;
86
		return result;
83
	}
87
	}

Return to bug 316650