github.com/ijc/docker-app@v0.6.1-0.20181012090447-c7ca8bc483fb/integrations/intellij/src/main/java/InitApp.java (about) 1 import com.intellij.notification.Notification; 2 import com.intellij.notification.Notifications; 3 import com.intellij.notification.NotificationType; 4 import com.intellij.openapi.actionSystem.*; 5 import com.intellij.openapi.project.Project; 6 import com.intellij.openapi.ui.Messages; 7 import com.intellij.ide.util.PropertiesComponent; 8 import java.util.Vector; 9 import java.util.Arrays; 10 import java.io.BufferedReader; 11 import java.io.File; 12 import java.io.InputStreamReader; 13 14 15 public class InitApp extends AnAction { 16 public InitApp() { 17 super("InitApp"); 18 } 19 public void actionPerformed(AnActionEvent event) { 20 Project project = event.getProject(); 21 InitDialog id = new InitDialog(); 22 id.pack(); 23 id.setVisible(true); 24 if (!id.wasValidated()) { 25 return; 26 } 27 InitDialog.Result r = id.result(); 28 Vector<String> cmd = new Vector<String>(); 29 cmd.add("docker-app"); 30 cmd.add("init"); 31 cmd.add(r.name); 32 if (r.singleFile) { 33 cmd.add("-s"); 34 } 35 if (!r.description.isEmpty()) { 36 cmd.add("-d"); 37 cmd.add(r.description); 38 } 39 if (!r.maintainers.isEmpty()) { 40 String[] mts = r.maintainers.split("\n"); 41 for (String m: mts) { 42 if (!m.isEmpty()) { 43 cmd.add("-m"); 44 cmd.add(m); 45 } 46 } 47 } 48 Notification no = new Notification("docker-app", "init", cmd.toString(), NotificationType.INFORMATION); 49 Notifications.Bus.notify(no); 50 try { 51 String[] scmd = Arrays.copyOf(cmd.toArray(), cmd.size(), String[].class); 52 Process p = Runtime.getRuntime().exec(scmd, null, new File(project.getBasePath())); 53 BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); 54 String line; 55 while ((line = input.readLine()) != null) { 56 Notification n = new Notification("docker-app", "init", line, NotificationType.INFORMATION); 57 Notifications.Bus.notify(n); 58 } 59 BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream())); 60 while ((line = error.readLine()) != null) { 61 Notification n = new Notification("docker-app", "init", line, NotificationType.ERROR); 62 Notifications.Bus.notify(n); 63 } 64 p.wait(); 65 String msg = "Application successfuly created."; 66 if (p.exitValue()!=0) { 67 msg = "Application creation failed, check event log for more informations."; 68 } 69 Messages.showMessageDialog(project, msg, "Application creation result", Messages.getInformationIcon()); 70 71 } catch (Exception e) { 72 Messages.showMessageDialog(project, "docker-app invocation failed with " + e.toString(), "Render Failure", Messages.getInformationIcon()); 73 e.printStackTrace(); 74 } 75 } 76 }