@Override public SCMRevision getTrustedRevision(SCMRevision revision, TaskListener listener) throws IOException, InterruptedException { String branch = revision.getHead().getName(); if (branch.equals("master")) { return revision; } else { listener.getLogger().println("not trusting " + branch); return fetch(new SCMHead("master"), listener); } } @Override public SCMSourceDescriptor getDescriptor() {
/** * {@inheritDoc} */ @NonNull @Override public SubversionSCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) { if (revision != null && !head.equals(revision.getHead())) { revision = null; } if (revision != null && !(revision instanceof SCMRevisionImpl)) { revision = null; } StringBuilder remote = new StringBuilder(remoteBase); if (!remoteBase.endsWith("/")) { remote.append('/'); } remote.append(head.getName()); if (revision != null) { remote.append('@').append(((SCMRevisionImpl) revision).getRevision()); } else if (remote.indexOf("@") != -1) { // name contains an @ so need to ensure there is an @ at the end of the name remote.append('@'); } return new SubversionSCM(remote.toString(), credentialsId, "."); }
for (SCMHead h : includes) { if (h instanceof BranchSCMHead) { branchNames.add(h.getName()); } else if (h instanceof PullRequestSCMHead) { pullRequestNumbers.add(((PullRequestSCMHead) h).getNumber()); if (SCMHeadOrigin.DEFAULT.equals(h.getOrigin())) { branchNames.add(((PullRequestSCMHead) h).getOriginName()); tagNames.add(h.getName());
@Test public void ofSourceRevision() throws Exception { sampleRepo.init(); sampleRepo.svnkit("copy", "--message=branching", sampleRepo.trunkUrl(), sampleRepo.branchesUrl() + "/dev"); sampleRepo.svnkit("switch", sampleRepo.branchesUrl() + "/dev", sampleRepo.wc()); SCMSource source = new SubversionSCMSource(null, sampleRepo.prjUrl()); SCMRevision revision = source.fetch(new SCMHead("branches/dev"), null); sampleRepo.write("file", "modified"); sampleRepo.svnkit("commit", "--message=dev1", sampleRepo.wc()); try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"), revision)) { assertThat(fs, notNullValue()); SCMFile root = fs.getRoot(); assertThat(root, notNullValue()); Iterable<SCMFile> children = root.children(); Iterator<SCMFile> iterator = children.iterator(); assertThat(iterator.hasNext(), is(true)); SCMFile file = iterator.next(); assertThat(iterator.hasNext(), is(false)); assertThat(file.getName(), is("file")); assertThat(file.contentAsString(), is("")); } }
sampleRepo.svnkit("commit", "--message=dev1", sampleRepo.wc()); SCMSource source = new SubversionSCMSource(null, sampleRepo.prjUrl()); try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"));) { assertThat(fs, notNullValue()); assertThat(fs.getRoot(), notNullValue()); Iterable<SCMFile> children = fs.getRoot().children(); Set<String> names = new TreeSet<String>(); assertThat(names, containsInAnyOrder(is("file"), is("file2"), is("dir"))); assertThat(file.getType(), is(SCMFile.Type.REGULAR_FILE)); assertThat(file2.getType(), is(SCMFile.Type.REGULAR_FILE));
@Test public void lastModified_Smokes() throws Exception { long currentTime = isWindows() ? System.currentTimeMillis() / 1000L * 1000L : System.currentTimeMillis(); sampleRepo.init(); sampleRepo.svnkit("copy", "--message=branching", sampleRepo.trunkUrl(), sampleRepo.branchesUrl() + "/dev"); sampleRepo.svnkit("switch", sampleRepo.branchesUrl() + "/dev", sampleRepo.wc()); SCMSource source = new SubversionSCMSource(null, sampleRepo.prjUrl()); SCMRevision revision = source.fetch(new SCMHead("branches/dev"), null); long oneMinute = 60*1000; sampleRepo.write("file", "modified"); sampleRepo.svnkit("commit", "--message=dev1", sampleRepo.wc()); try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"), revision);) { long lastModified = fs.lastModified(); //ensure the timestamp is from after we started but not in the distant future assertThat(lastModified, greaterThanOrEqualTo(currentTime)); assertThat(lastModified, lessThanOrEqualTo(currentTime + oneMinute)); SCMFile file = fs.getRoot().child("file"); lastModified = file.lastModified(); assertThat(lastModified, greaterThanOrEqualTo(currentTime)); assertThat(lastModified, lessThanOrEqualTo(currentTime + oneMinute)); } }
@NonNull @Override public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource source) { if (source instanceof MercurialSCMSource) { MercurialSCMSource hg = (MercurialSCMSource) source; String repository = hg.getSource(); if (repository != null) { if (MercurialStatus.looselyMatches(payload.getUrl(), repository)) { SCMHead head = new SCMHead(getPayload().getBranch()); SCMRevision revision = new MercurialSCMSource.MercurialRevision( head, getPayload().getChangesetId() ); return Collections.singletonMap(head, revision); } } } return Collections.emptyMap(); }
assertRevision(source.fetch(new SCMHead("trunk"), listener), "trunk", source, run, listener); assertRevision(source.fetch(new SCMHead("branches/dev"), listener), "dev2", source, run, listener); assertRevision(source.fetch(new SCMHead("tags/dev-1"), listener), "dev1", source, run, listener); assertRevision(source.fetch("\n", listener), null, source, run, listener); assertThat(source.fetchRevisions(listener), hasItems("trunk", "branches/dev", "tags/dev-1"));
public GitHubSCMProbe(GitHub github, GHRepository repo, SCMHead head, SCMRevision revision) { this.gitHub = github; this.revision = revision; this.repo = repo; this.name = head.getName(); if (head instanceof PullRequestSCMHead) { PullRequestSCMHead pr = (PullRequestSCMHead) head; this.ref = "refs/pull/" + pr.getNumber() + (pr.isMerge() ? "/merge" : "/head"); } else { this.ref = "refs/heads/" + head.getName(); } }
@Nonnull @Override public Branch getBranch(@Nonnull P project) { BranchProjectProperty property = project.getProperty(BranchProjectProperty.class); /* * Ugly hackish stuff, in the event that the user configures a branch project directly, thereby removing the * BranchProjectProperty. The property must exist and we can't bash the @Nonnull return value restriction! * * Fudge some generic Branch with the expectation that indexing will soon reset the Branch with proper values, * or that it will be converted to Branch.Dead and the guessed values for sourceId and properties won't matter. */ if (property == null) { Branch branch = new Branch("unknown", new SCMHead(project.getDisplayName()), project.getScm(), Collections.<BranchProperty>emptyList()); setBranch(project, branch); return branch; } return property.getBranch(); }
/** * {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } SCMRevisionImpl that = (SCMRevisionImpl) o; return StringUtils.equals(hash, that.hash) && getHead().equals(that.getHead()); }
public boolean checkCriteria(@Nonnull GitHubCause<?> cause) throws IOException { if (nonNull(criteria)) { GitHubSCMRevision revision = cause.createSCMRevision(source.getId()); listener.getLogger().println(""); listener.getLogger().println("Checking " + revision.getHead().getPronoun()); if (!criteria.isHead(source.newProbe(revision.getHead(), revision), listener)) { listener.getLogger().println(" Didn't meet criteria\n"); return false; } listener.getLogger().println(" Met criteria\n"); } return true; }
sampleRepo.svnkit("commit", "--message=dev1", sampleRepo.wc()); SCMSource source = new SubversionSCMSource(null, sampleRepo.prjUrl()); try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"))) { assertThat(fs, notNullValue()); assertThat(fs.getRoot(), notNullValue()); Iterable<SCMFile> children = fs.getRoot().children(); Iterator<SCMFile> iterator = children.iterator(); assertThat(iterator.hasNext(), is(true)); SCMFile dir = iterator.next(); assertThat(iterator.hasNext(), is(false));
@Override public String toString() { return getHead().getName() + ":" + hash; } public @Nonnull String getHash() {
for (SCMHead h : includes) { if (h instanceof BranchSCMHead) { branchNames.add(h.getName()); } else if (h instanceof PullRequestSCMHead) { pullRequestNumbers.add(Long.parseLong(((PullRequestSCMHead) h).getId())); if (SCMHeadOrigin.DEFAULT.equals(h.getOrigin())) { branchNames.add(((PullRequestSCMHead) h).getOriginName()); tagNames.add(h.getName());
@Override public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException { String hash; try { hash = client.revParse(revision).name(); } catch (GitException x) { // Try prepending remote name in case it was a branch. try { hash = client.revParse(context.remoteName() + "/" + revision).name(); } catch (GitException x2) { listener.getLogger().println(x.getMessage()); listener.getLogger().println(x2.getMessage()); return null; } } return new SCMRevisionImpl(new SCMHead(revision), hash); } },
@Override public boolean equivalent(ChangeRequestSCMRevision<?> o) { if (!(o instanceof PullRequestSCMRevision)) { return false; } PullRequestSCMRevision other = (PullRequestSCMRevision) o; return getHead().equals(other.getHead()) && pullHash.equals(other.pullHash); }
@Override public <T> String getText(Message<T> text, T context) { if (text == AbstractItem.PRONOUN && context instanceof WorkflowJob) { WorkflowJob job = (WorkflowJob) context; BranchJobProperty property = job.getProperty(BranchJobProperty.class); if (property != null) { return property.getBranch().getHead().getPronoun(); } } return null; } }