Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-43507] Add a test for the GitSCMExtension equals, hashCode a…
…nd toString implementation requirements
  • Loading branch information
stephenc committed Jun 12, 2017
1 parent f09e7a2 commit f056b80
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 38 deletions.
Expand Up @@ -17,11 +17,17 @@ public class AuthorInChangelog extends FakeGitSCMExtension {
public AuthorInChangelog() {
}

/**
* {@inheritDoc}
*/
@Override
public boolean requiresWorkspaceForPolling() {
return true;
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -33,18 +39,27 @@ public boolean equals(Object o) {
return o instanceof AuthorInChangelog;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return AuthorInChangelog.class.hashCode();
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "AuthorInChangelog{}";
}

@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "Use commit author in changelog";
Expand Down
Expand Up @@ -32,22 +32,34 @@ public Integer getTimeout() {
return timeout;
}

/**
* {@inheritDoc}
*/
@Override
public boolean requiresWorkspaceForPolling() {
return false;
}

/**
* {@inheritDoc}
*/
@Override
public void decorateCheckoutCommand(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, CheckoutCommand cmd) throws IOException, InterruptedException, GitException {
cmd.timeout(timeout);
}

/**
* {@inheritDoc}
*/
@Override
@Deprecated
public void decorateCheckoutCommand(GitSCM scm, AbstractBuild<?, ?> build, GitClient git, BuildListener listener, CheckoutCommand cmd) throws IOException, InterruptedException, GitException {
cmd.timeout(timeout);
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -62,11 +74,17 @@ public boolean equals(Object o) {
return timeout != null ? timeout.equals(that.timeout) : that.timeout == null;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return 0;
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "CheckoutOption{" +
Expand All @@ -77,6 +95,9 @@ public String toString() {
@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {

/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "Advanced checkout behaviours";
Expand Down
@@ -1,21 +1,16 @@
package hudson.plugins.git.extensions.impl;

import hudson.Extension;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.TaskListener;
import hudson.plugins.git.GitException;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;

import org.jenkinsci.plugins.gitclient.CloneCommand;
import java.io.IOException;
import org.jenkinsci.plugins.gitclient.FetchCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;

/**
* git-clean before the checkout.
*
Expand All @@ -26,6 +21,9 @@ public class CleanBeforeCheckout extends GitSCMExtension {
public CleanBeforeCheckout() {
}

/**
* {@inheritDoc}
*/
@Override
public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listener, FetchCommand cmd) throws IOException, InterruptedException, GitException {
listener.getLogger().println("Cleaning workspace");
Expand All @@ -36,6 +34,9 @@ public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listene
}
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -47,11 +48,17 @@ public boolean equals(Object o) {
return o instanceof CleanBeforeCheckout;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return CleanBeforeCheckout.class.hashCode();
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "CleanBeforeCheckout{}";
Expand All @@ -60,6 +67,9 @@ public String toString() {
@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
@Override
/**
* {@inheritDoc}
*/
public String getDisplayName() {
return "Clean before checkout";
}
Expand Down
Expand Up @@ -7,11 +7,10 @@
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
import java.io.IOException;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;

/**
* git-clean after the checkout.
*
Expand All @@ -22,6 +21,9 @@ public class CleanCheckout extends GitSCMExtension {
public CleanCheckout() {
}

/**
* {@inheritDoc}
*/
@Override
public void onCheckoutCompleted(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener) throws IOException, InterruptedException, GitException {
listener.getLogger().println("Cleaning workspace");
Expand All @@ -32,6 +34,9 @@ public void onCheckoutCompleted(GitSCM scm, Run<?, ?> build, GitClient git, Task
}
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -43,18 +48,27 @@ public boolean equals(Object o) {
return o instanceof CleanCheckout;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return CleanCheckout.class.hashCode();
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "CleanCheckout{}";
}

@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "Clean after checkout";
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/hudson/plugins/git/extensions/impl/CloneOption.java
Expand Up @@ -8,18 +8,16 @@
import hudson.plugins.git.extensions.GitClientType;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;

import java.io.IOException;
import java.util.List;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.jenkinsci.plugins.gitclient.CloneCommand;
import org.jenkinsci.plugins.gitclient.FetchCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import java.io.IOException;
import java.util.List;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;

/**
* @author Kohsuke Kawaguchi
*/
Expand Down Expand Up @@ -111,6 +109,9 @@ public int getDepth() {
return depth;
}

/**
* {@inheritDoc}
*/
@Override
public void decorateCloneCommand(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, CloneCommand cmd) throws IOException, InterruptedException, GitException {
if (shallow) {
Expand Down Expand Up @@ -142,11 +143,14 @@ public void decorateCloneCommand(GitSCM scm, Run<?, ?> build, GitClient git, Tas
cmd.reference(build.getEnvironment(listener).expand(reference));
}

/**
* {@inheritDoc}
*/
@Override
public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listener, FetchCommand cmd) throws IOException, InterruptedException, GitException {
cmd.shallow(shallow);
if (shallow && depth > 1) {
cmd.depth(depth);
cmd.depth(depth);
}
cmd.tags(!noTags);
/* cmd.refspecs() not required.
Expand All @@ -157,12 +161,18 @@ public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listene
cmd.timeout(timeout);
}

/**
* {@inheritDoc}
*/
@Override
public GitClientType getRequiredClient() {
return GitClientType.GITCLI;
}


/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -192,11 +202,17 @@ public boolean equals(Object o) {
return timeout != null ? timeout.equals(that.timeout) : that.timeout == null;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return CloneOption.class.hashCode();
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "CloneOption{" +
Expand All @@ -211,6 +227,9 @@ public String toString() {

@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "Advanced clone behaviours";
Expand Down

0 comments on commit f056b80

Please sign in to comment.