Skip to content
Permalink
Browse files

[JENKINS-43507] Check-pointing work in progress

  • Loading branch information...
stephenc committed Apr 28, 2017
1 parent 79c66eb commit 84913c76fdf2898eb51d15abaa9b3ddd445c69a6
Showing with 2,020 additions and 272 deletions.
  1. +6 −1 pom.xml
  2. +248 −132 src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java
  3. +211 −0 src/main/java/jenkins/plugins/git/GitSCMBuilder.java
  4. +4 −3 src/main/java/jenkins/plugins/git/GitSCMFileSystem.java
  5. +299 −97 src/main/java/jenkins/plugins/git/GitSCMSource.java
  6. +90 −0 src/main/java/jenkins/plugins/git/GitSCMSourceContext.java
  7. +47 −0 src/main/java/jenkins/plugins/git/GitSCMSourceRequest.java
  8. +20 −0 src/main/java/jenkins/plugins/git/traits/AuthorInChangelogTrait.java
  9. +20 −0 src/main/java/jenkins/plugins/git/traits/CheckoutOptionTrait.java
  10. +20 −0 src/main/java/jenkins/plugins/git/traits/CleanAfterCheckoutTrait.java
  11. +20 −0 src/main/java/jenkins/plugins/git/traits/CleanBeforeCheckoutTrait.java
  12. +20 −0 src/main/java/jenkins/plugins/git/traits/CloneOptionTrait.java
  13. +81 −0 src/main/java/jenkins/plugins/git/traits/GitBrowserSCMSourceTrait.java
  14. +20 −0 src/main/java/jenkins/plugins/git/traits/GitLFSPullTrait.java
  15. +27 −0 src/main/java/jenkins/plugins/git/traits/GitSCMExtensionTrait.java
  16. +138 −0 src/main/java/jenkins/plugins/git/traits/GitSCMExtensionTraitDescriptor.java
  17. +78 −0 src/main/java/jenkins/plugins/git/traits/GitToolSCMSourceTrait.java
  18. +65 −0 src/main/java/jenkins/plugins/git/traits/IgnoreOnPushNotificationTrait.java
  19. +34 −0 src/main/java/jenkins/plugins/git/traits/LocalBranchTrait.java
  20. +20 −0 src/main/java/jenkins/plugins/git/traits/PruneStaleBranchTrait.java
  21. +109 −0 src/main/java/jenkins/plugins/git/traits/RefSpecsSCMSourceTrait.java
  22. +142 −0 src/main/java/jenkins/plugins/git/traits/RemoteNameSCMSourceTrait.java
  23. +20 −0 src/main/java/jenkins/plugins/git/traits/SubmoduleOptionTrait.java
  24. +20 −0 src/main/java/jenkins/plugins/git/traits/UserIdentityTrait.java
  25. +20 −0 src/main/java/jenkins/plugins/git/traits/WipeWorkspaceTrait.java
  26. +4 −30 src/main/resources/jenkins/plugins/git/GitSCMSource/config-detail.jelly
  27. +30 −0 src/main/resources/jenkins/plugins/git/traits/GitBrowserSCMSourceTrait/config.jelly
  28. +29 −0 src/main/resources/jenkins/plugins/git/traits/GitSCMExtensionTrait/config.jelly
  29. +31 −0 src/main/resources/jenkins/plugins/git/traits/GitToolSCMSourceTrait/config.jelly
  30. +27 −0 src/main/resources/jenkins/plugins/git/traits/LocalBranchTrait/config.jelly
  31. 0 src/main/resources/jenkins/plugins/git/traits/Messages.properties
  32. +31 −0 src/main/resources/jenkins/plugins/git/traits/RefSpecsSCMSourceTrait/RefSpecTemplate/config.jelly
  33. +4 −0 src/main/resources/jenkins/plugins/git/traits/RefSpecsSCMSourceTrait/RefSpecTemplate/help-value.html
  34. +37 −0 src/main/resources/jenkins/plugins/git/traits/RefSpecsSCMSourceTrait/config.jelly
  35. +31 −0 src/main/resources/jenkins/plugins/git/traits/RemoteNameSCMSourceTrait/config.jelly
  36. +17 −9 src/test/java/jenkins/plugins/git/AbstractGitSCMSourceRetrieveHeadsTest.java
