Example usage for org.eclipse.jgit.transport RemoteConfig getName

List of usage examples for org.eclipse.jgit.transport RemoteConfig getName

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport RemoteConfig getName.

Prototype

public String getName() 

Source Link

Document

Get the local name this remote configuration is recognized as.

Usage

From source file:com.gitblit.service.MirrorService.java

License:Apache License

@Override
public void run() {
    if (!isReady()) {
        return;//from   w w  w.j a va  2s  .  c o m
    }

    running.set(true);

    for (String repositoryName : repositoryManager.getRepositoryList()) {
        if (forceClose.get()) {
            break;
        }
        if (repositoryManager.isCollectingGarbage(repositoryName)) {
            logger.debug("mirror is skipping {} garbagecollection", repositoryName);
            continue;
        }
        RepositoryModel model = null;
        Repository repository = null;
        try {
            model = repositoryManager.getRepositoryModel(repositoryName);
            if (!model.isMirror && !model.isBare) {
                // repository must be a valid bare git mirror
                logger.debug("mirror is skipping {} !mirror !bare", repositoryName);
                continue;
            }

            repository = repositoryManager.getRepository(repositoryName);
            if (repository == null) {
                logger.warn(
                        MessageFormat.format("MirrorExecutor is missing repository {0}?!?", repositoryName));
                continue;
            }

            // automatically repair (some) invalid fetch ref specs
            if (!repairAttempted.contains(repositoryName)) {
                repairAttempted.add(repositoryName);
                JGitUtils.repairFetchSpecs(repository);
            }

            // find the first mirror remote - there should only be one
            StoredConfig rc = repository.getConfig();
            RemoteConfig mirror = null;
            List<RemoteConfig> configs = RemoteConfig.getAllRemoteConfigs(rc);
            for (RemoteConfig config : configs) {
                if (config.isMirror()) {
                    mirror = config;
                    break;
                }
            }

            if (mirror == null) {
                // repository does not have a mirror remote
                logger.debug("mirror is skipping {} no mirror remote found", repositoryName);
                continue;
            }

            logger.debug("checking {} remote {} for ref updates", repositoryName, mirror.getName());
            final boolean testing = false;
            Git git = new Git(repository);
            FetchResult result = git.fetch().setRemote(mirror.getName()).setDryRun(testing).call();
            Collection<TrackingRefUpdate> refUpdates = result.getTrackingRefUpdates();
            if (refUpdates.size() > 0) {
                ReceiveCommand ticketBranchCmd = null;
                for (TrackingRefUpdate ru : refUpdates) {
                    StringBuilder sb = new StringBuilder();
                    sb.append("updated mirror ");
                    sb.append(repositoryName);
                    sb.append(" ");
                    sb.append(ru.getRemoteName());
                    sb.append(" -> ");
                    sb.append(ru.getLocalName());
                    if (ru.getResult() == Result.FORCED) {
                        sb.append(" (forced)");
                    }
                    sb.append(" ");
                    sb.append(ru.getOldObjectId() == null ? "" : ru.getOldObjectId().abbreviate(7).name());
                    sb.append("..");
                    sb.append(ru.getNewObjectId() == null ? "" : ru.getNewObjectId().abbreviate(7).name());
                    logger.info(sb.toString());

                    if (BranchTicketService.BRANCH.equals(ru.getLocalName())) {
                        ReceiveCommand.Type type = null;
                        switch (ru.getResult()) {
                        case NEW:
                            type = Type.CREATE;
                            break;
                        case FAST_FORWARD:
                            type = Type.UPDATE;
                            break;
                        case FORCED:
                            type = Type.UPDATE_NONFASTFORWARD;
                            break;
                        default:
                            type = null;
                            break;
                        }

                        if (type != null) {
                            ticketBranchCmd = new ReceiveCommand(ru.getOldObjectId(), ru.getNewObjectId(),
                                    ru.getLocalName(), type);
                        }
                    }
                }

                if (ticketBranchCmd != null) {
                    repository.fireEvent(new ReceiveCommandEvent(model, ticketBranchCmd));
                }
            }
        } catch (Exception e) {
            logger.error("Error updating mirror " + repositoryName, e);
        } finally {
            // cleanup
            if (repository != null) {
                repository.close();
            }
        }
    }

    running.set(false);
}

