@Override public Path getPath( final URI uri ) throws IllegalArgumentException, FileSystemNotFoundException, SecurityException { checkNotNull( "uri", uri ); checkCondition( "uri scheme not supported", uri.getScheme().equals( getScheme() ) || uri.getScheme().equals( "default" ) ); checkURI( "uri", uri ); final JGitFileSystem fileSystem = fileSystems.get( extractRepoName( uri ) ); if ( fileSystem == null ) { throw new FileSystemNotFoundException(); } try { return JGitPathImpl.create( fileSystem, URIUtil.decode( extractPath( uri ) ), extractHost( uri ), false ); } catch ( final URIException e ) { return null; } }
throws IllegalArgumentException, IOException, SecurityException, FileSystemAlreadyExistsException { checkNotNull( "uri", uri ); checkCondition( "uri scheme not supported", uri.getScheme().equals( getScheme() ) || uri.getScheme().equals( "default" ) ); checkURI( "uri", uri ); checkNotNull( "env", env ); final URI initURI = URI.create( getScheme() + "://master@" + name + "/readme.md" ); final CommentedOption op = setupOp( env ); final OutputStream stream = newOutputStream( getPath( initURI ), op );
@Override public FileSystem getFileSystem( final URI uri ) throws IllegalArgumentException, FileSystemNotFoundException, SecurityException { checkNotNull( "uri", uri ); checkCondition( "uri scheme not supported", uri.getScheme().equals( getScheme() ) || uri.getScheme().equals( "default" ) ); checkURI( "uri", uri ); final JGitFileSystem fileSystem = fileSystems.get( extractRepoName( uri ) ); if ( fileSystem == null ) { throw new FileSystemNotFoundException( "No filesystem for uri (" + uri + ") found." ); } if ( hasSyncFlag( uri ) ) { try { final String treeRef = "master"; final ObjectId oldHead = JGitUtil.getTreeRefObjectId( fileSystem.gitRepo().getRepository(), treeRef ); final Map<String, String> params = getQueryParams( uri ); syncRepository( fileSystem.gitRepo(), fileSystem.getCredential(), params.get( "sync" ), hasForceFlag( uri ) ); final ObjectId newHead = JGitUtil.getTreeRefObjectId( fileSystem.gitRepo().getRepository(), treeRef ); notifyDiffs( fileSystem, treeRef, "<system>", "<system>", oldHead, newHead ); } catch ( final Exception ex ) { throw new IOException( ex ); } } return fileSystem; }
@Test public void testPathBranchRooted() 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 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 testPathBranchNonRooted2() 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() ).isFalse(); 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 testPathNonBranchRooted() 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( "/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://master@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 testPathNonBranchNonRooted() 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( "path/to/some/place.txt" ); assertThat( path ).isNotNull(); assertThat( path.isAbsolute() ).isFalse(); assertThat( path.toString() ).isEqualTo( "path/to/some/place.txt" ); assertThat( path.toUri().toString() ).isEqualTo( "git://master@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 testPathBranchNonRooted() 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() ).isFalse(); 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( "" ); }