From 99221a9332ee2b876c040c4af32c1ffc55173d8d Mon Sep 17 00:00:00 2001 From: johan duparc Date: Sun, 14 Dec 2014 19:26:03 +0100 Subject: [PATCH] moved conf reading in Cst.java --- AutoDerivPlugin/ChangeLog | 2 +- AutoDerivPlugin/src/autoderiv/Activator.java | 2 +- AutoDerivPlugin/src/autoderiv/Tools.java | 126 ------------------- 3 files changed, 2 insertions(+), 128 deletions(-) diff --git a/AutoDerivPlugin/ChangeLog b/AutoDerivPlugin/ChangeLog index 7003524..f93b9af 100644 --- a/AutoDerivPlugin/ChangeLog +++ b/AutoDerivPlugin/ChangeLog @@ -8,7 +8,7 @@ AutoDeriv TODO list [ ] hash useful part of rule, compare this hash before reparsing [ ] make use of IProgress.isCanceled method ? [ ] handle conf files with zero rules - especially master -[ ] command to force usage of regex even if path is OK. Eg. "^a$" +[ ] command to force usage of regex even if path is legal. Eg. "^a$" [ ] command 'post' & 'pre' for the global .derived file [ ] command to disable [Pattern -> fnmatch] regex syntax conversion [ ] add info, warn, err for .derived files diff --git a/AutoDerivPlugin/src/autoderiv/Activator.java b/AutoDerivPlugin/src/autoderiv/Activator.java index 436d358..81f1d28 100644 --- a/AutoDerivPlugin/src/autoderiv/Activator.java +++ b/AutoDerivPlugin/src/autoderiv/Activator.java @@ -18,7 +18,7 @@ public void start(BundleContext context) throws Exception { info("AutoDeriv plugin starts"); // it about the plugin configuration itself - Tools.readConf(); + Cst.readConf(); // launch the listener, + ini listener = new ChangeEventHandler(); diff --git a/AutoDerivPlugin/src/autoderiv/Tools.java b/AutoDerivPlugin/src/autoderiv/Tools.java index d43fd13..548d3b2 100644 --- a/AutoDerivPlugin/src/autoderiv/Tools.java +++ b/AutoDerivPlugin/src/autoderiv/Tools.java @@ -1,15 +1,6 @@ package autoderiv; -import static autoderiv.Cst.*; -import static autoderiv.Debug.*; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -44,121 +35,4 @@ public static void checkedSetDerived_nt(IResource res, boolean derived, IProgres } } - - public static void readConf() { - File f = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata").append(PLUGIN_CONF_FILE_NAME).toFile(); - if(f==null || !f.exists()){ - f = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(PLUGIN_CONF_FILE_NAME).toFile(); - if(f==null || !f.exists()) - return; - } - - dbg("found plugin conf file at "+f.getAbsolutePath()); - - FileInputStream fis; - try { - fis = new FileInputStream(f); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return; - } - - BufferedReader br = new BufferedReader(new InputStreamReader(fis)); - try { - String line = null; - int i = 0; - while ((line = br.readLine()) != null){ - try { - parseConfLine(line, ++i); - } catch (Exception e) { - warn("bad pluging conf parsing at line "+i); - } - } - br.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - DECORATION_FOREGROUND_ENABLED = - ( DECORATION_FOREGROUND_R>0 - & DECORATION_FOREGROUND_G>0 - & DECORATION_FOREGROUND_B>0); - - DECORATION_BACKGROUND_ENABLED = - ( DECORATION_BACKGROUND_R > 0 - & DECORATION_BACKGROUND_G > 0 - & DECORATION_BACKGROUND_B > 0); - - } - - - private static void parseConfLine(String line, int i) throws NumberFormatException { - // filter out comments (after #char) - int commentLocation = line.indexOf('#'); - if(commentLocation != -1) - line = line.substring(0, commentLocation); - if(line.trim().isEmpty()) return; // comments - - dbg("parse line ["+i+"]: "+ line); - - // check that its an affectation line - String[] a = line.split("="); - if(a.length==2){ - String key = a[0].trim(); - String val = a[1]; - String valt = a[1].trim(); - dbg("parsed: [" + key +"] = "+ valt); - if(key.equals(PLUGIN_ID+TRACE_LOG_STR)) - Cst.TRACE_LOG = "true".equals(valt); - if(key.equals(PLUGIN_ID+TRACE_STD_STR)) - Cst.TRACE_STD = "true".equals(valt); - else if(key.equals(PLUGIN_ID+TRACE_DBG_STR)) - Cst.ENABLE_DBG = "true".equals(valt); - else if(key.equals(PLUGIN_ID+TRACE_INFO_STR)) - Cst.ENABLE_INFO = "true".equals(valt); - else if(key.equals(PLUGIN_ID+TRACE_WARN_STR)) - Cst.ENABLE_WARN = "true".equals(valt); - - - else if(key.equals(PLUGIN_ID+DECORATION_SUFFIX_STR)){ - DECORATION_SUFFIX_ENABLED = true; - DECORATION_SUFFIX = val; - } - else if(key.equals(PLUGIN_ID+DECORATION_PREFIX_STR)){ - DECORATION_PREFIX_ENABLED = true; - DECORATION_PREFIX = val; - } - - else if(key.equals(PLUGIN_ID+DECORATION_FOREGROUND_R_STR)) - DECORATION_FOREGROUND_R = Integer.parseInt(valt); - else if(key.equals(PLUGIN_ID+DECORATION_FOREGROUND_G_STR)) - DECORATION_FOREGROUND_G = Integer.parseInt(valt); - else if(key.equals(PLUGIN_ID+DECORATION_FOREGROUND_B_STR)) - DECORATION_FOREGROUND_B = Integer.parseInt(valt); - - else if(key.equals(PLUGIN_ID+DECORATION_BACKGROUND_R_STR)) - DECORATION_BACKGROUND_R = Integer.parseInt(valt); - else if(key.equals(PLUGIN_ID+DECORATION_BACKGROUND_G_STR)) - DECORATION_BACKGROUND_G = Integer.parseInt(valt); - else if(key.equals(PLUGIN_ID+DECORATION_BACKGROUND_B_STR)) - DECORATION_BACKGROUND_B = Integer.parseInt(valt); - else - warn("key not recognized at line: " + i); - } - else if(a.length==1){ - // it like an affectation to nothing - String key = a[0].trim(); - - if(key.equals(PLUGIN_ID+DECORATION_PREFIX_STR)) - DECORATION_PREFIX_ENABLED = false; - else if(key.equals(PLUGIN_ID+DECORATION_SUFFIX_STR)) - DECORATION_SUFFIX_ENABLED = false; - else - warn("key not affected correctly: " + i); - } - else{ - warn("bad line: " + i); - } - } - }