private ExtendedAttributeView getFileAttributeView(final JGitPathImpl path, final String name, final LinkOption... options) { final ExtendedAttributeView view = path.getAttrView(name); if (view == null) { if (name.equals("basic")) { final JGitBasicAttributeView newView = new JGitBasicAttributeView(path); path.addAttrView(newView); return newView; } else if (name.equals("extended")) { final JGitHiddenAttributeView newView = new JGitHiddenAttributeView(path); path.addAttrView(newView); return newView; } else if (name.equals("version")) { final JGitVersionAttributeView newView = new JGitVersionAttributeView(path); path.addAttrView(newView); return newView; } } return view; }
@Test public void accessOldVersions() throws Exception { final URI newRepo = URI.create("git://old-versions-test-repo"); final FileSystem fs = provider.newFileSystem(newRepo, new HashMap<String, Object>() {{ put(JGitFileSystemProviderConfiguration.GIT_ENV_KEY_INIT, "true"); }}); assertThat(fs).isNotNull(); for (int i = 0; i < 5; i++) { final Path path = provider.getPath(URI.create("git://old-versions-test-repo/some/path/myfile.txt")); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write(("my cool content" + i).getBytes()); outStream.close(); } final Path path = provider.getPath(URI.create("git://old-versions-test-repo/some/path/myfile.txt")); final JGitVersionAttributeView attrs = provider.getFileAttributeView(path, JGitVersionAttributeView.class); assertThat(attrs.readAttributes().history().records().size()).isEqualTo(5); for (int i = 0; i < 5; i++) { final Path oldPath = provider.getPath(URI.create("git://" + attrs.readAttributes().history().records().get(i).id() + "@old-versions-test-repo/some/path/myfile.txt")); final InputStream stream = provider.newInputStream(oldPath); assertNotNull(stream); final String content = new Scanner(stream).useDelimiter("\\A").next(); assertEquals("my cool content" + i, content); } }
@Override public VersionAttributes readAttributes() throws IOException { if (attrs == null) { attrs = buildAttrs(path.getFileSystem(), path.getRefTree(), path.getPath()); } return attrs; }
when(path.getPath()).thenReturn("path/to/file2.txt"); final VersionAttributes versionAttributes = new JGitVersionAttributeView(path).readAttributes();
when(path.getPath()).thenReturn("path/to/file2.txt"); final VersionAttributes versionAttributes = new JGitVersionAttributeView(path).readAttributes();
@Test public void accessOldVersions() throws Exception { final URI newRepo = URI.create("git://old-versions-test-repo"); final FileSystem fs = provider.newFileSystem(newRepo, new HashMap<String, Object>() {{ put(JGitFileSystemProviderConfiguration.GIT_ENV_KEY_INIT, "true"); }}); assertThat(fs).isNotNull(); for (int i = 0; i < 5; i++) { final Path path = provider.getPath(URI.create("git://old-versions-test-repo/some/path/myfile.txt")); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write(("my cool content" + i).getBytes()); outStream.close(); } final Path path = provider.getPath(URI.create("git://old-versions-test-repo/some/path/myfile.txt")); final JGitVersionAttributeView attrs = provider.getFileAttributeView(path, JGitVersionAttributeView.class); assertThat(attrs.readAttributes().history().records().size()).isEqualTo(5); for (int i = 0; i < 5; i++) { final Path oldPath = provider.getPath(URI.create("git://" + attrs.readAttributes().history().records().get(i).id() + "@old-versions-test-repo/some/path/myfile.txt")); final InputStream stream = provider.newInputStream(oldPath); assertNotNull(stream); final String content = new Scanner(stream).useDelimiter("\\A").next(); assertEquals("my cool content" + i, content); } }
return newView; } else if (type == VersionAttributeView.class || type == JGitVersionAttributeView.class) { final V newView = (V) new JGitVersionAttributeView(gPath); gPath.addAttrView(newView); return newView;
JGitVersionAttributeView.class); assertThat(attrs.readAttributes().history().records().size()).isEqualTo(5);
JGitVersionAttributeView.class); assertThat(attrs.readAttributes().history().records().size()).isEqualTo(5);
JGitVersionAttributeView.class); assertThat(attrs.readAttributes().history().records().size()).isEqualTo(1); assertThat(attrs.readAttributes().history().records().get(0).uri()).isNotNull(); assertThat(attrs.readAttributes().isDirectory()).isFalse(); assertThat(attrs.readAttributes().isRegularFile()).isTrue(); assertThat(attrs.readAttributes().creationTime()).isNotNull(); assertThat(attrs.readAttributes().lastModifiedTime()).isNotNull(); assertThat(attrs.readAttributes().size()).isEqualTo(15L);
JGitVersionAttributeView.class); assertThat(attrs.readAttributes().history().records().size()).isEqualTo(1); assertThat(attrs.readAttributes().history().records().get(0).uri()).isNotNull(); assertThat(attrs.readAttributes().isDirectory()).isFalse(); assertThat(attrs.readAttributes().isRegularFile()).isTrue(); assertThat(attrs.readAttributes().creationTime()).isNotNull(); assertThat(attrs.readAttributes().lastModifiedTime()).isNotNull(); assertThat(attrs.readAttributes().size()).isEqualTo(15L);
JGitVersionAttributeView.class, options); return (A) view.readAttributes(); } else if (type == HiddenAttributes.class) { final JGitHiddenAttributeView view = getFileAttributeView(path,