001package com.ganteater.ae.maven.plugin; 002 003import java.io.File; 004import java.io.FileReader; 005import java.io.IOException; 006import java.util.Enumeration; 007import java.util.List; 008import java.util.Map; 009import java.util.Properties; 010import java.util.Set; 011 012import org.apache.commons.lang.StringUtils; 013import org.apache.maven.plugin.AbstractMojo; 014import org.apache.maven.plugin.MojoExecutionException; 015import org.apache.maven.plugin.descriptor.PluginDescriptor; 016import org.apache.maven.plugins.annotations.Parameter; 017import org.apache.maven.project.MavenProject; 018 019import com.ganteater.ae.AEWorkspace; 020import com.ganteater.ae.RecipeRunner; 021 022public abstract class AEBase extends AbstractMojo { 023 024 @Parameter(readonly = true, defaultValue = "${project}") 025 protected MavenProject project; 026 027 @Parameter(defaultValue = "src/it/ae") 028 protected File basedir; 029 030 @Parameter(defaultValue = "${plugin}", readonly = true) 031 protected PluginDescriptor plugin; 032 033 @Parameter 034 protected Map<String, String> variables; 035 036 @Parameter 037 protected List<File> propertiesFiles; 038 039 @Parameter 040 protected String config; 041 042 @Parameter 043 protected List<String> operationsDependencies; 044 045 protected Set<Class> operations; 046 047 @Parameter 048 protected String[] recipes; 049 050 protected void importVariables(AEWorkspace workspace) { 051 Map<String, Object> systemVariables = workspace.getSystemVariables(); 052 if (variables != null) { 053 variables.entrySet().stream().forEach(e -> systemVariables.put(e.getKey().toUpperCase(), e.getValue())); 054 } 055 056 if (propertiesFiles != null) { 057 propertiesFiles.stream().forEach(file -> { 058 Properties props = new Properties(); 059 try { 060 props.load(new FileReader(file)); 061 } catch (IOException e) { 062 e.printStackTrace(); 063 } 064 Enumeration<Object> keys = props.keys(); 065 while (keys.hasMoreElements()) { 066 String key = (String) keys.nextElement(); 067 systemVariables.put(key.toUpperCase(), props.get(key)); 068 } 069 }); 070 } 071 } 072 073 protected void runRecipes(AEWorkspace workspace, boolean async) throws MojoExecutionException { 074 if (recipes == null) { 075 String sysRecipes = System.getProperty("recipes"); 076 if (sysRecipes != null) { 077 recipes = StringUtils.split(sysRecipes, ','); 078 } 079 } 080 081 if (recipes != null) { 082 for (String name : recipes) { 083 RecipeRunner runTask = workspace.runTask(name, async); 084 if (!async && runTask.getStatus() == RecipeRunner.STATUS_FAILED) { 085 throw new MojoExecutionException("Status: Failed. See logs for details Reason for failure."); 086 } 087 } 088 } 089 } 090 091}