Skip to content

Commit

Permalink
Removed a lot of debug output in favor of using the hava java logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew O. Smith committed Jan 3, 2015
1 parent 6dc5be3 commit 8fa0b26
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 39 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
compile 'jline:jline:2.11'
compile 'org.fusesource.jansi:jansi:1.11'
compile 'junit:junit:4.11'
compile 'org.slf4j:slf4j-jdk14:1.7.5'

testCompile 'net.java.quickcheck:quickcheck:0.6'

Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/com/software_ninja/malabar/Malabar.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MalabarStart {
public MalabarStart(port) { this.defaultPort = port;}

def startArgs(String[] args) {
println "ARGS: " + args
//println "ARGS: " + args
def argMap = new SpreadMap(args);
String port = defaultPort;
if(argMap["-p"] != null) port = argMap["-p"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ public class MalabarUtil {


}

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package com.software_ninja.malabar.http;
import com.sun.net.httpserver.HttpHandler
import com.sun.net.httpserver.HttpExchange
import groovy.json.JsonBuilder
import groovy.util.logging.*


@Log
class JsonHandlerFactory {

private Map cache;
Expand Down Expand Up @@ -45,11 +46,11 @@ class JsonHandlerFactory {
httpExchange.responseHeaders.set('Content-Type', 'application/json')

//final String query = httpExchange.requestURI.rawQuery
println "QUERY:" + httpExchange.requestURI.rawQuery
println "METHOD:" + httpExchange.requestMethod
println "PARAMS:" + params
log.fine "QUERY:" + httpExchange.requestURI.rawQuery
log.fine "METHOD:" + httpExchange.requestMethod
log.fine "PARAMS:" + params

//println params["repo"]
//log.fine params["repo"]
// if(!query || !query.contains('string')){
// httpExchange.sendResponseHeaders(400,0)
// return
Expand All @@ -76,7 +77,7 @@ class JsonHandlerFactory {

} finally {
httpExchange.close()
println "end end end"
log.fine "end end end"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.Filter;
import com.sun.net.httpserver.Filter.Chain;
import groovy.util.logging.*
import java.util.logging.Handler
import java.util.logging.Logger
import java.util.logging.Level
import java.util.logging.LogManager

@Log
class MalabarServer {
def cache = [:];
def config = [ cache :cache ];

def start(String port) {

def mph = new MavenProjectHandler(config);
def addr = new InetSocketAddress(Integer.parseInt(port))
def httpServer = com.sun.net.httpserver.HttpServer.create(addr, 0)
Expand Down Expand Up @@ -40,13 +47,18 @@ class MalabarServer {
context = httpServer.createContext('/tags/', new JsonHandlerFactory(config).build({params ->
def pmIn = params["pm"];
def pm = (pmIn == null ? null : MalabarUtil.expandFile(pmIn));
mph.tags(params["repo"], pm, params["class"]);}));
mph.tags(params["repo"], pm, params["class"]);}));
context.getFilters().add(new ParameterFilter());

context = httpServer.createContext('/debug/', new JsonHandlerFactory(config).build({params ->
def pmIn = params["pm"];
def pm = (pmIn == null ? null : MalabarUtil.expandFile(pmIn));
mph.debug(params["repo"], pm)}));
def jmx = LogManager.getLoggingMXBean()
jmx.loggerNames.each({ if( it.startsWith("com.software_ninja")) {
jmx.setLoggerLevel( it, "FINEST")}});


def pmIn = params["pm"];
def pm = (pmIn == null ? null : MalabarUtil.expandFile(pmIn));
mph.debug(params["repo"], pm)}));
context.getFilters().add(new ParameterFilter());

context = httpServer.createContext('/spawn/', new JsonHandlerFactory(config).build({params ->
Expand All @@ -69,7 +81,7 @@ class MalabarServer {
context.getFilters().add(new ParameterFilter());

context = httpServer.createContext('/add/', new JsonHandlerFactory(config).build({params ->
println "ADD: " + params
log.fine "ADD: " + params
mph.additionalClasspath(params["relative"], params["absolute"]);}));
context.getFilters().add(new ParameterFilter());

Expand All @@ -80,14 +92,14 @@ class MalabarServer {
httpServer.setExecutor(Executors.newCachedThreadPool())
httpServer.start()

println "running on " + port;
log.fine "running on " + port;
return httpServer;
}


}


@Log
class ParameterFilter extends Filter {

@Override
Expand All @@ -98,11 +110,11 @@ class ParameterFilter extends Filter {
@Override
public void doFilter(HttpExchange exchange, Chain chain)
throws IOException {
println exchange;
log.fine exchange.toString();
try {
parseGetParameters(exchange);
parsePostParameters(exchange);
println exchange.getAttribute("parameters");
log.fine exchange.getAttribute("parameters").toString();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
Expand All @@ -116,7 +128,7 @@ class ParameterFilter extends Filter {
Map<String, Object> parameters = new HashMap<String, Object>();
URI requestedUri = exchange.getRequestURI();
String query = requestedUri.getRawQuery();
//println "GET QUERY:" + query;
//log.fine "GET QUERY:" + query;
parseQuery(query, parameters);
exchange.setAttribute("parameters", parameters);
}
Expand All @@ -128,12 +140,12 @@ class ParameterFilter extends Filter {
@SuppressWarnings("unchecked")
Map<String, Object> parameters =
(Map<String, Object>)exchange.getAttribute("parameters");
//println "POST PARAMETERS:" + parameters;
//log.fine "POST PARAMETERS:" + parameters;
InputStreamReader isr =
new InputStreamReader(exchange.getRequestBody(),"utf-8");
BufferedReader br = new BufferedReader(isr);
String query = br.readLine();
//println "POST QUERY:" + query;
//log.fine "POST QUERY:" + query;
parseQuery(query, parameters);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import javax.lang.model.element.NestingKind;
import javax.tools.JavaFileObject.Kind;
import java.nio.CharBuffer;
import javax.tools.JavaFileObject;
import groovy.util.logging.*

/**
* Provides simple implementations for most methods in JavaFileObject.
Expand All @@ -52,7 +53,7 @@ import javax.tools.JavaFileObject;
*/



@Log
public class FileJavaFileObject implements JavaFileObject {
/**
* A URI for this file object.
Expand Down Expand Up @@ -97,7 +98,7 @@ public class FileJavaFileObject implements JavaFileObject {
FileReader fr = new FileReader(file);
fr.read(rtnval);
rtnval.flip();
println rtnval
log.fine rtnval.toString()
rtnval;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.software_ninja.malabar.lang;

import org.codehaus.groovy.control.ErrorCollector;
import groovy.util.logging.*

public class GroovyParser implements Parser {

Expand All @@ -25,8 +26,8 @@ public class GroovyParser implements Parser {
def regex = /.*At \[(\d+):(\d+)\] (.*)/
def message = ex.cause.message;
def matcher = ( message =~ regex );
println matcher.matches()
println matcher[0]
log.fine matcher.matches().toString()
log.fine matcher[0].toString()
if (matcher.groupCount() > 0) {
def line = matcher[0][1];
def col = matcher[0][2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import javax.tools.StandardLocation;
import java.nio.CharBuffer;

import java.lang.reflect.Modifier;

import groovy.util.logging.*

@Log
public class JavaParser implements Parser {

def classloader;
Expand All @@ -22,7 +24,7 @@ public class JavaParser implements Parser {
}

def parse(File f) {
println "FILE:" + f.toURI();
log.fine "FILE:" + f.toURI();
def fileObjects = new FileJavaFileObject(f);
parseInternal( [ fileObjects ]);
}
Expand All @@ -49,7 +51,7 @@ public class JavaParser implements Parser {

if(result) {
def m = output.toString() =~ /\[checking (.*)\]/
println output.toString();
//log.fine output.toString();
def clazzes = m.collect({classloader.loadClass(it[1])});
def clazz = null;
if(clazzes.size > 0 ) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/groovy/com/software_ninja/malabar/lang/NewVM.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.software_ninja.malabar.lang;

import groovy.util.logging.*

public class NewVM {

Expand All @@ -12,7 +13,7 @@ public class NewVM {
String separator = System.getProperty("path.separator");
String classpath = classLoader.classPath.join(separator)
def ii = jdkPath + "bin/javaw.exe"
//println(classpath);
//log.fine(classpath);
ProcessBuilder processBuilder = new ProcessBuilder(ii, "-cp",
classpath,
'-Xmx128m',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import groovy.util.logging.*


@Log
public class MavenProjectHandler {

/**
Expand Down Expand Up @@ -112,7 +113,7 @@ public class MavenProjectHandler {
def parent = pomFile.getParent();
def relPaths =relative.collect({new File (parent, it).getAbsolutePath()});
def bootClasspath = System.getProperty("sun.boot.class.path");
println "RELPATHS" + relPaths;
log.fine "RELPATHS" + relPaths;
def classpath = relPaths +
absolute +
projectInfo['test']['resources'].collect({it.directory}) +
Expand All @@ -128,7 +129,7 @@ public class MavenProjectHandler {

def staticClassloader = createClassLoaderStatic(classpath);
def classloader = createClassLoader(classpath);
//println classpath
//log.fine classpath
def rtnval = [timestamp : mod,
projectInfo : projectInfo,
resourceCache : resourceCache,
Expand Down Expand Up @@ -188,8 +189,8 @@ public class MavenProjectHandler {
def regex = /.*At \[(\d+):(\d+)\] (.*)/
def message = ex.cause.message;
def matcher = ( message =~ regex );
println matcher.matches()
println matcher[0]
log.fine matcher.matches().toString()
log.fine matcher[0].toString()
if (matcher.groupCount() > 0) {
def line = matcher[0][1];
def col = matcher[0][2];
Expand All @@ -210,7 +211,7 @@ public class MavenProjectHandler {
* Parse the script on disk. Return errors as a list
*/
def parse(repo, pom, scriptIn, scriptBody, parserName) {
println "Start Parse";
log.fine "Start Parse";
try{

def cached = lookInCache( pom, { fecthProjectInfo(repo, pom)});
Expand All @@ -219,15 +220,15 @@ public class MavenProjectHandler {
def rtnval = null;
if(scriptBody == null) {
def script = MalabarUtil.expandFile(scriptIn);
println "PArsing script:" + script + " with parser:" + parser;
log.fine "PArsing script:" + script + " with parser:" + parser;
rtnval = parser.parse(new File(script));

} else {
println "PArsing scriptBody: with parser:" + parser;
log.fine "PArsing scriptBody: with parser:" + parser;
rtnval = parser.parse(scriptBody);

}
println "parsed fine";
log.fine "parsed fine";
rtnval['class'] == null ? rtnval['errors'] : [];

} catch (Exception ex){
Expand Down Expand Up @@ -255,7 +256,7 @@ public class MavenProjectHandler {
it['stackTrace']]});
}
Request request = Request.method(clazz,method);
println "UnitTest "+ clazz.getName() + " ..."
log.fine "UnitTest "+ clazz.getName() + " ..."

if( method == null ) {
request = Request.aClass(clazz);
Expand Down Expand Up @@ -291,7 +292,7 @@ public class MavenProjectHandler {
def resource(repo, pm, pattern, max, isClass, useRegex){
def cached = lookInCache( pm, { fecthProjectInfo(repo, pm)});
def resourceCache = cached['resourceCache'];
println "RESOURCE:" + resourceCache + " " + isClass + " " + useRegex + " " + max;
log.fine "RESOURCE:" + resourceCache + " " + isClass + " " + useRegex + " " + max;
if( isClass == null || isClass ){

resourceCache.findClass(pattern, max);
Expand Down Expand Up @@ -434,7 +435,7 @@ public class MavenProjectsCreator {
boolean rtnval = ! optional && ! (['activation', 'xerces-impl', 'ant',
'com.springsource.org.hibernate.validator-4.1.0.GA',
'xerces-impl-2.6.2'].contains(artifactId));
//println "" + rtnval + " NODE:" + optional + ' ' + artifactId + " " + parents;
//log.fine "" + rtnval + " NODE:" + optional + ' ' + artifactId + " " + parents;

return rtnval;

Expand Down

0 comments on commit 8fa0b26

Please sign in to comment.