private void copyDirectory( final JGitPathImpl source, final JGitPathImpl target, final CopyOption... options ) { final List<JGitPathImpl> directories = new ArrayList<JGitPathImpl>(); for ( final Path path : newDirectoryStream( source, null ) ) { final JGitPathImpl gPath = toPathImpl( path ); final Pair<PathType, ObjectId> pathResult = checkPath( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); if ( pathResult.getK1() == DIRECTORY ) { directories.add( gPath ); continue; } final JGitPathImpl gTarget = composePath( target, (JGitPathImpl) gPath.getFileName() ); copyFile( gPath, gTarget ); } for ( final JGitPathImpl directory : directories ) { createDirectory( composePath( target, (JGitPathImpl) directory.getFileName() ) ); } }
@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 ); }
outStream4.close(); final DirectoryStream<Path> stream1 = PROVIDER.newDirectoryStream( PROVIDER.getPath( URI.create( "git://user_branch@filter-dirstream-test-repo/" ) ), new DirectoryStream.Filter<Path>() { @Override public boolean accept( final Path entry ) throws org.kie.commons.java.nio.IOException { final DirectoryStream<Path> stream2 = PROVIDER.newDirectoryStream( PROVIDER.getPath( URI.create( "git://master@filter-dirstream-test-repo/" ) ), new DirectoryStream.Filter<Path>() { @Override public boolean accept( final Path entry ) throws org.kie.commons.java.nio.IOException {
outStream3.close(); final DirectoryStream<Path> stream1 = PROVIDER.newDirectoryStream( PROVIDER.getPath( URI.create( "git://user_branch@dirstream-test-repo/" ) ), null ); final DirectoryStream<Path> stream2 = PROVIDER.newDirectoryStream( PROVIDER.getPath( URI.create( "git://user_branch@dirstream-test-repo/other" ) ), null ); final DirectoryStream<Path> stream3 = PROVIDER.newDirectoryStream( PROVIDER.getPath( URI.create( "git://user_branch@dirstream-test-repo/other/path" ) ), null ); final DirectoryStream<Path> stream4 = PROVIDER.newDirectoryStream( PROVIDER.getPath( URI.create( "git://master@dirstream-test-repo/" ) ), null ); PROVIDER.newDirectoryStream( path, null ); failBecauseExceptionWasNotThrown( NotDirectoryException.class ); } catch ( NotDirectoryException ex ) { PROVIDER.newDirectoryStream( crazyPath, null ); failBecauseExceptionWasNotThrown( NotDirectoryException.class ); } catch ( NotDirectoryException ex ) { assertThat( PROVIDER.newDirectoryStream( crazyPath, null ) ).isNotNull().hasSize( 1 );
final DirectoryStream<Path> stream3 = PROVIDER.newDirectoryStream( dir, null );
final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( PROVIDER.getPath( URI.create( "git://other_branch@copybranch-test-repo/" ) ), null );
@Test public void testNewFileSystem() { final URI newRepo = URI.create( "git://repo-name" ); final FileSystem fs = PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); assertThat( fs ).isNotNull(); final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( PROVIDER.getPath( newRepo ), null ); assertThat( stream ).isNotNull().hasSize( 0 ); try { PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); failBecauseExceptionWasNotThrown( FileSystemAlreadyExistsException.class ); } catch ( final Exception ex ) { } PROVIDER.newFileSystem( URI.create( "git://repo-name2" ), EMPTY_ENV ); }
@Test public void testNewFileSystemInited() { final URI newRepo = URI.create( "git://init-repo-name" ); final Map<String, ?> env = new HashMap<String, Object>() {{ put( "init", Boolean.TRUE ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( PROVIDER.getPath( newRepo ), null ); assertThat( stream ).isNotNull().hasSize( 1 ); }
final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( target, null ); final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( target, null ); final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( target, null ); final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( target, null );
assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 2 ); } else if ( root.toAbsolutePath().toUri().toString().contains( "origin" ) ) { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 1 ); } else { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 2 ); assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 3 ); } else if ( root.toAbsolutePath().toUri().toString().contains( "origin" ) ) { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 1 ); } else { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 3 );