All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xlrit.gears.runner.RunnerMojo Maven / Gradle / Ivy

There is a newer version: 1.17.5
Show newest version
package com.xlrit.gears.runner;

import java.io.File;

import com.xlrit.gears.runner.driver.Config;
import com.xlrit.gears.runner.driver.Driver;
import com.xlrit.gears.runner.utils.MiscUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;

@SuppressWarnings({"rawtypes", "unchecked"})
public abstract class RunnerMojo extends AbstractMojo {

	@Parameter(property = "gears.runner.baseUrl")
	private String baseUrl;

	@Parameter(property = "gears.runner.pattern", defaultValue = "**")
	private String pattern;

	@Parameter(property = "gears.runner.dryRun")
	private Boolean dryRun;

	@Override
	public final void execute() throws MojoExecutionException {
		File currentDir = new File(".");

		Config config = getConfig();
		File configFile = new File("gears.json");
		if (configFile.exists()) {
			getLog().info("Loading configuration from " + configFile);
			config.readJsonFromFile(configFile);
		}

		config.projectDir = currentDir;
		if (baseUrl != null) config.baseUrl = baseUrl;
		if (pattern != null) config.filePattern = MiscUtils.unquoteIfQuoted(pattern);
		if (dryRun != null) config.dryRun = dryRun;

		Driver driver = getDriver();
		getLog().info("Configured with %s".formatted(config));
		int failCount = driver.run(config);
		if (failCount != 0) {
			throw new MojoExecutionException(failCount + " load failures occurred");
		}
	}

	protected abstract Config getConfig();
	protected abstract Driver getDriver();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy