/** * @return the {@link UserRemoteConfig} instances. * @deprecated use {@link GitSCMBuilder#asRemoteConfigs()} */ @Deprecated @Restricted(DoNotUse.class) @RestrictedSince("3.4.0") protected List<UserRemoteConfig> getRemoteConfigs() { List<RefSpec> refSpecs = getRefSpecs(); List<UserRemoteConfig> result = new ArrayList<>(refSpecs.size()); String remote = getRemote(); for (RefSpec refSpec : refSpecs) { result.add(new UserRemoteConfig(remote, getRemoteName(), refSpec.toString(), getCredentialsId())); } return result; }
/** * Returns true if the branchName isn't matched by includes or is matched by excludes. * * @param branchName name of branch to be tested * @return true if branchName is excluded or is not included * @deprecated use {@link WildcardSCMSourceFilterTrait} */ @Deprecated @Restricted(DoNotUse.class) @RestrictedSince("3.4.0") protected boolean isExcluded (String branchName){ return !Pattern.matches(getPattern(getIncludes()), branchName) || (Pattern.matches(getPattern(getExcludes()), branchName)); }
@CheckForNull protected StandardUsernameCredentials getCredentials() { String credentialsId = getCredentialsId(); if (credentialsId == null) { return null; } return CredentialsMatchers .firstOrNull( CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, getOwner(), ACL.SYSTEM, URIRequirementBuilder.fromUri(getRemote()).build()), CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId), GitClient.CREDENTIALS_MATCHER)); }
protected String getCacheEntry() { return getCacheEntry(getRemote()); }
GitSCMBuilder<?> builder = gitSCMSource.newBuilder(head, rev); String cacheEntry = gitSCMSource.getCacheEntry(); Lock cacheLock = AbstractGitSCMSource.getCacheLock(cacheEntry); cacheLock.lock(); try { File cacheDir = AbstractGitSCMSource.getCacheDir(cacheEntry); Git git = Git.with(listener, new EnvVars(EnvVars.masterEnvVars)).in(cacheDir); GitTool tool = gitSCMSource.resolveGitTool(builder.gitTool()); if (tool != null) { git.using(tool.getGitExe()); client.addDefaultCredentials(gitSCMSource.getCredentials()); if (!client.hasGitRepo()) { listener.getLogger().println("Creating git repository in " + cacheDir); listener.getLogger().println("Setting " + remoteName + " to " + gitSCMSource.getRemote()); client.setRemoteUrl(remoteName, gitSCMSource.getRemote()); listener.getLogger().println("Fetching & pruning " + remoteName + "..."); URIish remoteURI = null; return new GitSCMFileSystem(client, gitSCMSource.getRemote(), Constants.R_REMOTES+remoteName+"/"+head.getName(), (AbstractGitSCMSource.SCMRevisionImpl) rev); } finally {
/** * {@inheritDoc} */ @NonNull @Override public SCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) { GitSCMBuilder<?> builder = newBuilder(head, revision); if (MethodUtils.isOverridden(AbstractGitSCMSource.class, getClass(), "getExtensions")) { builder.withExtensions(getExtensions()); } if (MethodUtils.isOverridden(AbstractGitSCMSource.class, getClass(), "getBrowser")) { builder.withBrowser(getBrowser()); } if (MethodUtils.isOverridden(AbstractGitSCMSource.class, getClass(), "getGitTool")) { builder.withGitTool(getGitTool()); } if (MethodUtils.isOverridden(AbstractGitSCMSource.class, getClass(), "getRefSpecs")) { List<String> specs = new ArrayList<>(); for (RefSpec spec: getRefSpecs()) { specs.add(spec.toString()); } builder.withoutRefSpecs().withRefSpecs(specs); } builder.withTraits(getTraits()); decorate(builder); return builder.build(); }
private <T extends StandardCredentials> T credentials(AbstractGitSCMSource source, @Nonnull Class<T> type) { String credentialsId = source.getCredentialsId(); if (credentialsId == null) { return null; } return CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials( type, source.getOwner(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), CredentialsMatchers.allOf( CredentialsMatchers.withId(credentialsId), CredentialsMatchers.instanceOf(type))); } }
/** * {@inheritDoc} */ @NonNull @Override protected Set<String> retrieveRevisions(@NonNull final TaskListener listener) throws IOException, InterruptedException { final GitSCMSourceContext context = new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits()); return doRetrieve(new Retriever<Set<String>>() { @Override public Set<String> run(GitClient client, String remoteName) throws IOException, InterruptedException { Set<String> revisions = new HashSet<String>(); if (context.wantBranches()) { for (Branch branch : client.getRemoteBranches()) { revisions.add(branch.getName().replaceFirst( "^" + Pattern.quote(context.remoteName()) + "/", "" )); } } if (context.wantTags()) { revisions.addAll(client.getTagNames("*")); } return revisions; } }, context, listener, false); }
/** * Instantiates a new {@link GitSCMBuilder}. * Subclasses should override this method if they want to use a custom {@link GitSCMBuilder} or if they need * to pre-decorare the builder. * * @param head the {@link SCMHead}. * @param revision the {@link SCMRevision}. * @return the {@link GitSCMBuilder} * @see #decorate(GitSCMBuilder) for post-decoration. */ protected GitSCMBuilder<?> newBuilder(@NonNull SCMHead head, @CheckForNull SCMRevision revision) { return new GitSCMBuilder<>(head, revision, getRemote(), getCredentialsId()); }
/** * {@inheritDoc} */ @NonNull @Override protected List<Action> retrieveActions(@NonNull SCMHead head, @CheckForNull SCMHeadEvent event, @NonNull TaskListener listener) throws IOException, InterruptedException { SCMSourceOwner owner = getOwner(); if (owner instanceof Actionable) { for (GitRemoteHeadRefAction a: ((Actionable) owner).getActions(GitRemoteHeadRefAction.class)) { if (getRemote().equals(a.getRemote())) { if (head.getName().equals(a.getName())) { return Collections.<Action>singletonList(new PrimaryInstanceMetadataAction()); } } } } return Collections.emptyList(); }
BranchSpec branchSpec = gitSCM.getBranches().get(0); String remote = config.getUrl(); String cacheEntry = AbstractGitSCMSource.getCacheEntry(remote); Lock cacheLock = AbstractGitSCMSource.getCacheLock(cacheEntry); cacheLock.lock(); try { File cacheDir = AbstractGitSCMSource.getCacheDir(cacheEntry); Git git = Git.with(listener, new EnvVars(EnvVars.masterEnvVars)).in(cacheDir); GitTool tool = gitSCM.resolveGitTool(listener);
/** * {@inheritDoc} */ protected boolean isCategoryEnabled(@NonNull SCMHeadCategory category) { if (super.isCategoryEnabled(category)) { for (SCMSourceTrait trait : traits) { if (trait.isCategoryEnabled(category)) { return true; } } } return false; }
Lock cacheLock = AbstractGitSCMSource.getCacheLock(cacheEntry); cacheLock.lock(); try { File cacheDir = AbstractGitSCMSource.getCacheDir(cacheEntry); if (cacheDir == null || !cacheDir.isDirectory()) { throw new IOException("Closed");
static public String filterFromGitSCMSource(AbstractGitSCMSource gitscm, String defaultFilter) { if (gitscm == null) { logger.log(Level.FINE, "Git SCMSource unavailable. Using default value: {0}", defaultFilter); return defaultFilter; } StringBuffer filter = new StringBuffer(defaultFilter); final String includes = gitscm.getIncludes(); if (includes != null && !includes.isEmpty()) { for(String part : includes.split("\\s+")) { filter.append(String.format("%s ", part.replaceAll("\\*\\/", "d:"))); } } logger.log(Level.FINE, "Git includes transformation to filter result: {1} -> {0}; default: {2}", new Object[]{ filter, includes, defaultFilter }); return filter.toString().trim(); }
public String getRemote(AbstractGitSCMSource source) { if (source.getCredentialsId() != null && credentials(source, StandardCredentials.class) instanceof SSHUserPrivateKey) { return getSshUrl(); } else { return getHttpUrl(); } }
@Override public GitRepositoryBrowser getBrowser() { try { return new GitLab(project.getWebUrl(), gitLabAPI(getSourceSettings()).getVersion()); } catch (GitLabAPIException e) { LOGGER.warning("could not determine gitlab-version:" + e.getMessage()); return super.getBrowser(); } }
@Nonnull @Override public SCM build(@Nonnull SCMHead head, @CheckForNull SCMRevision revision) { GitSCM scm; if (head instanceof GitLabSCMHead) { scm = ((GitLabSCMHead) head).createSCM(this); if (revision instanceof SCMRevisionImpl) { scm.getExtensions().add(new BuildChooserSetting(new SpecificRevisionBuildChooser((SCMRevisionImpl) revision))); } } else { scm = (GitSCM) super.build(head, revision); scm.setBrowser(getBrowser()); } return scm; }
/** * Constructor. * * @param client the client * @param remote the remote GIT URL * @param head identifier for the head commit to be referenced * @param rev the revision. * @throws IOException on I/O error * @throws InterruptedException on thread interruption */ protected GitSCMFileSystem(GitClient client, String remote, final String head, @CheckForNull AbstractGitSCMSource.SCMRevisionImpl rev) throws IOException, InterruptedException { super(rev); this.remote = remote; this.head = head; cacheEntry = AbstractGitSCMSource.getCacheEntry(remote); listener = new LogTaskListener(LOGGER, Level.FINER); this.client = client; commitId = rev == null ? invoke(new FSFunction<ObjectId>() { @Override public ObjectId invoke(Repository repository) throws IOException, InterruptedException { return repository.getRef(head).getObjectId(); } }) : ObjectId.fromString(rev.getHash()); }
boolean prune) throws IOException, InterruptedException { String cacheEntry = getCacheEntry(); Lock cacheLock = getCacheLock(cacheEntry); cacheLock.lock(); try { File cacheDir = getCacheDir(cacheEntry); Git git = Git.with(listener, new EnvVars(EnvVars.masterEnvVars)).in(cacheDir); GitTool tool = resolveGitTool(context.gitTool()); if (tool != null) { git.using(tool.getGitExe()); client.addDefaultCredentials(getCredentials()); if (!client.hasGitRepo()) { listener.getLogger().println("Creating git repository in " + cacheDir); listener.getLogger().println("Setting " + remoteName + " to " + getRemote()); client.setRemoteUrl(remoteName, getRemote()); listener.getLogger().println((prune ? "Fetching & pruning " : "Fetching ") + remoteName + "..."); FetchCommand fetch = client.fetch_();
protected SCMRevision retrieve(@NonNull final SCMHead head, @NonNull TaskListener listener) throws IOException, InterruptedException { final GitSCMSourceContext context = new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits()); return doRetrieve(new Retriever<SCMRevision>() { @Override public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException {