diff --git a/pom.xml b/pom.xml index bba023176e..e632c47daa 100644 --- a/pom.xml +++ b/pom.xml @@ -24,14 +24,14 @@ 2007 - 3.10.2 + 3.11.0 -SNAPSHOT 2.121.1 8 false true 1C - 2.2.6 + 2.6.3 1.24 3.1.0 8.22 diff --git a/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java b/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java index e343c988f4..c4e526e199 100644 --- a/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java +++ b/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java @@ -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) { @@ -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(); @@ -1016,14 +1016,14 @@ public SCMRevision run(GitClient client, String remoteName) throws IOException, */ @NonNull @Override - protected Set retrieveRevisions(@NonNull final TaskListener listener) throws IOException, InterruptedException { + protected Set 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 referenceTypes = new HashSet<>(); if (context.wantBranches()) { @@ -1048,7 +1048,7 @@ protected Set retrieveRevisions(@NonNull final TaskListener listener) th git.using(tool.getGitExe()); } GitClient client = git.getClient(); - client.addDefaultCredentials(getCredentials()); + client.addDefaultCredentials(getCredentials(retrieveContext)); Set revisions = new HashSet<>(); if (context.wantBranches() || context.wantTags() || context.wantOtherRefs()) { listener.getLogger().println("Listing remote references..."); @@ -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)); diff --git a/src/main/java/jenkins/plugins/git/GitSCMFileSystem.java b/src/main/java/jenkins/plugins/git/GitSCMFileSystem.java index 1e27a0f79d..aae1097de0 100644 --- a/src/main/java/jenkins/plugins/git/GitSCMFileSystem.java +++ b/src/main/java/jenkins/plugins/git/GitSCMFileSystem.java @@ -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; @@ -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; @@ -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 { diff --git a/src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java b/src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java index 1741553b2c..5c20d4b0a7 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java @@ -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; @@ -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==';'; diff --git a/src/test/java/jenkins/plugins/git/GitSCMSourceTest.java b/src/test/java/jenkins/plugins/git/GitSCMSourceTest.java index e6edb78d43..0a488c4563 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMSourceTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMSourceTest.java @@ -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; @@ -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; @@ -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 { diff --git a/src/test/java/jenkins/plugins/git/GitSCMTelescopeTest.java b/src/test/java/jenkins/plugins/git/GitSCMTelescopeTest.java index f70e97030a..55f82c19b8 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMTelescopeTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMTelescopeTest.java @@ -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; @@ -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 { }