This is an automated email from the git hooks/post-receive script. pini pushed a commit to tag upstream/1.1.0_beta1 in repository sikuli.
commit 3a92e6466b185c5ee945826db89d4192f2cc3aec Author: Raimund Hocke <[email protected]> Date: Fri Feb 28 19:04:29 2014 +0100 more for multi scripting support - added a final cleaner for the temp folder in IDE --- .../src/main/java/org/sikuli/basics/Settings.java | 140 +++++++++++++++------ IDE/src/main/java/org/sikuli/ide/SikuliIDE.java | 63 ++++------ 2 files changed, 130 insertions(+), 73 deletions(-) diff --git a/Basics/src/main/java/org/sikuli/basics/Settings.java b/Basics/src/main/java/org/sikuli/basics/Settings.java index 09c5db7..a53a0cd 100644 --- a/Basics/src/main/java/org/sikuli/basics/Settings.java +++ b/Basics/src/main/java/org/sikuli/basics/Settings.java @@ -7,12 +7,17 @@ package org.sikuli.basics; import java.io.File; +import java.io.FilenameFilter; import java.net.InetAddress; import java.net.Proxy; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.ServiceLoader; import java.util.prefs.Preferences; public class Settings { @@ -24,6 +29,7 @@ public class Settings { private static String me = "Settings"; private static int lvl = 3; + private static void log(int level, String message, Object... args) { Debug.logx(level, level < 0 ? "error" : "debug", me + ": " + message, args); @@ -77,8 +83,7 @@ public class Settings { public static String SikuliVersionIDE; public static String SikuliVersionScript; public static final String versionMonth = "January 2014"; - public static final String libOpenCV = "libopencv_java248"; - + public static final String libOpenCV = "libopencv_java248"; /** * Resource types to be used with IResourceLoader implementations @@ -96,28 +101,32 @@ public class Settings { private static Preferences options = Preferences.userNodeForPackage(SikuliX.class); - public static Map<String, String> EndingTypes = new HashMap<String, String>(); - public static Map<String, String> TypeEndings = new HashMap<String, String>(); - public static String CPYTHON = "text/python"; - public static String CRUBY = "text/ruby"; - public static String CPLAIN = "text/plain"; - public static String EPYTHON = "py"; - public static String ERUBY = "rb"; - public static String EPLAIN = "txt"; - public static String RPYTHON = "jython"; - public static String RRUBY = "jruby"; - public static String EDEFAULT = EPYTHON; - public static String TypeCommentToken = "---SikuliX---"; - public static String TypeCommentDefault = "# This script uses %s " + TypeCommentToken + "\n"; - - static { + public static Map<String, IDESupport> ideSupporter = new HashMap<String, IDESupport>(); + public static Map<String, IScriptRunner> scriptRunner = new HashMap<String, IScriptRunner>(); + private static List<String> supportedRunner = new ArrayList<String>(); + public static Map<String, String> EndingTypes = new HashMap<String, String>(); + public static Map<String, String> TypeEndings = new HashMap<String, String>(); + public static String CPYTHON = "text/python"; + public static String CRUBY = "text/ruby"; + public static String CPLAIN = "text/plain"; + public static String EPYTHON = "py"; + public static String ERUBY = "rb"; + public static String EPLAIN = "txt"; + public static String RPYTHON = "jython"; + public static String RRUBY = "jruby"; + public static String RDEFAULT = "NotDefined"; + public static String EDEFAULT = EPYTHON; + public static String TypeCommentToken = "---SikuliX---"; + public static String TypeCommentDefault = "# This script uses %s " + TypeCommentToken + "\n"; + + static { Properties props = System.getProperties(); //for debugging if (System.getProperty("user.name") != null && !"".equals(System.getProperty("user.name"))) { UserName = System.getProperty("user.name"); } - BaseTempPath = System.getProperty("java.io.tmpdir") + File.separator + UserName; + BaseTempPath = new File(System.getProperty("java.io.tmpdir"), UserName).getAbsolutePath(); // TODO check existence of an extension repository SikuliRepo = null; @@ -133,12 +142,75 @@ public class Settings { SikuliVersionScript = SikuliVersionDefaultScript; } - EndingTypes.put("py", CPYTHON ); - EndingTypes.put("rb", CRUBY); - EndingTypes.put("txt", CPLAIN); - for (String k : EndingTypes.keySet()) { - TypeEndings.put(EndingTypes.get(k), k); - } + EndingTypes.put("py", CPYTHON); + EndingTypes.put("rb", CRUBY); + EndingTypes.put("txt", CPLAIN); + for (String k : EndingTypes.keySet()) { + TypeEndings.put(EndingTypes.get(k), k); + } + } + + public static void cleanTemp() { + for (File f : new File(System.getProperty("java.io.tmpdir")).listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + if (name.contains("BridJExtractedLibraries")) { + return true; + } + if (name.toLowerCase().contains("sikuli")) { + return true; + } + return false; + }})) + { + Debug.log(4, "cleanTemp: " + f.getName()); + FileManager.deleteFileOrFolder(f.getAbsolutePath()); + } + FileManager.deleteFileOrFolder(BaseTempPath); + } + + public static void initScriptingSupport() { + if (scriptRunner.size() == 0) { + ServiceLoader<IDESupport> sloader = ServiceLoader.load(IDESupport.class); + Iterator<IDESupport> supIterator = sloader.iterator(); + while (supIterator.hasNext()) { + IDESupport current = supIterator.next(); + try { + for (String ending : current.getEndings()) { + ideSupporter.put(ending, current); + } + } catch (Exception ex) { + } + } + ServiceLoader<IScriptRunner> rloader = ServiceLoader.load(IScriptRunner.class); + Iterator<IScriptRunner> rIterator = rloader.iterator(); + while (rIterator.hasNext()) { + IScriptRunner current = rIterator.next(); + String name = current.getName(); + if (!name.startsWith("Not")) { + scriptRunner.put(name, current); + } + } + } + if (scriptRunner.size() == 0) { + Debug.error("Settings: No scripting support available. Rerun Setup!"); + SikuliX.popup("No scripting support available. Rerun Setup!", "SikuliX - Fatal Error!"); + System.exit(1); + } else { + RDEFAULT = (String) scriptRunner.keySet().toArray()[0]; + EDEFAULT = scriptRunner.get(RDEFAULT).getFileEndings()[0]; + for (IScriptRunner r : scriptRunner.values()) { + for (String e : r.getFileEndings()){ + if (!supportedRunner.contains(EndingTypes.get(e))) { + supportedRunner.add(EndingTypes.get(e)); + } + } + } + } + } + + public static boolean hasTypeRunner(String type) { + return supportedRunner.contains(type); } public static final int ISWINDOWS = 0; @@ -174,11 +246,11 @@ public class Settings { public static boolean OcrTextRead = false; /** - * true = start slow motion mode, false: stop it (default: false) show a visual for - * SlowMotionDelay seconds (default: 2) + * true = start slow motion mode, false: stop it (default: false) show a visual for SlowMotionDelay seconds (default: + * 2) */ - public static boolean TRUE = true; - public static boolean FALSE = false; + public static boolean TRUE = true; + public static boolean FALSE = false; private static boolean ShowActions = false; @@ -189,8 +261,7 @@ public class Settings { public static void setShowActions(boolean ShowActions) { if (ShowActions) { MoveMouseDelaySaved = MoveMouseDelay; - } - else { + } else { MoveMouseDelay = MoveMouseDelaySaved; } Settings.ShowActions = ShowActions; @@ -201,8 +272,8 @@ public class Settings { private static float MoveMouseDelaySaved = MoveMouseDelay; /** - * true = highlight every match (default: false) (show red rectangle around) for - * DefaultHighlightTime seconds (default: 2) + * true = highlight every match (default: false) (show red rectangle around) for DefaultHighlightTime seconds + * (default: 2) */ public static boolean Highlight = false; public static float DefaultHighlightTime = 2f; @@ -307,14 +378,13 @@ public class Settings { public static String getVersionShort() { if (SikuliVersionBetaN > 0 && SikuliVersionBetaN < 99) { return bversion; - } - else { + } else { return sversion; } } public static String getVersionShortBasic() { - return sversion.substring(0, 3); + return sversion.substring(0, 3); } public static void setArgs(String[] args, String[] sargs) { diff --git a/IDE/src/main/java/org/sikuli/ide/SikuliIDE.java b/IDE/src/main/java/org/sikuli/ide/SikuliIDE.java index 29cbe24..e466a12 100755 --- a/IDE/src/main/java/org/sikuli/ide/SikuliIDE.java +++ b/IDE/src/main/java/org/sikuli/ide/SikuliIDE.java @@ -114,40 +114,14 @@ public class SikuliIDE extends JFrame { private static JFrame splash; private boolean firstRun = true; private static long start; - private static Map<String, IDESupport> ideSupporter = new HashMap<String, IDESupport>(); - public static Map<String, IScriptRunner> scriptRunner = new HashMap<String, IScriptRunner>(); - - static { - ServiceLoader<IDESupport> sloader = ServiceLoader.load(IDESupport.class); - Iterator<IDESupport> supIterator = sloader.iterator(); - while (supIterator.hasNext()) { - IDESupport current = supIterator.next(); - try { - for (String ending : current.getEndings()) { - ideSupporter.put(ending, current); - } - } catch (Exception ex) { - } - } - ServiceLoader<IScriptRunner> rloader = ServiceLoader.load(IScriptRunner.class); - Iterator<IScriptRunner> rIterator = rloader.iterator(); - IScriptRunner current; - while (rIterator.hasNext()) { - current = rIterator.next(); - String name = current.getName(); - if (!name.startsWith("Not")) { - scriptRunner.put(name, current); - } - } - if (scriptRunner.size() == 0) { - Debug.error("SikuliIDE: No scripting support available. Rerun Setup!"); - } - current = (IScriptRunner) scriptRunner.values().toArray()[0]; - Settings.EDEFAULT = current.getFileEndings()[0]; - } + private static File isRunning; + private static FileOutputStream isRunningFile = null; + + static { + } public static IDESupport getIDESupport(String ending) { - return ideSupporter.get(ending); + return Settings.ideSupporter.get(ending); } public static String _I(String key, Object... args) { @@ -173,10 +147,8 @@ public class SikuliIDE extends JFrame { String[] splashArgs = new String[]{ "splash", "#", "#" + Settings.SikuliVersionIDE, "", "#", "#... starting - please wait ..."}; - File isRunning; new File(Settings.BaseTempPath).mkdirs(); isRunning = new File(Settings.BaseTempPath, "sikuli-ide-isrunning"); - FileOutputStream isRunningFile = null; try { isRunning.createNewFile(); isRunningFile = new FileOutputStream(isRunning); @@ -190,11 +162,24 @@ public class SikuliIDE extends JFrame { } catch (Exception ex) { splashArgs[5] = "Terminating on FatalError: cannot access IDE lock "; splash = new MultiFrame(splashArgs); - log(-1, splashArgs[5] + isRunning.getAbsolutePath()); + log(-1, splashArgs[5] + "\n" + isRunning.getAbsolutePath()); SikuliX.pause(3); System.exit(1); } + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + log(lvl, "final cleanup"); + try { + isRunningFile.close(); + } catch (IOException ex) { + } + isRunning.delete(); + Settings.cleanTemp(); + } + }); + if (System.getProperty("sikuli.FromCommandLine") == null) { String[] userOptions = SikuliX.collectOptions("IDE", args); if (userOptions == null) { @@ -209,6 +194,9 @@ public class SikuliIDE extends JFrame { } start = (new Date()).getTime(); + + Settings.initScriptingSupport(); + for (String e : args) { splashArgs[3] += e + " "; } @@ -540,7 +528,7 @@ public class SikuliIDE extends JFrame { setCurrentFileTabTitle(file); return true; } - Debug.error("Can't load file " + file); + Debug.error("Can't load file " + file + " --- check available runners!"); // (new FileAction()).doCloseTab(null); return false; } @@ -2007,8 +1995,7 @@ public class SikuliIDE extends JFrame { String runnerType = null; String cType = pane.getContentType(); runnerType = cType.equals(Settings.CPYTHON) ? Settings.RPYTHON : Settings.RRUBY; - IScriptRunner srunner = SikuliX.getScriptRunner( - runnerType, null, Settings.getArgs()); + IScriptRunner srunner = SikuliX.getScriptRunner(runnerType, null, Settings.getArgs()); if (srunner == null) { Debug.error("Could not load a script runner for: %s (%s)", cType, runnerType); return; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/sikuli.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

