Java Code Examples for org.openide.util.BaseUtilities#toURI()

The following examples show how to use org.openide.util.BaseUtilities#toURI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleAntArtifact.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private URI getArtifactLocation0() {
    String locationResolved = eval.getProperty(locationProperty);
    if (locationResolved == null) {
        return URI.create("file:/UNDEFINED"); // NOI18N
    }
    File locF = new File(locationResolved);
    if (locF.isAbsolute()) {
        return BaseUtilities.toURI(locF);
    } else {
        // Project-relative path.
        try {
            return new URI(null, null, locationResolved.replace(File.separatorChar, '/'), null);
        } catch (URISyntaxException e) {
            Logger.getLogger(this.getClass().getName()).log(Level.INFO, null, e);
            return URI.create("file:/BROKEN"); // NOI18N
        }
    }
}
 
Example 2
Source File: LibrariesSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Properly converts possibly relative file path to URI.
 * @param path file path to convert; can be relative; cannot be null
 * @return uri
 * @since org.netbeans.modules.project.libraries/1 1.18
 */
public static URI convertFilePathToURI(final @NonNull String path) {
    Parameters.notNull("path", path);   //NOI18N
    try {
        File f = new File(path);
        if (f.isAbsolute()) {
            return BaseUtilities.toURI(f);
        } else {
            // create hierarchical relative URI (that is no schema)
            return new URI(null, null, path.replace('\\', '/'), null);
        }

    } catch (URISyntaxException ex) {
 IllegalArgumentException y = new IllegalArgumentException();
 y.initCause(ex);
 throw y;
    }
}
 
Example 3
Source File: JarClassLoader.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static String toURI(final File file) {
    class VFile extends File {
        public VFile() {
            super(file.getPath());
        }

        @Override
        public boolean isDirectory() {
            return false;
        }

        @Override
        public File getAbsoluteFile() {
            return this;
        }
    }
    return "jar:" + BaseUtilities.toURI(new VFile()) + "!/"; // NOI18N
}
 
Example 4
Source File: SharabilityQueryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNotSharableBridge2New() throws IOException {
    File file = new File(home, "aFile.not_sharable2");
    int sharability = SharabilityQuery.getSharability(file);
    assertEquals(SharabilityQuery.NOT_SHARABLE, sharability);
    URI uri = BaseUtilities.toURI(file);
    Sharability sharability2 = SharabilityQuery.getSharability(uri);
    assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, sharability2);
    FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "not_sharable2");
    assertEquals(sharability2, SharabilityQuery.getSharability(fo));
}
 
Example 5
Source File: LuceneIndex.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private synchronized void hit() {
    if (reader != null) {
        final URI uri = BaseUtilities.toURI(folder);
        if (memDir != null) {
            IndexCacheFactory.getDefault().getRAMCache().put(uri, this);
            if (ref != null) {
                ref.get();
            }
        } else {
            IndexCacheFactory.getDefault().getNIOCache().put(uri, this);
        }
    }
}
 
Example 6
Source File: URLMapperTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Check that jar: URLs are correctly mapped back into JarFileSystem resources.
 * @see "#39190"
 */
public void testJarMapping() throws Exception {
    clearWorkDir();
    File workdir = getWorkDir();
    File jar = new File(workdir, "test.jar");
    String textPath = "x.txt";
    OutputStream os = new FileOutputStream(jar);
    try {
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(ZipEntry.STORED);
        JarEntry entry = new JarEntry(textPath);
        entry.setSize(0L);
        entry.setTime(System.currentTimeMillis());
        entry.setCrc(new CRC32().getValue());
        jos.putNextEntry(entry);
        jos.flush();
        jos.close();
    } finally {
        os.close();
    }
    assertTrue("JAR was created", jar.isFile());
    assertTrue("JAR is not empty", jar.length() > 0L);
    JarFileSystem jfs = new JarFileSystem();
    jfs.setJarFile(jar);
    Repository.getDefault().addFileSystem(jfs);
    FileObject rootFO = jfs.getRoot();
    FileObject textFO = jfs.findResource(textPath);
    assertNotNull("JAR contains a/b.txt", textFO);
    String rootS = "jar:" + BaseUtilities.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));
    assertEquals("correct FO -> URL for " + textPath, textU, URLMapper.findURL(textFO, URLMapper.EXTERNAL));
    assertTrue("correct URL -> FO for root", Arrays.asList(URLMapper.findFileObjects(rootU)).contains(rootFO));
    assertTrue("correct URL -> FO for " + textPath, Arrays.asList(URLMapper.findFileObjects(textU)).contains(textFO));
}
 
Example 7
Source File: SharabilityQueryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testUnknown() throws IOException {
    File file = new File(home, "aFile.txt");
    int sharability = SharabilityQuery.getSharability(file);
    assertEquals(SharabilityQuery.UNKNOWN, sharability);
    URI uri = BaseUtilities.toURI(file);
    Sharability sharability2 = SharabilityQuery.getSharability(uri);
    assertEquals(SharabilityQuery.Sharability.UNKNOWN, sharability2);
    FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "txt");
    assertEquals(sharability2, SharabilityQuery.getSharability(fo));
}
 
Example 8
Source File: SharabilityQueryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testMixedBridge2New() throws IOException {
    File file = new File(home, "aFile.mixed2");
    int sharability = SharabilityQuery.getSharability(file);
    assertEquals(SharabilityQuery.MIXED, sharability);
    URI uri = BaseUtilities.toURI(file);
    Sharability sharability2 = SharabilityQuery.getSharability(uri);
    assertEquals(SharabilityQuery.Sharability.MIXED, sharability2);
    FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "mixed2");
    assertEquals(sharability2, SharabilityQuery.getSharability(fo));
}
 
