Browse Source

Use Logger instead of System.out and System.err (#10328,#13300).

Change-Id: I6a93e763c212eb39d7da9fdbd38f6a8609799c34
tags/7.2.0.beta1
denisanisimov 10 years ago
parent
commit
bfe548e6d6

+ 5
- 1
common.xml View File

@@ -139,6 +139,7 @@
<fileset dir="${src}">
<patternset>
<include name="**/*.java" />
<include name="**/*.properties" />
</patternset>
</fileset>
<fileset refid="common.files.for.all.jars" />
@@ -184,7 +185,7 @@
<property name="src" location="{$result.dir}/../src" />

<union id="jar.files">
<fileset dir="${classes}" excludes="${classes.exclude}" erroronmissingdir="false" />
<fileset dir="${classes}" excludes="${classes.exclude}" erroronmissingdir="false"/>
<fileset dir="${src}" excludes="${jar.exclude}" erroronmissingdir="false" />
<fileset refid="common.files.for.all.jars" />
<union refid="extra.jar.includes" />
@@ -277,6 +278,9 @@
<classpath refid="classpath.compile.dependencies" />
<classpath refid="classpath.compile.custom" />
</javac>
<copy todir="${classes}">
<fileset dir="${src}" includes="${extra.classes}"/>
</copy>
</target>

<target name="exec-buildhelper" depends="compile">

+ 2
- 2
theme-compiler/build.xml View File

@@ -20,8 +20,8 @@
</path>
<path id="classpath.test.custom" />

<!--<property name="classes.exclude" value="com/vaadin/buildhelpers/**"
/> -->
<property name="classes.exclude" value="**/*.properties"/>
<property name="extra.classes" value="${classes.exclude}"/>

<target name="parser">
<!-- Copy javacc-5.0.jar to ${result.dir}/javacc/javacc.jar as the

+ 52
- 0
theme-compiler/src/com/vaadin/sass/CustomConsoleHandler.java View File

@@ -0,0 +1,52 @@
/*
* Copyright 2000-2013 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.sass;

import java.io.PrintStream;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

/**
*
* @since
* @author Vaadin Ltd
*/
public class CustomConsoleHandler extends ConsoleHandler {

private ConsoleHandler stdoutHandler;

public CustomConsoleHandler() {
PrintStream err = System.err;
/*
* ConsoleHandler uses System.err to output all messages. Replace
* System.err temporary to construct ConsoleHandler and set it back
* after construction.
*/
System.setErr(System.out);
stdoutHandler = new ConsoleHandler();
System.setErr(err);
}

@Override
public void publish(LogRecord record) {
if (!Level.SEVERE.equals(record.getLevel())) {
stdoutHandler.publish(record);
} else {
super.publish(record);
}
}
}

+ 17
- 0
theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java View File

@@ -24,11 +24,13 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.InputSource;

import com.vaadin.buildhelpers.CompileTheme;
import com.vaadin.sass.internal.handler.SCSSDocumentHandler;
import com.vaadin.sass.internal.handler.SCSSDocumentHandlerImpl;
import com.vaadin.sass.internal.handler.SCSSErrorHandler;
@@ -457,4 +459,19 @@ public class ScssStylesheet extends Node {
public void setCharset(String charset) {
this.charset = charset;
}

static {
String logFile = System.getProperty("java.util.logging.config.file");
if (logFile == null) {
try {
LogManager.getLogManager().readConfiguration(
CompileTheme.class
.getResourceAsStream("/logging.properties"));
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

+ 24
- 9
theme-compiler/src/com/vaadin/sass/internal/handler/SCSSDocumentHandlerImpl.java View File

@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.InputSource;
@@ -98,7 +100,7 @@ public class SCSSDocumentHandlerImpl implements SCSSDocumentHandler {
public ForNode forDirective(String var, String from, String to,
boolean exclusive, String body) {
ForNode node = new ForNode(var, from, to, exclusive, body);
System.out.println(node);
log(node);
return node;
}

@@ -126,7 +128,7 @@ public class SCSSDocumentHandlerImpl implements SCSSDocumentHandler {
@Override
public WhileNode whileDirective(String condition, String body) {
WhileNode node = new WhileNode(condition, body);
System.out.println(node);
log(node);
return node;
}

@@ -138,14 +140,14 @@ public class SCSSDocumentHandlerImpl implements SCSSDocumentHandler {

@Override
public void ignorableAtRule(String atRule) throws CSSException {
System.out.println("ignorableAtRule(String atRule): " + atRule);
log("ignorableAtRule(String atRule): " + atRule);
}

@Override
public void namespaceDeclaration(String prefix, String uri)
throws CSSException {
System.out.println("namespaceDeclaration(String prefix, String uri): "
+ prefix + ", " + uri);
log("namespaceDeclaration(String prefix, String uri): " + prefix + ", "
+ uri);
}

@Override
@@ -167,14 +169,14 @@ public class SCSSDocumentHandlerImpl implements SCSSDocumentHandler {

@Override
public void startPage(String name, String pseudo_page) throws CSSException {
System.out.println("startPage(String name, String pseudo_page): "
+ name + ", " + pseudo_page);
log("startPage(String name, String pseudo_page): " + name + ", "
+ pseudo_page);
}

@Override
public void endPage(String name, String pseudo_page) throws CSSException {
System.out.println("endPage(String name, String pseudo_page): " + name
+ ", " + pseudo_page);
log("endPage(String name, String pseudo_page): " + name + ", "
+ pseudo_page);
}

@Override
@@ -386,4 +388,17 @@ public class SCSSDocumentHandlerImpl implements SCSSDocumentHandler {
public void endIncludeContentBlock() {
nodeStack.pop();
}

private void log(Object object) {
if (object != null) {
log(object.toString());
} else {
log(null);
}
}

private void log(String msg) {
Logger.getLogger(SCSSDocumentHandlerImpl.class.getName()).log(
Level.INFO, msg);
}
}

+ 16
- 20
theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java View File

@@ -15,7 +15,8 @@
*/
package com.vaadin.sass.internal.handler;

import java.io.PrintStream;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.CSSParseException;
@@ -23,38 +24,33 @@ import org.w3c.css.sac.ErrorHandler;

public class SCSSErrorHandler implements ErrorHandler {

private PrintStream errorStream;

public SCSSErrorHandler(PrintStream errorStream) {
this.errorStream = errorStream;
}

public SCSSErrorHandler() {
this(System.out);
}

@Override
public void error(CSSParseException arg0) throws CSSException {
errorStream.println("Error when parsing file \n" + arg0.getURI()
+ " on line " + arg0.getLineNumber() + ", column "
+ arg0.getColumnNumber());
errorStream.println(arg0.getMessage() + "\n");
log("Error when parsing file \n" + arg0.getURI() + " on line "
+ arg0.getLineNumber() + ", column " + arg0.getColumnNumber());
log(arg0.getMessage() + "\n");
}

@Override
public void fatalError(CSSParseException arg0) throws CSSException {
errorStream.println("FATAL Error when parsing file \n" + arg0.getURI()
+ " on line " + arg0.getLineNumber() + ", column "
+ arg0.getColumnNumber());
errorStream.println(arg0.getMessage() + "\n");
log("FATAL Error when parsing file \n" + arg0.getURI() + " on line "
+ arg0.getLineNumber() + ", column " + arg0.getColumnNumber());
log(arg0.getMessage() + "\n");
}

@Override
public void warning(CSSParseException arg0) throws CSSException {
errorStream.println("Warning when parsing file \n" + arg0.getURI()
+ " on line " + arg0.getLineNumber() + ", column "
+ arg0.getColumnNumber());
errorStream.println(arg0.getMessage() + "\n");
log("Warning when parsing file \n" + arg0.getURI() + " on line "
+ arg0.getLineNumber() + ", column " + arg0.getColumnNumber());
log(arg0.getMessage() + "\n");
}

private void log(String msg) {
Logger.getLogger(SCSSDocumentHandlerImpl.class.getName()).log(
Level.SEVERE, msg);
}

}

+ 20
- 9
theme-compiler/src/com/vaadin/sass/internal/parser/LocatorImpl.java View File

@@ -23,8 +23,13 @@
*/
package com.vaadin.sass.internal.parser;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.Locator;

import com.vaadin.sass.internal.handler.SCSSDocumentHandlerImpl;

/**
* @version $Revision: 1.2 $
* @author Philippe Le Hegaret
@@ -51,14 +56,17 @@ public class LocatorImpl implements Locator {
int line;
int column;

@Override
public String getURI() {
return uri;
}

@Override
public int getLineNumber() {
return line;
}

@Override
public int getColumnNumber() {
return column;
}
@@ -68,7 +76,7 @@ public class LocatorImpl implements Locator {
*/
public LocatorImpl(Parser p) {
if (W3CDebug) {
System.err.println("LocatorImpl::newLocator(" + p + ");");
log("LocatorImpl::newLocator(" + p + ");");
}
uri = p.source.getURI();
line = p.token.beginLine;
@@ -80,8 +88,7 @@ public class LocatorImpl implements Locator {
*/
public LocatorImpl(Parser p, Token tok) {
if (W3CDebug) {
System.err.println("LocatorImpl::newLocator(" + p + ", " + tok
+ ");");
log("LocatorImpl::newLocator(" + p + ", " + tok + ");");
}
uri = p.source.getURI();
line = tok.beginLine;
@@ -93,8 +100,8 @@ public class LocatorImpl implements Locator {
*/
public LocatorImpl(Parser p, int line, int column) {
if (W3CDebug) {
System.err.println("LocatorImpl::newLocator(" + p + ", " + line
+ ", " + column + ");");
log("LocatorImpl::newLocator(" + p + ", " + line + ", " + column
+ ");");
}
uri = p.source.getURI();
this.line = line;
@@ -106,7 +113,7 @@ public class LocatorImpl implements Locator {
*/
public LocatorImpl reInit(Parser p) {
if (W3CDebug) {
System.err.println("LocatorImpl::reInit(" + p + ");");
log("LocatorImpl::reInit(" + p + ");");
}
uri = p.source.getURI();
line = p.token.beginLine;
@@ -119,7 +126,7 @@ public class LocatorImpl implements Locator {
*/
public LocatorImpl reInit(Parser p, Token tok) {
if (W3CDebug) {
System.err.println("LocatorImpl::reInit(" + p + ", " + tok + ");");
log("LocatorImpl::reInit(" + p + ", " + tok + ");");
}
uri = p.source.getURI();
line = tok.beginLine;
@@ -132,12 +139,16 @@ public class LocatorImpl implements Locator {
*/
public LocatorImpl reInit(Parser p, int line, int column) {
if (W3CDebug) {
System.err.println("LocatorImpl::reInit(" + p + ", " + line + ", "
+ column + ");");
log("LocatorImpl::reInit(" + p + ", " + line + ", " + column + ");");
}
uri = p.source.getURI();
this.line = line;
this.column = column;
return this;
}

private void log(String msg) {
Logger.getLogger(SCSSDocumentHandlerImpl.class.getName()).log(
Level.SEVERE, msg);
}
}

+ 5
- 3
theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java View File

@@ -22,6 +22,8 @@ import java.util.ArrayList;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.ConditionFactory;
import org.w3c.css.sac.Condition;
@@ -1203,7 +1205,7 @@ public class Parser implements org.w3c.css.sac.Parser, ParserConstants {

} finally {
if (start) {
documentHandler.endMedia(ml);
documentHandler.endMedia(ml);
}
}
}
@@ -4527,7 +4529,7 @@ boolean isPseudoElement = false;
jj_consume_token(DEBUG_SYM);
String content = skipStatementUntilSemiColon();
// TODO should evaluate the content expression, call documentHandler.debugDirective() etc.
System.out.println(content);
Logger.getLogger(Parser.class.getName()).log(Level.INFO, content);
label_138:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -4546,7 +4548,7 @@ boolean isPseudoElement = false;
jj_consume_token(WARN_SYM);
String content = skipStatementUntilSemiColon();
// TODO should evaluate the content expression, call documentHandler.warnDirective() etc.
System.err.println(content);
Logger.getLogger(Parser.class.getName()).log(Level.SEVERE, content);
label_139:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {

+ 4
- 2
theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj View File

@@ -40,6 +40,8 @@ import java.util.ArrayList;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.ConditionFactory;
import org.w3c.css.sac.Condition;
@@ -1937,7 +1939,7 @@ void debugDirective() :
{
String content = skipStatementUntilSemiColon();
// TODO should evaluate the content expression, call documentHandler.debugDirective() etc.
System.out.println(content);
Logger.getLogger(Parser.class.getName()).log(Level.INFO, content);
}
(<S>)*
}
@@ -1949,7 +1951,7 @@ void warnDirective() :
{
String content = skipStatementUntilSemiColon();
// TODO should evaluate the content expression, call documentHandler.warnDirective() etc.
System.err.println(content);
Logger.getLogger(Parser.class.getName()).log(Level.SEVERE, content);
}
(<S>)*
}

+ 2
- 0
theme-compiler/src/com/vaadin/sass/internal/parser/ParserTokenManager.java View File

@@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.css.sac.ConditionFactory;
import org.w3c.css.sac.Condition;
import org.w3c.css.sac.SelectorFactory;

+ 10
- 3
theme-compiler/src/com/vaadin/sass/internal/selector/SelectorUtil.java View File

@@ -16,6 +16,9 @@

package com.vaadin.sass.internal.selector;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.CombinatorCondition;
import org.w3c.css.sac.Condition;
import org.w3c.css.sac.ConditionFactory;
@@ -115,7 +118,7 @@ public class SelectorUtil {
} else if (selector.getSelectorType() == CompositeSelector.SCSS_COMPOSITE_SELECTOR) {
return toString((CompositeSelector) selector);
} else {
System.out.println("SU !Unknown selector type, type: "
log("SU !Unknown selector type, type: "
+ selector.getSelectorType() + ", " + selector.toString());
}
return "";
@@ -162,8 +165,8 @@ public class SelectorUtil {
PseudoClassConditionImpl pseudoClassCondition = (PseudoClassConditionImpl) condition;
return ":" + pseudoClassCondition.getValue();
} else {
System.out.println("CU !condition type not identified, type: "
+ conditionType + ", " + condition.toString());
log("CU !condition type not identified, type: " + conditionType
+ ", " + condition.toString());
return "";
}
}
@@ -330,4 +333,8 @@ public class SelectorUtil {
throw new Exception("Invalid selector type");
}
}

private static void log(String msg) {
Logger.getLogger(SelectorUtil.class.getName()).log(Level.INFO, msg);
}
}

+ 4
- 1
theme-compiler/src/com/vaadin/sass/internal/tree/BlockNode.java View File

@@ -17,6 +17,8 @@
package com.vaadin.sass.internal.tree;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.visitor.BlockNodeHandler;
@@ -109,7 +111,8 @@ public class BlockNode extends Node implements IVariableNode {
BlockNodeHandler.traverse(this);
replaceVariables(ScssStylesheet.getVariables());
} catch (Exception e) {
e.printStackTrace();
Logger.getLogger(BlockNode.class.getName()).log(Level.SEVERE, null,
e);
}
}


+ 4
- 1
theme-compiler/src/com/vaadin/sass/internal/tree/ExtendNode.java View File

@@ -17,6 +17,8 @@
package com.vaadin.sass.internal.tree;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.vaadin.sass.internal.visitor.ExtendNodeHandler;

@@ -54,7 +56,8 @@ public class ExtendNode extends Node implements IVariableNode {
ExtendNodeHandler.traverse(this);
getParentNode().removeChild(this);
} catch (Exception e) {
e.printStackTrace();
Logger.getLogger(ExtendNode.class.getName()).log(Level.SEVERE,
null, e);
}
}
}

+ 4
- 1
theme-compiler/src/com/vaadin/sass/internal/tree/MixinNode.java View File

@@ -19,6 +19,8 @@ package com.vaadin.sass.internal.tree;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;
@@ -119,7 +121,8 @@ public class MixinNode extends Node implements IVariableNode {
ScssStylesheet.closeVariableScope(variableScope);

} catch (Exception e) {
e.printStackTrace();
Logger.getLogger(MixinNode.class.getName()).log(Level.SEVERE, null,
e);
}
}


+ 5
- 1
theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/IfElseDefNode.java View File

@@ -15,6 +15,9 @@
*/
package com.vaadin.sass.internal.tree.controldirective;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.vaadin.sass.internal.tree.Node;
import com.vaadin.sass.internal.visitor.IfElseNodeHandler;

@@ -40,7 +43,8 @@ public class IfElseDefNode extends Node {

IfElseNodeHandler.traverse(this);
} catch (Exception e) {
e.printStackTrace();
Logger.getLogger(IfElseDefNode.class.getName()).log(Level.SEVERE,
null, e);
}
}


+ 9
- 3
theme-compiler/src/com/vaadin/sass/internal/util/DeepCopy.java View File

@@ -22,13 +22,15 @@ import java.io.ObjectOutputStream;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Utility for making deep copies (vs. clone()'s shallow copies) of objects.
* Objects are first serialized and then deserialized. Error checking is fairly
* minimal in this implementation. If an object is encountered that cannot be
* serialized (or that references an object that cannot be serialized) an error
* is printed to System.err and null is returned. Depending on your specific
* is printed to the logger and null is returned. Depending on your specific
* application, it might make more sense to have copy(...) re-throw the
* exception.
*/
@@ -56,9 +58,9 @@ public class DeepCopy {
obj = in.readObject();
in.close();
} catch (IOException e) {
e.printStackTrace();
log(e);
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
log(cnfe);
}
return obj;
} else {
@@ -80,4 +82,8 @@ public class DeepCopy {
}
return copies;
}

private static void log(Throwable e) {
Logger.getLogger(DeepCopy.class.getName()).log(Level.SEVERE, null, e);
}
}

+ 6
- 2
theme-compiler/src/com/vaadin/sass/internal/visitor/ImportNodeHandler.java View File

@@ -19,6 +19,8 @@ package com.vaadin.sass.internal.visitor;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.LexicalUnit;
@@ -78,9 +80,11 @@ public class ImportNodeHandler {
importNode);
node.removeChild(importNode);
} catch (CSSException e) {
e.printStackTrace();
Logger.getLogger(ImportNodeHandler.class.getName())
.log(Level.SEVERE, null, e);
} catch (IOException e) {
e.printStackTrace();
Logger.getLogger(ImportNodeHandler.class.getName())
.log(Level.SEVERE, null, e);
}
} else {
if (styleSheet != node) {

+ 2
- 0
theme-compiler/src/logging.properties View File

@@ -0,0 +1,2 @@
handlers = com.vaadin.sass.CustomConsoleHandler
.level = ALL

Loading…
Cancel
Save