001package com.ganteater.ae.maven.plugin; 002 003import java.io.File; 004import java.io.IOException; 005import java.util.List; 006 007import javax.swing.WindowConstants; 008 009import org.apache.commons.lang.StringUtils; 010import org.apache.maven.plugin.MojoExecutionException; 011import org.apache.maven.plugin.MojoFailureException; 012import org.apache.maven.plugins.annotations.Mojo; 013import org.apache.maven.plugins.annotations.ResolutionScope; 014 015import com.ganteater.ae.AEWorkspace; 016import com.ganteater.ae.ConfigurationException; 017import com.ganteater.ae.TaskCancelingException; 018import com.ganteater.ae.desktop.DesktopWorkspace; 019import com.ganteater.ae.desktop.ui.AEFrame; 020 021@Mojo(name = "run", requiresProject = false, requiresDependencyCollection = ResolutionScope.TEST, requiresDependencyResolution = ResolutionScope.TEST) 022public class AE extends AEBase { 023 024 @Override 025 public void execute() throws MojoExecutionException, MojoFailureException { 026 027 if (plugin != null && operationsDependencies != null) { 028 List<File> dependenciesToScan = DependencyScanner.filter(plugin.getArtifacts(), operationsDependencies); 029 DependencyScanner scanner = new DependencyScanner(dependenciesToScan); 030 operations = scanner.scan(); 031 } 032 033 AEFrame frame = new AEFrame() { 034 035 private static final long serialVersionUID = 1L; 036 037 @Override 038 protected DesktopWorkspace createWorkspace() { 039 return new DesktopWorkspace(this) { 040 @Override 041 public void refreshTaskPath() throws IOException { 042 super.refreshTaskPath(); 043 getRecipesPanel().refreshTaskPathTable(); 044 } 045 046 @Override 047 protected File findAlternativeConfiguration(String baseDir) { 048 File confFile = null; 049 if (StringUtils.equals(project.getPackaging(), "pom")) { 050 confFile = super.findAlternativeConfiguration(aeDir); 051 } 052 053 if (confFile == null) { 054 confFile = super.selectConfiguration(); 055 } 056 057 return confFile; 058 } 059 }; 060 } 061 062 }; 063 AEWorkspace workspace = frame.getWorkspace(); 064 065 File file = aeDir == null ? project.getBasedir() : new File(project.getBasedir(), aeDir); 066 workspace.setStartDir(file); 067 workspace.setOperationsClasses(operations); 068 069 importVariables(workspace); 070 071 try { 072 startRecipe(frame, workspace); 073 074 } catch (Exception e) { 075 throw new MojoExecutionException("Anteater failed.", e); 076 } 077 078 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 079 try { 080 for (;;) { 081 if (!frame.isVisible()) { 082 break; 083 } 084 Thread.sleep(500); 085 } 086 } catch (InterruptedException e) { 087 Thread.currentThread().interrupt(); 088 } 089 } 090 091 private void startRecipe(AEFrame frame, AEWorkspace workspace) throws MojoExecutionException { 092 try { 093 frame.start(); 094 runRecipes(workspace, true); 095 096 } catch (TaskCancelingException e) { 097 System.exit(0); 098 } catch (ConfigurationException e) { 099 e.printStackTrace(); 100 System.exit(0); 101 } 102 } 103 104}