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 Details

    • SCALA_LIBRARY_ARTIFACTID

      public static final String SCALA_LIBRARY_ARTIFACTID
      See Also:
    • SCALA_COMPILER_ARTIFACTID

      public static final String SCALA_COMPILER_ARTIFACTID
      See Also:
    • POM

      protected static final String POM
      Constant String for "pom". Used to specify the Maven POM artifact type.
      See Also:
    • JAR

      protected static final String JAR
      Constant String 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 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
    • scalaVersion

      @Parameter(property="scala.version") private String 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 scalaOrganization
      Organization/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

      @Parameter(property="scala.compat.version") private String 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

      @Parameter(property="scala.home") private String scalaHome
      Path to Scala installation to use instead of the artifact (define as dependencies).
    • 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)
      See Also:
    • 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)
      See Also:
    • mavenProjectBuilder

      @Component protected org.apache.maven.project.MavenProjectBuilder mavenProjectBuilder
      Artifact factory, needed to download source jars.
    • localRepository

      @Parameter(property="localRepository", required=true, readonly=true) private org.apache.maven.artifact.repository.ArtifactRepository localRepository
      The artifact repository to use.
    • artifactFactory

      @Component private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory
      The artifact factory to use.
    • artifactMetadataSource

      @Component private org.apache.maven.artifact.metadata.ArtifactMetadataSource artifactMetadataSource
      The artifact metadata source to use.
    • artifactCollector

      @Component private org.apache.maven.artifact.resolver.ArtifactCollector artifactCollector
      The artifact collector to use.
    • dependencyTreeBuilder

      @Component private org.apache.maven.shared.dependency.graph.DependencyGraphBuilder dependencyTreeBuilder
      The dependency tree builder to use.
    • toolchainManager

      @Component protected org.apache.maven.toolchain.ToolchainManager toolchainManager
      The toolchain manager to use.
    • pluginArtifacts

      @Parameter(defaultValue="${plugin.artifacts}") private List<org.apache.maven.artifact.Artifact> pluginArtifacts
      List of artifacts to run plugin
    • _scalaVersionN

      private VersionNumber _scalaVersionN
  • Constructor Details

    • ScalaMojoSupport

      public ScalaMojoSupport()
  • Method Details

    • getScalaOrganization

      public String getScalaOrganization()
    • scalaCompilerArtifact

      protected final org.apache.maven.artifact.Artifact scalaCompilerArtifact(String scalaVersion)
      Constructs an Artifact 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.
      Parameters:
      artifact - the Artifact used to retrieve dependencies.
      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) throws Exception
      This method resolves all transitive dependencies of an artifact.
      Parameters:
      artifact - the Artifact used to retrieve dependencies.
      collectionFilter - an ArtifactFilter used to determine which members of the dependency graph should be included in resolution.
      collectionFilter - an ArtifactFilter 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 - the Artifact used to retrieve dependencies.
      collectionFilter - an ArtifactFilter used to determine which members of the dependency graph should be included in resolution.
      collectionFilter - an ArtifactFilter used to determine which members dependency graph should be downloaded.
      remoteRepositories - a List of remote ArtifactRespository values to used for dependency resolution of the provided Artifact.
      localRepository - the local ArtifactRepository to use for dependency resolution of the given Artifact.
      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 a ArtifactResolutionRequest.
      Parameters:
      artifact - the Artifact used to retrieve dependencies.
      collectionFilter - an ArtifactFilter used to determine which members of the dependency graph should be included in resolution.
      collectionFilter - an ArtifactFilter used to determine which members dependency graph should be downloaded.
      remoteRepositories - a List of remote ArtifactRespository values to used for dependency resolution of the provided Artifact.
      localRepository - the local ArtifactRepository to use for dependency resolution of the given Artifact.
      Returns:
      an ArtifactResolutionRequest, typically used for dependency resolution requests against an ArtifactResolver.
    • 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
    • findScalaVersionFromDependencies

      private String findScalaVersionFromDependencies() throws Exception
      Throws:
      Exception
    • findVersionFromDependencies

      protected String findVersionFromDependencies(String groupId, String artifactId) throws Exception
      Throws:
      Exception
    • checkScalaVersion

      protected void checkScalaVersion() throws Exception
      Throws:
      Exception
    • checkCorrectVersionsOfScalaLibrary

      private void checkCorrectVersionsOfScalaLibrary(String scalaDefVersion) throws Exception
      this method checks to see if there are multiple versions of the scala library
      Throws:
      Exception
    • checkArtifactForScalaVersion

      private void checkArtifactForScalaVersion(VersionNumber requiredScalaVersion, org.apache.maven.shared.dependency.graph.DependencyNode rootNode) throws Exception
      Visits a node (and all dependencies) to see if it contains duplicate scala versions
      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

      protected abstract void doExecute() throws Exception
      Throws:
      Exception
    • getScalaCommand

      protected JavaMainCaller getScalaCommand() throws Exception
      Throws:
      Exception
    • getScalaCommand

      protected final JavaMainCaller getScalaCommand(boolean forkOverride, String mainClass) throws Exception
      Get a JavaMainCaller 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 invoking new 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 for fork. 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 a JavaMainCaller 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 a JavaMainCaller 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 for fork. 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

      private String getToolClasspath() throws Exception
      Throws:
      Exception
    • getScalaOptions

      protected List<String> getScalaOptions() throws Exception
      Throws:
      Exception
    • getJavacOptions

      protected List<String> getJavacOptions() throws Exception
      Throws:
      Exception
    • getLibraryJar

      protected File getLibraryJar() throws Exception
      Throws:
      Exception
    • getCompilerJar

      protected File getCompilerJar() throws Exception
      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
    • getCompilerPlugins

      private Set<String> getCompilerPlugins() throws Exception
      Retrieves a list of paths to scala compiler plugins.
      Returns:
      The list of plugins
      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
    • getPluginArtifactJar

      protected File getPluginArtifactJar(String groupId, String artifactId, String version, String classifier) throws Exception
      Throws:
      Exception