Package scala_maven
Class ScalaMojoSupport
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- scala_maven.ScalaMojoSupport
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
ScalaConsoleMojo
,ScalaHelpMojo
,ScalaRunMojo
,ScalaScriptMojo
,ScalaSourceMojoSupport
public abstract class ScalaMojoSupport extends org.apache.maven.plugin.AbstractMojo
-
-
Field Summary
Fields Modifier and Type Field Description protected String
addJavacArgs
Alternative method for specifying javac arguments (when using incremental compiler).protected String
addScalacArgs
Additional parameter to use to call the main class.protected String[]
args
compiler additional argumentsprotected boolean
checkMultipleScalaVersions
Check if every dependencies use the same version of scala-library or scala.compat.version.protected BasicArtifact[]
compilerPlugins
Compiler plugin dependencies to use when compiling.protected BasicArtifact[]
dependencies
Additional dependencies/jar to add to classpath to run "scalaClassName" (scope and optional field not supported) ex :boolean
displayCmd
Display the command line called ? (property 'maven.scala.displayCmd' replaced by 'displayCmd')protected String
encoding
The -encoding argument for the Java compiler.protected org.apache.maven.repository.RepositorySystem
factory
Used to look up Artifacts in the remote repository.protected boolean
failOnMultipleScalaVersions
Determines if a detection of multiple scala versions in the dependencies will cause the build to fail.protected boolean
forceUseArgFile
Force the use of an external ArgFile to run any forked process.protected boolean
fork
Forks the execution of scalac into a separate process.protected static String
JAR
ConstantString
for "jar".protected String[]
javacArgs
Arguments for javac (when using incremental compiler).protected boolean
javacGenerateDebugSymbols
Whether to instruct javac to generate debug symbols (when using incremental compiler)protected String[]
jvmArgs
Jvm Arguments.protected org.apache.maven.artifact.repository.ArtifactRepository
localRepo
Location of the local repository.protected org.apache.maven.project.MavenProjectBuilder
mavenProjectBuilder
Artifact factory, needed to download source jars.protected static String
POM
ConstantString
for "pom".protected org.apache.maven.project.MavenProject
project
The maven project.protected List<org.apache.maven.project.MavenProject>
reactorProjects
Contains the full list of projects in the reactor.protected List<org.apache.maven.artifact.repository.ArtifactRepository>
remoteRepos
List of Remote Repositories used by the resolverprotected org.apache.maven.artifact.resolver.ArtifactResolver
resolver
Used to look up Artifacts in the remote repository.static String
SCALA_COMPILER_ARTIFACTID
static String
SCALA_LIBRARY_ARTIFACTID
protected String
scalaClassName
className (FQN) of the scala tool to provide asprotected org.apache.maven.execution.MavenSession
session
The Maven Session Objectprotected String
source
The -source argument for the Java compiler (when using incremental compiler).protected String
target
The -target argument for the Java compiler (when using incremental compiler).protected org.apache.maven.toolchain.ToolchainManager
toolchainManager
The toolchain manager to use.protected boolean
useCanonicalPath
Should use CanonicalPath to normalize path (true => getCanonicalPath, false => getAbsolutePath)
-
Constructor Summary
Constructors Constructor Description ScalaMojoSupport()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addCompilerPluginOptions(JavaMainCaller scalac)
Adds appropriate compiler plugins to the scalac command.protected void
addCompilerToClasspath(Set<String> classpath)
protected void
addLibraryToClasspath(Set<String> classpath)
void
addToClasspath(String groupId, String artifactId, String version, String classifier, Set<String> classpath, boolean addDependencies)
added for classifier support.void
addToClasspath(String groupId, String artifactId, String version, Set<String> classpath)
void
addToClasspath(String groupId, String artifactId, String version, Set<String> classpath, boolean addDependencies)
protected void
addToClasspath(org.apache.maven.artifact.Artifact artifact, Set<String> classpath, boolean addDependencies)
protected void
checkScalaVersion()
protected abstract void
doExecute()
void
execute()
protected VersionNumber
findScalaVersion()
protected String
findVersionFromDependencies(String groupId, String artifactId)
protected String
findVersionFromPluginArtifacts(String groupId, String artifactId)
protected Set<org.apache.maven.artifact.Artifact>
getAllDependencies(String groupId, String artifactId, String version)
protected File
getArtifactJar(String groupId, String artifactId, String version)
protected File
getArtifactJar(String groupId, String artifactId, String version, String classifier)
protected List<File>
getCompilerDependencies()
protected File
getCompilerJar()
protected List<String>
getCompilerPluginOptions()
protected List<org.apache.maven.model.Dependency>
getDependencies()
protected JavaMainCaller
getEmptyScalaCommand(String mainClass)
Get aJavaMainCaller
used invoke a Java process.protected JavaMainCaller
getEmptyScalaCommand(String mainClass, boolean forkOverride)
Get aJavaMainCaller
used invoke a Java process.protected List<String>
getJavacOptions()
protected File
getLibraryJar()
protected File
getPluginArtifactJar(String groupId, String artifactId, String version)
protected File
getPluginArtifactJar(String groupId, String artifactId, String version, String classifier)
protected JavaMainCaller
getScalaCommand()
protected JavaMainCaller
getScalaCommand(boolean forkOverride, String mainClass)
Get aJavaMainCaller
used invoke a Java process.protected List<String>
getScalaOptions()
String
getScalaOrganization()
protected boolean
isJavaSupportedByCompiler()
protected Set<org.apache.maven.artifact.Artifact>
resolveArtifactDependencies(org.apache.maven.artifact.Artifact artifact)
This method resolves all transitive dependencies of an artifact.protected Set<org.apache.maven.artifact.Artifact>
resolveDependencyArtifacts(org.apache.maven.artifact.Artifact artifact, org.apache.maven.artifact.resolver.filter.ArtifactFilter collectionFilter, org.apache.maven.artifact.resolver.filter.ArtifactFilter resolutionFilter)
This method resolves all transitive dependencies of an artifact.protected Set<org.apache.maven.artifact.Artifact>
resolveDependencyArtifacts(org.apache.maven.artifact.Artifact artifact, org.apache.maven.artifact.resolver.filter.ArtifactFilter collectionFilter, org.apache.maven.artifact.resolver.filter.ArtifactFilter resolutionFilter, List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories, org.apache.maven.artifact.repository.ArtifactRepository localRepository)
This method resolves all transitive dependencies of an artifact.protected org.apache.maven.artifact.Artifact
scalaCompilerArtifact(String scalaVersion)
Constructs anArtifact
for Scala Compiler.
-
-
-
Field Detail
-
SCALA_LIBRARY_ARTIFACTID
public static final String SCALA_LIBRARY_ARTIFACTID
- See Also:
- Constant Field Values
-
SCALA_COMPILER_ARTIFACTID
public static final String SCALA_COMPILER_ARTIFACTID
- See Also:
- Constant Field Values
-
POM
protected static final String POM
ConstantString
for "pom". Used to specify the Maven POM artifact type.- See Also:
- Constant Field Values
-
JAR
protected static final String JAR
ConstantString
for "jar". Used to specify the Maven JAR artifact type.- See Also:
- Constant Field Values
-
project
@Parameter(property="project", required=true, readonly=true) protected org.apache.maven.project.MavenProject project
The maven project.
-
session
@Parameter(property="session", required=true, readonly=true) protected org.apache.maven.execution.MavenSession session
The Maven Session Object
-
reactorProjects
@Parameter(defaultValue="${reactorProjects}", readonly=true, required=true) protected List<org.apache.maven.project.MavenProject> reactorProjects
Contains the full list of projects in the reactor.
-
factory
@Component protected org.apache.maven.repository.RepositorySystem factory
Used to look up Artifacts in the remote repository.
-
resolver
@Component protected org.apache.maven.artifact.resolver.ArtifactResolver resolver
Used to look up Artifacts in the remote repository.
-
localRepo
@Parameter(property="localRepository", readonly=true, required=true) protected org.apache.maven.artifact.repository.ArtifactRepository localRepo
Location of the local repository.
-
remoteRepos
@Parameter(property="project.remoteArtifactRepositories", readonly=true, required=true) protected List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepos
List of Remote Repositories used by the resolver
-
dependencies
@Parameter protected BasicArtifact[] dependencies
Additional dependencies/jar to add to classpath to run "scalaClassName" (scope and optional field not supported) ex :<dependencies> <dependency> <groupId>org.scala-tools</groupId> <artifactId>scala-compiler-addon</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>
-
compilerPlugins
@Parameter protected BasicArtifact[] compilerPlugins
Compiler plugin dependencies to use when compiling. ex:<compilerPlugins> <compilerPlugin> <groupId>my.scala.plugin</groupId> <artifactId>amazingPlugin</artifactId> <version>1.0-SNAPSHOT</version> </compilerPlugin> </compilerPlugins>
-
jvmArgs
@Parameter protected String[] jvmArgs
Jvm Arguments.
-
args
@Parameter protected String[] args
compiler additional arguments
-
addScalacArgs
@Parameter(property="addScalacArgs") protected String addScalacArgs
Additional parameter to use to call the main class. Use this parameter only from command line ("-DaddScalacArgs=arg1|arg2|arg3|..."), not from pom.xml. To define compiler arguments in pom.xml see the "args" parameter.
-
scalaClassName
@Parameter(required=true, property="maven.scala.className", defaultValue="scala.tools.nsc.Main") protected String scalaClassName
className (FQN) of the scala tool to provide as
-
javacArgs
@Parameter(property="javacArgs") protected String[] javacArgs
Arguments for javac (when using incremental compiler).
-
javacGenerateDebugSymbols
@Parameter(property="javacGenerateDebugSymbols", defaultValue="true") protected boolean javacGenerateDebugSymbols
Whether to instruct javac to generate debug symbols (when using incremental compiler)
-
addJavacArgs
@Parameter(property="addJavacArgs") protected String addJavacArgs
Alternative method for specifying javac arguments (when using incremental compiler). Can be used from command line with -DaddJavacArgs=arg1|arg2|arg3|... rather than in pom.xml.
-
source
@Parameter(property="maven.compiler.source") protected String source
The -source argument for the Java compiler (when using incremental compiler).
-
target
@Parameter(property="maven.compiler.target") protected String target
The -target argument for the Java compiler (when using incremental compiler).
-
encoding
@Parameter(property="project.build.sourceEncoding", defaultValue="UTF-8") protected String encoding
The -encoding argument for the Java compiler. (when using incremental compiler).
-
displayCmd
@Parameter(property="displayCmd", defaultValue="false", required=true) public boolean displayCmd
Display the command line called ? (property 'maven.scala.displayCmd' replaced by 'displayCmd')
-
fork
@Parameter(defaultValue="true") protected boolean fork
Forks the execution of scalac into a separate process.
-
forceUseArgFile
@Parameter(defaultValue="false") protected boolean forceUseArgFile
Force the use of an external ArgFile to run any forked process.
-
checkMultipleScalaVersions
@Parameter(property="maven.scala.checkConsistency", defaultValue="true") protected boolean checkMultipleScalaVersions
Check if every dependencies use the same version of scala-library or scala.compat.version.
-
failOnMultipleScalaVersions
@Parameter(defaultValue="false") protected boolean failOnMultipleScalaVersions
Determines if a detection of multiple scala versions in the dependencies will cause the build to fail.
-
useCanonicalPath
@Parameter(property="maven.scala.useCanonicalPath", defaultValue="true") protected boolean useCanonicalPath
Should use CanonicalPath to normalize path (true => getCanonicalPath, false => getAbsolutePath)
-
mavenProjectBuilder
@Component protected org.apache.maven.project.MavenProjectBuilder mavenProjectBuilder
Artifact factory, needed to download source jars.
-
toolchainManager
@Component protected org.apache.maven.toolchain.ToolchainManager toolchainManager
The toolchain manager to use.
-
-
Method Detail
-
getScalaOrganization
public String getScalaOrganization()
-
scalaCompilerArtifact
protected final org.apache.maven.artifact.Artifact scalaCompilerArtifact(String scalaVersion)
Constructs anArtifact
for Scala Compiler.- Parameters:
scalaVersion
- the version of the Scala Compiler/Library we are using for this execution.- Returns:
- a
Artifact
for the Scala Compiler.
-
resolveArtifactDependencies
protected final Set<org.apache.maven.artifact.Artifact> resolveArtifactDependencies(org.apache.maven.artifact.Artifact artifact) throws Exception
This method resolves all transitive dependencies of an artifact.
-
resolveDependencyArtifacts
protected final Set<org.apache.maven.artifact.Artifact> resolveDependencyArtifacts(org.apache.maven.artifact.Artifact artifact, org.apache.maven.artifact.resolver.filter.ArtifactFilter collectionFilter, org.apache.maven.artifact.resolver.filter.ArtifactFilter resolutionFilter) throws Exception
This method resolves all transitive dependencies of an artifact.- Parameters:
artifact
- theArtifact
used to retrieve dependencies.collectionFilter
- anArtifactFilter
used to determine which members of the dependency graph should be included in resolution.collectionFilter
- anArtifactFilter
used to determine which members dependency graph should be downloaded.- Returns:
- resolved
Set
of dependencies. - Throws:
Exception
-
resolveDependencyArtifacts
protected final Set<org.apache.maven.artifact.Artifact> resolveDependencyArtifacts(org.apache.maven.artifact.Artifact artifact, org.apache.maven.artifact.resolver.filter.ArtifactFilter collectionFilter, org.apache.maven.artifact.resolver.filter.ArtifactFilter resolutionFilter, List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories, org.apache.maven.artifact.repository.ArtifactRepository localRepository) throws Exception
This method resolves all transitive dependencies of an artifact.- Parameters:
artifact
- theArtifact
used to retrieve dependencies.collectionFilter
- anArtifactFilter
used to determine which members of the dependency graph should be included in resolution.collectionFilter
- anArtifactFilter
used to determine which members dependency graph should be downloaded.remoteRepositories
- aList
of remoteArtifactRespository
values to used for dependency resolution of the providedArtifact
.localRepository
- the localArtifactRepository
to use for dependency resolution of the givenArtifact
.- Returns:
- resolved
Set
of dependencies. - Throws:
Exception
-
addToClasspath
public void addToClasspath(String groupId, String artifactId, String version, Set<String> classpath) throws Exception
- Throws:
Exception
-
addToClasspath
public void addToClasspath(String groupId, String artifactId, String version, Set<String> classpath, boolean addDependencies) throws Exception
- Throws:
Exception
-
addToClasspath
public void addToClasspath(String groupId, String artifactId, String version, String classifier, Set<String> classpath, boolean addDependencies) throws Exception
added for classifier support.- Throws:
Exception
-
addToClasspath
protected void addToClasspath(org.apache.maven.artifact.Artifact artifact, Set<String> classpath, boolean addDependencies) throws Exception
- Throws:
Exception
-
addCompilerToClasspath
protected void addCompilerToClasspath(Set<String> classpath) throws Exception
- Throws:
Exception
-
addLibraryToClasspath
protected void addLibraryToClasspath(Set<String> classpath) throws Exception
- Throws:
Exception
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
- Throws:
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
-
getDependencies
protected List<org.apache.maven.model.Dependency> getDependencies()
-
findScalaVersion
protected VersionNumber findScalaVersion() throws Exception
- Throws:
Exception
-
findVersionFromDependencies
protected String findVersionFromDependencies(String groupId, String artifactId) throws Exception
- Throws:
Exception
-
getScalaCommand
protected JavaMainCaller getScalaCommand() throws Exception
- Throws:
Exception
-
getScalaCommand
protected final JavaMainCaller getScalaCommand(boolean forkOverride, String mainClass) throws Exception
Get aJavaMainCaller
used invoke a Java process. Typically this will be one of the Scala utilities (Compiler, ScalaDoc, REPL, etc.).This method does some setup on the
JavaMainCaller
which is not done by merely invokingnew
on one of the implementations. Specifically, it adds any Scala compiler plugin options, JVM options, and Scalac options defined on the plugin.- Parameters:
forkOverride
- override the setting forfork
. Currently this should only be set if you are invoking the REPL.mainClass
- the JVM main class to invoke.- Returns:
- a
JavaMainCaller
to use to invoke the given command. - Throws:
Exception
-
getEmptyScalaCommand
protected final JavaMainCaller getEmptyScalaCommand(String mainClass) throws Exception
Get aJavaMainCaller
used invoke a Java process. Typically this will be one of the Scala utilities (Compiler, ScalaDoc, REPL, etc.).- Parameters:
mainClass
- the JVM main class to invoke.- Returns:
- a
JavaMainCaller
to use to invoke the given command. - Throws:
Exception
-
getEmptyScalaCommand
protected JavaMainCaller getEmptyScalaCommand(String mainClass, boolean forkOverride) throws Exception
Get aJavaMainCaller
used invoke a Java process. Typically this will be one of the Scala utilities (Compiler, ScalaDoc, REPL, etc.).- Parameters:
mainClass
- the JVM main class to invoke.forkOverride
- override the setting forfork
. Currently this should only be set if you are invoking the REPL.- Returns:
- a
JavaMainCaller
to use to invoke the given command. - Throws:
Exception
-
getCompilerDependencies
protected List<File> getCompilerDependencies() throws Exception
- Throws:
Exception
-
getArtifactJar
protected File getArtifactJar(String groupId, String artifactId, String version) throws Exception
- Throws:
Exception
-
getArtifactJar
protected File getArtifactJar(String groupId, String artifactId, String version, String classifier) throws Exception
- Throws:
Exception
-
getAllDependencies
protected Set<org.apache.maven.artifact.Artifact> getAllDependencies(String groupId, String artifactId, String version) throws Exception
- Throws:
Exception
-
isJavaSupportedByCompiler
protected boolean isJavaSupportedByCompiler() throws Exception
- Returns:
- This returns whether or not the scala version can support having java sent into the compiler
- Throws:
Exception
-
addCompilerPluginOptions
protected void addCompilerPluginOptions(JavaMainCaller scalac) throws Exception
Adds appropriate compiler plugins to the scalac command.- Parameters:
scalac
-- Throws:
Exception
-
getCompilerPluginOptions
protected List<String> getCompilerPluginOptions() throws Exception
- Throws:
Exception
-
findVersionFromPluginArtifacts
protected String findVersionFromPluginArtifacts(String groupId, String artifactId) throws Exception
- Throws:
Exception
-
getPluginArtifactJar
protected File getPluginArtifactJar(String groupId, String artifactId, String version) throws Exception
- Throws:
Exception
-
-