diff -r 8a9abb71988c core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java --- a/core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java Thu Jun 21 13:46:12 2012 +0200 +++ b/core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java Thu Jun 21 13:57:34 2012 +0200 @@ -87,6 +87,7 @@ import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.SharedClassObject; +import org.openide.util.Utilities; import org.openide.util.actions.SystemAction; import org.openide.util.io.NbObjectInputStream; @@ -265,10 +266,10 @@ } private static String toAbsoluteURL(String relURL) { if (relURL.startsWith("home@")) { - return "jar:file:" + System.getProperty("netbeans.home") + relURL.substring(5); + return toJarURI(System.getProperty("netbeans.home")) + relURL.substring(5); } if (relURL.startsWith("user@")) { - return "jar:file:" + System.getProperty("netbeans.user") + relURL.substring(5); + return toJarURI(System.getProperty("netbeans.user")) + relURL.substring(5); } if (relURL.startsWith("abs@")) { return "jar:file:" + relURL.substring(4); @@ -278,7 +279,33 @@ return relURL; } int cluster = Integer.parseInt(relURL.substring(0, indx)); - return "jar:file:" + RelPaths.cluster(cluster) + relURL.substring(indx + 1); + return toJarURI(RelPaths.cluster(cluster)) + relURL.substring(indx + 1); + } + + private static String toJarURI(String path) { + class DirFile extends File { + public DirFile(String pathname) { + super(pathname); + } + + @Override + public boolean isDirectory() { + return true; + } + + @Override + public boolean isFile() { + return false; + } + + @Override + public File getAbsoluteFile() { + return this; + } + } + String ret = "jar:" + Utilities.toURI(new DirFile(path)).toString(); // NOI18N + assert !ret.contains("//") : ret; + return ret; } @Override diff -r 8a9abb71988c core.startup/src/org/netbeans/core/startup/preferences/RelPaths.java --- a/core.startup/src/org/netbeans/core/startup/preferences/RelPaths.java Thu Jun 21 13:46:12 2012 +0200 +++ b/core.startup/src/org/netbeans/core/startup/preferences/RelPaths.java Thu Jun 21 13:57:34 2012 +0200 @@ -72,21 +72,17 @@ return null; } String[] ret = {null, null}; - if (testWritePath(path, System.getProperty("netbeans.user"), "user", ret)) { - return ret; - } + testWritePath(path, System.getProperty("netbeans.user"), "user", ret); // NOI18N int cnt = 0; for (String p : dirs()) { - if (testWritePath(path, p, "" + cnt, ret)) { - return ret; - } + testWritePath(path, p, "" + cnt, ret); cnt++; } - if (testWritePath(path, System.getProperty("netbeans.home"), "home", ret)) { - return ret; + testWritePath(path, System.getProperty("netbeans.home"), "home", ret); // NOI18N + if (ret[1] == null) { + ret[0] = "abs"; // NOI18N + ret[1] = path; } - ret[0] = "abs"; - ret[1] = path; return ret; } @@ -144,8 +140,17 @@ return false; } if (path.startsWith(prefix)) { - ret[0] = codeName; - ret[1] = path.substring(prefix.length()); + String relPath = path.substring(prefix.length()); + while (relPath.startsWith("/")) { + relPath = relPath.substring(1); + } + if ( + ret[1] == null || + ret[1].length() > relPath.length() + ) { + ret[0] = codeName; + ret[1] = relPath; + } return true; } return false; @@ -154,7 +159,7 @@ private static synchronized String[] dirs() { if (dirs == null) { List tmp = new ArrayList(); - String nbdirs = System.getProperty("netbeans.dirs"); + String nbdirs = System.getProperty("netbeans.dirs"); // NOI18N if (nbdirs != null) { StringTokenizer tok = new StringTokenizer(nbdirs, File.pathSeparator); while (tok.hasMoreTokens()) { @@ -165,4 +170,8 @@ } return dirs; } + + static synchronized void assignDirs(String... arr) { + dirs = arr; + } } diff -r 8a9abb71988c core.startup/test/unit/src/org/netbeans/core/startup/preferences/RelPathsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/preferences/RelPathsTest.java Thu Jun 21 13:57:34 2012 +0200 @@ -0,0 +1,58 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.core.startup.preferences; + +import org.netbeans.junit.NbTestCase; + +public class RelPathsTest extends NbTestCase { + + public RelPathsTest(String s) { + super(s); + } + + public void testFindRelativePath() { + RelPaths.assignDirs("/root/java", "/root/javacard"); + String[] arr = RelPaths.findRelativePath("/root/javacard/isMyFriend"); + assertEquals("1", arr[0]); + assertEquals("isMyFriend", arr[1]); + } +}