1 19 20 package org.apache.tools.ant.module.run; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.List ; 27 import java.util.Map ; 28 import javax.swing.event.ChangeEvent ; 29 import javax.swing.event.ChangeListener ; 30 import org.apache.tools.ant.module.api.AntProjectCookie; 31 import org.openide.execution.ExecutorTask; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileUtil; 34 import org.openide.loaders.DataObject; 35 import org.openide.loaders.DataObjectNotFoundException; 36 37 41 public class LastTargetExecuted { 42 43 private LastTargetExecuted() {} 44 45 private static File buildScript; 46 private static int verbosity; 47 private static String [] targets; 48 private static Map <String ,String > properties; 49 50 51 static void record(File buildScript, int verbosity, String [] targets, Map <String ,String > properties) { 52 LastTargetExecuted.buildScript = buildScript; 53 LastTargetExecuted.verbosity = verbosity; 54 LastTargetExecuted.targets = targets; 55 LastTargetExecuted.properties = properties; 56 fireChange(); 57 } 58 59 63 public static AntProjectCookie getLastBuildScript() { 64 if (buildScript != null && buildScript.isFile()) { 65 FileObject fo = FileUtil.toFileObject(buildScript); 66 assert fo != null; 67 try { 68 return DataObject.find(fo).getCookie(AntProjectCookie.class); 69 } catch (DataObjectNotFoundException e) { 70 assert false : e; 71 } 72 } 73 return null; 74 } 75 76 80 public static String [] getLastTargets() { 81 return targets; 82 } 83 84 88 public static String getProcessDisplayName() { 89 AntProjectCookie apc = getLastBuildScript(); 90 if (apc != null) { 91 return TargetExecutor.getProcessDisplayName(apc, targets != null ? Arrays.asList(targets) : null); 92 } else { 93 return null; 94 } 95 } 96 97 100 public static ExecutorTask rerun() throws IOException { 101 AntProjectCookie apc = getLastBuildScript(); 102 if (apc == null) { 103 fireChange(); 106 return null; 107 } 108 TargetExecutor t = new TargetExecutor(apc, targets); 109 t.setVerbosity(verbosity); 110 t.setProperties(properties); 111 return t.execute(); 112 } 113 114 private static final List <ChangeListener > listeners = new ArrayList <ChangeListener >(); 115 116 public static void addChangeListener(ChangeListener l) { 117 synchronized (listeners) { 118 listeners.add(l); 119 } 120 } 121 122 public static void removeChangeListener(ChangeListener l) { 123 synchronized (listeners) { 124 listeners.remove(l); 125 } 126 } 127 128 private static void fireChange() { 129 ChangeEvent ev = new ChangeEvent (LastTargetExecuted.class); 130 ChangeListener [] ls; 131 synchronized (listeners) { 132 ls = listeners.toArray(new ChangeListener [listeners.size()]); 133 } 134 for (ChangeListener l : ls) { 135 l.stateChanged(ev); 136 } 137 } 138 139 } 140 | Popular Tags |