[Japi-cvs] SF.net SVN: japi:[1405] tools/archStat/trunk/src/prj/net/sf/japi/archstat
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2010-04-11 11:06:54
|
Revision: 1405 http://japi.svn.sourceforge.net/japi/?rev=1405&view=rev Author: christianhujer Date: 2010-04-11 11:06:48 +0000 (Sun, 11 Apr 2010) Log Message: ----------- Move the logging classes to a package of their own. Modified Paths: -------------- tools/archStat/trunk/src/prj/net/sf/japi/archstat/RegexLineCheck.java Added Paths: ----------- tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/ tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/LogEntry.java tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/LogSystem.java tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/Logger.java tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/StreamLogger.java Removed Paths: ------------- tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogEntry.java tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java tools/archStat/trunk/src/prj/net/sf/japi/archstat/Logger.java tools/archStat/trunk/src/prj/net/sf/japi/archstat/StreamLogger.java Deleted: tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogEntry.java =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogEntry.java 2010-04-11 10:44:37 UTC (rev 1404) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogEntry.java 2010-04-11 11:06:48 UTC (rev 1405) @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2009 Christian Hujer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sf.japi.archstat; - -import java.io.File; -import java.util.Formatter; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** A LogEntry represents an atomic ArchStat information. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @since 0.1 - */ -public class LogEntry { - - /** The File for which this LogEntry is being logged. */ - private final File file; - - /** The line in {@link #file} for which this LogEntry is being logged. - * Maybe <code>null</code> if the LogEntry does not apply to a particular line. - */ - @Nullable private final String line; - - /** The lineNumber in {@link #file} for which this LogEntry is being logged. - * Maybe <code>null</code> if the LogEntry does not apply to a particular lineNumber. - * The line number is the user line, the first line is 1. - */ - @Nullable private final Integer lineNumber; - - /** The column in {@link #file} {@link #lineNumber} for which this LogEntry is being logged. - * Maybe <code>null</code> if the LogEntry does not apply to a particular column. - * The column is the user column, the first column is 1. - */ - @Nullable private final Integer column; - - /** The MessageType for this LogEntry. */ - @NotNull private final MessageType messageType; - - /** The message ID of this type of log entry. */ - @NotNull private final String messageId; - - /** The message of this log entry. */ - @NotNull private final String message; - - /** Creates a LogEntry. - * @param file File for which this LogEntry is being logged. - * @param line Line in <var>file</var> or <code>null</code>. - * @param lineNumber Line number in <var>file</var> or <code>null</code> (user line, first line is 1). - * @param column Column in <var>lineNumber</var> or <code>null</code> (user column, first column is 1). - * @param messageType Message Type. - * @param messageId Message ID. - * @param message The message. - */ - public LogEntry(final File file, @Nullable final String line, @Nullable final Integer lineNumber, @Nullable final Integer column, @NotNull final MessageType messageType, @NotNull final String messageId, @NotNull final String message) { - this.file = file; - this.line = removeEOL(line); - this.lineNumber = lineNumber; - this.column = column; - this.messageType = messageType; - this.messageId = messageId; - this.message = message; - } - - /** Returns a String with any trailing end of line characters removed. - * Trailing whitespace other than EOL characters are not removed. - * This method currently treats LF and CR as EOL characters. - * @param line Line from which to remove trailing end of line characters, maybe <code>null</code> - * @return The line with trailing end of line characters removed. - */ - private static String removeEOL(@Nullable final String line) { - if (line != null) { - return line.replaceAll("[\n\r]+$", ""); - } - return line; - } - - /** Creates a LogEntry. - * @param file File for which this LogEntry is being logged. - * @param messageType Message Type. - * @param messageId Message ID. - * @param message The message. - */ - public LogEntry(final File file, @NotNull final MessageType messageType, @NotNull final String messageId, @NotNull final String message) { - this(file, null, null, null, messageType, messageId, message); - } - - /** Returns the file for which this LogEntry was created. - * @return The file for which this LogEntry was created. - */ - public File getFile() { - return file; - } - - /** Returns the lineNumber for which this LogEntry was created. - * @return The lineNumber number or <code>null</code> in case it's not applicable. - */ - @Nullable public Integer getLineNumber() { - return lineNumber; - } - - /** Returns the column for which this LogEntry was created. - * @return The column number or <code>null</code> in case it's not applicable. - */ - @Nullable public Integer getColumn() { - return column; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return toString(new Formatter()).toString(); - } - - /** Formats this LogEntry to the specified formatter. - * @param out Formatter to log to. - * @return <var>out</var> for convenience. - */ - public Formatter toString(@NotNull final Formatter out) { - if (lineNumber != null && column != null) { - out.format("%s:%s:%s: %s: (%s): %s", file, lineNumber, column, messageType, messageId, message); - if (line != null) { - out.format("%n%s%n", line); - for (int i = 1; i < column; i++) { - out.format("-"); - } - out.format("^%n"); - } - } else if (lineNumber != null) { - out.format("%s:%s: %s: (%s): %s", file, lineNumber, messageType, messageId, message); - } else { - out.format("%s: %s: (%s): %s", file, messageType, messageId, message); - } - return out; - } -} Deleted: tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java 2010-04-11 10:44:37 UTC (rev 1404) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java 2010-04-11 11:06:48 UTC (rev 1405) @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2009 Christian Hujer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sf.japi.archstat; - -import org.jetbrains.annotations.NotNull; - -/** Static access to logging. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @since 0.1 - */ -public final class LogSystem { - - /** The loggers. */ - private static final Logger[] LOGGERS = { new StreamLogger(System.err) }; - - /** Utility class - do not instanciate. */ - private LogSystem() { - } - - /** Logs a single log entry. - * @param logEntry LogEntry to log. - */ - public static void log(@NotNull final LogEntry logEntry) { - for (final Logger logger : LOGGERS) { - logger.log(logEntry); - } - } -} Deleted: tools/archStat/trunk/src/prj/net/sf/japi/archstat/Logger.java =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/Logger.java 2010-04-11 10:44:37 UTC (rev 1404) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/Logger.java 2010-04-11 11:06:48 UTC (rev 1405) @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2009 Christian Hujer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sf.japi.archstat; - -import org.jetbrains.annotations.NotNull; - -/** Loggers log LogEntries. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @since 0.1 - */ -public interface Logger { - - /** Logs a LogEntry. - * @param logEntry LogEntry to log. - */ - void log(@NotNull LogEntry logEntry); -} Modified: tools/archStat/trunk/src/prj/net/sf/japi/archstat/RegexLineCheck.java =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/RegexLineCheck.java 2010-04-11 10:44:37 UTC (rev 1404) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/RegexLineCheck.java 2010-04-11 11:06:48 UTC (rev 1405) @@ -23,6 +23,8 @@ import org.w3c.dom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import net.sf.japi.archstat.log.LogEntry; +import net.sf.japi.archstat.log.LogSystem; /** A Line-based Check. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> Deleted: tools/archStat/trunk/src/prj/net/sf/japi/archstat/StreamLogger.java =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/StreamLogger.java 2010-04-11 10:44:37 UTC (rev 1404) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/StreamLogger.java 2010-04-11 11:06:48 UTC (rev 1405) @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2009 Christian Hujer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sf.japi.archstat; - -import java.util.Formatter; -import org.jetbrains.annotations.NotNull; - -/** The StreamLogger is a Logger for LogEntries that logs to the specified Stream. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @since 0.1 - */ -public class StreamLogger implements Logger { - - /** The Stream for logging. */ - @NotNull - private final Formatter out; - - /** Creates a StreamLogger. - * @param out Stream for logging. - */ - public StreamLogger(@NotNull final Appendable out) { - this.out = new Formatter(out); - } - - /** {@inheritDoc} */ - public void log(@NotNull final LogEntry logEntry) { - out.format("%s%n", logEntry); - } -} Copied: tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/LogEntry.java (from rev 1404, tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogEntry.java) =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/LogEntry.java (rev 0) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/LogEntry.java 2010-04-11 11:06:48 UTC (rev 1405) @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2009 - 2010 Christian Hujer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.archstat.log; + +import java.io.File; +import java.util.Formatter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import net.sf.japi.archstat.MessageType; + +/** A LogEntry represents an atomic ArchStat information. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class LogEntry { + + /** The File for which this LogEntry is being logged. */ + private final File file; + + /** The line in {@link #file} for which this LogEntry is being logged. + * Maybe <code>null</code> if the LogEntry does not apply to a particular line. + */ + @Nullable private final String line; + + /** The lineNumber in {@link #file} for which this LogEntry is being logged. + * Maybe <code>null</code> if the LogEntry does not apply to a particular lineNumber. + * The line number is the user line, the first line is 1. + */ + @Nullable private final Integer lineNumber; + + /** The column in {@link #file} {@link #lineNumber} for which this LogEntry is being logged. + * Maybe <code>null</code> if the LogEntry does not apply to a particular column. + * The column is the user column, the first column is 1. + */ + @Nullable private final Integer column; + + /** The MessageType for this LogEntry. */ + @NotNull private final MessageType messageType; + + /** The message ID of this type of log entry. */ + @NotNull private final String messageId; + + /** The message of this log entry. */ + @NotNull private final String message; + + /** Creates a LogEntry. + * @param file File for which this LogEntry is being logged. + * @param line Line in <var>file</var> or <code>null</code>. + * @param lineNumber Line number in <var>file</var> or <code>null</code> (user line, first line is 1). + * @param column Column in <var>lineNumber</var> or <code>null</code> (user column, first column is 1). + * @param messageType Message Type. + * @param messageId Message ID. + * @param message The message. + */ + public LogEntry(final File file, @Nullable final String line, @Nullable final Integer lineNumber, @Nullable final Integer column, @NotNull final MessageType messageType, @NotNull final String messageId, @NotNull final String message) { + this.file = file; + this.line = removeEOL(line); + this.lineNumber = lineNumber; + this.column = column; + this.messageType = messageType; + this.messageId = messageId; + this.message = message; + } + + /** Returns a String with any trailing end of line characters removed. + * Trailing whitespace other than EOL characters are not removed. + * This method currently treats LF and CR as EOL characters. + * @param line Line from which to remove trailing end of line characters, maybe <code>null</code> + * @return The line with trailing end of line characters removed. + */ + private static String removeEOL(@Nullable final String line) { + if (line != null) { + return line.replaceAll("[\n\r]+$", ""); + } + return line; + } + + /** Creates a LogEntry. + * @param file File for which this LogEntry is being logged. + * @param messageType Message Type. + * @param messageId Message ID. + * @param message The message. + */ + public LogEntry(final File file, @NotNull final MessageType messageType, @NotNull final String messageId, @NotNull final String message) { + this(file, null, null, null, messageType, messageId, message); + } + + /** Returns the file for which this LogEntry was created. + * @return The file for which this LogEntry was created. + */ + public File getFile() { + return file; + } + + /** Returns the lineNumber for which this LogEntry was created. + * @return The lineNumber number or <code>null</code> in case it's not applicable. + */ + @Nullable public Integer getLineNumber() { + return lineNumber; + } + + /** Returns the column for which this LogEntry was created. + * @return The column number or <code>null</code> in case it's not applicable. + */ + @Nullable public Integer getColumn() { + return column; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return toString(new Formatter()).toString(); + } + + /** Formats this LogEntry to the specified formatter. + * @param out Formatter to log to. + * @return <var>out</var> for convenience. + */ + public Formatter toString(@NotNull final Formatter out) { + if (lineNumber != null && column != null) { + out.format("%s:%s:%s: %s: (%s): %s", file, lineNumber, column, messageType, messageId, message); + if (line != null) { + out.format("%n%s%n", line); + for (int i = 1; i < column; i++) { + out.format("-"); + } + out.format("^%n"); + } + } else if (lineNumber != null) { + out.format("%s:%s: %s: (%s): %s", file, lineNumber, messageType, messageId, message); + } else { + out.format("%s: %s: (%s): %s", file, messageType, messageId, message); + } + return out; + } +} Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/LogEntry.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Copied: tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/LogSystem.java (from rev 1404, tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java) =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/LogSystem.java (rev 0) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/LogSystem.java 2010-04-11 11:06:48 UTC (rev 1405) @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2009 - 2010 Christian Hujer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.archstat.log; + +import org.jetbrains.annotations.NotNull; + +/** Static access to logging. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public final class LogSystem { + + /** The loggers. */ + private static final Logger[] LOGGERS = { new StreamLogger(System.err) }; + + /** Utility class - do not instanciate. */ + private LogSystem() { + } + + /** Logs a single log entry. + * @param logEntry LogEntry to log. + */ + public static void log(@NotNull final LogEntry logEntry) { + for (final Logger logger : LOGGERS) { + logger.log(logEntry); + } + } +} Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/LogSystem.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Copied: tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/Logger.java (from rev 1404, tools/archStat/trunk/src/prj/net/sf/japi/archstat/Logger.java) =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/Logger.java (rev 0) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/Logger.java 2010-04-11 11:06:48 UTC (rev 1405) @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2009 - 2010 Christian Hujer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.archstat.log; + +import org.jetbrains.annotations.NotNull; + +/** Loggers log LogEntries. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public interface Logger { + + /** Logs a LogEntry. + * @param logEntry LogEntry to log. + */ + void log(@NotNull LogEntry logEntry); +} Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/Logger.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Copied: tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/StreamLogger.java (from rev 1404, tools/archStat/trunk/src/prj/net/sf/japi/archstat/StreamLogger.java) =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/StreamLogger.java (rev 0) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/StreamLogger.java 2010-04-11 11:06:48 UTC (rev 1405) @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2009 - 2010 Christian Hujer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.archstat.log; + +import java.util.Formatter; +import org.jetbrains.annotations.NotNull; + +/** The StreamLogger is a Logger for LogEntries that logs to the specified Stream. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class StreamLogger implements Logger { + + /** The Stream for logging. */ + @NotNull + private final Formatter out; + + /** Creates a StreamLogger. + * @param out Stream for logging. + */ + public StreamLogger(@NotNull final Appendable out) { + this.out = new Formatter(out); + } + + /** {@inheritDoc} */ + public void log(@NotNull final LogEntry logEntry) { + out.format("%s%n", logEntry); + } +} Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/log/StreamLogger.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |