<commit_before>package com.joelj.jenkins.eztemplates.exclusion;

import com.google.common.base.Throwables;
import hudson.model.AbstractProject;
import hudson.model.JobProperty;
import jenkins.model.Jenkins;

import java.io.IOException;

/**
 * Generic {@link Exclusion} which retains a given {@link JobProperty} through cloning
 */
public class JobPropertyExclusion extends HardCodedExclusion {
    private final String id;
    private final String description;
    private final String className;
    private JobProperty cached;

    public JobPropertyExclusion(String id, String description, String className) {
        this.id = id;
        this.description = description;
        this.className = className;
    }

    @Override
    public void preClone(AbstractProject implementationProject) {
        cached = implementationProject.getProperty(className);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void postClone(AbstractProject implementationProject) {
        try {
            if (cached != null) {
                implementationProject.removeProperty(cached.getClass());
                implementationProject.addProperty(cached);
            }
        } catch (IOException e) {
            Throwables.propagate(e);
        }
    }

    @Override
    public String getId() {<commit_msg>Bugfix: Removing job property from template should remove from all implementations<commit_after>package com.joelj.jenkins.eztemplates.exclusion;

import com.google.common.base.Throwables;
import hudson.model.AbstractProject;
import hudson.model.JobProperty;

import java.io.IOException;

/**
 * Generic {@link Exclusion} which retains a given {@link JobProperty} through cloning
 */
public class JobPropertyExclusion extends HardCodedExclusion {
    private final String id;
    private final String description;
    private final String className;
    private JobProperty cached;

    public JobPropertyExclusion(String id, String description, String className) {
        this.id = id;
        this.description = description;
        this.className = className;
    }

    @Override
    public void preClone(AbstractProject implementationProject) {
        cached = implementationProject.getProperty(className);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void postClone(AbstractProject implementationProject) {
        try {
            if (cached != null) {
                // Removed from template = removed from all impls
                if (implementationProject.removeProperty(cached.getClass()) != null) {
                    implementationProject.addProperty(cached);
                }
            }
        } catch (IOException e) {
            Throwables.propagate(e);
        }
    }

    @Override
    public String getId() {
{'fraction_non_alphanumeric': 0.07982740021574973, 'fraction_numerical': 0.0, 'mean_word_length': 2.946099290780142, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4826882', 'n_tokens_mistral': 697, 'n_tokens_neox': 678, 'n_words': 183}