/** * Converts the ref spec templates into {@link RefSpec} instances. * * @return the list of {@link RefSpec} instances. */ @NonNull public final List<RefSpec> asRefSpecs() { // de-duplicate effective ref-specs after substitution of placeholder Set<String> refSpecs = new LinkedHashSet<>(Math.max(this.refSpecs.size(), 1)); for (String template : refSpecs()) { refSpecs.add(template.replaceAll(AbstractGitSCMSource.REF_SPEC_REMOTE_NAME_PLACEHOLDER, remoteName())); } List<RefSpec> result = new ArrayList<>(refSpecs.size()); for (String refSpec : refSpecs) { result.add(new RefSpec(refSpec)); } return result; } }
/** * Gets the remote URL of the git repository for the specified remote name. * * @param remoteName the additional remote name. * @return the remote URL of the named additional remote or {@code null} if the supplied name is not in * {@link #additionalRemoteNames()} */ @CheckForNull public final String additionalRemote(String remoteName) { AdditionalRemote additionalRemote = additionalRemotes.get(remoteName); return additionalRemote == null ? null : additionalRemote.remote(); }
/** * Configures an additional remote. It is the responsibility of the caller to ensure that there are no conflicts * with the eventual {@link #remote()} name. * * @param remoteName the name of the additional remote. * @param remote the url of the additional remote. * @param refSpecs the ref specs of the additional remote, if empty will default to * {@link AbstractGitSCMSource#REF_SPEC_DEFAULT} * @return {@code this} for method chaining. */ @SuppressWarnings("unchecked") @NonNull public final B withAdditionalRemote(@NonNull String remoteName, @NonNull String remote, List<String> refSpecs) { this.additionalRemotes.put(remoteName, new AdditionalRemote(remoteName, remote, refSpecs)); return (B) this; }
/** * Converts the {@link #asRefSpecs()} into {@link UserRemoteConfig} instances. * * @return the list of {@link UserRemoteConfig} instances. */ @NonNull public final List<UserRemoteConfig> asRemoteConfigs() { List<UserRemoteConfig> result = new ArrayList<>(1 + additionalRemotes.size()); result.add(new UserRemoteConfig(remote(), remoteName(), joinRefSpecs(asRefSpecs()), credentialsId())); for (AdditionalRemote r : additionalRemotes.values()) { result.add(new UserRemoteConfig(r.remote(), r.remoteName(), joinRefSpecs(r.asRefSpecs()), credentialsId())); } return result; }
/** * Gets the ref specs to use for the git repository of the specified remote name. * * @param remoteName the additional remote name. * @return the ref specs for the named additional remote or {@code null} if the supplied name is not in * {@link #additionalRemoteNames()} */ @CheckForNull public final List<String> additionalRemoteRefSpecs(String remoteName) { AdditionalRemote additionalRemote = additionalRemotes.get(remoteName); return additionalRemote == null ? null : additionalRemote.refSpecs(); }