Search in sources :

Example 26 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class GitblitAuthority method setSizeAndPosition.

private void setSizeAndPosition() {
    String sz = null;
    String pos = null;
    try {
        StoredConfig config = getConfig();
        sz = config.getString("ui", null, "size");
        pos = config.getString("ui", null, "position");
        defaultDuration = config.getInt("new", "duration", 365);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    // try to restore saved window size
    if (StringUtils.isEmpty(sz)) {
        setSize(900, 600);
    } else {
        String[] chunks = sz.split("x");
        int width = Integer.parseInt(chunks[0]);
        int height = Integer.parseInt(chunks[1]);
        setSize(width, height);
    }
    // try to restore saved window position
    if (StringUtils.isEmpty(pos)) {
        setLocationRelativeTo(null);
    } else {
        String[] chunks = pos.split(",");
        int x = Integer.parseInt(chunks[0]);
        int y = Integer.parseInt(chunks[1]);
        setLocation(x, y);
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Point(java.awt.Point)

Example 27 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class JGitUtils method createRepository.

/**
	 * Creates a bare, shared repository.
	 *
	 * @param repositoriesFolder
	 * @param name
	 * @param shared
	 *          the setting for the --shared option of "git init".
	 * @return Repository
	 */
public static Repository createRepository(File repositoriesFolder, String name, String shared) {
    try {
        Repository repo = null;
        try {
            Git git = Git.init().setDirectory(new File(repositoriesFolder, name)).setBare(true).call();
            repo = git.getRepository();
        } catch (GitAPIException e) {
            throw new RuntimeException(e);
        }
        GitConfigSharedRepository sharedRepository = new GitConfigSharedRepository(shared);
        if (sharedRepository.isShared()) {
            StoredConfig config = repo.getConfig();
            config.setString("core", null, "sharedRepository", sharedRepository.getValue());
            config.setBoolean("receive", null, "denyNonFastforwards", true);
            config.save();
            if (!JnaUtils.isWindows()) {
                Iterator<File> iter = org.apache.commons.io.FileUtils.iterateFilesAndDirs(repo.getDirectory(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
                // Adjust permissions on file/directory
                while (iter.hasNext()) {
                    adjustSharedPerm(iter.next(), sharedRepository);
                }
            }
        }
        return repo;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) IOException(java.io.IOException) File(java.io.File)

Example 28 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class ITicketService method deleteLabel.

/**
	 * Deletes a label.
	 *
	 * @param repository
	 * @param label
	 * @param createdBy
	 * @return true if the delete was successful
	 * @since 1.4.0
	 */
public synchronized boolean deleteLabel(RepositoryModel repository, String label, String createdBy) {
    if (StringUtils.isEmpty(label)) {
        throw new IllegalArgumentException("label can not be empty!");
    }
    Repository db = null;
    try {
        db = repositoryManager.getRepository(repository.name);
        StoredConfig config = db.getConfig();
        config.unsetSection(LABEL, label);
        config.save();
        return true;
    } catch (IOException e) {
        log.error("failed to delete label " + label + " in " + repository, e);
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) IOException(java.io.IOException)

Example 29 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class ITicketService method deleteMilestone.

/**
	 * Deletes a milestone.
	 *
	 * @param repository
	 * @param milestone
	 * @param createdBy
	 * @param notifyOpenTickets
	 * @return true if successful
	 * @since 1.6.0
	 */
public synchronized boolean deleteMilestone(RepositoryModel repository, String milestone, String createdBy, boolean notifyOpenTickets) {
    if (StringUtils.isEmpty(milestone)) {
        throw new IllegalArgumentException("milestone can not be empty!");
    }
    Repository db = null;
    try {
        TicketMilestone tm = getMilestone(repository, milestone);
        if (tm == null) {
            return false;
        }
        db = repositoryManager.getRepository(repository.name);
        StoredConfig config = db.getConfig();
        config.unsetSection(MILESTONE, milestone);
        config.save();
        milestonesCache.remove(repository.name);
        TicketNotifier notifier = createNotifier();
        for (QueryResult qr : tm.tickets) {
            Change change = new Change(createdBy);
            change.setField(Field.milestone, "");
            TicketModel ticket = updateTicket(repository, qr.number, change);
            if (notifyOpenTickets && ticket.isOpen()) {
                notifier.queueMailing(ticket);
            }
        }
        if (notifyOpenTickets) {
            notifier.sendAll();
        }
        return true;
    } catch (IOException e) {
        log.error("failed to delete milestone " + milestone + " in " + repository, e);
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) IOException(java.io.IOException)

Example 30 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class ITicketService method updateLabel.

/**
	 * Updates a label.
	 *
	 * @param repository
	 * @param label
	 * @param createdBy
	 * @return true if the update was successful
	 * @since 1.4.0
	 */
public synchronized boolean updateLabel(RepositoryModel repository, TicketLabel label, String createdBy) {
    Repository db = null;
    try {
        db = repositoryManager.getRepository(repository.name);
        StoredConfig config = db.getConfig();
        config.setString(LABEL, label.name, COLOR, label.color);
        config.save();
        return true;
    } catch (IOException e) {
        log.error("failed to update label " + label + " in " + repository, e);
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) IOException(java.io.IOException)

Aggregations

StoredConfig (org.eclipse.jgit.lib.StoredConfig)40 IOException (java.io.IOException)26 Repository (org.eclipse.jgit.lib.Repository)19 File (java.io.File)9 ArrayList (java.util.ArrayList)8 URISyntaxException (java.net.URISyntaxException)6 GitException (org.eclipse.che.api.git.exception.GitException)6 SimpleDateFormat (java.text.SimpleDateFormat)5 GitBlitException (com.gitblit.GitBlitException)4 RepositoryModel (com.gitblit.models.RepositoryModel)4 Point (java.awt.Point)4 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)4 RemoteConfig (org.eclipse.jgit.transport.RemoteConfig)4 TeamModel (com.gitblit.models.TeamModel)3 Change (com.gitblit.models.TicketModel.Change)3 UserModel (com.gitblit.models.UserModel)3 HashSet (java.util.HashSet)3 Git (org.eclipse.jgit.api.Git)3 RefSpec (org.eclipse.jgit.transport.RefSpec)3 AccessPermission (com.gitblit.Constants.AccessPermission)2