Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-37953 Add support to ProxySCM
- Loading branch information
Showing
12 changed files
with
191 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/scms/EmptySCM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package net.uaznia.lukanus.hudson.plugins.gitparameter.scms; | ||
|
||
import hudson.scm.SCM; | ||
|
||
public class EmptySCM implements SCMWrapper { | ||
@Override | ||
public SCM getSCM() { | ||
return null; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/scms/ProxySCM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.uaznia.lukanus.hudson.plugins.gitparameter.scms; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import hudson.scm.SCM; | ||
|
||
public class ProxySCM implements SCMWrapper { | ||
public static final String PROXY_SCM_CLASS_NAME = "hudson.plugins.templateproject.ProxySCM"; | ||
private static final Logger LOGGER = Logger.getLogger(ProxySCM.class.getName()); | ||
private SCM scm; | ||
|
||
public ProxySCM(SCM scm) { | ||
this.scm = scm; | ||
} | ||
|
||
@Override | ||
public SCM getSCM() { | ||
//((ProxySCM)projectScm).getProjectScm() | ||
try { | ||
Class<?> clazz = scm.getClass(); | ||
Method getProjectScmMethod = clazz.getDeclaredMethod("getProjectScm"); | ||
|
||
SCM projectSCM = (SCM) getProjectScmMethod.invoke(scm); | ||
return projectSCM; | ||
} catch (Exception e) { | ||
LOGGER.log(Level.SEVERE, Messages.ProxySCM_getSCMFromProxySCM(), e); | ||
} | ||
return null; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/scms/RepoSCM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package net.uaznia.lukanus.hudson.plugins.gitparameter.scms; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import hudson.plugins.git.GitSCM; | ||
import hudson.plugins.git.UserRemoteConfig; | ||
import hudson.scm.SCM; | ||
|
||
public class RepoSCM implements SCMWrapper { | ||
public static final String REPO_SCM_CLASS_NAME = "hudson.plugins.repo.RepoScm"; | ||
private static final String REPO_SCM_NAME = "repo"; | ||
private static final String REPO_MANIFESTS_DIR = ".repo/manifests"; | ||
private static final Logger LOGGER = Logger.getLogger(RepoSCM.class.getName()); | ||
private SCM scm; | ||
|
||
public RepoSCM(SCM scm) { | ||
this.scm = scm; | ||
} | ||
|
||
@Override | ||
public SCM getSCM() { | ||
try { | ||
Class<?> clazz = scm.getClass(); | ||
Method method = clazz.getDeclaredMethod("getManifestRepositoryUrl"); | ||
String repositoryUrl = (String) method.invoke(scm); | ||
UserRemoteConfig config = new UserRemoteConfig(repositoryUrl, REPO_SCM_NAME, null, null); | ||
List<UserRemoteConfig> configs = new ArrayList<>(); | ||
configs.add(config); | ||
return new GitSCM(configs, null, false, null, null, null, null); | ||
} catch (Exception e) { | ||
LOGGER.log(Level.SEVERE, Messages.RepoSCM_getRepoScmFailed(), e); | ||
} | ||
return null; | ||
} | ||
|
||
public static boolean isRepoSCM(String repositoryName) { | ||
return REPO_SCM_NAME.equals(repositoryName); | ||
} | ||
|
||
public static String getRepoMainfestsDir() { | ||
return REPO_MANIFESTS_DIR; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/scms/SCMFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package net.uaznia.lukanus.hudson.plugins.gitparameter.scms; | ||
|
||
import static net.uaznia.lukanus.hudson.plugins.gitparameter.scms.ProxySCM.PROXY_SCM_CLASS_NAME; | ||
import static net.uaznia.lukanus.hudson.plugins.gitparameter.scms.RepoSCM.REPO_SCM_CLASS_NAME; | ||
|
||
import hudson.plugins.git.GitSCM; | ||
import hudson.scm.SCM; | ||
import net.uaznia.lukanus.hudson.plugins.gitparameter.jobs.JobWrapper; | ||
|
||
public class SCMFactory { | ||
private static final SCMWrapper EMPTY_SCM = new EmptySCM(); | ||
|
||
public static GitSCM getGitSCM(JobWrapper jobWrapper) { | ||
SCM scm = getSCM(jobWrapper); | ||
if (scm instanceof GitSCM) { | ||
return (GitSCM) scm; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static SCM getSCM(JobWrapper jobWrapper) { | ||
if (jobWrapper == null) { | ||
return EMPTY_SCM.getSCM(); | ||
} | ||
|
||
SCM projectSCM = jobWrapper.getScm(); | ||
|
||
if (projectSCM == null) { | ||
return EMPTY_SCM.getSCM(); | ||
} | ||
|
||
String projectSCMClassName = projectSCM.getClass().getName(); | ||
if (PROXY_SCM_CLASS_NAME.equals(projectSCMClassName)) { | ||
projectSCM = new ProxySCM(projectSCM).getSCM(); | ||
projectSCMClassName = projectSCM.getClass().getName(); | ||
} | ||
|
||
if (REPO_SCM_CLASS_NAME.equals(projectSCMClassName)) { | ||
projectSCM = new RepoSCM(projectSCM).getSCM(); | ||
} | ||
|
||
return projectSCM; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/scms/SCMWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.uaznia.lukanus.hudson.plugins.gitparameter.scms; | ||
|
||
import hudson.scm.SCM; | ||
|
||
public interface SCMWrapper { | ||
SCM getSCM(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/main/resources/net/uaznia/lukanus/hudson/plugins/gitparameter/scms/Messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ProxySCM.getSCMFromProxySCM=get scm from proxy scm failed | ||
RepoSCM.getRepoScmFailed=get repo scm failed |
2 changes: 2 additions & 0 deletions
2
...main/resources/net/uaznia/lukanus/hudson/plugins/gitparameter/scms/Messages_pl.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ProxySCM.getSCMFromProxySCM=B\u0142\u0105d przy obs\u0142udze proxy scm | ||
RepoSCM.getRepoScmFailed=B\u0142\u0105d przy obs\u0142udze repo scm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters