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:org.apache.maven.scm.provider.git.jgit.command.checkin.JGitCheckInCommandCommitterAuthorTckTest.java
License:Apache License
/** * make sure the local .gitconfig is in a clean state *///www . j a v a 2s. c o m private void unsetConfig(StoredConfig config) { config.unsetSection("user", null); config.unset("user", null, "name"); // somehow unset does not always work on "user" config.setString("user", null, "name", null); config.setString("user", null, "email", null); config.unsetSection(JGitCheckInCommand.GIT_MAVEN_SECTION, null); }
From source file:org.apache.maven.scm.provider.git.jgit.command.JGitUtils.java
License:Apache License
/** * Prepares the in memory configuration of git to connect to the configured * repository. It configures the following settings in memory: <br /> * <li>push url</li> <li>fetch url</li> * <p/>//from ww w . jav a 2 s .c o m * * @param logger used to log some details * @param git the instance to configure (only in memory, not saved) * @param repository the repo config to be used * @return {@link CredentialsProvider} in case there are credentials * informations configured in the repository. */ public static CredentialsProvider prepareSession(ScmLogger logger, Git git, GitScmProviderRepository repository) { StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", repository.getFetchUrl()); config.setString("remote", "origin", "pushURL", repository.getPushUrl()); // make sure we do not log any passwords to the output String password = StringUtils.isNotBlank(repository.getPassword()) ? repository.getPassword().trim() : "no-pwd-defined"; logger.info("fetch url: " + repository.getFetchUrl().replace(password, "******")); logger.info("push url: " + repository.getPushUrl().replace(password, "******")); return getCredentials(repository); }
From source file:org.apache.nifi.registry.provider.flow.git.TestGitFlowPersistenceProvider.java
License:Apache License
private void assertProvider(final Map<String, String> properties, final GitConsumer gitConsumer, final Consumer<GitFlowPersistenceProvider> assertion, boolean deleteDir) throws IOException, GitAPIException { final File gitDir = new File(properties.get(GitFlowPersistenceProvider.FLOW_STORAGE_DIR_PROP)); try {//from w ww . j a v a 2 s . c o m FileUtils.ensureDirectoryExistAndCanReadAndWrite(gitDir); try (final Git git = Git.init().setDirectory(gitDir).call()) { logger.debug("Initiated a git repository {}", git); final StoredConfig config = git.getRepository().getConfig(); config.setString("user", null, "name", "git-user"); config.setString("user", null, "email", "git-user@example.com"); config.save(); gitConsumer.accept(git); } final GitFlowPersistenceProvider persistenceProvider = new GitFlowPersistenceProvider(); final ProviderConfigurationContext configurationContext = new StandardProviderConfigurationContext( properties); persistenceProvider.onConfigured(configurationContext); assertion.accept(persistenceProvider); } finally { if (deleteDir) { FileUtils.deleteFile(gitDir, true); } } }
From source file:org.apache.openaz.xacml.admin.XacmlAdminUI.java
License:Apache License
private static void initializeGitRepository() throws ServletException { XacmlAdminUI.repositoryPath = Paths .get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_REPOSITORY)); FileRepositoryBuilder builder = new FileRepositoryBuilder(); try {/*from ww w.jav a 2 s .c om*/ XacmlAdminUI.repository = builder.setGitDir(XacmlAdminUI.repositoryPath.toFile()).readEnvironment() .findGitDir().setBare().build(); if (Files.notExists(XacmlAdminUI.repositoryPath) || Files.notExists(Paths.get(XacmlAdminUI.repositoryPath.toString(), "HEAD"))) { // // Create it if it doesn't exist. As a bare repository // logger.info("Creating bare git repository: " + XacmlAdminUI.repositoryPath.toString()); XacmlAdminUI.repository.create(); // // Add the magic file so remote works. // Path daemon = Paths.get(XacmlAdminUI.repositoryPath.toString(), "git-daemon-export-ok"); Files.createFile(daemon); } } catch (IOException e) { logger.error("Failed to build repository: " + repository, e); throw new ServletException(e.getMessage(), e.getCause()); } // // Make sure the workspace directory is created // Path workspace = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_WORKSPACE)); workspace = workspace.toAbsolutePath(); if (Files.notExists(workspace)) { try { Files.createDirectory(workspace); } catch (IOException e) { logger.error("Failed to build workspace: " + workspace, e); throw new ServletException(e.getMessage(), e.getCause()); } } // // Create the user workspace directory // workspace = Paths.get(workspace.toString(), "pe"); if (Files.notExists(workspace)) { try { Files.createDirectory(workspace); } catch (IOException e) { logger.error("Failed to create directory: " + workspace, e); throw new ServletException(e.getMessage(), e.getCause()); } } // // Get the path to where the repository is going to be // Path gitPath = Paths.get(workspace.toString(), XacmlAdminUI.repositoryPath.getFileName().toString()); if (Files.notExists(gitPath)) { try { Files.createDirectory(gitPath); } catch (IOException e) { logger.error("Failed to create directory: " + gitPath, e); throw new ServletException(e.getMessage(), e.getCause()); } } // // Initialize the domain structure // String base = null; String domain = XacmlAdminUI.getDomain(); if (domain != null) { for (String part : Splitter.on(':').trimResults().split(domain)) { if (base == null) { base = part; } Path subdir = Paths.get(gitPath.toString(), part); if (Files.notExists(subdir)) { try { Files.createDirectory(subdir); Files.createFile(Paths.get(subdir.toString(), ".svnignore")); } catch (IOException e) { logger.error("Failed to create: " + subdir, e); throw new ServletException(e.getMessage(), e.getCause()); } } } } else { try { Files.createFile(Paths.get(workspace.toString(), ".svnignore")); base = ".svnignore"; } catch (IOException e) { logger.error("Failed to create file", e); throw new ServletException(e.getMessage(), e.getCause()); } } try { // // These are the sequence of commands that must be done initially to // finish setting up the remote bare repository. // Git git = Git.init().setDirectory(gitPath.toFile()).setBare(false).call(); git.add().addFilepattern(base).call(); git.commit().setMessage("Initialize Bare Repository").call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", XacmlAdminUI.repositoryPath.toAbsolutePath().toString()); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); git.push().setRemote("origin").add("master").call(); /* * This will not work unless git.push().setRemote("origin").add("master").call(); * is called first. Otherwise it throws an exception. However, if the push() is * called then calling this function seems to add nothing. * git.branchCreate().setName("master") .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM) .setStartPoint("origin/master").setForce(true).call(); */ } catch (GitAPIException | IOException e) { logger.error(e); throw new ServletException(e.getMessage(), e.getCause()); } }
From source file:org.apache.openaz.xacml.admin.XacmlAdminUI.java
License:Apache License
/** * Initializes a user's git repository./*from w ww . j ava 2 s. c o m*/ * * * @param workspacePath * @param userId * @param email * @return * @throws IOException * @throws InvalidRemoteException * @throws TransportException * @throws GitAPIException */ private static Path initializeUserRepository(Path workspacePath, String userId, URI email) throws IOException, InvalidRemoteException, TransportException, GitAPIException { Path gitPath = null; // // Initialize the User's Git repository // if (Files.notExists(workspacePath)) { logger.info("Creating user workspace: " + workspacePath.toAbsolutePath().toString()); // // Create our user's directory // Files.createDirectory(workspacePath); } gitPath = Paths.get(workspacePath.toString(), XacmlAdminUI.repositoryPath.getFileName().toString()); if (Files.notExists(gitPath)) { // // It doesn't exist yet, so Clone it and check it out // logger.info("Cloning user git directory: " + gitPath.toAbsolutePath().toString()); Git.cloneRepository().setURI(XacmlAdminUI.repositoryPath.toUri().toString()) .setDirectory(gitPath.toFile()).setNoCheckout(false).call(); // // Set userid // Git git = Git.open(gitPath.toFile()); StoredConfig config = git.getRepository().getConfig(); config.setString("user", null, "name", userId); if (email != null && email.getPath() != null) { config.setString("user", null, "email", email.toString()); } config.save(); } return gitPath; }
From source file:org.apache.stratos.cartridge.agent.artifact.deployment.synchronizer.git.impl.GitBasedArtifactRepository.java
License:Apache License
/** * Handles the Invalid configuration issues * * @param gitRepoCtx RepositoryContext instance of the tenant *//*from w w w .j ava 2 s . c om*/ private void handleInvalidConfigurationError(RepositoryContext gitRepoCtx) { StoredConfig storedConfig = gitRepoCtx.getLocalRepo().getConfig(); boolean modifiedConfig = false; if (storedConfig != null) { if (storedConfig.getString("branch", "master", "remote") == null || storedConfig.getString("branch", "master", "remote").isEmpty()) { storedConfig.setString("branch", "master", "remote", "origin"); modifiedConfig = true; } if (storedConfig.getString("branch", "master", "merge") == null || storedConfig.getString("branch", "master", "merge").isEmpty()) { storedConfig.setString("branch", "master", "merge", "refs/heads/master"); modifiedConfig = true; } if (modifiedConfig) { try { storedConfig.save(); // storedConfig.load(); } catch (IOException e) { String message = "Error saving git configuration file in local repo at " + gitRepoCtx.getGitLocalRepoPath(); System.out.println(message); log.error(message, e); } } } }
From source file:org.apache.stratos.cartridge.agent.artifact.deployment.synchronizer.git.impl.GitBasedArtifactRepository.java
License:Apache License
public static boolean addRemote(Repository repository, String remoteUrl) { boolean remoteAdded = false; StoredConfig config = repository.getConfig(); config.setString(GitDeploymentSynchronizerConstants.REMOTE, GitDeploymentSynchronizerConstants.ORIGIN, GitDeploymentSynchronizerConstants.URL, remoteUrl); config.setString(GitDeploymentSynchronizerConstants.REMOTE, GitDeploymentSynchronizerConstants.ORIGIN, GitDeploymentSynchronizerConstants.FETCH, GitDeploymentSynchronizerConstants.FETCH_LOCATION); config.setString(GitDeploymentSynchronizerConstants.BRANCH, GitDeploymentSynchronizerConstants.MASTER, GitDeploymentSynchronizerConstants.REMOTE, GitDeploymentSynchronizerConstants.ORIGIN); config.setString(GitDeploymentSynchronizerConstants.BRANCH, GitDeploymentSynchronizerConstants.MASTER, GitDeploymentSynchronizerConstants.MERGE, GitDeploymentSynchronizerConstants.GIT_REFS_HEADS_MASTER); try {/*from www . jav a 2s .co m*/ config.save(); remoteAdded = true; } catch (IOException e) { log.error( "Error in adding remote origin " + remoteUrl + " for local repository " + repository.toString(), e); } return remoteAdded; }
From source file:org.archicontribs.modelrepository.grafico.GraficoUtils.java
License:Open Source License
/** * Clone a model/*from ww w . j ava 2s .c o m*/ * @param localGitFolder * @param repoURL * @param userName * @param userPassword * @param monitor * @throws GitAPIException * @throws IOException */ public static void cloneModel(File localGitFolder, String repoURL, String userName, String userPassword, ProgressMonitor monitor) throws GitAPIException, IOException { CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setDirectory(localGitFolder); cloneCommand.setURI(repoURL); cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, userPassword)); cloneCommand.setProgressMonitor(monitor); try (Git git = cloneCommand.call()) { // Use the same line endings StoredConfig config = git.getRepository().getConfig(); config.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); //$NON-NLS-1$ config.save(); } }
From source file:org.codice.git.GitHandler.java
License:Open Source License
public void setConfigString(String section, String subsection, String key, String value) throws IOException { final StoredConfig config = repo.getConfig(); config.setString(section, subsection, key, value); config.save();/*from ww w. j a va2s . c om*/ LOGGER.log(Level.FINE, "Value for [{0}, {1}, {2}] set to: {3}\n", new Object[] { section, subsection, key, value }); }
From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitBranchDeployer.java
License:Open Source License
private void addWorkAreaRemote(String site, Repository envStoreRepo) { envStoreRepo.getRemoteName("work-area"); Git git = new Git(envStoreRepo); StoredConfig config = git.getRepository().getConfig(); Path siteRepoPath = Paths.get(rootPath, "sites", site, ".git"); config.setString("remote", "work-area", "url", siteRepoPath.normalize().toAbsolutePath().toString()); try {/* w w w .j a va 2s . c o m*/ config.save(); } catch (IOException e) { logger.error("Error adding work area as remote for environment store.", e); } }