Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
<inceptionYear>2007</inceptionYear>

<properties>
<revision>3.10.2</revision>
<revision>3.11.0</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.121.1</jenkins.version>
<java.level>8</java.level>
<no-test-jar>false</no-test-jar>
<useBeta>true</useBeta>
<concurrency>1C</concurrency>
<scm-api-plugin.version>2.2.6</scm-api-plugin.version>
<scm-api-plugin.version>2.6.3</scm-api-plugin.version>
<jcasc.version>1.24</jcasc.version>
<maven.checkstyle.plugin.version>3.1.0</maven.checkstyle.plugin.version>
<maven.checkstyle.version>8.22</maven.checkstyle.version>
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -786,14 +786,14 @@ public void record(@NonNull SCMHead head, SCMRevision revision, boolean isMatch)
*/
@CheckForNull
@Override
protected SCMRevision retrieve(@NonNull final String revision, @NonNull final TaskListener listener) throws IOException, InterruptedException {
protected SCMRevision retrieve(@NonNull final String revision, @NonNull final TaskListener listener, @CheckForNull Item retrieveContext) throws IOException, InterruptedException {

final GitSCMSourceContext context =
new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits());
final GitSCMTelescope telescope = GitSCMTelescope.of(this);
if (telescope != null) {
final String remote = getRemote();
final StandardUsernameCredentials credentials = getCredentials();
final StandardUsernameCredentials credentials = getCredentials(retrieveContext);
telescope.validate(remote, credentials);
SCMRevision result = telescope.getRevision(remote, credentials, revision);
if (result != null) {
Expand Down Expand Up @@ -825,7 +825,7 @@ protected SCMRevision retrieve(@NonNull final String revision, @NonNull final Ta
git.using(tool.getGitExe());
}
final GitClient client = git.getClient();
client.addDefaultCredentials(getCredentials());
client.addDefaultCredentials(getCredentials(retrieveContext));
listener.getLogger().printf("Attempting to resolve %s from remote references...%n", revision);
boolean headsOnly = !context.wantOtherRefs() && context.wantBranches();
boolean tagsOnly = !context.wantOtherRefs() && context.wantTags();
Expand Down Expand Up @@ -1016,14 +1016,14 @@ public SCMRevision run(GitClient client, String remoteName) throws IOException,
*/
@NonNull
@Override
protected Set<String> retrieveRevisions(@NonNull final TaskListener listener) throws IOException, InterruptedException {
protected Set<String> retrieveRevisions(@NonNull final TaskListener listener, @CheckForNull Item retrieveContext) throws IOException, InterruptedException {

final GitSCMSourceContext context =
new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits());
final GitSCMTelescope telescope = GitSCMTelescope.of(this);
if (telescope != null) {
final String remote = getRemote();
final StandardUsernameCredentials credentials = getCredentials();
final StandardUsernameCredentials credentials = getCredentials(retrieveContext);
telescope.validate(remote, credentials);
Set<GitSCMTelescope.ReferenceType> referenceTypes = new HashSet<>();
if (context.wantBranches()) {
Expand All @@ -1048,7 +1048,7 @@ protected Set<String> retrieveRevisions(@NonNull final TaskListener listener) th
git.using(tool.getGitExe());
}
GitClient client = git.getClient();
client.addDefaultCredentials(getCredentials());
client.addDefaultCredentials(getCredentials(retrieveContext));
Set<String> revisions = new HashSet<>();
if (context.wantBranches() || context.wantTags() || context.wantOtherRefs()) {
listener.getLogger().println("Listing remote references...");
Expand Down Expand Up @@ -1237,13 +1237,18 @@ protected static Lock getCacheLock(String cacheEntry) {

@CheckForNull
protected StandardUsernameCredentials getCredentials() {
return getCredentials(getOwner());
}

@CheckForNull
private StandardUsernameCredentials getCredentials(@CheckForNull Item context) {
String credentialsId = getCredentialsId();
if (credentialsId == null) {
return null;
}
return CredentialsMatchers
.firstOrNull(
CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, getOwner(),
CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, context,
ACL.SYSTEM, URIRequirementBuilder.fromUri(getRemote()).build()),
CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId),
GitClient.CREDENTIALS_MATCHER));
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/jenkins/plugins/git/GitSCMFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import hudson.plugins.git.UserRemoteConfig;
import hudson.remoting.VirtualChannel;
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
import hudson.security.ACL;
import hudson.util.LogTaskListener;
import java.io.File;
Expand All @@ -61,6 +62,7 @@
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceDescriptor;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
Expand Down Expand Up @@ -279,6 +281,16 @@ public boolean supports(SCMSource source) {
return source instanceof AbstractGitSCMSource;
}

@Override
public boolean supportsDescriptor(SCMDescriptor descriptor) {
return descriptor instanceof GitSCM.DescriptorImpl;
}

@Override
public boolean supportsDescriptor(SCMSourceDescriptor descriptor) {
return AbstractGitSCMSource.class.isAssignableFrom(descriptor.clazz);
}

@Override
public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, @CheckForNull SCMRevision rev)
throws IOException, InterruptedException {
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceDescriptor;
import org.eclipse.jgit.lib.ObjectId;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
Expand Down Expand Up @@ -347,6 +348,13 @@ public void given_filesystem_when_askingChangesSinceNewRevision_then_changesAreP
assertThat(out.toString(), is(""));
}

@Issue("JENKINS-52964")
@Test
public void filesystem_supports_descriptor() throws Exception {
SCMSourceDescriptor descriptor = r.jenkins.getDescriptorByType(GitSCMSource.DescriptorImpl.class);
assertTrue(SCMFileSystem.supports(descriptor));
}

/** inline ${@link hudson.Functions#isWindows()} to prevent a transient remote classloader issue */
private boolean isWindows() {
return java.io.File.pathSeparatorChar==';';
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/jenkins/plugins/git/GitSCMSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import hudson.model.TopLevelItem;
import hudson.plugins.git.GitStatus;
import hudson.util.LogTaskListener;
import hudson.scm.SCMDescriptor;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
Expand All @@ -31,6 +32,7 @@
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceCriteria;
import jenkins.scm.api.SCMSourceDescriptor;
import jenkins.scm.api.SCMSourceOwner;
import jenkins.scm.api.metadata.PrimaryInstanceMetadataAction;
import jenkins.scm.api.trait.SCMSourceTrait;
Expand Down Expand Up @@ -340,6 +342,16 @@ public boolean supports(@NonNull String remote) {
return "http://git.test/telescope.git".equals(remote);
}

@Override
public boolean supportsDescriptor(SCMDescriptor descriptor) {
return false;
}

@Override
public boolean supportsDescriptor(SCMSourceDescriptor descriptor) {
return false;
}

@Override
public void validate(@NonNull String remote, StandardCredentials credentials)
throws IOException, InterruptedException {
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/jenkins/plugins/git/GitSCMTelescopeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.scm.NullSCM;
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
import hudson.search.Search;
import hudson.search.SearchIndex;
import hudson.security.ACL;
Expand Down Expand Up @@ -498,6 +499,16 @@ public boolean supports(String remote) {
return allowedRemote.equals(remote);
}

@Override
public boolean supportsDescriptor(SCMDescriptor descriptor) {
return false;
}

@Override
public boolean supportsDescriptor(SCMSourceDescriptor descriptor) {
return false;
}

@Override
public void validate(String remote, StandardCredentials credentials) throws IOException, InterruptedException {
}
Expand Down