Package scala_maven

Class ScalaConsoleMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
scala_maven.ScalaMojoSupport
scala_maven.ScalaConsoleMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

@Mojo(name="console", requiresDependencyResolution=TEST, inheritByDefault=false, requiresDirectInvocation=true, executionStrategy="once-per-session") public class ScalaConsoleMojo extends ScalaMojoSupport
Run the Scala console with all the classes of the projects (dependencies and builded)
  • Field Details

    • JLINE

      private static final String JLINE
      Constant String for "jline". Used for the artifact id, and usually the group id, for the JLine library needed by the Scala Console.
      See Also:
    • SCALA_ORG_GROUP

      private static final String SCALA_ORG_GROUP
      Constant String for "org.scala-lang". In this class it is used for the forked JLine group id.
      See Also:
    • mainConsole

      @Parameter(property="mainConsole", defaultValue="scala.tools.nsc.MainGenericRunner", required=true) protected String mainConsole
      The console to run.
    • useTestClasspath

      @Parameter(property="maven.scala.console.useTestClasspath", defaultValue="true", required=true) protected boolean useTestClasspath
      Add the test classpath (include classes from test directory), to the console's classpath ?
    • useRuntimeClasspath

      @Parameter(property="maven.scala.console.useRuntimeClasspath", defaultValue="true", required=true) protected boolean useRuntimeClasspath
      Add the runtime classpath, to the console's classpath ?
    • javaRebelPath

      @Parameter(property="javarebel.jar.path") protected File javaRebelPath
      Path of the javaRebel jar. If this option is set then the console run with javarebel enabled.
  • Constructor Details

    • ScalaConsoleMojo

      public ScalaConsoleMojo()
  • Method Details

    • doExecute

      protected void doExecute() throws Exception
      Specified by:
      doExecute in class ScalaMojoSupport
      Throws:
      Exception
    • handleJavaRebel

      private void handleJavaRebel(JavaMainCaller jcmd) throws IOException
      If javaRebelPath is defined, then attempt to resolve it on the filesystem and setup the Scala console to use it.

      If we are unable to find it or javaRebelPath is null, then nothing is done to the given JavaMainCaller.

      Parameters:
      jcmd - the JavaMainCaller to which to add the JRebel settings.
      Throws:
      IOException
    • setupClassPathForConsole

      private Set<String> setupClassPathForConsole(VersionNumber scalaVersion) throws Exception
      Construct the appropriate Classpath for the Scala console.
      Parameters:
      scalaVersion - the VersionNumber for the Scala Compiler/Library we are using.
      Returns:
      A Set of String defining classpath values to provide to the Scala console.
      Throws:
      Exception
    • setupProjectClasspaths

      private Set<String> setupProjectClasspaths() throws Exception
      Construct the Classpath defined by the project and plugin settings.

      This should include the following entities.

      Returns:
      A Set of String defining the classpath for the project and plugin settings.
      Throws:
      Exception
    • setupConsoleClasspaths

      private Set<String> setupConsoleClasspaths(VersionNumber scalaVersion) throws Exception
      Construct the Classpath for any additional dependencies that are needed to run the Scala console.

      This should include the following entities.

      • Jline, used for readline like features in the REPL.
      Parameters:
      scalaVersion - the version of the Scala Compiler/Library we are using for this execution.
      Returns:
      A Set of String of the classpath as defined by
      Throws:
      Exception
    • resolveJLine

      private org.apache.maven.artifact.Artifact resolveJLine(VersionNumber scalaVersion, org.apache.maven.artifact.Artifact defaultFallback) throws Exception
      Attempt to resolve JLine against the Scala Compiler's dependency tree.

      This allows us to not have to worry about manually keeping the JLine dependency synchronized with the Scala REPL, which is likely to cause binary compatibility errors. If, for some reason, we are unable to resolve this dependency using the Compiler's dependency tree, we fallback to a set of hard-coded defaults that will usually work, but will not always work.

      If the dynamic approach to finding the JLine dependency proves stable, we may drop the fallback in the future.

      Parameters:
      scalaVersion - the version of the Scala Compiler/Library we are using for this execution.
      defaultFallback - returned if we are unable to resolve JLine against the Scala Compiler's dependency tree.
      Returns:
      an Artifact to provide to the runtime of the Scala console conforming the JLine.
      Throws:
      Exception
    • filterForJline

      private boolean filterForJline(org.apache.maven.artifact.Artifact artifact)
      Helper function to filter a collection of Artifact for JLine.

      Since different versions of the Scala Compiler were using different artifacts for JLine, things are a bit tricky here. Any Artifact to have an artifact id equal to "jline" and a group id equal to either "jline" or "org.scala-lang" will yield true. The latter group id corresponds to a fork of JLine that is not being used anymore.

      Parameters:
      artifact - the Artifact to check to see if it is viable JLine candidate.
    • fallbackJLine

      private org.apache.maven.artifact.Artifact fallbackJLine(VersionNumber scalaVersion)
      Hard coded fallback values for JLine. This used to be the only way we resolve JLine, but required manually upkeep to avoid binary comparability errors.

      You should favor resolveJLine(scala_maven.VersionNumber, org.apache.maven.artifact.Artifact) only using this for a fallback default.

      Current mapping is as follows.

      • Scala 2.12.0-M4 and after, jline:jline:2.14.1:jar
      • After Scala 2.11.0 through Scala 2.12.0-M3, jline:jline:2.12:jar
      • After Scala 2.9.0 before Scala 2.11.0, org.scala-lang:jline:SCALA-VERSION:jar
      • Before Scala 2.9.0, jline:jline:0.9.94:jar
      Parameters:
      scalaVersion - the version of the Scala Compiler/Library we are using for this execution.
      Returns:
      a fallback Artifact which we hope will work with the Scala REPL.