Sha256: 54d96a24b84557ea2199ea139c66b39d00330c08c22f0fd0593c3bf8456e77fe

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

package org.embulk.tester;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.embulk.EmbulkEmbed;
import org.embulk.config.ConfigLoader;

public class EmbulkPluginTester {

	public EmbulkPluginTester(Class<?> iface, String name, Class<?> impl)
	{
		TestExtension.addPlugin(iface, name, impl);
	}

	public void run(String ymlPath) throws Exception
	{
		EmbulkEmbed.Bootstrap bootstrap = new EmbulkEmbed.Bootstrap();

		EmbulkEmbed embulk = bootstrap.initialize();

		ConfigLoader configLoader = new ConfigLoader(embulk.getModelManager());
		embulk.run(configLoader.fromYamlFile(new File(convert(ymlPath))));


	}

	private String convert(String yml) throws Exception
	{
		File rootPath = new File(EmbulkPluginTester.class.getResource("/resource.txt").toURI()).getParentFile();
		File ymlPath = new File(EmbulkPluginTester.class.getResource(yml).toURI());
		File tempYmlPath = new File(ymlPath.getParentFile(), "temp-" + ymlPath.getName());
		Pattern pathPrefixPattern = Pattern.compile("^ *path(_prefix)?: '(.*)'$");
		try (BufferedReader reader = new BufferedReader(new FileReader(ymlPath))) {
			try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempYmlPath))) {
				String line;
				while ((line = reader.readLine()) != null) {
					Matcher matcher = pathPrefixPattern.matcher(line);
					if (matcher.matches()) {
						int group = 2;
						writer.write(line.substring(0, matcher.start(group)));
						writer.write(new File(rootPath, matcher.group(group)).getAbsolutePath());
						writer.write(line.substring(matcher.end(group)));
					} else {
						writer.write(line);
					}
					writer.newLine();
				}
			}
		}
		return tempYmlPath.getAbsolutePath();
	}

}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
embulk-parser-apache-custom-log-0.4.1 src/test/java/org/embulk/tester/EmbulkPluginTester.java
embulk-parser-apache-custom-log-0.4.0 src/test/java/org/embulk/tester/EmbulkPluginTester.java