private File getNiogitDir() { final ConfigProperties configProperties = new ConfigProperties(System.getProperties()); final JGitFileSystemProviderConfiguration providerConfig = new JGitFileSystemProviderConfiguration(); providerConfig.load(configProperties); final File niogit = providerConfig.getGitReposParentDir(); return niogit; }
JGitFileSystemLock createLock(Git git) { return new JGitFileSystemLock(git, config.getDefaultJgitCacheEvictThresholdTimeUnit(), config.getJgitCacheEvictThresholdDuration()); }
public static Map<String, Supplier<JGitFileSystem>> create(JGitFileSystemProviderConfiguration config) { return Collections.synchronizedMap(new LinkedHashMap<String, Supplier<JGitFileSystem>>(config.getJgitFileSystemsInstancesCache() + 1, 0.75f, true) {
private void loadConfig(final ConfigProperties systemConfig) { config.load(systemConfig); if (config.httpProxyIsDefined()) { setupProxyAuthentication(); } }
@Test public void testNoProxy() { JGitFileSystemProviderConfiguration config = new JGitFileSystemProviderConfiguration() { }; config.load(new ConfigProperties(Collections.emptyMap())); final JGitSSHConfigSessionFactory instance = new JGitSSHConfigSessionFactory(config) { @Override ProxyHTTP buildProxy(final JGitFileSystemProviderConfiguration config) { fail("no proxy should be set"); return null; } }; instance.configure(mock(OpenSshConfig.Host.class), mock(Session.class)); }
fsName + DOT_GIT_EXT); } else { repoDest = new File(config.getGitReposParentDir(), fsName + DOT_GIT_EXT); fsName, credential, config.isEnableKetch() ? leaders : null, config.getHookDir(), config.isSslVerify()); } else if (subdirectory != null) { if (isMirror) { credential, leaders, config.getHookDir(), config.isSslVerify()); } else { git = Git.clone(repoDest, isMirror, credential, config.isEnableKetch() ? leaders : null, config.getHookDir(), config.isSslVerify()); config.getHookDir(), config.isEnableKetch() ? leaders : null, config.isSslVerify());
/** * Returns the directory that contains all the git repositories managed by this file system provider. */ public File getGitRepoContainerDir() { return config.getGitReposParentDir(); }
private void setupConfigs(ConfigProperties gitPrefs) { config = new JGitFileSystemProviderConfiguration(); loadConfig(gitPrefs); }
@Override public boolean removeEldestEntry(Map.Entry eldest) { if (removeEldestEntryIterations > config.getJgitRemoveEldestEntryIterations()) { removeEldestEntryIterations = 0; return false; } if (size() > config.getJgitFileSystemsInstancesCache()) { JGitFileSystem targetFS = (JGitFileSystem) ((MemoizedFileSystemsSupplier) eldest.getValue()).get(); if (targetFS.hasBeenInUse()) { removeEldestEntryIterations++; this.remove(eldest.getKey()); this.put((String) eldest.getKey(), (MemoizedFileSystemsSupplier) eldest.getValue()); return false; } else { return true; } } return false; } });
@Test public void cloneMirrorRepoNoSSLVerifyConfigTest() throws IOException { final File parentFolder = createTempDirectory(); final File gitSource = new File(parentFolder, SOURCE_GIT + ".git"); final File gitTarget = new File(parentFolder, TARGET_GIT + ".git"); final Git origin = setupGitRepo(gitSource, null); assertTrue(provider.config.isSslVerify()); boolean isMirror = true; boolean sslVerify = false; final Git clonedMirror = new Clone(gitTarget, gitSource.getAbsolutePath(), isMirror, CredentialsProvider.getDefault(), null, null, sslVerify).execute().get(); assertThat(clonedMirror).isNotNull(); StoredConfig config = clonedMirror.getRepository().getConfig(); assertEquals(Clone.REFS_MIRRORED, config.getString("remote", "origin", "fetch")); assertNull(config.getString("remote", "origin", "mirror")); assertEquals(gitSource.getAbsolutePath(), config.getString("remote", "origin", "url")); assertEquals(sslVerify, config.getBoolean("http", null, "sslVerify", !sslVerify)); }
new JGitFileSystemLock(git, TimeUnit.MILLISECONDS, config.getJgitCacheEvictThresholdDuration()), "fs1", CredentialsProvider.getDefault(),
private void firePostponedBatchEvents(JGitFileSystem fileSystem) { synchronized (postponedEventsLock) { if (fileSystem.hasPostponedEvents()) { fileSystem.publishEvents(fileSystem.getRootDirectories().iterator().next(), fileSystem.getPostponedWatchEvents()); } fileSystem.clearPostponedWatchEvents(); int value = fileSystem.incrementAndGetCommitCount(); if (value >= config.getCommitLimit()) { fileSystem.getGit().gc(); fileSystem.resetCommitCount(); } } }
@Test public void testNoProxy() { JGitFileSystemProviderConfiguration config = new JGitFileSystemProviderConfiguration() { }; config.load(new ConfigProperties(Collections.emptyMap())); final JGitSSHConfigSessionFactory instance = new JGitSSHConfigSessionFactory(config) { @Override ProxyHTTP buildProxy(final JGitFileSystemProviderConfiguration config) { fail("no proxy should be set"); return null; } }; instance.configure(mock(OpenSshConfig.Host.class), mock(Session.class)); }
private String extractFSNameFromRepo(Repository db) { final String fullRepoName = config.getGitReposParentDir().toPath().relativize(db.getDirectory().toPath()).toString(); return fullRepoName.substring(0, fullRepoName.indexOf(DOT_GIT_EXT)).replace('\\', '/'); }
@Test public void cloneMirrorRepoNoSSLVerifyConfigTest() throws IOException { final File parentFolder = createTempDirectory(); final File gitSource = new File(parentFolder, SOURCE_GIT + ".git"); final File gitTarget = new File(parentFolder, TARGET_GIT + ".git"); final Git origin = setupGitRepo(gitSource, null); assertTrue(provider.config.isSslVerify()); boolean isMirror = true; boolean sslVerify = false; final Git clonedMirror = new Clone(gitTarget, gitSource.getAbsolutePath(), isMirror, CredentialsProvider.getDefault(), null, null, sslVerify).execute().get(); assertThat(clonedMirror).isNotNull(); StoredConfig config = clonedMirror.getRepository().getConfig(); assertEquals(Clone.REFS_MIRRORED, config.getString("remote", "origin", "fetch")); assertNull(config.getString("remote", "origin", "mirror")); assertEquals(gitSource.getAbsolutePath(), config.getString("remote", "origin", "url")); assertEquals(sslVerify, config.getBoolean("http", null, "sslVerify", !sslVerify)); }
new JGitFileSystemLock(git, TimeUnit.MILLISECONDS, config.getJgitCacheEvictThresholdDuration()), "fs1", CredentialsProvider.getDefault(),
if (hasCommit) { int value = fileSystem.incrementAndGetCommitCount(); if (value >= config.getCommitLimit()) { git.gc(); fileSystem.resetCommitCount();
private File getNiogitDir() { final ConfigProperties configProperties = new ConfigProperties(System.getProperties()); final JGitFileSystemProviderConfiguration providerConfig = new JGitFileSystemProviderConfiguration(); providerConfig.load(configProperties); final File niogit = providerConfig.getGitReposParentDir(); return niogit; }
@Test public void testHttpsProxy() { JGitFileSystemProviderConfiguration config = new JGitFileSystemProviderConfiguration() { }; config.load(new ConfigProperties(new HashMap<String, String>() {{ put("org.uberfire.nio.git.proxy.ssh.over.https", "true"); put("https.proxyHost", "somehost"); put("https.proxyPort", "10"); }})); final JGitSSHConfigSessionFactory instance = new JGitSSHConfigSessionFactory(config) { @Override ProxyHTTP buildProxy(final JGitFileSystemProviderConfiguration config) { ProxyHTTP proxy = super.buildProxy(config); assertThat(proxy).hasFieldOrPropertyWithValue("proxy_host", "somehost"); assertThat(proxy).hasFieldOrPropertyWithValue("proxy_port", 10); assertThat(proxy).hasFieldOrPropertyWithValue("user", null); assertThat(proxy).hasFieldOrPropertyWithValue("passwd", null); return proxy; } }; instance.configure(mock(OpenSshConfig.Host.class), mock(Session.class)); }
@Override public Supplier<JGitFileSystem> putIfAbsent(String key, Supplier<JGitFileSystem> value) { Supplier<JGitFileSystem> jGitFileSystemSupplier = super.putIfAbsent(key, value); if (size() > config.getJgitFileSystemsInstancesCache()) { fitListToCacheSize(); } return jGitFileSystemSupplier; }