<commit_before>package org.springframework.cloud.contract.stubrunner.provider.wiremock;

import com.github.jknack.handlebars.Helper;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.contract.stubrunner.HttpServerStub;
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsEscapeHelper;
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsJsonPathHelper;
import org.springframework.cloud.contract.wiremock.WireMockSpring;
import org.springframework.util.ClassUtils;
import org.springframework.util.SocketUtils;
import org.springframework.util.StreamUtils;

/**
 * Abstraction over WireMock as a HTTP Server Stub
 *
 * @author <NAME>
 * @since 1.1.0
 */
public class WireMockHttpServerStub implements HttpServerStub {

	private static final Logger log = LoggerFactory.getLogger(WireMockHttpServerStub.class);
	private static final int INVALID_PORT = -1;

	private WireMockServer wireMockServer;

	private WireMockConfiguration config() {
		if (ClassUtils.isPresent("org.springframework.cloud.contract.wiremock.WireMockSpring", null)) {
			return WireMockSpring.options()
					.extensions(responseTemplateTransformer());
		}
		return new WireMockConfiguration().extensions(responseTemplateTransformer());
	}

	private ResponseTemplateTransformer responseTemplateTransformer() {
		return new ResponseTemplateTransformer(false, helpers());
	}

	/**
	 * Override this if you want to register your own helpers
	 */
	protected Map<String, Helper> helpers() {
		Map<String, Helper> helpers = new HashMap<>();
		helpers.put(HandlebarsJsonPathHelper.NAME, new HandlebarsJsonPathHelper());
		helpers.put(HandlebarsEscapeHelper.NAME, new HandlebarsEscapeHelper());
		return helpers;
	}

	@Override
	public int port() {
		return isRunning() ? this.wireMockServer.port() : INVALID_PORT;
	}

	@Override
	public boolean isRunning() {
		return this.wireMockServer != null && this.wireMockServer.isRunning();
	}

	@Override
	public HttpServerStub start() {
		if (isRunning()) {
			if (log.isDebugEnabled()) {
				log.info("The server is already running at port [" + port() + "]");
			}
			return this;
		}
		return start(SocketUtils.findAvailableTcpPort());
	}

	@Override
	public HttpServerStub start(int port) {
		this.wireMockServer = new WireMockServer(config().port(port));
		this.wireMockServer.start();
		return this;
	}

	@Override
	public HttpServerStub stop() {
		if (!isRunning()) {
			if (log.isDebugEnabled()) {
				log.warn("Trying to stop a non started server!");
			}
			return this;
		}
		this.wireMockServer.stop();
		return this;
	}

	@Override
	public HttpServerStub registerMappings(Collection<File> stubFiles) {
		if (!isRunning()) {
			throw new IllegalStateException("Server not started!");
		}
		registerStubMappings(stubFiles);
		return this;
	}

	@Override
	public boolean isAccepted(File file) {
		return file.getName().endsWith(".json");<commit_msg>Fixed the logging level for #329<commit_after>package org.springframework.cloud.contract.stubrunner.provider.wiremock;

import com.github.jknack.handlebars.Helper;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.contract.stubrunner.HttpServerStub;
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsEscapeHelper;
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsJsonPathHelper;
import org.springframework.cloud.contract.wiremock.WireMockSpring;
import org.springframework.util.ClassUtils;
import org.springframework.util.SocketUtils;
import org.springframework.util.StreamUtils;

/**
 * Abstraction over WireMock as a HTTP Server Stub
 *
 * @author <NAME>
 * @since 1.1.0
 */
public class WireMockHttpServerStub implements HttpServerStub {

	private static final Logger log = LoggerFactory.getLogger(WireMockHttpServerStub.class);
	private static final int INVALID_PORT = -1;

	private WireMockServer wireMockServer;

	private WireMockConfiguration config() {
		if (ClassUtils.isPresent("org.springframework.cloud.contract.wiremock.WireMockSpring", null)) {
			return WireMockSpring.options()
					.extensions(responseTemplateTransformer());
		}
		return new WireMockConfiguration().extensions(responseTemplateTransformer());
	}

	private ResponseTemplateTransformer responseTemplateTransformer() {
		return new ResponseTemplateTransformer(false, helpers());
	}

	/**
	 * Override this if you want to register your own helpers
	 */
	protected Map<String, Helper> helpers() {
		Map<String, Helper> helpers = new HashMap<>();
		helpers.put(HandlebarsJsonPathHelper.NAME, new HandlebarsJsonPathHelper());
		helpers.put(HandlebarsEscapeHelper.NAME, new HandlebarsEscapeHelper());
		return helpers;
	}

	@Override
	public int port() {
		return isRunning() ? this.wireMockServer.port() : INVALID_PORT;
	}

	@Override
	public boolean isRunning() {
		return this.wireMockServer != null && this.wireMockServer.isRunning();
	}

	@Override
	public HttpServerStub start() {
		if (isRunning()) {
			if (log.isDebugEnabled()) {
				log.debug("The server is already running at port [" + port() + "]");
			}
			return this;
		}
		return start(SocketUtils.findAvailableTcpPort());
	}

	@Override
	public HttpServerStub start(int port) {
		this.wireMockServer = new WireMockServer(config().port(port));
		this.wireMockServer.start();
		return this;
	}

	@Override
	public HttpServerStub stop() {
		if (!isRunning()) {
			if (log.isDebugEnabled()) {
				log.debug("Trying to stop a non started server!");
			}
			return this;
		}
		this.wireMockServer.stop();
		return this;
	}

	@Override
	public HttpServerStub registerMappings(Collection<File> stubFiles) {
		if (!isRunning()) {
			throw new IllegalStateException("Server not started!");
		}
		registerStubMappings(stubFiles);
		return this;
	}

	@Override
	public boolean isAccepted(File file) {
		return file.getName().endsWith(".json");
{'fraction_non_alphanumeric': 0.11006154286532131, 'fraction_numerical': 0.0021468441391155, 'mean_word_length': 5.4944237918215615, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1800134', 'n_tokens_mistral': 2189, 'n_tokens_neox': 2064, 'n_words': 430}