Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<hpi.strictBundledArtifacts>true</hpi.strictBundledArtifacts>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.504</jenkins.baseline>
<jenkins.baseline>2.516</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<no-test-jar>false</no-test-jar>
<!-- Do not run extra reporting for pmd -->
Expand All @@ -55,7 +55,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>5983.v443959746f1f</version>
<version>6210.v69ea_fd8a_f010</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -69,6 +69,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git-client</artifactId>
<version>6.6.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package hudson.plugins.git.extensions.impl;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.Extension;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.git.GitException;
import hudson.plugins.git.GitSCM;
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.Objects;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.gitclient.CloneCommand;
import org.jenkinsci.plugins.gitclient.FetchCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.DataBoundConstructor;

public class PartialCloneFilter extends GitSCMExtension {

private final String filterSpec;

@DataBoundConstructor
public PartialCloneFilter(String filterSpec) {
this.filterSpec = filterSpec;
}

@Whitelisted
public String getFilterSpec() {
return filterSpec;
}

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

cmd.filter(filterSpec);
}

/**
* {@inheritDoc}
*/
@Override
public void decorateFetchCommand(
GitSCM scm, @CheckForNull Run<?, ?> run, GitClient git, TaskListener listener, FetchCommand cmd)
throws IOException, InterruptedException, GitException {

cmd.filter(filterSpec);
}

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

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

PartialCloneFilter that = (PartialCloneFilter) o;

return Objects.equals(filterSpec, that.filterSpec);
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(filterSpec);
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "PartialCloneFilter{" + "filterSpec=" + filterSpec + '}';
}

@Extension
@Symbol("partialCloneFilter")
public static class DescriptorImpl extends GitSCMExtensionDescriptor {

/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "Partial clone";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package jenkins.plugins.git.traits;

import hudson.Extension;
import hudson.plugins.git.extensions.impl.PartialCloneFilter;
import jenkins.scm.api.trait.SCMSourceTrait;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Exposes {@link PartialCloneFilter} as a {@link SCMSourceTrait}.
*
* @since 6.3.0
*/
public class PartialCloneFilterTrait extends GitSCMExtensionTrait<PartialCloneFilter> {

/**
* Stapler constructor.
*
* @param extension the {@link PartialCloneFilter}
*/
@DataBoundConstructor
public PartialCloneFilterTrait(PartialCloneFilter extension) {
super(extension);
}

/**
* Our {@link hudson.model.Descriptor}
*/
@Extension
@Symbol("partialCloneFilter")
public static class DescriptorImpl extends GitSCMExtensionTraitDescriptor {

/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "Partial clone";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hudson.plugins.git.extensions.impl.PartialCloneFilter

def f = namespace(lib.FormTagLib)

f.entry(title:_("Filter specification"), field:"filterSpec") {
f.textbox()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
Specify an object filter for clone and fetch.<br/>
If set, the repository is converted to a partial clone.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ private String randomPipelineExtensions() {
// Inverse build chooser will find nothing to build and fails the test
// "[$class: 'BuildChooserSetting', buildChooser: [$class: 'InverseBuildChooser']]",
"[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'src'], [path: 'Makefile']]]",
"[$class: 'PartialCloneFilter', filterSpec: 'blob:none'",
"[$class: 'AuthorInChangelog']",
"[$class: 'BuildChooserSetting', buildChooser: [$class: 'DefaultBuildChooser']]",
"[$class: 'BuildSingleRevisionOnly']",
Expand Down Expand Up @@ -160,6 +161,7 @@ private String randomPipelineExtensions() {
"pruneTags(false)",
"pruneTags(true)",
"sparseCheckout(sparseCheckoutPaths: [[path: 'src'], [path: 'Makefile']])",
"partialCloneFilter('blob:none')",
"submodule(disableSubmodules: true)",
"submodule(depth: 1, shallow: true)",
"submodule(parentCredentials: true, recursiveSubmodules: true, threads: 13)",
Expand Down
Loading