Example 9
Source File: SharabilityQueryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testMixedBridge2Old() throws IOException {
    File file = new File(home, "aFile.mixed");
    int sharability = SharabilityQuery.getSharability(file);
    assertEquals(SharabilityQuery.MIXED, sharability);
    URI uri = BaseUtilities.toURI(file);
    Sharability sharability2 = SharabilityQuery.getSharability(uri);
    assertEquals(SharabilityQuery.Sharability.MIXED, sharability2);
    FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "mixed");
    assertEquals(sharability2, SharabilityQuery.getSharability(fo));
}
 
Example 10
Source File: FileObjects.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public URI toUri () {
    if (this.uriCache == null) {
        this.uriCache = BaseUtilities.toURI(f);
    }
    return this.uriCache;
}
 
Example 11
Source File: SharabilityQueryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNotSharableBridge2Old() throws IOException {
    File file = new File(home, "aFile.not_sharable");
    int sharability = SharabilityQuery.getSharability(file);
    assertEquals(SharabilityQuery.NOT_SHARABLE, sharability);
    URI uri = BaseUtilities.toURI(file);
    Sharability sharability2 = SharabilityQuery.getSharability(uri);
    assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, sharability2);
    FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "not_sharable");
    assertEquals(sharability2, SharabilityQuery.getSharability(fo));
}
 
Example 12
Source File: SharabilityQueryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testSharableBridge2New() throws IOException {
    File file = new File(home, "aFile.sharable2");
    int sharability = SharabilityQuery.getSharability(file);
    assertEquals(SharabilityQuery.SHARABLE, sharability);
    URI uri = BaseUtilities.toURI(file);
    Sharability sharability2 = SharabilityQuery.getSharability(uri);
    assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability2);
    FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "sharable2");
    assertEquals(sharability2, SharabilityQuery.getSharability(fo));
}
 
Example 13
Source File: SharabilityQueryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testSharableBridge2Old() throws IOException {
    File file = new File(home, "aFile.sharable");
    int sharability = SharabilityQuery.getSharability(file);
    assertEquals(SharabilityQuery.SHARABLE, sharability);
    URI uri = BaseUtilities.toURI(file);
    Sharability sharability2 = SharabilityQuery.getSharability(uri);
    assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability2);
    FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "sharable");
    assertEquals(sharability2, SharabilityQuery.getSharability(fo));
}
 
Example 14
Source File: CachingPathArchiveTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void verifyURIs(Path module) throws IOException {
    final URI javaHome = BaseUtilities.toURI(TestUtilities.getJava9Home());
    final URI rootURI = URI.create("nbjrt:"+javaHome+"!"+module+"/");
    final CachingPathArchive cpa = new CachingPathArchive(module, rootURI);
    final PathArchive pa = new PathArchive(module, rootURI);
    final Set<String> pkgs = getPackages(module).keySet();
    for (String pkg : pkgs) {
        final Iterable<? extends JavaFileObject> cjfos = cpa.getFiles(pkg, null, null, null, false);
        final Iterable<? extends JavaFileObject> jfos = pa.getFiles(pkg, null, null, null, false);
        assertJFOEquals(jfos, cjfos);
    }
}
 
Example 15
Source File: XMLFileSystemTestHid.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testOverridingReferencedFilesInMultipleLayers() throws Exception {

        File jar1 = writeJarFile("jar1.jar",
            new JEntry("layer.xml",
                "<filesystem>\n" +
                "  <folder name='dir'>\n" +
                "    <file name='file' url='file1.txt'/>" +
                "  </folder>" +
                "</filesystem>"
                ),
            new JEntry("file1.txt",
                "file1.txt content"
            )
        );
        
        File jar2 = writeJarFile("jar2.jar",
            new JEntry("layer.xml",
                "<filesystem>\n" +
                "  <folder name='dir'>\n" +
                "    <file name='file' url='file2.txt'/>" +
                "  </folder>" +
                "</filesystem>"
                ),
            new JEntry("file2.txt",
                "file2.txt content"
            )
        );

        URL url1 = new URL("jar:" + BaseUtilities.toURI(jar1) + "!/layer.xml");
        URL url2 = new URL("jar:" + BaseUtilities.toURI(jar2) + "!/layer.xml");

        FileSystem xfs1 = FileSystemFactoryHid.createXMLSystem(getName(), this, url1);
        FileObject fo1 = xfs1.findResource("dir/file");
        assertNotNull(fo1);

        FileSystem xfs2 = FileSystemFactoryHid.createXMLSystem(getName(), this, url2);
        FileObject fo2 = xfs2.findResource("dir/file");
        assertNotNull(fo2);

        FileSystem xfs12 = FileSystemFactoryHid.createXMLSystem(getName(), this, url1, url2);
        FileObject fo12 = xfs12.findResource("dir/file");
        assertNotNull(fo12);
        assertEqualContent("content of " + fo1 + " and " + fo12 + " differ", fo1, fo12);

        FileSystem xfs21 = FileSystemFactoryHid.createXMLSystem(getName(), this, url2, url1);
        FileObject fo21 = xfs21.findResource("dir/file");
        assertNotNull(fo21);
        assertEqualContent("content of " + fo2 + " and " + fo21 + " differ", fo2, fo21);
    }
 
Example 16
Source File: FileObjects.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public URI getArchiveURI () {
    return BaseUtilities.toURI(new File (this.zipFile.getName()));
}
 
Example 17
Source File: FileObjects.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public URI getArchiveURI () {
    return BaseUtilities.toURI(this.archiveFile);
}