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

org.jlot.maven.plugin.AbstractJlotMojo Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package org.jlot.maven.plugin;

import java.util.Arrays;
import java.util.Properties;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.jlot.client.config.JlotClient;
import org.jlot.client.executor.spi.CommandExecutor;
import org.jlot.client.executor.support.StringListConverter;

abstract class AbstractJlotMojo extends AbstractMojo
{
	@Parameter(defaultValue = "https://www.jlot.org/")
	private String				server;

	@Parameter(defaultValue = "${project.artifactId}")
	private String				projectName;

	@Parameter
	private String[]			resources;

	@Parameter(defaultValue = "UTF-8")
	private String				encoding;

	@Parameter(defaultValue = "true")
	private String				messageFormat;

	@Parameter(defaultValue = "${project.version}")
	private String				version;

	@Parameter(defaultValue = "${project}", readonly = true)
	private MavenProject		mavenProject;

	private StringListConverter	stringListConverter	= new StringListConverter();
	private JlotClient			jlotClient			= new JlotClient();

	public AbstractJlotMojo ()
	{}

	protected String[] getResources ( )
	{
		return resources;
	}

	protected Properties getJlotProperties ( )
	{
		Properties properties = new Properties();
		properties.put("projectName", projectName);
		properties.put("baseDir", getMavenProject().getBasedir().getAbsolutePath());
		properties.put("serverUrl", server);
		properties.put("resources", stringListConverter.toString(Arrays.asList(resources)));
		properties.put("version", version);
		properties.put("encoding", encoding);
		properties.put("messageFormat", messageFormat);
		return properties;
	}

	private Properties getExecutionProperties ( )
	{
		return System.getProperties();
	}

	protected CommandExecutor getCommandExecuter ( Class commandExecutorClass )
	{
		if (!jlotClient.isStarted())
		{
			jlotClient.start(getJlotProperties());
		}
		return jlotClient.getCommandExecuter(commandExecutorClass);
	}

	public MavenProject getMavenProject ( )
	{
		return mavenProject;
	}

	@Override
	public void execute ( ) throws MojoExecutionException, MojoFailureException
	{
		try
		{
			CommandExecutor commandExecuter = getCommandExecuter(getCommandExecutorClass());
			boolean success = commandExecuter.execute(getExecutionProperties());
			if (!success)
			{
				throw new MojoFailureException("build failed");
			}
		}
		catch (Exception e)
		{
			throw new MojoExecutionException(e.getMessage(), e);
		}
	}

	protected abstract Class getCommandExecutorClass ( ) throws Exception;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy