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 Summary
Fields Modifier and Type Field Description protected java.io.File
javaRebelPath
Path of the javaRebel jar.private static java.lang.String
JLINE
ConstantString
for "jline".protected java.lang.String
mainConsole
The console to run.private static java.lang.String
SCALA_ORG_GROUP
ConstantString
for "org.scala-lang".protected boolean
useRuntimeClasspath
Add the runtime classpath, to the console's classpath ?protected boolean
useTestClasspath
Add the test classpath (include classes from test directory), to the console's classpath ?-
Fields inherited from class scala_maven.ScalaMojoSupport
addJavacArgs, addScalacArgs, args, checkMultipleScalaVersions, compilerPlugins, dependencies, displayCmd, encoding, factory, failOnMultipleScalaVersions, forceUseArgFile, fork, JAR, javacArgs, javacGenerateDebugSymbols, jvmArgs, localRepo, mavenProjectBuilder, POM, project, reactorProjects, remoteRepos, resolver, SCALA_COMPILER_ARTIFACTID, SCALA_LIBRARY_ARTIFACTID, scalaClassName, session, source, target, toolchainManager, useCanonicalPath
-
-
Constructor Summary
Constructors Constructor Description ScalaConsoleMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doExecute()
private org.apache.maven.artifact.Artifact
fallbackJLine(VersionNumber scalaVersion)
Hard coded fallback values for JLine.private boolean
filterForJline(org.apache.maven.artifact.Artifact artifact)
Helper function to filter a collection ofArtifact
for JLine.private void
handleJavaRebel(JavaMainCaller jcmd)
IfjavaRebelPath
is defined, then attempt to resolve it on the filesystem and setup the Scala console to use it.private org.apache.maven.artifact.Artifact
resolveJLine(VersionNumber scalaVersion, org.apache.maven.artifact.Artifact defaultFallback)
Attempt to resolve JLine against the Scala Compiler's dependency tree.private java.util.Set<java.lang.String>
setupClassPathForConsole(VersionNumber scalaVersion)
Construct the appropriate Classpath for the Scala console.private java.util.Set<java.lang.String>
setupConsoleClasspaths(VersionNumber scalaVersion)
Construct the Classpath for any additional dependencies that are needed to run the Scala console.private java.util.Set<java.lang.String>
setupProjectClasspaths()
Construct the Classpath defined by the project and plugin settings.-
Methods inherited from class scala_maven.ScalaMojoSupport
addCompilerPluginOptions, addCompilerToClasspath, addLibraryToClasspath, addToClasspath, addToClasspath, addToClasspath, addToClasspath, checkScalaVersion, execute, findScalaVersion, findVersionFromDependencies, findVersionFromPluginArtifacts, getAllDependencies, getArtifactJar, getArtifactJar, getCompilerDependencies, getCompilerJar, getCompilerPluginOptions, getDependencies, getEmptyScalaCommand, getEmptyScalaCommand, getJavacOptions, getLibraryJar, getPluginArtifactJar, getPluginArtifactJar, getScalaCommand, getScalaCommand, getScalaOptions, getScalaOrganization, isJavaSupportedByCompiler, resolveArtifactDependencies, resolveDependencyArtifacts, resolveDependencyArtifacts, scalaCompilerArtifact
-
-
-
-
Field Detail
-
JLINE
private static final java.lang.String JLINE
ConstantString
for "jline". Used for the artifact id, and usually the group id, for the JLine library needed by the Scala Console.- See Also:
- Constant Field Values
-
SCALA_ORG_GROUP
private static final java.lang.String SCALA_ORG_GROUP
ConstantString
for "org.scala-lang". In this class it is used for the forked JLine group id.- See Also:
- Constant Field Values
-
mainConsole
@Parameter(property="mainConsole", defaultValue="scala.tools.nsc.MainGenericRunner", required=true) protected java.lang.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 java.io.File javaRebelPath
Path of the javaRebel jar. If this option is set then the console run with javarebel enabled.
-
-
Method Detail
-
doExecute
protected void doExecute() throws java.lang.Exception
- Specified by:
doExecute
in classScalaMojoSupport
- Throws:
java.lang.Exception
-
handleJavaRebel
private void handleJavaRebel(JavaMainCaller jcmd) throws java.io.IOException
IfjavaRebelPath
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
isnull
, then nothing is done to the givenJavaMainCaller
.- Parameters:
jcmd
- theJavaMainCaller
to which to add the JRebel settings.- Throws:
java.io.IOException
-
setupClassPathForConsole
private java.util.Set<java.lang.String> setupClassPathForConsole(VersionNumber scalaVersion) throws java.lang.Exception
Construct the appropriate Classpath for the Scala console.- Parameters:
scalaVersion
- theVersionNumber
for the Scala Compiler/Library we are using.- Returns:
- A
Set
ofString
defining classpath values to provide to the Scala console. - Throws:
java.lang.Exception
-
setupProjectClasspaths
private java.util.Set<java.lang.String> setupProjectClasspaths() throws java.lang.Exception
Construct the Classpath defined by the project and plugin settings.This should include the following entities.
- Scala Compiler, as defined by
ScalaMojoSupport.addCompilerToClasspath(java.util.Set<java.lang.String>)
. - Library Classpath, as defined by
ScalaMojoSupport.addLibraryToClasspath(java.util.Set<java.lang.String>)
. - Test Classpath, if
useTestClasspath
istrue
. - Runtime Classpath, if
useRuntimeClasspath
istrue
.
- Returns:
- A
Set
ofString
defining the classpath for the project and plugin settings. - Throws:
java.lang.Exception
- Scala Compiler, as defined by
-
setupConsoleClasspaths
private java.util.Set<java.lang.String> setupConsoleClasspaths(VersionNumber scalaVersion) throws java.lang.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
ofString
of the classpath as defined by - Throws:
java.lang.Exception
-
resolveJLine
private org.apache.maven.artifact.Artifact resolveJLine(VersionNumber scalaVersion, org.apache.maven.artifact.Artifact defaultFallback) throws java.lang.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:
java.lang.Exception
-
filterForJline
private boolean filterForJline(org.apache.maven.artifact.Artifact artifact)
Helper function to filter a collection ofArtifact
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 yieldtrue
. The latter group id corresponds to a fork of JLine that is not being used anymore.- Parameters:
artifact
- theArtifact
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.
-
-