<commit_before>package org.jenkinsci.plugins.p4.asset;

import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.security.ACL;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Notifier;
import hudson.tasks.Publisher;
import hudson.util.ListBoxModel;

import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;

import jenkins.model.Jenkins;

import org.acegisecurity.Authentication;
import org.jenkinsci.plugins.p4.client.ClientHelper;
import org.jenkinsci.plugins.p4.client.ConnectionHelper;
import org.jenkinsci.plugins.p4.credentials.P4StandardCredentials;
import org.jenkinsci.plugins.p4.publish.Publish;
import org.jenkinsci.plugins.p4.workspace.Workspace;
import org.kohsuke.stapler.DataBoundConstructor;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;

public class AssetNotifier extends Notifier {

	private static Logger logger = Logger.getLogger(AssetNotifier.class
			.getName());

	private final String credential;
	private final Workspace workspace;
	private final Publish publish;

	public String getCredential() {
		return credential;
	}

	public Workspace getWorkspace() {
		return workspace;
	}

	public Publish getPublish() {
		return publish;
	}

	@DataBoundConstructor
	public AssetNotifier(String credential, Workspace workspace, Publish publish) {
		this.credential = credential;
		this.workspace = workspace;
		this.publish = publish;
	}

	public BuildStepMonitor getRequiredMonitorService() {
		return BuildStepMonitor.NONE;
	}

	@Override
	public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
			BuildListener listener) throws InterruptedException {

		// open connection to Perforce
		P4StandardCredentials cdt;
		cdt = ConnectionHelper.findCredential(credential);

		Workspace ws = (Workspace) workspace.clone();
		try {
			EnvVars envVars = build.getEnvironment(listener);
			ws.clear();
			ws.load(envVars);
			String desc = publish.getDescription();
			desc = ws.expand(desc, false);
			publish.setExpandedDesc(desc);
		} catch (IOException e) {
			e.printStackTrace();
		}

		String client = ws.getFullName();
		ClientHelper p4 = new ClientHelper(cdt, listener, client);

		// test server connection
		try {
			if (!p4.isConnected()) {
				p4.log("P4: Server connection error:" + cdt.getP4port());
				return false;
			}
			p4.log("Connected to server: " + cdt.getP4port());

			// setup the client workspace to publish asset.
			if (!p4.setClient(workspace)) {
				p4.log("P4: Undefined workspace: " + workspace.getFullName());
				return false;
			}

			// test client connection
			if (p4.getClient() == null) {
				p4.log("P4: Client unknown: " + client);
				return false;
			}
			p4.log("Connected to client: " + client);

			boolean open = p4.buildChange();
			if (open) {
				p4.publishChange(publish);
			}

		} catch (Exception e) {
			String msg = "Unable to update workspace: " + e;
			logger.warning(msg);
			throw new InterruptedException(msg);
		} finally {<commit_msg>Fix: Use cloned workspace not config<commit_after>package org.jenkinsci.plugins.p4.asset;

import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.security.ACL;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Notifier;
import hudson.tasks.Publisher;
import hudson.util.ListBoxModel;

import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;

import jenkins.model.Jenkins;

import org.acegisecurity.Authentication;
import org.jenkinsci.plugins.p4.client.ClientHelper;
import org.jenkinsci.plugins.p4.client.ConnectionHelper;
import org.jenkinsci.plugins.p4.credentials.P4StandardCredentials;
import org.jenkinsci.plugins.p4.publish.Publish;
import org.jenkinsci.plugins.p4.workspace.Workspace;
import org.kohsuke.stapler.DataBoundConstructor;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;

public class AssetNotifier extends Notifier {

	private static Logger logger = Logger.getLogger(AssetNotifier.class
			.getName());

	private final String credential;
	private final Workspace workspace;
	private final Publish publish;

	public String getCredential() {
		return credential;
	}

	public Workspace getWorkspace() {
		return workspace;
	}

	public Publish getPublish() {
		return publish;
	}

	@DataBoundConstructor
	public AssetNotifier(String credential, Workspace workspace, Publish publish) {
		this.credential = credential;
		this.workspace = workspace;
		this.publish = publish;
	}

	public BuildStepMonitor getRequiredMonitorService() {
		return BuildStepMonitor.NONE;
	}

	@Override
	public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
			BuildListener listener) throws InterruptedException {

		// open connection to Perforce
		P4StandardCredentials cdt;
		cdt = ConnectionHelper.findCredential(credential);

		Workspace ws = (Workspace) workspace.clone();
		try {
			EnvVars envVars = build.getEnvironment(listener);
			ws.clear();
			ws.load(envVars);
			String desc = publish.getDescription();
			desc = ws.expand(desc, false);
			publish.setExpandedDesc(desc);
		} catch (IOException e) {
			e.printStackTrace();
		}

		String client = ws.getFullName();
		ClientHelper p4 = new ClientHelper(cdt, listener, client);

		// test server connection
		try {
			if (!p4.isConnected()) {
				p4.log("P4: Server connection error:" + cdt.getP4port());
				return false;
			}
			p4.log("Connected to server: " + cdt.getP4port());

			// setup the client workspace to publish asset.
			if (!p4.setClient(ws)) {
				p4.log("P4: Undefined workspace: " + ws.getFullName());
				return false;
			}

			// test client connection
			if (p4.getClient() == null) {
				p4.log("P4: Client unknown: " + client);
				return false;
			}
			p4.log("Connected to client: " + client);

			boolean open = p4.buildChange();
			if (open) {
				p4.publishChange(publish);
			}

		} catch (Exception e) {
			String msg = "Unable to update workspace: " + e;
			logger.warning(msg);
			throw new InterruptedException(msg);
		} finally {
{'fraction_non_alphanumeric': 0.10760179594364452, 'fraction_numerical': 0.0074314909428704135, 'mean_word_length': 4.540308747855918, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2560300', 'n_tokens_mistral': 2242, 'n_tokens_neox': 1995, 'n_words': 459}