# HG changeset patch # Parent 6c0bac0c969cfc1f752b1cc630aeb80a9de2e36c # User Jesse Glick #213562: perform UNC-safe conversion between File and URI. diff --git a/api.java.classpath/nbproject/project.xml b/api.java.classpath/nbproject/project.xml --- a/api.java.classpath/nbproject/project.xml +++ b/api.java.classpath/nbproject/project.xml @@ -43,7 +43,7 @@ - 8.0 + 8.25 diff --git a/api.java.classpath/src/org/netbeans/api/java/classpath/ClassPath.java b/api.java.classpath/src/org/netbeans/api/java/classpath/ClassPath.java --- a/api.java.classpath/src/org/netbeans/api/java/classpath/ClassPath.java +++ b/api.java.classpath/src/org/netbeans/api/java/classpath/ClassPath.java @@ -311,7 +311,7 @@ //todo: Ignore non file urls, we can try to url->fileobject->url //if it becomes a file. if ("file".equals(url.getProtocol())) { //NOI18N - file = FileUtil.normalizeFile(new File(url.toURI())); + file = FileUtil.normalizeFile(Utilities.toFile(url.toURI())); } } catch (IllegalArgumentException e) { LOG.log(Level.WARNING, "Unexpected URL <{0}>: {1}", new Object[] {url, e}); @@ -800,7 +800,7 @@ } else { String fileState = null; try { - final File file = new File(this.url.toURI()); + final File file = Utilities.toFile(this.url.toURI()); fileState = "(exists: " + file.exists() + //NOI18N " file: " + file.isFile() + //NOI18N " directory: "+ file.isDirectory() + //NOI18N diff --git a/api.java.classpath/src/org/netbeans/modules/java/classpath/SimplePathResourceImplementation.java b/api.java.classpath/src/org/netbeans/modules/java/classpath/SimplePathResourceImplementation.java --- a/api.java.classpath/src/org/netbeans/modules/java/classpath/SimplePathResourceImplementation.java +++ b/api.java.classpath/src/org/netbeans/modules/java/classpath/SimplePathResourceImplementation.java @@ -50,6 +50,7 @@ import org.netbeans.spi.java.classpath.ClassPathImplementation; import java.net.URL; +import org.openide.util.Utilities; /** @@ -91,7 +92,7 @@ if (rootS.matches("file:.+[.]jar/?")) { boolean dir = false; try { - dir = new File (root.toURI()).isDirectory(); + dir = Utilities.toFile(root.toURI()).isDirectory(); } catch (URISyntaxException use) { //pass - handle as non dir } diff --git a/api.java.classpath/test/unit/src/org/netbeans/api/java/classpath/ClassPathTest.java b/api.java.classpath/test/unit/src/org/netbeans/api/java/classpath/ClassPathTest.java --- a/api.java.classpath/test/unit/src/org/netbeans/api/java/classpath/ClassPathTest.java +++ b/api.java.classpath/test/unit/src/org/netbeans/api/java/classpath/ClassPathTest.java @@ -76,6 +76,7 @@ import org.netbeans.spi.java.classpath.PathResourceImplementation; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; public class ClassPathTest extends NbTestCase { @@ -228,12 +229,12 @@ assertNotNull("Cannot find file",FileUtil.toFileObject(root_3)); TestClassPathImplementation impl = new TestClassPathImplementation(); ClassPath cp = ClassPathFactory.createClassPath (impl); - impl.addResource(root_1.toURI().toURL()); + impl.addResource(Utilities.toURI(root_1).toURL()); cp.addPropertyChangeListener (impl); - impl.addResource (root_2.toURI().toURL()); + impl.addResource (Utilities.toURI(root_2).toURL()); impl.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS); assertTrue (cp.getRoots().length==2); - impl.removeResource (root_2.toURI().toURL()); + impl.removeResource (Utilities.toURI(root_2).toURL()); impl.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS); assertTrue (cp.getRoots().length==1); FileObject fo = cp.getRoots()[0]; @@ -296,7 +297,7 @@ cp.addPropertyChangeListener(impl); File d = new File(getBaseDir(), "d"); d.mkdir(); - pri.changeRoots(new URL[] {d.toURI().toURL()}); + pri.changeRoots(new URL[] {Utilities.toURI(d).toURL()}); impl.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS); assertEquals(Collections.singletonList(FileUtil.toFileObject(d)), Arrays.asList(cp.getRoots())); } @@ -609,7 +610,7 @@ final String path = tk.nextToken(); final File f = FileUtil.normalizeFile(new File (path)); if (f.canRead()) { - roots.add(f.toURI().toURL()); + roots.add(Utilities.toURI(f).toURL()); } } final ClassLoader bootLoader = new URLClassLoader(roots.toArray(new URL[roots.size()]), null); @@ -624,7 +625,7 @@ if (!f.canRead()) { continue; } - URL url = f.toURI().toURL(); + URL url = Utilities.toURI(f).toURL(); roots2.add(url); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); @@ -739,7 +740,7 @@ } public void testJVMPathConversion() throws Exception { - String root = getWorkDir().toURI().toString(); + String root = Utilities.toURI(getWorkDir()).toString(); ClassPath cp = ClassPathSupport.createClassPath( new URL(root + "folder/"), new URL("jar:" + root + "file.zip!/"), diff --git a/api.java.classpath/test/unit/src/org/netbeans/api/java/queries/SourceForBinaryQueryTest.java b/api.java.classpath/test/unit/src/org/netbeans/api/java/queries/SourceForBinaryQueryTest.java --- a/api.java.classpath/test/unit/src/org/netbeans/api/java/queries/SourceForBinaryQueryTest.java +++ b/api.java.classpath/test/unit/src/org/netbeans/api/java/queries/SourceForBinaryQueryTest.java @@ -64,6 +64,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.ChangeSupport; +import org.openide.util.Utilities; /** * @@ -115,7 +116,7 @@ assertEquals(Collections.singletonList(sr2), Arrays.asList(res.getRoots())); assertFalse(res.preferSources()); - res = SourceForBinaryQuery.findSourceRoots2(getWorkDir().toURI().toURL()); + res = SourceForBinaryQuery.findSourceRoots2(Utilities.toURI(getWorkDir()).toURL()); assertNotNull(res); assertEquals(0, res.getRoots().length); assertTrue(res.preferSources()); @@ -135,7 +136,7 @@ assertEquals(Collections.singletonList(sr2), Arrays.asList(res.getRoots())); assertTrue(res.preferSources()); - res = SourceForBinaryQuery.findSourceRoots2(getWorkDir().toURI().toURL()); + res = SourceForBinaryQuery.findSourceRoots2(Utilities.toURI(getWorkDir()).toURL()); assertNotNull(res); assertEquals(0, res.getRoots().length); assertTrue(res.preferSources()); @@ -158,7 +159,7 @@ assertEquals(Collections.singletonList(sr2), Arrays.asList(res.getRoots())); assertFalse(res.preferSources()); - res = SourceForBinaryQuery.findSourceRoots2(getWorkDir().toURI().toURL()); + res = SourceForBinaryQuery.findSourceRoots2(Utilities.toURI(getWorkDir()).toURL()); assertNotNull(res); assertEquals(0, res.getRoots().length); assertTrue(res.preferSources()); @@ -181,7 +182,7 @@ assertEquals(Collections.singletonList(sr2), Arrays.asList(res.getRoots())); assertTrue(res.preferSources()); - res = SourceForBinaryQuery.findSourceRoots2(getWorkDir().toURI().toURL()); + res = SourceForBinaryQuery.findSourceRoots2(Utilities.toURI(getWorkDir()).toURL()); assertNotNull(res); assertEquals(0, res.getRoots().length); assertTrue(res.preferSources()); diff --git a/api.java.classpath/test/unit/src/org/netbeans/modules/java/classpath/SimplePathResourceImplementationTest.java b/api.java.classpath/test/unit/src/org/netbeans/modules/java/classpath/SimplePathResourceImplementationTest.java --- a/api.java.classpath/test/unit/src/org/netbeans/modules/java/classpath/SimplePathResourceImplementationTest.java +++ b/api.java.classpath/test/unit/src/org/netbeans/modules/java/classpath/SimplePathResourceImplementationTest.java @@ -45,6 +45,7 @@ import java.io.File; import java.net.URL; import org.netbeans.junit.NbTestCase; +import org.openide.util.Utilities; /** * @@ -101,7 +102,7 @@ final File wd = getWorkDir(); final File strangeFolder = new File(wd,"strange.jar"); //NOI18N strangeFolder.mkdirs(); - SimplePathResourceImplementation.verify(strangeFolder.toURI().toURL(),null); + SimplePathResourceImplementation.verify(Utilities.toURI(strangeFolder).toURL(),null); } catch (IllegalArgumentException e) { assertTrue("Verify should not fail for .jar folder",false); } diff --git a/apisupport.ant/nbproject/project.xml b/apisupport.ant/nbproject/project.xml --- a/apisupport.ant/nbproject/project.xml +++ b/apisupport.ant/nbproject/project.xml @@ -308,7 +308,7 @@ - 8.14 + 8.25 diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProject.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProject.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProject.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProject.java @@ -136,6 +136,7 @@ import org.openide.util.Lookup; import org.openide.util.Mutex; import org.openide.util.NbBundle.Messages; +import org.openide.util.Utilities; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; import org.openide.xml.XMLUtil; @@ -535,7 +536,7 @@ URL[] roots = platform.getSourceRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getProtocol().equals("file")) { // NOI18N - File f = new File(URI.create(roots[i].toExternalForm())); + File f = Utilities.toFile(URI.create(roots[i].toExternalForm())); if (ModuleList.isNetBeansOrg(f)) { return f; } diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProviderImpl.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProviderImpl.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProviderImpl.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProviderImpl.java @@ -73,6 +73,7 @@ import org.openide.filesystems.FileUtil; import org.openide.filesystems.XMLFileSystem; import org.openide.modules.SpecificationVersion; +import org.openide.util.Utilities; class NbModuleProviderImpl implements NbModuleProvider { @@ -196,7 +197,7 @@ if (layer != null) { File layerXml = new File(getClassesDirectory(), layer); if (layerXml.isFile()) { - otherLayerURLs.add(layerXml.toURI().toURL()); + otherLayerURLs.add(Utilities.toURI(layerXml).toURL()); } } // TODO cache diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/AntArtifactProviderImpl.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/AntArtifactProviderImpl.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/AntArtifactProviderImpl.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/AntArtifactProviderImpl.java @@ -55,6 +55,7 @@ import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.openide.util.Utilities; /** * Provide the module JAR as an exported artifact that other projects could import. @@ -104,7 +105,7 @@ throw new AssertionError(e); } } else { - return new URI[] {jar.toURI()}; + return new URI[] {Utilities.toURI(jar)}; } // XXX should it add in class path extensions? } diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/BinaryForSourceImpl.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/BinaryForSourceImpl.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/BinaryForSourceImpl.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/BinaryForSourceImpl.java @@ -57,6 +57,7 @@ import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; import org.openide.util.Parameters; +import org.openide.util.Utilities; /** * @@ -84,14 +85,14 @@ //Try project sources final FileObject srcDir = project.getSourceDirectory(); if (srcDir != null && srcDir.toURI().equals(key)) { - binRoot = project.getClassesDirectory().toURI().toURL(); + binRoot = Utilities.toURI(project.getClassesDirectory()).toURL(); } //Try project generated sources if (binRoot == null) { final File genSrcDir = project.getGeneratedClassesDirectory(); - if (genSrcDir != null && genSrcDir.toURI().equals(key)) { - binRoot = project.getClassesDirectory().toURI().toURL(); + if (genSrcDir != null && Utilities.toURI(genSrcDir).equals(key)) { + binRoot = Utilities.toURI(project.getClassesDirectory()).toURL(); } } @@ -100,12 +101,12 @@ for (final String testKind : project.supportedTestTypes()) { final FileObject testSrcDir = project.getTestSourceDirectory(testKind); if (testSrcDir != null && testSrcDir.toURI().equals(key)) { - binRoot = project.getTestClassesDirectory(testKind).toURI().toURL(); + binRoot = Utilities.toURI(project.getTestClassesDirectory(testKind)).toURL(); break; } final File testGenSrcDir = project.getTestGeneratedClassesDirectory(testKind); - if (testGenSrcDir != null && testGenSrcDir.toURI().equals(key)) { - binRoot = project.getTestClassesDirectory(testKind).toURI().toURL(); + if (testGenSrcDir != null && Utilities.toURI(testGenSrcDir).equals(key)) { + binRoot = Utilities.toURI(project.getTestClassesDirectory(testKind)).toURL(); break; } } diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImpl.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImpl.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImpl.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImpl.java @@ -70,6 +70,7 @@ import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; /** @@ -98,7 +99,7 @@ Util.err.log(binaryRoot + " is not an archive file."); // NOI18N return null; } - File binaryRootF = new File(URI.create(jar.toExternalForm())); + File binaryRootF = Utilities.toFile(URI.create(jar.toExternalForm())); // XXX this will only work for modules following regular naming conventions: String n = binaryRootF.getName(); if (!n.endsWith(".jar")) { // NOI18N diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/GlobalSourceForBinaryImpl.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/GlobalSourceForBinaryImpl.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/GlobalSourceForBinaryImpl.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/GlobalSourceForBinaryImpl.java @@ -77,6 +77,7 @@ import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; import org.openide.util.ChangeSupport; +import org.openide.util.Utilities; import org.openide.xml.XMLUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -132,7 +133,7 @@ String cnb = name.substring(0, name.length() - 4).replace('-', '.'); NbPlatform supposedPlaf = null; for (NbPlatform plaf : NbPlatform.getPlatformsOrNot()) { - String plafS = plaf.getDestDir().toURI().toURL().toExternalForm(); + String plafS = Utilities.toURI(plaf.getDestDir()).toURL().toExternalForm(); Matcher m = Pattern.compile("jar:\\Q" + plafS + "\\E[^/]+/(?:modules|lib|core)/([^/]+)[.]jar!/").matcher(binaryRootS); if (m.matches()) { supposedPlaf = plaf; @@ -235,7 +236,7 @@ @Override protected String resolveRelativePath(URL sourceRoot) throws IOException { // TODO C.P cache root + cnb -> relpath? dig into library wrappers? - File srPath = new File(URI.create(sourceRoot.toExternalForm())); + File srPath = Utilities.toFile(URI.create(sourceRoot.toExternalForm())); File moduleSrc = new File(srPath, "src"); // NOI18N if (moduleSrc.exists()) { // src root is module project root directly return "src/"; // NOI18N diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/JavadocForBinaryImpl.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/JavadocForBinaryImpl.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/JavadocForBinaryImpl.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/JavadocForBinaryImpl.java @@ -60,6 +60,7 @@ import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Utilities; /** * Defines Javadoc locations for built modules with built javadoc. @@ -134,7 +135,7 @@ URL jar = FileUtil.getArchiveFile(binaryRoot); if (jar == null) return null; // not a class-path-extension - File binaryRootF = new File(URI.create(jar.toExternalForm())); + File binaryRootF = Utilities.toFile(URI.create(jar.toExternalForm())); // XXX this will only work for modules following regular naming conventions: String n = binaryRootF.getName(); if (!n.endsWith(".jar")) { // NOI18N diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/ModuleProjectClassPathExtender.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/ModuleProjectClassPathExtender.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/ModuleProjectClassPathExtender.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/ModuleProjectClassPathExtender.java @@ -69,6 +69,7 @@ import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.openide.util.NbBundle; +import org.openide.util.Utilities; /** * Adds module dependencies that seem to correspond to some more visible artifact. @@ -199,7 +200,7 @@ // XXX handle >1 args String displayName = artifactElements.length > 0 ? artifactElements[0].toString() : ""; if (artifactElements.length > 0 && "file".equals(artifactElements[0].getScheme())) { // NOI18N - displayName = new File(artifactElements[0]).getAbsolutePath(); + displayName = Utilities.toFile(artifactElements[0]).getAbsolutePath(); } Exceptions.attachLocalizedMessage(e, NbBundle.getMessage(ModuleProjectClassPathExtender.class, "ERR_jar", displayName)); throw e; diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImpl.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImpl.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImpl.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImpl.java @@ -66,6 +66,7 @@ import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; import org.openide.xml.XMLUtil; import org.w3c.dom.Element; @@ -163,7 +164,7 @@ continue; } File jar = project.getHelper().resolveFile(piece); - Project owner = FileOwnerQuery.getOwner(jar.toURI()); + Project owner = FileOwnerQuery.getOwner(Utilities.toURI(jar)); if (owner != null) { s.add(owner); } diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/UnitTestForSourceQueryImpl.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/UnitTestForSourceQueryImpl.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/UnitTestForSourceQueryImpl.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/UnitTestForSourceQueryImpl.java @@ -57,6 +57,7 @@ import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.openide.filesystems.FileObject; +import org.openide.util.Utilities; public class UnitTestForSourceQueryImpl implements MultipleRootsUnitTestForSourceQueryImplementation { @@ -92,7 +93,7 @@ File f = helper.resolveFile(val); if (! f.exists()) { // #143633: need not to exist, ensure proper URI ending with a slash - URI u = f.toURI(); + URI u = Utilities.toURI(f); String path = u.getPath(); if (! path.endsWith("/")) path = path.concat("/"); @@ -105,7 +106,7 @@ } } - return new URL[] {f.toURI().toURL()}; + return new URL[] {Utilities.toURI(f).toURL()}; } catch (MalformedURLException e) { throw new AssertionError(e); } diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/UpdateTrackingFileOwnerQuery.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/UpdateTrackingFileOwnerQuery.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/UpdateTrackingFileOwnerQuery.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/queries/UpdateTrackingFileOwnerQuery.java @@ -57,6 +57,7 @@ import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * Associated built module files with their owning project. @@ -73,7 +74,7 @@ return null; // #65700 } if (file.getScheme().equals("file")) { // NOI18N - return getOwner(new File(file)); + return getOwner(Utilities.toFile(file)); } else { return null; } diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ClusterUtils.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ClusterUtils.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ClusterUtils.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ClusterUtils.java @@ -62,6 +62,7 @@ import org.netbeans.modules.apisupport.project.ui.customizer.SuiteProperties; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.openide.util.Utilities; /** * Utility methods for cluster-related tasks. @@ -183,7 +184,7 @@ File cd = evaluateClusterPathEntry(path, root, eval, nbPlatformRoot); boolean isPlaf = cd.getParentFile().equals(nbPlatformRoot); Project prj = null; - Project _prj = FileOwnerQuery.getOwner(cd.toURI()); + Project _prj = FileOwnerQuery.getOwner(Utilities.toURI(cd)); if (_prj != null) { // Must be actual cluster output of a suite or standalone module to qualify. See also: #168804, #180475 SuiteProvider prov = _prj.getLookup().lookup(SuiteProvider.class); diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java @@ -88,6 +88,7 @@ import org.openide.util.MutexException; import org.openide.util.NbBundle.Messages; import org.openide.util.NbCollections; +import org.openide.util.Utilities; import org.openide.xml.EntityCatalog; import org.openide.xml.XMLUtil; import org.w3c.dom.Document; @@ -965,7 +966,7 @@ String res; Document doc; try { - doc = XMLUtil.parse(new InputSource(xml.toURI().toString()), false, false, null, EntityCatalog.getDefault()); + doc = XMLUtil.parse(new InputSource(Utilities.toURI(xml).toString()), false, false, null, EntityCatalog.getDefault()); if (xpe == null) { xpe = XPathFactory.newInstance().newXPath().compile("module/param[@name='jar']/text()"); } @@ -999,7 +1000,7 @@ try { xmlFilesParsed++; timeSpentInXmlParsing -= System.currentTimeMillis(); - doc = XMLUtil.parse(new InputSource(tracking.toURI().toString()), false, false, null, null); + doc = XMLUtil.parse(new InputSource(Utilities.toURI(tracking).toString()), false, false, null, null); timeSpentInXmlParsing += System.currentTimeMillis(); } catch (SAXException e) { throw (IOException) new IOException(e.toString()).initCause(e); @@ -1038,7 +1039,7 @@ try { xmlFilesParsed++; timeSpentInXmlParsing -= System.currentTimeMillis(); - doc = XMLUtil.parse(new InputSource(projectXml.toURI().toString()), false, true, null, null); + doc = XMLUtil.parse(new InputSource(Utilities.toURI(projectXml).toString()), false, true, null, null); timeSpentInXmlParsing += System.currentTimeMillis(); } catch (SAXException e) { throw (IOException) new IOException(projectXml + ": " + e.toString()).initCause(e); // NOI18N diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/NbPlatform.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/NbPlatform.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/NbPlatform.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/NbPlatform.java @@ -86,6 +86,7 @@ import org.openide.util.MutexException; import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; +import org.openide.util.Utilities; /** * Represents one NetBeans platform, i.e. installation of the NB platform or IDE @@ -657,7 +658,7 @@ File loc = getDestDir(); if (loc.getName().equals("netbeans") && loc.getParentFile().getName().equals("nbbuild")) { // NOI18N try { - defaultSourceRoots = new URL[] {loc.getParentFile().getParentFile().toURI().toURL()}; + defaultSourceRoots = new URL[] {Utilities.toURI(loc.getParentFile().getParentFile()).toURL()}; } catch (MalformedURLException e) { assert false : e; } diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManager.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManager.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManager.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManager.java @@ -83,6 +83,7 @@ import org.openide.util.NbBundle.Messages; import org.openide.util.Parameters; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; /** * @@ -507,7 +508,7 @@ } List urll = new ArrayList(2); try { - URI juri = jar.toURI(); + URI juri = Utilities.toURI(jar); if (layer != null) { urll.add(new URL("jar:" + juri + "!/" + layer)); diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/SourceRootsSupport.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/SourceRootsSupport.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/SourceRootsSupport.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/SourceRootsSupport.java @@ -54,6 +54,7 @@ import java.util.List; import org.netbeans.modules.apisupport.project.api.Util; import org.openide.ErrorManager; +import org.openide.util.Utilities; /** @@ -124,7 +125,7 @@ if (!u.getProtocol().equals("file")) { // NOI18N continue; } - File dir = new File(URI.create(u.toExternalForm())); + File dir = Utilities.toFile(URI.create(u.toExternalForm())); if (dir.isDirectory()) { try { if (ModuleList.isNetBeansOrg(dir)) { diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/TestEntry.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/TestEntry.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/TestEntry.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/TestEntry.java @@ -57,6 +57,7 @@ import org.netbeans.spi.project.SubprojectProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * Representation of jarfile with tests @@ -130,7 +131,7 @@ public URL getSrcDir() throws IOException { String nborgPath = getNetBeansOrgPath(); if (nborgPath != null) { - return new File(getNBRoot(),nborgPath).toURI().toURL(); + return Utilities.toURI(new File(getNBRoot(),nborgPath)).toURL(); } File prjDir = getTestDistRoot(); if (prjDir == null) diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java @@ -83,6 +83,7 @@ import org.xml.sax.SAXException; import static org.netbeans.modules.apisupport.project.universe.TestModuleDependency.UNIT; import static org.netbeans.modules.apisupport.project.universe.TestModuleDependency.QA_FUNCTIONAL; +import org.openide.util.Utilities; /** * Tests ProjectXMLManager class. @@ -308,7 +309,7 @@ public Element run() { Element data = null; try { - Document doc = XMLUtil.parse(new InputSource(projectXML.toURI().toString()), + Document doc = XMLUtil.parse(new InputSource(Utilities.toURI(projectXML).toString()), false, true, null, null); Element project = doc.getDocumentElement(); Element config = XMLUtil.findElement(project, "configuration", null); // NOI18N diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/layers/LayerUtilsTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/layers/LayerUtilsTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/layers/LayerUtilsTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/layers/LayerUtilsTest.java @@ -94,6 +94,7 @@ import org.openide.filesystems.XMLFileSystem; import org.openide.loaders.DataObject; import org.openide.nodes.Node; +import org.openide.util.Utilities; /** * Test writing changes to layers. @@ -133,7 +134,7 @@ private FileSystem createCachedFS(LayerCacheManager m, File xf) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); - m.store(null, Collections.singletonList(xf.toURI().toURL()), os); + m.store(null, Collections.singletonList(Utilities.toURI(xf).toURL()), os); return m.load(null, ByteBuffer.wrap(os.toByteArray()).order(ByteOrder.LITTLE_ENDIAN)); } @@ -150,7 +151,7 @@ assertFalse(cf.exists()); assertTrue(cf.createNewFile()); OutputStream os = new BufferedOutputStream(new FileOutputStream(cf)); - URL url = xf.getName().endsWith(".jar") ? new URL("jar:" + xf.toURI() + "!/" + LAYER_PATH_IN_JAR) : xf.toURI().toURL(); + URL url = xf.getName().endsWith(".jar") ? new URL("jar:" + Utilities.toURI(xf) + "!/" + LAYER_PATH_IN_JAR) : Utilities.toURI(xf).toURL(); urll.set(0, url); m.store(null, urll, os); os.close(); @@ -190,8 +191,8 @@ new File(getDataDir(), "layers/a-layer.xml") )); - FileSystem xfs0 = new XMLFileSystem(files.get(0).toURI().toURL()); - FileSystem xfs1 = new XMLFileSystem(files.get(1).toURI().toURL()); + FileSystem xfs0 = new XMLFileSystem(Utilities.toURI(files.get(0)).toURL()); + FileSystem xfs1 = new XMLFileSystem(Utilities.toURI(files.get(1)).toURL()); FileSystem mfs = new MultiFileSystem(xfs0, xfs1); assertNotNull(xfs1.findResource("Menu/A Folder")); assertNotNull(mfs.findResource("Menu/File")); @@ -233,7 +234,7 @@ File la = new File(getDataDir(), "layers/a-layer.xml"); FileSystem cfs = createCachedFS(m, lb); - FileSystem xfs = new XMLFileSystem(la.toURI().toURL()); + FileSystem xfs = new XMLFileSystem(Utilities.toURI(la).toURL()); FileSystem mfs = new MultiFileSystem(cfs, xfs); assertNotNull(mfs.findResource("Menu/File")); assertNotNull(mfs.findResource("Menu/A Folder")); @@ -317,7 +318,7 @@ List urls = new ArrayList(NUM_LAYERS); for (File f : files) { - urls.add(f.toURI().toURL()); + urls.add(Utilities.toURI(f).toURL()); } XMLFileSystem[] xfss = new XMLFileSystem[NUM_LAYERS]; @@ -351,7 +352,7 @@ List urls = new ArrayList(NUM_LAYERS); for (File f : files) { - urls.add(new URL("jar:" + f.toURI() + "!/" + LAYER_PATH_IN_JAR)); + urls.add(new URL("jar:" + Utilities.toURI(f) + "!/" + LAYER_PATH_IN_JAR)); } XMLFileSystem[] xfss = new XMLFileSystem[NUM_LAYERS]; @@ -548,7 +549,7 @@ cmf.add(cmf.createLayerEntry("link-to-localized.shadow", null, null, null, Collections.singletonMap("originalFile", "test-module2-localized-action.instance"))); File dummyDir = new File(getWorkDir(), "dummy"); dummyDir.mkdir(); - cmf.add(cmf.createLayerEntry("link-to-url.shadow", null, null, null, Collections.singletonMap("originalFile", dummyDir.toURI().toURL()))); + cmf.add(cmf.createLayerEntry("link-to-url.shadow", null, null, null, Collections.singletonMap("originalFile", Utilities.toURI(dummyDir).toURL()))); cmf.run(); FileSystem fs = LayerUtils.getEffectiveSystemFilesystem(module2); diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/BinaryForSourceImplTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/BinaryForSourceImplTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/BinaryForSourceImplTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/BinaryForSourceImplTest.java @@ -48,6 +48,7 @@ import org.netbeans.api.java.queries.BinaryForSourceQuery; import org.netbeans.modules.apisupport.project.NbModuleProject; import org.netbeans.modules.apisupport.project.TestBase; +import org.openide.util.Utilities; /** * @@ -82,7 +83,7 @@ final File classesF = file(projectFolder, classesPath); final File srcF = file(projectFolder, srcPath); assertEquals("right binary root for " + srcPath, //NOI18N - Collections.singletonList(classesF.toURI().toURL()), - Arrays.asList(BinaryForSourceQuery.findBinaryRoots(srcF.toURI().toURL()).getRoots())); + Collections.singletonList(Utilities.toURI(classesF).toURL()), + Arrays.asList(BinaryForSourceQuery.findBinaryRoots(Utilities.toURI(srcF).toURL()).getRoots())); } } diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImplTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImplTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImplTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/GlobalJavadocForBinaryImplTest.java @@ -54,6 +54,7 @@ import org.netbeans.modules.apisupport.project.universe.NbPlatform; import org.openide.filesystems.FileUtil; import org.openide.filesystems.test.TestFileUtils; +import org.openide.util.Utilities; public class GlobalJavadocForBinaryImplTest extends TestBase { @@ -65,7 +66,7 @@ File nbDocZip = generateNbDocZip(); URL nbDocZipURL = FileUtil.urlForArchiveOrDir(nbDocZip); NbPlatform.getDefaultPlatform().addJavadocRoot(nbDocZipURL); - doTestFindJavadoc(file("openide.loaders/src").toURI().toURL(), nbDocZipURL); + doTestFindJavadoc(Utilities.toURI(file("openide.loaders/src")).toURL(), nbDocZipURL); doTestFindJavadoc(FileUtil.urlForArchiveOrDir(file("nbbuild/netbeans/platform/modules/org-openide-loaders.jar")), nbDocZipURL); } private void doTestFindJavadoc(URL binRoot, URL nbDocZipURL) throws Exception { diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImplTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImplTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImplTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImplTest.java @@ -62,6 +62,7 @@ import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * Test functionality of SourceForBinaryImpl. @@ -141,7 +142,7 @@ File srcF = PropertyUtils.resolveFile(nbRootFile(), srcS); FileObject src = FileUtil.toFileObject(srcF); assertNotNull("have " + srcF, src); - URL u = FileUtil.getArchiveRoot(jarF.toURI().toURL()); + URL u = FileUtil.getArchiveRoot(Utilities.toURI(jarF).toURL()); assertEquals("right results for " + u, Collections.singletonList(src), trimGenerated(Arrays.asList(SourceForBinaryQuery.findSourceRoots(u).getRoots()))); diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImplTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImplTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImplTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImplTest.java @@ -59,6 +59,7 @@ import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * Test subprojects. @@ -147,7 +148,7 @@ if (!f.isAbsolute()) { f = file(sp); } - expected.add(f.toURI().toString()); + expected.add(Utilities.toURI(f).toString()); } SortedSet actual = new TreeSet(); for (Project sp : spp.getSubprojects()) { diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/UnitTestForSourceQueryImplTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/UnitTestForSourceQueryImplTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/UnitTestForSourceQueryImplTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/UnitTestForSourceQueryImplTest.java @@ -55,6 +55,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Utilities; /** * Test for UnitTestForSourceQuery @@ -78,7 +79,7 @@ srcRoot = nbRoot().getFileObject("apisupport.project/src"); testRoots = UnitTestForSourceQuery.findUnitTests(srcRoot); assertEquals("Test root defined", 1, testRoots.length); - assertTrue("Test root exists", new File(URI.create(testRoots[0].toExternalForm())).exists()); + assertTrue("Test root exists", Utilities.toFile(URI.create(testRoots[0].toExternalForm())).exists()); assertEquals("Test root", URLMapper.findFileObject(testRoots[0]), nbRoot().getFileObject("apisupport.project/test/unit/src")); assertEquals("One test for this project", 1, UnitTestForSourceQuery.findUnitTests(nbRoot().getFileObject("openide.windows/src")).length); } @@ -96,7 +97,7 @@ testRoot = nbRoot().getFileObject("apisupport.project/test/unit/src"); srcRoots = UnitTestForSourceQuery.findSources(testRoot); assertEquals("Source root defined", 1, srcRoots.length); - assertTrue("Source root exists", new File(URI.create(srcRoots[0].toExternalForm())).exists()); + assertTrue("Source root exists", Utilities.toFile(URI.create(srcRoots[0].toExternalForm())).exists()); assertEquals("Source root", URLMapper.findFileObject(srcRoots[0]), nbRoot().getFileObject("apisupport.project/src")); } diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/UpdateTrackingFileOwnerQueryTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/UpdateTrackingFileOwnerQueryTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/UpdateTrackingFileOwnerQueryTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/queries/UpdateTrackingFileOwnerQueryTest.java @@ -52,6 +52,7 @@ import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * Test that project association by module inclusion list works. @@ -100,7 +101,7 @@ assertEquals("correct owner by FileObject of " + file, p, FileOwnerQuery.getOwner(fileFO)); } assertEquals("correct owner by URI of " + file, p, FileOwnerQuery.getOwner( - PropertyUtils.resolveFile(nbRootFile(), file).toURI())); + Utilities.toURI(PropertyUtils.resolveFile(nbRootFile(), file)))); } } diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/spi/BrandingSupportTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/spi/BrandingSupportTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/spi/BrandingSupportTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/spi/BrandingSupportTest.java @@ -62,6 +62,7 @@ import org.netbeans.modules.apisupport.project.universe.NbPlatform; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -138,7 +139,7 @@ File newSource = createNewSource(bFile); assertEquals(0,instance.getBrandedFiles().size()); - bFile.setBrandingSource(newSource.toURI().toURL()); + bFile.setBrandingSource(Utilities.toURI(newSource).toURL()); assertTrue(bFile.isModified()); assertEquals(0,instance.getBrandedFiles().size()); diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/suite/BuildZipDistributionTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/suite/BuildZipDistributionTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/suite/BuildZipDistributionTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/suite/BuildZipDistributionTest.java @@ -256,7 +256,7 @@ private void run(File nbexec, String... args) throws Exception { URL tu = MainCallback.class.getProtectionDomain().getCodeSource().getLocation(); - File testf = new File(tu.toURI()); + File testf = Utilities.toFile(tu.toURI()); assertTrue("file found: " + testf, testf.exists()); LinkedList allArgs = new LinkedList(Arrays.asList(args)); diff --git a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/universe/TestEntryTest.java b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/universe/TestEntryTest.java --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/universe/TestEntryTest.java +++ b/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/universe/TestEntryTest.java @@ -64,7 +64,7 @@ assertNotNull("TestEntry for aisupport/project tests",entry); assertNotNull("Nbroot wasn't found.", entry.getNBRoot()); URL srcDir = entry.getSrcDir(); - assertEquals(new File(nbRootFile(),"apisupport.project/test/unit/src").toURI().toURL(),srcDir); + assertEquals(Utilities.toURI(new File(nbRootFile(),"apisupport.project/test/unit/src")).toURL(),srcDir); } public void testGetSourcesFromExternalModule() throws IOException { @@ -73,7 +73,7 @@ assertNotNull("TestEntry for suite tests",entry); assertNull("Nbroot was found.", entry.getNBRoot()); URL srcDir = entry.getSrcDir(); - assertEquals(resolveEEPFile("/suite4/module1/test/unit/src").toURI().toURL().toExternalForm(),srcDir.toExternalForm()); + assertEquals(Utilities.toURI(resolveEEPFile("/suite4/module1/test/unit/src")).toURL().toExternalForm(),srcDir.toExternalForm()); } public void testNullsOnShortUNCPath144758() throws IOException { diff --git a/apisupport.project/nbproject/project.xml b/apisupport.project/nbproject/project.xml --- a/apisupport.project/nbproject/project.xml +++ b/apisupport.project/nbproject/project.xml @@ -259,7 +259,7 @@ - 8.6 + 8.25 diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/api/LayerHandle.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/api/LayerHandle.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/api/LayerHandle.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/api/LayerHandle.java @@ -72,6 +72,7 @@ import org.openide.filesystems.MultiFileSystem; import org.openide.filesystems.XMLFileSystem; import org.openide.util.Parameters; +import org.openide.util.Utilities; import org.xml.sax.SAXException; /** @@ -219,7 +220,7 @@ } if (generated != null && generated.isFile()) { try { - layers.add(new XMLFileSystem(generated.toURI().toString())); + layers.add(new XMLFileSystem(Utilities.toURI(generated).toString())); } catch (SAXException x) { Logger.getLogger(DualLayers.class.getName()).log(Level.INFO, "could not load " + generated, x); } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/api/ManifestManager.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/api/ManifestManager.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/api/ManifestManager.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/api/ManifestManager.java @@ -63,6 +63,7 @@ import java.util.logging.Logger; import org.netbeans.api.annotations.common.NonNull; import org.openide.modules.Dependency; +import org.openide.util.Utilities; // XXX a lot of code in this method is more or less duplicated from // org.netbeans.core.modules.Module class. Do not forgot to refactor this as @@ -210,7 +211,7 @@ if (piece.isEmpty()) { continue; } - File ext = new File(jar.getParentFile().toURI().resolve(piece.trim())); + File ext = Utilities.toFile(Utilities.toURI(jar.getParentFile()).resolve(piece.trim())); if (ext.isFile()) { ManifestManager mm2 = getInstanceFromJAR(ext); List toks = new ArrayList(Arrays.asList(mm.provTokens)); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingSupport.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingSupport.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingSupport.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingSupport.java @@ -416,7 +416,7 @@ private void loadBrandedFiles(final BrandableModule mEntry, final File file) throws IOException { String entryPath = PropertyUtils.relativizeFile(getModuleEntryDirectory(mEntry),file); - BrandedFile bf = new BrandedFile(mEntry, file.toURI().toURL(), entryPath); + BrandedFile bf = new BrandedFile(mEntry, Utilities.toURI(file).toURL(), entryPath); brandedFiles.add(bf); } @@ -565,7 +565,7 @@ this.moduleEntry = moduleEntry; this.entryPath = entry; if (source == null) { - brandingSource = moduleEntry.getJarLocation().toURI().toURL(); + brandingSource = Utilities.toURI(moduleEntry.getJarLocation()).toURL(); brandingSource = new URL("jar:" + brandingSource + "!/" + entryPath); // NOI18N } else { brandingSource = source; diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/LayerUtil.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/LayerUtil.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/LayerUtil.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/LayerUtil.java @@ -63,6 +63,7 @@ import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileSystem; import org.openide.filesystems.XMLFileSystem; +import org.openide.util.Utilities; /** * Utilities useful for {@link NbModuleProvider#getEffectiveSystemFilesystem}. @@ -103,7 +104,7 @@ String layer = mm.getLayer(); String generatedLayer = mm.getGeneratedLayer(); List urls = new ArrayList(2); - URI juri = jar.toURI(); + URI juri = Utilities.toURI(jar); for (String path : new String[] {layer, generatedLayer}) { if (path != null) { urls.add(new URL("jar:" + juri + "!/" + path)); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/BasicBrandingPanel.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/BasicBrandingPanel.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/BasicBrandingPanel.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/BasicBrandingPanel.java @@ -60,6 +60,7 @@ import org.netbeans.modules.apisupport.project.api.UIUtil; import org.openide.util.Exceptions; import org.openide.util.NbBundle; +import org.openide.util.Utilities; /** * Represents Application panel in branding editor. @@ -324,7 +325,7 @@ if (ret == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { - res = file.toURI().toURL(); + res = Utilities.toURI(file).toURL(); preview.setImage(new ImageIcon(res)); setModified(); } catch (MalformedURLException ex) { diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/ResourceBundleBrandingPanel.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/ResourceBundleBrandingPanel.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/ResourceBundleBrandingPanel.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/ResourceBundleBrandingPanel.java @@ -92,6 +92,7 @@ import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; import org.openide.util.actions.SystemAction; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; @@ -238,7 +239,7 @@ for (File file : jars) { try { - URI juri = file.toURI(); + URI juri = Utilities.toURI(file); JarFile jf = new JarFile(file); String codeNameBase = ManifestManager.getInstance(jf.getManifest(), false).getCodeNameBase(); Enumeration entries = jf.entries(); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/SplashBrandingPanel.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/SplashBrandingPanel.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/SplashBrandingPanel.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/branding/SplashBrandingPanel.java @@ -61,6 +61,7 @@ import org.netbeans.modules.apisupport.project.spi.BrandingSupport.BrandedFile; import org.openide.ErrorManager; import org.openide.util.NbBundle; +import org.openide.util.Utilities; /** * Represents Splash branding parameters panel in branding editor. @@ -524,7 +525,7 @@ if (ret == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { - splashSource = file.toURI().toURL(); + splashSource = Utilities.toURI(file).toURL(); Image oldImage = splashImage.image; splashImage.setSplashImageIcon(splashSource); Image newImage = splashImage.image; diff --git a/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/Installer.java b/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/Installer.java --- a/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/Installer.java +++ b/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/Installer.java @@ -42,7 +42,6 @@ package org.netbeans.modules.autoupdate.pluginimporter; import java.io.File; -import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -54,6 +53,7 @@ import org.netbeans.api.autoupdate.UpdateUnit; import org.netbeans.api.autoupdate.UpdateUnitProvider; import org.netbeans.api.autoupdate.UpdateUnitProviderFactory; +import org.openide.filesystems.FileUtil; import org.openide.modules.ModuleInstall; import org.openide.util.NbPreferences; import org.openide.util.RequestProcessor; @@ -190,18 +190,7 @@ String user = System.getProperty ("netbeans.user"); // NOI18N File userDir = null; if (user != null) { - userDir = new File (user); - if (userDir.getPath ().startsWith ("\\\\")) { // NOI18N - // Do not use URI.normalize for UNC paths because of http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4723726 (URI.normalize() ruins URI built from UNC File) - try { - userDir = userDir.getCanonicalFile (); - } catch (IOException ex) { - // fallback when getCanonicalFile fails - userDir = userDir.getAbsoluteFile (); - } - } else { - userDir = new File (userDir.toURI ().normalize ()).getAbsoluteFile (); - } + userDir = FileUtil.normalizeFile(new File(user)); } return userDir; diff --git a/autoupdate.services/libsrc/org/netbeans/updater/UpdateTracking.java b/autoupdate.services/libsrc/org/netbeans/updater/UpdateTracking.java --- a/autoupdate.services/libsrc/org/netbeans/updater/UpdateTracking.java +++ b/autoupdate.services/libsrc/org/netbeans/updater/UpdateTracking.java @@ -189,9 +189,10 @@ String user = System.getProperty ("netbeans.user"); File userDir = null; if (user != null) { + // XXX cannot use FileUtil.normalizeFile from here userDir = new File (user); if (userDir.getPath ().startsWith ("\\\\")) { - // Do not use URI.normalize for UNC paths because of http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4723726 (URI.normalize() ruins URI built from UNC File) + // Could use URI.normalize but only on userDir.getPath().toUri() in JDK 7 (#4723726 breaks UNC for userDir.toURI()) try { userDir = userDir.getCanonicalFile (); } catch (IOException ex) { diff --git a/core.startup/nbproject/project.xml b/core.startup/nbproject/project.xml --- a/core.startup/nbproject/project.xml +++ b/core.startup/nbproject/project.xml @@ -79,7 +79,7 @@ - 8.23 + 8.25 diff --git a/core.startup/src/org/netbeans/core/startup/CLICoreBridge.java b/core.startup/src/org/netbeans/core/startup/CLICoreBridge.java --- a/core.startup/src/org/netbeans/core/startup/CLICoreBridge.java +++ b/core.startup/src/org/netbeans/core/startup/CLICoreBridge.java @@ -60,6 +60,7 @@ import org.openide.filesystems.XMLFileSystem; import org.openide.util.Exceptions; import org.openide.util.Lookup; +import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; /** @@ -117,7 +118,7 @@ for (Module m : moduleSystem.getManager().getModules()) { for (File f : m.getAllJars()) { try { - urls.add(f.toURI().toURL()); + urls.add(Utilities.toURI(f).toURL()); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); diff --git a/core.startup/src/org/netbeans/core/startup/ModuleSystem.java b/core.startup/src/org/netbeans/core/startup/ModuleSystem.java --- a/core.startup/src/org/netbeans/core/startup/ModuleSystem.java +++ b/core.startup/src/org/netbeans/core/startup/ModuleSystem.java @@ -72,6 +72,7 @@ import org.openide.filesystems.FileUtil; import org.openide.modules.ModuleInfo; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** Controller of the IDE's whole module system. * Contains higher-level convenience methods to @@ -213,7 +214,7 @@ /* #121777 */ jarURL.getPath().startsWith("/")) { LOG.log(Level.FINE, "Considering JAR: {0}", jarURL); try { - if (ignoredJars.contains(new File(jarURL.toURI()))) { + if (ignoredJars.contains(Utilities.toFile(jarURL.toURI()))) { LOG.log(Level.FINE, "ignoring JDK/JRE manifest: {0}", manifestUrl); continue MANIFESTS; } diff --git a/core.startup/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java b/core.startup/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java --- a/core.startup/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java +++ b/core.startup/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java @@ -71,6 +71,7 @@ import org.openide.filesystems.Repository; import org.openide.filesystems.URLMapper; import org.openide.util.Exceptions; +import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; @ServiceProvider(service=URLMapper.class) @@ -92,11 +93,11 @@ archiveFile = jfs.getJarFile(); if (isRoot(archiveFile)) { try { - return new URL("jar:" + archiveFile.toURI() + "!/" + + return new URL("jar:" + Utilities.toURI(archiveFile) + "!/" + new URI(null, fo.getPath(), null).getRawSchemeSpecificPart() + (fo.isFolder() && !fo.isRoot() ? "/" : "")); // NOI18N } catch (URISyntaxException syntax) { - return new URL("jar:" + archiveFile.toURI() + "!/" + fo.getPath() + return new URL("jar:" + Utilities.toURI(archiveFile) + "!/" + fo.getPath() + ((fo.isFolder() && !fo.isRoot()) ? "/" : "")); // NOI18N } } diff --git a/core.startup/test/unit/src/org/netbeans/core/startup/layers/ArchiveURLMapperTest.java b/core.startup/test/unit/src/org/netbeans/core/startup/layers/ArchiveURLMapperTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/layers/ArchiveURLMapperTest.java +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/ArchiveURLMapperTest.java @@ -61,6 +61,7 @@ import org.netbeans.junit.RandomlyFails; import org.openide.filesystems.FileUtil; import org.openide.filesystems.JarFileSystem; +import org.openide.util.Utilities; import org.openide.util.test.TestFileUtils; /** @@ -95,7 +96,7 @@ out.putNextEntry(entry); out.write (RESOURCE.getBytes()); out.close(); - return jarFile.toURI().toURL(); + return Utilities.toURI(jarFile).toURL(); } public void testURLMapper () throws Exception { @@ -132,7 +133,7 @@ assertTrue ("".equals(rootFo.getPath())); assertTrue (rootFo.getFileSystem() instanceof JarFileSystem); File jarFile = ((JarFileSystem)rootFo.getFileSystem()).getJarFile(); - assertTrue (jarFileURL.equals(jarFile.toURI().toURL())); + assertTrue (jarFileURL.equals(Utilities.toURI(jarFile).toURL())); } public void testFunnyZipEntryNames() throws Exception { // #181671 @@ -145,7 +146,7 @@ jos.write("content".getBytes()); jos.close(); - FileObject docxFO = URLMapper.findFileObject(docx.toURI().toURL()); + FileObject docxFO = URLMapper.findFileObject(Utilities.toURI(docx).toURL()); assertNotNull(docxFO); assertTrue(FileUtil.isArchiveFile(docxFO)); @@ -182,7 +183,7 @@ jos.putNextEntry(entry); jos.write(baos.toByteArray()); jos.close(); - FileObject metaJarFO = URLMapper.findFileObject(metaJar.toURI().toURL()); + FileObject metaJarFO = URLMapper.findFileObject(Utilities.toURI(metaJar).toURL()); assertNotNull(metaJarFO); assertTrue(FileUtil.isArchiveFile(metaJarFO)); FileObject metaRoot = FileUtil.getArchiveRoot(metaJarFO); @@ -253,14 +254,14 @@ JarOutputStream jos = new JarOutputStream(new FileOutputStream(jar)); jos.putNextEntry(new ZipEntry("has spaces")); jos.close(); - URL source = new URL("jar:" + jar.toURI().toURL() + "!/has%20spaces"); + URL source = new URL("jar:" + Utilities.toURI(jar).toURL() + "!/has%20spaces"); source.toURI(); FileObject file = URLMapper.findFileObject(source); assertNotNull(file); assertEquals(source, URLMapper.findURL(file, URLMapper.INTERNAL)); assertEquals(0, source.openConnection().getContentLength()); ProxyURLStreamHandlerFactory.register(); - assertEquals(0, new URL("jar:" + jar.toURI().toURL() + "!/has%20spaces").openConnection().getContentLength()); + assertEquals(0, new URL("jar:" + Utilities.toURI(jar).toURL() + "!/has%20spaces").openConnection().getContentLength()); } } diff --git a/core.startup/test/unit/src/org/netbeans/core/startup/layers/AttributeChangeIsNotifiedTest.java b/core.startup/test/unit/src/org/netbeans/core/startup/layers/AttributeChangeIsNotifiedTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/layers/AttributeChangeIsNotifiedTest.java +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/AttributeChangeIsNotifiedTest.java @@ -57,6 +57,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileRenameEvent; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -100,8 +101,8 @@ { List list = new ArrayList(); - list.add(f1.toURI().toURL()); - list.add(f3.toURI().toURL()); + list.add(Utilities.toURI(f1).toURL()); + list.add(Utilities.toURI(f3).toURL()); fs.setURLs (list); } @@ -121,8 +122,8 @@ { List list = new ArrayList(); - list.add(f2.toURI().toURL()); - list.add(f3.toURI().toURL()); + list.add(Utilities.toURI(f2).toURL()); + list.add(Utilities.toURI(f3).toURL()); fs.setURLs (list); } String v2 = (String) file.getAttribute("value"); diff --git a/core.startup/test/unit/src/org/netbeans/core/startup/layers/CacheManagerTestBaseHid.java b/core.startup/test/unit/src/org/netbeans/core/startup/layers/CacheManagerTestBaseHid.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/layers/CacheManagerTestBaseHid.java +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/CacheManagerTestBaseHid.java @@ -62,6 +62,7 @@ import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; import org.openide.filesystems.MultiFileSystem; +import org.openide.util.Utilities; import org.openide.util.test.TestFileUtils; /** Test layer cache managers generally. * @author Jesse Glick @@ -111,7 +112,7 @@ } protected URL loadResource(String name) throws IOException { - return new URL(new URL(getDataDir().toURI().toURL(), "layers/"), name); + return new URL(new URL(Utilities.toURI(getDataDir()).toURL(), "layers/"), name); } public void testCacheManager() throws Exception { diff --git a/java.api.common/nbproject/project.xml b/java.api.common/nbproject/project.xml --- a/java.api.common/nbproject/project.xml +++ b/java.api.common/nbproject/project.xml @@ -215,7 +215,7 @@ - 8.0 + 8.25 diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/SourceRoots.java b/java.api.common/src/org/netbeans/modules/java/api/common/SourceRoots.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/SourceRoots.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/SourceRoots.java @@ -79,6 +79,7 @@ import org.openide.util.Mutex; import org.openide.util.NbBundle; import org.openide.util.Parameters; +import org.openide.util.Utilities; import org.openide.util.WeakListeners; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -277,7 +278,7 @@ if (prop != null) { File f = helper.getAntProjectHelper().resolveFile(prop); try { - URL url = f.toURI().toURL(); + URL url = Utilities.toURI(f).toURL(); if (!f.exists()) { url = new URL(url.toExternalForm() + "/"); // NOI18N } else if (f.isFile()) { @@ -312,7 +313,7 @@ if (prop != null) { File f = helper.getAntProjectHelper().resolveFile(prop); try { - URL url = f.toURI().toURL(); + URL url = Utilities.toURI(f).toURL(); if (!f.exists()) { url = new URL(url.toExternalForm() + "/"); // NOI18N } else if (f.isFile()) { @@ -383,7 +384,7 @@ rootName = MessageFormat.format( newRootNameTemplate, new Object[] {names[names.length - 1], rootIndex}); } - File f = FileUtil.normalizeFile(new File(URI.create(newRoot.toExternalForm()))); + File f = FileUtil.normalizeFile(Utilities.toFile(URI.create(newRoot.toExternalForm()))); File projDir = FileUtil.toFile(helper.getAntProjectHelper().getProjectDirectory()); String path = f.getAbsolutePath(); String prjPath = projDir.getAbsolutePath() + File.separatorChar; diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathSupport.java b/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathSupport.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathSupport.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathSupport.java @@ -73,6 +73,7 @@ import org.netbeans.spi.project.support.ant.EditableProperties; import org.openide.filesystems.FileUtil; import org.openide.util.Parameters; +import org.openide.util.Utilities; /** * Support for reading/writting classpath like properties. @@ -167,16 +168,7 @@ AntArtifact artifact = (AntArtifact)ret[0]; URI uri = (URI)ret[1]; File usedFile = antProjectHelper.resolveFile(evaluator.evaluate(pe[i])); - /* Workaround for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4723726 (URI.normalize() ruins URI built from UNC File) */ - File artifactFile = null; - if(uri.isAbsolute()) { - artifactFile = new File(uri); - } else { - artifactFile = new File(artifact.getScriptLocation().getParent(), uri.getPath()); - } - artifactFile = FileUtil.normalizeFile(artifactFile); - //File artifactFile = new File (artifact.getScriptLocation().toURI().resolve(uri).normalize()); - /* End of UNC workaround */ + File artifactFile = Utilities.toFile(Utilities.toURI(artifact.getScriptLocation()).resolve(uri).normalize()); if (usedFile.equals(artifactFile)) { item = Item.create( artifact, uri, pe[i]); } diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/SourcePathImplementation.java b/java.api.common/src/org/netbeans/modules/java/api/common/classpath/SourcePathImplementation.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/SourcePathImplementation.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/classpath/SourcePathImplementation.java @@ -69,6 +69,7 @@ import org.openide.filesystems.FileRenameEvent; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; +import org.openide.util.Utilities; import org.openide.util.WeakListeners; /** @@ -146,8 +147,7 @@ if (matcher == null) { matcher = new PathMatcher( evaluator.getProperty(ProjectProperties.INCLUDES), - evaluator.getProperty(ProjectProperties.EXCLUDES), - new File(URI.create(root.toExternalForm()))); + evaluator.getProperty(ProjectProperties.EXCLUDES), Utilities.toFile(URI.create(root.toExternalForm()))); } return matcher.matches(resource, true); } @@ -192,7 +192,7 @@ if (root.equals(apSourcesDir)) { continue; } - result.add(ClassPathSupport.createResource(root.toURI().toURL())); + result.add(ClassPathSupport.createResource(Utilities.toURI(root).toURL())); } } } diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/LibrariesNode.java b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/LibrariesNode.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/LibrariesNode.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/LibrariesNode.java @@ -107,6 +107,7 @@ import org.netbeans.spi.java.project.support.ui.PackageView; import org.netbeans.spi.project.libraries.support.LibrariesSupport; import org.openide.util.Exceptions; +import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; /** @@ -903,7 +904,7 @@ } else { //No MimeResolver fallback - return FileUtil.isArchiveFile(f.toURI().toURL()); + return FileUtil.isArchiveFile(Utilities.toURI(f).toURL()); } } catch (MalformedURLException mue) { Exceptions.printStackTrace(mue); diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/ProjectNode.java b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/ProjectNode.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/ProjectNode.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/ProjectNode.java @@ -77,6 +77,7 @@ import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; import org.openide.util.Lookup; +import org.openide.util.Utilities; @@ -235,7 +236,7 @@ File scriptLocation = this.antArtifact.getScriptLocation(); Set urls = new HashSet(); try { - URL artifactURL = scriptLocation.toURI().resolve(this.artifactLocation).normalize().toURL(); + URL artifactURL = Utilities.toURI(scriptLocation).resolve(this.artifactLocation).normalize().toURL(); if (FileUtil.isArchiveFile(artifactURL)) { artifactURL = FileUtil.getArchiveRoot(artifactURL); } diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/EditMediator.java b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/EditMediator.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/EditMediator.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/EditMediator.java @@ -89,6 +89,7 @@ import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.util.NbPreferences; +import org.openide.util.Utilities; /** * Visual classpath customizer support. @@ -368,7 +369,7 @@ String path = libraryPath.getText(0, libraryPath.getLength()); if (path != null && path.length() > 0) { File fil = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), path); - librariesFolder = FileUtil.normalizeFile(fil).toURI().toURL(); + librariesFolder = Utilities.toURI(FileUtil.normalizeFile(fil)).toURL(); manager = LibraryManager.forLocation(librariesFolder); } else { empty = true; diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/SourceRootsUi.java b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/SourceRootsUi.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/SourceRootsUi.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/SourceRootsUi.java @@ -92,6 +92,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.NbBundle; +import org.openide.util.Utilities; /** Handles adding, removing, reordering of source roots. * @@ -110,7 +111,7 @@ URL[] rootURLs = roots.getRootURLs(); Object[][] data = new Object[rootURLs.length] [2]; for (int i=0; i< rootURLs.length; i++) { - data[i][0] = new File (URI.create (rootURLs[i].toExternalForm())); + data[i][0] = Utilities.toFile(URI.create (rootURLs[i].toExternalForm())); data[i][1] = roots.getRootDisplayName(rootLabels[i], rootProps[i]); } return new SourceRootsModel(data); @@ -382,7 +383,7 @@ rootsFromRelatedSourceRoots.add (normalizedFile); continue; } - if ((p=FileOwnerQuery.getOwner(normalizedFile.toURI()))!=null && !p.getProjectDirectory().equals(project.getProjectDirectory())) { + if ((p=FileOwnerQuery.getOwner(Utilities.toURI(normalizedFile)))!=null && !p.getProjectDirectory().equals(project.getProjectDirectory())) { final Sources sources = p.getLookup().lookup(Sources.class); if (sources == null) { rootsFromOtherProjects.add (normalizedFile); @@ -622,7 +623,7 @@ File f = (File) value; String message = f.getAbsolutePath(); if (projectConflict) { - Project p = FileOwnerQuery.getOwner(f.toURI()); + Project p = FileOwnerQuery.getOwner(Utilities.toURI(f)); if (p!=null) { ProjectInformation pi = ProjectUtils.getInformation(p); String projectName = pi.getDisplayName(); diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/wizards/FolderList.java b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/wizards/FolderList.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/wizards/FolderList.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/wizards/FolderList.java @@ -86,6 +86,7 @@ import org.openide.filesystems.FileUtil; import org.openide.util.Cancellable; import org.openide.util.NbBundle; +import org.openide.util.Utilities; /** @@ -383,7 +384,7 @@ public static boolean isValidRoot (File file, File[] relatedRoots, File projectFolder) { Project p; - if ((p = FileOwnerQuery.getOwner(file.toURI()))!=null + if ((p = FileOwnerQuery.getOwner(Utilities.toURI(file)))!=null && !file.getAbsolutePath().startsWith(projectFolder.getAbsolutePath()+File.separatorChar)) { final Sources sources = p.getLookup().lookup(Sources.class); if (sources == null) { diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/queries/AnnotationProcessingQueryImpl.java b/java.api.common/src/org/netbeans/modules/java/api/common/queries/AnnotationProcessingQueryImpl.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/queries/AnnotationProcessingQueryImpl.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/queries/AnnotationProcessingQueryImpl.java @@ -69,6 +69,7 @@ import org.openide.filesystems.FileObject; import org.openide.modules.SpecificationVersion; import org.openide.util.ChangeSupport; +import org.openide.util.Utilities; import org.openide.util.WeakListeners; /** @@ -174,7 +175,7 @@ File output = helper.resolveFile(prop); try { - return output.toURI().toURL(); + return Utilities.toURI(output).toURL(); } catch (MalformedURLException ex) { Logger.getLogger(AnnotationProcessingQueryImpl.class.getName()).log(Level.FINE, null, ex); return null; diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/queries/BinaryForSourceQueryImpl.java b/java.api.common/src/org/netbeans/modules/java/api/common/queries/BinaryForSourceQueryImpl.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/queries/BinaryForSourceQueryImpl.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/queries/BinaryForSourceQueryImpl.java @@ -60,6 +60,7 @@ import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.openide.filesystems.FileUtil; import org.openide.util.ChangeSupport; +import org.openide.util.Utilities; /** * @@ -114,7 +115,7 @@ } String buildGeneratedDirS = eval.getProperty("build.generated.sources.dir"); if (buildGeneratedDirS != null) { // #105645 - String parent = helper.resolveFile(buildGeneratedDirS).toURI().toString(); + String parent = Utilities.toURI(helper.resolveFile(buildGeneratedDirS)).toString(); if (sourceRoot.toString().startsWith(parent)) { result = new R(sourceProps); cache.put(sourceRoot, result); diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/queries/CompiledSourceForBinaryQueryImpl.java b/java.api.common/src/org/netbeans/modules/java/api/common/queries/CompiledSourceForBinaryQueryImpl.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/queries/CompiledSourceForBinaryQueryImpl.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/queries/CompiledSourceForBinaryQueryImpl.java @@ -64,6 +64,7 @@ import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.openide.util.ChangeSupport; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * Default implementation of {@link SourceForBinaryQueryImplementation}. @@ -134,7 +135,7 @@ String outDir = evaluator.getProperty(binaryProperty); if (outDir != null) { File f = helper.resolveFile(outDir); - URL url = f.toURI().toURL(); + URL url = Utilities.toURI(f).toURL(); if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N // non-existing assert !url.toExternalForm().endsWith("/") : f; // NOI18N diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/queries/JavadocForBinaryQueryImpl.java b/java.api.common/src/org/netbeans/modules/java/api/common/queries/JavadocForBinaryQueryImpl.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/queries/JavadocForBinaryQueryImpl.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/queries/JavadocForBinaryQueryImpl.java @@ -56,6 +56,7 @@ import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.openide.util.ChangeSupport; import org.openide.util.Exceptions; +import org.openide.util.Utilities; import org.openide.util.WeakListeners; /** @@ -106,7 +107,7 @@ if (javadocDir != null) { File f = helper.resolveFile(javadocDir); try { - URL url = f.toURI().toURL(); + URL url = Utilities.toURI(f).toURL(); if (!f.exists()) { assert !url.toExternalForm().endsWith("/") : f; // NOI18N url = new URL(url.toExternalForm() + "/"); // NOI18N @@ -165,7 +166,7 @@ String outDir = evaluator.getProperty(binaryProperty); if (outDir != null) { File f = helper.resolveFile(outDir); - URL url = f.toURI().toURL(); + URL url = Utilities.toURI(f).toURL(); if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N assert !url.toExternalForm().endsWith("/") : f; // NOI18N url = new URL(url.toExternalForm() + "/"); // NOI18N diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java b/java.api.common/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java @@ -67,6 +67,7 @@ import org.netbeans.spi.queries.SharabilityQueryImplementation2; import org.openide.loaders.CreateFromTemplateAttributesProvider; import org.openide.util.Parameters; +import org.openide.util.Utilities; import org.openide.util.WeakListeners; import org.w3c.dom.Element; @@ -208,7 +209,7 @@ final SharabilityQueryImplementation2 sq2 = createSharabilityQuery2(helper, evaluator, srcRoots, testRoots, additionalSourceRoots); return new SharabilityQueryImplementation() { @Override public int getSharability(File file) { - return sq2.getSharability(file.toURI()).ordinal(); + return sq2.getSharability(Utilities.toURI(file)).ordinal(); } }; } diff --git a/java.j2seproject/nbproject/project.xml b/java.j2seproject/nbproject/project.xml --- a/java.j2seproject/nbproject/project.xml +++ b/java.j2seproject/nbproject/project.xml @@ -299,7 +299,7 @@ - 8.6 + 8.25 diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectOperations.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectOperations.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectOperations.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectOperations.java @@ -73,6 +73,7 @@ import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle; +import org.openide.util.Utilities; /** * @@ -334,7 +335,7 @@ if (libraryPath != null) { File prjRoot = FileUtil.toFile(project.getProjectDirectory()); libraryFile = PropertyUtils.resolveFile(prjRoot, libraryPath); - if (FileOwnerQuery.getOwner(libraryFile.toURI()) == project && + if (FileOwnerQuery.getOwner(Utilities.toURI(libraryFile)) == project && libraryFile.getAbsolutePath().startsWith(prjRoot.getAbsolutePath())) { //do not update the relative path if within the project.. libraryWithinProject = true; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNodeFactory.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNodeFactory.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNodeFactory.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNodeFactory.java @@ -70,6 +70,7 @@ import org.openide.nodes.Node; import org.openide.util.ChangeSupport; import org.openide.util.NbBundle; +import org.openide.util.Utilities; /** * @@ -118,7 +119,7 @@ URL[] testRoots = testSources.getRootURLs(); boolean addTestSources = false; for (int i = 0; i < testRoots.length; i++) { - File f = new File(URI.create(testRoots[i].toExternalForm())); + File f = Utilities.toFile(URI.create(testRoots[i].toExternalForm())); if (f.exists()) { addTestSources = true; break; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java @@ -69,6 +69,7 @@ import org.openide.util.Exceptions; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; +import org.openide.util.Utilities; /** Customizer for general project attributes. * @@ -230,7 +231,7 @@ try { File base = FileUtil.toFile(uiProperties.getProject().getProjectDirectory()); File location = FileUtil.normalizeFile(PropertyUtils.resolveFile(base, loc)); - URL url = location.toURI().toURL(); + URL url = Utilities.toURI(location).toURL(); man = LibraryManager.forLocation(url); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); diff --git a/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/J2SEProjectGeneratorTest.java b/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/J2SEProjectGeneratorTest.java --- a/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/J2SEProjectGeneratorTest.java +++ b/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/J2SEProjectGeneratorTest.java @@ -67,6 +67,7 @@ import org.openide.filesystems.FileUtil; import org.openide.modules.SpecificationVersion; import org.openide.util.Lookup; +import org.openide.util.Utilities; import org.openide.util.test.MockLookup; /** @@ -154,8 +155,8 @@ AntProjectHelper helper = J2SEProjectGenerator.createProject(proj, "test-project-ext-src", new File[] {srcRoot}, new File[] {testRoot}, "manifest.mf", null, null); final Project expected = FileOwnerQuery.getOwner(helper.getProjectDirectory()); assertNotNull(expected); - assertEquals(expected, FileOwnerQuery.getOwner(srcRoot.toURI())); - assertEquals(expected, FileOwnerQuery.getOwner(testRoot.toURI())); + assertEquals(expected, FileOwnerQuery.getOwner(Utilities.toURI(srcRoot))); + assertEquals(expected, FileOwnerQuery.getOwner(Utilities.toURI(testRoot))); } public void testProjectBuilder() throws Exception { diff --git a/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifierTest.java b/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifierTest.java --- a/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifierTest.java +++ b/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifierTest.java @@ -77,6 +77,7 @@ import org.openide.filesystems.test.TestFileUtils; import org.openide.modules.SpecificationVersion; import org.openide.util.Lookup; +import org.openide.util.Utilities; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.openide.util.test.MockLookup; @@ -164,7 +165,7 @@ assertEquals(1,cpRoots.length); URI projectURI = URI.create(output.getProject().getProjectDirectory().toURL().toExternalForm()); URI expected = projectURI.resolve(output.getArtifactLocations()[0]); - assertEquals(expected,this.helper.resolveFile(cpRoots[0]).toURI()); + assertEquals(expected,Utilities.toURI(this.helper.resolveFile(cpRoots[0]))); ProjectClassPathModifier.removeAntArtifacts(new AntArtifact[] {output}, new URI[] {output.getArtifactLocations()[0]},this.src, ClassPath.COMPILE); cp = this.eval.getProperty("javac.classpath"); assertNotNull (cp); @@ -202,7 +203,7 @@ @RandomlyFails // NB-Core-Build #3223; javac.classpath="" after addition public void testProjectLibrary() throws Exception { assertEquals(Collections.emptyList(), getPrjLibRefs()); - URL base = getWorkDir().toURI().toURL(); + URL base = Utilities.toURI(getWorkDir()).toURL(); helper.setLibrariesLocation(".."+File.separatorChar+"defs.properties"); Library lib = LibraryManager.forLocation(new URL(base, "defs.properties")).createLibrary("j2se", "test", Collections.singletonMap("classpath", Collections.singletonList(new URL(base, "stuff/")))); diff --git a/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementationTest.java b/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementationTest.java --- a/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementationTest.java +++ b/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementationTest.java @@ -71,6 +71,7 @@ import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator; import org.netbeans.modules.java.j2seproject.SourceRootsTest; import org.openide.util.Mutex; +import org.openide.util.Utilities; import org.openide.util.test.MockLookup; public class SourcePathImplementationTest extends NbTestCase { @@ -175,12 +176,12 @@ src2.mkdir(); AntProjectHelper h = J2SEProjectGenerator.createProject(new File(getWorkDir(), "prj"), "test", new File[] {src1, src2}, new File[0], null, null, null); Project p = ProjectManager.getDefault().findProject(h.getProjectDirectory()); - FileOwnerQuery.markExternalOwner(src1.toURI(), p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); + FileOwnerQuery.markExternalOwner(Utilities.toURI(src1), p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); ClassPath cp = ClassPath.getClassPath(FileUtil.toFileObject(src1), ClassPath.SOURCE); assertNotNull(cp); assertEquals(2, cp.getRoots().length); ClassPath.Entry cpe2 = cp.entries().get(1); - assertEquals(src2.toURI().toURL(), cpe2.getURL()); + assertEquals(Utilities.toURI(src2).toURL(), cpe2.getURL()); assertTrue(cpe2.includes("stuff/")); assertTrue(cpe2.includes("whatever/")); class L implements PropertyChangeListener { diff --git a/java.project/nbproject/project.xml b/java.project/nbproject/project.xml --- a/java.project/nbproject/project.xml +++ b/java.project/nbproject/project.xml @@ -240,7 +240,7 @@ - 8.0 + 8.25 diff --git a/java.project/src/org/netbeans/api/java/project/classpath/ProjectClassPathModifier.java b/java.project/src/org/netbeans/api/java/project/classpath/ProjectClassPathModifier.java --- a/java.project/src/org/netbeans/api/java/project/classpath/ProjectClassPathModifier.java +++ b/java.project/src/org/netbeans/api/java/project/classpath/ProjectClassPathModifier.java @@ -63,6 +63,7 @@ import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; import org.openide.util.Parameters; +import org.openide.util.Utilities; /** * An API for project's classpaths modification. @@ -194,7 +195,7 @@ } final FileObject fo; if (urlToAdd.isAbsolute()) { - fo = FileUtil.toFileObject(new File(urlToAdd)); + fo = FileUtil.toFileObject(Utilities.toFile(urlToAdd)); } else { File f = PropertyUtils.resolveFile(projectFolderFile, LibrariesSupport.convertURIToFilePath(urlToAdd)); fo = FileUtil.toFileObject(f); diff --git a/java.project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java b/java.project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java --- a/java.project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java +++ b/java.project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java @@ -70,6 +70,7 @@ import org.openide.filesystems.URLMapper; import org.openide.util.ChangeSupport; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * @@ -164,7 +165,7 @@ // #138349 - ignore non existing paths or entries with undefined IDE variables if (src.exists()) { try { - URL url = src.toURI().toURL(); + URL url = Utilities.toURI(src).toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } diff --git a/java.project/src/org/netbeans/spi/java/project/classpath/support/ProjectClassPathImplementation.java b/java.project/src/org/netbeans/spi/java/project/classpath/support/ProjectClassPathImplementation.java --- a/java.project/src/org/netbeans/spi/java/project/classpath/support/ProjectClassPathImplementation.java +++ b/java.project/src/org/netbeans/spi/java/project/classpath/support/ProjectClassPathImplementation.java @@ -65,6 +65,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Utilities; import org.openide.util.WeakListeners; /** @@ -150,7 +151,7 @@ //Logging for issue #181155, #186213 String foStatus; try { - final FileObject fo = URLMapper.findFileObject(f.toURI().toURL()); + final FileObject fo = URLMapper.findFileObject(Utilities.toURI(f).toURL()); foStatus = fo == null ? "not exist" : fo.isValid() ? fo.isFolder() ? "valid folder" : "valid file" : "invalid"; //NOI18N } catch (MalformedURLException ex) { foStatus = "malformed"; //NOI18N diff --git a/java.project/src/org/netbeans/spi/java/project/support/ui/MakeSharableVisualPanel2.java b/java.project/src/org/netbeans/spi/java/project/support/ui/MakeSharableVisualPanel2.java --- a/java.project/src/org/netbeans/spi/java/project/support/ui/MakeSharableVisualPanel2.java +++ b/java.project/src/org/netbeans/spi/java/project/support/ui/MakeSharableVisualPanel2.java @@ -82,6 +82,7 @@ import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; import org.openide.util.NbCollections; +import org.openide.util.Utilities; final class MakeSharableVisualPanel2 extends JPanel { @@ -360,7 +361,7 @@ File libraryFile = helper.resolveFile(location); File prjDir = FileUtil.toFile(helper.getProjectDirectory()); boolean absoluteLibrary = LibrariesSupport.convertFilePathToURI(location).isAbsolute(); - LibraryManager newmanager = LibraryManager.forLocation(libraryFile.toURI().toURL()); + LibraryManager newmanager = LibraryManager.forLocation(Utilities.toURI(libraryFile).toURL()); LibraryManager oldmanager = LibraryManager.getDefault(); //TODO once we support moving from one place to another, change this for (String lib : libraries) { Library library = oldmanager.getLibrary(lib); diff --git a/java.project/src/org/netbeans/spi/java/project/support/ui/SharableLibrariesUtils.java b/java.project/src/org/netbeans/spi/java/project/support/ui/SharableLibrariesUtils.java --- a/java.project/src/org/netbeans/spi/java/project/support/ui/SharableLibrariesUtils.java +++ b/java.project/src/org/netbeans/spi/java/project/support/ui/SharableLibrariesUtils.java @@ -88,6 +88,7 @@ import org.openide.util.NbBundle.Messages; import org.openide.util.NbCollections; import org.openide.util.NbPreferences; +import org.openide.util.Utilities; /** * Utility methods related to sharable libraries UI. @@ -470,7 +471,7 @@ assert loc != null; File mainPropertiesFile = helper.resolveFile(loc); try { - LibraryManager man = LibraryManager.forLocation(mainPropertiesFile.toURI().toURL()); + LibraryManager man = LibraryManager.forLocation(Utilities.toURI(mainPropertiesFile).toURL()); Map> volumes = new HashMap>(); LibraryTypeProvider provider = LibrariesSupport.getLibraryTypeProvider(library.getType()); assert provider != null; @@ -492,13 +493,13 @@ String str = PropertyUtils.relativizeFile(mainPropertiesFile.getParentFile(), path); if (str == null) { // the relative path cannot be established, different drives? - uri = path.toURI(); + uri = Utilities.toURI(path); } else { uri = LibrariesSupport.convertFilePathToURI(str); } } else { File path = FileUtil.toFile(fo); - uri = path.toURI(); + uri = Utilities.toURI(path); } if (FileUtil.isArchiveFile(fo)) { uri = appendJarFolder(uri, jarFolder); diff --git a/java.project/test/unit/src/org/netbeans/modules/java/project/JavaAntLoggerTest.java b/java.project/test/unit/src/org/netbeans/modules/java/project/JavaAntLoggerTest.java --- a/java.project/test/unit/src/org/netbeans/modules/java/project/JavaAntLoggerTest.java +++ b/java.project/test/unit/src/org/netbeans/modules/java/project/JavaAntLoggerTest.java @@ -64,6 +64,7 @@ import org.openide.filesystems.FileUtil; import org.openide.modules.InstalledFileLocator; import org.openide.util.Lookup; +import org.openide.util.Utilities; import org.openide.util.test.MockLookup; import org.openide.windows.IOProvider; import org.openide.windows.InputOutput; @@ -148,8 +149,8 @@ private FileObject src, testSrc; public void setSimpleAppDir(File simpleAppDir) throws Exception { - buildClasses = slashify(new File(simpleAppDir, "build" + File.separatorChar + "classes").toURI().toURL()); - buildTestClasses = slashify(new File(simpleAppDir, "build" + File.separatorChar + "test" + File.separatorChar + "classes").toURI().toURL()); + buildClasses = slashify(Utilities.toURI(new File(simpleAppDir, "build" + File.separatorChar + "classes")).toURL()); + buildTestClasses = slashify(Utilities.toURI(new File(simpleAppDir, "build" + File.separatorChar + "test" + File.separatorChar + "classes")).toURL()); src = FileUtil.toFileObject(new File(simpleAppDir, "src")); testSrc = FileUtil.toFileObject(new File(simpleAppDir, "test")); } diff --git a/java.source.ant/antsrc/org/netbeans/modules/java/source/ant/JavacTask.java b/java.source.ant/antsrc/org/netbeans/modules/java/source/ant/JavacTask.java --- a/java.source.ant/antsrc/org/netbeans/modules/java/source/ant/JavacTask.java +++ b/java.source.ant/antsrc/org/netbeans/modules/java/source/ant/JavacTask.java @@ -57,6 +57,7 @@ import org.netbeans.modules.java.source.usages.BuildArtifactMapperImpl; import org.netbeans.modules.parsing.api.indexing.IndexingManager; import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.openide.util.Utilities; /** * @@ -84,7 +85,7 @@ File f = PropertyUtils.resolveFile(p.getBaseDir().getAbsoluteFile(), path); try { - Boolean built = BuildArtifactMapperImpl.ensureBuilt(f.toURI().toURL(), getProject(), false, true); + Boolean built = BuildArtifactMapperImpl.ensureBuilt(Utilities.toURI(f).toURL(), getProject(), false, true); if (built == null) { noBin = true; @@ -134,7 +135,7 @@ try { p.log("Forcing rescan of: " + f.getAbsolutePath(), Project.MSG_VERBOSE); - IndexingManager.getDefault().refreshIndex(f.toURI().toURL(), null, false); + IndexingManager.getDefault().refreshIndex(Utilities.toURI(f).toURL(), null, false); } catch (MalformedURLException ex) { p.log(ex.getMessage(), ex, Project.MSG_VERBOSE); } diff --git a/java.source.ant/antsrc/org/netbeans/modules/java/source/ant/TranslateClassPath.java b/java.source.ant/antsrc/org/netbeans/modules/java/source/ant/TranslateClassPath.java --- a/java.source.ant/antsrc/org/netbeans/modules/java/source/ant/TranslateClassPath.java +++ b/java.source.ant/antsrc/org/netbeans/modules/java/source/ant/TranslateClassPath.java @@ -58,6 +58,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Utilities; /** * @@ -148,8 +149,8 @@ continue; } - final Boolean bamiResult = clean ? BuildArtifactMapperImpl.clean(sourceFile.toURI().toURL()) - : BuildArtifactMapperImpl.ensureBuilt(sourceFile.toURI().toURL(), getProject(), true, true); + final Boolean bamiResult = clean ? BuildArtifactMapperImpl.clean(Utilities.toURI(sourceFile).toURL()) + : BuildArtifactMapperImpl.ensureBuilt(Utilities.toURI(sourceFile).toURL(), getProject(), true, true); if (bamiResult == null) { appendEntry = true; continue; diff --git a/java.source.ant/nbproject/project.xml b/java.source.ant/nbproject/project.xml --- a/java.source.ant/nbproject/project.xml +++ b/java.source.ant/nbproject/project.xml @@ -156,7 +156,7 @@ - 8.0 + 8.25 diff --git a/java.source.ant/src/org/netbeans/modules/java/source/ant/ProjectRunnerImpl.java b/java.source.ant/src/org/netbeans/modules/java/source/ant/ProjectRunnerImpl.java --- a/java.source.ant/src/org/netbeans/modules/java/source/ant/ProjectRunnerImpl.java +++ b/java.source.ant/src/org/netbeans/modules/java/source/ant/ProjectRunnerImpl.java @@ -105,6 +105,7 @@ import org.netbeans.api.project.ProjectManager; import org.openide.loaders.DataObject; import org.openide.util.Lookup; +import org.openide.util.Utilities; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; @@ -484,7 +485,7 @@ continue; } - BuildArtifactMapperImpl.clean(sourceFile.toURI().toURL()); + BuildArtifactMapperImpl.clean(Utilities.toURI(sourceFile).toURL()); } } } diff --git a/java.source/nbproject/project.xml b/java.source/nbproject/project.xml --- a/java.source/nbproject/project.xml +++ b/java.source/nbproject/project.xml @@ -383,7 +383,7 @@ - 8.4 + 8.25 diff --git a/java.source/src/org/netbeans/api/java/source/ModificationResult.java b/java.source/src/org/netbeans/api/java/source/ModificationResult.java --- a/java.source/src/org/netbeans/api/java/source/ModificationResult.java +++ b/java.source/src/org/netbeans/api/java/source/ModificationResult.java @@ -178,7 +178,7 @@ for (List ds:diffs.values()) { for (Difference d: ds) { if (d.getKind() == Difference.Kind.CREATE) { - newFiles.add(new File(((CreateChange) d).getFileObject().toUri())); + newFiles.add(org.openide.util.Utilities.toFile(((CreateChange) d).getFileObject().toUri())); } } } diff --git a/java.source/src/org/netbeans/api/java/source/SourceUtils.java b/java.source/src/org/netbeans/api/java/source/SourceUtils.java --- a/java.source/src/org/netbeans/api/java/source/SourceUtils.java +++ b/java.source/src/org/netbeans/api/java/source/SourceUtils.java @@ -970,7 +970,7 @@ Iterable mainClasses = ExecutableFilesIndex.DEFAULT.getMainClasses(rootURL); List> classes = new LinkedList>(); for (URL mainClass : mainClasses) { - File mainFo = new File (URI.create(mainClass.toExternalForm())); + File mainFo = Utilities.toFile(URI.create(mainClass.toExternalForm())); if (mainFo.exists()) { classes.addAll(JavaCustomIndexer.getRelatedTypes(mainFo, rootFile)); } diff --git a/java.source/src/org/netbeans/api/java/source/WorkingCopy.java b/java.source/src/org/netbeans/api/java/source/WorkingCopy.java --- a/java.source/src/org/netbeans/api/java/source/WorkingCopy.java +++ b/java.source/src/org/netbeans/api/java/source/WorkingCopy.java @@ -108,6 +108,7 @@ import org.openide.loaders.DataFolder; import org.openide.loaders.DataObject; import org.openide.util.NbBundle; +import org.openide.util.Utilities; /**XXX: extends CompilationController now, finish method delegation * @@ -696,7 +697,7 @@ return scratchFolder.createData("out", "java"); } - File pack = new File(sourceFile.toUri()).getParentFile(); + File pack = Utilities.toFile(sourceFile.toUri()).getParentFile(); while (FileUtil.toFileObject(pack) == null) { pack = pack.getParentFile(); diff --git a/java.source/src/org/netbeans/modules/java/JavaNode.java b/java.source/src/org/netbeans/modules/java/JavaNode.java --- a/java.source/src/org/netbeans/modules/java/JavaNode.java +++ b/java.source/src/org/netbeans/modules/java/JavaNode.java @@ -80,6 +80,7 @@ import static org.openide.util.ImageUtilities.assignToolTipToImage; import static org.openide.util.ImageUtilities.loadImage; import static org.openide.util.NbBundle.getMessage; +import org.openide.util.Utilities; /** * The node representation of Java source files. @@ -262,12 +263,12 @@ URL u = entry.getURL(); String item = u.toExternalForm(); // fallback if (u.getProtocol().equals("file")) { // NOI18N - item = new File(URI.create(item)).getAbsolutePath(); + item = Utilities.toFile(URI.create(item)).getAbsolutePath(); } else if (u.getProtocol().equals("jar") && item.endsWith("!/")) { // NOI18N URL embedded = FileUtil.getArchiveFile(u); assert embedded != null : u; if (embedded.getProtocol().equals("file")) { // NOI18N - item = new File(URI.create(embedded.toExternalForm())).getAbsolutePath(); + item = Utilities.toFile(URI.create(embedded.toExternalForm())).getAbsolutePath(); } } if (sb.length() > 0) { diff --git a/java.source/src/org/netbeans/modules/java/source/classpath/AptCacheForSourceQuery.java b/java.source/src/org/netbeans/modules/java/source/classpath/AptCacheForSourceQuery.java --- a/java.source/src/org/netbeans/modules/java/source/classpath/AptCacheForSourceQuery.java +++ b/java.source/src/org/netbeans/modules/java/source/classpath/AptCacheForSourceQuery.java @@ -52,6 +52,7 @@ import org.netbeans.modules.java.source.indexing.JavaIndex; import org.openide.util.Exceptions; import org.openide.util.Parameters; +import org.openide.util.Utilities; /** * @@ -92,7 +93,7 @@ return sourceRoot; } final File aptFolder = JavaIndex.getAptFolder(sourceRoot, true); - final URL result = aptFolder.toURI().toURL(); + final URL result = Utilities.toURI(aptFolder).toURL(); emittedAptFolders.put(result,sourceRoot); return result; } catch (MalformedURLException e) { @@ -113,7 +114,7 @@ if (sourceRoot != null) { try { final File result = JavaIndex.getClassFolder(sourceRoot); - return result.toURI().toURL(); + return Utilities.toURI(result).toURL(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } diff --git a/java.source/src/org/netbeans/modules/java/source/indexing/COSSynchronizingIndexer.java b/java.source/src/org/netbeans/modules/java/source/indexing/COSSynchronizingIndexer.java --- a/java.source/src/org/netbeans/modules/java/source/indexing/COSSynchronizingIndexer.java +++ b/java.source/src/org/netbeans/modules/java/source/indexing/COSSynchronizingIndexer.java @@ -63,6 +63,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * @@ -107,7 +108,7 @@ context.getRoot() }); } else if (FileUtil.isParentOf(context.getRoot(), resource)) { - updated.add(new File(url.toURI())); + updated.add(Utilities.toFile(url.toURI())); } } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); @@ -115,7 +116,7 @@ } try { - File sourceRootFile = new File(context.getRootURI().toURI()); + File sourceRootFile = Utilities.toFile(context.getRootURI().toURI()); if (!context.checkForEditorModifications()) { // #187514, see also #152222 and JavaCustomIndexer BuildArtifactMapperImpl.classCacheUpdated(context.getRootURI(), sourceRootFile, Collections.emptyList(), updated, true); @@ -157,14 +158,14 @@ for (Indexable d : deleted) { try { - deletedFiles.add(new File(d.getURL().toURI())); + deletedFiles.add(Utilities.toFile(d.getURL().toURI())); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } } try { - File sourceRootFile = new File(context.getRootURI().toURI()); + File sourceRootFile = Utilities.toFile(context.getRootURI().toURI()); BuildArtifactMapperImpl.classCacheUpdated(context.getRootURI(), sourceRootFile, deletedFiles, Collections.emptyList(), true); } catch (URISyntaxException ex) { diff --git a/java.source/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java b/java.source/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java --- a/java.source/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java +++ b/java.source/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java @@ -347,7 +347,7 @@ return Collections.emptySet(); } try { - final File root = new File (URI.create(rootURL.toString())); + final File root = Utilities.toFile(URI.create(rootURL.toString())); return VirtualSourceProviderQuery.translate(virtualSources, root); } catch (IllegalArgumentException e) { //Called on non local fs => not supported, log and ignore. @@ -426,7 +426,7 @@ for (String fileName : readRSFile(file)) { File f = new File (aptFolder, fileName); if (f.exists() && FileObjects.JAVA.equals(FileObjects.getExtension(f.getName()))) { - sourceRelativeURLPairs.add(Pair.of(fileName,f.toURI().toURL())); + sourceRelativeURLPairs.add(Pair.of(fileName,Utilities.toURI(f).toURL())); } fmTx.delete(f); } diff --git a/java.source/src/org/netbeans/modules/java/source/indexing/JavaIndex.java b/java.source/src/org/netbeans/modules/java/source/indexing/JavaIndex.java --- a/java.source/src/org/netbeans/modules/java/source/indexing/JavaIndex.java +++ b/java.source/src/org/netbeans/modules/java/source/indexing/JavaIndex.java @@ -65,6 +65,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Utilities; /** * @@ -107,7 +108,7 @@ } public static File getClassFolder(File root) throws IOException { - return getClassFolder(root.toURI().toURL()); //XXX + return getClassFolder(Utilities.toURI(root).toURL()); //XXX } public static File getClassFolder(URL url) throws IOException { diff --git a/java.source/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java b/java.source/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java --- a/java.source/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java +++ b/java.source/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java @@ -56,6 +56,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Utilities; /** Global cache for Archives (zip files and folders). @@ -153,7 +154,7 @@ private static Archive create( URL root, boolean cacheFile ) { String protocol = root.getProtocol(); if ("file".equals(protocol)) { - File f = new File (URI.create(root.toExternalForm())); + File f = Utilities.toFile(URI.create(root.toExternalForm())); if (f.isDirectory()) { return new FolderArchive (f); } @@ -165,7 +166,7 @@ URL inner = FileUtil.getArchiveFile(root); protocol = inner.getProtocol(); if ("file".equals(protocol)) { - File f = new File (URI.create(inner.toExternalForm())); + File f = Utilities.toFile(URI.create(inner.toExternalForm())); if (f.isFile()) { return new CachingArchive( f, cacheFile ); } diff --git a/java.source/src/org/netbeans/modules/java/source/parsing/FileObjects.java b/java.source/src/org/netbeans/modules/java/source/parsing/FileObjects.java --- a/java.source/src/org/netbeans/modules/java/source/parsing/FileObjects.java +++ b/java.source/src/org/netbeans/modules/java/source/parsing/FileObjects.java @@ -703,7 +703,7 @@ * @return the relative path */ public static @NonNull String getRelativePath (@NonNull final URL root, @NonNull final URL fo) throws URISyntaxException { - final String path = getRelativePath(new File(root.toURI()), new File(fo.toURI())); + final String path = getRelativePath(Utilities.toFile(root.toURI()), Utilities.toFile(fo.toURI())); return path.replace(File.separatorChar, '/'); //NOI18N } @@ -953,7 +953,7 @@ @Override public URI toUri () { if (this.uriCache == null) { - this.uriCache = f.toURI(); + this.uriCache = Utilities.toURI(f); } return this.uriCache; } @@ -1283,7 +1283,7 @@ @Override public URI getArchiveURI () { - return this.archiveFile.toURI(); + return Utilities.toURI(this.archiveFile); } @Override @@ -1361,7 +1361,7 @@ @Override public URI getArchiveURI () { - return new File (this.zipFile.getName()).toURI(); + return Utilities.toURI(new File (this.zipFile.getName())); } @Override diff --git a/java.source/src/org/netbeans/modules/java/source/parsing/FolderArchive.java b/java.source/src/org/netbeans/modules/java/source/parsing/FolderArchive.java --- a/java.source/src/org/netbeans/modules/java/source/parsing/FolderArchive.java +++ b/java.source/src/org/netbeans/modules/java/source/parsing/FolderArchive.java @@ -65,6 +65,7 @@ import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * @@ -120,7 +121,7 @@ for (File f : content) { if ((kinds == null || kinds.contains(FileObjects.getKind(FileObjects.getExtension(f.getName())))) && f.isFile() && - (entry == null || entry.includes(f.toURI().toURL()))) { + (entry == null || entry.includes(Utilities.toURI(f).toURL()))) { result.add(FileObjects.fileFileObject(f,this.root,filter, encoding)); } } @@ -152,10 +153,10 @@ return FileObjects.fileFileObject(file,this.root,null,encoding); } try { - final URL srcRoot = getBaseSourceRoot(this.root.toURI().toURL()); + final URL srcRoot = getBaseSourceRoot(Utilities.toURI(this.root).toURL()); if (srcRoot != null && JavaIndex.hasSourceCache(srcRoot, false)) { if ("file".equals(srcRoot.getProtocol())) { //NOI18N - final File folder = new File(srcRoot.toURI()); + final File folder = Utilities.toFile(srcRoot.toURI()); file = new File (folder,path); if (file.exists()) { return FileObjects.fileFileObject(file,folder,null,encoding); diff --git a/java.source/src/org/netbeans/modules/java/source/parsing/OutputFileManager.java b/java.source/src/org/netbeans/modules/java/source/parsing/OutputFileManager.java --- a/java.source/src/org/netbeans/modules/java/source/parsing/OutputFileManager.java +++ b/java.source/src/org/netbeans/modules/java/source/parsing/OutputFileManager.java @@ -67,6 +67,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * @@ -261,7 +262,7 @@ final URL classFolder = AptCacheForSourceQuery.getClassFolder(entry.getURL()); if (classFolder != null) { try { - return new File(classFolder.toURI()); + return Utilities.toFile(classFolder.toURI()); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } @@ -282,7 +283,7 @@ final URL classFolder = AptCacheForSourceQuery.getClassFolder(entry.getURL()); if (classFolder != null) { try { - return new File(classFolder.toURI()); + return Utilities.toFile(classFolder.toURI()); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } diff --git a/java.source/src/org/netbeans/modules/java/source/parsing/ProcessorGenerated.java b/java.source/src/org/netbeans/modules/java/source/parsing/ProcessorGenerated.java --- a/java.source/src/org/netbeans/modules/java/source/parsing/ProcessorGenerated.java +++ b/java.source/src/org/netbeans/modules/java/source/parsing/ProcessorGenerated.java @@ -66,6 +66,7 @@ import org.netbeans.modules.java.source.usages.Pair; import org.openide.util.Exceptions; import org.openide.util.Parameters; +import org.openide.util.Utilities; /** * @@ -212,12 +213,12 @@ } apt = true; } - final File sourceRoot = new File (sourceRootURL.toURI()); + final File sourceRoot = Utilities.toFile(sourceRootURL.toURI()); final File classCache = apt ? - new File (AptCacheForSourceQuery.getClassFolder(sourceRootURL).toURI()): + Utilities.toFile(AptCacheForSourceQuery.getClassFolder(sourceRootURL).toURI()): JavaIndex.getClassFolder(sourceRoot); if (!genSources.isEmpty()) { - final File sourceFile = new File(forSource.toURI()); + final File sourceFile = Utilities.toFile(forSource.toURI()); final String relativePath = FileObjects.stripExtension(FileObjects.getRelativePath(sourceRoot, sourceFile)); final File cacheFile = new File (classCache, relativePath+'.'+FileObjects.RAPT); if (!cacheFile.getParentFile().exists()) { @@ -237,7 +238,7 @@ final StringBuilder sb = readResources(resFile, currentResources); boolean changed = false; for (javax.tools.FileObject file : genResources) { - String resPath = FileObjects.getRelativePath(classCache.toURI().toURL(), file.toUri().toURL()); + String resPath = FileObjects.getRelativePath(Utilities.toURI(classCache).toURL(), file.toUri().toURL()); if (currentResources.add(resPath)) { sb.append(resPath); sb.append('\n'); //NOI18N diff --git a/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileManager.java b/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileManager.java --- a/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileManager.java +++ b/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileManager.java @@ -62,6 +62,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Utilities; /** * @@ -158,7 +159,7 @@ if (rootFile == null) { return null; } - return FileObjects.nbFileObject(new File(rootFile,FileObjects.convertFolder2Package(rp, File.separatorChar)).toURI().toURL(), roots[0]); //Todo: wrap to protect from write + return FileObjects.nbFileObject(Utilities.toURI(new File(rootFile,FileObjects.convertFolder2Package(rp, File.separatorChar))).toURL(), roots[0]); //Todo: wrap to protect from write } else { return SourceFileObject.create (fileRootPair[0], fileRootPair[1]); //Todo: wrap to protect from write diff --git a/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileObject.java b/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileObject.java --- a/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileObject.java +++ b/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileObject.java @@ -80,6 +80,7 @@ import org.openide.filesystems.JarFileSystem; import org.openide.loaders.DataObject; import org.openide.text.NbDocument; +import org.openide.util.Utilities; /** * @@ -341,7 +342,7 @@ public @Override String toString () { final URI uri = toUri(); try { - final File file = new File (uri); + final File file = Utilities.toFile(uri); return file.getAbsolutePath(); } catch (IllegalArgumentException iae) { return uri.toString(); diff --git a/java.source/src/org/netbeans/modules/java/source/usages/BinaryAnalyser.java b/java.source/src/org/netbeans/modules/java/source/usages/BinaryAnalyser.java --- a/java.source/src/org/netbeans/modules/java/source/usages/BinaryAnalyser.java +++ b/java.source/src/org/netbeans/modules/java/source/usages/BinaryAnalyser.java @@ -115,6 +115,7 @@ import org.openide.filesystems.URLMapper; import org.openide.util.Exceptions; import org.openide.util.Parameters; +import org.openide.util.Utilities; @@ -250,7 +251,7 @@ final URL innerURL = FileUtil.getArchiveFile(root); if ("file".equals(innerURL.getProtocol())) { //NOI18N //Fast way - final File archive = new File (URI.create(innerURL.toExternalForm())); + final File archive = Utilities.toFile(URI.create(innerURL.toExternalForm())); if (archive.canRead()) { if (!isUpToDate(ROOT,archive.lastModified())) { writer.clear(); @@ -281,7 +282,7 @@ } } else if ("file".equals(mainP)) { //NOI18N //Fast way - final File rootFile = new File (URI.create(root.toExternalForm())); + final File rootFile = Utilities.toFile(URI.create(root.toExternalForm())); if (rootFile.isDirectory()) { String path = rootFile.getAbsolutePath (); if (path.charAt(path.length()-1) != File.separatorChar) { @@ -880,7 +881,7 @@ } catch (InvalidClassFormatException icf) { LOGGER.log(Level.WARNING, "Invalid class file format: {0}!/{1}", new Object[]{ - new File(zipFile.getName()).toURI(), + Utilities.toURI(new File(zipFile.getName())), ze.getName()}); //NOI18N } catch (IOException x) { Exceptions.attachMessage(x, "While scanning: " + ze.getName()); //NOI18N diff --git a/java.source/src/org/netbeans/modules/java/source/usages/BuildArtifactMapperImpl.java b/java.source/src/org/netbeans/modules/java/source/usages/BuildArtifactMapperImpl.java --- a/java.source/src/org/netbeans/modules/java/source/usages/BuildArtifactMapperImpl.java +++ b/java.source/src/org/netbeans/modules/java/source/usages/BuildArtifactMapperImpl.java @@ -97,6 +97,7 @@ import org.openide.util.NbBundle; import org.openide.util.NbPreferences; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; import org.openide.util.WeakSet; /** @@ -211,7 +212,7 @@ File f = FileUtil.archiveOrDirForURL(u); try { - if (FileUtil.isArchiveFile(f.toURI().toURL())) { + if (FileUtil.isArchiveFile(Utilities.toURI(f).toURL())) { continue; } @@ -663,7 +664,7 @@ } b.append("../"); // NOI18N } - URI u = base.toURI().relativize(file.toURI()); + URI u = Utilities.toURI(base).relativize(Utilities.toURI(file)); assert !u.isAbsolute() : u + " from " + basedir + " and " + file + " with common root " + base; b.append(u.getPath()); if (b.charAt(b.length() - 1) == '/') { diff --git a/java.source/src/org/netbeans/modules/java/source/usages/VirtualSourceProviderQuery.java b/java.source/src/org/netbeans/modules/java/source/usages/VirtualSourceProviderQuery.java --- a/java.source/src/org/netbeans/modules/java/source/usages/VirtualSourceProviderQuery.java +++ b/java.source/src/org/netbeans/modules/java/source/usages/VirtualSourceProviderQuery.java @@ -63,6 +63,7 @@ import org.openide.util.LookupEvent; import org.openide.util.LookupListener; import org.openide.util.Parameters; +import org.openide.util.Utilities; import org.openide.util.WeakListeners; /** @@ -133,7 +134,7 @@ l = p.second; } try { - final File file = new File(indexable.getURL().toURI()); + final File file = Utilities.toFile(indexable.getURL().toURI()); l.add(file); file2indexables.put(file, indexable); } catch (URISyntaxException use) { @@ -190,7 +191,7 @@ assert root != null; assert file2indexables != null; this.root = root; - String _rootURL = root.toURI().toURL().toString(); + String _rootURL = Utilities.toURI(root).toURL().toString(); if (!_rootURL.endsWith("/")) { //NOI18N _rootURL = _rootURL + '/'; //NOI18N } diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/ElementHandleTest.java b/java.source/test/unit/src/org/netbeans/api/java/source/ElementHandleTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/ElementHandleTest.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/ElementHandleTest.java @@ -75,6 +75,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Lookup; +import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; import org.openide.util.lookup.ProxyLookup; @@ -719,7 +720,7 @@ if (!f.exists()) { continue; } - URL url = f.toURI().toURL(); + URL url = Utilities.toURI(f).toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/JavaSourceTaskFactoryTest.java b/java.source/test/unit/src/org/netbeans/api/java/source/JavaSourceTaskFactoryTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/JavaSourceTaskFactoryTest.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/JavaSourceTaskFactoryTest.java @@ -77,6 +77,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Lookup; +import org.openide.util.Utilities; import org.openide.util.lookup.ProxyLookup; /** @@ -372,7 +373,7 @@ if (!f.exists()) { continue; } - URL url = f.toURI().toURL(); + URL url = Utilities.toURI(f).toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/JavaSourceTest.java b/java.source/test/unit/src/org/netbeans/api/java/source/JavaSourceTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/JavaSourceTest.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/JavaSourceTest.java @@ -2347,7 +2347,7 @@ if (!f.exists()) { continue; } - URL url = f.toURI().toURL(); + URL url = org.openide.util.Utilities.toURI(f).toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } @@ -2366,7 +2366,7 @@ if (!root.exists()) { root.mkdirs(); } - return ClassPathSupport.createClassPath(new URL[] {root.toURI().toURL()}); + return ClassPathSupport.createClassPath(new URL[] {org.openide.util.Utilities.toURI(root).toURL()}); } private FileObject createTestFile (FileObject srcRoot, String relativeName, String content) throws IOException { diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/ScanUtilsTest.java b/java.source/test/unit/src/org/netbeans/api/java/source/ScanUtilsTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/ScanUtilsTest.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/ScanUtilsTest.java @@ -123,7 +123,7 @@ if (!f.exists()) { continue; } - URL url = f.toURI().toURL(); + URL url = org.openide.util.Utilities.toURI(f).toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } @@ -142,7 +142,7 @@ if (!root.exists()) { root.mkdirs(); } - return ClassPathSupport.createClassPath(new URL[] {root.toURI().toURL()}); + return ClassPathSupport.createClassPath(new URL[] {org.openide.util.Utilities.toURI(root).toURL()}); } static class ScannerBlock implements Runnable { diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/TestUtilities.java b/java.source/test/unit/src/org/netbeans/api/java/source/TestUtilities.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/TestUtilities.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/TestUtilities.java @@ -73,6 +73,7 @@ import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * Utilities to aid unit testing java.source module. @@ -161,7 +162,7 @@ if (!f.exists()) { continue; } - URL url = f.toURI().toURL(); + URL url = Utilities.toURI(f).toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/TestUtilitiesTest.java b/java.source/test/unit/src/org/netbeans/api/java/source/TestUtilitiesTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/TestUtilitiesTest.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/TestUtilitiesTest.java @@ -55,6 +55,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Utilities; /** * @@ -78,7 +79,7 @@ sourceDir.mkdirs(); boot = TestUtilities.createBootClassPath (); compile = ClassPathSupport.createClassPath(new URL[0]); - source = ClassPathSupport.createClassPath(new URL[]{sourceDir.toURI().toURL()}); + source = ClassPathSupport.createClassPath(new URL[]{Utilities.toURI(sourceDir).toURL()}); TestUtilities.setCacheFolder(cache); IndexingManager.getDefault().refreshIndexAndWait(sourceDir.toURL(), null); assertTrue(TestUtilities.waitScanFinished(10, TimeUnit.SECONDS)); diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/UiUtilsTest.java b/java.source/test/unit/src/org/netbeans/api/java/source/UiUtilsTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/UiUtilsTest.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/UiUtilsTest.java @@ -65,6 +65,7 @@ import java.util.Collections; import java.util.List; import java.util.StringTokenizer; +import org.openide.util.Utilities; /** * @author Tomas Zezula @@ -159,7 +160,7 @@ while (tk.hasMoreTokens()) { String token = tk.nextToken(); File f = new File(token); - URL url = f.toURI().toURL(); + URL url = Utilities.toURI(f).toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } else if (!f.exists()) { diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/gen/GeneratorTestBase.java b/java.source/test/unit/src/org/netbeans/api/java/source/gen/GeneratorTestBase.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/GeneratorTestBase.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/gen/GeneratorTestBase.java @@ -74,6 +74,7 @@ import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileUtil; import org.openide.util.SharedClassObject; +import org.openide.util.Utilities; /** * @@ -174,9 +175,9 @@ URL url = null; try { if (isArchiveFile(f)) { - url = FileUtil.getArchiveRoot(f.toURI().toURL()); + url = FileUtil.getArchiveRoot(Utilities.toURI(f).toURL()); } else { - url = f.toURI().toURL(); + url = Utilities.toURI(f).toURL(); String surl = url.toExternalForm(); if (!surl.endsWith("/")) { url = new URL(surl+"/"); diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/gen/GeneratorTestMDRCompat.java b/java.source/test/unit/src/org/netbeans/api/java/source/gen/GeneratorTestMDRCompat.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/GeneratorTestMDRCompat.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/gen/GeneratorTestMDRCompat.java @@ -70,6 +70,7 @@ import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.openide.util.SharedClassObject; +import org.openide.util.Utilities; /** * @@ -138,9 +139,9 @@ URL url = null; try { if (isArchiveFile(f)) { - url = FileUtil.getArchiveRoot(f.toURI().toURL()); + url = FileUtil.getArchiveRoot(Utilities.toURI(f).toURL()); } else { - url = f.toURI().toURL(); + url = Utilities.toURI(f).toURL(); String surl = url.toExternalForm(); if (!surl.endsWith("/")) { url = new URL(surl+"/"); diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/gen/ImportAnalysis2Test.java b/java.source/test/unit/src/org/netbeans/api/java/source/gen/ImportAnalysis2Test.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/ImportAnalysis2Test.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/gen/ImportAnalysis2Test.java @@ -81,6 +81,7 @@ import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * Tests imports matching and its correct adding/removing. Just generator @@ -712,7 +713,7 @@ "\n" + "public abstract class Test implements Entry, Map {\n" + "}\n"; - final TransactionContext ctx = TransactionContext.beginStandardTransaction(true, getWorkDir().toURI().toURL()); + final TransactionContext ctx = TransactionContext.beginStandardTransaction(true, Utilities.toURI(getWorkDir()).toURL()); try { ClasspathInfo cpInfo = ClasspathInfoAccessor.getINSTANCE().create (ClassPathSupport.createClassPath(System.getProperty("sun.boot.class.path")), ClassPath.EMPTY, ClassPathSupport.createClassPath(getSourcePath()), null, true, false, false, true); JavaSource src = JavaSource.create(cpInfo, FileUtil.toFileObject(testFile)); @@ -755,7 +756,7 @@ "public abstract class Entry implements Map.Entry, Map {\n" + "}\n"; - final TransactionContext ctx = TransactionContext.beginStandardTransaction(true, getWorkDir().toURI().toURL()); + final TransactionContext ctx = TransactionContext.beginStandardTransaction(true, Utilities.toURI(getWorkDir()).toURL()); try { ClasspathInfo cpInfo = ClasspathInfoAccessor.getINSTANCE().create (ClassPathSupport.createClassPath(System.getProperty("sun.boot.class.path")), ClassPath.EMPTY, ClassPathSupport.createClassPath(getSourcePath()), null, true, false, false, true); JavaSource src = JavaSource.create(cpInfo, FileUtil.toFileObject(testFile)); diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/performance/Utilities.java b/java.source/test/unit/src/org/netbeans/api/java/source/performance/Utilities.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/performance/Utilities.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/performance/Utilities.java @@ -152,7 +152,7 @@ if (!root.exists()) { root.mkdirs(); } - return ClassPathSupport.createClassPath(new URL[]{root.toURI().toURL()}); + return ClassPathSupport.createClassPath(new URL[]{org.openide.util.Utilities.toURI(root).toURL()}); } public static String projectOpen(String path, String tmpFile) { diff --git a/java.source/test/unit/src/org/netbeans/modules/java/FileToURLTest.java b/java.source/test/unit/src/org/netbeans/modules/java/FileToURLTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/FileToURLTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/FileToURLTest.java @@ -35,6 +35,7 @@ import java.io.File; import java.net.URI; import java.net.MalformedURLException; +import org.openide.util.Utilities; /** * @author Rastislav Komara (RKo) @@ -62,7 +63,7 @@ } URI uri2; try { - uri2 = URI.create(file.toURI().toURL().toExternalForm()); + uri2 = URI.create(Utilities.toURI(file).toURL().toExternalForm()); } catch (Exception e) { // fail(e.getMessage()); e.printStackTrace(getLog()); @@ -70,7 +71,7 @@ } URI uri3; try { - uri3 = file.toURI(); + uri3 = Utilities.toURI(file); } catch (Exception e) { // fail(e.getMessage()); e.printStackTrace(getLog()); diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/classpath/SourcePathTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/classpath/SourcePathTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/classpath/SourcePathTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/classpath/SourcePathTest.java @@ -57,6 +57,7 @@ import org.netbeans.spi.java.classpath.ClassPathImplementation; import org.netbeans.spi.java.classpath.PathResourceImplementation; import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.openide.util.Utilities; /** * @@ -82,8 +83,8 @@ final ClassPathImplementation baseImpl = ClassPathSupport.createClassPathImplementation( Arrays.asList(new PathResourceImplementation[] { - ClassPathSupport.createResource(r1.toURI().toURL()), - ClassPathSupport.createResource(r2.toURI().toURL()) + ClassPathSupport.createResource(Utilities.toURI(r1).toURL()), + ClassPathSupport.createResource(Utilities.toURI(r2).toURL()) })); final ClassPath base = ClassPathFactory.createClassPath(baseImpl); diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/CachingFileManagerTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/CachingFileManagerTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/CachingFileManagerTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/CachingFileManagerTest.java @@ -61,6 +61,7 @@ import org.netbeans.modules.java.source.usages.Pair; import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -102,7 +103,7 @@ } finally { out.close(); } - final URL archiveRoot = FileUtil.getArchiveRoot(archiveFile.toURI().toURL()); + final URL archiveRoot = FileUtil.getArchiveRoot(Utilities.toURI(archiveFile).toURL()); final URI expectedURI = new URL (archiveRoot.toExternalForm()+"org/me/resources/test.txt").toURI(); doTestGetFileForInput(ClassPathSupport.createClassPath(archiveRoot), Arrays.asList( diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/ClasspathInfoTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/ClasspathInfoTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/ClasspathInfoTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/ClasspathInfoTest.java @@ -78,6 +78,7 @@ import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -108,7 +109,7 @@ IndexUtil.setCacheFolder(cacheFolder); TestUtil.copyFiles( TestUtil.getJdkDir(), workDir, TestUtil.RT_JAR ); rtJar = FileUtil.normalizeFile(new File( workDir, TestUtil.RT_JAR )); - URL url = FileUtil.getArchiveRoot (rtJar.toURI().toURL()); + URL url = FileUtil.getArchiveRoot (Utilities.toURI(rtJar).toURL()); this.bootPath = ClassPathSupport.createClassPath (new URL[] {url}); this.classPath = ClassPathSupport.createClassPath(new URL[0]); } diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/FileManagerTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/FileManagerTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/FileManagerTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/FileManagerTest.java @@ -56,6 +56,7 @@ import javax.tools.StandardLocation; import org.netbeans.junit.NbTestCase; import org.netbeans.modules.java.source.TestUtil; +import org.openide.util.Utilities; /** Base class for testing file managers. This class basically tests itself. * @@ -97,10 +98,10 @@ // Create archive provider archiveProvider = CachingArchiveProvider.getDefault(); - rtJarArchive = archiveProvider.getArchive(rtFile.toURI().toURL(), true); - rtFolderArchive = archiveProvider.getArchive(rtFolder.toURI().toURL(), true); - srcZipArchive = archiveProvider.getArchive(srcFile.toURI().toURL(), true); - srcFolderArchive = archiveProvider.getArchive(srcFolder.toURI().toURL(), true); + rtJarArchive = archiveProvider.getArchive(Utilities.toURI(rtFile).toURL(), true); + rtFolderArchive = archiveProvider.getArchive(Utilities.toURI(rtFolder).toURL(), true); + srcZipArchive = archiveProvider.getArchive(Utilities.toURI(srcFile).toURL(), true); + srcFolderArchive = archiveProvider.getArchive(Utilities.toURI(srcFolder).toURL(), true); } protected JavaFileManagerDescripton[] getDescriptions() throws IOException { diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/FileObjectsTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/FileObjectsTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/FileObjectsTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/FileObjectsTest.java @@ -60,6 +60,7 @@ import org.netbeans.modules.java.preprocessorbridge.spi.JavaFileFilterImplementation; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -148,7 +149,7 @@ assertFalse("OutputStream should exist for existing file",true); } File nonExistring = new File (new File(new File (workDir,"test"),"foo"),"nonexisting.java"); - final javax.tools.FileObject nonExistingFo = FileObjects.nbFileObject(nonExistring.toURI().toURL(), wd); + final javax.tools.FileObject nonExistingFo = FileObjects.nbFileObject(Utilities.toURI(nonExistring).toURL(), wd); assertEquals ("test.foo.nonexisting",((InferableJavaFileObject)nonExistingFo).inferBinaryName()); try { final InputStream in = nonExistingFo.openInputStream(); diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/PerfJavacIntefaceGCTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/PerfJavacIntefaceGCTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/PerfJavacIntefaceGCTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/PerfJavacIntefaceGCTest.java @@ -50,6 +50,7 @@ import org.netbeans.modules.java.source.TestUtil; import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** Tests whether the JavacInterface gets GCed after some operations * * @author Petr Hrebejk @@ -80,7 +81,7 @@ workDir = getWorkDir(); TestUtil.copyFiles( workDir, TestUtil.RT_JAR, "jdk/JTable.java" ); rtJar = new File( workDir, TestUtil.RT_JAR ); - URL url = FileUtil.getArchiveRoot (rtJar.toURI().toURL()); + URL url = FileUtil.getArchiveRoot (Utilities.toURI(rtJar).toURL()); this.bootPath = ClassPathSupport.createClassPath (new URL[] {url}); this.classPath = ClassPathSupport.createClassPath(new URL[0]); } diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/PerfResolveTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/PerfResolveTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/PerfResolveTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/parsing/PerfResolveTest.java @@ -50,6 +50,7 @@ import org.netbeans.modules.java.source.TestUtil; import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** Tests for basic JDK operations * * @author Petr Hrebejk @@ -79,7 +80,7 @@ workDir = getWorkDir(); TestUtil.copyFiles( workDir, TestUtil.RT_JAR, "jdk/JTable.java" ); rtJar = new File( workDir, TestUtil.RT_JAR ); - URL url = FileUtil.getArchiveRoot (rtJar.toURI().toURL()); + URL url = FileUtil.getArchiveRoot (Utilities.toURI(rtJar).toURL()); this.bootPath = ClassPathSupport.createClassPath (new URL[] {url}); this.classPath = ClassPathSupport.createClassPath(new URL[0]); } diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java @@ -76,6 +76,7 @@ import org.openide.filesystems.FileUtil; import org.openide.loaders.DataObject; import org.openide.util.SharedClassObject; +import org.openide.util.Utilities; /** * Test different formating options @@ -4264,9 +4265,9 @@ URL url = null; try { if (isArchiveFile(f)) { - url = FileUtil.getArchiveRoot(f.toURI().toURL()); + url = FileUtil.getArchiveRoot(Utilities.toURI(f).toURL()); } else { - url = f.toURI().toURL(); + url = Utilities.toURI(f).toURL(); String surl = url.toExternalForm(); if (!surl.endsWith("/")) { url = new URL(surl + "/"); diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/usages/BinaryAnalyserTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/usages/BinaryAnalyserTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/usages/BinaryAnalyserTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/usages/BinaryAnalyserTest.java @@ -68,6 +68,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * @@ -92,7 +93,7 @@ final Index index = IndexManager.createIndex(FileUtil.toFile(indexDir), DocumentUtil.createAnalyzer()); BinaryAnalyser a = new BinaryAnalyser(new IndexWriter(index), getWorkDir()); - assertEquals(Result.FINISHED, a.start(FileUtil.getArchiveRoot(binaryAnalyzerDataDir.toURI().toURL()), new AtomicBoolean(), new AtomicBoolean())); + assertEquals(Result.FINISHED, a.start(FileUtil.getArchiveRoot(Utilities.toURI(binaryAnalyzerDataDir).toURL()), new AtomicBoolean(), new AtomicBoolean())); a.finish(); @@ -132,7 +133,7 @@ setLowMemory(true); assertEquals(Result.FINISHED, - a.start(FileUtil.getArchiveRoot(binaryAnalyzerDataDir.toURI().toURL()), new AtomicBoolean(), new AtomicBoolean())); + a.start(FileUtil.getArchiveRoot(Utilities.toURI(binaryAnalyzerDataDir).toURL()), new AtomicBoolean(), new AtomicBoolean())); a.finish(); diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/usages/ClassIndexManagerTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/usages/ClassIndexManagerTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/usages/ClassIndexManagerTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/usages/ClassIndexManagerTest.java @@ -50,6 +50,7 @@ import org.netbeans.junit.NbTestCase; import org.openide.filesystems.*; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * @@ -82,7 +83,7 @@ holdsLock.countDown(); try { inListener.await(); - ClassIndexManager.getDefault().getUsagesQuery(root.toURI().toURL(), true); + ClassIndexManager.getDefault().getUsagesQuery(Utilities.toURI(root).toURL(), true); } catch (InterruptedException ie) { Exceptions.printStackTrace(ie); } catch (MalformedURLException ex) { @@ -94,7 +95,7 @@ }; worker.start(); holdsLock.await(); - ClassIndexManager.getDefault().getUsagesQuery(root.toURI().toURL(), true); + ClassIndexManager.getDefault().getUsagesQuery(Utilities.toURI(root).toURL(), true); } finally { FileUtil.removeRecursiveListener(dl, cache); } diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/usages/VirtualSourceProviderQueryTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/usages/VirtualSourceProviderQueryTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/usages/VirtualSourceProviderQueryTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/usages/VirtualSourceProviderQueryTest.java @@ -59,6 +59,7 @@ import org.netbeans.modules.parsing.spi.indexing.Indexable; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -79,7 +80,7 @@ public void testVirtualSourceProvider () throws Exception { final File root = new File (getWorkDir(),"src"); //NOI18N root.mkdir(); - final Indexable[] data = prepareData(root.toURI().toURL()); + final Indexable[] data = prepareData(Utilities.toURI(root).toURL()); final Iterable res = VirtualSourceProviderQuery.translate(Arrays.asList(data), root); assertEquals(new String[] {"a","b","c","d"}, res); //NOI18N } diff --git a/masterfs/nbproject/project.xml b/masterfs/nbproject/project.xml --- a/masterfs/nbproject/project.xml +++ b/masterfs/nbproject/project.xml @@ -79,7 +79,7 @@ - 8.3 + 8.25 diff --git a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedURLMapper.java b/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedURLMapper.java --- a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedURLMapper.java +++ b/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedURLMapper.java @@ -47,7 +47,6 @@ import java.net.URISyntaxException; import org.netbeans.modules.masterfs.filebasedfs.fileobjects.BaseFileObj; import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; import java.io.File; @@ -58,38 +57,7 @@ import java.util.logging.Logger; import org.netbeans.modules.masterfs.filebasedfs.fileobjects.FileObjectFactory; import org.netbeans.modules.masterfs.filebasedfs.fileobjects.RootObj; -import org.openide.util.Exceptions; - -//TODO: JDK problems with URL, URI, File conversion for UNC -/* -There must be consistently called conversion from FileUtil and URLMapper. -new File (URI.create (fo.getURL ().toExternalForm ())) is typical scenario that leads to this -bug: java.lang.IllegalArgumentException: URI has an authority component - at java.io.File.(File.java:326) - - -Maybe there would be also possible to return a little special URL from FileBasedURLMapper that -would get special subclass of URLStreamHandler in constructor. This subclass of URLStreamHandler -would provided external form (method toExternalForm) that would be suitable for above mentioned -conversion from URL to File. - -Known problems : -1/ at java.io.File.(File.java:326) - at org.netbeans.modules.javacore.parser.ASTProvider.getClassPath(ASTProvider.java:477) - at org.netbeans.lib.gjast.ASParser$BridgeContext.getClassPath(ASParser.java:421) - -2/ - at java.io.File.(File.java:326) - at org.netbeans.modules.javacore.scanning.FileScanner.(FileScanner.java:85) -catch] at org.netbeans.modules.javacore.JMManager.scanFiles(JMManager.java:1112) - -3/ org.netbeans.modules.javacore.parser.ECRequestDescImpl.getFileName(FileObject fo,StringBuffer buf) - at java.io.File.(File.java:326) - - - - -*/ +import org.openide.util.Utilities; public final class FileBasedURLMapper extends URLMapper { private static final Logger LOG = Logger.getLogger(FileBasedURLMapper.class.getName()); @@ -126,7 +94,7 @@ FileObject retVal = null; File file; try { - file = FileUtil.normalizeFile(url2F(url)); + file = Utilities.toFile(url.toURI()); } catch (URISyntaxException e) { LOG.log(Level.INFO, "URL=" + url, e); // NOI18N return null; @@ -155,7 +123,9 @@ /** #171330 - Method taken from java.io.File.toURI. We know whether given * FileObject is a file or folder, so we can eliminate File.isDirectory - * disk touch which is needed in file.toURI(). */ + * disk touch which is needed in file.toURI(). + * @see Utilities#toURI + */ private static URI toURI(final File file, boolean isDirectory) { return toURI(file.getAbsolutePath(), isDirectory, File.separatorChar); } @@ -182,13 +152,4 @@ return p; } - static File url2F(final URL url) throws URISyntaxException { - File file; - if (url.getHost() == null || url.getHost().length() == 0) { - file = new File(url.toURI()); - } else { - file = new File("\\\\" + url.getHost() + url.getPath().replace('/', '\\')); // NOI18N - } - return file; - } } diff --git a/masterfs/test/unit/src/org/netbeans/modules/masterfs/GlobalSharabilityQueryImplTest.java b/masterfs/test/unit/src/org/netbeans/modules/masterfs/GlobalSharabilityQueryImplTest.java --- a/masterfs/test/unit/src/org/netbeans/modules/masterfs/GlobalSharabilityQueryImplTest.java +++ b/masterfs/test/unit/src/org/netbeans/modules/masterfs/GlobalSharabilityQueryImplTest.java @@ -49,6 +49,7 @@ import org.netbeans.api.queries.SharabilityQuery; import org.netbeans.spi.queries.SharabilityQueryImplementation2; import org.openide.util.Lookup; +import org.openide.util.Utilities; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; import org.openide.util.lookup.ProxyLookup; @@ -89,7 +90,7 @@ }; for (int i = 0; i < all.length; i++) { - boolean isNotSharable = sq.getSharability(all[i].toURI()) == SharabilityQuery.Sharability.NOT_SHARABLE; + boolean isNotSharable = sq.getSharability(Utilities.toURI(all[i])) == SharabilityQuery.Sharability.NOT_SHARABLE; boolean isNotVisible = !vq.isVisible(all[i].getName()); assertEquals(isNotSharable, isNotVisible); } diff --git a/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/BaseFileObjectTestHid.java b/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/BaseFileObjectTestHid.java --- a/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/BaseFileObjectTestHid.java +++ b/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/BaseFileObjectTestHid.java @@ -705,8 +705,8 @@ assertNotNull(A); assertNotNull(root.getFileObject("a")); assertSame(root.getFileObject("A"), root.getFileObject("a")); - assertSame(URLMapper.findFileObject(testa.toURI().toURL()), - URLMapper.findFileObject(testA.toURI().toURL())); + assertSame(URLMapper.findFileObject(Utilities.toURI(testa).toURL()), + URLMapper.findFileObject(Utilities.toURI(testA).toURL())); //but root.getChildren(); @@ -860,7 +860,7 @@ assertTrue(testFile2.exists()); - assertEquals(FileUtil.normalizeFile(testFile).toURI().toURL(), FileUtil.normalizeFile(testFile2).toURI().toURL()); + assertEquals(Utilities.toURI(FileUtil.normalizeFile(testFile)).toURL(), Utilities.toURI(FileUtil.normalizeFile(testFile2)).toURL()); } @RandomlyFails // NB-Core-Build #7927 (from FileBasedFileSystemWithUninitializedExtensionsTest): Didn't receive a FileEvent on the parent. diff --git a/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedURLMapperTest.java b/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedURLMapperTest.java --- a/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedURLMapperTest.java +++ b/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedURLMapperTest.java @@ -50,7 +50,6 @@ import org.openide.filesystems.URLMapper; import org.openide.filesystems.FileUtil; import java.net.URL; -import org.openide.util.Utilities; /** * @author Radek Matous @@ -93,16 +92,4 @@ assertEquals("/data/services/web/com_resource/", uri.getPath()); } - public void testReverseUNCPath() throws Exception { - if (!Utilities.isWindows()) { - return; - } - assertEquals("C:\\some\\random path", uri2File(new URI("file:/C:/some/random%20path/")).getAbsolutePath()); - assertEquals("C:\\some\\random path", uri2File(new URI("file:///C:/some/random%20path/")).getAbsolutePath()); - assertEquals("\\\\server\\share\\some\\random path", uri2File(new URI("file://server/share/some/random%20path/")).getAbsolutePath()); - } - - private File uri2File(URI urI) throws Exception { - return FileBasedURLMapper.url2F(urI.toURL()); - } } diff --git a/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjTest.java b/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjTest.java --- a/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjTest.java +++ b/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjTest.java @@ -510,8 +510,8 @@ assertNotNull(A); assertNotNull(testRoot.getFileObject("a")); assertSame(testRoot.getFileObject("A"), testRoot.getFileObject("a")); - assertSame(URLMapper.findFileObject(testa.toURI().toURL()), - URLMapper.findFileObject(testA.toURI().toURL())); + assertSame(URLMapper.findFileObject(Utilities.toURI(testa).toURL()), + URLMapper.findFileObject(Utilities.toURI(testA).toURL())); //but testRoot.getChildren(); diff --git a/maven/nbproject/project.xml b/maven/nbproject/project.xml --- a/maven/nbproject/project.xml +++ b/maven/nbproject/project.xml @@ -372,7 +372,7 @@ - 8.13 + 8.25 diff --git a/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java b/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java --- a/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java +++ b/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java @@ -100,6 +100,7 @@ import org.openide.util.NbBundle.Messages; import org.openide.util.NbCollections; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; import org.openide.util.lookup.ProxyLookup; @@ -435,7 +436,7 @@ public URI[] getGeneratedSourceRoots(boolean test) { URI uri = FileUtilities.getDirURI(getProjectDirectory(), test ? "target/generated-test-sources" : "target/generated-sources"); //NOI18N Set uris = new HashSet(); - File[] roots = new File(uri).listFiles(); + File[] roots = Utilities.toFile(uri).listFiles(); if (roots != null) { for (File root : roots) { if (!test && root.getName().startsWith("test-")) { @@ -443,22 +444,22 @@ } File[] kids = root.listFiles(); if (kids != null && /* #190626 */kids.length > 0) { - uris.add(root.toURI()); + uris.add(Utilities.toURI(root)); } else { - watcher.addWatchedPath(root.toURI()); + watcher.addWatchedPath(Utilities.toURI(root)); } } } if (test) { // MCOMPILER-167 - roots = new File(FileUtilities.getDirURI(getProjectDirectory(), "target/generated-sources")).listFiles(); + roots = Utilities.toFile(FileUtilities.getDirURI(getProjectDirectory(), "target/generated-sources")).listFiles(); if (roots != null) { for (File root : roots) { if (root.getName().startsWith("test-")) { File[] kids = root.listFiles(); if (kids != null && kids.length > 0) { - uris.add(root.toURI()); + uris.add(Utilities.toURI(root)); } else { - watcher.addWatchedPath(root.toURI()); + watcher.addWatchedPath(Utilities.toURI(root)); } } } @@ -536,7 +537,7 @@ public File[] getOtherRoots(boolean test) { URI uri = FileUtilities.getDirURI(getProjectDirectory(), test ? "src/test" : "src/main"); //NOI18N Set toRet = new HashSet(); - File fil = new File(uri); + File fil = Utilities.toFile(uri); if (fil.exists()) { File[] fls = fil.listFiles(new FilenameFilter() { @@ -563,7 +564,7 @@ } URI[] res = getResources(test); for (URI rs : res) { - File fl = new File(rs); + File fl = Utilities.toFile(rs); //in node view we need only the existing ones, if anything else needs all, // a new method is probably necessary.. if (fl.exists()) { diff --git a/maven/src/org/netbeans/modules/maven/ProjectOpenedHookImpl.java b/maven/src/org/netbeans/modules/maven/ProjectOpenedHookImpl.java --- a/maven/src/org/netbeans/modules/maven/ProjectOpenedHookImpl.java +++ b/maven/src/org/netbeans/modules/maven/ProjectOpenedHookImpl.java @@ -92,6 +92,7 @@ import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; /** * openhook implementation, register global classpath and also @@ -241,10 +242,10 @@ // the project root. uris.addAll(Arrays.asList(project.getGeneratedSourceRoots(false))); uris.addAll(Arrays.asList(project.getGeneratedSourceRoots(true))); - URI rootUri = FileUtil.toFile(project.getProjectDirectory()).toURI(); - File rootDir = new File(rootUri); + URI rootUri = Utilities.toURI(FileUtil.toFile(project.getProjectDirectory())); + File rootDir = Utilities.toFile(rootUri); for (URI uri : uris) { - if (FileUtilities.getRelativePath(rootDir, new File(uri)) == null) { + if (FileUtilities.getRelativePath(rootDir, Utilities.toFile(uri)) == null) { toRet.add(uri); } } @@ -449,7 +450,7 @@ } } else { try { - MavenFileOwnerQueryImpl.getInstance().registerCoordinates(groupId, artifactId, version, basedir.toURI().toURL()); + MavenFileOwnerQueryImpl.getInstance().registerCoordinates(groupId, artifactId, version, Utilities.toURI(basedir).toURL()); } catch (MalformedURLException x) { LOGGER.log(Level.FINE, null, x); } diff --git a/maven/src/org/netbeans/modules/maven/SubprojectProviderImpl.java b/maven/src/org/netbeans/modules/maven/SubprojectProviderImpl.java --- a/maven/src/org/netbeans/modules/maven/SubprojectProviderImpl.java +++ b/maven/src/org/netbeans/modules/maven/SubprojectProviderImpl.java @@ -63,6 +63,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.ChangeSupport; +import org.openide.util.Utilities; import org.openide.util.WeakListeners; /** @@ -117,7 +118,7 @@ for (Artifact ar : compileArtifacts) { File f = ar.getFile(); if (f != null) { - Project p = MavenFileOwnerQueryImpl.getInstance().getOwner(f.toURI()); + Project p = MavenFileOwnerQueryImpl.getInstance().getOwner(Utilities.toURI(f)); if (p != null) { resultset.add(p); } diff --git a/maven/src/org/netbeans/modules/maven/actions/CreateLibraryAction.java b/maven/src/org/netbeans/modules/maven/actions/CreateLibraryAction.java --- a/maven/src/org/netbeans/modules/maven/actions/CreateLibraryAction.java +++ b/maven/src/org/netbeans/modules/maven/actions/CreateLibraryAction.java @@ -87,6 +87,7 @@ import org.openide.util.NbBundle.Messages; import org.openide.util.RequestProcessor; import static org.netbeans.modules.maven.actions.Bundle.*; +import org.openide.util.Utilities; /** * @@ -169,7 +170,7 @@ File base; if (libRoot != null) { try { - base = new File(libRoot.toURI()); + base = Utilities.toFile(libRoot.toURI()); //getLocation() points to a file base = base.getParentFile(); nonDefaultLibBase = base; @@ -276,7 +277,7 @@ private static URI getJarUri(Artifact a, File copyTo, File nonDefaultLibBase, ClassifierType type) throws IOException { File res = a.getFile(); - URI uri = res.toURI(); + URI uri = Utilities.toURI(res); String jarPath = null; if (copyTo != null) { res = new File(copyTo, a.getFile().getName()); diff --git a/maven/src/org/netbeans/modules/maven/api/FileUtilities.java b/maven/src/org/netbeans/modules/maven/api/FileUtilities.java --- a/maven/src/org/netbeans/modules/maven/api/FileUtilities.java +++ b/maven/src/org/netbeans/modules/maven/api/FileUtilities.java @@ -77,7 +77,7 @@ if (uri == null) { return null; } - File fil = FileUtil.normalizeFile(new File(uri)); + File fil = FileUtil.normalizeFile(Utilities.toFile(uri)); return FileUtil.toFileObject(fil); } @@ -103,7 +103,7 @@ if (str != null) { File fil = new File(str); fil = FileUtil.normalizeFile(fil); - return fil.toURI(); + return Utilities.toURI(fil); } return null; } @@ -157,7 +157,7 @@ pth = pth.replaceFirst("^\\./", ""); //NOI18N pth = pth.replaceFirst("^\\.\\\\", ""); //NOI18N File src = FileUtilities.resolveFilePath(root, pth); - return FileUtil.normalizeFile(src).toURI(); + return Utilities.toURI(FileUtil.normalizeFile(src)); } public static URI getDirURI(@NonNull FileObject root, @NonNull String path) { @@ -233,7 +233,7 @@ } b.append("../"); // NOI18N } - URI u = base.toURI().relativize(file.toURI()); + URI u = Utilities.toURI(base).relativize(Utilities.toURI(file)); assert !u.isAbsolute() : u + " from " + basedir + " and " + file + " with common root " + base; b.append(u.getPath()); if (b.charAt(b.length() - 1) == '/') { diff --git a/maven/src/org/netbeans/modules/maven/api/NbMavenProject.java b/maven/src/org/netbeans/modules/maven/api/NbMavenProject.java --- a/maven/src/org/netbeans/modules/maven/api/NbMavenProject.java +++ b/maven/src/org/netbeans/modules/maven/api/NbMavenProject.java @@ -82,6 +82,7 @@ import org.openide.util.RequestProcessor; import static org.netbeans.modules.maven.api.Bundle.*; import org.openide.util.NbBundle.Messages; +import org.openide.util.Utilities; /** * an instance resides in project lookup, allows to get notified on project and @@ -143,27 +144,27 @@ @Override public void fileFolderCreated(FileEvent fe) { - fireChange(FileUtil.toFile(fe.getFile()).toURI()); + fireChange(Utilities.toURI(FileUtil.toFile(fe.getFile()))); } @Override public void fileDataCreated(FileEvent fe) { - fireChange(FileUtil.toFile(fe.getFile()).toURI()); + fireChange(Utilities.toURI(FileUtil.toFile(fe.getFile()))); } @Override public void fileChanged(FileEvent fe) { - fireChange(FileUtil.toFile(fe.getFile()).toURI()); + fireChange(Utilities.toURI(FileUtil.toFile(fe.getFile()))); } @Override public void fileDeleted(FileEvent fe) { - fireChange(FileUtil.toFile(fe.getFile()).toURI()); + fireChange(Utilities.toURI(FileUtil.toFile(fe.getFile()))); } @Override public void fileRenamed(FileRenameEvent fe) { - fireChange(FileUtil.toFile(fe.getFile()).toURI()); + fireChange(Utilities.toURI(FileUtil.toFile(fe.getFile()))); } @Override @@ -339,7 +340,7 @@ public void addWatchedPath(URI uri) { //#110599 boolean addListener = false; - File fil = new File(uri); + File fil = Utilities.toFile(uri); synchronized (files) { if (!files.contains(fil)) { addListener = true; @@ -477,7 +478,7 @@ public void removeWatchedPath(URI uri) { //#110599 boolean removeListener = false; - File fil = new File(uri); + File fil = Utilities.toFile(uri); synchronized (files) { boolean rem = files.remove(fil); if (rem && !files.contains(fil)) { diff --git a/maven/src/org/netbeans/modules/maven/classpath/AbstractProjectClassPathImpl.java b/maven/src/org/netbeans/modules/maven/classpath/AbstractProjectClassPathImpl.java --- a/maven/src/org/netbeans/modules/maven/classpath/AbstractProjectClassPathImpl.java +++ b/maven/src/org/netbeans/modules/maven/classpath/AbstractProjectClassPathImpl.java @@ -60,6 +60,7 @@ import org.netbeans.spi.java.classpath.FilteringPathResourceImplementation; import org.netbeans.spi.java.classpath.PathResourceImplementation; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -169,7 +170,7 @@ for (int i = 0; i < pieces.length; i++) { try { // XXX would be cleaner to take a File[] if that is what these all are anyway! - final URL entry = FileUtil.urlForArchiveOrDir(new File(pieces[i])); + final URL entry = FileUtil.urlForArchiveOrDir(Utilities.toFile(pieces[i])); if (entry != null) { result.add(new FilteringPathResourceImplementation() { @Override public boolean includes(URL root, String resource) { diff --git a/maven/src/org/netbeans/modules/maven/classpath/ClassPathProviderImpl.java b/maven/src/org/netbeans/modules/maven/classpath/ClassPathProviderImpl.java --- a/maven/src/org/netbeans/modules/maven/classpath/ClassPathProviderImpl.java +++ b/maven/src/org/netbeans/modules/maven/classpath/ClassPathProviderImpl.java @@ -64,6 +64,7 @@ import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * Defines class path for maven2 projects.. @@ -218,7 +219,7 @@ } URI web = project.getWebAppDirectory(); - FileObject fo = FileUtil.toFileObject(new File(web)); + FileObject fo = FileUtil.toFileObject(Utilities.toFile(web)); if (fo != null && (fo.equals(file) || FileUtil.isParentOf(fo, file))) { return TYPE_WEB; } diff --git a/maven/src/org/netbeans/modules/maven/classpath/CompileClassPathImpl.java b/maven/src/org/netbeans/modules/maven/classpath/CompileClassPathImpl.java --- a/maven/src/org/netbeans/modules/maven/classpath/CompileClassPathImpl.java +++ b/maven/src/org/netbeans/modules/maven/classpath/CompileClassPathImpl.java @@ -49,6 +49,7 @@ import org.apache.maven.artifact.Artifact; import org.netbeans.modules.maven.NbMavenProjectImpl; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -71,7 +72,7 @@ for (Artifact art : arts) { if (art.getFile() != null) { File fil = FileUtil.normalizeFile(art.getFile()); - lst.add(fil.toURI()); + lst.add(Utilities.toURI(fil)); } else { //NOPMD //null means dependencies were not resolved.. } diff --git a/maven/src/org/netbeans/modules/maven/classpath/MavenSourcesImpl.java b/maven/src/org/netbeans/modules/maven/classpath/MavenSourcesImpl.java --- a/maven/src/org/netbeans/modules/maven/classpath/MavenSourcesImpl.java +++ b/maven/src/org/netbeans/modules/maven/classpath/MavenSourcesImpl.java @@ -85,6 +85,7 @@ import static org.netbeans.modules.maven.classpath.Bundle.*; import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.util.NbBundle.Messages; +import org.openide.util.Utilities; /** * Implementation of Sources interface for maven projects. @@ -240,7 +241,7 @@ } } if (create && existing.isEmpty()) { - File root = new File(virtuals.get(0)); + File root = Utilities.toFile(virtuals.get(0)); FileObject fo=null; try { fo = FileUtil.createFolder(root); @@ -265,7 +266,7 @@ private boolean checkSourceGroupCache(@NullAllowed File rootF, String name, String displayName, Map groups, NbMavenProject watcher) { FileObject root; if (rootF != null) { - watcher.addWatchedPath(rootF.toURI()); + watcher.addWatchedPath(Utilities.toURI(rootF)); root = FileUtil.toFileObject(rootF); } else { root = null; @@ -299,7 +300,7 @@ List checked = new ArrayList(); for (boolean test : new boolean[] {false, true}) { for (URI u : project().getGeneratedSourceRoots(test)) { - File file = FileUtil.normalizeFile(new File(u)); + File file = FileUtil.normalizeFile(Utilities.toFile(u)); FileObject folder = FileUtil.toFileObject(file); changed |= checkGeneratedGroupCache(folder, file, file.getName(), test); checked.add(file); @@ -357,7 +358,7 @@ URI[] res = project().getResources(test); Set resources = new HashSet(); for (URI ur : res) { - resources.add(new File(ur)); + resources.add(Utilities.toFile(ur)); } for (File f : roots) { diff --git a/maven/src/org/netbeans/modules/maven/classpath/PackagedClassPathImpl.java b/maven/src/org/netbeans/modules/maven/classpath/PackagedClassPathImpl.java --- a/maven/src/org/netbeans/modules/maven/classpath/PackagedClassPathImpl.java +++ b/maven/src/org/netbeans/modules/maven/classpath/PackagedClassPathImpl.java @@ -50,6 +50,7 @@ import org.apache.maven.model.Dependency; import org.netbeans.modules.maven.NbMavenProjectImpl; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -83,14 +84,14 @@ if (art.getClassifier() != null) { assemblies.add(0, fil); } else { - lst.add(fil.toURI()); + lst.add(Utilities.toURI(fil)); } } else { //NOPMD //null means dependencies were not resolved.. } } for (File ass : assemblies) { - lst.add(ass.toURI()); + lst.add(Utilities.toURI(ass)); } URI[] uris = new URI[lst.size()]; uris = lst.toArray(uris); diff --git a/maven/src/org/netbeans/modules/maven/classpath/RuntimeClassPathImpl.java b/maven/src/org/netbeans/modules/maven/classpath/RuntimeClassPathImpl.java --- a/maven/src/org/netbeans/modules/maven/classpath/RuntimeClassPathImpl.java +++ b/maven/src/org/netbeans/modules/maven/classpath/RuntimeClassPathImpl.java @@ -51,6 +51,7 @@ import org.apache.maven.project.MavenProject; import org.netbeans.modules.maven.NbMavenProjectImpl; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * class path def for runtime.. @@ -81,14 +82,14 @@ if (outputDirectory != null) { File fil = new File(outputDirectory); fil = FileUtil.normalizeFile(fil); - lst.add(fil.toURI()); + lst.add(Utilities.toURI(fil)); } } List arts = prj.getRuntimeArtifacts(); for (Artifact art : arts) { if (art.getFile() != null) { File fil = FileUtil.normalizeFile(art.getFile()); - lst.add(fil.toURI()); + lst.add(Utilities.toURI(fil)); } else { //NOPMD //null means dependencies were not resolved.. } diff --git a/maven/src/org/netbeans/modules/maven/classpath/SourceClassPathImpl.java b/maven/src/org/netbeans/modules/maven/classpath/SourceClassPathImpl.java --- a/maven/src/org/netbeans/modules/maven/classpath/SourceClassPathImpl.java +++ b/maven/src/org/netbeans/modules/maven/classpath/SourceClassPathImpl.java @@ -51,6 +51,7 @@ import java.util.Iterator; import java.util.List; import org.netbeans.modules.maven.NbMavenProjectImpl; +import org.openide.util.Utilities; /** * @@ -84,7 +85,7 @@ } } URI webSrc = getMavenProject().getWebAppDirectory(); - if (new File(webSrc).exists()) { + if (Utilities.toFile(webSrc).exists()) { col.add(webSrc); } col.addAll(resources); diff --git a/maven/src/org/netbeans/modules/maven/classpath/TestCompileClassPathImpl.java b/maven/src/org/netbeans/modules/maven/classpath/TestCompileClassPathImpl.java --- a/maven/src/org/netbeans/modules/maven/classpath/TestCompileClassPathImpl.java +++ b/maven/src/org/netbeans/modules/maven/classpath/TestCompileClassPathImpl.java @@ -49,6 +49,7 @@ import org.apache.maven.artifact.Artifact; import org.netbeans.modules.maven.NbMavenProjectImpl; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -73,12 +74,12 @@ for (Artifact art : arts) { if (art.getFile() != null) { File fil = FileUtil.normalizeFile(art.getFile()); - lst.add(fil.toURI()); + lst.add(Utilities.toURI(fil)); } else { //NOPMD //null means dependencies were not resolved.. } } - lst.add(0, getMavenProject().getProjectWatcher().getOutputDirectory(false).toURI()); + lst.add(0, Utilities.toURI(getMavenProject().getProjectWatcher().getOutputDirectory(false))); URI[] uris = new URI[lst.size()]; uris = lst.toArray(uris); return uris; diff --git a/maven/src/org/netbeans/modules/maven/classpath/TestRuntimeClassPathImpl.java b/maven/src/org/netbeans/modules/maven/classpath/TestRuntimeClassPathImpl.java --- a/maven/src/org/netbeans/modules/maven/classpath/TestRuntimeClassPathImpl.java +++ b/maven/src/org/netbeans/modules/maven/classpath/TestRuntimeClassPathImpl.java @@ -51,6 +51,7 @@ import org.apache.maven.project.MavenProject; import org.netbeans.modules.maven.NbMavenProjectImpl; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** @@ -83,20 +84,20 @@ if (testOutputDirectory != null) { File fil = new File(testOutputDirectory); fil = FileUtil.normalizeFile(fil); - lst.add(fil.toURI()); + lst.add(Utilities.toURI(fil)); } String outputDirectory = build.getOutputDirectory(); if (outputDirectory != null) { File fil = new File(outputDirectory); fil = FileUtil.normalizeFile(fil); - lst.add(fil.toURI()); + lst.add(Utilities.toURI(fil)); } } List arts = prj.getTestArtifacts(); for (Artifact art : arts) { if (art.getFile() != null) { File fil = FileUtil.normalizeFile(art.getFile()); - lst.add(fil.toURI()); + lst.add(Utilities.toURI(fil)); } else { //NOPMD //null means dependencies were not resolved.. } diff --git a/maven/src/org/netbeans/modules/maven/cos/CopyResourcesOnSave.java b/maven/src/org/netbeans/modules/maven/cos/CopyResourcesOnSave.java --- a/maven/src/org/netbeans/modules/maven/cos/CopyResourcesOnSave.java +++ b/maven/src/org/netbeans/modules/maven/cos/CopyResourcesOnSave.java @@ -70,6 +70,7 @@ import org.openide.filesystems.FileRenameEvent; import org.openide.filesystems.FileUtil; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; /** * @author mkleint @@ -126,7 +127,7 @@ continue; } URI uri = FileUtilities.getDirURI(project.getProjectDirectory(), dir); - File file = new File(uri); + File file = Utilities.toFile(uri); if (!old.contains(file) && added.add(file)) { // if a given file is there multiple times, we get assertion back from FileUtil. there can be only one listener+file tuple FileUtil.addFileChangeListener(this, file); } @@ -387,7 +388,7 @@ continue; } URI uri = FileUtilities.getDirURI(prj.getProjectDirectory(), dir); - FileObject fo = FileUtil.toFileObject(new File(uri)); + FileObject fo = FileUtil.toFileObject(Utilities.toFile(uri)); if (fo != null && FileUtil.isParentOf(fo, child)) { String path = FileUtil.getRelativePath(fo, child); //now check includes and excludes diff --git a/maven/src/org/netbeans/modules/maven/cos/CosChecker.java b/maven/src/org/netbeans/modules/maven/cos/CosChecker.java --- a/maven/src/org/netbeans/modules/maven/cos/CosChecker.java +++ b/maven/src/org/netbeans/modules/maven/cos/CosChecker.java @@ -97,6 +97,7 @@ import org.openide.util.ImageUtilities; import org.openide.util.NbBundle.Messages; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; @@ -513,7 +514,7 @@ File root = FileUtilities.resolveFilePath(base, add); if (root != null) { try { - URL url = root.toURI().toURL(); + URL url = Utilities.toURI(root).toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } diff --git a/maven/src/org/netbeans/modules/maven/debug/Utils.java b/maven/src/org/netbeans/modules/maven/debug/Utils.java --- a/maven/src/org/netbeans/modules/maven/debug/Utils.java +++ b/maven/src/org/netbeans/modules/maven/debug/Utils.java @@ -72,6 +72,7 @@ import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * various debugger related utility methods. @@ -242,7 +243,7 @@ static URL fileToURL(File file) { try { URL url; - url = file.toURI().toURL(); + url = Utilities.toURI(file).toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } diff --git a/maven/src/org/netbeans/modules/maven/newproject/CatalogRepoProvider.java b/maven/src/org/netbeans/modules/maven/newproject/CatalogRepoProvider.java --- a/maven/src/org/netbeans/modules/maven/newproject/CatalogRepoProvider.java +++ b/maven/src/org/netbeans/modules/maven/newproject/CatalogRepoProvider.java @@ -86,6 +86,7 @@ import org.netbeans.modules.maven.indexer.api.RepositoryPreferences; import org.openide.modules.Places; import org.openide.util.NbCollections; +import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; /** @@ -167,7 +168,7 @@ @Override protected URL file() throws IOException { File f = new File(RepositorySystem.userMavenConfigurationHome, "archetype-catalog.xml"); //NOI18N - return f.isFile() ? f.toURI().toURL() : null; + return f.isFile() ? Utilities.toURI(f).toURL() : null; } @Override protected String repository() { @@ -210,7 +211,7 @@ if (catalog.exists()) { try { - toRet.addAll(CatalogRepoProvider.getArchetypes(catalog.toURI().toURL(), info.getRepositoryUrl())); + toRet.addAll(CatalogRepoProvider.getArchetypes(Utilities.toURI(catalog).toURL(), info.getRepositoryUrl())); } catch (MalformedURLException ex) { LOG.log(Level.INFO, null, ex); } diff --git a/maven/src/org/netbeans/modules/maven/nodes/DependencyNode.java b/maven/src/org/netbeans/modules/maven/nodes/DependencyNode.java --- a/maven/src/org/netbeans/modules/maven/nodes/DependencyNode.java +++ b/maven/src/org/netbeans/modules/maven/nodes/DependencyNode.java @@ -312,7 +312,7 @@ if ( Artifact.SCOPE_SYSTEM.equals(art.getScope())) { return null; } - URI uri = art.getFile().toURI(); + URI uri = org.openide.util.Utilities.toURI(art.getFile()); return FileOwnerQuery.getOwner(uri); } @@ -1190,7 +1190,7 @@ for (Artifact art : context.lookupAll(Artifact.class)) { File f = art.getFile(); if (f != null) { - Project p = FileOwnerQuery.getOwner(f.toURI()); + Project p = FileOwnerQuery.getOwner(org.openide.util.Utilities.toURI(f)); if (p != null) { projects.add(p); } diff --git a/maven/src/org/netbeans/modules/maven/output/SiteOutputProcessor.java b/maven/src/org/netbeans/modules/maven/output/SiteOutputProcessor.java --- a/maven/src/org/netbeans/modules/maven/output/SiteOutputProcessor.java +++ b/maven/src/org/netbeans/modules/maven/output/SiteOutputProcessor.java @@ -52,6 +52,7 @@ import org.openide.awt.StatusDisplayer; import org.openide.filesystems.FileUtil; import org.openide.util.NbBundle.Messages; +import org.openide.util.Utilities; import org.openide.windows.OutputEvent; import org.openide.windows.OutputListener; @@ -110,7 +111,7 @@ File html = new File(FileUtil.toFile(prj.getProjectDirectory()), "target/site/index.html"); if (html.isFile()) { try { - HtmlBrowser.URLDisplayer.getDefault().showURL(html.toURI().toURL()); + HtmlBrowser.URLDisplayer.getDefault().showURL(Utilities.toURI(html).toURL()); } catch (MalformedURLException x) { assert false : x; } diff --git a/maven/src/org/netbeans/modules/maven/queries/MavenBinaryForSourceQueryImpl.java b/maven/src/org/netbeans/modules/maven/queries/MavenBinaryForSourceQueryImpl.java --- a/maven/src/org/netbeans/modules/maven/queries/MavenBinaryForSourceQueryImpl.java +++ b/maven/src/org/netbeans/modules/maven/queries/MavenBinaryForSourceQueryImpl.java @@ -64,6 +64,7 @@ import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * @@ -87,7 +88,7 @@ } if ("file".equals(url.getProtocol())) { //NOI18N try { - File fil = new File(url.toURI()); + File fil = Utilities.toFile(url.toURI()); fil = FileUtil.normalizeFile(fil); Res toReturn = findFor(fil); if (toReturn != null) { @@ -158,8 +159,8 @@ private Res checkRoot(File root, URI source, URI test) { return checkRoot(root, - source != null ? FileUtil.normalizeFile(new File(source)) : null, - test != null ? FileUtil.normalizeFile(new File(test)) : null); + source != null ? FileUtil.normalizeFile(Utilities.toFile(source)) : null, + test != null ? FileUtil.normalizeFile(Utilities.toFile(test)) : null); } diff --git a/maven/src/org/netbeans/modules/maven/queries/MavenFileOwnerQueryImpl.java b/maven/src/org/netbeans/modules/maven/queries/MavenFileOwnerQueryImpl.java --- a/maven/src/org/netbeans/modules/maven/queries/MavenFileOwnerQueryImpl.java +++ b/maven/src/org/netbeans/modules/maven/queries/MavenFileOwnerQueryImpl.java @@ -73,6 +73,7 @@ import org.openide.util.ChangeSupport; import org.openide.util.Lookup; import org.openide.util.NbPreferences; +import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProviders; @@ -166,7 +167,7 @@ public @Override Project getOwner(URI uri) { LOG.log(Level.FINEST, "getOwner of uri={0}", uri); if ("file".equals(uri.getScheme())) { //NOI18N - File file = new File(uri); + File file = Utilities.toFile(uri); return getOwner(file); } return null; @@ -314,7 +315,7 @@ try { URI uri = new URI(ownerURI); if ("file".equals(uri.getScheme())) { - File pom = new File(uri.resolve("pom.xml")); + File pom = Utilities.toFile(uri.resolve("pom.xml")); if (pom.isFile()) { ModelReader reader = EmbedderFactory.getProjectEmbedder().lookupComponent(ModelReader.class); Model model = reader.read(pom, Collections.singletonMap(ModelReader.IS_STRICT, false)); diff --git a/maven/src/org/netbeans/modules/maven/queries/MavenSharabilityQueryImpl.java b/maven/src/org/netbeans/modules/maven/queries/MavenSharabilityQueryImpl.java --- a/maven/src/org/netbeans/modules/maven/queries/MavenSharabilityQueryImpl.java +++ b/maven/src/org/netbeans/modules/maven/queries/MavenSharabilityQueryImpl.java @@ -55,6 +55,7 @@ import org.netbeans.spi.queries.SharabilityQueryImplementation2; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -71,7 +72,7 @@ public @Override SharabilityQuery.Sharability getSharability(URI uri) { //#119541 for the project's root, return MIXED right away. - File file = FileUtil.normalizeFile(new File(uri)); + File file = FileUtil.normalizeFile(Utilities.toFile(uri)); FileObject fo = FileUtil.toFileObject(file); if (fo != null && fo.equals(project.getProjectDirectory())) { return SharabilityQuery.Sharability.MIXED; diff --git a/maven/src/org/netbeans/modules/maven/queries/MavenSourceLevelImpl.java b/maven/src/org/netbeans/modules/maven/queries/MavenSourceLevelImpl.java --- a/maven/src/org/netbeans/modules/maven/queries/MavenSourceLevelImpl.java +++ b/maven/src/org/netbeans/modules/maven/queries/MavenSourceLevelImpl.java @@ -58,6 +58,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.ChangeSupport; +import org.openide.util.Utilities; import org.openide.util.WeakListeners; /** @@ -80,7 +81,7 @@ //#128609 something in jar? return null; } - URI uri = file.toURI(); + URI uri = Utilities.toURI(file); assert "file".equals(uri.getScheme()); String goal = "compile"; //NOI18N for (URI testuri : project.getLookup().lookup(NbMavenProjectImpl.class).getSourceRoots(true)) { diff --git a/maven/src/org/netbeans/modules/maven/queries/MavenTestForSourceImpl.java b/maven/src/org/netbeans/modules/maven/queries/MavenTestForSourceImpl.java --- a/maven/src/org/netbeans/modules/maven/queries/MavenTestForSourceImpl.java +++ b/maven/src/org/netbeans/modules/maven/queries/MavenTestForSourceImpl.java @@ -53,6 +53,7 @@ import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * JUnit tests queries. @@ -79,7 +80,7 @@ if (fl.equals(param)) { return null; } - URI uri = fl.toURI(); + URI uri = Utilities.toURI(fl); URL entry = uri.toURL(); if (!entry.toExternalForm().endsWith("/")) { //NOI18N entry = new URL(entry.toExternalForm() + "/"); //NOI18N @@ -102,7 +103,7 @@ if (fl.equals(param)) { return null; } - URI uri = fl.toURI(); + URI uri = Utilities.toURI(fl); URL entry = uri.toURL(); if (!entry.toExternalForm().endsWith("/")) { //NOI18N entry = new URL(entry.toExternalForm() + "/"); //NOI18N diff --git a/maven/src/org/netbeans/modules/maven/queries/RepositoryJavadocForBinaryQueryImpl.java b/maven/src/org/netbeans/modules/maven/queries/RepositoryJavadocForBinaryQueryImpl.java --- a/maven/src/org/netbeans/modules/maven/queries/RepositoryJavadocForBinaryQueryImpl.java +++ b/maven/src/org/netbeans/modules/maven/queries/RepositoryJavadocForBinaryQueryImpl.java @@ -59,6 +59,7 @@ import org.openide.filesystems.URLMapper; import org.openide.util.Exceptions; import org.openide.modules.InstalledFileLocator; +import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; /** @@ -157,14 +158,14 @@ URL[] url; if (path != null) { url = new URL[1]; - URL root = FileUtil.getArchiveRoot(file.toURI().toURL()); + URL root = FileUtil.getArchiveRoot(Utilities.toURI(file).toURL()); if (!path.endsWith("/")) { //NOI18N path = path + "/"; //NOI18N } url[0] = new URL(root, path); } else { url = new URL[1]; - url[0] = FileUtil.getArchiveRoot(file.toURI().toURL()); + url[0] = FileUtil.getArchiveRoot(Utilities.toURI(file).toURL()); } return url; } @@ -204,7 +205,7 @@ try { File j2eeDoc = InstalledFileLocator.getDefault().locate("docs/javaee6-doc-api.zip", "org.netbeans.modules.j2ee.platform", false); // NOI18N if (j2eeDoc != null) { - URL url = FileUtil.getArchiveRoot(j2eeDoc.toURI().toURL()); + URL url = FileUtil.getArchiveRoot(Utilities.toURI(j2eeDoc).toURL()); url = new URL(url + "docs/api/"); //NOI18N return new URL[]{url}; } diff --git a/maven/src/org/netbeans/modules/maven/queries/RepositoryMavenCPProvider.java b/maven/src/org/netbeans/modules/maven/queries/RepositoryMavenCPProvider.java --- a/maven/src/org/netbeans/modules/maven/queries/RepositoryMavenCPProvider.java +++ b/maven/src/org/netbeans/modules/maven/queries/RepositoryMavenCPProvider.java @@ -68,6 +68,7 @@ import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; /** @@ -98,8 +99,8 @@ //TODO can the .jar extension be hardwired? on CP.. File bin = new File(parent, artifact + "-" + version + ".jar"); //NOI18N File pom = new File(parent, artifact + "-" + version + ".pom"); //NOI18N - URI localRepo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile().toURI(); - URI rel = localRepo.relativize(parentParent.getParentFile().toURI()); + URI localRepo = Utilities.toURI(EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile()); + URI rel = localRepo.relativize(Utilities.toURI(parentParent.getParentFile())); if (!rel.isAbsolute()) { String groupId = rel.getPath(); if (groupId != null && !groupId.equals("")) { diff --git a/maven/test/unit/src/org/netbeans/modules/maven/NbArtifactFixerTest.java b/maven/test/unit/src/org/netbeans/modules/maven/NbArtifactFixerTest.java --- a/maven/test/unit/src/org/netbeans/modules/maven/NbArtifactFixerTest.java +++ b/maven/test/unit/src/org/netbeans/modules/maven/NbArtifactFixerTest.java @@ -41,6 +41,7 @@ import java.io.File; import org.netbeans.junit.NbTestCase; import org.netbeans.modules.maven.queries.MavenFileOwnerQueryImpl; +import org.openide.util.Utilities; import org.openide.util.test.TestFileUtils; import org.sonatype.aether.util.artifact.DefaultArtifact; @@ -58,7 +59,7 @@ File pom = TestFileUtils.writeFile(new File(getWorkDir(), "pom.xml"), "4.0.0" + "ga0" + ""); - MavenFileOwnerQueryImpl.getInstance().registerCoordinates("g", "a", "0", getWorkDir().toURI().toURL()); + MavenFileOwnerQueryImpl.getInstance().registerCoordinates("g", "a", "0", Utilities.toURI(getWorkDir()).toURL()); assertEquals(pom, new NbArtifactFixer().resolve(new DefaultArtifact("g:a:pom:0"))); assertEquals(null, new NbArtifactFixer().resolve(new DefaultArtifact("g:a:jar:0"))); File fallback = new NbArtifactFixer().resolve(new DefaultArtifact("g:a:pom:1")); diff --git a/maven/test/unit/src/org/netbeans/modules/maven/ProjectOpenedHookImplTest.java b/maven/test/unit/src/org/netbeans/modules/maven/ProjectOpenedHookImplTest.java --- a/maven/test/unit/src/org/netbeans/modules/maven/ProjectOpenedHookImplTest.java +++ b/maven/test/unit/src/org/netbeans/modules/maven/ProjectOpenedHookImplTest.java @@ -52,6 +52,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.test.TestFileUtils; +import org.openide.util.Utilities; public class ProjectOpenedHookImplTest extends NbTestCase { @@ -178,11 +179,11 @@ File repo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile(); File mArt = new File(repo, "g/m/0/m-0.jar"); // XXX verify that p2 has not yet been loaded - Project m = FileOwnerQuery.getOwner(mArt.toURI()); + Project m = FileOwnerQuery.getOwner(Utilities.toURI(mArt)); assertNotNull(m); assertEquals(d.getFileObject("p2/m"), m.getProjectDirectory()); File p2Art = new File(repo, "g/p2/0/p2-0.pom"); - Project p2 = FileOwnerQuery.getOwner(p2Art.toURI()); + Project p2 = FileOwnerQuery.getOwner(Utilities.toURI(p2Art)); assertNotNull(p2); assertEquals(d.getFileObject("p2"), p2.getProjectDirectory()); } finally { diff --git a/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenAnnotationProcessingQueryImplTest.java b/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenAnnotationProcessingQueryImplTest.java --- a/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenAnnotationProcessingQueryImplTest.java +++ b/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenAnnotationProcessingQueryImplTest.java @@ -46,6 +46,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.test.TestFileUtils; +import org.openide.util.Utilities; public class MavenAnnotationProcessingQueryImplTest extends NbTestCase { @@ -73,7 +74,7 @@ assertEquals(expected, "enabled=" + r.annotationProcessingEnabled() + " run=" + r.annotationProcessorsToRun() + - " s=" + (sOD != null ? sOD.toString().replace(getWorkDir().toURI().toString(), ".../") : "-") + + " s=" + (sOD != null ? sOD.toString().replace(Utilities.toURI(getWorkDir()).toString(), ".../") : "-") + " opts=" + opts); } diff --git a/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenFileOwnerQueryImplTest.java b/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenFileOwnerQueryImplTest.java --- a/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenFileOwnerQueryImplTest.java +++ b/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenFileOwnerQueryImplTest.java @@ -50,6 +50,7 @@ import org.netbeans.modules.maven.NbMavenProjectImpl; import org.netbeans.modules.maven.embedder.EmbedderFactory; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; import org.openide.util.test.TestFileUtils; public class MavenFileOwnerQueryImplTest extends NbTestCase { @@ -85,14 +86,14 @@ File repo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile(); File art10 = new File(repo, "test/prj/1.0/prj-1.0.jar"); File art11 = new File(repo, "test/prj/1.1/prj-1.1.jar"); - assertEquals(null, foq.getOwner(art10.toURI())); - assertEquals(null, foq.getOwner(art11.toURI())); + assertEquals(null, foq.getOwner(Utilities.toURI(art10))); + assertEquals(null, foq.getOwner(Utilities.toURI(art11))); foq.registerProject(p10); - assertEquals(p10, foq.getOwner(art10.toURI())); - assertEquals(null, foq.getOwner(art11.toURI())); + assertEquals(p10, foq.getOwner(Utilities.toURI(art10))); + assertEquals(null, foq.getOwner(Utilities.toURI(art11))); foq.registerProject(p11); - assertEquals(p10, foq.getOwner(art10.toURI())); - assertEquals(p11, foq.getOwner(art11.toURI())); + assertEquals(p10, foq.getOwner(Utilities.toURI(art10))); + assertEquals(p11, foq.getOwner(Utilities.toURI(art11))); } public void testOldEntriesGetRemoved() throws Exception { diff --git a/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenSharabilityQueryImplTest.java b/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenSharabilityQueryImplTest.java --- a/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenSharabilityQueryImplTest.java +++ b/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenSharabilityQueryImplTest.java @@ -45,6 +45,7 @@ import java.io.File; import org.netbeans.api.queries.SharabilityQuery; import org.netbeans.junit.NbTestCase; +import org.openide.util.Utilities; import org.openide.util.test.TestFileUtils; public class MavenSharabilityQueryImplTest extends NbTestCase { @@ -82,7 +83,7 @@ assertSharability(SharabilityQuery.Sharability.NOT_SHARABLE, "prj/modules/mod/target"); } private void assertSharability(SharabilityQuery.Sharability expected, String path) throws Exception { - assertEquals(path, expected, SharabilityQuery.getSharability(new File(getWorkDir(), path).toURI())); + assertEquals(path, expected, SharabilityQuery.getSharability(Utilities.toURI(new File(getWorkDir(), path)))); } } diff --git a/o.n.bootstrap/nbproject/project.xml b/o.n.bootstrap/nbproject/project.xml --- a/o.n.bootstrap/nbproject/project.xml +++ b/o.n.bootstrap/nbproject/project.xml @@ -62,7 +62,7 @@ - 8.0 + 8.25 diff --git a/o.n.bootstrap/src/org/netbeans/JarClassLoader.java b/o.n.bootstrap/src/org/netbeans/JarClassLoader.java --- a/o.n.bootstrap/src/org/netbeans/JarClassLoader.java +++ b/o.n.bootstrap/src/org/netbeans/JarClassLoader.java @@ -165,7 +165,7 @@ } final void addURL(URL location) throws IOException, URISyntaxException { - File f = new File(location.toURI()); + File f = Utilities.toFile(location.toURI()); assert f.exists() : "URL must be existing local file: " + location; List arr = new ArrayList(Arrays.asList(sources)); @@ -464,7 +464,7 @@ return this; } } - return "jar:" + new VFile().toURI() + "!/"; // NOI18N + return "jar:" + Utilities.toURI(new VFile()) + "!/"; // NOI18N } @Override @@ -813,7 +813,7 @@ File dir; DirSource(File file) throws MalformedURLException { - super(file.toURI().toURL()); + super(Utilities.toURI(file).toURL()); dir = file; } @@ -823,7 +823,7 @@ protected URL doGetResource(String name) throws MalformedURLException { File resFile = new File(dir, name); - return resFile.exists() ? resFile.toURI().toURL() : null; + return resFile.exists() ? Utilities.toURI(resFile).toURL() : null; } protected byte[] readClass(String path) throws IOException { @@ -946,7 +946,7 @@ AGAIN: for (;;) try { final URI uri = new URI(filePath); if (uri.getScheme().equals("file")) { - jar = uri2File(uri).getPath(); + jar = Utilities.toFile(uri).getPath(); } else { jar = null; } @@ -981,14 +981,6 @@ return new NbJarURLConnection (u, _src, _name, loader); } - static File uri2File(URI uri) { // #207060: UNC; candidate for API (#46813) - if (uri.getHost() == null) { - return new File(uri); - } else { - return new File("\\\\" + uri.getHost() + uri.getPath().replace('/', '\\')); - } - } - @Override protected void parseURL(URL u, String spec, int start, int limit) { if (spec.startsWith("/")) { diff --git a/o.n.bootstrap/test/unit/src/org/netbeans/JarClassLoaderTest.java b/o.n.bootstrap/test/unit/src/org/netbeans/JarClassLoaderTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/JarClassLoaderTest.java +++ b/o.n.bootstrap/test/unit/src/org/netbeans/JarClassLoaderTest.java @@ -65,6 +65,7 @@ import java.util.Map; import junit.framework.AssertionFailedError; import org.netbeans.junit.NbTestCase; +import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; import org.openide.util.test.TestFileUtils; @@ -243,7 +244,7 @@ assertTrue(conn instanceof JarURLConnection); JarURLConnection jconn = (JarURLConnection) conn; assertEquals("package/re source++.txt", jconn.getEntryName()); - assertEquals(jar.toURI().toURL(), jconn.getJarFileURL()); + assertEquals(Utilities.toURI(jar).toURL(), jconn.getJarFileURL()); assertEquals("bar", jconn.getMainAttributes().getValue("foo")); assertEquals(jar.getAbsolutePath(), jconn.getJarFile().getName()); } @@ -252,7 +253,7 @@ File jar = new File(getWorkDir(), "default-package-resource.jar"); TestFileUtils.writeZipFile(jar, "META-INF/MANIFEST.MF:Manifest-Version: 1.0\nfoo: bar\n\n", "package/re source++.txt:content"); JarClassLoader jcl = new JarClassLoader(Collections.emptyList(), new ProxyClassLoader[0]); - jcl.addURL(jar.toURI().toURL()); + jcl.addURL(Utilities.toURI(jar).toURL()); URL url = jcl.getResource("package/re source++.txt"); assertTrue(url.toString(), url.toString().endsWith("default-package-resource.jar!/package/re%20source++.txt")); URLConnection conn = url.openConnection(); @@ -260,7 +261,7 @@ assertTrue(conn instanceof JarURLConnection); JarURLConnection jconn = (JarURLConnection) conn; assertEquals("package/re source++.txt", jconn.getEntryName()); - assertEquals(jar.toURI().toURL(), jconn.getJarFileURL()); + assertEquals(Utilities.toURI(jar).toURL(), jconn.getJarFileURL()); assertEquals("bar", jconn.getMainAttributes().getValue("foo")); assertEquals(jar.getAbsolutePath(), jconn.getJarFile().getName()); } diff --git a/o.n.bootstrap/test/unit/src/org/netbeans/JarURLStreamHandlerTest.java b/o.n.bootstrap/test/unit/src/org/netbeans/JarURLStreamHandlerTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/JarURLStreamHandlerTest.java +++ b/o.n.bootstrap/test/unit/src/org/netbeans/JarURLStreamHandlerTest.java @@ -50,6 +50,7 @@ import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; import org.netbeans.junit.NbTestCase; +import org.openide.util.Utilities; /** * @@ -83,14 +84,14 @@ } public void testNormalHandler() throws Exception { - URL root = new URL("jar:" + jar.toURI() + "!/"); + URL root = new URL("jar:" + Utilities.toURI(jar) + "!/"); URL plain = new URL(root, "/fldr/plain.txt", ProxyURLStreamHandlerFactory.originalJarHandler()); assertTrue("Contains the plain.txt part: " + plain, plain.toExternalForm().contains("fldr/plain.txt")); assertContent("Ahoj", plain); } public void testNbHandler() throws Exception { - URL root = new URL("jar:" + jar.toURI() + "!/"); + URL root = new URL("jar:" + Utilities.toURI(jar) + "!/"); URL plain = new URL(root, "/fldr/plain.txt", new JarClassLoader.JarURLStreamHandler(null)); assertTrue("Contains the plain.txt part: " + plain, plain.toExternalForm().contains("fldr/plain.txt")); assertContent("Ahoj", plain); diff --git a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleFactoryAlienTest.java b/o.n.bootstrap/test/unit/src/org/netbeans/ModuleFactoryAlienTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleFactoryAlienTest.java +++ b/o.n.bootstrap/test/unit/src/org/netbeans/ModuleFactoryAlienTest.java @@ -64,6 +64,7 @@ import org.fakepkg.FakeIfceHidden; import org.openide.modules.SpecificationVersion; import org.openide.util.Enumerations; +import org.openide.util.Utilities; import org.openide.util.test.MockLookup; /** Verify contracts needed by Netigso. @@ -159,7 +160,7 @@ both = b; AlienModule am = (AlienModule)m2; - am.loader.l = new URLClassLoader(new URL[] { am.jar.toURI().toURL() }, m1.getClassLoader()); + am.loader.l = new URLClassLoader(new URL[] { Utilities.toURI(am.jar).toURL() }, m1.getClassLoader()); assertFalse("Finish without exception", m2.provides("false")); diff --git a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleFactoryTest.java b/o.n.bootstrap/test/unit/src/org/netbeans/ModuleFactoryTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleFactoryTest.java +++ b/o.n.bootstrap/test/unit/src/org/netbeans/ModuleFactoryTest.java @@ -54,6 +54,7 @@ import java.util.Set; import java.util.jar.JarFile; import java.util.jar.Manifest; +import org.openide.util.Utilities; import org.openide.util.test.MockLookup; /** @@ -89,7 +90,7 @@ File j1 = new File(jars, "simple-module.jar"); File j2 = new File(jars, "depends-on-simple-module.jar"); File j3 = new File(jars, "dep-on-two-modules.jar"); - URLClassLoader l = new URLClassLoader(new URL[] {j1.toURI().toURL(), j2.toURI().toURL()}); + URLClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(j1).toURL(), Utilities.toURI(j2).toURL()}); Manifest mani1, mani2; JarFile j = new JarFile(j1); try { diff --git a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java b/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java +++ b/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java @@ -823,8 +823,8 @@ } ClassLoader l = new URLClassLoader(new URL[] { // Order should be irrelevant: - jar.toURI().toURL(), - ljar.toURI().toURL(), + Utilities.toURI(jar).toURL(), + Utilities.toURI(ljar).toURL(), }); MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); @@ -2029,7 +2029,7 @@ File j1 = new File(jars, "simple-module.jar"); File j2 = new File(jars, "depends-on-simple-module.jar"); File j3 = new File(jars, "dep-on-two-modules.jar"); - URLClassLoader l = new URLClassLoader(new URL[] {j1.toURI().toURL(), j2.toURI().toURL()}); + URLClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(j1).toURL(), Utilities.toURI(j2).toURL()}); Manifest mani1, mani2; JarFile j = new JarFile(j1); try { @@ -2648,7 +2648,7 @@ assertNotNull(modules); mgr.mutexPrivileged().enterWriteAccess(); try { - ClassLoader l = new URLClassLoader(new URL[] {mod1JAR.toURI().toURL(), mod2JAR.toURI().toURL()}); + ClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(mod1JAR).toURL(), Utilities.toURI(mod2JAR).toURL()}); Module mod1 = mgr.createFixed(loadManifest(mod1JAR), null, l); mgr.enable(mod1); assertEquals(l, mod1.getClassLoader()); diff --git a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleMixedOnClasspathTest.java b/o.n.bootstrap/test/unit/src/org/netbeans/ModuleMixedOnClasspathTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleMixedOnClasspathTest.java +++ b/o.n.bootstrap/test/unit/src/org/netbeans/ModuleMixedOnClasspathTest.java @@ -50,6 +50,7 @@ import java.util.jar.JarFile; import java.util.jar.Manifest; import org.openide.util.Lookup; +import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; import org.openide.util.lookup.ProxyLookup; @@ -97,7 +98,7 @@ File j1 = new File(jars, "simple-module.jar"); File j2 = new File(jars, "depends-on-simple-module.jar"); File j3 = new File(jars, "dep-on-two-modules.jar"); - URLClassLoader l = new URLClassLoader(new URL[] {j1.toURI().toURL()}); + URLClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(j1).toURL()}); Manifest mani1, mani2; JarFile j = new JarFile(j1); try { diff --git a/o.n.bootstrap/test/unit/src/org/netbeans/ProxyClassLoaderTest.java b/o.n.bootstrap/test/unit/src/org/netbeans/ProxyClassLoaderTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/ProxyClassLoaderTest.java +++ b/o.n.bootstrap/test/unit/src/org/netbeans/ProxyClassLoaderTest.java @@ -55,6 +55,7 @@ import org.fakepkg.FakeIfceHidden; import org.openide.util.Enumerations; import org.openide.util.Exceptions; +import org.openide.util.Utilities; public class ProxyClassLoaderTest extends SetupHid { @@ -252,11 +253,11 @@ } File j1 = new File(jars, "simple-module.jar"); - ClassLoader l1 = new URLClassLoader(new URL[] { j1.toURI().toURL() }); + ClassLoader l1 = new URLClassLoader(new URL[] { Utilities.toURI(j1).toURL() }); Loader loader = new Loader("org.bar", "org.fakepkg"); File jar = new File(jars, "depends-on-simple-module.jar"); - loader.l = new URLClassLoader(new URL[] { jar.toURI().toURL() }, l1); + loader.l = new URLClassLoader(new URL[] { Utilities.toURI(jar).toURL() }, l1); Class clazz = loader.loadClass("org.bar.SomethingElse"); diff --git a/o.n.bootstrap/test/unit/src/org/netbeans/ProxyURLStreamHandlerFactoryTest.java b/o.n.bootstrap/test/unit/src/org/netbeans/ProxyURLStreamHandlerFactoryTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/ProxyURLStreamHandlerFactoryTest.java +++ b/o.n.bootstrap/test/unit/src/org/netbeans/ProxyURLStreamHandlerFactoryTest.java @@ -79,7 +79,7 @@ return; } File uncFile = new File("\\\\computerName\\sharedFolder\\a\\b\\c\\d.txt"); - URI uri = uncFile.toURI(); + URI uri = Utilities.toURI(uncFile); String expectedURI = "file:////computerName/sharedFolder/a/b/c/d.txt"; assertEquals("Wrong URI from File.toURI.", expectedURI, uri.toString()); URL url = uri.toURL(); diff --git a/o.n.bootstrap/test/unit/src/org/netbeans/URLsAreEqualTest.java b/o.n.bootstrap/test/unit/src/org/netbeans/URLsAreEqualTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/URLsAreEqualTest.java +++ b/o.n.bootstrap/test/unit/src/org/netbeans/URLsAreEqualTest.java @@ -47,6 +47,7 @@ import java.util.Collections; import java.util.logging.Level; import org.netbeans.junit.NbTestCase; +import org.openide.util.Utilities; import org.openide.util.test.TestFileUtils; /** @@ -69,7 +70,7 @@ File jar = new File(wd, "default-package-resource.jar"); - URL orig = new URL("jar:" + jar.toURI() + "!/package/resource.txt"); + URL orig = new URL("jar:" + Utilities.toURI(jar) + "!/package/resource.txt"); URLConnection conn = orig.openConnection(); assertFalse("JDK connection: " + conn, conn.getClass().getName().startsWith("org.netbeans")); diff --git a/o.n.bootstrap/test/unit/src/org/netbeans/nbexec/NbExecPassesCorrectlyQuotedArgsTest.java b/o.n.bootstrap/test/unit/src/org/netbeans/nbexec/NbExecPassesCorrectlyQuotedArgsTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/nbexec/NbExecPassesCorrectlyQuotedArgsTest.java +++ b/o.n.bootstrap/test/unit/src/org/netbeans/nbexec/NbExecPassesCorrectlyQuotedArgsTest.java @@ -93,13 +93,13 @@ private void run(File workDir, String... args) throws Exception { URL u = Lookup.class.getProtectionDomain().getCodeSource().getLocation(); - File f = new File(u.toURI()); + File f = Utilities.toFile(u.toURI()); assertTrue("file found: " + f, f.exists()); File nbexec = Utilities.isWindows() ? new File(f.getParent(), "nbexec.exe") : new File(f.getParent(), "nbexec"); assertTrue("nbexec found: " + nbexec, nbexec.exists()); URL tu = MainCallback.class.getProtectionDomain().getCodeSource().getLocation(); - File testf = new File(tu.toURI()); + File testf = Utilities.toFile(tu.toURI()); assertTrue("file found: " + testf, testf.exists()); LinkedList allArgs = new LinkedList(Arrays.asList(args)); diff --git a/openide.filesystems/nbproject/project.xml b/openide.filesystems/nbproject/project.xml --- a/openide.filesystems/nbproject/project.xml +++ b/openide.filesystems/nbproject/project.xml @@ -54,7 +54,7 @@ - 8.10 + 8.25 diff --git a/openide.filesystems/src/org/openide/filesystems/FileUtil.java b/openide.filesystems/src/org/openide/filesystems/FileUtil.java --- a/openide.filesystems/src/org/openide/filesystems/FileUtil.java +++ b/openide.filesystems/src/org/openide/filesystems/FileUtil.java @@ -1008,7 +1008,7 @@ } if ((fileURL != null) && "file".equals(fileURL.getProtocol())) { - retVal = new File(URI.create(fileURL.toExternalForm())); + retVal = Utilities.toFile(URI.create(fileURL.toExternalForm())); } if (retVal != null) { retVal = normalizeFile(retVal); @@ -1061,13 +1061,7 @@ FileObject retVal = null; try { - URL url = file.toURI().toURL(); - - if ((url.getAuthority() != null) && - (Utilities.isWindows() || (Utilities.getOperatingSystem() == Utilities.OS_OS2))) { - return null; - } - + URL url = Utilities.toURI(file).toURL(); retVal = URLMapper.findFileObject(url); /*probably temporary piece of code to catch the cause of #46630*/ @@ -1111,15 +1105,7 @@ } try { - URL url = (file.toURI().toURL()); - - if ( - (url.getAuthority() != null) && - (Utilities.isWindows() || (Utilities.getOperatingSystem() == Utilities.OS_OS2)) - ) { - return null; - } - + URL url = (Utilities.toURI(file).toURL()); retVal = URLMapper.findFileObjects(url); } catch (MalformedURLException e) { retVal = null; @@ -1815,7 +1801,7 @@ private static File normalizeFileOnUnixAlike(File file) { // On Unix, do not want to traverse symlinks. // URI.normalize removes ../ and ./ sequences nicely. - file = new File(file.toURI().normalize()).getAbsoluteFile(); + file = Utilities.toFile(Utilities.toURI(file).normalize()).getAbsoluteFile(); while (file.getAbsolutePath().startsWith("/../")) { // NOI18N file = new File(file.getAbsolutePath().substring(3)); } @@ -1831,7 +1817,7 @@ try { // URI.normalize removes ../ and ./ sequences nicely. - File absoluteFile = new File(file.toURI().normalize()); + File absoluteFile = Utilities.toFile(Utilities.toURI(file).normalize()); File canonicalFile = file.getCanonicalFile(); String absolutePath = absoluteFile.getAbsolutePath(); if (absolutePath.equals("/..")) { // NOI18N @@ -2162,7 +2148,7 @@ do { wasDir = entry.isDirectory(); LOG.finest("urlForArchiveOrDir:toURI:entry"); //NOI18N - u = entry.toURI().toURL(); + u = Utilities.toURI(entry).toURL(); isDir = entry.isDirectory(); } while (wasDir ^ isDir); if (isArchiveFile(u) || entry.isFile() && entry.length() < 4) { @@ -2197,9 +2183,9 @@ public static File archiveOrDirForURL(URL entry) { String u = entry.toString(); if (u.startsWith("jar:file:") && u.endsWith("!/")) { // NOI18N - return new File(URI.create(u.substring(4, u.length() - 2))); + return Utilities.toFile(URI.create(u.substring(4, u.length() - 2))); } else if (u.startsWith("file:")) { // NOI18N - return new File(URI.create(u)); + return Utilities.toFile(URI.create(u)); } else { return null; } diff --git a/openide.filesystems/src/org/openide/filesystems/URLMapper.java b/openide.filesystems/src/org/openide/filesystems/URLMapper.java --- a/openide.filesystems/src/org/openide/filesystems/URLMapper.java +++ b/openide.filesystems/src/org/openide/filesystems/URLMapper.java @@ -64,6 +64,7 @@ import org.openide.util.Lookup; import org.openide.util.LookupEvent; import org.openide.util.LookupListener; +import org.openide.util.Utilities; /** Mapper from FileObject -> URL. * Should be registered in default lookup. For details see {@link Lookup#getDefault()}. @@ -421,7 +422,7 @@ // XXX clumsy; see ArchiveURLMapper for possible cleaner style String toReplace = "__EXCLAMATION_REPLACEMENT__";//NOI18N retURL = new URL( - "jar:" + new File(f,toReplace + fo.getPath()).toURI().toString().replaceFirst("/"+toReplace,"!/") + // NOI18N + "jar:" + Utilities.toURI(new File(f,toReplace + fo.getPath())).toString().replaceFirst("/"+toReplace,"!/") + // NOI18N ((fo.isFolder() && !fo.isRoot()) ? "/" : "") ); // NOI18N } catch (MalformedURLException mfx) { @@ -459,7 +460,7 @@ } private static URL toURL(File fFile, FileObject fo) throws MalformedURLException { - URL retVal = fFile.toURI().toURL(); + URL retVal = Utilities.toURI(fFile).toURL(); if (retVal != null && fo.isFolder()) { // #155742,160333 - URL for folder must always end with slash final String urlDef = retVal.toExternalForm(); @@ -528,7 +529,7 @@ try { URI uri = new URI(u.toExternalForm()); - return FileUtil.normalizeFile(new File(uri)); + return FileUtil.normalizeFile(Utilities.toFile(uri)); } catch (URISyntaxException use) { // malformed URL return null; diff --git a/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java b/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java --- a/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java +++ b/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java @@ -74,6 +74,7 @@ import org.openide.util.Enumerations; import org.openide.util.Exceptions; import org.openide.util.NbBundle; +import org.openide.util.Utilities; import org.openide.xml.XMLUtil; import org.xml.sax.Attributes; import org.xml.sax.InputSource; @@ -1119,7 +1120,7 @@ if ("file".equals(protocol)) { //NOI18N try { - File f = new File(URI.create(url.toExternalForm())); + File f = Utilities.toFile(URI.create(url.toExternalForm())); if (!f.equals(lastFile)) { lastFile = f; lastFileDate = new Date(f.lastModified()); diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/AttributesTestHidden.java b/openide.filesystems/test/unit/src/org/openide/filesystems/AttributesTestHidden.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/AttributesTestHidden.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/AttributesTestHidden.java @@ -48,6 +48,7 @@ import java.util.*; import java.io.*; import java.lang.reflect.Method; +import org.openide.util.Utilities; /** * @@ -305,7 +306,7 @@ ).getBytes()); fos.close(); - XMLFileSystem xfs = new XMLFileSystem(f.toURI().toURL()); + XMLFileSystem xfs = new XMLFileSystem(Utilities.toURI(f).toURL()); FileObject template = xfs.findResource("Templates/Other/special"); assertNotNull("template found", template); FileObject foTested = testedFS.getRoot().createData("copiedTemplate"); diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java b/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java @@ -188,12 +188,12 @@ } private void assertCorrectURL(String filename, String expectedURLPrefix, String expectedURLSuffix) throws Exception { File d = getWorkDir(); - assertEquals(expectedURLSuffix == null ? null : new URL(expectedURLPrefix + d.toURI() + expectedURLSuffix), + assertEquals(expectedURLSuffix == null ? null : new URL(expectedURLPrefix + Utilities.toURI(d) + expectedURLSuffix), FileUtil.urlForArchiveOrDir(new File(d, filename))); } private void assertCorrectFile(String expectedFilename, String urlPrefix, String urlSuffix) throws Exception { assertEquals(expectedFilename == null ? null : new File(getWorkDir(), expectedFilename), - FileUtil.archiveOrDirForURL(new URL(urlPrefix + getWorkDir().toURI() + urlSuffix))); + FileUtil.archiveOrDirForURL(new URL(urlPrefix + Utilities.toURI(getWorkDir()) + urlSuffix))); } /** Tests translation from jar resource url to jar archive url. */ @@ -262,7 +262,7 @@ }; log.addHandler(handler); try { - final boolean result = FileUtil.isArchiveFile(testFile.toURI().toURL()); + final boolean result = FileUtil.isArchiveFile(Utilities.toURI(testFile).toURL()); assertTrue("The test.jar should be archive.",result); //NOI18N } finally { log.removeHandler(handler); diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTestHidden.java b/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTestHidden.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTestHidden.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTestHidden.java @@ -182,7 +182,7 @@ } public void testIsArchiveFile() throws Exception { - final String base = getWorkDir().toURI().toURL().toExternalForm(); + final String base = Utilities.toURI(getWorkDir()).toURL().toExternalForm(); URL url = new URL(base + "test.jar"); //NOI18N assertTrue("test.jar has to be an archive", FileUtil.isArchiveFile(url)); //NOI18N url = new URL(base + ".hidden.jar"); //NOI18N diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/MultiFileObjectTestHid.java b/openide.filesystems/test/unit/src/org/openide/filesystems/MultiFileObjectTestHid.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/MultiFileObjectTestHid.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/MultiFileObjectTestHid.java @@ -49,6 +49,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.openide.util.Utilities; public class MultiFileObjectTestHid extends TestBaseHid { private static String[] resources = new String [] { @@ -235,7 +236,7 @@ + " \n" + " \n" + ""); - XMLFileSystem xml = new XMLFileSystem(f.toURI().toURL()); + XMLFileSystem xml = new XMLFileSystem(Utilities.toURI(f).toURL()); all.add(xml); mfs.setDelegates(all.toArray(new FileSystem[0])); diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/TestUtilHid.java b/openide.filesystems/test/unit/src/org/openide/filesystems/TestUtilHid.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/TestUtilHid.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/TestUtilHid.java @@ -57,6 +57,7 @@ import java.util.Iterator; import java.util.Map; import java.util.StringTokenizer; +import org.openide.util.Utilities; /** * @author rm111737 @@ -176,7 +177,7 @@ XMLFileSystem xfs = new XMLFileSystem (); try { - xfs.setXmlUrl(xmlFile.toURI().toURL()); + xfs.setXmlUrl(Utilities.toURI(xmlFile).toURL()); } catch (Exception ex) {} return xfs; diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/URLMapper50852Test.java b/openide.filesystems/test/unit/src/org/openide/filesystems/URLMapper50852Test.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/URLMapper50852Test.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/URLMapper50852Test.java @@ -50,6 +50,7 @@ import java.net.URL; import java.io.File; +import org.openide.util.Utilities; /** * Simulates issue 50852. @@ -76,7 +77,7 @@ */ protected void setUp() throws Exception { File workdir = getWorkDir(); - testURL = workdir.toURI().toURL(); + testURL = Utilities.toURI(workdir).toURL(); System.setProperty("org.openide.util.Lookup", "org.openide.filesystems.URLMapper50852Test$Lkp"); MAPPER_INSTANCE = new MyURLMapper (); Lkp lkp = (Lkp)org.openide.util.Lookup.getDefault(); diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/URLMapperTest.java b/openide.filesystems/test/unit/src/org/openide/filesystems/URLMapperTest.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/URLMapperTest.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/URLMapperTest.java @@ -57,6 +57,7 @@ import java.util.zip.CRC32; import java.util.zip.ZipEntry; import org.netbeans.junit.NbTestCase; +import org.openide.util.Utilities; /** * Test functionality of URLMapper. @@ -76,7 +77,7 @@ lfs.setRootDirectory(getWorkDir()); Repository.getDefault().addFileSystem(lfs); - URL uPlus = plus.toURI().toURL(); + URL uPlus = Utilities.toURI(plus).toURL(); FileObject fo = URLMapper.findFileObject(uPlus); assertNotNull("File object found", fo); assertEquals("plus+plus", fo.getNameExt()); @@ -116,7 +117,7 @@ FileObject rootFO = jfs.getRoot(); FileObject textFO = jfs.findResource(textPath); assertNotNull("JAR contains a/b.txt", textFO); - String rootS = "jar:" + jar.toURI() + "!/"; + String rootS = "jar:" + Utilities.toURI(jar) + "!/"; URL rootU = new URL(rootS); URL textU = new URL(rootS + textPath); assertEquals("correct FO -> URL for root", rootU, URLMapper.findURL(rootFO, URLMapper.EXTERNAL)); diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java b/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java @@ -62,6 +62,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import org.openide.util.Enumerations; +import org.openide.util.Utilities; public class XMLFileSystemTestHid extends TestBaseHid { /** Factory for all filesystems that want to use TCK in this class. @@ -106,7 +107,7 @@ resources = new String[] {"a/b/c","a/b1/c"}; - if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, createXMLLayer().toURI().toURL())) { + if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, Utilities.toURI(createXMLLayer()).toURL())) { // OK, unsupported return; } @@ -119,7 +120,7 @@ @Override protected void setUp() throws Exception { File f = createXMLLayer(); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); this.testedFS = xfs; this.allTestedFS = new FileSystem[] { xfs }; super.setUp(); @@ -151,13 +152,13 @@ - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertEquals ("Four bytes there", 4, fo.getSize ()); registerDefaultListener (fo); - if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURI().toURL())) { + if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, Utilities.toURI(f2).toURL())) { // OK, unsupported return; } @@ -190,13 +191,13 @@ - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertEquals ("Four bytes there", 4, fo.getSize ()); registerDefaultListener (fo); - if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURI().toURL())) { + if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, Utilities.toURI(f2).toURL())) { // OK, unsupported return; } @@ -230,13 +231,13 @@ - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertEquals("Old value is in the attribute", "old", fo.getAttribute("value")); registerDefaultListener (fo); - if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURI().toURL())) { + if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, Utilities.toURI(f2).toURL())) { // OK, unsupported return; } @@ -264,13 +265,13 @@ - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource("TestModule/sample.txt"); assertEquals("Four bytes there", 4, fo.getSize()); registerDefaultListener(fo); - if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURI().toURL())) { + if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, Utilities.toURI(f2).toURL())) { // OK, unsupported return; } @@ -300,7 +301,7 @@ f.lastModified() < f2.lastModified() ); } - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertNotNull(fo); assertEquals(fo.lastModified().getTime(), f.lastModified()); @@ -325,7 +326,7 @@ "\n" ); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertNotNull(fo); @@ -349,7 +350,7 @@ + " \n" + ""); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); final LocalFileSystem lfs = new LocalFileSystem(); lfs.setRootDirectory(getWorkDir()); MultiFileSystem mfs = new MultiFileSystem(lfs, xfs); @@ -376,7 +377,7 @@ ); Count.cnt = 0; - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); /** the following is a fake implementation of filesystem that * allows us to prevent calls to fileObject.getAttributes() */ @@ -499,7 +500,7 @@ "\n" ); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertNotNull(fo); @@ -524,7 +525,7 @@ "\n" ); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertNotNull(fo); @@ -549,7 +550,7 @@ "\n" ); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertNotNull(fo); @@ -579,11 +580,11 @@ "\n" ); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertNotNull(fo); - XMLFileSystem realXMLFS = new XMLFileSystem(f.toURI().toURL()); + XMLFileSystem realXMLFS = new XMLFileSystem(Utilities.toURI(f).toURL()); FileObject realfo = realXMLFS.findResource("TestModule/sample.txt"); assertNotNull(realfo); @@ -620,7 +621,7 @@ "\n" ); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); FileObject snd = xfs.findResource ("TestModule/snd.txt"); assertNotNull(fo); @@ -721,7 +722,7 @@ "\n" ); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertNotNull(fo); @@ -770,8 +771,8 @@ ) ); - URL url1 = new URL("jar:" + jar1.toURI() + "!/layer.xml"); - URL url2 = new URL("jar:" + jar2.toURI() + "!/layer.xml"); + URL url1 = new URL("jar:" + Utilities.toURI(jar1) + "!/layer.xml"); + URL url2 = new URL("jar:" + Utilities.toURI(jar2) + "!/layer.xml"); FileSystem xfs1 = FileSystemFactoryHid.createXMLSystem(getName(), this, url1); FileObject fo1 = xfs1.findResource("dir/file"); @@ -901,7 +902,7 @@ File f2 = changeOfAnAttributeInLayerIsFiredgenerateLayer("Folder", "java.awt.Button"); File f3 = changeOfAnAttributeInLayerIsFiredgenerateLayer("NoChange", "nochange"); - fs.setXmlUrls (new URL[] { f1.toURI().toURL(), f3.toURI().toURL() } ); + fs.setXmlUrls (new URL[] { Utilities.toURI(f1).toURL(), Utilities.toURI(f3).toURL() } ); FileObject file = fs.findResource("Folder/empty.xml"); assertNotNull("File found in layer", file); @@ -917,7 +918,7 @@ assertAttr("The first value is list", file, "value", "java.awt.List"); assertAttr("Imutable value is nochange", nochange, "value", "nochange"); - fs.setXmlUrls (new URL[] { f2.toURI().toURL(), f3.toURI().toURL() } ); + fs.setXmlUrls (new URL[] { Utilities.toURI(f2).toURL(), Utilities.toURI(f3).toURL() } ); String v2 = (String) file.getAttribute("value"); assertEquals("The second value is button", "java.awt.Button", v2); @@ -952,7 +953,7 @@ LocalFileSystem target = new LocalFileSystem(); target.setRootDirectory(r); - FileSystem source = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL()); + FileSystem source = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f).toURL()); FileObject template = source.findResource("Templates/Other/special"); assertNotNull("template found", template); FileObject foTested = target.getRoot().createData("copiedTemplate"); @@ -1077,7 +1078,7 @@ w.close(); } - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f1.toURI().toURL(), f2.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f1).toURL(), Utilities.toURI(f2).toURL()); FileObject just1 = xfs.findResource("just1/empty.xml"); @@ -1089,19 +1090,19 @@ String layers2 = layers(just2); String layersB = layers(both); - if (!layersR.contains(f1.toURI().toString())) { - fail("Missing " + f1.toURI().toString() + "\ninside: " + layersR); + if (!layersR.contains(Utilities.toURI(f1).toString())) { + fail("Missing " + Utilities.toURI(f1).toString() + "\ninside: " + layersR); } - if (!layersR.contains(f2.toURI().toString())) { - fail("Missing " + f2.toURI().toString() + "\ninside: " + layersR); + if (!layersR.contains(Utilities.toURI(f2).toString())) { + fail("Missing " + Utilities.toURI(f2).toString() + "\ninside: " + layersR); } - assertEquals(f1.toURI().toString(), layers1); - assertEquals(f2.toURI().toString(), layers2); - if (!layersB.contains(f1.toURI().toString())) { + assertEquals(Utilities.toURI(f1).toString(), layers1); + assertEquals(Utilities.toURI(f2).toString(), layers2); + if (!layersB.contains(Utilities.toURI(f1).toString())) { fail("Missing " + f1 + "\ninside: " + layersB); } - if (!layersB.contains(f2.toURI().toString())) { + if (!layersB.contains(Utilities.toURI(f2).toString())) { fail("Missing " + f2 + "\ninside: " + layersB); } } @@ -1119,7 +1120,7 @@ + ""); w.close(); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, layer.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(layer).toURL()); FileObject fo = xfs.findResource("f/empty.xml"); assertNotNull("File found", fo); @@ -1142,25 +1143,25 @@ File f1 = writeFile("layer1.xml", "\n" + "\n" + - "" + + "" + "\n" + "\n" ); File f2 = writeFile("layer2.xml", "\n" + "\n" + - "" + + "" + " " + "\n" + "\n" + "\n" ); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f2.toURI().toURL(), f1.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f2).toURL(), Utilities.toURI(f1).toURL()); FileObject fo = xfs.findResource("d/f"); assertNotNull(fo); assertEquals(6, fo.getSize()); - xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f1.toURI().toURL(), f2.toURI().toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, Utilities.toURI(f1).toURL(), Utilities.toURI(f2).toURL()); fo = xfs.findResource("d/f"); assertNotNull(fo); assertEquals(6, fo.getSize()); diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/annotations/LayerBuilderTest.java b/openide.filesystems/test/unit/src/org/openide/filesystems/annotations/LayerBuilderTest.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/annotations/LayerBuilderTest.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/annotations/LayerBuilderTest.java @@ -67,6 +67,7 @@ import org.netbeans.junit.NbTestCase; import org.openide.filesystems.FileObject; import org.openide.filesystems.XMLFileSystem; +import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; import org.openide.util.test.AnnotationProcessorTestUtils; import org.openide.util.test.TestFileUtils; @@ -303,12 +304,12 @@ File j = TestFileUtils.writeZipFile(new File(getWorkDir(), "cp.jar"), "other/x1:x1"); TestFileUtils.writeFile(new File(src, "p/resources/x2"), "x2"); ByteArrayOutputStream err = new ByteArrayOutputStream(); - boolean status = AnnotationProcessorTestUtils.runJavac(src, null, dest, new File[] {j, new File(LayerBuilderTest.class.getProtectionDomain().getCodeSource().getLocation().toURI())}, err); + boolean status = AnnotationProcessorTestUtils.runJavac(src, null, dest, new File[] {j, Utilities.toFile(LayerBuilderTest.class.getProtectionDomain().getCodeSource().getLocation().toURI())}, err); String msgs = err.toString(); assertTrue(msgs, status); assertTrue(msgs, msgs.contains("r1=x1") ^ AnnotationProcessorTestUtils.searchClasspathBroken()); assertTrue(msgs, msgs.contains("r2=x2")); - FileObject f = new XMLFileSystem(new File(dest, "META-INF/generated-layer.xml").toURI().toURL()).findResource("f"); + FileObject f = new XMLFileSystem(Utilities.toURI(new File(dest, "META-INF/generated-layer.xml")).toURL()).findResource("f"); assertNotNull(f); assertEquals("other/x1", f.getAttribute("r1")); assertEquals("p/resources/x2", f.getAttribute("r2")); @@ -319,14 +320,14 @@ File j = TestFileUtils.writeZipFile(new File(getWorkDir(), "cp.jar"), "other/x1:x1"); TestFileUtils.writeFile(new File(src, "p/resources/x2"), "x2"); ByteArrayOutputStream err = new ByteArrayOutputStream(); - boolean status = AnnotationProcessorTestUtils.runJavac(src, null, dest, new File[] {j, new File(LayerBuilderTest.class.getProtectionDomain().getCodeSource().getLocation().toURI())}, err); + boolean status = AnnotationProcessorTestUtils.runJavac(src, null, dest, new File[] {j, Utilities.toFile(LayerBuilderTest.class.getProtectionDomain().getCodeSource().getLocation().toURI())}, err); String msgs = err.toString(); assertFalse(msgs, status); assertTrue(msgs, msgs.contains("resourcez")); assertTrue(msgs, msgs.contains("r1=x1") ^ AnnotationProcessorTestUtils.searchClasspathBroken()); AnnotationProcessorTestUtils.makeSource(src, "p.C", "@" + V.class.getCanonicalName() + "(r1=\"othr/x1\", r2=\"resources/x2\") public class C {}"); err = new ByteArrayOutputStream(); - status = AnnotationProcessorTestUtils.runJavac(src, null, dest, new File[] {j, new File(LayerBuilderTest.class.getProtectionDomain().getCodeSource().getLocation().toURI())}, err); + status = AnnotationProcessorTestUtils.runJavac(src, null, dest, new File[] {j, Utilities.toFile(LayerBuilderTest.class.getProtectionDomain().getCodeSource().getLocation().toURI())}, err); msgs = err.toString(); assertFalse(msgs, status ^ AnnotationProcessorTestUtils.searchClasspathBroken()); assertTrue(msgs, msgs.contains("othr") ^ AnnotationProcessorTestUtils.searchClasspathBroken()); diff --git a/openide.loaders/nbproject/project.xml b/openide.loaders/nbproject/project.xml --- a/openide.loaders/nbproject/project.xml +++ b/openide.loaders/nbproject/project.xml @@ -154,7 +154,7 @@ - 8.4 + 8.25 diff --git a/openide.loaders/src/org/openide/loaders/DataFolder.java b/openide.loaders/src/org/openide/loaders/DataFolder.java --- a/openide.loaders/src/org/openide/loaders/DataFolder.java +++ b/openide.loaders/src/org/openide/loaders/DataFolder.java @@ -1488,7 +1488,7 @@ } try { URI uri = new URI(s); - File file = new File(uri); + File file = Utilities.toFile(uri); list.add( file ); } catch( java.net.URISyntaxException e ) { // malformed URI diff --git a/openide.loaders/src/org/openide/loaders/DataNode.java b/openide.loaders/src/org/openide/loaders/DataNode.java --- a/openide.loaders/src/org/openide/loaders/DataNode.java +++ b/openide.loaders/src/org/openide/loaders/DataNode.java @@ -658,7 +658,7 @@ } }); //linux - final String uriList = file.toURI().toString() + "\r\n"; + final String uriList = Utilities.toURI(file).toString() + "\r\n"; t.put( new ExTransferable.Single( createUriListFlavor() ) { public Object getData() { return uriList; diff --git a/openide.loaders/test/unit/src/org/openide/loaders/DataFolderPasteTypesTest.java b/openide.loaders/test/unit/src/org/openide/loaders/DataFolderPasteTypesTest.java --- a/openide.loaders/test/unit/src/org/openide/loaders/DataFolderPasteTypesTest.java +++ b/openide.loaders/test/unit/src/org/openide/loaders/DataFolderPasteTypesTest.java @@ -56,6 +56,7 @@ import org.openide.filesystems.LocalFileSystem; import org.openide.filesystems.Repository; import org.openide.nodes.Node; +import org.openide.util.Utilities; import org.openide.util.datatransfer.PasteType; public class DataFolderPasteTypesTest extends NbTestCase { @@ -119,7 +120,7 @@ DataFlavor flavor = new DataFlavor( "unsupported/flavor;class=java.lang.Object" ); FileObject testFO = FileUtil.createData( testFileSystem.getRoot(), "testFile.txt" ); File testFile = FileUtil.toFile( testFO ); - String uriList = testFile.toURI() + "\r\n"; + String uriList = Utilities.toURI(testFile) + "\r\n"; Transferable t = new MockTransferable( new DataFlavor[] {new DataFlavor("text/uri-list;class=java.lang.String")}, uriList ); DataFolder.FolderNode node = (DataFolder.FolderNode)folderNode; diff --git a/openide.loaders/test/unit/src/org/openide/loaders/DataShadowTest.java b/openide.loaders/test/unit/src/org/openide/loaders/DataShadowTest.java --- a/openide.loaders/test/unit/src/org/openide/loaders/DataShadowTest.java +++ b/openide.loaders/test/unit/src/org/openide/loaders/DataShadowTest.java @@ -191,7 +191,7 @@ //If masterfs isn't reachable - second test crucial for URL,File, FileObject conversions // not necessary to be able to convert - but at least no IllegalArgumentException is expected if ("file".equals(url.getProtocol())) { - new File (URI.create(url.toExternalForm())); + Utilities.toFile(URI.create(url.toExternalForm())); } } diff --git a/openide.loaders/test/unit/src/org/openide/loaders/DragAndDropDataNodeTest.java b/openide.loaders/test/unit/src/org/openide/loaders/DragAndDropDataNodeTest.java --- a/openide.loaders/test/unit/src/org/openide/loaders/DragAndDropDataNodeTest.java +++ b/openide.loaders/test/unit/src/org/openide/loaders/DragAndDropDataNodeTest.java @@ -55,6 +55,7 @@ import org.openide.nodes.Children; import org.netbeans.junit.*; import org.openide.filesystems.LocalFileSystem; +import org.openide.util.Utilities; public class DragAndDropDataNodeTest extends NbTestCase { @@ -89,7 +90,7 @@ assertTrue( t.isDataFlavorSupported( uriListFlavor ) ); String uriList = (String) t.getTransferData( uriListFlavor ); - assertEquals( tmpFile.toURI()+"\r\n", uriList ); + assertEquals( Utilities.toURI(tmpFile)+"\r\n", uriList ); } public void testClipboardCut() throws ClassNotFoundException, IOException, UnsupportedFlavorException { @@ -110,6 +111,6 @@ assertTrue( t.isDataFlavorSupported( uriListFlavor ) ); String uriList = (String) t.getTransferData( uriListFlavor ); - assertEquals( tmpFile.toURI()+"\r\n", uriList ); + assertEquals( Utilities.toURI(tmpFile)+"\r\n", uriList ); } } diff --git a/openide.util/apichanges.xml b/openide.util/apichanges.xml --- a/openide.util/apichanges.xml +++ b/openide.util/apichanges.xml @@ -51,6 +51,27 @@ Actions API + + + UNC-safe File / URI interconversion + + + + +

