Skip to content

Commit

Permalink
moved conf reading in Cst.java
Browse files Browse the repository at this point in the history
  • Loading branch information
nodj committed Dec 14, 2014
1 parent feb583e commit 99221a9
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 128 deletions.
2 changes: 1 addition & 1 deletion AutoDerivPlugin/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion AutoDerivPlugin/src/autoderiv/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
126 changes: 0 additions & 126 deletions AutoDerivPlugin/src/autoderiv/Tools.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}
}

}

0 comments on commit 99221a9

Please sign in to comment.