From source file:com.google.gerrit.server.git.PushOp.java

License:Apache License

@Inject
PushOp(final GitRepositoryManager grm, final SchemaFactory<ReviewDb> s,
        final PushReplication.ReplicationConfig p, final RemoteConfig c,
        final SecureCredentialsProvider.Factory cpFactory, @Assisted final Project.NameKey d,
        @Assisted final URIish u) {
    repoManager = grm;/*from  w w  w .j a v a  2 s.  c  om*/
    schema = s;
    pool = p;
    config = c;
    credentialsProvider = cpFactory.create(c.getName());
    projectName = d;
    uri = u;
}

From source file:com.google.gerrit.server.git.PushReplication.java

License:Apache License

private List<ReplicationConfig> allConfigs(final SitePaths site) throws ConfigInvalidException, IOException {
    final FileBasedConfig cfg = new FileBasedConfig(site.replication_config, FS.DETECTED);

    if (!cfg.getFile().exists()) {
        log.warn("No " + cfg.getFile() + "; not replicating");
        return Collections.emptyList();
    }//w w w .  j  a va2 s.co m
    if (cfg.getFile().length() == 0) {
        log.info("Empty " + cfg.getFile() + "; not replicating");
        return Collections.emptyList();
    }

    try {
        cfg.load();
    } catch (ConfigInvalidException e) {
        throw new ConfigInvalidException("Config file " + cfg.getFile() + " is invalid: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new IOException("Cannot read " + cfg.getFile() + ": " + e.getMessage(), e);
    }

    final List<ReplicationConfig> r = new ArrayList<ReplicationConfig>();
    for (final RemoteConfig c : allRemotes(cfg)) {
        if (c.getURIs().isEmpty()) {
            continue;
        }

        for (final URIish u : c.getURIs()) {
            if (u.getPath() == null || !u.getPath().contains("${name}")) {
                throw new ConfigInvalidException("remote." + c.getName() + ".url" + " \"" + u
                        + "\" lacks ${name} placeholder in " + cfg.getFile());
            }
        }

        // In case if refspec destination for push is not set then we assume it is
        // equal to source
        for (RefSpec ref : c.getPushRefSpecs()) {
            if (ref.getDestination() == null) {
                ref.setDestination(ref.getSource());
            }
        }

        if (c.getPushRefSpecs().isEmpty()) {
            RefSpec spec = new RefSpec();
            spec = spec.setSourceDestination("refs/*", "refs/*");
            spec = spec.setForceUpdate(true);
            c.addPushRefSpec(spec);
        }

        r.add(new ReplicationConfig(injector, workQueue, c, cfg, database, replicationUserFactory));
    }
    return Collections.unmodifiableList(r);
}

From source file:com.googlesource.gerrit.plugins.github.replication.Destination.java

License:Apache License

Destination(final Injector injector, final RemoteConfig rc, final Config cfg, final SchemaFactory<ReviewDb> db,
        final RemoteSiteUser.Factory replicationUserFactory, final PluginUser pluginUser,
        final GitRepositoryManager gitRepositoryManager, final GroupBackend groupBackend) {
    remote = rc;//w w w.j  a v a2s  .c o m

    remoteNameStyle = Objects.firstNonNull(cfg.getString("remote", rc.getName(), "remoteNameStyle"), "slash");

    String[] authGroupNames = cfg.getStringList("remote", rc.getName(), "authGroup");
    if (authGroupNames.length > 0) {
        ImmutableSet.Builder<AccountGroup.UUID> builder = ImmutableSet.builder();
        for (String name : authGroupNames) {
            GroupReference g = GroupBackends.findExactSuggestion(groupBackend, name);
            if (g != null) {
                builder.add(g.getUUID());
            } else {
                GitHubDestinations.log
                        .warn(String.format("Group \"%s\" not recognized, removing from authGroup", name));
            }
        }
        remoteUser = replicationUserFactory.create(new ListGroupMembership(builder.build()));
    } else {
        remoteUser = pluginUser;
    }

    projectControlFactory = injector.getInstance(ProjectControl.Factory.class);
}

From source file:com.googlesource.gerrit.plugins.github.replication.GitHubDestinations.java

License:Apache License

private List<Destination> getDestinations(File cfgPath) throws ConfigInvalidException, IOException {
    FileBasedConfig cfg = new FileBasedConfig(cfgPath, FS.DETECTED);
    if (!cfg.getFile().exists() || cfg.getFile().length() == 0) {
        return Collections.emptyList();
    }//  ww  w . j av  a 2s .  co m

    try {
        cfg.load();
    } catch (ConfigInvalidException e) {
        throw new ConfigInvalidException(
                String.format("Config file %s is invalid: %s", cfg.getFile(), e.getMessage()), e);
    } catch (IOException e) {
        throw new IOException(String.format("Cannot read %s: %s", cfg.getFile(), e.getMessage()), e);
    }

    ImmutableList.Builder<Destination> dest = ImmutableList.builder();
    for (RemoteConfig c : allRemotes(cfg)) {
        if (c.getURIs().isEmpty()) {
            continue;
        }

        for (URIish u : c.getURIs()) {
            if (u.getPath() == null || !u.getPath().contains("${name}")) {
                throw new ConfigInvalidException(String.format(
                        "remote.%s.url \"%s\" lacks ${name} placeholder in %s", c.getName(), u, cfg.getFile()));
            }
        }

        // If destination for push is not set assume equal to source.
        for (RefSpec ref : c.getPushRefSpecs()) {
            if (ref.getDestination() == null) {
                ref.setDestination(ref.getSource());
            }
        }

        if (c.getPushRefSpecs().isEmpty()) {
            c.addPushRefSpec(new RefSpec().setSourceDestination("refs/*", "refs/*").setForceUpdate(true));
        }

        dest.add(new Destination(injector, c, cfg, database, replicationUserFactory, pluginUser,
                gitRepositoryManager, groupBackend));
    }
    return dest.build();
}

From source file:com.googlesource.gerrit.plugins.replication.DestinationConfiguration.java

License:Apache License

DestinationConfiguration(RemoteConfig remoteConfig, Config cfg) {
    this.remoteConfig = remoteConfig;
    String name = remoteConfig.getName();
    urls = ImmutableList.copyOf(cfg.getStringList("remote", name, "url"));
    delay = Math.max(0, getInt(remoteConfig, cfg, "replicationdelay", 15));
    projects = ImmutableList.copyOf(cfg.getStringList("remote", name, "projects"));
    adminUrls = ImmutableList.copyOf(cfg.getStringList("remote", name, "adminUrl"));
    retryDelay = Math.max(0, getInt(remoteConfig, cfg, "replicationretry", 1));
    poolThreads = Math.max(0, getInt(remoteConfig, cfg, "threads", 1));
    authGroupNames = ImmutableList.copyOf(cfg.getStringList("remote", name, "authGroup"));
    lockErrorMaxRetries = cfg.getInt("replication", "lockErrorMaxRetries", 0);

    createMissingRepos = cfg.getBoolean("remote", name, "createMissingRepositories", true);
    replicatePermissions = cfg.getBoolean("remote", name, "replicatePermissions", true);
    replicateProjectDeletions = cfg.getBoolean("remote", name, "replicateProjectDeletions", false);
    replicateHiddenProjects = cfg.getBoolean("remote", name, "replicateHiddenProjects", false);
    remoteNameStyle = MoreObjects.firstNonNull(cfg.getString("remote", name, "remoteNameStyle"), "slash");
}

From source file:com.googlesource.gerrit.plugins.replication.DestinationConfiguration.java

License:Apache License

private static int getInt(RemoteConfig rc, Config cfg, String name, int defValue) {
    return cfg.getInt("remote", rc.getName(), name, defValue);
}

From source file:com.googlesource.gerrit.plugins.replication.PushOne.java

License:Apache License

@Inject
PushOne(GitRepositoryManager grm, SchemaFactory<ReviewDb> s, Destination p, RemoteConfig c,
        CredentialsFactory cpFactory, TagCache tc, PerThreadRequestScope.Scoper ts, ChangeNotes.Factory nf,
        SearchingChangeCacheImpl cc, ReplicationQueue rq, IdGenerator ig, ReplicationStateListener sl,
        ReplicationMetrics m, @Assisted Project.NameKey d, @Assisted URIish u) {
    gitManager = grm;/*from  w  ww . j  a v a 2  s . c om*/
    schema = s;
    pool = p;
    config = c;
    credentialsProvider = cpFactory.create(c.getName());
    tagCache = tc;
    threadScoper = ts;
    changeNotesFactory = nf;
    changeCache = cc;
    replicationQueue = rq;
    projectName = d;
    uri = u;
    lockRetryCount = 0;
    maxLockRetries = pool.getLockErrorMaxRetries();
    id = ig.next();
    stateLog = sl;
    createdAt = System.nanoTime();
    metrics = m;
    canceledWhileRunning = new AtomicBoolean(false);
}

From source file:com.googlesource.gerrit.plugins.replication.ReplicationFileBasedConfig.java

License:Apache License

private List<Destination> allDestinations() throws ConfigInvalidException, IOException {
    if (!config.getFile().exists()) {
        log.warn("Config file " + config.getFile() + " does not exist; not replicating");
        return Collections.emptyList();
    }//from   ww  w.  j a  va  2 s  .  co  m
    if (config.getFile().length() == 0) {
        log.info("Config file " + config.getFile() + " is empty; not replicating");
        return Collections.emptyList();
    }

    try {
        config.load();
    } catch (ConfigInvalidException e) {
        throw new ConfigInvalidException(
                String.format("Config file %s is invalid: %s", config.getFile(), e.getMessage()), e);
    } catch (IOException e) {
        throw new IOException(String.format("Cannot read %s: %s", config.getFile(), e.getMessage()), e);
    }

    replicateAllOnPluginStart = config.getBoolean("gerrit", "replicateOnStartup", true);

    defaultForceUpdate = config.getBoolean("gerrit", "defaultForceUpdate", false);

    ImmutableList.Builder<Destination> dest = ImmutableList.builder();
    for (RemoteConfig c : allRemotes(config)) {
        if (c.getURIs().isEmpty()) {
            continue;
        }

        // If destination for push is not set assume equal to source.
        for (RefSpec ref : c.getPushRefSpecs()) {
            if (ref.getDestination() == null) {
                ref.setDestination(ref.getSource());
            }
        }

        if (c.getPushRefSpecs().isEmpty()) {
            c.addPushRefSpec(
                    new RefSpec().setSourceDestination("refs/*", "refs/*").setForceUpdate(defaultForceUpdate));
        }

        Destination destination = new Destination(injector, new DestinationConfiguration(c, config),
                replicationUserFactory, pluginUser, gitRepositoryManager, groupBackend, stateLog,
                groupIncludeCache);

        if (!destination.isSingleProjectMatch()) {
            for (URIish u : c.getURIs()) {
                if (u.getPath() == null || !u.getPath().contains("${name}")) {
                    throw new ConfigInvalidException(
                            String.format("remote.%s.url \"%s\" lacks ${name} placeholder in %s", c.getName(),
                                    u, config.getFile()));
                }
            }
        }

        dest.add(destination);
    }
    return dest.build();
}

From source file:com.madgag.agit.git.model.RDTRemote.java

License:Open Source License

@Override
CharSequence conciseSummary(RemoteConfig rc) {
    return rc.getName() + ": " + rc.getURIs().get(0);
}