+ Use the Jackpot-format upgrade hint. +

+
+ +

+ Utilities gets new methods toURI(File) + and toFile(URI) which offer the UNC safety of NIO.2 + even on JDK 6. +

+
+ + +
Exit with status code diff --git a/openide.util/manifest.mf b/openide.util/manifest.mf --- a/openide.util/manifest.mf +++ b/openide.util/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.util OpenIDE-Module-Localizing-Bundle: org/openide/util/Bundle.properties -OpenIDE-Module-Specification-Version: 8.24 +OpenIDE-Module-Specification-Version: 8.25 diff --git a/openide.util/src/META-INF/upgrade/Utilities.hint b/openide.util/src/META-INF/upgrade/Utilities.hint new file mode 100644 --- /dev/null +++ b/openide.util/src/META-INF/upgrade/Utilities.hint @@ -0,0 +1,9 @@ +$f.toURI() :: $f instanceof java.io.File +=> +org.openide.util.Utilities.toURI($f) +;; + +new java.io.File($u) :: $u instanceof java.net.URI +=> +org.openide.util.Utilities.toFile($u) +;; diff --git a/openide.util/src/org/openide/util/Utilities.java b/openide.util/src/org/openide/util/Utilities.java --- a/openide.util/src/org/openide/util/Utilities.java +++ b/openide.util/src/org/openide/util/Utilities.java @@ -72,6 +72,7 @@ import java.lang.ref.ReferenceQueue; import java.lang.ref.SoftReference; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.MalformedURLException; @@ -3022,6 +3023,88 @@ new AsyncInitSupport(comp4Init, initJob); } + /** JDK 7 */ + private static Method fileToPath, pathToUri, pathsGet, pathToFile; + static { + try { + fileToPath = File.class.getMethod("toPath"); + } catch (NoSuchMethodException x) { + // fine, JDK 6 + } + if (fileToPath != null) { + try { + Class path = Class.forName("java.nio.file.Path"); + pathToUri = path.getMethod("toUri"); + pathsGet = Class.forName("java.nio.file.Paths").getMethod("get", URI.class); + pathToFile = path.getMethod("toFile"); + } catch (Exception x) { + throw new ExceptionInInitializerError(x); + } + } + } + + /** + * Converts a file to a URI while being safe for UNC paths. + * Unlike {@link File#toURI} the result works with {@link URI#normalize()}. + * @param f a file + * @return a {@code file}-protocol URI which may use the host field + * @see java.nio.file.Path.toUri + * @since 8.25 + */ + public static URI toURI(File f) { + if (fileToPath != null) { + try { + return (URI) pathToUri.invoke(fileToPath.invoke(f)); + } catch (Exception x) { + LOG.log(Level.WARNING, "could not convert " + f + " to URI", x); + } + } + String path = f.getAbsolutePath(); + if (path.startsWith("\\\\")) { // UNC + if (!path.endsWith("\\") && f.isDirectory()) { + path += "\\"; + } + try { + return new URI("file", null, path.replace('\\', '/'), null); + } catch (URISyntaxException x) { + LOG.log(Level.WARNING, "could not convert " + f + " to URI", x); + } + } + return f.toURI(); + } + + /** + * Converts a URI to a file while being safe for UNC paths. + * Unlike {@link File#File(URI)} UNC URIs with a host field are accepted. + * @param u a {@code file}-protocol URI which may use the host field + * @return a file + * @see java.nio.file.Paths.get(java.net.URI) + * @since 8.25 + */ + public static File toFile(URI u) throws IllegalArgumentException { + if (pathsGet != null) { + try { + return (File) pathToFile.invoke(pathsGet.invoke(null, u)); + } catch (InvocationTargetException x) { + Throwable cause = x.getCause(); + if (cause instanceof IllegalArgumentException) { + throw (IllegalArgumentException) cause; + } else if (cause instanceof UnsupportedOperationException || cause != null && cause.getClass().getName().equals("java.nio.file.FileSystemNotFoundException")) { + throw new IllegalArgumentException(cause); + } else { + LOG.log(Level.WARNING, "could not convert " + u + " to File", x); + } + } catch (Exception x) { + LOG.log(Level.WARNING, "could not convert " + u + " to File", x); + } + } + String host = u.getHost(); + if (host != null && !host.isEmpty() && "file".equals(u.getScheme())) { + return new File("\\\\" + host + u.getPath().replace('/', '\\')); + } + return new File(u); + } + /** * Convert a file to a matching file: URL. * @param f a file (absolute only) @@ -3030,7 +3113,7 @@ * @see #toFile * @see Issue #29711 * @since 3.26 - * @deprecated Use {@link File#toURI} and {@link URI#toURL} instead under JDK 1.4. + * @deprecated Use {@link #toURI} and {@link URI#toURL} instead under JDK 1.4. * ({@link File#toURL} is buggy in JDK 1.3 and the bugs are not fixed in JDK 1.4.) */ @Deprecated @@ -3043,7 +3126,7 @@ throw new IllegalArgumentException("Relative path: " + f); // NOI18N } - URI uri = f.toURI(); + URI uri = toURI(f); return uri.toURL(); } @@ -3059,7 +3142,7 @@ * @see #toURL * @see Issue #29711 * @since 3.26 - * @deprecated Use {@link URI#URI(String)} and {@link File#File(URI)} instead under JDK 1.4. + * @deprecated Use {@link URL#toURI} and {@link #toFile(URI)} instead under JDK 1.4. * (There was no proper equivalent under JDK 1.3.) */ @Deprecated @@ -3069,9 +3152,9 @@ } try { - URI uri = new URI(u.toExternalForm()); - - return new File(uri); + URI uri = u.toURI(); + + return toFile(uri); } catch (URISyntaxException use) { // malformed URL return null; diff --git a/openide.util/test/unit/src/org/netbeans/modules/openide/util/NbBundleProcessorTest.java b/openide.util/test/unit/src/org/netbeans/modules/openide/util/NbBundleProcessorTest.java --- a/openide.util/test/unit/src/org/netbeans/modules/openide/util/NbBundleProcessorTest.java +++ b/openide.util/test/unit/src/org/netbeans/modules/openide/util/NbBundleProcessorTest.java @@ -54,6 +54,7 @@ import org.openide.util.NbBundle.Messages; import org.openide.util.test.TestFileUtils; import static org.netbeans.modules.openide.util.Bundle.*; +import org.openide.util.Utilities; @Messages("k3=value #3") public class NbBundleProcessorTest extends NbTestCase { @@ -103,7 +104,7 @@ "public static final Object X = new Object() {public String toString() {return Bundle.k();}};", "}"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); - ClassLoader l = new URLClassLoader(new URL[] {dest.toURI().toURL()}); + ClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); assertEquals("v", l.loadClass("p.C").getField("X").get(null).toString()); } @@ -138,7 +139,7 @@ public void testPackageKeys() throws Exception { AnnotationProcessorTestUtils.makeSource(src, "p.package-info", "@org.openide.util.NbBundle.Messages(\"k=v\")", "package p;"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); - ClassLoader l = new URLClassLoader(new URL[] {dest.toURI().toURL()}); + ClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); Method m = l.loadClass("p.Bundle").getDeclaredMethod("k"); m.setAccessible(true); assertEquals("v", m.invoke(null)); @@ -230,17 +231,17 @@ AnnotationProcessorTestUtils.makeSource(src, "p.C2", "@org.openide.util.NbBundle.Messages(\"k2=v2\")", "public class C2 {public @Override String toString() {return Bundle.k2();}}"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); - ClassLoader l = new URLClassLoader(new URL[] {dest.toURI().toURL()}); + ClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); assertEquals("v1", l.loadClass("p.C1").newInstance().toString()); assertEquals("v2", l.loadClass("p.C2").newInstance().toString()); AnnotationProcessorTestUtils.makeSource(src, "p.C1", "@org.openide.util.NbBundle.Messages(\"k1=v3\")", "public class C1 {public @Override String toString() {return Bundle.k1();}}"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, "C1.java", dest, null, null)); - l = new URLClassLoader(new URL[] {dest.toURI().toURL()}); + l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); assertEquals("v3", l.loadClass("p.C1").newInstance().toString()); assertEquals("v2", l.loadClass("p.C2").newInstance().toString()); AnnotationProcessorTestUtils.makeSource(src, "p.C1", "@org.openide.util.NbBundle.Messages(\"k3=v4\")", "public class C1 {public @Override String toString() {return Bundle.k3();}}"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, "C1.java", dest, null, null)); - l = new URLClassLoader(new URL[] {dest.toURI().toURL()}); + l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); assertEquals("v4", l.loadClass("p.C1").newInstance().toString()); assertEquals("v2", l.loadClass("p.C2").newInstance().toString()); } @@ -251,7 +252,7 @@ AnnotationProcessorTestUtils.makeSource(src, "p.C3", "class C3 {C3() {new Runnable() {public @Override void run() {new Runnable() {public @Override void run() {}};}};}}"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); - ClassLoader l = new URLClassLoader(new URL[] {dest.toURI().toURL()}); + ClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); assertEquals("v1", l.loadClass("p.C1").newInstance().toString()); assertEquals("v2", l.loadClass("p.C2").newInstance().toString()); assertTrue(new File(dest, "p/C3.class").delete()); @@ -259,7 +260,7 @@ assertTrue(new File(dest, "p/C3$1$1.class").isFile()); AnnotationProcessorTestUtils.makeSource(src, "p.C1", "@org.openide.util.NbBundle.Messages(\"k1=v3\")", "public class C1 {public @Override String toString() {return Bundle.k1();}}"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, "C1.java", dest, null, null)); - l = new URLClassLoader(new URL[] {dest.toURI().toURL()}); + l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); assertEquals("v3", l.loadClass("p.C1").newInstance().toString()); assertEquals("v2", l.loadClass("p.C2").newInstance().toString()); } @@ -269,11 +270,11 @@ AnnotationProcessorTestUtils.makeSource(src, "p.package-info", "@org.openide.util.NbBundle.Messages(\"k2=v2\")", "package p;"); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null)); - ClassLoader l = new URLClassLoader(new URL[] {dest.toURI().toURL()}); + ClassLoader l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); assertEquals("v1v2", l.loadClass("p.C").newInstance().toString()); assertTrue(new File(dest, "p/C.class").delete()); assertTrue(AnnotationProcessorTestUtils.runJavac(src, "C.java", dest, null, null)); - l = new URLClassLoader(new URL[] {dest.toURI().toURL()}); + l = new URLClassLoader(new URL[] {Utilities.toURI(dest).toURL()}); assertEquals("v1v2", l.loadClass("p.C").newInstance().toString()); } diff --git a/openide.util/test/unit/src/org/openide/util/EditablePropertiesTest.java b/openide.util/test/unit/src/org/openide/util/EditablePropertiesTest.java --- a/openide.util/test/unit/src/org/openide/util/EditablePropertiesTest.java +++ b/openide.util/test/unit/src/org/openide/util/EditablePropertiesTest.java @@ -388,7 +388,7 @@ private String filenameOfTestProperties() { // #50987: never use URL.path for this purpose... - return new File(URI.create(EditablePropertiesTest.class.getResource("data/test.properties").toExternalForm())).getAbsolutePath(); + return Utilities.toFile(URI.create(EditablePropertiesTest.class.getResource("data/test.properties").toExternalForm())).getAbsolutePath(); } private EditableProperties loadTestProperties() throws IOException { diff --git a/openide.util/test/unit/src/org/openide/util/UtilitiesTest.java b/openide.util/test/unit/src/org/openide/util/UtilitiesTest.java --- a/openide.util/test/unit/src/org/openide/util/UtilitiesTest.java +++ b/openide.util/test/unit/src/org/openide/util/UtilitiesTest.java @@ -112,6 +112,7 @@ import java.awt.peer.TextFieldPeer; import java.awt.peer.WindowPeer; import java.io.File; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -380,6 +381,31 @@ } } + public void testFileURI() throws Exception { + if (Utilities.isWindows()) { + assertFileURI("C:\\some\\path #1", "file:/C:/some/path%20%231"); + assertEquals(new File("C:\\some\\path"), Utilities.toFile(new URI("file:/C:/some/path"))); + assertEquals(new File("C:\\some\\path"), Utilities.toFile(new URI("file:///C:/some/path"))); + assertEquals(new File("C:\\some\\path"), Utilities.toFile(new URI("file:/C:/some/path/"))); + assertFileURI("\\\\server\\share\\path", "file://server/share/path"); + assertEquals(new File("\\\\server\\share\\path"), Utilities.toFile(new URI("file:////server/share/path"))); + } else { + assertFileURI("/some/path #1", "file:/some/path%20%231"); + assertEquals(new File("/some/path"), Utilities.toFile(new URI("file:/some/path"))); + assertEquals(new File("/some/path"), Utilities.toFile(new URI("file:///some/path"))); + assertEquals(new File("/some/path"), Utilities.toFile(new URI("file:/some/path/"))); + } + String s = Utilities.toURI(getWorkDir()).toString(); + assertTrue(s, s.endsWith("/")); + // XXX test that IllegalArgumentException is thrown where appropriate + } + private static void assertFileURI(String file, String uri) throws Exception { + URI u = new URI(uri); + File f = new File(file); + assertEquals(u, Utilities.toURI(f)); + assertEquals(f, Utilities.toFile(u)); + } + private static class CustomToolkitComponent extends Component { private Toolkit customToolkit; diff --git a/openide.util/test/unit/src/org/openide/xml/XMLUtilTest.java b/openide.util/test/unit/src/org/openide/xml/XMLUtilTest.java --- a/openide.util/test/unit/src/org/openide/xml/XMLUtilTest.java +++ b/openide.util/test/unit/src/org/openide/xml/XMLUtilTest.java @@ -59,6 +59,7 @@ import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import org.netbeans.junit.NbTestCase; +import org.openide.util.Utilities; import org.openide.util.test.TestFileUtils; import org.w3c.dom.CDATASection; import org.w3c.dom.Document; @@ -454,7 +455,7 @@ File ent = new File(d, "ent.xml"); TestFileUtils.writeFile(main, "]> &ent;"); TestFileUtils.writeFile(ent, "there"); - Document doc = XMLUtil.parse(new InputSource(main.toURI().toString()), false, true, null, null); + Document doc = XMLUtil.parse(new InputSource(Utilities.toURI(main).toString()), false, true, null, null); XMLUtil.validate(doc.getDocumentElement(), s); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLUtil.write(doc, baos, "UTF-8"); @@ -467,7 +468,7 @@ // XXX #160806 reported a problem with "xml:base" being consider a no-NS attr; not yet caught by test // Try again with no xmlns specified in entity; should inherit from main.xml: TestFileUtils.writeFile(ent, "there"); - doc = XMLUtil.parse(new InputSource(main.toURI().toString()), false, true, null, null); + doc = XMLUtil.parse(new InputSource(Utilities.toURI(main).toString()), false, true, null, null); XMLUtil.validate(doc.getDocumentElement(), s); baos = new ByteArrayOutputStream(); XMLUtil.write(doc, baos, "UTF-8"); diff --git a/parsing.api/nbproject/project.xml b/parsing.api/nbproject/project.xml --- a/parsing.api/nbproject/project.xml +++ b/parsing.api/nbproject/project.xml @@ -218,7 +218,7 @@ - 8.0 + 8.25
diff --git a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java --- a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java +++ b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java @@ -962,7 +962,7 @@ final File parentFile = FileUtil.toFile(newFile.getParent()); if (parentFile != null) { try { - URL oldBinaryRoot = new File (parentFile, oldNameExt).toURI().toURL(); + URL oldBinaryRoot = org.openide.util.Utilities.toURI(new File (parentFile, oldNameExt)).toURL(); eventQueue.record( FileEventLog.FileOp.DELETE, oldBinaryRoot, @@ -3010,7 +3010,7 @@ } try { if ("file".equals(tmp.getProtocol())) { //NOI18N - final File file = new File(new URI(tmp.toString())); + final File file = org.openide.util.Utilities.toFile(new URI(tmp.toString())); msg = file.getAbsolutePath(); } } catch (URISyntaxException ex) { @@ -4717,7 +4717,7 @@ if (packedIndex != null ) { unpack(packedIndex, downloadFolder); packedIndex.delete(); - if (patchDownloadedIndex(root,downloadFolder.toURI().toURL())) { + if (patchDownloadedIndex(root,org.openide.util.Utilities.toURI(downloadFolder).toURL())) { final FileObject df = CacheFolder.getDataFolder(root); assert df != null; final File dataFolder = FileUtil.toFile(df); @@ -5592,7 +5592,7 @@ if (sourcesListener != null) { if (!sourceRoots.containsKey(root) && root.getProtocol().equals("file")) { //NOI18N try { - File f = new File(root.toURI()); + File f = org.openide.util.Utilities.toFile(root.toURI()); safeAddRecursiveListener(sourcesListener, f, entry); sourceRoots.put(root, f); } catch (URISyntaxException use) { @@ -5608,7 +5608,7 @@ try { URI uri = archiveUrl != null ? archiveUrl.toURI() : root.toURI(); if (uri.getScheme().equals("file")) { //NOI18N - f = new File(uri); + f = org.openide.util.Utilities.toFile(uri); } } catch (URISyntaxException use) { LOGGER.log(Level.INFO, "Can't convert " + root + " to java.io.File; archiveUrl=" + archiveUrl, use); //NOI18N @@ -5669,7 +5669,7 @@ @Override public boolean accept(@NonNull final File pathname) { try { - return entry.includes(pathname.toURI().toURL()); + return entry.includes(org.openide.util.Utilities.toURI(pathname).toURL()); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); return true; diff --git a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/Util.java b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/Util.java --- a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/Util.java +++ b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/Util.java @@ -54,6 +54,7 @@ import org.netbeans.modules.editor.settings.storage.api.EditorSettings; import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; +import org.openide.util.Utilities; /** * @@ -158,7 +159,7 @@ final Boolean isDirectoryFin = isDirectory; // Performance optimization for File.toURI() which calls this method // and the original implementation calls into native method - return new File(new File(root.toURI()), relativePath) { + return Utilities.toURI(new File(Utilities.toFile(root.toURI()), relativePath) { @Override public File getAbsoluteFile() { @@ -175,7 +176,7 @@ super.isDirectory() : isDirectoryFin; } - }.toURI().toURL(); + }).toURL(); } else { return new URL(root, relativePath); } diff --git a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java --- a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java +++ b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java @@ -310,7 +310,7 @@ } URI rootURI = root.toURI(); File cacheRoot = getCacheRoot(root); - URI cacheRootURI = cacheRoot.toURI(); + URI cacheRootURI = org.openide.util.Utilities.toURI(cacheRoot); Queue todo = new LinkedList(); todo.add(cacheRoot); @@ -322,13 +322,13 @@ if (f.isFile()) { if (f.getName().endsWith(ERR_EXT)) { - String relative = cacheRootURI.relativize(f.toURI()).getRawPath(); + String relative = cacheRootURI.relativize(org.openide.util.Utilities.toURI(f)).getRawPath(); relative = relative.replaceAll("." + ERR_EXT + "$", ""); //NOI18N result.add(rootURI.resolve(relative).toURL()); } if (!onlyErrors && f.getName().endsWith(WARN_EXT)) { - String relative = cacheRootURI.relativize(f.toURI()).getRawPath(); + String relative = cacheRootURI.relativize(org.openide.util.Utilities.toURI(f)).getRawPath(); relative = relative.replaceAll("." + WARN_EXT + "$", ""); //NOI18N result.add(rootURI.resolve(relative).toURL()); diff --git a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/lucene/DocumentBasedIndexManager.java b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/lucene/DocumentBasedIndexManager.java --- a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/lucene/DocumentBasedIndexManager.java +++ b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/lucene/DocumentBasedIndexManager.java @@ -53,6 +53,7 @@ import org.netbeans.modules.parsing.lucene.support.DocumentIndex; import org.netbeans.modules.parsing.lucene.support.IndexManager; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * @@ -102,7 +103,7 @@ switch (mode) { case CREATE: { - final File file = new File(root.toURI()); + final File file = Utilities.toFile(root.toURI()); file.mkdir(); li = IndexManager.createDocumentIndex(file); indexes.put(root,li); @@ -110,7 +111,7 @@ } case IF_EXIST: { - final File file = new File(root.toURI()); + final File file = Utilities.toFile(root.toURI()); String[] children; if (file.isDirectory() && (children=file.list())!= null && children.length > 0) { li = IndexManager.createDocumentIndex(file); diff --git a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/lucene/LuceneIndexFactory.java b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/lucene/LuceneIndexFactory.java --- a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/lucene/LuceneIndexFactory.java +++ b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/lucene/LuceneIndexFactory.java @@ -58,6 +58,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * @@ -124,7 +125,7 @@ assert indexFolder != null; final String indexVersion = Integer.toString(VERSION); final File luceneIndexFolder = new File (FileUtil.toFile(indexFolder),indexVersion); - URL result = luceneIndexFolder.toURI().toURL(); + URL result = Utilities.toURI(luceneIndexFolder).toURL(); final String surl = result.toExternalForm(); if (surl.charAt(surl.length()-1) != '/') { //NOI18N result = new URL(surl+'/'); //NOI18N diff --git a/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/event/EventSupportTest.java b/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/event/EventSupportTest.java --- a/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/event/EventSupportTest.java +++ b/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/event/EventSupportTest.java @@ -46,6 +46,7 @@ import org.netbeans.junit.NbTestCase; import org.netbeans.modules.parsing.api.indexing.IndexingManager; import org.netbeans.modules.parsing.impl.indexing.IndexingManagerAccessor; +import org.openide.util.Utilities; /** * @@ -75,7 +76,7 @@ final File src = new File (wd,"src"); src.mkdirs(); try { - IndexingManager.getDefault().refreshIndexAndWait(src.toURI().toURL(), null); + IndexingManager.getDefault().refreshIndexAndWait(Utilities.toURI(src).toURL(), null); } catch (IllegalStateException ae) { assertTrue("IllegalStateException not expected when EventSupport.releaseCompletionCondition called by IndexingManager.refreshIndexAndWait", false); } diff --git a/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/ArchiveTimeStampsTest.java b/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/ArchiveTimeStampsTest.java --- a/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/ArchiveTimeStampsTest.java +++ b/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/ArchiveTimeStampsTest.java @@ -58,6 +58,7 @@ import org.netbeans.junit.NbTestCase; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -94,7 +95,7 @@ final File base = getWorkDir(); for (int i=1; i<=100; i++) { final File f = new File(base,String.format("archive%d.jar", i)); //NOI18N - final URL u = f.toURI().toURL(); + final URL u = Utilities.toURI(f).toURL(); final Pair,Integer>> state = Pair.,Integer>>of((long)i,indexers); expected.put(u, state); @@ -132,7 +133,7 @@ final File base = getWorkDir(); for (int i=1; i<=100; i++) { final File f = new File(base,String.format("archive%d.jar", i)); //NOI18N - final URL u = f.toURI().toURL(); + final URL u = Utilities.toURI(f).toURL(); final Pair,Integer>> state = Pair.,Integer>>of((long)i,indexers); expected.put(u, state); @@ -177,7 +178,7 @@ File f = new File(base,String.format("ar_bs.jar")); //NOI18N Pair,Integer>> state = Pair.,Integer>>of(1L,indexers); - URL u = f.toURI().toURL(); + URL u = Utilities.toURI(f).toURL(); expected.put(u, state); ArchiveTimeStamps.setLastModified(u,state); } catch (IOException e) { @@ -194,7 +195,7 @@ File f = new File(base,String.format("ar_as.jar")); //NOI18N Pair,Integer>> state = Pair.,Integer>>of(1L,indexers); - URL u = f.toURI().toURL(); + URL u = Utilities.toURI(f).toURL(); expected.put(u, state); ArchiveTimeStamps.setLastModified(u,state); } catch (IOException e) { @@ -208,7 +209,7 @@ File f = new File(base,String.format("start.jar")); //NOI18N Pair,Integer>> state = Pair.,Integer>>of(1L,indexers); - URL u = f.toURI().toURL(); + URL u = Utilities.toURI(f).toURL(); expected.put(u, state); h.last = true; ArchiveTimeStamps.setLastModified(u,state); diff --git a/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdaterTest.java b/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdaterTest.java --- a/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdaterTest.java +++ b/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdaterTest.java @@ -543,7 +543,7 @@ handler.reset(); indexerFactory.indexer.setExpectedFile(new URL[0], new URL[0], new URL[0]); eindexerFactory.indexer.setExpectedFile(new URL[0],new URL[0], new URL[0]); - File file = new File (embeddedFiles[0].toURI()); + File file = org.openide.util.Utilities.toFile(embeddedFiles[0].toURI()); file.setLastModified(System.currentTimeMillis()); globalPathRegistry_register(SOURCES,new ClassPath[]{cp1}); assertTrue (handler.await()); @@ -561,9 +561,9 @@ handler.reset(); indexerFactory.indexer.setExpectedFile(new URL[0], new URL[0], new URL[0]); eindexerFactory.indexer.setExpectedFile(new URL[0],new URL[0], new URL[0]); - file = new File (embeddedFiles[0].toURI()); + file = org.openide.util.Utilities.toFile(embeddedFiles[0].toURI()); file.setLastModified(System.currentTimeMillis()); - file = new File (embeddedFiles[1].toURI()); + file = org.openide.util.Utilities.toFile(embeddedFiles[1].toURI()); file.delete(); srcRootWithFiles1.getFileSystem().refresh(true); @@ -631,7 +631,7 @@ final File container = f.getParentFile(); File newFile = new File (container,"c.emb"); indexerFactory.indexer.setExpectedFile(new URL[0], new URL[0], new URL[0]); - eindexerFactory.indexer.setExpectedFile(new URL[]{newFile.toURI().toURL()}, new URL[0], new URL[0]); + eindexerFactory.indexer.setExpectedFile(new URL[]{org.openide.util.Utilities.toURI(newFile).toURL()}, new URL[0], new URL[0]); assertNotNull(FileUtil.createData(newFile)); assertTrue(indexerFactory.indexer.awaitIndex(TIME)); assertTrue(eindexerFactory.indexer.awaitIndex()); @@ -644,7 +644,7 @@ newFile = new File (newFolder,"d.emb"); File newFile2 = new File (newFolder,"e.emb"); indexerFactory.indexer.setExpectedFile(new URL[0], new URL[0], new URL[0]); - eindexerFactory.indexer.setExpectedFile(new URL[]{newFile.toURI().toURL(), newFile2.toURI().toURL()}, new URL[0], new URL[0]); + eindexerFactory.indexer.setExpectedFile(new URL[]{org.openide.util.Utilities.toURI(newFile).toURL(), org.openide.util.Utilities.toURI(newFile2).toURL()}, new URL[0], new URL[0]); newFolder.mkdirs(); touchFile (newFile); touchFile (newFile2); @@ -978,14 +978,14 @@ File root = FileUtil.toFile(srcRootWithFiles1); File fdf = new File (root, "direct.emb"); //NOI18N - eindexerFactory.indexer.setExpectedFile(new URL[]{fdf.toURI().toURL()}, new URL[0], new URL[0]); + eindexerFactory.indexer.setExpectedFile(new URL[]{org.openide.util.Utilities.toURI(fdf).toURL()}, new URL[0], new URL[0]); FileObject df = FileUtil.createData(fdf); assertNotNull(df); assertEquals(EMIME, df.getMIMEType()); eindexerFactory.indexer.awaitIndex(); File newfdf = new File (root, "new_direct.emb"); //NOI18N - eindexerFactory.indexer.setExpectedFile(new URL[]{newfdf.toURI().toURL()}, new URL[]{fdf.toURI().toURL()}, new URL[0]); + eindexerFactory.indexer.setExpectedFile(new URL[]{org.openide.util.Utilities.toURI(newfdf).toURL()}, new URL[]{org.openide.util.Utilities.toURI(fdf).toURL()}, new URL[0]); FileLock lock = df.lock(); try { df.rename(lock, "new_direct", "emb"); @@ -1282,8 +1282,8 @@ final File a = new File(srcRoot1File,"folder/a.foo"); final File b = new File(srcRoot1File,"folder/b.emb"); - indexerFactory.indexer.setExpectedFile(new URL[]{a.toURI().toURL()}, new URL[0], new URL[0]); - eindexerFactory.indexer.setExpectedFile(new URL[]{b.toURI().toURL()}, new URL[0], new URL[0]); + indexerFactory.indexer.setExpectedFile(new URL[]{org.openide.util.Utilities.toURI(a).toURL()}, new URL[0], new URL[0]); + eindexerFactory.indexer.setExpectedFile(new URL[]{org.openide.util.Utilities.toURI(b).toURL()}, new URL[0], new URL[0]); FileUtil.runAtomicAction(new FileSystem.AtomicAction() { @Override public void run() throws IOException { @@ -2179,11 +2179,11 @@ //Unsee root - index should be donwloaded and no indexer should be called final URL rootURL = FileUtil.urlForArchiveOrDir(root); final ClassPath cp1 = ClassPathSupport.createClassPath(rootURL); - IndexDownloaderImpl.expect(rootURL, index.toURI().toURL()); + IndexDownloaderImpl.expect(rootURL, org.openide.util.Utilities.toURI(index).toURL()); indexerFactory.indexer.setExpectedFile( new URL[]{ - a.toURI().toURL(), - b.toURI().toURL()}, + org.openide.util.Utilities.toURI(a).toURL(), + org.openide.util.Utilities.toURI(b).toURL()}, new URL[0], new URL[0]); globalPathRegistry_register(SOURCES,new ClassPath[]{cp1}); @@ -2196,11 +2196,11 @@ touchFile(a); //Seen root - index should NOT be donwloaded and indexer should be called on modified file - IndexDownloaderImpl.expect(rootURL, index.toURI().toURL()); + IndexDownloaderImpl.expect(rootURL, org.openide.util.Utilities.toURI(index).toURL()); indexerFactory.indexer.setExpectedFile( new URL[]{ - a.toURI().toURL(), - b.toURI().toURL(), //Should be removed if timestamps maps + org.openide.util.Utilities.toURI(a).toURL(), + org.openide.util.Utilities.toURI(b).toURL(), //Should be removed if timestamps maps }, new URL[0], new URL[0]); @@ -2212,13 +2212,13 @@ //Simulate the index download error - indexer should be started globalPathRegistry_unregister(SOURCES, new ClassPath[]{cp1}); RepositoryUpdater.getDefault().waitUntilFinished(TIME); - FileObject fo = CacheFolder.getDataFolder(root.toURI().toURL()); + FileObject fo = CacheFolder.getDataFolder(org.openide.util.Utilities.toURI(root).toURL()); fo.delete(); - IndexDownloaderImpl.expect(rootURL, new File(workDir,"non_existent_index.zip").toURI().toURL()); + IndexDownloaderImpl.expect(rootURL, org.openide.util.Utilities.toURI(new File(workDir,"non_existent_index.zip")).toURL()); indexerFactory.indexer.setExpectedFile( new URL[]{ - a.toURI().toURL(), - b.toURI().toURL()}, + org.openide.util.Utilities.toURI(a).toURL(), + org.openide.util.Utilities.toURI(b).toURL()}, new URL[0], new URL[0]); globalPathRegistry_register(SOURCES,new ClassPath[]{cp1}); @@ -2229,14 +2229,14 @@ //Test DownloadedIndexPatcher - votes false -> IndexDownloader should be called and then Indexers should be called globalPathRegistry_unregister(SOURCES, new ClassPath[]{cp1}); RepositoryUpdater.getDefault().waitUntilFinished(TIME); - fo = CacheFolder.getDataFolder(root.toURI().toURL()); + fo = CacheFolder.getDataFolder(org.openide.util.Utilities.toURI(root).toURL()); fo.delete(); - IndexDownloaderImpl.expect(rootURL, index.toURI().toURL()); + IndexDownloaderImpl.expect(rootURL, org.openide.util.Utilities.toURI(index).toURL()); IndexPatcherImpl.expect(rootURL, false); indexerFactory.indexer.setExpectedFile( new URL[]{ - a.toURI().toURL(), - b.toURI().toURL()}, + org.openide.util.Utilities.toURI(a).toURL(), + org.openide.util.Utilities.toURI(b).toURL()}, new URL[0], new URL[0]); globalPathRegistry_register(SOURCES,new ClassPath[]{cp1}); @@ -2248,14 +2248,14 @@ //Test DownloadedIndexPatcher - votes true -> IndexDownloader should be called and NO Indexers should be called globalPathRegistry_unregister(SOURCES, new ClassPath[]{cp1}); RepositoryUpdater.getDefault().waitUntilFinished(TIME); - fo = CacheFolder.getDataFolder(root.toURI().toURL()); + fo = CacheFolder.getDataFolder(org.openide.util.Utilities.toURI(root).toURL()); fo.delete(); - IndexDownloaderImpl.expect(rootURL, index.toURI().toURL()); + IndexDownloaderImpl.expect(rootURL, org.openide.util.Utilities.toURI(index).toURL()); IndexPatcherImpl.expect(rootURL, true); indexerFactory.indexer.setExpectedFile( new URL[]{ - a.toURI().toURL(), - b.toURI().toURL()}, + org.openide.util.Utilities.toURI(a).toURL(), + org.openide.util.Utilities.toURI(b).toURL()}, new URL[0], new URL[0]); globalPathRegistry_register(SOURCES,new ClassPath[]{cp1}); @@ -2306,8 +2306,8 @@ File af = FileUtil.toFile(a); File anf = new File (af.getParentFile(),"an.foo"); //NOI18N indexerFactory.indexer.setExpectedFile( - new URL[]{anf.toURI().toURL()}, - new URL[]{af.toURI().toURL()}, + new URL[]{org.openide.util.Utilities.toURI(anf).toURL()}, + new URL[]{org.openide.util.Utilities.toURI(af).toURL()}, new URL[0]); FileLock l = a.lock(); try { @@ -2323,8 +2323,8 @@ File bf = FileUtil.toFile(b); File bnf = new File (bf.getParentFile(),"bn.foo"); //NOI18N indexerFactory.indexer.setExpectedFile( - new URL[]{bnf.toURI().toURL()}, - new URL[]{bf.toURI().toURL()}, + new URL[]{org.openide.util.Utilities.toURI(bnf).toURL()}, + new URL[]{org.openide.util.Utilities.toURI(bf).toURL()}, new URL[0]); l = b.lock(); try { diff --git a/parsing.lucene/nbproject/project.xml b/parsing.lucene/nbproject/project.xml --- a/parsing.lucene/nbproject/project.xml +++ b/parsing.lucene/nbproject/project.xml @@ -37,7 +37,7 @@ - 8.9 + 8.25 diff --git a/parsing.lucene/src/org/netbeans/modules/parsing/lucene/LuceneIndex.java b/parsing.lucene/src/org/netbeans/modules/parsing/lucene/LuceneIndex.java --- a/parsing.lucene/src/org/netbeans/modules/parsing/lucene/LuceneIndex.java +++ b/parsing.lucene/src/org/netbeans/modules/parsing/lucene/LuceneIndex.java @@ -974,7 +974,7 @@ private synchronized void hit() { if (!cachePolicy.hasMemCache()) { try { - final URL url = folder.toURI().toURL(); + final URL url = Utilities.toURI(folder).toURL(); IndexCacheFactory.getDefault().getCache().put(url, this); } catch (MalformedURLException e) { Exceptions.printStackTrace(e); diff --git a/project.ant/antsrc/org/netbeans/modules/project/ant/task/RegenerateFilesTask.java b/project.ant/antsrc/org/netbeans/modules/project/ant/task/RegenerateFilesTask.java --- a/project.ant/antsrc/org/netbeans/modules/project/ant/task/RegenerateFilesTask.java +++ b/project.ant/antsrc/org/netbeans/modules/project/ant/task/RegenerateFilesTask.java @@ -118,10 +118,10 @@ assert projectFO != null; } GeneratedFilesHelper h = new GeneratedFilesHelper(projectFO); - if (buildXsl != null && h.refreshBuildScript(GeneratedFilesHelper.BUILD_XML_PATH, buildXsl.toURI().toURL(), true)) { + if (buildXsl != null && h.refreshBuildScript(GeneratedFilesHelper.BUILD_XML_PATH, org.openide.util.Utilities.toURI(buildXsl).toURL(), true)) { log("Regenerating " + new File(projectDir, GeneratedFilesHelper.BUILD_XML_PATH.replace('/', File.separatorChar)).getAbsolutePath()); } - if (buildImplXsl != null && h.refreshBuildScript(GeneratedFilesHelper.BUILD_IMPL_XML_PATH, buildImplXsl.toURI().toURL(), true)) { + if (buildImplXsl != null && h.refreshBuildScript(GeneratedFilesHelper.BUILD_IMPL_XML_PATH, org.openide.util.Utilities.toURI(buildImplXsl).toURL(), true)) { log("Regenerating " + new File(projectDir, GeneratedFilesHelper.BUILD_IMPL_XML_PATH.replace('/', File.separatorChar)).getAbsolutePath()); } } catch (IOException e) { diff --git a/project.ant/nbproject/project.xml b/project.ant/nbproject/project.xml --- a/project.ant/nbproject/project.xml +++ b/project.ant/nbproject/project.xml @@ -170,7 +170,7 @@ - 8.4 + 8.25 diff --git a/project.ant/src/org/netbeans/api/project/ant/AntArtifact.java b/project.ant/src/org/netbeans/api/project/ant/AntArtifact.java --- a/project.ant/src/org/netbeans/api/project/ant/AntArtifact.java +++ b/project.ant/src/org/netbeans/api/project/ant/AntArtifact.java @@ -61,6 +61,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Utilities; // XXX may also need displayName field (any default? or only in SimpleAntArtifact?) @@ -199,7 +200,7 @@ URL artifact; try { // XXX this should probably use something in PropertyUtils? - artifact = getScriptLocation().toURI().resolve(artifactLocation).normalize().toURL(); + artifact = Utilities.toURI(getScriptLocation()).resolve(artifactLocation).normalize().toURL(); } catch (MalformedURLException e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); return null; @@ -254,7 +255,7 @@ * @return the associated project, or null if there is none or it could not be located */ public Project getProject() { - return FileOwnerQuery.getOwner(getScriptLocation().toURI()); + return FileOwnerQuery.getOwner(Utilities.toURI(getScriptLocation())); } /** diff --git a/project.ant/src/org/netbeans/api/project/ant/FileChooser.java b/project.ant/src/org/netbeans/api/project/ant/FileChooser.java --- a/project.ant/src/org/netbeans/api/project/ant/FileChooser.java +++ b/project.ant/src/org/netbeans/api/project/ant/FileChooser.java @@ -54,6 +54,7 @@ import org.netbeans.modules.project.ant.ProjectLibraryProvider; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** @@ -82,7 +83,7 @@ if (lm != null) { URL u = lm.getLocation(); if (u != null) { - File libBase = new File(URI.create(u.toExternalForm())).getParentFile(); + File libBase = Utilities.toFile(URI.create(u.toExternalForm())).getParentFile(); accessory = new FileChooserAccessory(this, FileUtil.toFile(helper.getProjectDirectory()), libBase, copyAllowed); setAccessory(accessory); diff --git a/project.ant/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingleton.java b/project.ant/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingleton.java --- a/project.ant/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingleton.java +++ b/project.ant/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingleton.java @@ -335,7 +335,7 @@ } byte[] data = baos.toByteArray(); InputSource src = new InputSource(new ByteArrayInputStream(data)); - src.setSystemId(projectDiskFile.toURI().toString()); + src.setSystemId(Utilities.toURI(projectDiskFile).toString()); try { // Document projectXml = XMLUtil.parse(src, false, true, Util.defaultErrorHandler(), null); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); diff --git a/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.java b/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.java --- a/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.java +++ b/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.java @@ -69,6 +69,7 @@ import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; +import org.openide.util.Utilities; /** * Accessory allowing to choose how file is referenced from a project - relative @@ -343,7 +344,7 @@ private boolean areCollocated(File base, Collection files){ for(File file: files){ - if (!CollocationQuery.areCollocated(base.toURI(), file.toURI())) { + if (!CollocationQuery.areCollocated(Utilities.toURI(base), Utilities.toURI(file))) { return false; } } diff --git a/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java b/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java --- a/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java +++ b/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java @@ -223,7 +223,7 @@ public ProjectLibraryArea loadArea(URL location) { if (location.getProtocol().equals("file") && location.getPath().endsWith(".properties")) { // NOI18N try { - return new ProjectLibraryArea(new File(location.toURI())); + return new ProjectLibraryArea(Utilities.toFile(location.toURI())); } catch (URISyntaxException x) { Exceptions.printStackTrace(x); } @@ -367,7 +367,7 @@ } } } - ProjectLibraryArea pla = loadArea(pli.mainPropertiesFile.toURI().toURL()); + ProjectLibraryArea pla = loadArea(Utilities.toURI(pli.mainPropertiesFile).toURL()); if (pla != null) { LP lp = getLibraries(pla); if (lp.libraries.remove(pli.name) != null) { @@ -527,7 +527,7 @@ File normalizedFile = FileUtil.normalizeFile(new File(component.replace('/', File.separatorChar).replace('\\', File.separatorChar).replace("${base}", area.mainPropertiesFile.getParent()))); try { URI u = LibrariesSupport.convertFilePathToURI(f); - if (FileUtil.isArchiveFile(normalizedFile.toURI().toURL())) { + if (FileUtil.isArchiveFile(Utilities.toURI(normalizedFile).toURL())) { u = appendJarFolder(u, jarFolder); } else if (!u.getPath().endsWith("/")) { // NOI18N u = new URI(u.toString() + "/"); // NOI18N @@ -739,7 +739,7 @@ List resolvedUrls = new ArrayList(uris.size()); for (URI u : uris) { try { - resolvedUrls.add(LibrariesSupport.resolveLibraryEntryURI(mainPropertiesFile.toURI().toURL(), u).toURL()); + resolvedUrls.add(LibrariesSupport.resolveLibraryEntryURI(Utilities.toURI(mainPropertiesFile).toURL(), u).toURL()); } catch (MalformedURLException ex) { Logger.getLogger(ProjectLibraryProvider.class.getName()).log(Level.INFO, "#184304: " + u, ex); } @@ -919,7 +919,7 @@ public URL getLocation() { try { - return mainPropertiesFile.toURI().toURL(); + return Utilities.toURI(mainPropertiesFile).toURL(); } catch (MalformedURLException x) { throw new AssertionError(x); } @@ -1085,7 +1085,7 @@ Definitions defs = findDefinitions(helper); if (defs != null) { try { - return LibraryManager.forLocation(defs.mainPropertiesFile.toURI().toURL()); + return LibraryManager.forLocation(Utilities.toURI(defs.mainPropertiesFile).toURL()); } catch (MalformedURLException x) { Exceptions.printStackTrace(x); } @@ -1149,7 +1149,7 @@ */ public static Library copyLibrary(final Library lib, final URL location, final boolean generateLibraryUniqueName) throws IOException { - final File libBaseFolder = new File(URI.create(location.toExternalForm())).getParentFile(); + final File libBaseFolder = Utilities.toFile(URI.create(location.toExternalForm())).getParentFile(); FileObject sharedLibFolder = null; final Map> content = new HashMap>(); String[] volumes = LibrariesSupport.getLibraryTypeProvider(lib.getType()).getSupportedVolumeTypes(); @@ -1178,7 +1178,7 @@ URI u; FileObject newFO; String name; - if (CollocationQuery.areCollocated(libBaseFolder.toURI(), libEntryFO.toURI())) { + if (CollocationQuery.areCollocated(Utilities.toURI(libBaseFolder), libEntryFO.toURI())) { // if the jar/folder is in relation to the library folder (parent+child/same vcs) // don't replicate it but reference the original file. newFO = libEntryFO; diff --git a/project.ant/src/org/netbeans/modules/project/ant/StandardAntArtifactQueryImpl.java b/project.ant/src/org/netbeans/modules/project/ant/StandardAntArtifactQueryImpl.java --- a/project.ant/src/org/netbeans/modules/project/ant/StandardAntArtifactQueryImpl.java +++ b/project.ant/src/org/netbeans/modules/project/ant/StandardAntArtifactQueryImpl.java @@ -51,6 +51,7 @@ import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.spi.project.ant.AntArtifactProvider; import org.netbeans.spi.project.ant.AntArtifactQueryImplementation; +import org.openide.util.Utilities; /** * Standard implementation of {@link AntArtifactQueryImplementation} which uses @@ -64,7 +65,7 @@ public StandardAntArtifactQueryImpl() {} public AntArtifact findArtifact(File file) { - Project p = FileOwnerQuery.getOwner(file.toURI()); + Project p = FileOwnerQuery.getOwner(Utilities.toURI(file)); if (p == null) { return null; } @@ -76,7 +77,7 @@ for (int i = 0; i < artifacts.length; i++) { URI uris[] = artifacts[i].getArtifactLocations(); for (int y = 0; y < uris.length; y++) { - File testFile = new File(artifacts[i].getScriptLocation().toURI().resolve(uris[y])); + File testFile = Utilities.toFile(Utilities.toURI(artifacts[i].getScriptLocation()).resolve(uris[y])); if (file.equals(testFile)) { return artifacts[i]; } diff --git a/project.ant/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java b/project.ant/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java --- a/project.ant/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java +++ b/project.ant/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java @@ -92,6 +92,7 @@ import org.openide.util.MutexException; import org.openide.util.RequestProcessor; import org.openide.util.UserQuestionException; +import org.openide.util.Utilities; import org.openide.util.WeakSet; import org.openide.xml.XMLUtil; import org.w3c.dom.Document; @@ -307,7 +308,7 @@ File f = FileUtil.toFile(xml); assert f != null; try { - Document doc = XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null); + Document doc = XMLUtil.parse(new InputSource(Utilities.toURI(f).toString()), false, true, XMLUtil.defaultErrorHandler(), null); ProjectXMLCatalogReader.validate(doc.getDocumentElement()); return doc; } catch (IOException e) { @@ -1205,7 +1206,7 @@ final SharabilityQueryImplementation2 sq2 = createSharabilityQuery2(eval, sourceRoots, buildDirectories); return new SharabilityQueryImplementation() { @Override public int getSharability(File file) { - return sq2.getSharability(file.toURI()).ordinal(); + return sq2.getSharability(Utilities.toURI(file)).ordinal(); } }; } diff --git a/project.ant/src/org/netbeans/spi/project/support/ant/GeneratedFilesHelper.java b/project.ant/src/org/netbeans/spi/project/support/ant/GeneratedFilesHelper.java --- a/project.ant/src/org/netbeans/spi/project/support/ant/GeneratedFilesHelper.java +++ b/project.ant/src/org/netbeans/spi/project/support/ant/GeneratedFilesHelper.java @@ -327,7 +327,7 @@ File projectXmlF = FileUtil.toFile(projectXml); assert projectXmlF != null; StreamSource projectXmlSource = new StreamSource( - new ByteArrayInputStream(projectXmlData), projectXmlF.toURI().toString()); + new ByteArrayInputStream(projectXmlData), Utilities.toURI(projectXmlF).toString()); ByteArrayOutputStream result = new ByteArrayOutputStream(); t.transform(projectXmlSource, new StreamResult(result)); if (BUILD_IMPL_XML_PATH.equals(path)) { diff --git a/project.ant/src/org/netbeans/spi/project/support/ant/PropertyUtils.java b/project.ant/src/org/netbeans/spi/project/support/ant/PropertyUtils.java --- a/project.ant/src/org/netbeans/spi/project/support/ant/PropertyUtils.java +++ b/project.ant/src/org/netbeans/spi/project/support/ant/PropertyUtils.java @@ -81,6 +81,7 @@ import org.openide.util.MutexException; import org.openide.util.NbCollections; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; /** * Support for working with Ant properties and property files. @@ -434,7 +435,7 @@ } b.append("../"); // NOI18N } - URI u = base.toURI().relativize(file.toURI()); + URI u = Utilities.toURI(base).relativize(Utilities.toURI(file)); assert !u.isAbsolute() : u + " from " + basedir + " and " + file + " with common root " + base; b.append(u.getPath()); if (b.charAt(b.length() - 1) == '/') { diff --git a/project.ant/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java b/project.ant/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java --- a/project.ant/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java +++ b/project.ant/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java @@ -83,6 +83,7 @@ import org.openide.util.Mutex; import org.openide.util.NbCollections; import org.openide.util.Parameters; +import org.openide.util.Utilities; import org.openide.xml.XMLUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -239,7 +240,7 @@ try { scriptLocation = new URI(null, null, rel, null); } catch (URISyntaxException ex) { - scriptLocation = forProjDir.toURI().relativize(scriptFile.toURI()); + scriptLocation = Utilities.toURI(forProjDir).relativize(Utilities.toURI(scriptFile)); } ref = new RawReference(forProjName, artifact.getType(), scriptLocation, artifact.getTargetName(), artifact.getCleanTargetName(), artifact.getID()); } else { @@ -270,7 +271,7 @@ URI artFile = location; String refPath; if (artFile.isAbsolute()) { - refPath = new File(artFile).getAbsolutePath(); + refPath = Utilities.toFile(artFile).getAbsolutePath(); propertiesFile = AntProjectHelper.PRIVATE_PROPERTIES_PATH; } else { refPath = "${" + forProjPathProp + "}/" + artFile.getPath(); // NOI18N @@ -1523,7 +1524,7 @@ FileUtil.toFile(p.getProjectDirectory())); if (libFile != null) { try { - return LibraryManager.forLocation(libFile.toURI().toURL()); + return LibraryManager.forLocation(Utilities.toURI(libFile).toURL()); } catch (MalformedURLException e) { // ok, no project manager Logger.getLogger(ReferenceHelper.class.getName()).info( @@ -1556,7 +1557,7 @@ return lib; } File mainPropertiesFile = h.resolveFile(h.getLibrariesLocation()); - return copyLibrary(lib, mainPropertiesFile.toURI().toURL()); + return copyLibrary(lib, Utilities.toURI(mainPropertiesFile).toURL()); } /** diff --git a/project.ant/src/org/netbeans/spi/project/support/ant/SharabilityQueryImpl.java b/project.ant/src/org/netbeans/spi/project/support/ant/SharabilityQueryImpl.java --- a/project.ant/src/org/netbeans/spi/project/support/ant/SharabilityQueryImpl.java +++ b/project.ant/src/org/netbeans/spi/project/support/ant/SharabilityQueryImpl.java @@ -53,6 +53,7 @@ import org.netbeans.api.queries.SharabilityQuery; import org.netbeans.modules.project.ant.ProjectLibraryProvider; import org.netbeans.spi.queries.SharabilityQueryImplementation2; +import org.openide.util.Utilities; import org.openide.util.WeakListeners; /** @@ -109,7 +110,7 @@ @Override public SharabilityQuery.Sharability getSharability(URI uri) { // XXX might be more efficient to precompute URIs for includePaths and excludePaths - String path = new File(uri).getAbsolutePath(); + String path = Utilities.toFile(uri).getAbsolutePath(); if (contains(path, excludePaths, false)) { return SharabilityQuery.Sharability.NOT_SHARABLE; } diff --git a/project.ant/src/org/netbeans/spi/project/support/ant/SimpleAntArtifact.java b/project.ant/src/org/netbeans/spi/project/support/ant/SimpleAntArtifact.java --- a/project.ant/src/org/netbeans/spi/project/support/ant/SimpleAntArtifact.java +++ b/project.ant/src/org/netbeans/spi/project/support/ant/SimpleAntArtifact.java @@ -51,6 +51,7 @@ import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton; import org.openide.ErrorManager; +import org.openide.util.Utilities; /** * A basic AntArtifact implementation. @@ -88,7 +89,7 @@ } File locF = new File(locationResolved); if (locF.isAbsolute()) { - return locF.toURI(); + return Utilities.toURI(locF); } else { // Project-relative path. try { diff --git a/project.ant/test/unit/src/org/netbeans/modules/project/ant/ProjectLibraryProviderTest.java b/project.ant/test/unit/src/org/netbeans/modules/project/ant/ProjectLibraryProviderTest.java --- a/project.ant/test/unit/src/org/netbeans/modules/project/ant/ProjectLibraryProviderTest.java +++ b/project.ant/test/unit/src/org/netbeans/modules/project/ant/ProjectLibraryProviderTest.java @@ -70,6 +70,7 @@ import org.openide.loaders.DataFolder; import org.openide.loaders.InstanceDataObject; import org.openide.util.NbCollections; +import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; import org.openide.util.test.MockChangeListener; import org.openide.util.test.MockLookup; @@ -95,14 +96,14 @@ protected void setUp() throws Exception { super.setUp(); libraryProvider = new TestLibraryProvider(); - MockLookup.setLookup(Lookups.fixed(AntBasedTestUtil.testAntBasedProjectType(), AntBasedTestUtil.testCollocationQueryImplementation(getWorkDir().toURI()), libraryProvider), + MockLookup.setLookup(Lookups.fixed(AntBasedTestUtil.testAntBasedProjectType(), AntBasedTestUtil.testCollocationQueryImplementation(Utilities.toURI(getWorkDir())), libraryProvider), // Filter out standard CQIs since they are bogus. Lookups.exclude(Lookups.metaInfServices(ProjectLibraryProviderTest.class.getClassLoader()), CollocationQueryImplementation.class)); projdir = TestUtil.makeScratchDir(this).createFolder("prj"); helper = ProjectGenerator.createProject(projdir, "test"); project = ProjectManager.getDefault().findProject(projdir); close(OpenProjects.getDefault().getOpenProjects()); - base = getWorkDir().toURI().toURL(); + base = Utilities.toURI(getWorkDir()).toURL(); ProjectLibraryProvider.FIRE_CHANGES_SYNCH = true; registerTestLibraryTypeProvider(); } @@ -396,7 +397,7 @@ } else { FileUtil.createData(f); } - assertEquals(mode, SharabilityQuery.getSharability(f.toURI())); + assertEquals(mode, SharabilityQuery.getSharability(Utilities.toURI(f))); } private void writeProperties(String path, String... properties) throws IOException { @@ -481,13 +482,13 @@ FileUtil.toFileObject(getWorkDir()).getFileSystem().refresh(false); LibraryImplementation l1 = LibrariesSupport.createLibraryImplementation("j2test", new String[]{"jars", "sources"}); l1.setName("vino"); - l1.setContent("jars", Arrays.asList(new URL[]{f.toURI().toURL(), f1.toURI().toURL()})); - l1.setContent("sources", Arrays.asList(new URL[]{new URL("jar:" + f2.toURI().toURL() + "!/docs/api/")})); + l1.setContent("jars", Arrays.asList(new URL[]{Utilities.toURI(f).toURL(), Utilities.toURI(f1).toURL()})); + l1.setContent("sources", Arrays.asList(new URL[]{new URL("jar:" + Utilities.toURI(f2).toURL() + "!/docs/api/")})); libraryProvider.set(l1); Library l = LibraryManager.getDefault().getLibrary("vino"); assertNotNull(l); assertEquals(LibraryManager.getDefault(), l.getManager()); - URL u = f3.toURI().toURL(); + URL u = Utilities.toURI(f3).toURL(); Library result = ProjectLibraryProvider.copyLibrary(l, u, false); assertNotNull(result); assertEquals(u, result.getManager().getLocation()); @@ -497,20 +498,20 @@ assertEquals("vino", result.getName()); assertEquals("j2test", result.getType()); //assertNotNull(LibrariesSupport.resolveLibraryEntryFileObject(u, result.getURIContent("jars").get(0))); - assertEquals("jar:"+(new File(this.getWorkDir(), "libraries/vino/bertie.jar").toURI().toString())+"!/", + assertEquals("jar:"+(Utilities.toURI(new File(this.getWorkDir(), "libraries/vino/bertie.jar")).toString())+"!/", LibrariesSupport.resolveLibraryEntryURI(u, result.getURIContent("jars").get(0)).toString()); - assertEquals("jar:"+(new File(this.getWorkDir(), "libraries/vino/bertie.jar").toURI().toString())+"!/", + assertEquals("jar:"+(Utilities.toURI(new File(this.getWorkDir(), "libraries/vino/bertie.jar")).toString())+"!/", result.getContent("jars").get(0).toExternalForm()); //assertNotNull(LibrariesSupport.resolveLibraryEntryFileObject(u, result.getContent("sources").get(0))); - assertEquals("jar:"+(new File(this.getWorkDir(), "libraries/vino/bertie-2.jar").toURI())+"!/docs/api/", + assertEquals("jar:"+(Utilities.toURI(new File(this.getWorkDir(), "libraries/vino/bertie-2.jar")))+"!/docs/api/", LibrariesSupport.resolveLibraryEntryURI(u, result.getURIContent("sources").get(0)).toString()); - assertEquals("jar:"+(new File(this.getWorkDir(), "libraries/vino/bertie-2.jar").toURI())+"!/docs/api/", + assertEquals("jar:"+(Utilities.toURI(new File(this.getWorkDir(), "libraries/vino/bertie-2.jar")))+"!/docs/api/", result.getContent("sources").get(0).toExternalForm()); // enable test collocation query: - MockLookup.setLookup(Lookups.fixed(AntBasedTestUtil.testAntBasedProjectType(), AntBasedTestUtil.testCollocationQueryImplementation(getWorkDir().toURI()), libraryProvider), + MockLookup.setLookup(Lookups.fixed(AntBasedTestUtil.testAntBasedProjectType(), AntBasedTestUtil.testCollocationQueryImplementation(Utilities.toURI(getWorkDir())), libraryProvider), // Filter out standard CQIs since they are bogus. Lookups.exclude(Lookups.metaInfServices(ProjectLibraryProviderTest.class.getClassLoader()), CollocationQueryImplementation.class)); - u = f4.toURI().toURL(); + u = Utilities.toURI(f4).toURL(); result = ProjectLibraryProvider.copyLibrary(l, u, false); assertNotNull(result); assertEquals(u, result.getManager().getLocation()); diff --git a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java --- a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java +++ b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java @@ -83,6 +83,7 @@ import org.openide.filesystems.FileObject; import org.openide.util.ChangeSupport; import org.openide.util.Lookup; +import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; import org.openide.xml.XMLUtil; import org.w3c.dom.Document; @@ -326,7 +327,7 @@ if (!f.isFile()) { return null; } - return XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null); + return XMLUtil.parse(new InputSource(Utilities.toURI(f).toString()), false, true, XMLUtil.defaultErrorHandler(), null); } /** diff --git a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntProjectHelperTest.java b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntProjectHelperTest.java --- a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntProjectHelperTest.java +++ b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntProjectHelperTest.java @@ -67,6 +67,7 @@ import org.openide.filesystems.FileUtil; import org.openide.filesystems.test.TestFileUtils; import org.openide.util.Mutex; +import org.openide.util.Utilities; import org.openide.util.test.MockChangeListener; import org.openide.util.test.MockLookup; import org.openide.util.test.MockPropertyChangeListener; @@ -371,8 +372,8 @@ File somethingElseF = new File(scratchF.getParentFile(), "nonexistent-file-path"); assertEquals("absolute (nonexistent) path is left alone", somethingElseF, h.resolveFile(somethingElseF.getAbsolutePath())); assertEquals("absolute (nonexistent) path has no file object", null, h.resolveFileObject(somethingElseF.getAbsolutePath())); - assertEquals("URI already normalized (Unix-style)", h.resolveFile("../proj").toURI().normalize().toURL(), h.resolveFile("../proj").toURI().toURL()); - assertEquals("URI already normalized (DOS-style)", h.resolveFile("..\\proj").toURI().normalize().toURL(), h.resolveFile("..\\proj").toURI().toURL()); + assertEquals("URI already normalized (Unix-style)", Utilities.toURI(h.resolveFile("../proj")).normalize().toURL(), Utilities.toURI(h.resolveFile("../proj")).toURL()); + assertEquals("URI already normalized (DOS-style)", Utilities.toURI(h.resolveFile("..\\proj")).normalize().toURL(), Utilities.toURI(h.resolveFile("..\\proj")).toURL()); } /** diff --git a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/EditablePropertiesTest.java b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/EditablePropertiesTest.java --- a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/EditablePropertiesTest.java +++ b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/EditablePropertiesTest.java @@ -55,6 +55,7 @@ import java.net.URI; import java.net.URL; import org.netbeans.junit.NbTestCase; +import org.openide.util.Utilities; // here because AntBasedTestUtil.countTextDiffs cannot be moved to openide.util public class EditablePropertiesTest extends NbTestCase { @@ -183,7 +184,7 @@ private String filenameOfTestProperties() { // #50987: never use URL.path for this purpose... - return new File(URI.create(EditablePropertiesTest.class.getResource("data/test.properties").toExternalForm())).getAbsolutePath(); + return Utilities.toFile(URI.create(EditablePropertiesTest.class.getResource("data/test.properties").toExternalForm())).getAbsolutePath(); } private EditableProperties loadTestProperties() throws IOException { diff --git a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/ReferenceHelperTest.java b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/ReferenceHelperTest.java --- a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/ReferenceHelperTest.java +++ b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/ReferenceHelperTest.java @@ -71,6 +71,7 @@ import org.netbeans.spi.queries.CollocationQueryImplementation; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; import org.openide.util.test.MockLookup; import org.openide.xml.XMLUtil; @@ -156,7 +157,7 @@ super.setUp(); ClassLoader l = ReferenceHelper.class.getClassLoader(); MockLookup.setLookup( - Lookups.fixed(AntBasedTestUtil.testAntBasedProjectType(), AntBasedTestUtil.testCollocationQueryImplementation(getWorkDir().toURI())), + Lookups.fixed(AntBasedTestUtil.testAntBasedProjectType(), AntBasedTestUtil.testCollocationQueryImplementation(Utilities.toURI(getWorkDir()))), Lookups.singleton(l), Lookups.exclude(Lookups.metaInfServices(l), CollocationQueryImplementation.class)); scratch = TestUtil.makeScratchDir(this); @@ -1095,11 +1096,11 @@ assertProjectLibraryManagers(null); File fooJar = new File(getWorkDir(), "foo.jar"); File f = new File(getWorkDir(), "libs.properties"); - URL loc = f.toURI().toURL(); + URL loc = Utilities.toURI(f).toURL(); LibraryManager mgr = LibraryManager.forLocation(loc); assertEquals(loc, mgr.getLocation()); Library fooLib = mgr.createLibrary("j2se", "foo", - Collections.singletonMap("classpath", Arrays.asList(new URL("jar:" + fooJar.toURI() + "!/")))); + Collections.singletonMap("classpath", Arrays.asList(new URL("jar:" + Utilities.toURI(fooJar) + "!/")))); assertEquals(mgr, fooLib.getManager()); try { r.createLibraryReference(fooLib, "classpath"); @@ -1120,7 +1121,7 @@ File barDir = new File(getWorkDir(), "bar"); barDir.mkdirs(); String barref = r.createLibraryReference(mgr.createLibrary("j2se", "bar", - Collections.singletonMap("classpath", Arrays.asList(barDir.toURI().toURL()))), "classpath"); + Collections.singletonMap("classpath", Arrays.asList(Utilities.toURI(barDir).toURL()))), "classpath"); assertEquals("${libs.bar.classpath}", barref); assertEquals(barDir.getAbsolutePath(), pev.evaluate(barref).replace('/', File.separatorChar)); EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); diff --git a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SharabilityQueryImplTest.java b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SharabilityQueryImplTest.java --- a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SharabilityQueryImplTest.java +++ b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SharabilityQueryImplTest.java @@ -53,6 +53,7 @@ import org.netbeans.spi.queries.SharabilityQueryImplementation2; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; import org.openide.util.test.MockLookup; /** @@ -94,7 +95,7 @@ } private URI file(String path) { - return new File(scratchF, path.replace('/', File.separatorChar)).toURI(); + return Utilities.toURI(new File(scratchF, path.replace('/', File.separatorChar))); } public void testBasicIncludesExcludes() throws Exception { diff --git a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SimpleAntArtifactTest.java b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SimpleAntArtifactTest.java --- a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SimpleAntArtifactTest.java +++ b/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SimpleAntArtifactTest.java @@ -54,6 +54,7 @@ import org.netbeans.junit.NbTestCase; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; import org.openide.util.test.MockLookup; /** @@ -111,7 +112,7 @@ assertEquals("correct project", pm.findProject(sisterprojdir), art.getProject()); art = sisterh.createSimpleAntArtifact("jar", "build.jar.absolute", sisterh.getStandardPropertyEvaluator(), "dojar", "clean"); - assertEquals("correct artifact location", (new File(getWorkDir().getAbsolutePath()+"/build/proj3.jar")).toURI(), art.getArtifactLocations()[0]); + assertEquals("correct artifact location", Utilities.toURI((new File(getWorkDir().getAbsolutePath()+"/build/proj3.jar"))), art.getArtifactLocations()[0]); } } diff --git a/project.libraries/nbproject/project.xml b/project.libraries/nbproject/project.xml --- a/project.libraries/nbproject/project.xml +++ b/project.libraries/nbproject/project.xml @@ -135,7 +135,7 @@ - 8.0 + 8.25 diff --git a/project.libraries/src/org/netbeans/modules/project/libraries/ui/AllLibrariesCustomizer.java b/project.libraries/src/org/netbeans/modules/project/libraries/ui/AllLibrariesCustomizer.java --- a/project.libraries/src/org/netbeans/modules/project/libraries/ui/AllLibrariesCustomizer.java +++ b/project.libraries/src/org/netbeans/modules/project/libraries/ui/AllLibrariesCustomizer.java @@ -63,6 +63,7 @@ import org.openide.util.HelpCtx; import org.openide.util.Lookup; import org.openide.util.NbBundle.Messages; +import org.openide.util.Utilities; class AllLibrariesCustomizer extends JPanel implements HelpCtx.Provider { @@ -155,7 +156,7 @@ try { //#131452 prevent space in path problem when converting to URL. File loc = FileUtil.normalizeFile(new File((String) libraryManagerComboBox.getModel().getSelectedItem())); - u = loc.toURI().toURL(); + u = Utilities.toURI(loc).toURL(); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } diff --git a/project.libraries/src/org/netbeans/modules/project/libraries/ui/LibrariesCustomizer.java b/project.libraries/src/org/netbeans/modules/project/libraries/ui/LibrariesCustomizer.java --- a/project.libraries/src/org/netbeans/modules/project/libraries/ui/LibrariesCustomizer.java +++ b/project.libraries/src/org/netbeans/modules/project/libraries/ui/LibrariesCustomizer.java @@ -327,7 +327,7 @@ LibraryStorageArea area = nodes[0].getLookup().lookup(LibraryStorageArea.class); if (area != null && area != LibrariesModel.GLOBAL_AREA) { customizerContext = new LibraryCustomizerContextWrapper(impl, area); - File f = new File(URI.create(area.getLocation().toExternalForm())); + File f = Utilities.toFile(URI.create(area.getLocation().toExternalForm())); this.libraryLocation.setText(f.getPath()); } else { customizerContext = new LibraryCustomizerContextWrapper(impl, null); diff --git a/project.libraries/src/org/netbeans/spi/project/libraries/support/LibrariesSupport.java b/project.libraries/src/org/netbeans/spi/project/libraries/support/LibrariesSupport.java --- a/project.libraries/src/org/netbeans/spi/project/libraries/support/LibrariesSupport.java +++ b/project.libraries/src/org/netbeans/spi/project/libraries/support/LibrariesSupport.java @@ -54,10 +54,10 @@ import org.netbeans.modules.project.libraries.DefaultLibraryImplementation; import org.netbeans.spi.project.libraries.LibraryTypeProvider; import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; import org.openide.util.Exceptions; import org.openide.util.Parameters; +import org.openide.util.Utilities; /** * SPI Support class. @@ -111,7 +111,7 @@ try { File f = new File(path); if (f.isAbsolute()) { - return f.toURI(); + return Utilities.toURI(f); } else { // create hierarchical relative URI (that is no schema) return new URI(null, null, path.replace('\\', '/'), null); @@ -132,8 +132,7 @@ */ public static String convertURIToFilePath(URI uri) { if (uri.isAbsolute()) { - // uri.getPath() starts with extra slath, e.g. "/D:/path/" - return new File(uri).getPath(); + return Utilities.toFile(uri).getPath(); } else { return uri.getPath().replace('/', File.separatorChar); } @@ -176,32 +175,19 @@ if (!"file".equals(libraryLocation.getProtocol())) { //NOI18N throw new IllegalArgumentException("not file: protocol - "+libraryLocation.toExternalForm()); //NOI18N } - File libLocation = new File(URI.create(libraryLocation.toExternalForm())); - if (!libLocation.getName().endsWith(".properties")) { //NOI18N + if (!libraryLocation.getPath().endsWith(".properties")) { //NOI18N throw new IllegalArgumentException("library location must be a file - "+libraryLocation.toExternalForm()); //NOI18N } - File libBase = libLocation.getParentFile(); - /* Do not use URI.resolve because of http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4723726 (URI.normalize() ruins URI built from UNC File) */ - String jarFolder = null; - String libEntryPath = libraryEntry.getPath(); - int index = libEntryPath.indexOf("!/"); - if (index != -1) { // NOI18N - libEntryPath = libEntryPath.substring(0, index); - // use raw path instead because it will be append to URI as is: - jarFolder = libraryEntry.getRawPath().substring(libraryEntry.getRawPath().indexOf("!/")+2); - } - URI resolvedPath = FileUtil.normalizeFile(new File(libBase, libEntryPath)).toURI(); - if (jarFolder != null) { // NOI18N - return URI.create("jar:"+resolvedPath.toString()+"!/"+jarFolder); // NOI18N + URI resolved; + try { + resolved = libraryLocation.toURI().resolve(libraryEntry); + } catch (URISyntaxException x) { + throw new AssertionError(x); + } + if (libraryEntry.getPath().contains("!/")) { + return URI.create("jar:" + resolved); } else { - //If the original was a folder but translated not (non existing file) preserve / - final boolean relativeEndsWithSlash = libEntryPath.endsWith("/"); //NOI18N - final String suri = resolvedPath.toString(); - final boolean absoluteEndsWithSlash = suri.endsWith("/"); //NOI18N - if (relativeEndsWithSlash && !absoluteEndsWithSlash) { - resolvedPath = URI.create (suri+'/'); //NOI18N - } - return resolvedPath; + return resolved; } } } diff --git a/project.libraries/test/unit/src/org/netbeans/spi/project/libraries/support/LibrariesSupportTest.java b/project.libraries/test/unit/src/org/netbeans/spi/project/libraries/support/LibrariesSupportTest.java --- a/project.libraries/test/unit/src/org/netbeans/spi/project/libraries/support/LibrariesSupportTest.java +++ b/project.libraries/test/unit/src/org/netbeans/spi/project/libraries/support/LibrariesSupportTest.java @@ -47,6 +47,7 @@ import org.netbeans.junit.NbTestCase; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; public class LibrariesSupportTest extends NbTestCase { @@ -65,7 +66,7 @@ public void testConvertFilePathToURI() throws Exception { String path = getWorkDirPath()+"/aa/bb/c c.ext".replace('/', File.separatorChar); URI u = LibrariesSupport.convertFilePathToURI(path); - assertEquals(FileUtil.normalizeFile(new File(path)).toURI(), u); + assertEquals(Utilities.toURI(FileUtil.normalizeFile(new File(path))), u); path = "../zz/re l.ext".replace('/', File.separatorChar); u = LibrariesSupport.convertFilePathToURI(path); assertEquals("../zz/re%20l.ext", u.toString()); @@ -75,7 +76,7 @@ * Test of convertURLToFilePath method, of class LibrariesSupport. */ public void testConvertURIToFilePath() throws Exception{ - URI u = getWorkDir().toURI(); + URI u = Utilities.toURI(getWorkDir()); String path = LibrariesSupport.convertURIToFilePath(u); assertEquals(getWorkDir().getPath(), path); u = new URI(null, null, "../zz/re l.ext", null); @@ -92,12 +93,12 @@ f.createNewFile(); f2.createNewFile(); FileObject fo = LibrariesSupport.resolveLibraryEntryFileObject( - f.toURI().toURL(), + Utilities.toURI(f).toURL(), new URI(null, null, "bertie.jar", null)); assertEquals(f2.getPath(), FileUtil.toFile(fo).getPath()); fo = LibrariesSupport.resolveLibraryEntryFileObject( null, - f2.toURI()); + Utilities.toURI(f2)); assertEquals(f2.getPath(), FileUtil.toFile(fo).getPath()); } @@ -107,37 +108,37 @@ f.createNewFile(); f2.createNewFile(); URI u = LibrariesSupport.resolveLibraryEntryURI( - f.toURI().toURL(), + Utilities.toURI(f).toURL(), new URI(null, null, "ber tie.jar", null)); - assertEquals(new File(f.getParentFile(), f2.getName()).toURI(), u); + assertEquals(Utilities.toURI(new File(f.getParentFile(), f2.getName())), u); u = LibrariesSupport.resolveLibraryEntryURI( - f.toURI().toURL(), - f2.toURI()); - assertEquals(f2.toURI(), u); + Utilities.toURI(f).toURL(), + Utilities.toURI(f2)); + assertEquals(Utilities.toURI(f2), u); u = LibrariesSupport.resolveLibraryEntryURI( - f.toURI().toURL(), + Utilities.toURI(f).toURL(), new URI(null, null, "ber tie.jar!/main/ja va", null)); - assertEquals(new URI("jar:"+ (new File(f.getParentFile(), f2.getName()).toURI().toString()) + "!/main/ja%20va"), u); + assertEquals(new URI("jar:"+ (Utilities.toURI(new File(f.getParentFile(), f2.getName())).toString()) + "!/main/ja%20va"), u); u = LibrariesSupport.resolveLibraryEntryURI( - f.toURI().toURL(), + Utilities.toURI(f).toURL(), new URI(null, null, "../"+getWorkDir().getName()+"/ber tie.jar!/main/ja va", null)); - assertEquals(new URI("jar:"+ (new File(f.getParentFile(), f2.getName()).toURI().toString()) + "!/main/ja%20va"), u); + assertEquals(new URI("jar:"+ (Utilities.toURI(new File(f.getParentFile(), f2.getName())).toString()) + "!/main/ja%20va"), u); u = LibrariesSupport.resolveLibraryEntryURI( - f.toURI().toURL(), + Utilities.toURI(f).toURL(), new URI(null, null, "../a folder/", null)); - assertEquals(new URI(new File(getWorkDir().getParentFile(), "a folder").toURI().toString() + "/"), u); + assertEquals(new URI(Utilities.toURI(new File(getWorkDir().getParentFile(), "a folder")).toString() + "/"), u); // UNC paths - URI uncBaseURI = URI.create("file:////computerName/sharedFolder/a/b/c/d.properties"); + URI uncBaseURI = URI.create("file://computerName/sharedFolder/a/b/c/d.properties"); URI uncEntryURI = URI.create("e/e.jar"); - URI expectedURI = new File(new File(uncBaseURI).getParent(), uncEntryURI.getPath()).toURI(); + URI expectedURI = URI.create("file://computerName/sharedFolder/a/b/c/e/e.jar"); URI resolvedURI = LibrariesSupport.resolveLibraryEntryURI(uncBaseURI.toURL(), uncEntryURI); assertEquals("UNC entry wrongly resolved.", expectedURI, resolvedURI); uncEntryURI = new URI(null, null, "e/e.jar!/f f/f", null); - expectedURI = URI.create("jar:"+new File(new File(uncBaseURI).getParent(), uncEntryURI.getPath()).toURI().toString()); + expectedURI = URI.create("jar:file://computerName/sharedFolder/a/b/c/e/e.jar!/f%20f/f"); resolvedURI = LibrariesSupport.resolveLibraryEntryURI(uncBaseURI.toURL(), uncEntryURI); assertEquals("UNC jar entry wrongly resolved.", expectedURI, resolvedURI); uncEntryURI = new URI(null, null, "e/e.jar!/", null); - expectedURI = URI.create("jar:"+new File(new File(uncBaseURI).getParent()).toURI().toString()+"/e/e.jar!/"); + expectedURI = URI.create("jar:file://computerName/sharedFolder/a/b/c/e/e.jar!/"); resolvedURI = LibrariesSupport.resolveLibraryEntryURI(uncBaseURI.toURL(), uncEntryURI); assertEquals("UNC jar entry wrongly resolved.", expectedURI, resolvedURI); } diff --git a/projectapi/nbproject/project.xml b/projectapi/nbproject/project.xml --- a/projectapi/nbproject/project.xml +++ b/projectapi/nbproject/project.xml @@ -104,7 +104,7 @@ - 8.4 + 8.25 diff --git a/projectapi/src/org/netbeans/api/project/FileOwnerQuery.java b/projectapi/src/org/netbeans/api/project/FileOwnerQuery.java --- a/projectapi/src/org/netbeans/api/project/FileOwnerQuery.java +++ b/projectapi/src/org/netbeans/api/project/FileOwnerQuery.java @@ -60,6 +60,7 @@ import org.openide.util.Lookup; import org.openide.util.LookupEvent; import org.openide.util.LookupListener; +import org.openide.util.Utilities; /** * Find the project which owns a file. @@ -135,7 +136,7 @@ try { URL u = new URL(schemaPart); // XXX bad to ever use new File(URL.getPath()): - uri = new File(u.getPath()).toURI(); + uri = Utilities.toURI(new File(u.getPath())); } catch (MalformedURLException ex2) { ex2.printStackTrace(); assert false : schemaPart; diff --git a/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery.java b/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery.java --- a/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery.java +++ b/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery.java @@ -48,6 +48,7 @@ import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.queries.SharabilityQuery; +import org.openide.util.Utilities; /** * Delegates {@link SharabilityQuery} to implementations in project lookup. @@ -60,7 +61,7 @@ public ProjectSharabilityQuery() {} public @Override int getSharability(File file) { - Project p = FileOwnerQuery.getOwner(file.toURI()); + Project p = FileOwnerQuery.getOwner(Utilities.toURI(file)); if (p != null) { org.netbeans.spi.queries.SharabilityQueryImplementation sqi = p.getLookup().lookup(org.netbeans.spi.queries.SharabilityQueryImplementation.class); if (sqi != null) { diff --git a/projectapi/test/unit/src/org/netbeans/api/project/FileOwnerQueryTest.java b/projectapi/test/unit/src/org/netbeans/api/project/FileOwnerQueryTest.java --- a/projectapi/test/unit/src/org/netbeans/api/project/FileOwnerQueryTest.java +++ b/projectapi/test/unit/src/org/netbeans/api/project/FileOwnerQueryTest.java @@ -52,6 +52,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.test.TestFileUtils; +import org.openide.util.Utilities; import org.openide.util.test.MockLookup; /** @@ -123,21 +124,21 @@ public void testFileOwner() throws Exception { assertEquals("correct project from projfile FileObject", p, FileOwnerQuery.getOwner(projfile)); - URI u = FileUtil.toFile(projfile).toURI(); + URI u = Utilities.toURI(FileUtil.toFile(projfile)); assertEquals("correct project from projfile URI " + u, p, FileOwnerQuery.getOwner(u)); assertEquals("correct project from projfile2 FileObject", p, FileOwnerQuery.getOwner(projfile2)); - assertEquals("correct project from projfile2 URI", p, FileOwnerQuery.getOwner(FileUtil.toFile(projfile2).toURI())); + assertEquals("correct project from projfile2 URI", p, FileOwnerQuery.getOwner(Utilities.toURI(FileUtil.toFile(projfile2)))); assertEquals("correct project from projdir FileObject", p, FileOwnerQuery.getOwner(projdir)); - assertEquals("correct project from projdir URI", p, FileOwnerQuery.getOwner(FileUtil.toFile(projdir).toURI())); + assertEquals("correct project from projdir URI", p, FileOwnerQuery.getOwner(Utilities.toURI(FileUtil.toFile(projdir)))); // Check that it loads the project even though we have not touched it yet: Project p2 = FileOwnerQuery.getOwner(subprojfile); Project subproj = ProjectManager.getDefault().findProject(subprojdir); assertEquals("correct project from subprojdir FileObject", subproj, p2); - assertEquals("correct project from subprojdir URI", subproj, FileOwnerQuery.getOwner(FileUtil.toFile(subprojdir).toURI())); + assertEquals("correct project from subprojdir URI", subproj, FileOwnerQuery.getOwner(Utilities.toURI(FileUtil.toFile(subprojdir)))); assertEquals("correct project from subprojfile FileObject", subproj, FileOwnerQuery.getOwner(subprojfile)); - assertEquals("correct project from subprojfile URI", subproj, FileOwnerQuery.getOwner(FileUtil.toFile(subprojfile).toURI())); + assertEquals("correct project from subprojfile URI", subproj, FileOwnerQuery.getOwner(Utilities.toURI(FileUtil.toFile(subprojfile)))); assertEquals("no project from randomfile FileObject", null, FileOwnerQuery.getOwner(randomfile)); - assertEquals("no project from randomfile URI", null, FileOwnerQuery.getOwner(FileUtil.toFile(randomfile).toURI())); + assertEquals("no project from randomfile URI", null, FileOwnerQuery.getOwner(Utilities.toURI(FileUtil.toFile(randomfile)))); assertEquals("no project in C:\\", null, FileOwnerQuery.getOwner(URI.create("file:/C:/"))); } diff --git a/projectui/nbproject/project.xml b/projectui/nbproject/project.xml --- a/projectui/nbproject/project.xml +++ b/projectui/nbproject/project.xml @@ -215,7 +215,7 @@ - 8.6 + 8.25 diff --git a/projectui/src/org/netbeans/modules/project/ui/ProjectChooserAccessory.java b/projectui/src/org/netbeans/modules/project/ui/ProjectChooserAccessory.java --- a/projectui/src/org/netbeans/modules/project/ui/ProjectChooserAccessory.java +++ b/projectui/src/org/netbeans/modules/project/ui/ProjectChooserAccessory.java @@ -80,6 +80,7 @@ import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; /** * Special component on side of project filechooser. @@ -393,7 +394,7 @@ } b.append("../"); // NOI18N } - URI u = base.toURI().relativize(f2.toURI()); + URI u = Utilities.toURI(base).relativize(Utilities.toURI(f2)); assert !u.isAbsolute() : u + " from " + f1 + " and " + f2 + " with common root " + base; b.append(u.getPath()); if (b.charAt(b.length() - 1) == '/') { diff --git a/projectui/src/org/netbeans/modules/project/ui/zip/ExportZIP.java b/projectui/src/org/netbeans/modules/project/ui/zip/ExportZIP.java --- a/projectui/src/org/netbeans/modules/project/ui/zip/ExportZIP.java +++ b/projectui/src/org/netbeans/modules/project/ui/zip/ExportZIP.java @@ -210,7 +210,7 @@ } boolean kidMixed; if (mixedSharability) { - switch (SharabilityQuery.getSharability(kid.toURI())) { + switch (SharabilityQuery.getSharability(Utilities.toURI(kid))) { case SHARABLE: kidMixed = false; break; diff --git a/projectui/src/org/netbeans/modules/project/ui/zip/ImportZIP.java b/projectui/src/org/netbeans/modules/project/ui/zip/ImportZIP.java --- a/projectui/src/org/netbeans/modules/project/ui/zip/ImportZIP.java +++ b/projectui/src/org/netbeans/modules/project/ui/zip/ImportZIP.java @@ -82,6 +82,7 @@ import org.openide.util.Cancellable; import org.openide.util.NbBundle.Messages; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; public class ImportZIP extends JPanel { @@ -224,7 +225,7 @@ return false; } try { - if (!FileUtil.isArchiveFile(zip.toURI().toURL())) { + if (!FileUtil.isArchiveFile(Utilities.toURI(zip).toURL())) { notifications.setErrorMessage(ERR_not_zip(zip)); return false; } diff --git a/queries/nbproject/project.xml b/queries/nbproject/project.xml --- a/queries/nbproject/project.xml +++ b/queries/nbproject/project.xml @@ -62,7 +62,7 @@ - 8.0 + 8.25 diff --git a/queries/src/org/netbeans/api/queries/CollocationQuery.java b/queries/src/org/netbeans/api/queries/CollocationQuery.java --- a/queries/src/org/netbeans/api/queries/CollocationQuery.java +++ b/queries/src/org/netbeans/api/queries/CollocationQuery.java @@ -49,6 +49,7 @@ import org.netbeans.spi.queries.CollocationQueryImplementation2; import org.openide.filesystems.FileUtil; import org.openide.util.Lookup; +import org.openide.util.Utilities; /** * Find out whether some files logically belong in one directory tree, @@ -85,8 +86,8 @@ throw new IllegalArgumentException("Parameter file2 was not "+ // NOI18N "normalized. Was "+file2+" instead of "+FileUtil.normalizeFile(file2)); // NOI18N } - URI uri1 = file1.toURI(); - URI uri2 = file2.toURI(); + URI uri1 = Utilities.toURI(file1); + URI uri2 = Utilities.toURI(file2); for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) { if (cqi.areCollocated(uri1, uri2)) { return true; @@ -125,8 +126,8 @@ } } if ("file".equals(file1.getScheme()) && "file".equals(file2.getScheme())) { // NOI18N - File f1 = FileUtil.normalizeFile(new File(file1)); - File f2 = FileUtil.normalizeFile(new File(file2)); + File f1 = FileUtil.normalizeFile(Utilities.toFile(file1)); + File f2 = FileUtil.normalizeFile(Utilities.toFile(file2)); for (org.netbeans.spi.queries.CollocationQueryImplementation cqi : implementations.allInstances()) { if (cqi.areCollocated(f1, f2)) { return true; @@ -148,11 +149,11 @@ throw new IllegalArgumentException("Parameter file was not "+ // NOI18N "normalized. Was "+file+" instead of "+FileUtil.normalizeFile(file)); // NOI18N } - URI uri = file.toURI(); + URI uri = Utilities.toURI(file); for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) { URI root = cqi.findRoot(uri); if (root != null) { - return new File(root); + return Utilities.toFile(root); } } for (org.netbeans.spi.queries.CollocationQueryImplementation cqi : implementations.allInstances()) { @@ -183,11 +184,11 @@ } } if ("file".equals(file.getScheme())) { // NOI18N - File f = FileUtil.normalizeFile(new File(file)); + File f = FileUtil.normalizeFile(Utilities.toFile(file)); for (org.netbeans.spi.queries.CollocationQueryImplementation cqi : implementations.allInstances()) { File root = cqi.findRoot(f); if (root != null) { - return root.toURI(); + return Utilities.toURI(root); } } } diff --git a/queries/src/org/netbeans/api/queries/SharabilityQuery.java b/queries/src/org/netbeans/api/queries/SharabilityQuery.java --- a/queries/src/org/netbeans/api/queries/SharabilityQuery.java +++ b/queries/src/org/netbeans/api/queries/SharabilityQuery.java @@ -172,7 +172,7 @@ URI uri = null; for (SharabilityQueryImplementation2 sqi : implementations2.allInstances()) { if (uri == null) { - uri = file.toURI(); + uri = Utilities.toURI(file); } Sharability x = sqi.getSharability(uri); if (x != Sharability.UNKNOWN) { @@ -211,7 +211,7 @@ } } if ("file".equals(uri.getScheme())) { // NOI18N - File file = FileUtil.normalizeFile(new File(uri)); + File file = FileUtil.normalizeFile(Utilities.toFile(uri)); for (org.netbeans.spi.queries.SharabilityQueryImplementation sqi : implementations.allInstances()) { int x = sqi.getSharability(file); if (x != UNKNOWN) { diff --git a/queries/test/unit/src/org/netbeans/api/queries/CollocationQuery2Test.java b/queries/test/unit/src/org/netbeans/api/queries/CollocationQuery2Test.java --- a/queries/test/unit/src/org/netbeans/api/queries/CollocationQuery2Test.java +++ b/queries/test/unit/src/org/netbeans/api/queries/CollocationQuery2Test.java @@ -47,6 +47,7 @@ import org.netbeans.junit.MockServices; import org.netbeans.junit.NbTestCase; import org.netbeans.spi.queries.CollocationQueryImplementation2; +import org.openide.util.Utilities; /** * @@ -74,37 +75,37 @@ File proj2 = new File(base, "proj2"); proj2.mkdirs(); assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1, proj3)); - assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj3.toURI())); + assertTrue("Must be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj3))); assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3, proj1)); - assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3.toURI(), proj1.toURI())); + assertTrue("Must be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj3), Utilities.toURI(proj1))); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj2)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj2.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj2))); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2, proj1)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2.toURI(), proj1.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj2), Utilities.toURI(proj1))); // folder does not exist: File proj4 = new File(base, "proj"); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj4))); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj4), Utilities.toURI(proj1))); proj4.mkdirs(); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj4))); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj4), Utilities.toURI(proj1))); // files do not exist: File file1 = new File(base, "file1.txt"); File file2 = new File(base, "file1"); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1, file2)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1.toURI(), file2.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(file1), Utilities.toURI(file2))); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2, file1)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2.toURI(), file1.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(file2), Utilities.toURI(file1))); // passing the same parameter assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1, proj1)); - assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1.toURI(), proj1.toURI())); + assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj1))); } public static class CollocationQueryImplementation2Impl implements CollocationQueryImplementation2 { @@ -114,8 +115,8 @@ if (uri1.equals(uri2)) { return true; } - File file1 = new File(uri1); - File file2 = new File(uri2); + File file1 = Utilities.toFile(uri1); + File file2 = Utilities.toFile(uri2); String f1 = file1.getPath(); if ((file1.isDirectory() || !file1.exists()) && !f1.endsWith(File.separator)) { f1 += File.separatorChar; diff --git a/queries/test/unit/src/org/netbeans/api/queries/CollocationQueryTest.java b/queries/test/unit/src/org/netbeans/api/queries/CollocationQueryTest.java --- a/queries/test/unit/src/org/netbeans/api/queries/CollocationQueryTest.java +++ b/queries/test/unit/src/org/netbeans/api/queries/CollocationQueryTest.java @@ -44,6 +44,7 @@ import java.io.File; import java.io.IOException; import org.netbeans.junit.NbTestCase; +import org.openide.util.Utilities; /** * @@ -70,37 +71,37 @@ File proj2 = new File(base, "proj2"); proj2.mkdirs(); assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1, proj3)); - assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj3.toURI())); + assertTrue("Must be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj3))); assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3, proj1)); - assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3.toURI(), proj1.toURI())); + assertTrue("Must be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj3), Utilities.toURI(proj1))); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj2)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj2.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj2))); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2, proj1)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2.toURI(), proj1.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj2), Utilities.toURI(proj1))); // folder does not exist: File proj4 = new File(base, "proj"); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj4))); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj4), Utilities.toURI(proj1))); proj4.mkdirs(); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj4))); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(proj4), Utilities.toURI(proj1))); // files do not exist: File file1 = new File(base, "file1.txt"); File file2 = new File(base, "file1"); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1, file2)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1.toURI(), file2.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(file1), Utilities.toURI(file2))); assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2, file1)); - assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2.toURI(), file1.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(Utilities.toURI(file2), Utilities.toURI(file1))); // passing the same parameter assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1, proj1)); - assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1.toURI(), proj1.toURI())); + assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj1))); } } diff --git a/queries/test/unit/src/org/netbeans/api/queries/FileEncodingQueryTest.java b/queries/test/unit/src/org/netbeans/api/queries/FileEncodingQueryTest.java --- a/queries/test/unit/src/org/netbeans/api/queries/FileEncodingQueryTest.java +++ b/queries/test/unit/src/org/netbeans/api/queries/FileEncodingQueryTest.java @@ -82,6 +82,7 @@ import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -118,7 +119,7 @@ public static Test suite () throws Exception { URL url = FileEncodingQueryTest.class.getResource("data"); - File dataFolder = new File(URI.create(url.toExternalForm())); + File dataFolder = Utilities.toFile(URI.create(url.toExternalForm())); assertTrue(dataFolder.isDirectory()); File dataFile = new File (dataFolder, "data.properties"); assertTrue (dataFile.exists()); @@ -204,7 +205,7 @@ public void testLongUnicode () throws IOException { URL url = FileEncodingQueryTest.class.getResource("data"); - File dataFolder = new File(URI.create(url.toExternalForm())); + File dataFolder = Utilities.toFile(URI.create(url.toExternalForm())); assertTrue(dataFolder.isDirectory()); File dataFile = new File (dataFolder, "longUnicode.txt"); assertTrue (dataFile.exists()); @@ -220,7 +221,7 @@ public void testLongUnicode2 () throws IOException { URL url = FileEncodingQueryTest.class.getResource("data"); - File dataFolder = new File(URI.create(url.toExternalForm())); + File dataFolder = Utilities.toFile(URI.create(url.toExternalForm())); assertTrue(dataFolder.isDirectory()); File dataFile = new File (dataFolder, "longUnicode2.txt"); assertTrue (dataFile.exists()); diff --git a/queries/test/unit/src/org/netbeans/api/queries/SharabilityQueryTest.java b/queries/test/unit/src/org/netbeans/api/queries/SharabilityQueryTest.java --- a/queries/test/unit/src/org/netbeans/api/queries/SharabilityQueryTest.java +++ b/queries/test/unit/src/org/netbeans/api/queries/SharabilityQueryTest.java @@ -52,6 +52,7 @@ import org.netbeans.spi.queries.SharabilityQueryImplementation2; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; /** * @@ -76,7 +77,7 @@ File file = new File(home, "aFile.sharable"); int sharability = SharabilityQuery.getSharability(file); assertEquals(SharabilityQuery.SHARABLE, sharability); - URI uri = file.toURI(); + URI uri = Utilities.toURI(file); Sharability sharability2 = SharabilityQuery.getSharability(uri); assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability2); FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "sharable"); @@ -87,7 +88,7 @@ File file = new File(home, "aFile.sharable2"); int sharability = SharabilityQuery.getSharability(file); assertEquals(SharabilityQuery.SHARABLE, sharability); - URI uri = file.toURI(); + URI uri = Utilities.toURI(file); Sharability sharability2 = SharabilityQuery.getSharability(uri); assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability2); FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "sharable2"); @@ -98,7 +99,7 @@ File file = new File(home, "aFile.not_sharable"); int sharability = SharabilityQuery.getSharability(file); assertEquals(SharabilityQuery.NOT_SHARABLE, sharability); - URI uri = file.toURI(); + URI uri = Utilities.toURI(file); Sharability sharability2 = SharabilityQuery.getSharability(uri); assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, sharability2); FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "not_sharable"); @@ -109,7 +110,7 @@ File file = new File(home, "aFile.not_sharable2"); int sharability = SharabilityQuery.getSharability(file); assertEquals(SharabilityQuery.NOT_SHARABLE, sharability); - URI uri = file.toURI(); + URI uri = Utilities.toURI(file); Sharability sharability2 = SharabilityQuery.getSharability(uri); assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, sharability2); FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "not_sharable2"); @@ -120,7 +121,7 @@ File file = new File(home, "aFile.mixed"); int sharability = SharabilityQuery.getSharability(file); assertEquals(SharabilityQuery.MIXED, sharability); - URI uri = file.toURI(); + URI uri = Utilities.toURI(file); Sharability sharability2 = SharabilityQuery.getSharability(uri); assertEquals(SharabilityQuery.Sharability.MIXED, sharability2); FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "mixed"); @@ -131,7 +132,7 @@ File file = new File(home, "aFile.mixed2"); int sharability = SharabilityQuery.getSharability(file); assertEquals(SharabilityQuery.MIXED, sharability); - URI uri = file.toURI(); + URI uri = Utilities.toURI(file); Sharability sharability2 = SharabilityQuery.getSharability(uri); assertEquals(SharabilityQuery.Sharability.MIXED, sharability2); FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "mixed2"); @@ -142,7 +143,7 @@ File file = new File(home, "aFile.txt"); int sharability = SharabilityQuery.getSharability(file); assertEquals(SharabilityQuery.UNKNOWN, sharability); - URI uri = file.toURI(); + URI uri = Utilities.toURI(file); Sharability sharability2 = SharabilityQuery.getSharability(uri); assertEquals(SharabilityQuery.Sharability.UNKNOWN, sharability2); FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "txt"); @@ -158,7 +159,7 @@ exception = e; } assertNotNull(exception); - URI uri = file.toURI(); + URI uri = Utilities.toURI(file); exception = null; try { SharabilityQuery.getSharability(uri); diff --git a/queries/test/unit/src/org/netbeans/modules/queries/ParentChildCollocationQueryTest.java b/queries/test/unit/src/org/netbeans/modules/queries/ParentChildCollocationQueryTest.java --- a/queries/test/unit/src/org/netbeans/modules/queries/ParentChildCollocationQueryTest.java +++ b/queries/test/unit/src/org/netbeans/modules/queries/ParentChildCollocationQueryTest.java @@ -46,6 +46,7 @@ import java.io.File; import org.netbeans.junit.NbTestCase; +import org.openide.util.Utilities; /** * Test of ParentChildCollocationQuery impl. @@ -69,27 +70,27 @@ proj2.mkdirs(); ParentChildCollocationQuery query = new ParentChildCollocationQuery(); - assertTrue("Must be collocated", query.areCollocated(proj1.toURI(), proj3.toURI())); - assertTrue("Must be collocated", query.areCollocated(proj3.toURI(), proj1.toURI())); - assertFalse("Cannot be collocated", query.areCollocated(proj1.toURI(), proj2.toURI())); - assertFalse("Cannot be collocated", query.areCollocated(proj2.toURI(), proj1.toURI())); + assertTrue("Must be collocated", query.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj3))); + assertTrue("Must be collocated", query.areCollocated(Utilities.toURI(proj3), Utilities.toURI(proj1))); + assertFalse("Cannot be collocated", query.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj2))); + assertFalse("Cannot be collocated", query.areCollocated(Utilities.toURI(proj2), Utilities.toURI(proj1))); // folder does not exist: File proj4 = new File(base, "proj"); - assertFalse("Cannot be collocated", query.areCollocated(proj1.toURI(), proj4.toURI())); - assertFalse("Cannot be collocated", query.areCollocated(proj4.toURI(), proj1.toURI())); + assertFalse("Cannot be collocated", query.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj4))); + assertFalse("Cannot be collocated", query.areCollocated(Utilities.toURI(proj4), Utilities.toURI(proj1))); proj4.mkdirs(); - assertFalse("Cannot be collocated", query.areCollocated(proj1.toURI(), proj4.toURI())); - assertFalse("Cannot be collocated", query.areCollocated(proj4.toURI(), proj1.toURI())); + assertFalse("Cannot be collocated", query.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj4))); + assertFalse("Cannot be collocated", query.areCollocated(Utilities.toURI(proj4), Utilities.toURI(proj1))); // files do not exist: File file1 = new File(base, "file1.txt"); File file2 = new File(base, "file1"); - assertFalse("Cannot be collocated", query.areCollocated(file1.toURI(), file2.toURI())); - assertFalse("Cannot be collocated", query.areCollocated(file2.toURI(), file1.toURI())); + assertFalse("Cannot be collocated", query.areCollocated(Utilities.toURI(file1), Utilities.toURI(file2))); + assertFalse("Cannot be collocated", query.areCollocated(Utilities.toURI(file2), Utilities.toURI(file1))); // passing the same parameter - assertTrue("A file must be collocated with itself", query.areCollocated(proj1.toURI(), proj1.toURI())); + assertTrue("A file must be collocated with itself", query.areCollocated(Utilities.toURI(proj1), Utilities.toURI(proj1))); } }