<commit_before>package de.unistuttgart.iste.rss.bugminer.testutils;

import java.io.IOException;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.junit.rules.ExternalResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import de.unistuttgart.iste.rss.bugminer.computing.SshConfig;
import de.unistuttgart.iste.rss.bugminer.computing.vagrant.VagrantStrategy;
import de.unistuttgart.iste.rss.bugminer.config.EntityFactory;
import de.unistuttgart.iste.rss.bugminer.model.Cluster;
import de.unistuttgart.iste.rss.bugminer.model.Node;
import de.unistuttgart.iste.rss.bugminer.model.SystemSpecification;

@Component
@Scope("prototype")
public class VagrantMachine extends ExternalResource {
	private SshConfig sshConfig;

	@Autowired
	private VagrantStrategy vagrant;

	@Autowired
	private EntityFactory entityFactory;

	private Node node;

	private static int nodeIndex;

	private final Logger logger = Logger.getLogger(VagrantMachine.class.getName());

	private Node createNode() {
		Node node = entityFactory.make(Node.class);
		node.setSystemSpecification(SystemSpecification.UBUNTU_1404);
		nodeIndex++;
		node.setId(nodeIndex);
		Cluster cluster = entityFactory.make(Cluster.class);
		node.setCluster(cluster);
		cluster.setName("unittest-" + UUID.randomUUID());
		cluster.setProvider("vagrant");
		node.setCluster(cluster);
		return node;
	}

	@Override
	protected void before() throws Throwable {
		try {
			node = createNode();
			vagrant.initializeNode(node);
			vagrant.startNode(node);
			sshConfig = vagrant.getSshConfig(node);
		} catch (Exception e) {
			throw new RuntimeException("Unable to prepare vagrant node for VagrantMachine rule", e);
		}
	}

	public SshConfig getSshConfig() {
		return sshConfig;
	}

	public Node getNode() {
		return node;
	}

	@Override
	protected void after() {
		try {
			vagrant.destroyNode(node);
		} catch (IOException e) {
			logger.log(Level.WARNING, "Unable to destroy vagrant node for Vagrantmachine rule", e);
		}
	}
}
<commit_msg>Skip tests if vagrant is required via VagrantMachine but not installed<commit_after>package de.unistuttgart.iste.rss.bugminer.testutils;

import java.io.IOException;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.ExternalResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import de.unistuttgart.iste.rss.bugminer.computing.SshConfig;
import de.unistuttgart.iste.rss.bugminer.computing.vagrant.VagrantStrategy;
import de.unistuttgart.iste.rss.bugminer.config.EntityFactory;
import de.unistuttgart.iste.rss.bugminer.model.Cluster;
import de.unistuttgart.iste.rss.bugminer.model.Node;
import de.unistuttgart.iste.rss.bugminer.model.SystemSpecification;

@Component
@Scope("prototype")
public class VagrantMachine extends ExternalResource {
	private SshConfig sshConfig;

	@Autowired
	private VagrantStrategy vagrant;

	@Autowired
	private EntityFactory entityFactory;

	private Node node;

	private static int nodeIndex;

	private final Logger logger = Logger.getLogger(VagrantMachine.class.getName());

	private Node createNode() {
		Node node = entityFactory.make(Node.class);
		node.setSystemSpecification(SystemSpecification.UBUNTU_1404);
		nodeIndex++;
		node.setId(nodeIndex);
		Cluster cluster = entityFactory.make(Cluster.class);
		node.setCluster(cluster);
		cluster.setName("unittest-" + UUID.randomUUID());
		cluster.setProvider("vagrant");
		node.setCluster(cluster);
		return node;
	}

	@Override
	protected void before() throws Throwable {
		if (!vagrant.isAvailable()) {
			throw new AssumptionViolatedException("Vagrant is required, but not installed");
		}

		try {
			node = createNode();
			vagrant.initializeNode(node);
			vagrant.startNode(node);
			sshConfig = vagrant.getSshConfig(node);
		} catch (Exception e) {
			throw new RuntimeException("Unable to prepare vagrant node for VagrantMachine rule", e);
		}
	}

	public SshConfig getSshConfig() {
		return sshConfig;
	}

	public Node getNode() {
		return node;
	}

	@Override
	protected void after() {
		try {
			vagrant.destroyNode(node);
		} catch (IOException e) {
			logger.log(Level.WARNING, "Unable to destroy vagrant node for Vagrantmachine rule", e);
		}
	}
}

{'fraction_non_alphanumeric': 0.10579678201454706, 'fraction_numerical': 0.001763279700242451, 'mean_word_length': 5.3115438108484, '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': '3143432', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1434, 'n_words': 292}