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
FieldsModifier and TypeFieldDescriptionprivate VersionNumber
protected String
Alternative method for specifying javac arguments (when using incremental compiler).protected String
Additional parameter to use to call the main class.protected String[]
compiler additional argumentsprivate org.apache.maven.artifact.resolver.ArtifactCollector
The artifact collector to use.private org.apache.maven.artifact.factory.ArtifactFactory
The artifact factory to use.private org.apache.maven.artifact.metadata.ArtifactMetadataSource
The artifact metadata source to use.protected boolean
Check if every dependencies use the same version of scala-library or scala.compat.version.protected BasicArtifact[]
Compiler plugin dependencies to use when compiling.protected BasicArtifact[]
Additional dependencies/jar to add to classpath to run "scalaClassName" (scope and optional field not supported) ex :private org.apache.maven.shared.dependency.graph.DependencyGraphBuilder
The dependency tree builder to use.boolean
Display the command line called ? (property 'maven.scala.displayCmd' replaced by 'displayCmd')protected String
The -encoding argument for the Java compiler.protected org.apache.maven.repository.RepositorySystem
Used to look up Artifacts in the remote repository.protected boolean
Determines if a detection of multiple scala versions in the dependencies will cause the build to fail.protected boolean
Force the use of an external ArgFile to run any forked process.protected boolean
Forks the execution of scalac into a separate process.protected static final String
ConstantString
for "jar".protected String[]
Arguments for javac (when using incremental compiler).protected boolean
Whether to instruct javac to generate debug symbols (when using incremental compiler)protected String[]
Jvm Arguments.protected org.apache.maven.artifact.repository.ArtifactRepository
Location of the local repository.private org.apache.maven.artifact.repository.ArtifactRepository
The artifact repository to use.protected org.apache.maven.project.MavenProjectBuilder
Artifact factory, needed to download source jars.private List
<org.apache.maven.artifact.Artifact> List of artifacts to run pluginprotected static final String
ConstantString
for "pom".protected org.apache.maven.project.MavenProject
The maven project.protected List
<org.apache.maven.project.MavenProject> Contains the full list of projects in the reactor.protected List
<org.apache.maven.artifact.repository.ArtifactRepository> List of Remote Repositories used by the resolverprotected org.apache.maven.artifact.resolver.ArtifactResolver
Used to look up Artifacts in the remote repository.static final String
static final String
protected String
className (FQN) of the scala tool to provide asprivate String
Scala 's version to use to check binary compatibility (like suffix in artifactId of dependency).private String
Path to Scala installation to use instead of the artifact (define as dependencies).private String
Organization/group ID of the Scala used in the project.private String
Scala 's version to use.protected org.apache.maven.execution.MavenSession
The Maven Session Objectprotected String
The -source argument for the Java compiler (when using incremental compiler).protected String
The -target argument for the Java compiler (when using incremental compiler).protected org.apache.maven.toolchain.ToolchainManager
The toolchain manager to use.protected boolean
Should use CanonicalPath to normalize path (true => getCanonicalPath, false => getAbsolutePath)Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
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
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) private void
checkArtifactForScalaVersion
(VersionNumber requiredScalaVersion, org.apache.maven.shared.dependency.graph.DependencyNode rootNode) Visits a node (and all dependencies) to see if it contains duplicate scala versionsprivate void
checkCorrectVersionsOfScalaLibrary
(String scalaDefVersion) this method checks to see if there are multiple versions of the scala libraryprotected void
private org.apache.maven.artifact.resolver.ArtifactResolutionRequest
createArtifactResolutionRequest
(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) Create aArtifactResolutionRequest
.private org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter
protected abstract void
void
execute()
protected VersionNumber
private String
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 File
Retrieves a list of paths to scala compiler plugins.protected List
<org.apache.maven.model.Dependency> protected final 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 File
protected File
getPluginArtifactJar
(String groupId, String artifactId, String version) protected File
getPluginArtifactJar
(String groupId, String artifactId, String version, String classifier) protected JavaMainCaller
protected final JavaMainCaller
getScalaCommand
(boolean forkOverride, String mainClass) Get aJavaMainCaller
used invoke a Java process.private String
protected boolean
protected final Set
<org.apache.maven.artifact.Artifact> resolveArtifactDependencies
(org.apache.maven.artifact.Artifact artifact) This method resolves all transitive dependencies of an artifact.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) This method resolves all transitive dependencies of an artifact.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) This method resolves all transitive dependencies of an artifact.protected final org.apache.maven.artifact.Artifact
scalaCompilerArtifact
(String scalaVersion) Constructs anArtifact
for Scala Compiler.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
SCALA_LIBRARY_ARTIFACTID
- See Also:
-
SCALA_COMPILER_ARTIFACTID
- See Also:
-
POM
ConstantString
for "pom". Used to specify the Maven POM artifact type.- See Also:
-
JAR
ConstantString
for "jar". Used to specify the Maven JAR artifact type.- See Also:
-
project
@Parameter(property="project", required=true, readonly=true) protected org.apache.maven.project.MavenProject projectThe maven project. -
session
@Parameter(property="session", required=true, readonly=true) protected org.apache.maven.execution.MavenSession sessionThe Maven Session Object -
reactorProjects
@Parameter(defaultValue="${reactorProjects}", readonly=true, required=true) protected List<org.apache.maven.project.MavenProject> reactorProjectsContains the full list of projects in the reactor. -
factory
@Component protected org.apache.maven.repository.RepositorySystem factoryUsed to look up Artifacts in the remote repository. -
resolver
@Component protected org.apache.maven.artifact.resolver.ArtifactResolver resolverUsed to look up Artifacts in the remote repository. -
localRepo
@Parameter(property="localRepository", readonly=true, required=true) protected org.apache.maven.artifact.repository.ArtifactRepository localRepoLocation of the local repository. -
remoteRepos
@Parameter(property="project.remoteArtifactRepositories", readonly=true, required=true) protected List<org.apache.maven.artifact.repository.ArtifactRepository> remoteReposList of Remote Repositories used by the resolver -
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
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
Jvm Arguments. -
args
compiler additional arguments -
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 scalaClassNameclassName (FQN) of the scala tool to provide as -
scalaVersion
Scala 's version to use. (property 'maven.scala.version' replaced by 'scala.version') -
scalaOrganization
@Parameter(property="scala.organization", defaultValue="org.scala-lang") private String scalaOrganizationOrganization/group ID of the Scala used in the project. Default value is 'org.scala-lang'. This is an advanced setting used for clones of the Scala Language. It should be disregarded in standard use cases. -
scalaCompatVersion
Scala 's version to use to check binary compatibility (like suffix in artifactId of dependency). If it is defined then it is used to checkMultipleScalaVersions -
scalaHome
Path to Scala installation to use instead of the artifact (define as dependencies). -
javacArgs
Arguments for javac (when using incremental compiler). -
javacGenerateDebugSymbols
@Parameter(property="javacGenerateDebugSymbols", defaultValue="true") protected boolean javacGenerateDebugSymbolsWhether to instruct javac to generate debug symbols (when using incremental compiler)- See Also:
-
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
The -source argument for the Java compiler (when using incremental compiler). -
target
The -target argument for the Java compiler (when using incremental compiler). -
encoding
The -encoding argument for the Java compiler. (when using incremental compiler). -
displayCmd
@Parameter(property="displayCmd", defaultValue="false", required=true) public boolean displayCmdDisplay the command line called ? (property 'maven.scala.displayCmd' replaced by 'displayCmd') -
fork
@Parameter(defaultValue="true") protected boolean forkForks the execution of scalac into a separate process. -
forceUseArgFile
@Parameter(defaultValue="false") protected boolean forceUseArgFileForce the use of an external ArgFile to run any forked process. -
checkMultipleScalaVersions
@Parameter(property="maven.scala.checkConsistency", defaultValue="true") protected boolean checkMultipleScalaVersionsCheck if every dependencies use the same version of scala-library or scala.compat.version. -
failOnMultipleScalaVersions
@Parameter(defaultValue="false") protected boolean failOnMultipleScalaVersionsDetermines 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 useCanonicalPathShould use CanonicalPath to normalize path (true => getCanonicalPath, false => getAbsolutePath)- See Also:
-
mavenProjectBuilder
@Component protected org.apache.maven.project.MavenProjectBuilder mavenProjectBuilderArtifact factory, needed to download source jars. -
localRepository
@Parameter(property="localRepository", required=true, readonly=true) private org.apache.maven.artifact.repository.ArtifactRepository localRepositoryThe artifact repository to use. -
artifactFactory
@Component private org.apache.maven.artifact.factory.ArtifactFactory artifactFactoryThe artifact factory to use. -
artifactMetadataSource
@Component private org.apache.maven.artifact.metadata.ArtifactMetadataSource artifactMetadataSourceThe artifact metadata source to use. -
artifactCollector
@Component private org.apache.maven.artifact.resolver.ArtifactCollector artifactCollectorThe artifact collector to use. -
dependencyTreeBuilder
@Component private org.apache.maven.shared.dependency.graph.DependencyGraphBuilder dependencyTreeBuilderThe dependency tree builder to use. -
toolchainManager
@Component protected org.apache.maven.toolchain.ToolchainManager toolchainManagerThe toolchain manager to use. -
pluginArtifacts
@Parameter(defaultValue="${plugin.artifacts}") private List<org.apache.maven.artifact.Artifact> pluginArtifactsList of artifacts to run plugin -
_scalaVersionN
-
-
Constructor Details
-
ScalaMojoSupport
public ScalaMojoSupport()
-
-
Method Details
-
getScalaOrganization
-
scalaCompilerArtifact
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.remoteRepositories
- aList
of remoteinvalid reference
ArtifactRespository
Artifact
.localRepository
- the localArtifactRepository
to use for dependency resolution of the givenArtifact
.collectionFilter
- anArtifactFilter
used to determine which members dependency graph should be downloaded.- Returns:
- resolved
Set
of dependencies. - Throws:
Exception
-
createArtifactResolutionRequest
private org.apache.maven.artifact.resolver.ArtifactResolutionRequest createArtifactResolutionRequest(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) Create aArtifactResolutionRequest
.- Parameters:
artifact
- theArtifact
used to retrieve dependencies.collectionFilter
- anArtifactFilter
used to determine which members of the dependency graph should be included in resolution.remoteRepositories
- aList
of remoteinvalid reference
ArtifactRespository
Artifact
.localRepository
- the localArtifactRepository
to use for dependency resolution of the givenArtifact
.collectionFilter
- anArtifactFilter
used to determine which members dependency graph should be downloaded.- Returns:
- an
ArtifactResolutionRequest
, typically used for dependency resolution requests against anArtifactResolver
.
-
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
- Throws:
Exception
-
addLibraryToClasspath
- 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
-
findScalaVersion
- Throws:
Exception
-
findScalaVersionFromDependencies
- Throws:
Exception
-
findVersionFromDependencies
- Throws:
Exception
-
checkScalaVersion
- Throws:
Exception
-
checkCorrectVersionsOfScalaLibrary
this method checks to see if there are multiple versions of the scala library- Throws:
Exception
-
createScalaDistroDependencyFilter
private org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter createScalaDistroDependencyFilter()- Returns:
- A filter to only extract artifacts deployed from scala distributions
-
doExecute
- Throws:
Exception
-
getScalaCommand
- 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
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
-
getToolClasspath
- Throws:
Exception
-
getScalaOptions
- Throws:
Exception
-
getJavacOptions
- Throws:
Exception
-
getLibraryJar
- Throws:
Exception
-
getCompilerJar
- Throws:
Exception
-
getCompilerDependencies
- Throws:
Exception
-
getArtifactJar
- 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
- Returns:
- This returns whether or not the scala version can support having java sent into the compiler
- Throws:
Exception
-
addCompilerPluginOptions
Adds appropriate compiler plugins to the scalac command.- Parameters:
scalac
-- Throws:
Exception
-
getCompilerPluginOptions
- Throws:
Exception
-
getCompilerPlugins
Retrieves a list of paths to scala compiler plugins.- Returns:
- The list of plugins
- Throws:
Exception
-
findVersionFromPluginArtifacts
- Throws:
Exception
-
getPluginArtifactJar
protected File getPluginArtifactJar(String groupId, String artifactId, String version) throws Exception - Throws:
Exception
-
getPluginArtifactJar
protected File getPluginArtifactJar(String groupId, String artifactId, String version, String classifier) throws Exception - Throws:
Exception
-