diff --git a/uberfire-nio2-backport/uberfire-nio2-impls/uberfire-nio2-jgit/src/main/java/org/uberfire/java/nio/fs/jgit/JGitFileSystemProvider.java b/uberfire-nio2-backport/uberfire-nio2-impls/uberfire-nio2-jgit/src/main/java/org/uberfire/java/nio/fs/jgit/JGitFileSystemProvider.java index 9b43ed4e9d..9b48079773 100644 --- a/uberfire-nio2-backport/uberfire-nio2-impls/uberfire-nio2-jgit/src/main/java/org/uberfire/java/nio/fs/jgit/JGitFileSystemProvider.java +++ b/uberfire-nio2-backport/uberfire-nio2-impls/uberfire-nio2-jgit/src/main/java/org/uberfire/java/nio/fs/jgit/JGitFileSystemProvider.java @@ -1980,14 +1980,17 @@ private void notifyAllDiffs() { for ( Map.Entry> jGitFileSystemMapEntry : oldHeadsOfPendingDiffs.entrySet() ) { for ( Map.Entry branchNameNotificationModelEntry : jGitFileSystemMapEntry.getValue().entrySet() ) { final ObjectId newHead = JGitUtil.getTreeRefObjectId( jGitFileSystemMapEntry.getKey().gitRepo().getRepository(), branchNameNotificationModelEntry.getKey() ); - - notifyDiffs( jGitFileSystemMapEntry.getKey(), - branchNameNotificationModelEntry.getKey(), - branchNameNotificationModelEntry.getValue().getSessionId(), - branchNameNotificationModelEntry.getValue().getUserName(), - branchNameNotificationModelEntry.getValue().getMessage(), - branchNameNotificationModelEntry.getValue().getOriginalHead(), - newHead ); + try { + notifyDiffs( jGitFileSystemMapEntry.getKey(), + branchNameNotificationModelEntry.getKey(), + branchNameNotificationModelEntry.getValue().getSessionId(), + branchNameNotificationModelEntry.getValue().getUserName(), + branchNameNotificationModelEntry.getValue().getMessage(), + branchNameNotificationModelEntry.getValue().getOriginalHead(), + newHead ); + } catch ( final Exception ex ) { + LOG.error( String.format( "Couldn't produce diff notification for repository `%s` branch `%s`.", jGitFileSystemMapEntry.getKey().toString(), branchNameNotificationModelEntry.getKey() ), ex ); + } } } @@ -2003,13 +2006,13 @@ private void notifyAllDiffs() { } } - private void notifyDiffs( final JGitFileSystem fs, - final String _tree, - final String sessionId, - final String userName, - final String message, - final ObjectId oldHead, - final ObjectId newHead ) { + void notifyDiffs( final JGitFileSystem fs, + final String _tree, + final String sessionId, + final String userName, + final String message, + final ObjectId oldHead, + final ObjectId newHead ) { final String tree; if ( _tree.startsWith( "refs/" ) ) { diff --git a/uberfire-nio2-backport/uberfire-nio2-impls/uberfire-nio2-jgit/src/test/java/org/uberfire/java/nio/fs/jgit/JGitFileSystemProviderTest.java b/uberfire-nio2-backport/uberfire-nio2-impls/uberfire-nio2-jgit/src/test/java/org/uberfire/java/nio/fs/jgit/JGitFileSystemProviderTest.java index 075d79e8f4..71ef6406e9 100644 --- a/uberfire-nio2-backport/uberfire-nio2-impls/uberfire-nio2-jgit/src/test/java/org/uberfire/java/nio/fs/jgit/JGitFileSystemProviderTest.java +++ b/uberfire-nio2-backport/uberfire-nio2-impls/uberfire-nio2-jgit/src/test/java/org/uberfire/java/nio/fs/jgit/JGitFileSystemProviderTest.java @@ -59,6 +59,7 @@ import org.uberfire.java.nio.fs.jgit.util.JGitUtil.*; import static org.fest.assertions.api.Assertions.*; +import static org.mockito.Mockito.*; import static org.uberfire.java.nio.file.StandardDeleteOption.*; import static org.uberfire.java.nio.fs.jgit.util.JGitUtil.*; @@ -1354,6 +1355,42 @@ public void checkProperAmend() throws Exception { assertThat( attrs.readAttributes().history().records().size() ).isEqualTo( 5 ); } + @Test + public void checkBatchError() throws Exception { + final URI newRepo = URI.create( "git://outstream-test-repo" ); + + final FileSystem fs = provider.newFileSystem( newRepo, new HashMap() {{ + put( JGitFileSystemProvider.GIT_ENV_KEY_INIT, "true" ); + }} ); + + provider = spy( provider ); + + doThrow( new RuntimeException() ). + when( provider ). + notifyDiffs( any( JGitFileSystem.class ), + any( String.class ), + any( String.class ), + any( String.class ), + any( String.class ), + any( ObjectId.class ), + any( ObjectId.class ) ); + + assertThat( fs ).isNotNull(); + + final Path path = provider.getPath( URI.create( "git://user_branch@outstream-test-repo/some/path/myfile.txt" ) ); + provider.setAttribute( path, FileSystemState.FILE_SYSTEM_STATE_ATTR, FileSystemState.BATCH ); + final OutputStream outStream = provider.newOutputStream( path ); + assertThat( outStream ).isNotNull(); + outStream.write( ( "my cool content" ).getBytes() ); + outStream.close(); + + try { + provider.setAttribute( path, FileSystemState.FILE_SYSTEM_STATE_ATTR, FileSystemState.NORMAL ); + } catch ( Exception ex ) { + fail( "Batch can't fail!", ex ); + } + } + private static interface MyAttrs extends BasicFileAttributes { }