@@ -30,7 +30,7 @@
<concurrency>1C</concurrency>
<findbugs.failOnError>false</findbugs.failOnError>
<workflow.version>1.14.2</workflow.version>
<scm-api-plugin.version>2.1.0</scm-api-plugin.version>
<scm-api-plugin.version>2.2.0-SNAPSHOT</scm-api-plugin.version>
</properties>

<build>
@@ -132,6 +132,11 @@
<artifactId>joda-time</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-annotation</artifactId>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,211 @@
package jenkins.plugins.git;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.plugins.git.BranchSpec;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.SubmoduleConfig;
import hudson.plugins.git.UserRemoteConfig;
import hudson.plugins.git.browser.GitRepositoryBrowser;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.impl.BuildChooserSetting;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import jenkins.scm.api.trait.SCMBuilder;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jgit.transport.RefSpec;

/**
* @author Stephen Connolly
*/
public class GitSCMBuilder<B extends GitSCMBuilder<B>> extends SCMBuilder<B, GitSCM> {

private final List<GitSCMExtension> extensions = new ArrayList<>();
private List<String> refSpecs = new ArrayList<>();
private final List<UserRemoteConfig> remoteConfigs = new ArrayList<>();
private GitRepositoryBrowser browser;
private String gitTool;
private String remoteName = AbstractGitSCMSource.DEFAULT_REMOTE_NAME;
private String remote;
private String credentialsId;

public GitSCMBuilder(@NonNull SCMHead head, SCMRevision revision) {
super(GitSCM.class, head, revision);
}

public final B withExtension(@CheckForNull GitSCMExtension extension) {
if (extension != null) {
// the extensions only allow one of each type.
for (Iterator<GitSCMExtension> iterator = extensions.iterator(); iterator.hasNext(); ) {
if (extension.getClass().equals(iterator.next().getClass())) {
iterator.remove();
}
}
extensions.add(extension);
}
return (B) this;
}

public final B withExtensions(GitSCMExtension... extensions) {
for (GitSCMExtension extension : extensions) {
withExtension(extension);
}
return (B) this;
}

public final B withExtensions(List<GitSCMExtension> extensions) {
for (GitSCMExtension extension : extensions) {
withExtension(extension);
}
return (B) this;
}

public final List<GitSCMExtension> extensions() {
return new ArrayList<>(extensions);
}

public final B withRemoteConfig(@CheckForNull UserRemoteConfig remoteConfig) {
if (remoteConfig != null) {
// the remoteConfigs only allow one of each type.
for (Iterator<UserRemoteConfig> iterator = remoteConfigs.iterator(); iterator.hasNext(); ) {
if (remoteConfig.getClass().equals(iterator.next().getClass())) {
iterator.remove();
}
}
remoteConfigs.add(remoteConfig);
}
return (B) this;
}

public final B withRemoteConfigs(UserRemoteConfig... remoteConfigs) {
for (UserRemoteConfig remoteConfig : remoteConfigs) {
withRemoteConfig(remoteConfig);
}
return (B) this;
}

public final B withRemoteConfigs(List<UserRemoteConfig> remoteConfigs) {
for (UserRemoteConfig remoteConfig : remoteConfigs) {
withRemoteConfig(remoteConfig);
}
return (B) this;
}

public final List<UserRemoteConfig> remoteConfigs() {
return new ArrayList<>(remoteConfigs);
}

public final B withRemoteName(String remoteName) {
this.remoteName = StringUtils.defaultIfBlank(remoteName, AbstractGitSCMSource.DEFAULT_REMOTE_NAME);
return (B) this;
}

public final String remoteName() {
return remoteName;
}

public final B withBrowser(GitRepositoryBrowser browser) {
this.browser = browser;
return (B) this;
}

public final GitRepositoryBrowser browser() {
return browser;
}

public final B withGitTool(String gitTool) {
this.gitTool = gitTool;
return (B) this;
}

public final String gitTool() {
return gitTool;
}

public B withRefSpecs(List<String> refSpecs) {
this.refSpecs.clear();
this.refSpecs.addAll(refSpecs);
return (B) this;
}

public B withAdditionalRefSpecs(List<String> refSpecs) {
this.refSpecs.addAll(refSpecs);
return (B) this;
}

public B withRefSpec(String refSpec) {
this.refSpecs.add(refSpec);
return (B) this;
}

public List<String> refSpecs() {
if (refSpecs.isEmpty()) {
return Collections.singletonList(AbstractGitSCMSource.REF_SPEC_DEFAULT);
}
return new ArrayList<>(refSpecs);
}

public List<RefSpec> asRefSpecs() {
List<RefSpec> result = new ArrayList<>(Math.max(refSpecs.size(), 1));
for (String template: refSpecs()){
result.add(new RefSpec(
template.replaceAll(AbstractGitSCMSource.REF_SPEC_REMOTE_NAME_PLACEHOLDER, remoteName())
));
}
return result;
}

public List<UserRemoteConfig> asRemoteConfigs() {
List<RefSpec> refSpecs = asRefSpecs();
List<UserRemoteConfig> result = new ArrayList<>(refSpecs.size());
String remote = remote();
for (RefSpec refSpec : refSpecs) {
result.add(new UserRemoteConfig(remote, remoteName(), refSpec.toString(), credentialsId()));
}
return result;

}

public B withRemote(String remote) {
this.remote = remote;
return (B)this;
}

public String remote() {
return remote;
}

public B withCredentials(String credentialsId) {
this.credentialsId = credentialsId;
return (B)this;
}

public String credentialsId() {
return credentialsId;
}

@Override
public GitSCM build() {
List<GitSCMExtension> extensions = extensions();
if (revision() instanceof AbstractGitSCMSource.SCMRevisionImpl) {
// remove any conflicting BuildChooserSetting if present
for (Iterator<GitSCMExtension> iterator = extensions.iterator(); iterator.hasNext(); ) {
if (iterator.next() instanceof BuildChooserSetting) {
iterator.remove();
}
}
extensions.add(new BuildChooserSetting(new AbstractGitSCMSource.SpecificRevisionBuildChooser(
(AbstractGitSCMSource.SCMRevisionImpl) revision())));
}
return new GitSCM(
asRemoteConfigs(),
Collections.singletonList(new BranchSpec(head().getName())),
false, Collections.<SubmoduleConfig>emptyList(),
browser(), gitTool(),
extensions);
}
}
@@ -319,13 +319,14 @@ public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @Ch
}
TaskListener listener = new LogTaskListener(LOGGER, Level.FINE);
AbstractGitSCMSource gitSCMSource = (AbstractGitSCMSource) source;
GitSCMBuilder<?> builder = gitSCMSource.newBuilder(head, rev);
String cacheEntry = gitSCMSource.getCacheEntry();
Lock cacheLock = AbstractGitSCMSource.getCacheLock(cacheEntry);
cacheLock.lock();
try {
File cacheDir = AbstractGitSCMSource.getCacheDir(cacheEntry);
Git git = Git.with(listener, new EnvVars(EnvVars.masterEnvVars)).in(cacheDir);
GitTool tool = gitSCMSource.resolveGitTool();
GitTool tool = gitSCMSource.resolveGitTool(builder.gitTool());
if (tool != null) {
git.using(tool.getGitExe());
}
@@ -335,7 +336,7 @@ public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @Ch
listener.getLogger().println("Creating git repository in " + cacheDir);
client.init();
}
String remoteName = gitSCMSource.getRemoteName();
String remoteName = builder.remoteName();
listener.getLogger().println("Setting " + remoteName + " to " + gitSCMSource.getRemote());
client.setRemoteUrl(remoteName, gitSCMSource.getRemote());
listener.getLogger().println("Fetching & pruning " + remoteName + "...");
@@ -345,7 +346,7 @@ public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @Ch
} catch (URISyntaxException ex) {
listener.getLogger().println("URI syntax exception for '" + remoteName + "' " + ex);
}
client.fetch_().prune().from(remoteURI, gitSCMSource.getRefSpecs()).execute();
client.fetch_().prune().from(remoteURI, builder.asRefSpecs()).execute();
listener.getLogger().println("Done.");
return new GitSCMFileSystem(client, gitSCMSource.getRemote(), Constants.R_REMOTES+remoteName+"/"+head.getName(),
(AbstractGitSCMSource.SCMRevisionImpl) rev);
Oops, something went wrong.

0 comments on commit 84913c7

Please sign in to comment.
You can’t perform that action at this time.