List of usage examples for org.eclipse.jgit.lib StoredConfig setString
public void setString(final String section, final String subsection, final String name, final String value)
From source file:io.fabric8.deployer.ProjectDeployerTest.java
License:Apache License
@Before public void setUp() throws Exception { URL.setURLStreamHandlerFactory(new CustomBundleURLStreamHandlerFactory()); basedir = System.getProperty("basedir", "."); String karafRoot = basedir + "/target/karaf"; System.setProperty("karaf.root", karafRoot); System.setProperty("karaf.data", karafRoot + "/data"); sfb = new ZKServerFactoryBean(); delete(sfb.getDataDir());/*from w w w . ja va 2 s . c o m*/ delete(sfb.getDataLogDir()); sfb.setPort(9123); sfb.afterPropertiesSet(); int zkPort = sfb.getClientPortAddress().getPort(); LOG.info("Connecting to ZK on port: " + zkPort); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString("localhost:" + zkPort).retryPolicy(new RetryOneTime(1000)) .connectionTimeoutMs(360000); curator = builder.build(); curator.start(); curator.getZookeeperClient().blockUntilConnectedOrTimedOut(); // setup a local and remote git repo File root = new File(basedir + "/target/git").getCanonicalFile(); delete(root); new File(root, "remote").mkdirs(); remote = Git.init().setDirectory(new File(root, "remote")).call(); remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath(); new File(root, "local").mkdirs(); git = Git.init().setDirectory(new File(root, "local")).call(); git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", remoteUrl); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); runtimeProperties = EasyMock.createMock(RuntimeProperties.class); EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes(); EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes(); EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes(); EasyMock.expect(runtimeProperties.getProperty(EasyMock.eq(SystemProperties.FABRIC_ENVIRONMENT))) .andReturn("").anyTimes(); EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null) .anyTimes(); EasyMock.replay(runtimeProperties); FabricGitServiceImpl gitService = new FabricGitServiceImpl(); gitService.bindRuntimeProperties(runtimeProperties); gitService.activate(); gitService.setGitForTesting(git); /* dataStore = new GitDataStoreImpl(); dataStore.bindCurator(curator); dataStore.bindGitService(gitService); dataStore.bindRuntimeProperties(runtimeProperties); dataStore.bindConfigurer(new Configurer() { @Override public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception { return null; } @Override public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception { return null; } }); Map<String, Object> datastoreProperties = new HashMap<String, Object>(); datastoreProperties.put(GitDataStore.GIT_REMOTE_URL, remoteUrl); dataStore.activate(datastoreProperties); */ fabricService = new FabricServiceImpl(); //fabricService.bindDataStore(dataStore); fabricService.bindRuntimeProperties(runtimeProperties); fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("port")); fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("zk")); fabricService.bindPlaceholderResolver(new ProfilePropertyPointerResolver()); fabricService.bindPlaceholderResolver(new ChecksumPlaceholderResolver()); fabricService.bindPlaceholderResolver(new VersionPropertyPointerResolver()); fabricService.bindPlaceholderResolver(new EnvPlaceholderResolver()); fabricService.activateComponent(); projectDeployer = new ProjectDeployerImpl(); projectDeployer.bindFabricService(fabricService); projectDeployer.bindMBeanServer(ManagementFactory.getPlatformMBeanServer()); String defaultVersion = null; //dataStore.getDefaultVersion(); assertEquals("defaultVersion", "1.0", defaultVersion); // now lets import some data - using the old non-git file layout... String importPath = basedir + "/../fabric8-karaf/src/main/resources/distro/fabric/import"; assertFolderExists(importPath); dataStore.importFromFileSystem(importPath); assertHasVersion(defaultVersion); }
From source file:io.fabric8.forge.rest.git.RepositoryResource.java
License:Apache License
protected void configureBranch(Git git, String branch) { // lets update the merge config if (Strings.isNotBlank(branch)) { StoredConfig config = git.getRepository().getConfig(); if (Strings.isNullOrBlank(config.getString("branch", branch, "remote")) || Strings.isNullOrBlank(config.getString("branch", branch, "merge"))) { config.setString("branch", branch, "remote", getRemote()); config.setString("branch", branch, "merge", "refs/heads/" + branch); try { config.save();// w ww .j a v a 2s . c om } catch (IOException e) { LOG.error("Failed to save the git configuration to " + basedir + " with branch " + branch + " on remote repo: " + remoteRepository + " due: " + e.getMessage() + ". This exception is ignored.", e); } } } }
From source file:io.fabric8.forge.rest.main.GitCommandCompletePostProcessor.java
License:Apache License
protected void configureBranch(Git git, String branch, String origin, String remoteRepository) { // lets update the merge config if (!Strings.isNullOrEmpty(branch)) { StoredConfig config = git.getRepository().getConfig(); config.setString("branch", branch, "remote", origin); config.setString("branch", branch, "merge", "refs/heads/" + branch); config.setString("remote", origin, "url", remoteRepository); config.setString("remote", origin, "fetch", "+refs/heads/*:refs/remotes/" + origin + "/*"); try {//from w w w . j a v a2s . c o m config.save(); } catch (IOException e) { LOG.error("Failed to save the git configuration to " + git.getRepository().getDirectory() + " with branch " + branch + " on " + origin + " remote repo: " + remoteRepository + " due: " + e.getMessage() + ". This exception is ignored.", e); } } }
From source file:io.fabric8.git.internal.CachingGitDataStoreTest.java
License:Apache License
@Before public void setUp() throws Exception { sfb = new ZKServerFactoryBean(); delete(sfb.getDataDir());/*from w w w. j a v a 2s . c om*/ delete(sfb.getDataLogDir()); sfb.afterPropertiesSet(); runtimeProperties = EasyMock.createMock(RuntimeProperties.class); EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes(); EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes(); EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes(); EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null) .anyTimes(); EasyMock.replay(runtimeProperties); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString("localhost:" + sfb.getClientPortAddress().getPort()) .retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000); curator = builder.build(); curator.start(); curator.getZookeeperClient().blockUntilConnectedOrTimedOut(); // setup a local and remote git repo basedir = System.getProperty("basedir", "."); File root = new File(basedir + "/target/git").getCanonicalFile(); delete(root); new File(root, "remote").mkdirs(); remote = Git.init().setDirectory(new File(root, "remote")).call(); remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath(); new File(root, "local").mkdirs(); git = Git.init().setDirectory(new File(root, "local")).call(); git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", remoteUrl); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); FabricGitServiceImpl gitService = new FabricGitServiceImpl(); gitService.bindRuntimeProperties(runtimeProperties); gitService.activate(); gitService.setGitForTesting(git); dataStore = new GitDataStoreImpl(); dataStore.bindCurator(curator); dataStore.bindGitService(gitService); dataStore.bindRuntimeProperties(runtimeProperties); dataStore.bindConfigurer(new Configurer() { @Override public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception { return null; } @Override public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception { return null; } }); Map<String, Object> datastoreProperties = new HashMap<String, Object>(); // datastoreProperties.put(GitDataStoreImpl.GIT_REMOTE_URL, remoteUrl); dataStore.activate(datastoreProperties); }
From source file:io.fabric8.git.internal.GitHelpers.java
License:Apache License
protected static void configureBranch(Git git, String branch, String remote) { // lets update the merge config if (Strings.isNotBlank(branch)) { StoredConfig config = git.getRepository().getConfig(); if (Strings.isNullOrBlank(config.getString("branch", branch, "remote")) || Strings.isNullOrBlank(config.getString("branch", branch, "merge"))) { config.setString("branch", branch, "remote", remote); config.setString("branch", branch, "merge", "refs/heads/" + branch); try { config.save();/* w ww .ja va 2 s. c om*/ } catch (IOException e) { LOGGER.error("Failed to configure the branch configuration to " + getRootGitDirectory(git) + " with branch " + branch + " on remote repo: " + remote + ". " + e, e); } } } }
From source file:io.fabric8.git.zkbridge.BridgeTest.java
License:Apache License
@Before public void setUp() throws Exception { sfb = new ZKServerFactoryBean(); delete(sfb.getDataDir());//from w w w. ja v a 2 s. co m delete(sfb.getDataLogDir()); sfb.afterPropertiesSet(); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString("localhost:" + sfb.getClientPortAddress().getPort()) .retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000); curator = builder.build(); curator.start(); curator.getZookeeperClient().blockUntilConnectedOrTimedOut(); File root = new File(System.getProperty("basedir", ".") + "/target/git").getCanonicalFile(); delete(root); new File(root, "remote").mkdirs(); remote = Git.init().setDirectory(new File(root, "remote")).call(); remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); new File(root, "local").mkdirs(); git = Git.init().setDirectory(new File(root, "local")).call(); git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", "file://" + new File(root, "remote").getCanonicalPath()); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); }
From source file:io.fabric8.itests.basic.git.GitUtils.java
License:Apache License
public static void configureBranch(Git git, String remote, String remoteUrl, String branch) { if (git != null && remoteUrl != null && !remoteUrl.isEmpty()) { Repository repository = git.getRepository(); if (repository != null) { StoredConfig config = repository.getConfig(); config.setString("remote", remote, "url", remoteUrl); config.setString("remote", remote, "fetch", "+refs/heads/*:refs/remotes/" + branch + "/*"); config.setString("branch", branch, "merge", "refs/heads/" + branch); config.setString("branch", branch, "remote", "origin"); try { config.save();/*from w w w . j ava 2 s . c om*/ } catch (IOException e) { //Ignore } } } }
From source file:io.fabric8.maven.CreateBranchMojo.java
License:Apache License
protected void configureBranch(String branch) { // lets update the merge config if (Strings.isNotBlank(branch) && hasRemoteRepo()) { StoredConfig config = git.getRepository().getConfig(); if (Strings.isNullOrBlank(config.getString("branch", branch, "remote")) || Strings.isNullOrBlank(config.getString("branch", branch, "merge"))) { config.setString("branch", branch, "remote", remoteName); config.setString("branch", branch, "merge", "refs/heads/" + branch); try { config.save();//from ww w. j av a 2 s. com } catch (IOException e) { getLog().error("Failed to save the git configuration into " + new File(buildDir, ".git") + " with branch " + branch + " on remote repo: " + gitUrl + " due: " + e.getMessage() + ". This exception is ignored.", e); } } } }
From source file:io.fabric8.openshift.agent.CartridgeGitRepository.java
License:Apache License
/** * Clones or pulls the remote repository and returns the directory with the checkout *///from ww w . j a v a 2s. co m public void cloneOrPull(final String repo, final CredentialsProvider credentials) throws Exception { if (!localRepo.exists() && !localRepo.mkdirs()) { throw new IOException("Failed to create local repository"); } File gitDir = new File(localRepo, ".git"); if (!gitDir.exists()) { LOG.info("Cloning remote repo " + repo); CloneCommand command = Git.cloneRepository().setCredentialsProvider(credentials).setURI(repo) .setDirectory(localRepo).setRemote(remoteName); git = command.call(); } else { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(gitDir).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); git = new Git(repository); // update the remote repo just in case StoredConfig config = repository.getConfig(); config.setString("remote", remoteName, "url", repo); config.setString("remote", remoteName, "fetch", "+refs/heads/*:refs/remotes/" + remoteName + "/*"); String branch = "master"; config.setString("branch", branch, "remote", remoteName); config.setString("branch", branch, "merge", "refs/heads/" + branch); try { config.save(); } catch (IOException e) { LOG.error("Failed to save the git configuration to " + localRepo + " with remote repo: " + repo + ". " + e, e); } // now pull LOG.info("Pulling from remote repo " + repo); git.pull().setCredentialsProvider(credentials).setRebase(true).call(); } }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.agent.UpdaterImpl.java
License:Apache License
private void addSubmoduleUsernames(@NotNull File repositoryDir, @NotNull Config gitModules) throws IOException, ConfigInvalidException, VcsException { if (!myPluginConfig.isUseMainRepoUserForSubmodules()) return;/*from www . j a v a 2s .co m*/ Loggers.VCS.info("Update submodules credentials"); AuthSettings auth = myRoot.getAuthSettings(); final String userName = auth.getUserName(); if (userName == null) { Loggers.VCS.info("Username is not specified in the main VCS root settings, skip updating credentials"); return; } Repository r = new RepositoryBuilder().setBare().setGitDir(getGitDir(repositoryDir)).build(); StoredConfig gitConfig = r.getConfig(); Set<String> submodules = gitModules.getSubsections("submodule"); if (submodules.isEmpty()) { Loggers.VCS.info("No submodule sections found in " + new File(repositoryDir, ".gitmodules").getCanonicalPath() + ", skip updating credentials"); return; } File modulesDir = new File(r.getDirectory(), Constants.MODULES); for (String submoduleName : submodules) { String url = gitModules.getString("submodule", submoduleName, "url"); Loggers.VCS.info("Update credentials for submodule with url " + url); if (url == null || !isRequireAuth(url)) { Loggers.VCS.info("Url " + url + " does not require authentication, skip updating credentials"); continue; } try { URIish uri = new URIish(url); String updatedUrl = uri.setUser(userName).toASCIIString(); gitConfig.setString("submodule", submoduleName, "url", updatedUrl); String submodulePath = gitModules.getString("submodule", submoduleName, "path"); if (submodulePath != null && myPluginConfig.isUpdateSubmoduleOriginUrl()) { File submoduleDir = new File(modulesDir, submodulePath); if (submoduleDir.isDirectory() && new File(submoduleDir, Constants.CONFIG).isFile()) updateOriginUrl(submoduleDir, updatedUrl); } Loggers.VCS.debug("Submodule url " + url + " changed to " + updatedUrl); } catch (URISyntaxException e) { Loggers.VCS.warn("Error while parsing an url " + url + ", skip updating submodule credentials", e); } catch (Exception e) { Loggers.VCS.warn("Error while updating the '" + submoduleName + "' submodule url", e); } } gitConfig.save(); }