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

org.etlunit.cli.ListInstalledFeaturesCmd Maven / Gradle / Ivy

There is a newer version: 1.6.9
Show newest version
package org.etlunit.cli;

import org.clamshellcli.api.Command;
import org.clamshellcli.api.Configurator;
import org.clamshellcli.api.Context;
import org.clamshellcli.api.IOConsole;
import org.etlunit.maven.ETLUnitMojo;
import org.etlunit.parser.ETLTestParser;
import org.etlunit.parser.ETLTestValueObject;
import org.etlunit.util.IOUtils;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListInstalledFeaturesCmd implements Command {
	private static final String NAMESPACE = "syscmd";
	public static final String ACTION_NAME = "list-installed-features";

	public Object execute(Context ctx) {
		IOConsole console = ctx.getIoConsole();

		File root = new File(".");

		try {
				List list = getInstalledFeatures(root);

			if (list != null && list.size() != 0)
			{
				console.writeOutput("Installed features:" + Configurator.VALUE_LINE_SEP);

				for (String feature : list)
				{
					console.writeOutput("\t" + feature + Configurator.VALUE_LINE_SEP);
				}
			}
			else
			{
				console.writeOutput("No features installed" + Configurator.VALUE_LINE_SEP);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}

	public static List getInstalledFeatures(File root) throws Exception {
		File cfg = ETLUnitMojo.getEtlunitConfiguration(root);

		// read the contents, and parse into an object
		String text = IOUtils.readFileToString(cfg);

		ETLTestValueObject obj = ETLTestParser.loadObject(text);

		ETLTestValueObject feat = obj.query("install-features");

		if (feat != null)
		{
			return feat.getValueAsListOfStrings();
		}
		else
		{
			return null;
		}
	}

	public void plug(Context plug) {
		// no load-time setup needed
	}

	public Descriptor getDescriptor() {
		return new Descriptor() {
			public String getNamespace() {
				return NAMESPACE;
			}

			public String getName() {
				return ACTION_NAME;
			}

			public String getDescription() {
				return "Lists all installed features";
			}

			public String getUsage() {
				return "";
			}

			public Map getArguments() {
				Map map = new HashMap();
				
				return map;
			}
		};
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy