/** * @param path A path for a JGit file system. Must not be null. * @return The file path for an niogit directory that contains the given path's filesystem. */ public String getNiogitRepoPath(org.uberfire.java.nio.file.Path path) { try { final JGitPathImpl gPath = (JGitPathImpl) path; final File directory = gPath.getFileSystem().getGit().getRepository().getDirectory(); return directory.toURI().toString(); } catch (ClassCastException cce) { throw new IllegalArgumentException("Cannot get .niogit directory for non-jgit path.", cce); } }
@Override public Repository open(final T client, final String name) throws RepositoryNotFoundException, ServiceNotAuthorizedException, ServiceNotEnabledException, ServiceMayNotContinueException { final JGitFileSystem fs = fsManager.get(name); if (fs == null) { throw new RepositoryNotFoundException(name); } return fs.getGit().getRepository(); }
private void prepareHook(final Integer code) throws IOException { File destHookFile = fs.getGit().getRepository().getDirectory().toPath().resolve(HOOKS_FOLDER).resolve("post-commit").toFile(); FileUtils.write(destHookFile, SCRIPT + code, Charset.defaultCharset()); Set<PosixFilePermission> perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.GROUP_EXECUTE); perms.add(PosixFilePermission.OTHERS_EXECUTE); perms.add(PosixFilePermission.OWNER_EXECUTE); Files.setPosixFilePermissions(destHookFile.toPath(), perms); }
private void prepareHook(final Integer code) throws IOException { File destHookFile = fs.getGit().getRepository().getDirectory().toPath().resolve(HOOKS_FOLDER).resolve("post-commit").toFile(); FileUtils.write(destHookFile, SCRIPT + code, Charset.defaultCharset()); Set<PosixFilePermission> perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.GROUP_EXECUTE); perms.add(PosixFilePermission.OTHERS_EXECUTE); perms.add(PosixFilePermission.OWNER_EXECUTE); Files.setPosixFilePermissions(destHookFile.toPath(), perms); }
@Override public FileTime lastModifiedTime() { if (lastModifiedDate == null) { try { lastModifiedDate = new FileTimeImpl(fs.getGit().getLastCommit(ref).getCommitterIdent().getWhen().getTime()); } catch (final Exception e) { lastModifiedDate = new FileTimeImpl(0); } } return lastModifiedDate; }
private void removeSpaceDirectory(final Space space) { final URI configPathURI = URI.create(SpacesAPI.resolveConfigFileSystemPath(SpacesAPI.Scheme.DEFAULT, space.getName())); final Path configPath = ioService.get(configPathURI); final JGitPathImpl configGitPath = (JGitPathImpl) configPath; final File spacePath = configGitPath.getFileSystem().getGit().getRepository().getDirectory().getParentFile().getParentFile(); ioService.delete(configPath.getFileSystem().getPath("")); spacePath.delete(); }
@Override public FileTime creationTime() { if (creationDate == null) { try { creationDate = new FileTimeImpl(fs.getGit().getFirstCommit(ref).getCommitterIdent().getWhen().getTime()); } catch (final Exception e) { creationDate = new FileTimeImpl(0); } } return creationDate; }
protected void cleanupOrigin(Repository repository) { try { // AF-1715: Cleaning origin to prevent errors while importing the new generated repo. Git git = ((JGitPathImpl) pathUtil.convert(repository.getDefaultBranch().get().getPath())).getFileSystem().getGit(); new RemoveRemote(git,"origin",REMOTE_ORIGIN_REF).execute(); } catch (GitException e) { log.warn("Error cleaning up origin for repository '{}': {}", repository.getAlias(), e); } }
private RevCommit writeFile(final JGitFileSystem fs, final Path path, String branch) throws IOException, GitAPIException { final OutputStream stream = provider.newOutputStream(path); logger.info("Writing file: " + path.getFileName().toString()); stream.write("my cool content".getBytes()); stream.close(); return this.getCommitsFromBranch((GitImpl) fs.getGit(), branch).get(0); }
protected void cleanupOrigin(Repository repository) { try { // AF-1715: Cleaning origin to prevent errors while importing the new generated repo. Git git = ((JGitPathImpl) pathUtil.convert(repository.getDefaultBranch().get().getPath())).getFileSystem().getGit(); new RemoveRemote(git,"origin",REMOTE_ORIGIN_REF).execute(); } catch (GitException e) { log.warn("Error cleaning up origin for repository '{}': {}", repository.getAlias(), e); } }
private RevCommit writeFile(final JGitFileSystem fs, final Path path, String branch) throws IOException, GitAPIException { final OutputStream stream = provider.newOutputStream(path); logger.info("Writing file: " + path.getFileName().toString()); stream.write("my cool content".getBytes()); stream.close(); return this.getCommitsFromBranch((GitImpl) fs.getGit(), branch).get(0); }
@Override public FileStore getFileStore(final Path path) throws IOException, SecurityException { checkNotNull("path", path); return new JGitFileStore(toPathImpl(path).getFileSystem().getGit().getRepository()); }
public void deleteBranch(final JGitPathImpl path) { final Ref branch = path.getFileSystem().getGit().getRef(path.getRefTree()); if (branch == null) { throw new NoSuchFileException(path.toString()); } try { path.getFileSystem().lock(); path.getFileSystem().getGit().deleteRef(branch); } finally { path.getFileSystem().unlock(); } }
private void cherryPick(final JGitPathImpl source, final JGitPathImpl target, final String... commits) { try { target.getFileSystem().lock(); source.getFileSystem().getGit().cherryPick(target, commits); } finally { target.getFileSystem().unlock(); } }
@Override public InputStream newInputStream(final Path path, final OpenOption... options) throws IllegalArgumentException, UnsupportedOperationException, IOException, SecurityException { checkNotNull("path", path); final JGitPathImpl gPath = toPathImpl(path); return gPath.getFileSystem().getGit().blobAsInputStream(gPath.getRefTree(), gPath.getPath()); }
private void postCommitHook(final JGitFileSystem fileSystem) { ProcessResult result = detectedFS.runHookIfPresent(fileSystem.getGit().getRepository(), "post-commit", new String[0]); if(result.getStatus().equals(ProcessResult.Status.OK)) { fileSystem.notifyPostCommit(result.getExitCode()); } }
@Test public void resolveByRepositoryTest() { JGitFileSystem fsSimpleName = ((JGitFileSystemProxy) provider.newFileSystem(URI.create("git://repo"), EMPTY_ENV)).getRealJGitFileSystem(); JGitFileSystemProvider.RepositoryResolverImpl<Object> objectRepositoryResolver = provider.new RepositoryResolverImpl<>(); assertEquals(fsSimpleName, objectRepositoryResolver.resolveFileSystem(fsSimpleName.getGit().getRepository())); JGitFileSystem fsComposedName1 = ((JGitFileSystemProxy) provider.newFileSystem(URI.create("git://user1/dora"), EMPTY_ENV)).getRealJGitFileSystem(); assertEquals(fsComposedName1, objectRepositoryResolver.resolveFileSystem(fsComposedName1.getGit().getRepository())); }
@Test public void resolveByRepositoryTest() { JGitFileSystem fsSimpleName = ((JGitFileSystemProxy) provider.newFileSystem(URI.create("git://repo"), EMPTY_ENV)).getRealJGitFileSystem(); JGitFileSystemProvider.RepositoryResolverImpl<Object> objectRepositoryResolver = provider.new RepositoryResolverImpl<>(); assertEquals(fsSimpleName, objectRepositoryResolver.resolveFileSystem(fsSimpleName.getGit().getRepository())); JGitFileSystem fsComposedName1 = ((JGitFileSystemProxy) provider.newFileSystem(URI.create("git://user1/dora"), EMPTY_ENV)).getRealJGitFileSystem(); assertEquals(fsComposedName1, objectRepositoryResolver.resolveFileSystem(fsComposedName1.getGit().getRepository())); }
private void merge(final JGitPathImpl source, final JGitPathImpl target) { try { target.getFileSystem().lock(); source.getFileSystem().getGit().merge(source.getRefTree(), target.getRefTree()); } finally { target.getFileSystem().unlock(); } }
private void createBranch(final JGitPathImpl source, final JGitPathImpl target) { try { target.getFileSystem().lock(); source.getFileSystem().getGit().createRef(source.getRefTree(), target.getRefTree()); } finally { target.getFileSystem().unlock(); } }