Skip to content

Commit 39f958b

Browse files
committed
Remove injection
The `GitScriptlerRepository` and `GitScriptlerRepositorySSHAccess` classes used injection to receive objects of the given type. Switch from injection to dynamic lookup using `ExtensionList`.
1 parent 364927f commit 39f958b

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/main/java/org/jenkinsci/plugins/scriptler/git/GitScriptlerRepository.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import hudson.Extension;
77
import hudson.ExtensionList;
88
import hudson.model.RootAction;
9-
import jakarta.inject.Inject;
109
import java.io.IOException;
1110
import java.net.MalformedURLException;
1211
import java.net.URL;
@@ -34,6 +33,8 @@
3433
import org.jenkinsci.plugins.scriptler.ScriptlerPermissions;
3534
import org.jenkinsci.plugins.scriptler.SyncUtil;
3635
import org.jenkinsci.plugins.scriptler.config.ScriptlerConfiguration;
36+
import org.kohsuke.accmod.Restricted;
37+
import org.kohsuke.accmod.restrictions.NoExternalUse;
3738

3839
/**
3940
* Exposes Git repository at <code>/scriptler.git</code>
@@ -45,9 +46,6 @@
4546
public class GitScriptlerRepository extends FileBackedHttpGitRepository implements RootAction {
4647
private static final Logger LOGGER = Logger.getLogger(GitScriptlerRepository.class.getName());
4748

48-
@Inject
49-
public SSHD sshd;
50-
5149
private static final int LOG_MAX_COMMITS = 20;
5250
static final String REPOID = "scriptler.git";
5351

@@ -80,9 +78,14 @@ public String getHttpCloneUrl() {
8078
return Jenkins.get().getRootUrl() + REPOID;
8179
}
8280

81+
@Restricted(NoExternalUse.class)
82+
public int getSshdPort() {
83+
return SSHD.get().getActualPort();
84+
}
85+
8386
public String getSshCloneUrl() throws MalformedURLException {
8487
String hostname = new URL(Objects.requireNonNull(Jenkins.get().getRootUrl())).getHost();
85-
int port = sshd.getActualPort();
88+
int port = getSshdPort();
8689
return "ssh://" + hostname + ":" + port + "/" + REPOID;
8790
}
8891

src/main/java/org/jenkinsci/plugins/scriptler/git/GitScriptlerRepositorySSHAccess.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package org.jenkinsci.plugins.scriptler.git;
55

66
import hudson.Extension;
7-
import jakarta.inject.Inject;
7+
import hudson.ExtensionList;
88
import java.io.IOException;
99
import org.eclipse.jgit.transport.ReceivePack;
1010
import org.eclipse.jgit.transport.UploadPack;
@@ -19,15 +19,15 @@
1919
@Extension
2020
public class GitScriptlerRepositorySSHAccess extends RepositoryResolver {
2121

22-
@Inject
23-
GitScriptlerRepository repo;
24-
2522
/**
2623
* @see org.jenkinsci.plugins.gitserver.RepositoryResolver#createReceivePack(java.lang.String)
2724
*/
2825
@Override
2926
public ReceivePack createReceivePack(String fullRepositoryName) throws IOException {
30-
if (isMine(fullRepositoryName)) return repo.createReceivePack(repo.openRepository());
27+
if (isMine(fullRepositoryName)) {
28+
GitScriptlerRepository repo = ExtensionList.lookupSingleton(GitScriptlerRepository.class);
29+
return repo.createReceivePack(repo.openRepository());
30+
}
3131
return null;
3232
}
3333

@@ -36,7 +36,10 @@ public ReceivePack createReceivePack(String fullRepositoryName) throws IOExcepti
3636
*/
3737
@Override
3838
public UploadPack createUploadPack(String fullRepositoryName) throws IOException {
39-
if (isMine(fullRepositoryName)) return new UploadPack(repo.openRepository());
39+
if (isMine(fullRepositoryName)) {
40+
GitScriptlerRepository repo = ExtensionList.lookupSingleton(GitScriptlerRepository.class);
41+
return new UploadPack(repo.openRepository());
42+
}
4043
return null;
4144
}
4245

src/main/resources/org/jenkinsci/plugins/scriptler/git/GitScriptlerRepository/index.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<p>${%blurb}</p>
88
<pre>
99
${%git_clone_command(it.httpCloneUrl)}
10-
<j:if test="${it.sshd.actualPort > 0}">${%git_clone_command(it.sshCloneUrl)}</j:if>
10+
<j:if test="${it.sshdPort > 0}">${%git_clone_command(it.sshCloneUrl)}</j:if>
1111
</pre>
1212
<j:if test="${it.hasPushPermission()}">
1313
<p>

0 commit comments

Comments
 (0)