/** * @throws IllegalArgumentException * @see <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Paths.html#get(java.lang.String, java.lang.String...)">JDK JavaDoc</a> */ public static Path get(final String first, final String... more) throws IllegalArgumentException { checkNotNull("first", first); if (first.trim().length() == 0) { return FileSystems.getDefault().getPath(first); } URI uri = null; if (more == null || more.length == 0) { try { uri = new URI(first); } catch (URISyntaxException ex) { try { uri = URI.create(first); } catch (IllegalArgumentException e) { uri = null; } } } if (uri != null && uri.getScheme() != null) { return get(uri); } return FileSystems.getDefault().getPath(first, more); }
private static FileSystemProvider providerOf( final Path path ) { return path.getFileSystem().provider(); }
@Override public void endBatch( final Option... options ) { lockService.unlock(); if ( !fileSystems.isEmpty() ) { final Path path = fileSystems.values().iterator().next().get( 0 ).getRootDirectories().iterator().next(); setAttribute( path, FileSystemState.FILE_SYSTEM_STATE_ATTR, FileSystemState.NORMAL ); } }
@Test public void simpleTests() { final FileSystem fileSystem = new SimpleUnixFileSystem( fsProvider, "/" ); assertThat( fileSystem.isOpen() ).isTrue(); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( System.getProperty( "file.separator" ) ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 1 ).contains( "basic" ); assertThat( fileSystem.getPath( "/path/to/file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); assertThat( fileSystem.getPath( "/path/to/file.txt", null ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); assertThat( fileSystem.getPath( "/path", "to", "file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); try { fileSystem.close(); fail( "can't close this fileSystem" ); } catch ( UnsupportedOperationException ex ) { } assertThat( fileSystem.getFileStores() ).isNotNull().hasSize( 1 ); assertThat( fileSystem.getFileStores().iterator().next().name() ).isEqualTo( "/" ); assertThat( fileSystem.getRootDirectories() ).isNotNull().hasSize( 1 ); assertThat( fileSystem.getRootDirectories().iterator().next().toString() ).isEqualTo( "/" ); assertThat( fileSystem.getRootDirectories().iterator().next().isAbsolute() ).isTrue(); }
assertThat( fs.getRootDirectories() ).hasSize( 2 ); assertThat( fs.getPath( "file.txt" ).toFile() ).isNotNull().exists(); assertThat( fs.getRootDirectories() ).hasSize( 3 ); for ( final Path root : fs.getRootDirectories() ) { if ( root.toAbsolutePath().toUri().toString().contains( "upstream" ) ) { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 2 ); assertThat( fs.getRootDirectories() ).hasSize( 3 ); for ( final Path root : fs.getRootDirectories() ) { if ( root.toAbsolutePath().toUri().toString().contains( "upstream" ) ) { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 3 );
@Test @Ignore public void testDaemob() throws InterruptedException { final URI newRepo = URI.create( "git://repo-name" ); final Map<String, ?> env = new HashMap<String, Object>() {{ put( "init", Boolean.TRUE ); }}; FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); WatchService ws = null; ws = fs.newWatchService(); final Path path = fs.getRootDirectories().iterator().next(); path.register( ws, StandardWatchEventKind.ENTRY_CREATE, StandardWatchEventKind.ENTRY_MODIFY, StandardWatchEventKind.ENTRY_DELETE, StandardWatchEventKind.ENTRY_RENAME ); final WatchKey k = ws.take(); final List<WatchEvent<?>> events = k.pollEvents(); for ( WatchEvent object : events ) { if ( object.kind() == StandardWatchEventKind.ENTRY_MODIFY ) { System.out.println( "Modify: " + object.context().toString() ); } if ( object.kind() == StandardWatchEventKind.ENTRY_RENAME ) { System.out.println( "Rename: " + object.context().toString() ); } if ( object.kind() == StandardWatchEventKind.ENTRY_DELETE ) { System.out.println( "Delete: " + object.context().toString() ); } if ( object.kind() == StandardWatchEventKind.ENTRY_CREATE ) { System.out.println( "Created: " + object.context().toString() ); } } }
private char getSeparator() { if ( usesWindowsFormat ) { return '\\'; } return fs.getSeparator().toCharArray()[ 0 ]; }
@Override public void dispose() { isDisposed = true; ioWatchService.dispose(); for ( final FileSystem fileSystem : getFileSystems() ) { try { fileSystem.close(); } catch ( final Exception ignored ) { } } }
private String getRootDirectory( final org.kie.commons.java.nio.file.Path path ) { final Iterator<FileStore> fileStoreIterator = path.getFileSystem().getFileStores().iterator(); if ( fileStoreIterator.hasNext() ) { return fileStoreIterator.next().name(); } return ""; }
private FileSystem registerFS( final FileSystem fs, final FileSystemType type ) { checkNotNull( "type", type ); if ( fs == null ) { return fs; } if ( ioWatchService != null ) { ioWatchService.addWatchService( fs.newWatchService() ); } synchronized ( this ) { List<FileSystem> fsList = fileSystems.get( type ); if ( fsList == null ) { fsList = new ArrayList<FileSystem>(); fileSystems.put( type, fsList ); } fsList.add( fs ); } return fs; }
private void addFileSystem( final Repository repository, final Map<String, Object> env ) { FileSystem fs = null; final URI fsURI = URI.create( repository.getUri() ); final String scheme = repository.getScheme(); final String alias = repository.getAlias(); try { fs = ioService.newFileSystem( fsURI, env ); } catch ( FileSystemAlreadyExistsException ex ) { fs = ioService.getFileSystem( fsURI ); } fileSystems.addFileSystem( FileSystemFactory.newFS( new HashMap<String, String>() {{ put( scheme + "://" + alias, alias ); }}, fs.supportedFileAttributeViews() ) ); }
@Test public void simpleTests() { final FileSystem fileSystem = new SimpleWindowsFileSystem( roots, fsProvider, "c:\\" ); assertThat( fileSystem.isOpen() ).isTrue(); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "\\" ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 1 ).contains( "basic" ); assertThat( fileSystem.getPath( "c:\\path\\to\\file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); assertThat( fileSystem.getPath( "c:\\path\\to\\file.txt", null ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); assertThat( fileSystem.getPath( "c:\\path", "to", "file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); try { fileSystem.close(); fail( "can't close this fileSystem" ); } catch ( UnsupportedOperationException ex ) { } assertThat( fileSystem.getFileStores() ).isNotNull().hasSize( 2 ); assertThat( fileSystem.getFileStores().iterator().next().name() ).isEqualTo( "c:\\" ); assertThat( fileSystem.getRootDirectories() ).isNotNull().hasSize( 2 ); assertThat( fileSystem.getRootDirectories().iterator().next().toString() ).isEqualTo( "c:\\" ); assertThat( fileSystem.getRootDirectories().iterator().next().isAbsolute() ).isTrue(); }
if ( i < path.length && this.path[ i ] != fs.getSeparator().charAt( 0 ) ) { return false;
private boolean deleteRepo( final FileSystem fileSystem ) { final File gitDir = ( (JGitFileSystem) fileSystem ).gitRepo().getRepository().getDirectory(); fileSystem.close(); try { FileUtils.delete( gitDir, FileUtils.RECURSIVE ); closedFileSystems.remove( fileSystem ); fileSystems.remove( ( (JGitFileSystem) fileSystem ).id() ); return true; } catch ( java.io.IOException e ) { throw new IOException( e ); } }
@Test public void checkGetFileStore() { final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider(); final Path path = GeneralPathImpl.create( fsProvider.getFileSystem( URI.create( "file:///" ) ), "/path/to/file.txt", false ); assertThat( fsProvider.getFileStore( path ) ).isNotNull(); assertThat( fsProvider.getFileSystem( path.toUri() ).getFileStores() ).isNotNull().contains( fsProvider.getFileStore( path ) ); }
@Override public boolean startsWith( final String other ) throws InvalidPathException { checkNotNull( "other", other ); return startsWith( getFileSystem().getPath( other ) ); }
@Override public void startBatch( final Option... options ) { lockService.lock(); if ( !fileSystems.isEmpty() ) { final Path path = fileSystems.values().iterator().next().get( 0 ).getRootDirectories().iterator().next(); setAttribute( path, FileSystemState.FILE_SYSTEM_STATE_ATTR, FileSystemState.BATCH ); } }
if (selectedForm == null) { String rootPath = processPath.getRoot().toUri().toString(); if (!rootPath.endsWith(processPath.getFileSystem().getSeparator())) { rootPath +=processPath.getFileSystem().getSeparator();