Class ScalaConsoleMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FilePath of the javaRebel jar.private static final StringConstantStringfor "jline".protected StringThe console to run.private static final StringConstantStringfor "org.scala-lang".protected booleanAdd the runtime classpath, to the console's classpath ?protected booleanAdd 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, useCanonicalPathFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprivate org.apache.maven.artifact.ArtifactfallbackJLine(VersionNumber scalaVersion) Hard coded fallback values for JLine.private booleanfilterForJline(org.apache.maven.artifact.Artifact artifact) Helper function to filter a collection ofArtifactfor JLine.private voidIfjavaRebelPathis defined, then attempt to resolve it on the filesystem and setup the Scala console to use it.private org.apache.maven.artifact.ArtifactresolveJLine(VersionNumber scalaVersion, org.apache.maven.artifact.Artifact defaultFallback) Attempt to resolve JLine against the Scala Compiler's dependency tree.setupClassPathForConsole(VersionNumber scalaVersion) Construct the appropriate Classpath for the Scala console.setupConsoleClasspaths(VersionNumber scalaVersion) Construct the Classpath for any additional dependencies that are needed to run the Scala console.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, scalaCompilerArtifactMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
JLINE
ConstantStringfor "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
ConstantStringfor "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 mainConsoleThe console to run. -
useTestClasspath
@Parameter(property="maven.scala.console.useTestClasspath", defaultValue="true", required=true) protected boolean useTestClasspathAdd 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 useRuntimeClasspathAdd the runtime classpath, to the console's classpath ? -
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
- Specified by:
doExecutein classScalaMojoSupport- Throws:
Exception
-
handleJavaRebel
IfjavaRebelPathis 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
javaRebelPathisnull, then nothing is done to the givenJavaMainCaller.- Parameters:
jcmd- theJavaMainCallerto which to add the JRebel settings.- Throws:
IOException
-
setupClassPathForConsole
Construct the appropriate Classpath for the Scala console.- Parameters:
scalaVersion- theVersionNumberfor the Scala Compiler/Library we are using.- Returns:
- A
SetofStringdefining classpath values to provide to the Scala console. - Throws:
Exception
-
setupProjectClasspaths
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
useTestClasspathistrue. - Runtime Classpath, if
useRuntimeClasspathistrue.
- Scala Compiler, as defined by
-
setupConsoleClasspaths
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.
-
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
Artifactto 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 ofArtifactfor JLine.Since different versions of the Scala Compiler were using different artifacts for JLine, things are a bit tricky here. Any
Artifactto 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- theArtifactto check to see if it is viable JLine candidate.
-
fallbackJLine
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
Artifactwhich we hope will work with the Scala REPL.
-