Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions cli/src/main/scala/scalaxb/compiler/Log.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,56 @@
*/
package scalaxb.compiler

import org.apache.log4j.{Logger, Level, ConsoleAppender, EnhancedPatternLayout}
import org.apache.log4j.spi.LoggingEvent
import org.apache.logging.log4j.{Logger, LogManager, Level}
import org.apache.logging.log4j.core.appender.ConsoleAppender
import org.apache.logging.log4j.core.layout.{PatternLayout, AbstractStringLayout}
import org.apache.logging.log4j.core.LogEvent

case class Log(logger: Logger) {
def info(message: String, args: Any*): Unit = {
if (args.toSeq.isEmpty) logger.info(message)
if (args.isEmpty) logger.info(message)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you split refactoring into another PR plz?

else try {
logger.info(message.format(args.toSeq: _*))
logger.info(message.format(args: _*))
}
catch {
case _: Throwable => logger.info(message)
}
}

def debug(message: String, args: Any*): Unit = {
if (args.toSeq.isEmpty) logger.debug(message)
if (args.isEmpty) logger.debug(message)
else try {
logger.debug(message.format(args.toSeq: _*))
logger.debug(message.format(args: _*))
}
catch {
case _: Throwable => logger.debug(message)
}
}

def warn(message: String, args: Any*): Unit = {
if (args.toSeq.isEmpty) logger.warn(message)
if (args.isEmpty) logger.warn(message)
else try {
logger.warn(message.format(args.toSeq: _*))
logger.warn(message.format(args: _*))
}
catch {
case _: Throwable => logger.warn(message)
}
}

def error(message: String, args: Any*): Unit = {
if (args.toSeq.isEmpty) logger.error(message)
if (args.isEmpty) logger.error(message)
else try {
logger.error(message.format(args.toSeq: _*))
logger.error(message.format(args: _*))
}
catch {
case _: Throwable => logger.error(message)
}
}

def fatal(message: String, args: Any*): Unit = {
if (args.toSeq.isEmpty) logger.fatal(message)
if (args.isEmpty) logger.fatal(message)
else try {
logger.fatal(message.format(args.toSeq: _*))
logger.fatal(message.format(args: _*))
}
catch {
case _: Throwable => logger.fatal(message)
Expand All @@ -77,40 +79,41 @@ case class Log(logger: Logger) {
}

object Log {
def forName(name: String) = Log(Logger.getLogger(name))
def forName(name: String) = Log(LogManager.getLogger(name))

def configureLogger(verbose: Boolean): Unit = {
val root = Logger.getRootLogger()
val root = LogManager.getRootLogger.asInstanceOf[org.apache.logging.log4j.core.Logger]
val level = if (verbose) Level.TRACE else Level.WARN
root.setLevel(level)

val console = new ConsoleAppender(new Formatter)
val threshold = if (verbose) Level.TRACE else Level.INFO
console.setThreshold(threshold)
val console = ConsoleAppender
.createDefaultAppenderForLayout(new Formatter())

console.start()
root.addAppender(console)
}

/**
* Formats log messages. Prepends a '!' to each line of an exception.
*/
class Formatter extends EnhancedPatternLayout("%-5p [%d] %c: %m\n") {

override def ignoresThrowable = false
class Formatter extends AbstractStringLayout(PatternLayout.createDefaultLayout().getCharset) {

override def format(event: LoggingEvent) : String = {
val message = super.format(event)
val frames = event.getThrowableStrRep()
if (frames == null) {
override def toSerializable(event: LogEvent): String = {
val message = event.getMessage.getFormattedMessage
val throwable = event.getThrown
if (throwable == null) {
message
} else {
val msg = new StringBuilder(message)
for (line <- frames) {
msg.append("! ").append(line).append("\n")
for (line <- throwable.getStackTrace) {
msg.append("! ").append(line.toString).append("\n")
}
msg.toString
}
}

override def toByteArray(event: LogEvent): Array[Byte] = {
toSerializable(event).getBytes(getCharset)
}
}

}
}
4 changes: 2 additions & 2 deletions cli/src/main/scala/scalaxb/compiler/wsdl11/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ class Driver extends Module { driver =>
case (VersionPattern(0, 14, _), style) =>
// Same as 0.13.x
generateDispatchFromResource(style, "/httpclients_dispatch0130", config)
case (VersionPattern(1, 0 | 1, _), style) =>
case (VersionPattern(1, 0 | 1 | 2, _), style) =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we split these fixes to another PR and add a scripted test that's called only for JDK 11+?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure on the 2nd part of writing the scripted test case for JDK 11+ part. Can you guide me on how to achieve it?

// Same as 0.13.x
generateDispatchFromResource(style, "/httpclients_dispatch0130", config)
case (VersionPattern(2, 0 | 2, _), style) =>
case (VersionPattern(2, 0, _), style) =>
// New for 2.0.x
generateDispatchFromResource(style, "/httpclients_dispatch2000", config)
} else Nil) ++
Expand Down
12 changes: 7 additions & 5 deletions project/dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sbt._

object Dependencies {
val scala3 = "3.3.1"
val scala213 = "2.13.12"
val scala213 = "2.13.16"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a separate PR

val scala212 = "2.12.18"

val jaxb = "javax.xml.bind" % "jaxb-api" % "2.3.1"
Expand All @@ -14,10 +14,11 @@ object Dependencies {
"com.github.scopt" %% "scopt" % "4.1.0"
}
}
val log4j = "log4j" % "log4j" % "1.2.17"
val defaultDispatchVersion = "1.0.1"
val log4j = "org.apache.logging.log4j" % "log4j-core" % "2.24.3"
val log4jApi = "org.apache.logging.log4j" %% "log4j-api-scala" % "13.1.0"
val defaultDispatchVersion = "1.2.0"
def dispatch(sv: String) = CrossVersion partialVersion sv match {
case Some((2, x)) if x >= 13 => "org.dispatchhttp" %% "dispatch-core" % "1.1.0"
case Some((2, x)) if x >= 13 => "org.dispatchhttp" %% "dispatch-core" % "1.2.0"
case Some(_) => "org.dispatchhttp" %% "dispatch-core" % "1.0.1"
case x => sys error s"Unexpected Scala version [$sv], with partial version $x"
}
Expand Down Expand Up @@ -65,7 +66,8 @@ object Dependencies {
launcherInterface % "provided",
jaxb % "provided",
scopt(sv),
log4j
log4j,
log4jApi
) ++ (sv match {
case x if sv.startsWith("2.12.") => Seq(scalaXml2, scalaParserCombinators1)
case x => Seq(scalaXml2, scalaParserCombinators2)
Expand Down