@Override public boolean accepts( final Path path ) { final String pattern = getPattern(); final String suffix = "." + pattern; final String uri = path.toUri().toString(); return uri.substring( uri.length() - suffix.length() ).equals( suffix ); }
@Override public boolean accept( final org.kie.commons.java.nio.file.Path path ) { boolean accept = super.accept( path ); if ( !accept ) { return accept; } if ( !Files.isRegularFile( path ) ) { return false; } final String uri = path.toUri().toString(); if ( uri.substring( uri.length() - extension.length() ).equals( extension ) ) { return true; } return false; }
@Override public Object value() { return file.toUri().toString(); } } );
@Override public String uri() { return fs.getPath( commit.name(), path ).toUri().toString(); } } );
/** * @throws IllegalArgumentException * @throws ProviderNotFoundException * @throws ServiceConfigurationError * @throws IOException * @throws SecurityException * @see <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystems.html#newFileSystem(java.nio.file.Path, java.lang.ClassLoader)">Original JavaDoc</a> */ public static FileSystem newFileSystem(final Path path, final ClassLoader loader) throws IllegalArgumentException, ProviderNotFoundException, ServiceConfigurationError, IOException, SecurityException { checkNotNull("path", path); final Map<String, ?> env = emptyMap(); return newFileSystem(path.toUri(), env, null); }
@Override public boolean accepts(final Path path) { final String uri = path.toUri().toString(); return uri.substring(uri.length() - extension.length()).equals(extension); }
@Override public Map<String, String> buildContent() { return new HashMap<String, String>() {{ put( "fs_scheme", fileSystem.getRootDirectories().iterator().next().toUri().getScheme() ); put( "fs_id", ( (FileSystemId) fileSystem ).id() ); put( "fs_uri", fileSystem.toString() ); }}; } }
private Path makePath(final String prefix, final String suffix) throws URISyntaxException { Path path = mock(Path.class); when( path.toUri() ).thenReturn( new URI(prefix + suffix) ); return path; }
private Path makePath(final String prefix, final String suffix) throws URISyntaxException { Path path = mock(Path.class); when( path.toUri() ).thenReturn( new URI(prefix + suffix) ); return path; }
@Override public boolean accepts(final Path path) { final String uri = path.toUri().toString(); return uri.substring(uri.length() - extension.length()).equals(extension); }
private void visitPaths( final DirectoryStream<org.kie.commons.java.nio.file.Path> directoryStream ) { for ( final org.kie.commons.java.nio.file.Path path : directoryStream ) { if ( Files.isDirectory( path ) ) { visitPaths( Files.newDirectoryStream( path ) ); } else if ( filter.accept( path ) ) { final String destinationPath = path.toUri().toString().substring( projectPrefix.length() + 1 ); final InputStream is = ioService.newInputStream( path ); final BufferedInputStream bis = new BufferedInputStream( is ); kieFileSystem.write( destinationPath, KieServices.Factory.get().getResources().newInputStreamResource( bis ) ); handles.put( destinationPath, paths.convert( path ) ); } } }
@Test public void testGetPath() { final URI newRepo = URI.create( "git://new-get-repo-name" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@new-get-repo-name/home" ) ); assertThat( path ).isNotNull(); assertThat( path.getRoot().toString() ).isEqualTo( "/" ); assertThat( path.getRoot().toRealPath().toUri().toString() ).isEqualTo( "git://master@new-get-repo-name/" ); assertThat( path.toString() ).isEqualTo( "/home" ); final Path pathRelative = PROVIDER.getPath( URI.create( "git://master@new-get-repo-name/:home" ) ); assertThat( pathRelative ).isNotNull(); assertThat( pathRelative.toRealPath().toUri().toString() ).isEqualTo( "git://master@new-get-repo-name/:home" ); assertThat( pathRelative.getRoot().toString() ).isEqualTo( "" ); assertThat( pathRelative.toString() ).isEqualTo( "home" ); }
@Test public void testSimpleBranchedGitRoot() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "/", "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/"); assertThat(path.getRoot().toString()).isEqualTo("/"); assertThat(path.getNameCount()).isEqualTo(0); }
@Test public void testSimpleBranchedGitRelative() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "home", "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isFalse(); assertThat(path.toString()).isEqualTo("home"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/:home"); assertThat(path.getRoot().toString()).isEqualTo(""); assertThat(path.getNameCount()).isEqualTo(1); }
@Test public void testPathBranchRooted2() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); when( fsProvider.isDefault() ).thenReturn( false ); when( fsProvider.getScheme() ).thenReturn( "git" ); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); final Path path = fileSystem.getPath( "test-branch", "/path/to", "some/place.txt" ); assertThat( path ).isNotNull(); assertThat( path.isAbsolute() ).isTrue(); assertThat( path.toString() ).isEqualTo( "/path/to/some/place.txt" ); assertThat( path.toUri().toString() ).isEqualTo( "git://test-branch@my-repo/path/to/some/place.txt" ); assertThat( path.getNameCount() ).isEqualTo( 4 ); assertThat( path.getName( 0 ).toString() ).isNotNull().isEqualTo( "path" ); assertThat( path.getRoot().toString() ).isNotNull().isEqualTo( "/" ); }
@Test public void testSimpleImplicitBranchGit() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "/path/to/some/place.txt", "my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/some/place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/place.txt"); assertThat(path.getNameCount()).isEqualTo(4); assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path"); assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/"); }
@Test public void testSimpleBranchedGitRoot2() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "/path/to/some/place.txt", "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/some/place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/place.txt"); assertThat(path.getNameCount()).isEqualTo(4); assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path"); assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/"); }
@Test public void testSimpleBranchedGitRoot2Spaced() throws URIException { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, URIUtil.decode("/path/to/some/some%20place.txt"), "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/some/some place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/some%20place.txt"); assertThat(path.getNameCount()).isEqualTo(4); assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path"); assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/"); }
@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 ) ); }
@Test public void testSimpleBranchedGit() { final Path path = JGitPathImpl.create(fs, "", "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/"); assertThat(path.getRoot()).isEqualTo(path); assertThat(path.getNameCount()).isEqualTo(0); assertThat(path.getRoot()).isNotNull().isEqualTo(path); }