@Override public void createDirectory( final Path path, final FileAttribute<?>... attrs ) throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { checkNotNull( "path", path ); final JGitPathImpl gPath = toPathImpl( path ); final Pair<PathType, ObjectId> result = checkPath( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); if ( !result.getK1().equals( NOT_FOUND ) ) { throw new FileAlreadyExistsException( path.toString() ); } try { final OutputStream outputStream = newOutputStream( path.resolve( ".gitignore" ) ); outputStream.write( "# empty\n".getBytes() ); outputStream.close(); } catch ( final Exception e ) { throw new IOException( e ); } }
@Test public void testIsSameFile() throws IOException { final URI newRepo = URI.create( "git://issamefile-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@issamefile-test-repo/path/to/myfile1.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final Path path2 = PROVIDER.getPath( URI.create( "git://user_branch@issamefile-test-repo/path/to/myfile2.txt" ) ); final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); final Path path3 = PROVIDER.getPath( URI.create( "git://user_branch@issamefile-test-repo/path/to/myfile3.txt" ) ); final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close(); assertThat( PROVIDER.isSameFile( path, path2 ) ).isTrue(); assertThat( PROVIDER.isSameFile( path, path3 ) ).isTrue(); }
@Test public void testMoveFiles() throws IOException { final URI newRepo = URI.create( "git://moveasset-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@moveasset-test-repo/myfile1.txt" ) ); { final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); } final Path path2 = PROVIDER.getPath( URI.create( "git://user_branch@moveasset-test-repo/other/path/myfile2.txt" ) ); { final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); } final Path path3 = PROVIDER.getPath( URI.create( "git://user_branch@moveasset-test-repo/myfile3.txt" ) ); { final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close(); } final Path target = PROVIDER.getPath( URI.create( "git://user_branch@moveasset-test-repo/myfile1.txt" ) ); try { PROVIDER.move( path, target ); } catch ( final Exception e ) { fail( "should move file", e ); } }
@Test public void testCopyFiles() throws IOException { final URI newRepo = URI.create( "git://copyasset-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@copyasset-test-repo/myfile1.txt" ) ); { final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); } final Path path2 = PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/other/path/myfile2.txt" ) ); { final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); } final Path path3 = PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/myfile3.txt" ) ); { final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close(); } final Path target = PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/myfile1.txt" ) ); PROVIDER.copy( path, target ); final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/" ) ), null ); for ( Path path1 : stream ) { System.out.println("content: " + path1.toUri()); } assertThat( stream ).isNotNull().hasSize( 3 ); }
final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close();
@Test public void testCheckAccess() throws Exception { final URI newRepo = URI.create( "git://checkaccess-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@checkaccess-test-repo/path/to/myfile1.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); PROVIDER.checkAccess( path ); final Path path_to_dir = PROVIDER.getPath( URI.create( "git://master@checkaccess-test-repo/path/to" ) ); PROVIDER.checkAccess( path_to_dir ); final Path path_not_exists = PROVIDER.getPath( URI.create( "git://master@checkaccess-test-repo/path/to/some.txt" ) ); try { PROVIDER.checkAccess( path_not_exists ); failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException e ) { } }
@Test public void testGetFileStore() throws Exception { final URI newRepo = URI.create( "git://filestore-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@filestore-test-repo/path/to/myfile1.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final FileStore fileStore = PROVIDER.getFileStore( path ); assertThat( fileStore ).isNotNull(); assertThat( fileStore.getAttribute( "readOnly" ) ).isEqualTo( Boolean.FALSE ); }
final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close();
final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close(); final OutputStream outStream4 = PROVIDER.newOutputStream( path4 ); outStream4.write( "my cool content".getBytes() ); outStream4.close();
final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close();
@Test public void testDeleteBranchIfExists() throws IOException { final URI newRepo = URI.create( "git://deletebranchifexists1-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@deletebranchifexists1-test-repo/path/to/myfile.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() ); outStream.close(); PROVIDER.newInputStream( path ).close(); assertThat( PROVIDER.deleteIfExists( PROVIDER.getPath( URI.create( "git://user_branch@deletebranchifexists1-test-repo" ) ) ) ).isTrue(); assertThat( PROVIDER.deleteIfExists( PROVIDER.getPath( URI.create( "git://not_user_branch@deletebranchifexists1-test-repo" ) ) ) ).isFalse(); assertThat( PROVIDER.deleteIfExists( PROVIDER.getPath( URI.create( "git://user_branch@deletebranchifexists1-test-repo" ) ) ) ).isFalse(); }
final OutputStream outRootStream = PROVIDER.newOutputStream( _root ); outRootStream.write( "my cool content".getBytes() ); outRootStream.close(); final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close();
@Test public void testDeleteBranch() throws IOException { final URI newRepo = URI.create( "git://delete-branch-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@delete-branch-test-repo/path/to/myfile.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() ); outStream.close(); PROVIDER.newInputStream( path ).close(); PROVIDER.delete( PROVIDER.getPath( URI.create( "git://user_branch@delete-branch-test-repo" ) ) ); try { PROVIDER.delete( PROVIDER.getPath( URI.create( "git://user_branch@delete-branch-test-repo" ) ) ); failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException ex ) { } try { PROVIDER.delete( PROVIDER.getPath( URI.create( "git://some_user_branch@delete-branch-test-repo" ) ) ); failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException ex ) { } }
@Test public void testDeleteIfExists() throws IOException { final URI newRepo = URI.create( "git://deleteifexists1-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@deleteifexists1-test-repo/path/to/myfile.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() ); outStream.close(); PROVIDER.newInputStream( path ).close(); assertThat( PROVIDER.deleteIfExists( PROVIDER.getPath( URI.create( "git://user_branch@deleteifexists1-test-repo/non_existent_path" ) ) ) ).isFalse(); try { PROVIDER.deleteIfExists( PROVIDER.getPath( URI.create( "git://user_branch@deleteifexists1-test-repo/path/to/" ) ) ); failBecauseExceptionWasNotThrown( DirectoryNotEmptyException.class ); } catch ( DirectoryNotEmptyException ex ) { } assertThat( PROVIDER.deleteIfExists( path ) ).isTrue(); }
@Test public void testIsHidden() throws IOException { final URI newRepo = URI.create( "git://ishidden-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@ishidden-test-repo/path/to/.myfile.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() ); outStream.close(); final Path path2 = PROVIDER.getPath( URI.create( "git://user_branch@ishidden-test-repo/path/to/myfile.txt" ) ); final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); assertThat( outStream2 ).isNotNull(); outStream2.write( "my cool content".getBytes() ); outStream2.close(); assertThat( PROVIDER.isHidden( PROVIDER.getPath( URI.create( "git://user_branch@ishidden-test-repo/path/to/.myfile.txt" ) ) ) ).isTrue(); assertThat( PROVIDER.isHidden( PROVIDER.getPath( URI.create( "git://user_branch@ishidden-test-repo/path/to/myfile.txt" ) ) ) ).isFalse(); assertThat( PROVIDER.isHidden( PROVIDER.getPath( URI.create( "git://user_branch@ishidden-test-repo/path/to/non_existent/.myfile.txt" ) ) ) ).isTrue(); assertThat( PROVIDER.isHidden( PROVIDER.getPath( URI.create( "git://user_branch@ishidden-test-repo/path/to/non_existent/myfile.txt" ) ) ) ).isFalse(); assertThat( PROVIDER.isHidden( PROVIDER.getPath( URI.create( "git://user_branch@ishidden-test-repo/" ) ) ) ).isFalse(); assertThat( PROVIDER.isHidden( PROVIDER.getPath( URI.create( "git://user_branch@ishidden-test-repo/some" ) ) ) ).isFalse(); }
@Test public void testNewOutputStreamWithJGitOp() throws Exception { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "master", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "myfile.txt", tempFile( "temp\n.origin\n.content" ) ); }} ); commit( origin, "user_branch", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "path/to/some/file/myfile.txt", tempFile( "some\n.content\nhere" ) ); }} ); final URI newRepo = URI.create( "git://outstreamwithop-test-repo" ); final Map<String, Object> env = new HashMap<String, Object>() {{ put( JGitFileSystemProvider.GIT_DEFAULT_REMOTE_NAME, origin.getRepository().getDirectory().toString() ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final SimpleDateFormat formatter = new SimpleDateFormat( "dd/MM/yyyy" ); final CommentedOption op = new CommentedOption( "User Tester", "user.tester@example.com", "omg, is it the end?", formatter.parse( "31/12/2012" ) ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@outstreamwithop-test-repo/some/path/myfile.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path, op ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() ); outStream.close(); final InputStream inStream = PROVIDER.newInputStream( path ); final String content = new Scanner( inStream ).useDelimiter( "\\A" ).next(); inStream.close(); assertThat( content ).isNotNull().isEqualTo( "my cool content" ); }
final OutputStream outStream = PROVIDER.newOutputStream( path ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() ); PROVIDER.newOutputStream( PROVIDER.getPath( URI.create( "git://user_branch@outstream-test-repo/some/path/" ) ) ); failBecauseExceptionWasNotThrown( org.kie.commons.java.nio.IOException.class ); } catch ( Exception e ) {
final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close();
final OutputStream outStream = PROVIDER.newOutputStream( path ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() );
final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close();