<commit_before>package javaposse.jobdsl.dsl.helpers.common

import javaposse.jobdsl.dsl.helpers.Context

/**
 * Common DSL for the workspace cleanup plugin.
 *
 * See https://wiki.jenkins-ci.org/display/JENKINS/Workspace+Cleanup+Plugin
 */
class WorkspaceCleanupContext implements Context {

    private enum PatternType {
        INCLUDE ("INCLUDE"),
        EXCLUDE ("EXCLUDE")

        private PatternType(String type) {
            this.type = type
        }
        private String type

        private String value() {
            return type;
        }
    }

    List<Node> patternNodes = []
    boolean deleteDirectories = false
    boolean cleanWhenSuccess = true
    boolean cleanWhenUnstable = true
    boolean cleanWhenFailure = true
    boolean cleanWhenNotBuilt = true
    boolean cleanWhenAborted = true
    boolean failBuild = true
    String deleteCommand

    void includePattern(String pattern) {
        addPattern(PatternType.INCLUDE, pattern)
    }

    void excludePattern(String pattern) {
        addPattern(PatternType.EXCLUDE, pattern)
    }

    void deleteDirectories(boolean deleteDirectories = true) {
        this.deleteDirectories = deleteDirectories
    }

    void cleanWhenSuccess(boolean cleanWhenSuccess = true) {
        this.cleanWhenSuccess = cleanWhenSuccess
    }

    void cleanWhenUnstable(boolean cleanWhenUnstable = true) {
        this.cleanWhenUnstable = cleanWhenUnstable
    }

    void cleanWhenFailure(boolean cleanWhenFailure = true) {
        this.cleanWhenFailure = cleanWhenFailure
    }

    void cleanWhenNotBuilt(boolean cleanWhenNotBuilt = true) {
        this.cleanWhenNotBuilt = cleanWhenNotBuilt
    }

    void cleanWhenAborted(boolean cleanWhenAborted = true) {
        this.cleanWhenAborted = cleanWhenAborted
    }

    void failBuildWhenCleanupFails(boolean failBuild = true) {
        this.failBuild = failBuild
    }

    void deleteCommand(String deleteCommand) {
        this.deleteCommand = deleteCommand
    }

    /**
     * <hudson.plugins.ws__cleanup.Pattern>
     *     <pattern>*.class</pattern>
     *     <type>INCLUDE</type>
     * </hudson.plugins.ws__cleanup.Pattern>
     */
    private void addPattern(PatternType type, String pattern) {
        patternNodes << new NodeBuilder().'hudson.plugins.ws__cleanup.Pattern' {
            delegate.pattern(pattern)
            delegate.type(type.value())
        }
    }
}
<commit_msg>[JENKINS-22857] DSL support for post build cleanup the workspace using the Workspace Cleanup Plugin<commit_after>package javaposse.jobdsl.dsl.helpers.common

import javaposse.jobdsl.dsl.helpers.Context

/**
 * Common DSL for the workspace cleanup plugin.
 *
 * See https://wiki.jenkins-ci.org/display/JENKINS/Workspace+Cleanup+Plugin
 */
class WorkspaceCleanupContext implements Context {

    List<Node> patternNodes = []
    boolean deleteDirectories = false
    String deleteCommand

    void includePattern(String pattern) {
        addPattern('INCLUDE', pattern)
    }

    void excludePattern(String pattern) {
        addPattern('EXCLUDE', pattern)
    }

    void deleteDirectories(boolean deleteDirectories = true) {
        this.deleteDirectories = deleteDirectories
    }

    void deleteCommand(String deleteCommand) {
        this.deleteCommand = deleteCommand
    }

    /**
     * <hudson.plugins.ws__cleanup.Pattern>
     *     <pattern>*.class</pattern>
     *     <type>INCLUDE</type>
     * </hudson.plugins.ws__cleanup.Pattern>
     */
    private void addPattern(String type, String pattern) {
        patternNodes << new NodeBuilder().'hudson.plugins.ws__cleanup.Pattern' {
            delegate.pattern(pattern)
            delegate.type(type)
        }
    }
}

{'fraction_non_alphanumeric': 0.08759124087591241, 'fraction_numerical': 0.0013517166801838335, 'mean_word_length': 2.850156087408949, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6004823', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1006, 'n_words': 207}