Skip to content

Commit 1f2238c

Browse files
authored
Merge pull request #767 from res0nance/annotate
[JENKINS-59540] Add annotation to getUrl
2 parents 7449005 + 06f94df commit 1f2238c

File tree

3 files changed

+47
-37
lines changed

3 files changed

+47
-37
lines changed

src/main/java/hudson/plugins/git/UserRemoteConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public String getRefspec() {
6868
}
6969

7070
@Exported
71+
@CheckForNull
7172
public String getUrl() {
7273
return url;
7374
}

src/main/java/jenkins/plugins/git/GitSCMFileSystem.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,15 @@ public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, @CheckForNull
282282
if (rev != null && !(rev instanceof AbstractGitSCMSource.SCMRevisionImpl)) {
283283
return null;
284284
}
285-
TaskListener listener = new LogTaskListener(LOGGER, Level.FINE);
286285
GitSCM gitSCM = (GitSCM) scm;
287286
UserRemoteConfig config = gitSCM.getUserRemoteConfigs().get(0);
288287
BranchSpec branchSpec = gitSCM.getBranches().get(0);
289288
String remote = config.getUrl();
289+
TaskListener listener = new LogTaskListener(LOGGER, Level.FINE);
290+
if (remote == null) {
291+
listener.getLogger().println("Git remote url is null");
292+
return null;
293+
}
290294
String cacheEntry = AbstractGitSCMSource.getCacheEntry(remote);
291295
Lock cacheLock = AbstractGitSCMSource.getCacheLock(cacheEntry);
292296
cacheLock.lock();

src/main/java/jenkins/plugins/git/GitSCMTelescope.java

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,13 @@ public final boolean supports(@NonNull SCM source) {
137137
GitSCM git = (GitSCM) source;
138138
List<UserRemoteConfig> configs = git.getUserRemoteConfigs();
139139
List<BranchSpec> branches = git.getBranches();
140-
return configs.size() == 1
141-
&& supports(configs.get(0).getUrl())
140+
if (configs.size() == 1) {
141+
String remote = configs.get(0).getUrl();
142+
return remote != null
143+
&& supports(remote)
142144
&& branches.size() == 1
143145
&& !branches.get(0).getName().contains("*");
146+
}
144147
}
145148
return false;
146149
}
@@ -183,48 +186,50 @@ public final SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, SCMRevis
183186
GitSCM git = (GitSCM) scm;
184187
List<UserRemoteConfig> configs = git.getUserRemoteConfigs();
185188
List<BranchSpec> branches = git.getBranches();
186-
if (configs.size() == 1 && supports(configs.get(0).getUrl())
187-
&& branches.size() == 1 && !branches.get(0).getName().contains("*")) {
189+
if (configs.size() == 1) {
188190
UserRemoteConfig config = configs.get(0);
189-
StandardCredentials credentials;
190-
String credentialsId = config.getCredentialsId();
191191
String remote = config.getUrl();
192-
if (credentialsId != null) {
193-
List<StandardUsernameCredentials> urlCredentials = CredentialsProvider
194-
.lookupCredentials(StandardUsernameCredentials.class, owner,
195-
owner instanceof Queue.Task
196-
? Tasks.getAuthenticationOf((Queue.Task) owner)
197-
: ACL.SYSTEM, URIRequirementBuilder.fromUri(remote).build());
198-
credentials = CredentialsMatchers.firstOrNull(
199-
urlCredentials,
200-
CredentialsMatchers
201-
.allOf(CredentialsMatchers.withId(credentialsId), GitClient.CREDENTIALS_MATCHER)
202-
);
203-
} else {
204-
credentials = null;
205-
}
206-
validate(remote, credentials);
207-
SCMHead head;
208-
if (rev == null) {
209-
String name = branches.get(0).getName();
210-
if (name.startsWith(Constants.R_TAGS)) {
211-
head = new GitTagSCMHead(
212-
name.substring(Constants.R_TAGS.length()),
213-
getTimestamp(remote, credentials, name)
192+
if (remote != null && supports(remote)
193+
&& branches.size() == 1 && !branches.get(0).getName().contains("*")) {
194+
StandardCredentials credentials;
195+
String credentialsId = config.getCredentialsId();
196+
if (credentialsId != null) {
197+
List<StandardUsernameCredentials> urlCredentials = CredentialsProvider
198+
.lookupCredentials(StandardUsernameCredentials.class, owner,
199+
owner instanceof Queue.Task
200+
? Tasks.getAuthenticationOf((Queue.Task) owner)
201+
: ACL.SYSTEM, URIRequirementBuilder.fromUri(remote).build());
202+
credentials = CredentialsMatchers.firstOrNull(
203+
urlCredentials,
204+
CredentialsMatchers
205+
.allOf(CredentialsMatchers.withId(credentialsId), GitClient.CREDENTIALS_MATCHER)
214206
);
215-
} else if (name.startsWith(Constants.R_HEADS)) {
216-
head = new GitBranchSCMHead(name.substring(Constants.R_HEADS.length()));
217207
} else {
218-
if (name.startsWith(config.getName() + "/")) {
219-
head = new GitBranchSCMHead(name.substring(config.getName().length() + 1));
208+
credentials = null;
209+
}
210+
validate(remote, credentials);
211+
SCMHead head;
212+
if (rev == null) {
213+
String name = branches.get(0).getName();
214+
if (name.startsWith(Constants.R_TAGS)) {
215+
head = new GitTagSCMHead(
216+
name.substring(Constants.R_TAGS.length()),
217+
getTimestamp(remote, credentials, name)
218+
);
219+
} else if (name.startsWith(Constants.R_HEADS)) {
220+
head = new GitBranchSCMHead(name.substring(Constants.R_HEADS.length()));
220221
} else {
221-
head = new GitBranchSCMHead(name);
222+
if (name.startsWith(config.getName() + "/")) {
223+
head = new GitBranchSCMHead(name.substring(config.getName().length() + 1));
224+
} else {
225+
head = new GitBranchSCMHead(name);
226+
}
222227
}
228+
} else {
229+
head = rev.getHead();
223230
}
224-
} else {
225-
head = rev.getHead();
231+
return build(remote, credentials, head, rev);
226232
}
227-
return build(remote, credentials, head, rev);
228233
}
229234
}
230235
return null;

0 commit comments

Comments
 (0)